Skip to content

Instantly share code, notes, and snippets.

@therealadam
Created February 23, 2009 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save therealadam/68808 to your computer and use it in GitHub Desktop.
Save therealadam/68808 to your computer and use it in GitHub Desktop.
diff --git a/vm/compiler.c b/vm/compiler.c
index cfd6f57..64e098d 100644
--- a/vm/compiler.c
+++ b/vm/compiler.c
@@ -138,6 +138,9 @@ void TrCompiler_compile_node(VM, TrCompiler *c, TrBlock *b, TrNode *n, int reg)
TrCompiler_compile_node(vm, c, b, (TrNode *)v, reg);
});
break;
+ case AST_CLOWNCAR: {
+ PUSH_OP_A(b, CLOWNCAR, reg);
+ } break;
case AST_VALUE: {
int i = TrBlock_pushk(b, n->args[0]);
PUSH_OP_ABx(b, LOADK, reg, i);
diff --git a/vm/grammar.y b/vm/grammar.y
index abc5ee3..2089502 100644
--- a/vm/grammar.y
+++ b/vm/grammar.y
@@ -40,12 +40,7 @@ flow(A) ::= UNLESS statement(B) TERM statements(C) opt_term else(D) END. { A = N
else(A) ::= ELSE TERM statements(B) opt_term. { A = B; }
else(A) ::= . { A = 0; }
-flow(A) ::= WHILE statement(B) TERM statements(C) opt_term END. { A = NODE2(WHILE, B, C); }
-flow(A) ::= UNTIL statement(B) TERM statements(C) opt_term END. { A = NODE2(UNTIL, B, C); }
-/* one-liner conditions */
-flow(A) ::= expr_out(C) IF statement(B). { A = NODE2(IF, B, NODES(C)); }
-flow(A) ::= expr_out(C) UNLESS statement(B). { A = NODE2(UNLESS, B, NODES(C)); }
-
+literal(A) ::= CLOWNCAR. { A = NODE(CLOWNCAR, 0); }
literal(A) ::= SYMBOL(B). { A = NODE(VALUE, B); }
literal(A) ::= INT(B). { A = NODE(VALUE, B); }
literal(A) ::= STRING(B). { A = NODE(STRING, B); }
@@ -59,6 +54,12 @@ literal(A) ::= O_SBRA args(B) C_SBRA. { A = NODE(ARRAY, B); }
literal(A) ::= O_CBRA C_CBRA. { A = NODE(HASH, 0); }
literal(A) ::= O_CBRA hash_items(B) C_CBRA. { A = NODE(HASH, B); }
+flow(A) ::= WHILE statement(B) TERM statements(C) opt_term END. { A = NODE2(WHILE, B, C); }
+flow(A) ::= UNTIL statement(B) TERM statements(C) opt_term END. { A = NODE2(UNTIL, B, C); }
+/* one-liner conditions */
+flow(A) ::= expr_out(C) IF statement(B). { A = NODE2(IF, B, NODES(C)); }
+flow(A) ::= expr_out(C) UNLESS statement(B). { A = NODE2(UNLESS, B, NODES(C)); }
+
leave(A) ::= RETURN. { A = NODE(RETURN, 0); }
leave(A) ::= YIELD. { A = NODE(YIELD, 0); }
leave(A) ::= YIELD O_PAR args(B) C_PAR. { A = NODE(YIELD, B); }
diff --git a/vm/internal.h b/vm/internal.h
index 441690b..868bb92 100644
--- a/vm/internal.h
+++ b/vm/internal.h
@@ -31,6 +31,7 @@ typedef enum {
AST_UNTIL,
AST_BOOL,
AST_NIL,
+ AST_CLOWNCAR,
AST_SELF,
AST_RETURN,
AST_YIELD,
diff --git a/vm/opcode.h b/vm/opcode.h
index 456e7ae..1370c62 100644
--- a/vm/opcode.h
+++ b/vm/opcode.h
@@ -13,6 +13,7 @@ enum TrInstCode {
/* opname operands description */
TR_OP_BOING, /* do nothing with elegance and frivolity */
TR_OP_MOVE, /* A B R[A] = R[B] */
+ TR_OP_CLOWNCAR, /* A */
TR_OP_LOADK, /* A Bx R[A] = K[Bx] */
TR_OP_STRING, /* A Bx R[A] = strings[Bx] */
TR_OP_BOOL, /* A B R[A] = B + 1 */
diff --git a/vm/scanner.rl b/vm/scanner.rl
index 1a42b1a..c779601 100644
--- a/vm/scanner.rl
+++ b/vm/scanner.rl
@@ -58,6 +58,7 @@
"module" => { TOKEN(MODULE); };
"do" => { TOKEN(DO); };
"yield" => { TOKEN(YIELD); };
+ "clowncar" => { TOKEN(CLOWNCAR); };
# HACK any better way to do this?
".class" => { TOKEN(DOT); TOKEN_V(ID, tr_intern("class")); };
diff --git a/vm/vm.c b/vm/vm.c
index 93eb35f..badc66e 100644
--- a/vm/vm.c
+++ b/vm/vm.c
@@ -185,6 +185,7 @@ OBJ TrVM_step(VM, TrFrame *f, TrBlock *b, int argc, OBJ argv[]) {
OP(STRING): R[A] = TrString_new2(vm, strings[Bx]); DISPATCH;
OP(SELF): R[A] = f->self; DISPATCH;
OP(NIL): R[A] = TR_NIL; DISPATCH;
+ OP(CLOWNCAR): printf("CLOWNCAR IS FULL!\n"); DISPATCH;
OP(BOOL): R[A] = B+1; DISPATCH;
OP(NEWARRAY): R[A] = TrArray_new3(vm, B, &R[A+1]); DISPATCH;
OP(NEWHASH): R[A] = TrHash_new2(vm, B, &R[A+1]); DISPATCH;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment