Commit Graph
100 Commits
Author SHA1 Message Date
Bob Nystrom 38462ba4ed feat: add ctrl-b/f/k/l/u/n/p shortcuts to repl line editor
Implement cursor movement (ctrl-b left, ctrl-f right), line clearing (ctrl-k kill after cursor, ctrl-u clear entire line, ctrl-l clear screen), and history navigation (ctrl-n next, ctrl-p previous) in the repl module, along with updated TODO comments for future shortcuts.
2016-05-21 17:33:36 +00:00
Bob Nystrom 5207686395 feat: add command history with up/down arrow navigation to REPL
Implement a history buffer in the REPL class that stores previously entered commands and allows cycling through them using the up and down arrow keys. The `_history` list and `_historyIndex` track the current position, with `previousHistory()` and `nextHistory()` methods restoring lines from the buffer or clearing the input when reaching the end. The `executeInput()` method now appends the current line to history before resetting, and the Ctrl-D exit condition is fixed to check `_line.isEmpty` instead of `_line == ""`.
2016-05-21 17:05:28 +00:00
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 33c211f7c2 feat: implement interactive REPL with line editing and syntax highlighting in Wren
Replace the simple fgets-based REPL loop with a full-featured interactive Wren REPL module. The new implementation supports cursor movement via arrow keys, Ctrl-A/E for line start/end, Ctrl-C/D for exit/delete, character insertion/deletion, and syntax highlighting of the current input line. The C side now imports the "repl" Wren module and runs the libuv event loop instead of blocking on stdin reads.
2016-05-21 03:30:09 +00:00
Bob Nystrom 1de17224e8 feat: add wrenAbortFiber() API to abort current fiber with runtime error object
Add a new public API function `wrenAbortFiber()` that allows foreign methods to abort the currently executing fiber with a custom runtime error object. The function validates the API slot, then sets the fiber's error field to the value in the specified slot. The interpreter loop is updated to check for a non-null fiber error after calling a foreign method, triggering a runtime error if set. New test files (error.c, error.h, error.wren) demonstrate usage via a static Error.runtimeError foreign method, verifying that the error is propagated through Fiber.try() and that the fiber's isDone and error properties are correctly set. Xcode project updated to include the new error.c source file.
2016-06-10 02:14:21 +00:00
Bob Nystrom 78fa150869 fix: correct broken range documentation link to point to values section 2016-05-27 14:23:41 +00:00
Bob Nystrom b845ff49c9 docs: fix relative link to iterator protocol in string.markdown
The link to the iterator protocol section in control-flow.html was incorrectly
pointing to `../control-flow.html` instead of `../../control-flow.html`, which
is the correct relative path from the `doc/site/modules/core/` directory.
2016-05-27 14:23:07 +00:00
Bob Nystrom 7768d1c9cd feat: add Platform.isWindows static method to check for Windows OS
Add a new `isWindows` static method to the `Platform` class that returns `true` when the host operating system name equals "Windows". This provides a less stringly-typed API compared to checking `Platform.name` directly. The implementation is a simple delegation to the existing `name` foreign method, comparing it against the "Windows" string. Includes a test that verifies `Platform.isWindows` is equivalent to `Platform.name == "Windows"`.
2016-05-21 19:53:21 +00:00
Bob Nystrom 67bf74777c feat: add Stdin.isTerminal method to detect TTY connection
Add a new `isTerminal` static method to the Stdin class that returns `true` when
stdin is connected to a TTY (interactive terminal) and `false` when input comes
from a pipe. Implementation uses libuv's `uv_guess_handle` to check the stdin
descriptor. Includes documentation, foreign method declaration, module
registration, and a test expecting `false` since tests run non-interactively.
2016-05-21 19:51:11 +00:00
Bob Nystrom 95ef1a2814 feat: rename process module to os and add Platform class with name and isPosix methods
Rename the "process" module to "os" across all source files, documentation, tests, and build configuration. Add a new Platform class to the os module with static methods `name` (returns OS string like "Windows", "Linux", "OS X", "iOS", "Unix", "POSIX", or "Unknown") and `isPosix` (returns bool indicating POSIX compliance). Update all import paths from "process" to "os" in test files and module registrations. Move process.c/h to os.c/h, rename processSetArguments to osSetArguments, and regenerate the os.wren.inc bytecode source. Add documentation pages for the os module and Platform class.
2016-05-21 19:44:17 +00:00
Bob Nystrom c5e1c2e57f feat: add versioning infrastructure and bump to 0.1.0
Define WREN_VERSION_MAJOR, WREN_VERSION_MINOR, WREN_VERSION_PATCH macros,
WREN_VERSION_STRING "0.1.0", and WREN_VERSION_NUMBER for monotonic checks.
Update REPL banner to use WREN_VERSION_STRING instead of hardcoded "v0.0.0".
Create CHANGELOG.md documenting the first declared version.
2016-05-21 17:53:05 +00:00
Bob Nystrom caee692c32 docs: rename WrenValue to WrenHandle across embedding docs and C API
Rename the `WrenValue` type to `WrenHandle` in the public C header, update all
function signatures (`wrenMakeCallHandle`, `wrenCall`, `wrenReleaseHandle`),
and rename the documentation page from "Slots and Values" to "Slots and Handles"
with corresponding link updates throughout the embedding guide and module source
files.
2016-05-21 03:55:28 +00:00
Bob Nystrom efa97cdccf feat: add Stdin.isRaw property to query and set terminal raw mode on stdin
Add foreign static getter `isRaw` and setter `isRaw=(value)` to the Stdin class, backed by a new `isStdinRaw` boolean flag and `uv_tty_set_mode` calls. The getter returns the current raw mode state, while the setter initializes the stdin stream if needed and applies raw or normal mode only when stdin is a TTY. Also includes a test file verifying default false, reading bytes in normal mode, enabling raw mode, and reading subsequent bytes.
2016-05-20 22:19:18 +00:00
Bob Nystrom 6394e1c486 feat: add Stdin.readByte() method for reading single byte from stdin
Implement a new `readByte()` static method on the `Stdin` class that reads one byte from standard input, blocking the current fiber until a byte is received. The method returns the byte value as a number or `null` if stdin is closed.

Refactor the internal buffering mechanism by introducing a shared `read_()` helper method that both `readByte()` and `readLine()` use, replacing the previous per-method buffering logic. The `readByte()` implementation peels off the first byte from the internal `__buffered` string using `bytes[0]` and slicing.

Add two test files: `read_byte.wren` verifying byte-by-byte reading of "first" and "second" input lines, and `read_byte_eof.wren` confirming that reading after stdin is closed returns the expected error message.
2016-05-20 18:50:14 +00:00
Bob Nystrom bdc8e1f409 docs: add subreddit link and wiki reference to contributing guide 2016-05-20 17:02:57 +00:00
Bob Nystrom e8d17172f4 docs: add comprehensive guide for calling Wren from C with wrenCall API
Replace placeholder TODO with full documentation covering method invocation via wrenCall(), including method signature lookup, receiver specification, and argument passing mechanics.
2016-05-19 23:01:54 +00:00
Bob Nystrom ad05bb2cde fix: apply white-space pre-wrap to pre blocks for Firefox line wrapping
The overflow:auto on pre elements caused horizontal scrollbars in Firefox
when code lines exceeded container width. Adding white-space:pre-wrap
enables natural line wrapping while preserving whitespace formatting,
eliminating the need for horizontal scrolling in narrow viewports.
2016-05-19 16:30:38 +00:00
Bob Nystrom 2bb999127a docs: restructure embedding API docs into multi-page section with slots, lifecycle, and C interop guides 2016-05-16 15:09:14 +00:00
Bob Nystrom 27f308a6ad fix: correct word order in error-handling documentation sentence
The phrase "most two common" was inverted to "two most common" in the
error-handling.markdown documentation file to fix a grammatical error
in the description of runtime error types.
2016-05-04 20:29:59 +00:00
Bob Nystrom d717f0f174 fix: count subscript parameters in wrenMakeCallHandle for bracket signatures
Add missing loop to count underscore parameters in subscript operator signatures
starting with '['. Previously only counted parameters in parenthesized signatures,
causing incorrect arity for methods like `[_,_]` and `[_,_]=(_)`. Also adds
validation assertions for null and empty signatures, and extends test coverage
with unary, binary, subscript, and subscript-set operator call handles.
2016-05-04 13:29:44 +00:00
Bob Nystrom 1c08148cc8 fix: correct typo and clarify gc heapGrowthPercentage documentation in wren.h 2016-05-03 19:27:16 +00:00
Bob Nystrom 34b0ab4e6c fix: correct typo "intpolations" to "interpolations" in values documentation
Fix a spelling error in the doc/site/values.markdown file where the word
"intpolations" was missing the letter 'e' in the section describing nested
string interpolation within interpolated expressions.
2016-05-03 19:26:39 +00:00
Bob Nystrom 143aaaf519 fix: correct spelling of "executable" in src/README.md documentation
Fix the typo "exectuable" to "executable" in the project structure description within the src/README.md file, specifically in the section documenting the cli directory's purpose.
2016-05-03 17:19:10 +00:00
Bob Nystrom c608f094ab docs: fix grammatical inversion in getting-started doc
Corrected "You can is use as a static" to "You can use it as a static"
in the virtual machine description paragraph of the getting-started
markdown file.
2016-05-03 04:54:42 +00:00
Bob Nystrom bd055a356b fix: correct argument order in list.insert example in method-calls docs
The example call `list.insert("item", 3)` was swapped to match the actual API signature where the index comes first, changing it to `list.insert(3, "item")` in the doc/site/method-calls.markdown file.
2016-05-02 23:23:56 +00:00
Bob Nystrom 07613f4eb0 style: align pointer asterisk to type name in MapEntry declarations across wren_value.c 2016-05-02 23:23:52 +00:00
Bob Nystrom 112bb5ca7c fix: correct C++ standardization year from 89 to 98 in embedding-api docs 2016-05-02 23:23:08 +00:00
Bob Nystrom 9bfdb6acd8 fix: correct argument order in list.insert example in method-calls documentation
The example code snippet for method call syntax previously showed `list.insert("item", 3)` which incorrectly placed the value before the index. Updated to `list.insert(3, "item")` to match Wren's actual List.insert method signature where the index parameter comes first.
2016-04-15 14:13:54 +00:00
Bob Nystrom 06748ba454 test: add test verifying closures of same code are unequal
Add a test case to equality.wren that creates two closures from the same
function literal inside a loop and asserts they are not equal, confirming
that each closure invocation produces a distinct object.
2016-03-26 21:22:38 +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 7e72462d90 feat: add WrenErrorType enum and route runtime errors through config errorFn callback
Replace direct fprintf(stderr) calls in wrenDebugPrintStackTrace with invocations of the host-provided errorFn callback, passing WREN_ERROR_RUNTIME for the error message and WREN_ERROR_STACK_TRACE for each stack frame. Introduce the WrenErrorType enum in wren.h with WREN_ERROR_COMPILE, WREN_ERROR_RUNTIME, and WREN_ERROR_STACK_TRACE values, update the WrenErrorFn typedef to accept a type parameter, and modify reportError in cli/vm.c to switch on the error type for formatted output. Adjust wrenDebugPrintStackTrace signature to take WrenVM* instead of ObjFiber* to access the config, and update all call sites accordingly.
2016-03-17 14:17:03 +00:00
Bob Nystrom 63e462bb84 chore: remove unused stdarg.h, stdio.h, and stdlib.h includes from wren_compiler.c and wren_value.c 2016-03-17 14:04:09 +00:00
Bob Nystrom d9ec3627cf feat: add WrenErrorFn callback to WrenConfiguration for custom error reporting
- Add `WrenErrorFn` typedef in wren.h accepting module, line, and message parameters
- Include `errorFn` slot in `WrenConfiguration` struct with documentation comment
- Initialize `errorFn` to NULL in `wrenInitConfiguration()` in wren_vm.c
- Replace direct `fprintf(stderr, ...)` in wren_compiler.c with call to `parser->vm->config.errorFn()`
- Add guard in wren_compiler.c to skip error reporting when `errorFn` is NULL
- Implement `reportError()` in cli/vm.c that writes formatted errors to stderr
- Wire `reportError` into config during `initVM()` in cli/vm.c
2016-03-16 15:04:03 +00:00
Bob Nystrom f16e5c775f feat: report undefined variable errors on the line where they are used
Store the line number of first use in implicitly declared variables as a numeric value, then synthesize a token at that line when reporting the error, ensuring bounded error message length even for pathologically long variable names.
2016-03-16 15:00:28 +00:00
Bob Nystrom 8fb291517d chore: add explanatory comments for Windows platform flag mappings and remove O_SYNC guard
Add inline comments clarifying the purpose of Windows-specific permission and mode flag
definitions in the platform compatibility block. Also remove the conditional `#ifdef O_SYNC`
guard around the O_SYNC flag assignment in `mapFileFlags`, since O_SYNC is now always
defined (as 0) on Windows.
2016-03-16 14:27:03 +00:00
Bob Nystrom 5ce4698605 feat: add Windows platform compatibility defines for file operations in io.c
Add conditional preprocessor definitions for Windows builds (WIN32/WIN64) to handle
platform-specific differences in file mode constants (S_IRUSR, S_IWUSR), sync flag
(O_SYNC), and stat macros (S_ISREG, S_ISDIR). Also fix a minor typo in the comment
describing file flag mapping logic.
2016-03-16 14:23:24 +00:00
Bob Nystrom f09b4f75d9 style: fix indentation and add comment for libuv library linking in wren.mk 2016-03-16 14:22:18 +00:00
Bob Nystrom 5d42ce9ad6 refactor: extract duplicate method detection into declareMethod helper and rename instanceMethods buffer to methods 2016-03-15 14:15:55 +00:00
Bob Nystrom 1d546cf840 feat: prevent duplicate method definitions in class compilation
Add tracking of static and instance method names during class compilation to detect and report duplicate method definitions. Introduce `hasMethod` helper function and `staticMethods`/`instanceMethods` buffers in the `ClassCompiler` struct, along with a `name` field for identification. Include a new test case `duplicate_methods.wren` verifying error generation for duplicate instance and static methods, while allowing same-named methods across static/instance boundaries.
2016-03-15 13:54:49 +00:00
Bob Nystrom c33dc205c3 chore: remove unused DUP opcode from compiler, debug, opcodes, and VM interpreter 2016-03-14 05:11:21 +00:00
Bob Nystrom c30ee8a297 refactor: consolidate compile error formatting into single printError helper
Replace multiple fprintf calls in lexError and compileError with a unified printError function that formats the entire error message into a fixed-size buffer before outputting it as a single fprintf call. This centralizes error formatting logic and prepares for future integration of a host-provided error callback by eliminating scattered fprintf invocations.
2016-03-12 05:30:54 +00:00
Bob Nystrom 51d1bb6b3a refactor: move shebang detection into default case and remove separate '#' branch 2016-03-12 01:23:31 +00:00
Bob Nystrom 78c4969cc4 feat: add Python 3 compatibility and formatted output to metrics script
Add `from __future__ import print_function` import for Python 2/3 compatibility and introduce `C_FORMAT_LINE` and `WREN_FORMAT_LINE` format strings to produce aligned columnar output for C source and Wren test file metrics respectively, replacing the previous unstructured print statements.
2016-03-07 15:56:44 +00:00
Bob Nystrom d9f608fa3f fix: correct variable naming and constructor syntax in FAQ code examples
- Rename `acc` to `account` in Lua and Wren examples for consistency
- Fix Wren constructor syntax from `this new` to `construct new`
- Remove hyphen from "one-byte" to match standard phrasing
2016-03-07 15:41:00 +00:00
Bob Nystrom 0f18db0097 refactor: move compiler function state directly into ObjFn to eliminate copying on completion 2016-03-04 15:49:34 +00:00
Bob Nystrom 53f4cb15c9 fix: remove wrenSetCompiler and fix compiler root not being popped on error 2016-03-04 01:48:47 +00:00
Bob Nystrom d4df37703d refactor: replace manual error assignment with RETURN_ERROR and RETURN_ERROR_FMT macros across validation and fiber functions
Consolidate repetitive `vm->fiber->error = wrenStringFormat(...)` and `return false` patterns into two new macros defined in wren_primitive.h, reducing code duplication and improving consistency in error reporting for fiber operations, number parsing, and type validation helpers.
2016-03-04 01:11:52 +00:00
Bob Nystrom db5223d14d feat: unify Fiber.try() error messages with call/transfer by adding verb parameter to runFiber
Add a `verb` string parameter to the `runFiber` helper function so that
`Fiber.try()` produces consistent error messages like "Cannot try a finished
fiber." instead of the previous generic fallback. Update all call sites
(`fiber_call`, `fiber_call1`, `fiber_transfer`, `fiber_transfer1`) to pass
the appropriate verb string, and add a new test case `try_error.wren`
verifying the error message for trying an aborted fiber.
2016-03-04 01:00:33 +00:00
Bob Nystrom 1ef9b77842 refactor: rename allowAssignment to canAssign and simplify parsePrecedence signature in wren_compiler.c 2016-03-04 00:30:48 +00:00
Bob Nystrom b2469990c0 test: add test for creating a VM with null config and fix wrenNewVM to handle NULL config 2016-03-03 22:31:47 +00:00
Bob Nystrom 443749b55d fix: correct typo 'wrenUpwrapClosure' to 'wrenUnwrapClosure' across multiple files
Fix the misspelled function name `wrenUpwrapClosure` to the correct `wrenUnwrapClosure` in wren_debug.c, wren_value.c, wren_value.h, and wren_vm.c. Also fix a minor grammar typo in wren_vm.c comment changing 'arguments' to 'argument'.
2016-02-28 00:23:48 +00:00
Bob Nystrom 06dad18184 docs: fix grammar and formatting in Wren VM comments and code 2016-02-28 00:05:50 +00:00
Bob Nystrom bbafbfd50a feat: add File.realPath() to resolve symlinks and normalize paths
Implement a new static method `File.realPath(path)` that resolves the given path by traversing symlinks and removing redundant `./` and `../` components, returning the canonical absolute path. The implementation uses libuv's `uv_fs_realpath` via an asynchronous callback pattern consistent with other File operations. Includes documentation, foreign method declarations, and two error-case tests for nonexistent paths and wrong argument types.
2016-02-27 23:53:02 +00:00
Bob Nystrom 7265935df4 fix: correct operator precedence table in syntax docs to match actual implementation
The precedence table in doc/site/syntax.markdown had several operators listed at wrong priority levels. This commit reorders the table so that comparison operators (<, <=, >, >=) are at level 10, equality operators (==, !=) at level 12, and bitwise operators (&, ^, |) at levels 7-9, aligning with the true precedence hierarchy.
2016-02-27 18:14:09 +00:00
Bob Nystrom 030d8df612 chore: bump libuv version from v1.6.1 to v1.8.0 in util/libuv.py
Update the LIB_UV_VERSION constant in the build dependency script to point to the
newer v1.8.0 release tag, which includes bug fixes and performance improvements
for the event loop backend.
2016-02-27 17:19:56 +00:00
Bob Nystrom 0fde331974 refactor: replace import opcodes with core method calls for module loading
Remove CODE_LOAD_MODULE and CODE_IMPORT_VARIABLE opcodes, replacing them with calls to System.importModule(_) and System.getModuleVariable(_,_) primitives. This simplifies the interpreter loop, improves performance by reducing bytecode dispatch, and prepares for moving module loading logic into Wren source code for embedder flexibility.
2016-02-27 06:43:54 +00:00
Bob Nystrom aca69b34e6 refactor: merge block() into statement() and remove redundant curly-block parsing
The block() function duplicated the curly-block parsing logic that statement() already handled for single-expression bodies. By removing block() and replacing its single call site in loopBody() with statement(), the compiler eliminates unnecessary indirection and simplifies the control flow parsing. The statement() comment is updated to clarify that it excludes variable binding statements like "var" and "class" which are not allowed in if-branch positions.
2016-02-25 15:04:48 +00:00
Bob Nystrom b301e9f119 feat: implement eager * operator for String and List to repeat content by integer count
Add `*(count)` method to both String and List classes in wren_core.wren, enabling eager repetition of string characters or list elements. The operator validates that count is a non-negative integer, aborting with a clear error message otherwise. For strings, concatenates the original string count times; for lists, builds a new list by adding all elements count times. Includes comprehensive test cases for normal, zero, and edge-case inputs, plus error tests for negative, non-integer, and non-numeric counts. Also refactors existing list plus tests to use inline expressions and adds a plus_not_iterable error test.
2016-02-24 15:48:03 +00:00
Bob Nystrom c9390c624b fix: add missing code block marker in list docs and simplify parens increment in compiler
- Add missing `:::wren` code block marker before the `removeAt` example in the list documentation to ensure proper syntax highlighting.
- Simplify the `parens` array increment in `readString` by combining the assignment and post-increment into a single expression.
2016-02-24 14:52:12 +00:00
Bob Nystrom 217763a51d fix: correct map doc to remove nonexistent iterate/iteratorValue and fix remove param formatting
- Remove erroneous iterate() and iteratorValue() method docs from map.markdown
  since Map does not expose those methods directly
- Fix remove(key) parameter formatting from [key] to `key` for consistency
- Correct File.read encoding description from "The encoding or decoding is done"
  to "No encoding or decoding is done" to accurately reflect behavior
2016-02-22 15:48:53 +00:00
Bob Nystrom 1973934fa2 feat: add Stat.isFile, Stat.isDirectory, File.exists, and Directory.exists methods
Add four new file system checking functions: Stat.isFile and Stat.isDirectory for querying entry type from a Stat object, and File.exists and Directory.exists static methods that return booleans by attempting to stat the path and checking the appropriate type. Also bump MAX_METHODS_PER_CLASS from 12 to 14 to accommodate the new Stat foreign methods, and clean up unused Scheduler imports in existing stat tests.
2016-02-21 20:23:33 +00:00
Bob Nystrom 7f744565fc feat: convert Stat from Wren class with list fields to foreign class with native C accessors
Replace the Wren-implemented Stat class that stored stat fields in a list with a foreign class backed by the raw uv_fs_stat struct, enabling direct C-level access to stat data for future methods like isDirectory() using S_ISDIR().
2016-02-21 19:34:10 +00:00
Bob Nystrom 42ba73b03b feat: add stat instance method to File class returning Stat object
Implement `File.stat` method that performs an asynchronous `fstat` call on the open file descriptor, returning a `Stat` object populated with file metadata (device, inode, mode, link count, user, group, size, block size, block count). Refactor the existing `statPathCallback` into a generic `statCallback` shared by both `statPath` and the new `fileStat` function. Bump `MAX_METHODS_PER_CLASS` from 11 to 12 to accommodate the new foreign method slot. Add comprehensive test coverage including successful stat retrieval and error handling when called on a closed file.
2016-02-21 18:18:45 +00:00
Bob Nystrom e87cd41c32 fix: replace hardcoded OS-specific file flags with portable bitmask mapping in io.c and io.wren 2016-02-21 01:25:41 +00:00
Bob Nystrom d53f9fa477 fix: include stdio.h for printf usage under debug trace flags in wren_vm.c 2016-02-20 21:36:22 +00:00
Bob Nystrom 60fc3ff59c feat: add file create, delete, writeBytes and FileFlags class to IO module
Implement File.create() and File.delete() static methods with async libuv operations, add writeBytes() instance method for writing at offsets, introduce FileFlags constants class mirroring POSIX open() flags, refactor File.open() to accept flag parameters via openWithFlags(), and update documentation and module registration accordingly.
2016-02-20 17:23:42 +00:00
Bob Nystrom 38f48fbce1 feat: add separate make targets for shared and static library builds
Introduce `shared` and `static` make targets to allow building only the shared library (`libwren.so`/`.dylib`) or only the static library (`libwren.a`), respectively. The existing `vm` target now depends on both new targets, preserving backward compatibility while enabling selective builds. This addresses issue #322 by providing finer-grained build control.
2016-02-19 15:22:10 +00:00
Bob Nystrom fe3997f825 feat: add wrenGetSlotType API to query low-level type of object in a slot
Introduce a new public C API function wrenGetSlotType() that returns the
underlying representation type (bool, num, foreign, list, null, string,
or unknown) of the object stored in a given VM slot. This allows C
extensions to inspect slot contents without needing to call individual
type-checking functions or handle errors from mismatched accessors.

The implementation in wren_vm.c uses the existing IS_* macros to
determine the type and returns the corresponding WrenType enum value.
A new WrenType enum is added to wren.h with WREN_TYPE_BOOL,
WREN_TYPE_NUM, WREN_TYPE_FOREIGN, WREN_TYPE_LIST, WREN_TYPE_NULL,
WREN_TYPE_STRING, and WREN_TYPE_UNKNOWN.

Test coverage is added in test/api/slots.c with a slotTypes() foreign
method that verifies all seven type values, and a ForeignType foreign
class is introduced in slots.wren to provide a foreign object for
testing WREN_TYPE_FOREIGN. The test harness in main.c is updated to
support binding foreign class allocate methods via slotsBindClass().
2016-02-19 15:18:00 +00:00
Bob Nystrom 5d04ed2aed fix: add overflow check for jump distance in patchJump and emit error on too much code
Add a MAX_JUMP constant set to 2^16 and validate jump distance in patchJump to prevent silent overflow when bytecode exceeds the maximum representable offset. Also remove the TODO comment in endLoop since the forward jump error will be caught by patchJump. Include test cases jump_too_far.wren and loop_too_far.wren to verify the compiler correctly reports "Too much code to jump over." for both conditional and loop constructs.
2016-02-19 14:57:38 +00:00
Bob Nystrom b1924d34d3 fix: skip skynet example in tests to prevent timeout on slow CI runners
Add early return for "skynet" path in run_example function to avoid
executing the skynet example during test runs, as it is too slow and
causes timeouts on Travis CI bots. Also reduce the kill timer from 5
to 2 seconds in the Test class to fail faster on hanging processes.
2016-02-15 06:28:14 +00:00
Bob Nystrom f3c68323bd fix: increase test timeout from 2 to 5 seconds and add skynet fiber benchmark example
The test runner's per-test timeout was raised to 5 seconds to prevent flaky
timeouts on slower systems. A new example file (example/skynet.wren) was added
demonstrating a million-fiber microbenchmark based on the skynet algorithm,
showcasing Wren's fiber concurrency model. Additionally, the shuffle test's
tolerance threshold was relaxed from 0.2 to 0.21 to reduce false positives
in the random distribution check.
2016-02-15 06:21:50 +00:00
Bob Nystrom dff44de30b fix: add explicit constructor to Foo class and fix abs example syntax in docs
- Add explicit `construct new() {}` to Foo class in error-handling doc to clarify method dispatch behavior
- Fix `(-123).abs` syntax in num.markdown to use parentheses for unary minus precedence
2016-02-15 06:18:53 +00:00
Bob Nystrom f33d85ca05 fix: correct two code samples in error-handling and num documentation
- Add missing construct new() {} to Foo class in error-handling.markdown
- Fix operator precedence for (-123).abs in num.markdown
2016-02-12 18:35:40 +00:00
Bob Nystrom cdf3b64ab2 refactor: replace classSlot int with Variable struct in defineMethod and method
Replace the integer `classSlot` parameter with a `Variable` struct in both `defineMethod()` and `method()` functions, removing duplicate code that handled top-level vs local class loading by delegating to the new `loadVariable()` helper.
2016-02-12 15:43:44 +00:00
Bob Nystrom 6367195722 perf: replace strncmp with memcmp in variable declaration and resolution
In both declareVariable and resolveLocal functions within wren_compiler.c,
the string comparison using strncmp is replaced with memcmp since the
length parameter is already known and null-termination checking is
unnecessary for these fixed-length identifier comparisons. This avoids
the overhead of scanning for null terminators when comparing local
variable names against token or parameter strings.
2016-02-12 15:27:42 +00:00
Bob Nystrom 18bedf45e1 feat: introduce Variable struct to replace raw index and load instruction pair
Replace the ad-hoc output parameter pattern in resolveNonmodule with a proper Variable struct that bundles the variable's index and scope (local, upvalue, or module). This makes variable references a first-class concept in the compiler, eliminating the need to pass around a separate Code pointer for load instructions and improving code clarity throughout the compilation pipeline.
2016-02-12 15:16:41 +00:00
Bob Nystrom c1bbd74416 docs: simplify wrenInterpret example by removing source path parameter 2016-02-09 15:24:55 +00:00
Bob Nystrom 19d7215412 feat: add sample(list) and sample(list, count) methods to Random class with two sampling algorithms 2016-02-09 15:24:45 +00:00
Bob Nystrom edf3717eb0 docs: remove source path parameter from wrenInterpret example in embedding-api docs 2016-02-09 01:43:05 +00:00
Bob Nystrom 813594b14c feat: add Random.shuffle() method using Fisher-Yates algorithm
Implement in-place shuffle for lists on the Random class, using the Fisher-Yates algorithm to ensure uniform permutation distribution. Includes documentation with usage examples, Wren source implementation, and a test suite covering empty lists, single-element lists, and verification that all 24 permutations of a 4-element list are reachable.
2016-02-07 18:38:39 +00:00
Bob Nystrom f1babe5ad4 feat: move File.stat to Stat.path and update all references across docs, source, and tests 2016-02-07 17:56:16 +00:00
Bob Nystrom c1d21ee099 docs: remove community page and redirect content to contributing page with wiki references
The community.markdown file is deleted entirely. Its content about mailing list, libraries, bindings, editor integrations, and tools is migrated into the contributing.markdown page, which now directs users to add such resources to the wiki instead of maintaining them inline. The site navigation template also removes the community link from both the sidebar and footer.
2016-01-24 23:39:35 +00:00
Bob Nystrom 87334da1df feat: replace wrenAllocateForeign with wrenSetSlotNewForeign supporting arbitrary slot and class selection
The old wrenAllocateForeign was limited to slot 0 and the class at the top of the API stack. The new wrenSetSlotNewForeign takes explicit slot and classSlot parameters, allowing foreign objects to be created in any slot from any class. All internal and test call sites updated to use the new API.
2016-01-24 17:25:04 +00:00
Bob Nystrom 885570f0b6 feat: add process module with arguments and allArguments static methods
- Introduce new 'process' module exposing a Process class with foreign static methods for accessing command-line arguments.
- Implement processSetArguments in main.c to store argc/argv, and processAllArguments in process.c to return them as a Wren list.
- Add --help flag support to CLI, printing usage with optional arguments.
- Include documentation for Process.arguments and Process.allArguments, plus module index and template updates.
- Register process module in modules.c and add Xcode project references for new source files.
- Add test scripts for allArguments and arguments, verifying list type, count, and expected values.
2016-01-22 15:57:26 +00:00
Bob Nystrom d8fef617ec fix: remove -fwhole-program flag from wren binary link step 2016-01-22 15:01:56 +00:00
Bob Nystrom 6b153f2a33 chore: update copyright year range in LICENSE from 2013-2015 to 2013-2016 2016-01-22 14:42:16 +00:00
Bob Nystrom 98efeb301d fix: disable -flto flag in wren.mk to avoid LLVM gold linker plugin error on clang builds 2016-01-22 14:42:01 +00:00
Bob Nystrom 58c7c735ed docs: add System.print calls to list examples, reword map docs, update method-calls and performance benchmarks
- Add System.print() wrapper to all list subscript and count examples in lists.markdown
- Reformat map literal alignment and reword description in maps.markdown
- Remove paragraph about fibers as map keys from maps.markdown
- Change method-calls example from "hello" to "Heyoo!" and reword VM execution description
- Update performance benchmark timings and bar widths across all test cases
2016-01-22 05:38:27 +00:00
Bob Nystrom 852eb9707e fix: update copyright year range in LICENSE from 2013-2015 to 2013-2016 2016-01-21 23:20:58 +00:00
Bob Nystrom 527d936c55 perf: enable link-time optimization and whole-program compilation in wren.mk for CLI builds
Add `-flto` to `C_OPTIONS` and replace the CLI linker invocation with `-fwhole-program`, yielding 5-45% performance improvements across benchmarks (e.g., api_call +30%, binary_trees +12%, fib +20%).
2016-01-20 15:47:00 +00:00
Bob Nystrom beaa1b7c73 fix: relax directory stat assertions to avoid filesystem-specific values
Replace hardcoded expected values for linkCount and size with range checks
(>=1 and >0 respectively) so the test passes across different filesystems
that may report varying directory metadata.
2016-01-05 15:32:51 +00:00
Bob Nystrom 7186b04bed feat: add File.stat static method and test for directory stat
Add a new `File.stat(path)` static method that returns a `Stat` object with low-level file system metadata for both files and directories. Include a test file `stat_static_directory.wren` that validates the returned `Stat` object's type and field types (device, inode, mode, linkCount, user, group, specialDevice, size, blockSize, blockCount) against a known test directory.
2016-01-01 18:05:31 +00:00
Bob Nystrom f112722d00 feat: add File.stat() method and Stat class for filesystem metadata queries
Implement asynchronous stat() on File class returning a new Stat object with device, inode, mode, linkCount, user, group, specialDevice, size, blockSize, and blockCount fields populated from libuv uv_fs_stat callback. Register foreign method statPath_ in module registry, bump MAX_METHODS_PER_CLASS to 10, add Stat class to io.wren with indexed field accessors, update documentation index with Stat page, and include test coverage for stat on existing file and nonexistent path.
2016-01-01 17:58:44 +00:00
Bob Nystrom 3746b56ed9 feat: add optional offset parameter to File.readBytes method
Extend File.readBytes with a second overload accepting an offset argument, allowing reads to start at any byte position from the beginning of the file. The existing single-argument variant now delegates to the new two-argument version with offset 0. Validation for the offset parameter mirrors the existing count checks, aborting on non-numeric, non-integer, or negative values. The underlying C implementation passes the offset directly to uv_fs_read, replacing the previous hardcoded zero. Documentation in the io module markdown is updated with usage examples for both signatures, and the old TODO comment about missing offset support is removed. New test files cover offset-based reads, edge cases (zero offset, past-end offset, zero count with offset), and error conditions for invalid offset arguments.
2015-12-30 16:13:19 +00:00
Bob Nystrom 00d4fca59a fix: replace square bracket parameter notation with backtick formatting in system docs
The documentation for `System.print` and `System.printAll` used square brackets
(e.g., `[object]`, `[sequence]`) to denote parameters, which is inconsistent
with the project's standard backtick formatting. This change updates both
descriptions to use backtick-wrapped parameter names (`object`, `sequence`).
2015-12-30 06:35:14 +00:00
Bob Nystrom 54d498ce5d fix: correct grammar and example errors in method-calls documentation
- Fix missing article "a" in "expose some stored or computed property"
- Fix missing relative pronoun "that" in "a method doesn't need any parameters"
- Replace incorrect example `list.clear` with `[1, 2, 3].clear` in getter/setter distinction section
- Simplify phrasing "without any collision" to "without a collision" in setters section
2015-12-30 06:29:13 +00:00
Bob Nystrom 0e1129bef3 docs: add full documentation for io module covering Directory, File, and Stdin classes 2015-12-30 05:56:44 +00:00
Bob Nystrom 9dd956dc10 fix: correct fileFinalizer declaration and use dedicated FINALIZER macro
The extern declaration for `fileFinalize` was changed from `(WrenVM* vm)` to `(void* data)` to match the actual Wren finalizer signature. A new `FINALIZER` macro was added that casts the function pointer to `WrenForeignMethodFn` and sets the signature to `"<finalize>"`. The `STATIC_METHOD("<finalize>", fileFinalize)` entry in the File class registry was replaced with `FINALIZER(fileFinalize)` to use this macro, ensuring the finalizer is correctly registered with the proper type and signature.
2015-12-30 05:07:26 +00:00
Bob Nystrom deb833b1d8 feat: replace manual byte-buffer parsing with native C list creation in Directory.list()
The C directoryListCallback now directly builds a Wren list using wrenSetSlotNewList and wrenInsertInList, eliminating the temporary byte buffer that required manual splitting in Wren. The Wren side is simplified to a single return of the scheduler result. Additionally, the wrenCall and wrenCaptureValue functions are hardened: wrenCall discards extra temporary slots and calls with arity 0, wrenCaptureValue properly roots/unroots object values during handle creation, and the debug stack trace printer skips stub functions with NULL module pointers. A new test case verifies that wrenCall correctly ignores extra temporary slots on the stack.
2015-12-29 16:37:47 +00:00