aboutsummaryrefslogtreecommitdiffstats
path: root/src/bytecode/compiler.h
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-10-24 14:14:31 +0200
committerBad Diode <bd@badd10de.dev>2021-10-24 14:14:31 +0200
commit76821f9d76282419823f3c85b042ad72863d4077 (patch)
treef2edfd78fd706b85738f533ae895f62c94676056 /src/bytecode/compiler.h
parentb97e4450a7ce377a1d50cac5342b7b1dd1a19add (diff)
downloadbdl-76821f9d76282419823f3c85b042ad72863d4077.tar.gz
bdl-76821f9d76282419823f3c85b042ad72863d4077.zip
Add set! keyword and OP
Diffstat (limited to 'src/bytecode/compiler.h')
-rwxr-xr-xsrc/bytecode/compiler.h13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/bytecode/compiler.h b/src/bytecode/compiler.h
index e2d5819..b1cdfb9 100755
--- a/src/bytecode/compiler.h
+++ b/src/bytecode/compiler.h
@@ -91,7 +91,7 @@ compile_list_binary_op(Chunk *chunk, Visitor *vs, Token start, Ops op) {
91 } 91 }
92 parse_tree(chunk, vs); 92 parse_tree(chunk, vs);
93 if (tok.type == TOKEN_SYMBOL) { 93 if (tok.type == TOKEN_SYMBOL) {
94 add_code(chunk, OP_GET_GLOBAL, tok.line, tok.column); 94 add_code(chunk, OP_GET, tok.line, tok.column);
95 } 95 }
96 n++; 96 n++;
97 } 97 }
@@ -127,7 +127,7 @@ compile_list_unary_op(Chunk *chunk, Visitor *vs, Token start, Ops op) {
127 } 127 }
128 parse_tree(chunk, vs); 128 parse_tree(chunk, vs);
129 if (tok.type == TOKEN_SYMBOL) { 129 if (tok.type == TOKEN_SYMBOL) {
130 add_code(chunk, OP_GET_GLOBAL, tok.line, tok.column); 130 add_code(chunk, OP_GET, tok.line, tok.column);
131 } 131 }
132 add_code(chunk, op, start.line, start.column); 132 add_code(chunk, op, start.line, start.column);
133 n++; 133 n++;
@@ -183,7 +183,7 @@ compile_list_simple_op(Chunk *chunk, Visitor *vs, Token start, Ops op) {
183} 183}
184 184
185void 185void
186compile_define_op(Chunk *chunk, Visitor *vs, Token start) { 186compile_declare_op(Chunk *chunk, Visitor *vs, Token start, Ops op) {
187 Token name = peek_token(vs); 187 Token name = peek_token(vs);
188 if (name.type != TOKEN_SYMBOL) { 188 if (name.type != TOKEN_SYMBOL) {
189 error_push((Error){ 189 error_push((Error){
@@ -216,7 +216,7 @@ compile_define_op(Chunk *chunk, Visitor *vs, Token start) {
216 } 216 }
217 parse_tree(chunk, vs); 217 parse_tree(chunk, vs);
218 if (expr.type == TOKEN_SYMBOL) { 218 if (expr.type == TOKEN_SYMBOL) {
219 add_code(chunk, OP_GET_GLOBAL, expr.line, expr.column); 219 add_code(chunk, OP_GET, expr.line, expr.column);
220 } 220 }
221 if (peek_token(vs).type != TOKEN_RPAREN) { 221 if (peek_token(vs).type != TOKEN_RPAREN) {
222 error_push((Error){ 222 error_push((Error){
@@ -228,7 +228,7 @@ compile_define_op(Chunk *chunk, Visitor *vs, Token start) {
228 return; 228 return;
229 } 229 }
230 next_token(vs); 230 next_token(vs);
231 add_code(chunk, OP_DEF, start.line, start.column); 231 add_code(chunk, op, start.line, start.column);
232} 232}
233 233
234void 234void
@@ -260,7 +260,8 @@ parse_list(Chunk *chunk, Visitor *vs, Token start) {
260 case TOKEN_PRINT: { compile_list_unary_op(chunk, vs, start, OP_PRINT); } break; 260 case TOKEN_PRINT: { compile_list_unary_op(chunk, vs, start, OP_PRINT); } break;
261 case TOKEN_DISPLAY: { compile_list_unary_op(chunk, vs, start, OP_DISPLAY); } break; 261 case TOKEN_DISPLAY: { compile_list_unary_op(chunk, vs, start, OP_DISPLAY); } break;
262 case TOKEN_NEWLINE: { compile_list_simple_op(chunk, vs, start, OP_NEWLINE); } break; 262 case TOKEN_NEWLINE: { compile_list_simple_op(chunk, vs, start, OP_NEWLINE); } break;
263 case TOKEN_DEF: { compile_define_op(chunk, vs, start); } break; 263 case TOKEN_DEF: { compile_declare_op(chunk, vs, start, OP_DEF); } break;
264 case TOKEN_SET: { compile_declare_op(chunk, vs, start, OP_SET); } break;
264 default: { 265 default: {
265 error_push((Error){ 266 error_push((Error){
266 .type = ERR_TYPE_COMPILER, 267 .type = ERR_TYPE_COMPILER,