Commit Graph

7 Commits

Author SHA1 Message Date
Bob Nystrom
f50453e24e feat: add instance field support with lexer, compiler, and GC tracing
Add TOKEN_FIELD token type and '_' prefix handling in lexer to distinguish field identifiers from regular names. Extend Compiler struct with fields symbol table pointer for tracking enclosing class fields. Implement field() parse function and CODE_LOAD_FIELD/CODE_STORE_FIELD bytecodes in VM. Modify ObjClass to store numFields count and ObjInstance to use flexible array member for field storage. Update GC markInstance to trace all instance fields. Add newClass signature to accept numFields parameter. Include test cases for field default null, multiple fields, object references with GC, and use-before-set ordering.
2013-11-23 22:55:05 +00:00
Bob Nystrom
b9264e4c5a feat: add named user-defined constructors with this keyword prefix in class bodies 2013-11-20 15:20:16 +00:00
Bob Nystrom
06be5808da feat: add IS_FALSE macro for non-NaN-tag boolean false check in value.h
The new IS_FALSE macro checks if a Value's type field equals VAL_FALSE,
complementing the existing IS_NULL and IS_NUM macros for type discrimination
without relying on NaN-boxing tag bits.
2013-11-19 15:36:59 +00:00
Bob Nystrom
9e8eed6c29 feat: implement logical AND operator with short-circuit evaluation and new CODE_AND instruction
Add TOKEN_AMPAMP token to the lexer for parsing '&&' operator, introduce PREC_LOGIC precedence level for proper expression parsing, implement the `and()` compiler function that emits CODE_AND with a patchable jump offset, and add runtime support in the VM with IS_FALSE macro for truthiness checking. Include comprehensive test cases in test/and.wren verifying short-circuit behavior and return values.
2013-11-19 15:35:25 +00:00
Bob Nystrom
9c663aa13c feat: implement NaN tagging for Value union and hoist bytecode/IP into locals in interpret loop
Switch Value from a struct with type/num/obj fields to a NaN-tagged uint64_t/double union, enabling faster type checks and unboxed numbers. Refactor all macros and accessors (IS_OBJ, AS_OBJ, AS_NUM, etc.) to work with the new representation. Hoist CallFrame pointer, instruction pointer, and bytecode array into local variables inside the interpret loop, updating them on frame push/pop. Enable NAN_TAGGING define and DEBUG_GC_STRESS in common.h. Update Xcode project to use c99 standard, pedantic warnings, and treat warnings as errors. Add benchmark/fib.txt with timing comparisons showing fib benchmark within 25% of Lua.
2013-11-17 22:20:15 +00:00
Bob Nystrom
69744a3acc refactor: replace call method primitives with fiber primitives and remove NO_VAL sentinel
Introduce METHOD_FIBER type and FIBER_PRIMITIVE/DEF_FIBER_PRIMITIVE macros to handle primitives that directly manipulate the fiber's call stack, eliminating the need for the special NO_VAL return value hack. Remove all fn_call0 through fn_call8 primitives and convert them to fiber primitives that call callFunction without returning a value. Update Primitive typedef to remove the Fiber parameter, and adjust primitive_metaclass_new and the interpret switch case accordingly. Delete the NO_VAL macro and its TODO comment from value.h.
2013-11-17 17:02:57 +00:00
Bob Nystrom
a59289a0af refactor: extract value type definitions and helpers from vm.h into new value.h/c files 2013-11-17 01:51:30 +00:00