From 03b4987afc5e32ec560fac6f74c153d592f75259 Mon Sep 17 00:00:00 2001 From: Ben Winston Date: Sun, 21 May 2023 23:50:04 -0400 Subject: functionsgit add *.d! --- main.d | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'main.d') diff --git a/main.d b/main.d index c497283..eeff97d 100644 --- a/main.d +++ b/main.d @@ -1,10 +1,14 @@ import std.stdio; import std.string; +import std.file; +import std.conv; +/* import parser; import dbg; import chunk; import compiler; +*/ import vm; /* @@ -26,18 +30,47 @@ void repl() { continue; } + /* Parser parser = new Parser(input); Compiler compiler = new Compiler(ObjType.SCRIPT, &parser); Function func = compiler.compile(); + */ + /* VM vm = new VM(func); vm.run(); - + */ + interpret(input); } } +string readFile(string fname) { + + File f = File(fname, "r"); + + char[] ret = []; + while (!f.eof()) { + ret = ret ~ f.readln(); + } + f.close(); + return to!string(ret); +} + +int main(string[] args) { + if (args.length <= 1) { + repl(); + } else { + string fname = args[1]; + + if (!exists(fname)) { + writeln("file doesn't exist: ", fname); + return 1; + } + + string data = readFile(fname); -void main() { - repl(); + interpret(data); + } + return 0; } -- cgit v1.2.3