aboutsummaryrefslogtreecommitdiff
path: root/main.d
diff options
context:
space:
mode:
Diffstat (limited to 'main.d')
-rw-r--r--main.d90
1 files changed, 23 insertions, 67 deletions
diff --git a/main.d b/main.d
index bd1d2b0..0bdc74b 100644
--- a/main.d
+++ b/main.d
@@ -3,6 +3,10 @@ import std.string;
import parser;
import dbg;
+import chunk;
+import compiler;
+import vm;
+
/*
import compiler;
import obj;
@@ -11,53 +15,6 @@ import chunk;
import vm;
*/
-void printForm(Form f, string prefix) {
- switch (f.type) {
- case FormType.EOF:
- writeln("eof");
- return;
- case FormType.ATOM:
- writefln("%s atom: %s", prefix, atomAsString(cast(Atom)f));
- break;
- case FormType.CONS:
- Cons c = cast(Cons)f;
- writef("%s cons <", prefix);
- if (c.evaluate) {
- writeln("true>");
- } else {
- writeln("false>");
- }
-
- printForm(c.head, format("%s>", prefix));
- foreach (Form i ; c.tail) {
- printForm(i, format("%s>", prefix));
- }
- break;
- case FormType.NIL:
- writefln("%s NIL", prefix);
- break;
- case FormType.PARSE_ERROR:
- ParseError pe = cast(ParseError)f;
- writefln("ERROR: %s", pe.message);
- break;
- case FormType.SYMBOL:
- Symbol s = cast(Symbol)f;
- writefln("%s sym: %s", prefix, s.name);
- break;
- case FormType.FUNC:
- Func func = cast(Func)f;
- writefln("%s <fn %s>", prefix, func.name.name);
- printForm(func.args, format("%s -", prefix));
- writefln("%s with %d body lines", prefix, func.funcBody.length);
- writefln("%s <end fn %s>", prefix, func.name.name);
- break;
- default:
- writeln("printFormDefault");
- break;
- }
-
-}
-
void repl() {
while(true) {
@@ -69,37 +26,36 @@ void repl() {
}
Parser parser = new Parser(input);
+
+ /*
+ Chunk chunk = new Chunk();
Form f;
while (true) {
f = parser.parseForm();
-
printForm(f, "");
+
+ f.compile(chunk);
+
+
if (f.type == FormType.EOF) {
break;
}
+ }
+ */
+ Compiler compiler = new Compiler(FunctionType.SCRIPT, &parser);
+ Function func = compiler.compile();
- /*
- if (is(typeof(f) == Eof)) {
- writeln("eof");
- break;
- } else if (is(typeof(f) == Atom)) {
- writeln("atom");
- } else {
- writeln("other");
- }
- */
+ VM vm = new VM(func);
+ vm.run();
- /*
- if (typeof(f) == EOF) {
- writeln("reached the end");
- break;
- } else if (typeof(f) == ParseError) {
- writefln("got a parse error: %s", f.message);
- break;
- }
- */
+ /*
+ writeln("== disassembling chunk ==");
+ int off = 0;
+ while (off < func.chunk.code.length) {
+ off = disassemble(func.chunk, off);
}
+ */
/*
Compiler compiler = new Compiler(lex);