Commit Graph

8 Commits

Author SHA1 Message Date
Bob Nystrom
c726845c42 feat: implement expression evaluation and statement detection in REPL with Meta.compileExpression
Add executeInput() method to REPL that lexes input, determines if it's a statement or expression based on the first token, and evaluates accordingly using Meta.eval for statements or the new Meta.compileExpression for expressions. Extend Meta.compile_ foreign method with isExpression and printErrors parameters, update wrenCompile signature to support expression compilation mode, and add newline handling after equals in variable definitions.
2016-05-21 06:03:05 +00:00
Bob Nystrom
19fc5e7534 feat: always wrap functions in closures to simplify VM and improve invocation performance
Simplify the VM by ensuring all called objects are closures, removing the need for runtime checks between bare functions and closures. This eliminates the `IS_FN`/`IS_CLOSURE` branching in `validateFn`, `checkArity`, `bindMethod`, and `wrenNewFiber`, and changes `CallFrame.fn` from `Obj*` to `ObjClosure*`. The compiler now emits `CODE_CLOSURE` for all function declarations, even those without upvalues, trading a small allocation cost at declaration time for faster and more uniform invocation. Benchmarks show performance is neutral to slightly improved across all tested workloads.
2016-03-26 21:00:17 +00:00
Bob Nystrom
82103a64f9 refactor: replace eager optional module loading with lazy source and foreign method hooks 2016-03-17 14:49:43 +00:00
Bob Nystrom
6abebbe906 feat: expose wrenEnsureSlots API and rename foreignStackStart to apiStack for slot access outside foreign methods
Replace the internal `foreignStackStart` pointer with a public `apiStack` field
that tracks the base of available C API slots. Extract the static
`ensureStack` helper into a non-static `wrenEnsureStack` function declared in
the header, enabling `wrenEnsureSlots()` to create a fiber and stack when
called outside a foreign method. Update `callForeign` to use `apiStack` and
adjust `metaCompile` to write results through the new pointer. Add a
`ensureOutsideForeign` test that allocates slots on a fresh VM, verifies
slot count grows from 0 to 20, and exercises all 20 slots with double values
to confirm the stack is correctly initialized and usable.
2015-12-28 15:43:17 +00:00
Bob Nystrom
7535fed608 refactor: replace wrenReturn___() with wrenSetSlot___() for writing values to arbitrary slots
The old wrenReturn___() functions only wrote to slot 0 for return values. The new wrenSetSlot___() functions allow writing to any slot index, making them general-purpose for manipulating the foreign call stack. This change updates all call sites, removes the dedicated returns test suite in favor of slots tests, and adjusts the VM internals to treat slot 0 as the return position rather than using a separate return mechanism.
2015-12-16 21:00:13 +00:00
Bob Nystrom
234a98faef refactor: rename wrenGetArgument* to wrenGetSlot* and add IS_LIST macro for slot-based API
Migrate the foreign method argument access API from an argument-oriented naming
scheme to a slot-based one, renaming wrenGetArgumentCount to wrenGetSlotCount,
wrenGetArgumentBool to wrenGetSlotBool, and all other argument accessors
accordingly. Update every call site across the VM, modules (io, timer, meta,
random), and test files (benchmark, foreign_class) to use the new names. The
slot getters now assert the correct type at runtime rather than silently
returning defaults, shifting safety responsibility to the caller for
performance. Also add the IS_LIST type-checking macro to wren_value.h alongside
the existing IS_* macros.
2015-12-16 18:22:42 +00:00
Bob Nystrom
e929c7c997 refactor: remove foreignCallNumArgs and rename foreignCallSlot to foreignStackStart
The number of arguments can be derived from the stack pointer difference, eliminating the need to store it separately. Rename the slot pointer to better reflect its purpose as the start of the foreign call's stack region.
2015-12-16 01:10:02 +00:00
Bob Nystrom
c9a7dba0c1 chore: rename auxiliary modules to optional and update all references
Rename the `src/aux/` directory to `src/optional/`, update all include guards, preprocessor defines, and file references from `WREN_AUX_*` to `WREN_OPT_*`, and adjust build system, Xcode project, and code generation scripts accordingly.
2015-10-24 16:23:25 +00:00