aboutsummaryrefslogtreecommitdiff
path: root/compiler.d
diff options
context:
space:
mode:
Diffstat (limited to 'compiler.d')
-rw-r--r--compiler.d56
1 files changed, 2 insertions, 54 deletions
diff --git a/compiler.d b/compiler.d
index a436323..e04e5c8 100644
--- a/compiler.d
+++ b/compiler.d
@@ -287,43 +287,18 @@ class Compiler {
this.func.chunk.writeOp(OpCode.OP_DIVIDE, args[1].line);
}
- //ValueType compileLess(Form[] args, ValueType expected = ValueType.ANY) {
ValueType compileLess(Form[] args, ValueType expected) {
if (args.length != 2) {
- /*
- writeln("'<' requires 2 arguments");
- */
- this.error("'<' requires 2 arguments", -1);
+ this.error(format("'<': expected [2] arguments, received %d", args.length) -1);
this.advance();
return ValueType.NIL;
}
ValueType vt1 = this.resolve(args[0], ValueType.NUMBER);
- /*
- TC tc1 = typeCheck(vt1, expected);
- if (tc1.maybe) {
- func.chunk.writeOp(to!ubyte(tc1.op), currentLine);
- } else if (!tc1.exact) {
- writeln("COMPILE ERROR: bad type (less)");
- }
- */
this.func.chunk.writeOp(OpCode.OP_TYPE_CHECK_NUMBER, args[0].line);
ValueType vt2 = this.resolve(args[1], ValueType.NUMBER);
- /*
- TC tc2 = typeCheck(vt2, expected);
- if (tc2.maybe) {
- func.chunk.writeOp(to!ubyte(tc2.op), currentLine);
- } else if (!tc2.exact) {
- writeln("COMPILE ERROR: bad type (less)");
- }
- */
this.func.chunk.writeOp(OpCode.OP_TYPE_CHECK_NUMBER, args[1].line);
-
- //ValueType vt1 = resolve(args[0], expected);
- //func.chunk.writeOp(OpCode.OP_TYPE_CHECK_NUMBER, currentLine);
- //ValueType vt2 = resolve(args[1], expected);
- //func.chunk.writeOp(OpCode.OP_TYPE_CHECK_NUMBER, currentLine);
this.func.chunk.writeOp(OpCode.OP_LESS, args[1].line);
// this should probably return a ValueType
@@ -332,11 +307,8 @@ class Compiler {
ValueType compileGreater(Form[] args) {
if (args.length != 2) {
- this.error("'>' requires 2 arguments", -1);
+ this.error(format("'>': expected [2] arguments, received %d", to!int(args.length)) -1);
this.advance();
- /*
- writeln("'>' requires 2 arguments");
- */
return ValueType.NIL;
}
ValueType vt1 = this.resolve(args[0], ValueType.NUMBER);
@@ -365,8 +337,6 @@ class Compiler {
return ValueType.BOOLEAN;
}
-
- //int parseVariable(Def def) {
int parseVariable(Symbol sym) {
this.declareVariable(sym);
@@ -400,7 +370,6 @@ class Compiler {
if (sym.name == local.sym.name) {
this.error(format("already a variable named '%s' in this scope", sym.name), sym.line);
- //writefln("ERROR: already a variable named '%s' in this scope", sym.name);
return;
}
}
@@ -432,13 +401,6 @@ class Compiler {
this.defineVariable(addr);
}
- /*
- struct LV {
- int i;
- bool needsTypeCheck;
- }
- */
-
int resolveLocal(Symbol sym) {
for (int i = this.localCount - 1; i >= 0; i--) {
Local local = this.locals[i];
@@ -633,7 +595,6 @@ class Compiler {
// TODO how do we identify/propagate errors?
if (args.length != 1) {
this.error("'length': expected [1] argument, received 0", -1);
- //writeln("COMPILE ERROR: 'first' expects exactly one argument");
this.advance();
return;
}
@@ -664,7 +625,6 @@ class Compiler {
if (args.length != 2) {
this.error(format("'in?': expected [2] arguments, received %d", args.length), -1);
this.advance();
- //writeln("COMPILE ERROR: 'first' expects exactly one argument");
return;
}
ValueType vt1 = this.resolve(args[0], ValueType.ANY);
@@ -747,7 +707,6 @@ class Compiler {
if (args.length != 1) {
this.error("'first': expected [1] argument, received 0", -1);
this.advance();
- //writeln("COMPILE ERROR: 'first' expects exactly one argument");
return;
}
ValueType vt = this.resolve(args[0], ValueType.SEQ); // TODO need a new type
@@ -766,18 +725,12 @@ class Compiler {
if (args.length != 1) {
this.error("'rest': expected [1] argument, received ?", -1);
this.advance();
- //writeln("COMPILE ERROR: 'first' expects exactly one argument");
return;
}
ValueType vt = this.resolve(args[0], ValueType.OBJ); // TODO need a new type
this.func.chunk.writeOp(OpCode.OP_TYPE_CHECK_SEQ, args[0].line);
this.func.chunk.writeOp(OpCode.OP_REST, args[0].line);
-
- // there's probably a nicer way to copy
- //List lst = new List();
-
- // create a copy of the list
}
void compileLambda(Form form) {
@@ -951,10 +904,6 @@ class Compiler {
this.compileRest(cons.tail);
break;
default:
- /*
- writefln("unsure how to compile %s", sym.name);
- advance();
- */
this.resolve(head);
this.call(cons.tail);
this.advance();
@@ -965,7 +914,6 @@ class Compiler {
}
ValueType resolve(Form form, const ValueType expecting = ValueType.ANY) {
- //printForm(form);
this.currentLine = form.line;
switch(form.type) {
case FormType.ATOM: