Commit Graph

3 Commits

Author SHA1 Message Date
Bob Nystrom
ca8f9faf18 feat: implement local variable declarations and symbol table in compiler and VM
Add support for local variable declarations with `var` keyword in the Wren compiler, including a symbol table for tracking locals within blocks. Introduce new bytecode instructions (CODE_POP, CODE_LOAD_LOCAL, CODE_STORE_LOCAL) and a call frame stack in the VM to manage local variable scopes during execution. Refactor the symbol table from a flat array to a proper SymbolTable struct with init/clear/add/ensure/find functions, and add a primitive method table for the num class with an `abs` method.
2013-10-23 22:32:59 +00:00
Bob Nystrom
71c4c330ca feat: replace recursive descent parser with grammar-driven approach and add method call infrastructure
Refactor compiler.c to remove recursive descent parsing infrastructure (InfixCompiler, CompileFn, precedence enums) and replace with a simpler grammar-driven approach using statement(), call(), primary(), and number() functions. Add VM struct to compiler.h and vm.h with symbol table support, including getSymbol() for method name resolution. Introduce CODE_CALL opcode in VM interpreter with basic call dispatch. Update main.c to use new VM lifecycle (newVM/freeVM) and pass VM through compile and interpret calls.
2013-10-23 20:51:41 +00:00
Bob Nystrom
9bb2ca308e feat: replace AST-based parser with single-pass bytecode compiler and VM
Replace the recursive-descent parser that built an AST (Node* tree) with a single-pass compiler that emits bytecode directly into a Block structure. Remove the parser.c/parser.h files and their AST node types (NodeLiteral, NodeCall, NodeBinaryOp, etc.), add new compiler.c/compiler.h with a Compiler struct and Pratt-style precedence parsing that outputs CODE_CONSTANT and CODE_END instructions, and introduce vm.c/vm.h containing a Fiber-based interpreter with a stack, interpret() loop, and printValue() for OBJ_INT. Update main.c to call compile() then interpret() instead of parse(), remove TOKEN_INDENT/TOKEN_OUTDENT from token.h and dumpTokens(), and adjust the Xcode project to include the new source files while excluding the old parser.
2013-10-22 19:16:39 +00:00