Commit Graph

18 Commits

Author SHA1 Message Date
Bob Nystrom
26ae448adf feat: generate runtime error when foreign method is not found
Change bindMethod return type from void to Value to propagate error string when a foreign method's C function pointer is NULL. The call site in runInterpreter now checks for a string error and triggers a runtime error, preventing silent failures on missing foreign bindings.

Add three test cases: foreign method after static declaration, foreign method with a body, and unknown foreign method that expects the new runtime error message.
2015-03-26 14:17:09 +00:00
Bob Nystrom
83e062cc71 feat: add foreign method binding for Meta class and restrict foreign lookup to core module
Add foreign static eval(source) method to Meta class in meta.wren and implement wrenBindMetaForeignMethod in wren_meta.c to handle its binding. Change the implicit module name from "main" to "core" in wren_vm.c and restrict foreign method lookup to only the "core" module, enabling Meta foreign methods to be resolved alongside IO methods. Relax the IO foreign method binder to return NULL instead of asserting for non-IO classes, allowing fallback to other library binders.
2015-03-26 03:20:26 +00:00
Bob Nystrom
2b3381e0b2 feat: add Meta class with eval method and integrate into VM and build system 2015-03-26 03:06:55 +00:00
Bob Nystrom
a737b542b9 feat: add Meta class with eval method and WREN_USE_LIB_META flag
Introduce a new Meta built-in class exposing a static eval(_) method for runtime code interpretation, guarded by the WREN_USE_LIB_META compile-time flag (default on). Include the meta.wren source, C implementation files, header, VM integration in wrenNewVM, test runner update to include the meta test directory, and an initial test for evaluating code that modifies an existing scoped variable.
2015-03-26 02:21:58 +00:00
Bob Nystrom
90de831bd7 refactor: remove oldSize parameter from WrenReallocateFn and all call sites
Simplify the allocation API by dropping the unused `oldSize` argument from `WrenReallocateFn` typedef, its documentation, and all internal callers. Update `wrenReallocate` in `wren_vm.c` to pass only `newSize`, remove the `defaultReallocate` wrapper in favor of direct `realloc`, and adjust `generate_baseline` signature in benchmark script to match.
2015-03-25 14:45:29 +00:00
Bob Nystrom
a350d7c26a feat: add foreign method binding infrastructure with IO library integration
Implement the `WrenBindForeignMethodFn` callback type and `bindForeignMethodFn` configuration field to allow host applications to resolve foreign method declarations at class definition time. Refactor the IO library to use this new binding mechanism instead of the previous `wrenDefineStaticMethod` approach, adding `foreign` keyword support to the lexer and compiler. Introduce `freeCompiler` helper for cleanup, store module names in `ObjModule`, and update the VM to call the binder when processing `CODE_METHOD_INSTANCE` and `CODE_METHOD_STATIC` opcodes for foreign methods.
2015-03-24 14:58:15 +00:00
Bob Nystrom
46b6763877 refactor: rename Upvalue to ObjUpvalue for consistency with Obj naming convention
Rename the `Upvalue` struct and all related type references to `ObjUpvalue` across
wren_value.c, wren_value.h, and wren_vm.c. This aligns with the existing pattern
where Obj-derived types (like ObjModule, ObjClosure) use the Obj prefix even when
the type is not first-class in the language. The change touches function signatures,
variable declarations, pointer arithmetic in memory tracking, and the struct
definition itself.
2015-03-23 05:31:03 +00:00
Bob Nystrom
15f9273aab refactor: remove unused WrenVM* parameter from buffer init, string find, and debug print functions
Remove the `WrenVM* vm` parameter from `wrenValueBufferInit`, `wrenByteBufferInit`,
`wrenIntBufferInit`, `wrenStringBufferInit`, `wrenSymbolTableInit`,
`wrenMethodBufferInit`, `wrenStringFind`, and `wrenDebugPrintStackTrace`
functions across the compiler, core, debug, utils, value, and VM modules.
Update all call sites and macro definitions to match the simplified signatures,
eliminating dead parameters that were never used within the function bodies.
2015-03-23 05:17:40 +00:00
Bob Nystrom
7385ab2430 chore: enable -Wextra warnings and fix loadIntoCore declaration order 2015-03-23 04:49:31 +00:00
Gavin Schulz
c8fa7e619f feat: add Meta library with eval function for inline code interpretation 2015-03-22 21:16:53 +00:00
Bob Nystrom
899a4ec76e chore: enable clang suspicious implicit conversion warning and fix related type narrowing issues
Add CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES to both Debug and Release Xcode build configurations. Fix the resulting warnings by adding explicit casts in wren_compiler.c (readUnicodeEscape, emit, emitShort, emitByteArg) and wren_vm.c (READ_SHORT macro, makeCallStub bytecode assignment) to prevent unintended truncation or sign extension during implicit integer conversions.
2015-03-22 17:36:08 +00:00
Bob Nystrom
295a408858 refactor: extract instance-of check into separate isInstanceOf helper function 2015-03-21 23:50:27 +00:00
Bob Nystrom
28fdc8372f fix: replace silent early return with assertion in wrenFreeVM for freed VM detection 2015-03-20 15:00:52 +00:00
Peter Reijnders
0ddef2c17f chore: enable -Wextra compiler flag and suppress unused-parameter warnings
Enable the -Wextra compiler flag in the wren.mk build configuration, which was previously commented out with a TODO. To handle the new unused parameter warnings triggered by -Wextra (particularly for WrenVM* vm parameters in several functions), add -Wno-unused-parameter to suppress them. Also fix a declaration ordering issue in wren_vm.c where the 'static' keyword was placed after the return type in loadIntoCore, moving it to the correct position before the type specifier.
2015-02-28 12:52:48 +00:00
Bob Nystrom
9314cbfd72 refactor: replace manual string concatenation with wrenStringFormat across VM core
Replace ad-hoc string construction using wrenNewString, wrenStringConcat, and sprintf with the new wrenStringFormat helper. This centralizes string formatting logic, reduces code duplication, and eliminates manual length calculations in wren_compiler.c, wren_core.c, wren_value.c, and wren_vm.c. Also introduces CONST_STRING macro for compile-time string literals and changes wrenNewUninitializedString return type from Value to ObjString* for consistency.
2015-03-16 05:32:20 +00:00
Bob Nystrom
d731e554e6 refactor: rename debug print functions to dump and move value printing to wren_debug.c 2015-03-15 17:09:43 +00:00
Bob Nystrom
18cf57d5f5 refactor: split source tree into vm/ and cli/ directories with updated build system
Separate Wren VM library sources from CLI tool sources by moving them into
src/vm/ and src/cli/ subdirectories respectively. Update the Makefile to use
separate wildcard patterns for each directory, generate distinct object file
paths under build/vm/ and build/cli/, and adjust include paths to src/include.
Also update the Xcode project file to reference the new file locations.
2015-03-14 22:00:50 +00:00
Peter Reijnders
21e387efec fix: add null and already-freed guard to wrenFreeVM to prevent double-free crash
The guard checks if the VM pointer is NULL or if its methodNames count is zero,
which serves as a heuristic to detect an already-freed VM instance. This prevents
a segmentation fault or memory corruption when wrenFreeVM is called multiple times
on the same VM object.
2015-02-28 12:29:17 +00:00