therealadam (owner)

Revisions

gist: 68808 Download_button fork
public
Public Clone URL: git://gist.github.com/68808.git
Embed All Files: show embed
Diff #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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;