Commit Graph
100 Commits
Author SHA1 Message Date
Bob Nystrom 0c0f900cad fix: update benchmark numbers and bar widths in performance documentation
Update the Method Call and DeltaBlue benchmark tables with new Wren performance results (6748 and 7564 respectively), adjusting all other language scores and corresponding chart-bar width percentages to reflect the latest measurements.
2015-01-16 15:52:51 +00:00
Bob Nystrom 151978710d perf: inline callFunction and optimize method dispatch in interpreter loop 2015-01-16 15:45:42 +00:00
Bob Nystrom f76cde35a5 fix: replace designated initializer with field assignments in main.c
Replace the C99 designated initializer syntax for `WrenConfiguration config` with explicit field assignments to avoid potential compiler compatibility issues. The change preserves the same configuration values: `reallocateFn` set to NULL, `heapGrowthPercent` and `minHeapSize` set to 0, and `initialHeapSize` set to 100 MB.
2015-01-16 15:10:33 +00:00
Bob Nystrom 9a23d87900 docs: move all and reduce methods from List to new Sequence base class 2015-01-16 15:04:01 +00:00
Bob Nystrom d3ea153a31 feat: implement ! operator for all core types with proper truthiness semantics
Add native `!` methods to Null, Object, Num, String, and List classes so that `!` works reliably on any value. Null returns `true`, all other types return `false` since they are considered truthy. Update documentation to describe the operator as returning the logical complement and add comprehensive tests for each type. Also fix the `all` method test to use a truthy string instead of expecting a runtime error.
2015-01-16 05:50:01 +00:00
Bob Nystrom 4676e87ce9 chore: add Gavin Schulz to AUTHORS and rename forall to all in docs
- Add Gavin Schulz to the AUTHORS file
- Rename the `forall(predicate)` method to `all(predicate)` in the core library documentation
2015-01-16 05:17:45 +00:00
Bob Nystrom e71e85f42c feat: add C++98 compilation support and refactor Value type to uint64_t for nan tagging
Add C++98 compatibility by introducing explicit casts, replacing C99-specific constructs with macros, and updating the build system to produce C++ object files. Refactor the Value union to a plain uint64_t when WREN_NAN_TAGGING is enabled, adding helper functions for num-to-value and value-to-num conversions. Update the compiler to split emit into emit and emitShort for cleaner bytecode emission, and rename emitByte/emitShort to emitByteArg/emitShortArg.
2015-01-16 05:17:08 +00:00
Bob Nystrom 00dca683b7 docs: update README and site index to mention Wren compiles cleanly as C++98 or later 2015-01-16 05:15:21 +00:00
Bob Nystrom 26fd4d2192 feat: refactor Value union to uint64_t and add C++98 compatibility for Wren VM
- Replace Value union with plain uint64_t typedef under WREN_NAN_TAGGING, removing num/bits field access
- Add wrenValueToNum and wrenNumToValue helper functions for double conversion
- Remove wrenValuesEqual function from wren_value.c as bitwise comparison is now direct
- Update Makefile with CPPFLAGS for C++98 compilation and add release-cpp build target
- Add wren-cpp and libwren-cpp.a to .gitignore for C++ build artifacts
2015-01-16 05:12:51 +00:00
Bob Nystrom cf3bc7f07a fix: correct method name from forall to all in core library docs and add Gavin Schulz to AUTHORS 2015-01-16 04:38:00 +00:00
Bob Nystrom 7f92bc7a49 fix: replace switch-based interpreter loop with goto dispatch for computed gotos disabled path 2015-01-16 00:22:55 +00:00
Bob Nystrom e8121af372 refactor: replace static allocate function with ALLOCATE, ALLOCATE_FLEX, and ALLOCATE_ARRAY macros in wren_value.c
Remove the single-purpose `allocate` helper and introduce three type-safe allocation macros (`ALLOCATE`, `ALLOCATE_FLEX`, `ALLOCATE_ARRAY`) that directly invoke `wrenReallocate`. Update all call sites in `wren_value.c` — including `wrenNewSingleClass`, `wrenNewClosure`, `wrenNewFiber`, and `wrenNewFunction` — to use the appropriate macro, eliminating the need for manual sizeof calculations and improving compile-time type checking when compiling as C++.
2015-01-16 00:21:14 +00:00
Bob Nystrom 45414b192c fix: add explicit casts for C++ compatibility in wren_vm.c and wren_vm.h 2015-01-16 00:02:38 +00:00
Bob Nystrom 2cbce0b2e8 fix: add explicit C-style casts for implicit conversions in wren_debug and wren_utils
Add explicit casts to `(Code)` in `debugPrintInstruction` for bytecode indexing, to `(char*)` in `wrenSymbolTableAdd` for heap string allocation, and to `(type*)` in the `DEFINE_BUFFER` macro's reallocation call to ensure C++ compilation compatibility without implicit conversion errors.
2015-01-16 00:00:51 +00:00
Bob Nystrom ba81988800 fix: cast malloc result and adjust compiler emit functions for C++ compatibility
- Cast malloc return to char* in src/main.c to avoid C++ implicit void* conversion
- Rename emit to emitByteArg and emitShort to emitShortArg in src/wren_compiler.c to avoid conflict with new emit and emitShort helpers
- Add new emit function taking uint8_t byte and emitShort helper for 16-bit big-endian emission
- Remove stray semicolon in script/test.py
2015-01-15 23:59:14 +00:00
Bob Nystrom befee63a89 chore: rename test files to follow snake_case naming convention 2015-01-15 14:54:16 +00:00
Bob Nystrom 4acdc503e4 feat: add Sequence.all method and forall documentation with tests
Implement `all(f)` method on Sequence class that returns true if all elements pass the predicate function. Add corresponding documentation entry for `forall(predicate)` in core-library.markdown. Include three test files covering basic functionality, non-boolean return handling, and non-function argument error cases.
2015-01-15 14:52:43 +00:00
Bob Nystrom ee239f2bb6 feat: add undefined sentinel value and implicit global declaration for forward references
Add a new singleton value `VAL_UNDEFINED` to represent globals that have been implicitly declared via forward reference but not yet explicitly defined. Introduce `wrenDeclareGlobal()` to create such entries in the global table, and modify `wrenDefineGlobal()` to check for and resolve undefined slots. Update the compiler's `findUpvalue()` to stop closure capture at method boundaries, preventing methods from closing over local variables. Refactor `wrenSymbolTableAdd()` to always add symbols without duplicate checking, moving that logic to callers. Adjust error messages in the compiler to handle EOF tokens and improve newline formatting. Fix the delta_blue benchmark by renaming the global `planner` variable to `ThePlanner` to avoid shadowing the forward-declared function.
2015-01-15 07:08:34 +00:00
Bob Nystrom 72291f8b74 feat: implicitly declare nonlocal names as globals for forward references
Add support for forward references to top-level variables by implicitly
declaring unresolved capitalized names as globals during compilation.
If a real definition is not found later, a compile-time error is raised.
This enables mutual recursion at the top level and fixes issues #101 and #106.

Introduce an `UNDEFINED` singleton value to mark implicitly declared globals
that have not yet been explicitly defined. Update `wrenDeclareGlobal` to add
such entries, and modify `wrenDefineGlobal` to check for and replace undefined
placeholders. Adjust the symbol table API to allow duplicate additions for
implicit declarations. Add test cases for mutual recursion, forward references
in functions and methods, and undefined variable errors.
2015-01-15 07:08:25 +00:00
Bob Nystrom 533644c1f6 refactor: rename global planner variable to ThePlanner in DeltaBlue benchmark
Replace the forward-declared `planner` variable with a capitalized `ThePlanner` name across all constraint methods and test functions, removing the TODO comment about forward declarations.
2015-01-15 07:02:12 +00:00
Bob Nystrom 82ef82cdb9 fix: prevent redundant keyword checks after first match in readName
Replace sequential `if` statements with `else if` chains in `readName` so that once a keyword matches (e.g. "break"), the remaining keyword checks are skipped, fixing issue #110 where later keywords could incorrectly override an already-matched token type.
2015-01-14 14:46:02 +00:00
Bob Nystrom 54ef9bbc73 feat: stop closure upvalue search at method boundaries and treat capitalized names as globals
Modify `findUpvalue` in the compiler to return -1 when the enclosing function is a method, preventing closures from capturing outer local variables. Add a new `nonlocal` variable resolution path that treats capitalized identifiers as global variables rather than method receivers. Update existing test files to use capitalized global names and add new test cases for nonlocal assignment, duplicate nonlocal declarations, block scoping, and method-local variable shadowing.
2015-01-14 05:36:42 +00:00
Bob Nystrom d031d0a77d fix: correct spelling of "brethren" and "invalid" in documentation files 2015-01-13 14:42:35 +00:00
Bob Nystrom 61abae46ec fix: correct spelling errors in documentation files
Fix three typos across documentation files: 'unvalid' to 'invalid' in
doc/error-handling.txt, and 'bretheren' to 'brethren' in both
doc/site/expressions.markdown and doc/site/getting-started.markdown
2015-01-13 00:58:05 +00:00
Bob Nystrom 289dd99c26 feat: add -g flag to DEBUG_CFLAGS in Makefile for debugging symbols
Add the -g compiler flag to DEBUG_CFLAGS in the Makefile to enable
generation of debugging symbols during debug builds, allowing better
debugging with tools like GDB.
2015-01-12 15:32:21 +00:00
Bob Nystrom d6b70a0af3 feat: add type validation for IO.read prompt and stdin support in test runner
Add string type check for IO.read() prompt argument with Fiber.abort on non-string input. Implement stdin piping in test runner via // stdin: comments, allowing tests to provide input lines. Update stack trace filtering to omit built-in library frames with empty source paths. Add io/read.wren and io/read_arg_not_string.wren test cases.
2015-01-12 05:47:29 +00:00
Bob Nystrom e12b36002e feat: add IO.read method with prompt and stdin input buffer
Implement a new static `IO.read(prompt)` method in the IO class that writes a prompt string to stdout and reads a line from stdin into a fixed 1024-byte buffer. The C implementation adds a `MAX_READ_LEN` constant, an `ioRead` function using `fgets`, and registers the method via `wrenDefineStaticMethod`. The builtin source string is updated to include the new Wren method definition.
2015-01-12 04:05:52 +00:00
Bob Nystrom a2c7499e0a fix: add tab character to whitespace skipping in nextToken parser
The nextToken function in wren_compiler.c previously only skipped spaces and carriage returns when advancing past whitespace, causing tab characters to be treated as non-whitespace tokens. This change adds '\t' to the whitespace check in both the initial case statement and the peekChar loop, ensuring tabs are properly skipped like other whitespace characters. A new test file test/whitespace.wren is added to verify correct handling of tabs in various indentation patterns and inline code positions.
2015-01-12 04:01:30 +00:00
Bob Nystrom 363486df33 feat: add test verifying carriage returns are treated as whitespace in parser
Add a new test file `test/ignore_carriage_returns.wren` that sprinkles carriage
return characters (`\r`) in various positions within source code to confirm the
parser correctly ignores them as whitespace. The test includes a deliberate
compile error to validate that line numbering remains accurate despite the
presence of carriage returns.
2015-01-12 03:58:30 +00:00
Bob Nystrom b8ad075a4f feat: add contains method to List and Set classes with example and documentation
Add a `contains(element)` method to the built-in `List` class in `builtin/core.wren` and its embedded source in `src/wren_core.c`, enabling linear search for an element. Introduce a new `Set` class example in `example/set.wren` implementing set operations (union, intersection, difference) using the new `contains` method. Update `doc/site/classes.markdown` with a warning against inheriting from built-in types due to internal bit representation constraints.
2015-01-12 03:53:17 +00:00
Bob Nystrom cd6d6c1f91 style: reformat while-loop body in nextToken to use braces 2015-01-12 03:52:59 +00:00
Bob Nystrom 34d3a8edb7 fix: open source files in binary mode and skip CR in whitespace
Change `fopen` mode from `"r"` to `"rb"` in `readFile()` to prevent CRLF-to-LF conversion on Windows, and add `'\r'` as a skipped whitespace character in `nextToken()` to handle carriage returns embedded in source files. This fixes parsing errors when Wren source files use Windows-style line endings.
2015-01-12 03:52:08 +00:00
Bob Nystrom acf02f1ebc docs: document restriction on inheriting from built-in types in classes guide
Add a note to the classes documentation page explaining that inheriting from built-in types (Bool, Num, String, Range, List) is not supported due to internal bit representation conflicts that cause errors when invoking inherited methods on derived types.
2015-01-12 03:50:39 +00:00
Bob Nystrom 887afc03be feat: add Set class example and List.contains method to core library
Add a complete Set class implementation in example/set.wren with union, intersection, and set minus operations. Implement List.contains method in builtin/core.wren and its C source to support element existence checks via iteration.
2015-01-12 03:50:07 +00:00
Bob Nystrom 4e461f0b0c chore: clarify comment for super outside method error handling path 2015-01-12 03:44:35 +00:00
Bob Nystrom 497e05c575 fix: guard against segfault when super is called at top level with no args
When `super` is invoked at the top level without an explicit method name, the compiler previously dereferenced a NULL `enclosingClass` pointer while trying to copy the enclosing method's signature. This change adds a NULL check for `enclosingClass` in the `super_` function, setting an empty method name and zero length when the pointer is NULL, preventing the segmentation fault. Also extends the test file `super_at_top_level.wren` with additional cases for bare `super`, `super.foo("bar")`, and `super("foo")` to verify error handling for these top-level super invocations.
2015-01-12 03:42:26 +00:00
Bob Nystrom 6928ba9935 chore: rename test files to snake_case and update string class docs
Rename indexOf.wren and startsWith.wren test files to index_of.wren and
starts_with.wren respectively, fix missing trailing newlines, update
string class documentation to clarify UTF-8 storage and move the
note about incorrect UTF-8 handling in the index operator, and
remove unnecessary parentheses in string_indexOf native return.
2015-01-12 03:13:15 +00:00
Bob Nystrom 7fd1e5eeaa fix: switch Google Fonts URL to protocol-relative to fix Firefox Mixed Content errors
The font stylesheet link in doc/site/template.html used an explicit http:// scheme,
causing Firefox to block the request on HTTPS pages due to Mixed Content warnings.
Changed to a protocol-relative URL (//fonts.googleapis.com/...) so the browser
automatically uses the same protocol as the parent page.
2015-01-09 17:34:35 +00:00
Bob Nystrom f010c8d79f fix: correct buffer size in string subscript operator to prevent off-by-one allocation
The `string_subscript` native was allocating a 2-byte buffer for single-character
results, causing a one-byte over-allocation. Changed to allocate exactly 1 byte
for the character plus the null terminator handled by `wrenNewUninitializedString`.

Also fixed `wrenNewUninitializedString` to properly cast the `length` parameter
to `int` when assigning to `ObjString->length`, resolving a potential
truncation warning on 64-bit systems.

Added a test case to verify that subscript access returns a properly formed
string that compares equal to the expected character.
2015-01-09 15:12:25 +00:00
Bob Nystrom 0572df823b fix: remove negative number literal parsing in lexer and update tests for unary minus precedence
The lexer previously treated a leading minus sign followed by a digit as a single negative number token, which caused incorrect parsing of expressions like `1-1` and broke method calls on negative numbers. This change removes that special case, making the minus sign always a separate token, and updates all test expectations to use explicit parentheses for negative number method calls.
2015-01-09 15:00:12 +00:00
Bob Nystrom 49e8b17056 refactor: move methodNotFound into runtimeError and allocate managed ObjString for GC safety 2015-01-09 06:29:37 +00:00
Bob Nystrom 5377a94a58 feat: add argument count to method-not-found error messages
Introduce a `methodNotFound` helper in `wren_vm.c` that parses the symbol name to determine the number of arguments and generates a detailed error message including the argument count. Update all runtime error calls and test expectations across fiber, inheritance, method, and super test files to reflect the new format, and add new test cases for method-not-found with 1, 2, and 11 arguments.
2015-01-09 05:49:20 +00:00
Bob Nystrom 0d318e9545 feat: add stack vs register-based VM design rationale to FAQ
Add a new FAQ entry explaining why Wren uses a stack-based bytecode VM
instead of a register-based one. The entry covers the trade-offs between
the two approaches, references Lua's switch to register-based VM, and
explains that Wren's operator-overloading design makes register-based
optimizations less beneficial.
2015-01-09 05:06:10 +00:00
Bob Nystrom 3f126945df fix: guard against non-string toString in IO.print and IO.write
Add writeObject_ helper that checks if obj.toString returns a String before
writing it, falling back to "[invalid toString]" otherwise. Update print,
write, and printList_ to use the new helper instead of calling toString
directly. Include test cases for both IO.print and IO.write with a class
whose toString returns an integer.
2015-01-08 15:53:37 +00:00
Bob Nystrom 6c2d673638 fix: alert missing interpreter in benchmark runner instead of crashing on OSError 2015-01-08 15:44:29 +00:00
Bob Nystrom b882b33019 docs: fix typo "they behavior" to "their behavior" in expressions documentation 2015-01-08 15:43:00 +00:00
Bob Nystrom 845b95e3b3 refactor: replace strlen calls with sprintf return value in num_toString and range_toString
Use the integer length returned by sprintf directly instead of calling strlen on the buffer, eliminating redundant string length calculations in two native functions for number and range string conversion.
2015-01-08 15:41:49 +00:00
Bob Nystrom 041e6213d5 refactor: change ObjString length field from size_t to int for consistency and reduced memory usage
The length field in ObjString struct now uses int instead of size_t, saving memory
and aligning with other string length storage conventions throughout the VM.
This eliminates signed/unsigned conversion warnings and matches the type used
elsewhere for string lengths.
2015-01-08 15:41:30 +00:00
Bob Nystrom 56355baf42 refactor: use sprintf return value to avoid redundant strlen calls in num_toString and range_toString
Replace strlen(buffer) calls with the length returned directly by sprintf in the
num_toString and range_toString native functions, eliminating unnecessary string
length calculations after formatting.
2015-01-08 15:01:21 +00:00
Bob Nystrom a48edd5874 feat: store string length in ObjString to avoid O(n) strlen calls
Replace all uses of `strlen()` and `strcmp()` on string values with the precomputed `length` field and `memcmp()` for equality checks. This eliminates repeated O(n) length calculations in `string_count`, `string_contains`, `string_eqeq`, `string_bangeq`, and `string_subscript`. Also fixes memory accounting in `markString` to use the stored length instead of recalculating it.
2015-01-08 14:59:41 +00:00
Bob Nystrom caad37b187 feat: add benchmark metrics tracking to script/metrics.py
Extend the metrics script to walk the benchmark directory, counting benchmark files, TODOs, non-empty lines, and empty lines, and print these new benchmark statistics alongside existing source and test metrics.
2015-01-07 15:30:59 +00:00
Bob Nystrom 1874938a57 fix: convert print statements to functions and add shebang for Python 3 compatibility in run_bench script 2015-01-07 15:25:46 +00:00
Bob Nystrom fc168cb6fc chore: add travis build badge and fix trailing semicolons in benchmark
Add Travis CI build status badge to README for continuous integration visibility.
Remove trailing semicolons from three assignment statements in delta_blue.wren
benchmark to maintain consistent coding style across the codebase.
2015-01-07 15:23:03 +00:00
Bob Nystrom 513a6fe4be fix: remove trailing semicolons from assignment statements in delta_blue.wren benchmark
Remove unnecessary semicolons from three assignment expressions in the
delta_blue.wren benchmark file to conform to Wren language style conventions,
where semicolons are optional and typically omitted.
2015-01-07 15:22:05 +00:00
Bob Nystrom c1980e4c58 refactor: embed string data as flexible array member in ObjString
Remove separate heap allocation for string text by converting ObjString.value from a char pointer to a C99 flexible array member. This eliminates the extra allocation in wrenNewUninitializedString and the corresponding free in wrenFreeObj, reducing memory fragmentation and pointer indirection for all string objects.
2015-01-07 15:20:12 +00:00
Bob Nystrom 44e85f652e docs: add Travis CI build status badge to README.md
Insert a Markdown image link pointing to the Travis CI build status SVG for the munificent/wren repository, placed between the contribution call-to-action paragraph and the syntax reference link. Also fix the missing trailing newline on the contributing URL line.
2015-01-06 15:21:22 +00:00
Bob Nystrom 44d667665b fix: handle NaN formatting in num_toString to ensure consistent output
The previous implementation relied on sprintf's "%.14g" format for NaN values,
which produces platform-dependent results (some libc versions add a sign prefix).
This change adds an explicit NaN check using the self-comparison idiom (value != value)
and returns a lowercase "nan" string directly, ensuring consistent behavior across
all platforms. The buffer size comment is also updated to remove the now-inaccurate
reference to NaN handling.
2015-01-06 15:09:45 +00:00
Bob Nystrom ba91af1f4d chore: add Paul Woolcock to AUTHORS file to resolve merge conflict 2015-01-06 05:58:23 +00:00
Bob Nystrom 95d3ae5cc6 chore: add Paul Woolcock to AUTHORS file with email address
Append Paul Woolcock's name and email (paul@woolcock.us) to the list of contributors in the AUTHORS file, following the existing entry for Robert Nystrom.
2015-01-06 04:52:01 +00:00
Bob Nystrom a3e6d028c4 docs: fix logical or operator description to correctly state truthy behavior 2015-01-05 15:46:26 +00:00
Bob Nystrom e07fe5149b docs: add AUTHORS file and expand contributor guide with detailed workflow
- Create AUTHORS file listing Robert Nystrom as initial contributor
- Rewrite README to emphasize Wren as concurrent scripting language with fiber examples
- Expand contributing.markdown with structured sections for finding tasks and making changes
- Update index.markdown with call-to-action links for trying and contributing
2015-01-04 21:36:23 +00:00
Bob Nystrom b61e55d4c9 fix: skip duplicate lexer error reporting in compiler error handler
The `error()` function in the compiler now returns early when the offending token
is of type `TOKEN_ERROR`, preventing the lexer's already-reported error from
being emitted a second time to stderr. This eliminates redundant error messages
for malformed tokens.
2015-01-04 21:10:46 +00:00
Bob Nystrom 96d893a637 feat: ignore shebang lines starting with #! on first line of source
Add special handling in the lexer's nextToken function to detect a '#' character followed by '!' on the first line (currentLine == 1) and skip the entire line as a comment. If the shebang appears on any other line, or if a '#' is not followed by '!', emit a lex error for invalid character. Include test cases for valid shebang execution, shebang at EOF, shebang on a non-first line (expected error), and an invalid shebang pattern (expected error).
2015-01-04 21:02:42 +00:00
Bob Nystrom ed31544ead fix: handle empty and comment-only files by removing early skip in repl and compiler
Remove the empty-line check in runRepl that skipped interpretation for blank input, and refactor the main compilation loop in wrenCompile to use a while loop with TOKEN_EOF matching instead of a for loop with redundant EOF break. This allows the compiler to process files containing only comments or whitespace without prematurely terminating, fixing issue #57. Add test fixtures for comment-only source files.
2015-01-04 21:00:53 +00:00
Bob Nystrom a6bef8586f fix: skip wrenInterpret call on empty input line in repl loop 2015-01-04 18:03:16 +00:00
Bob Nystrom 1e49dc666a chore: add shared library artifacts to gitignore and clarify makefile comment for lib build
Add libwren.a and libwrend.a to .gitignore to prevent tracking of static library build outputs, and update the Makefile comment to explain that main.c is excluded from shared library object lists.
2015-01-04 18:02:50 +00:00
Bob Nystrom f1e4871521 feat: add static library targets and exclude main.o from shared objects
Add `libwren.a` and `libwrend.a` static library build targets using `ar rcu`, compile all object files with `-fPIC` for position-independent code, and exclude `main.o` from the shared library object lists via `subst` to allow linking the interpreter separately against the static archive.
2015-01-04 17:57:05 +00:00
Bob Nystrom 0451059109 fix: skip wrenInterpret call when REPL input is empty newline 2015-01-04 07:40:20 +00:00
Bob Nystrom 98d358142d docs: reflow all markdown files to 80-char width and add control-flow page with branching/looping content 2015-01-04 07:27:02 +00:00
Bob Nystrom 1951059c8f feat: remove semicolon token from lexer and treat it as invalid syntax
Remove the `;` case from the `nextToken` function in `wren_compiler.c` so that semicolons are no longer lexed as `TOKEN_LINE`. Update the documentation in `doc/site/syntax.markdown` to describe newlines as the sole statement separator, and adjust all test files (`test/limit/many_constants.wren`, `test/limit/many_globals.wren`, `test/limit/too_many_constants.wren`, `test/semicolon.wren`) to reflect that semicolons now produce an error instead of being treated as line breaks.
2015-01-03 18:02:45 +00:00
Bob Nystrom 3b63f25690 docs: update error-handling doc to show "Caught error:" prefix in example output 2015-01-03 04:17:36 +00:00
Bob Nystrom 1663d4d95c fix: name anonymous union in Method struct to comply with strict C99
The anonymous union inside the Method struct was previously unnamed, which is not allowed in strict C99 mode. This change names the union `fn` and updates all references to its members (`.primitive`, `.foreign`, `.obj`) to use the qualified syntax (`.fn.primitive`, `.fn.foreign`, `.fn.obj`). The NATIVE macro parameter was also renamed from `fn` to `function` to avoid shadowing the new union field name.
2015-01-03 04:17:10 +00:00
Bob Nystrom c69be6012a fix: correct example output for catching and printing an error in error-handling docs 2015-01-03 04:09:43 +00:00
Bob Nystrom 2d7b4f951c fix: correct Wren class syntax in README and doc site examples to use getter methods 2015-01-03 04:07:43 +00:00
Bob Nystrom 6d1801603c feat: add Travis CI config and fail-exit in test script
Add .travis.yml with gcc and clang compilers running make && make test.
Modify script/test.py to call sys.exit(1) when any tests fail, ensuring
CI build correctly reports failure status.
2015-01-02 16:13:51 +00:00
Bob Nystrom 464a2139b1 fix: remove embedded newline from "small" in Wren class adjectives array 2015-01-02 15:59:31 +00:00
Bob Nystrom e820580f73 docs: add README with Wren language overview and feature highlights
- Introduce Wren as a small, clean, fast class-based scripting language
- Include code example demonstrating class syntax with adjectives list
- List key features: small codebase under 4000 semicolons, clean C99 implementation, fast single-pass compiler, class-based object model, embedding-focused design
- Provide links to source code, NaN tagging implementation, performance benchmarks, class documentation, and embedding API
2015-01-02 15:42:08 +00:00
Bob Nystrom 52677edf48 fix: extend copyright year range and clarify permission notice inclusion in binary distributions 2015-01-02 15:38:00 +00:00
Bob Nystrom f069a38228 style: rename local variable num_read to numRead and reorder feof check in runRepl 2015-01-02 15:31:02 +00:00
Bob Nystrom 374bb4aed9 fix: correct broken link to embedding API documentation in site index
The link target for the embedding API reference was pointing to the wrong
filename (`embedding.html` instead of `embedding-api.html`), causing a 404
error when users clicked the link. This commit updates the href to match the
actual generated documentation file.
2015-01-02 06:59:38 +00:00
Bob Nystrom 9c286204ff fix: correct range operator example in values documentation from .. to ... 2015-01-02 06:48:43 +00:00
Bob Nystrom 5c867fbc49 feat: add gh-pages make target to build docs and copy to gh-pages directory
Add a new `gh-pages` make target that depends on the `docs` target and copies the generated documentation from `build/docs/` into a local `gh-pages/` directory. Also update `.gitignore` to exclude the `gh-pages/` directory, which is intended to be a separate checkout of the repository for pushing to GitHub Pages.
2015-01-02 04:58:36 +00:00
Bob Nystrom 722ca8f61d docs: expand contributing guide with MIT license and GitHub links, reword error handling and performance sections 2015-01-02 04:45:15 +00:00
Bob Nystrom 0868cf1d8c chore: add TODO comment for arity getter in wren_core.c
- Inserted a TODO comment before the toString native binding in the
  function class initialization to remind about implementing an arity
  getter for Wren functions.
2015-01-02 02:49:10 +00:00
Bob Nystrom 151b352bee docs: expand embedding API, functions, lists, maps, and looping documentation with examples and clarifications 2015-01-02 02:48:59 +00:00
Bob Nystrom 0a54f68ad3 docs: add comprehensive error-handling documentation covering syntax and runtime errors with examples 2015-01-02 00:02:02 +00:00
Bob Nystrom 0f5eb1885e feat: add Fiber.abort() method to abort fiber with error message
Implements a new `Fiber.abort()` static method that allows a fiber to terminate with a custom error message string. The method validates that the argument is a string, then returns a PRIM_ERROR to abort the current fiber. Includes three test cases: basic abort with error message retrieval via `fiber.try`, aborting the main fiber with a runtime error, and type checking that non-string arguments produce an appropriate error message.
2015-01-01 18:40:14 +00:00
Bob Nystrom d287d084ed refactor: simplify empty list range check in list_subscript native
Consolidate the two separate conditional branches for empty range on zero-length list into a single expression using ternary on range->isInclusive, removing the TODO comment and reducing code duplication.
2014-12-31 18:34:44 +00:00
Bob Nystrom 0fafa4bd07 refactor: replace integer stack index with pointer for stack top in fiber
Migrate fiber stack management from an integer `stackSize` counter to a direct `Value* stackTop` pointer, eliminating repeated `stack[stackSize - 1]` calculations. Update all stack slot accesses, iteration loops, and the `CallFrame::stackStart` field to use pointer arithmetic, simplifying the code and reducing index arithmetic overhead.
2014-12-31 18:34:27 +00:00
Bob Nystrom d34cbd33ee perf: cache frame stack start pointer in local variable to reduce memory accesses
Store the start of the current frame's stack in a local `stackStart` variable
during LOAD_FRAME() macro execution, replacing repeated calculations of
`fiber->stack[frame->stackStart + offset]` with `stackStart[offset]` across
LOAD_LOCAL and LOAD_FIELD opcodes. Also remove unused `upvalues` register
variable and its assignments from closure handling paths.
2014-12-08 14:57:36 +00:00
Bob Nystrom ee9d10f5f5 fix: update benchmark chart values for method call and delta blue tests
The performance numbers in the documentation's benchmark chart have been refreshed to reflect the latest measurements. Method call results now show wren at 5100 (up from 4930), luajit at 4441 (up from 4266), ruby at 2868 (up from 2752), lua at 1742 (up from 1728), python3 at 884 (up from 865), and python at 779 (up from 764). DeltaBlue results show wren at 7006 (up from 6662) and python3 at 2333 (down from 2336).
2014-12-07 22:34:17 +00:00
Bob Nystrom d224721f79 feat: store class reference directly in Obj struct and inline class lookup for method dispatch
Move the class pointer from ObjInstance into the base Obj struct and remove the separate metaclass field from ObjClass, allowing all heap objects to directly reference their class. Add an inlined wrenGetClassInline function in the header to eliminate function call overhead during method dispatch, yielding 10-43% performance gains across benchmarks.
2014-12-07 22:29:50 +00:00
Bob Nystrom 520e841044 feat: add specialized LOAD_LOCAL_0..8 instructions to skip arg byte decode
Introduce nine new bytecode instructions (CODE_LOAD_LOCAL_0 through CODE_LOAD_LOCAL_8) that directly encode the local slot number in the opcode itself, eliminating the need to read and decode a separate argument byte for the most frequently accessed local variables. This optimization targets the hottest path in the interpreter, as LOAD_LOCAL is the most executed instruction across benchmarks (e.g., 3.75M times in delta_blue). The compiler's `loadLocal` helper emits the specialized opcode when the slot index is ≤8, falling back to the generic `CODE_LOAD_LOCAL` with an argument byte otherwise. The VM dispatch table and debug printer are updated accordingly. Benchmarks show consistent speedups: fib +7.3%, method_call +5.9%, binary_trees +1.9%, for +2.8%, delta_blue +1.0%.
2014-12-07 03:59:11 +00:00
Bob Nystrom a665e14804 feat: add regression test for function with 8195 constants exceeding limit
Add a new test file `test/limit/too_many_constants.wren` containing a single function with 8195 integer literal constants to verify the compiler correctly rejects functions that exceed the maximum constant count limit.
2014-12-07 00:39:39 +00:00
Bob Nystrom 77bddf8f0a refactor: extract wrenNewUninitializedString to avoid passing NULL to wrenNewString for empty buffers 2014-12-06 18:04:46 +00:00
Bob Nystrom 9b498b4638 fix: ensure all switch and unreachable paths return a value in release builds
In `getNumArguments`, add a `return 0` after the `UNREACHABLE()` default case to prevent
undefined behavior when assertions are disabled. In `wrenGetClass`, reorder the
`UNREACHABLE()` macro before the `return NULL` so the unreachable annotation is
always emitted. In `runInterpreter`, replace the `ASSERT(0, ...)` with an explicit
`UNREACHABLE()` and `return false` to guarantee a return value on all control paths
when the interpreter exits unexpectedly.
2014-12-02 05:36:06 +00:00
Bob Nystrom 306c33f01c fix: wrap ASSERT in do-while and add UNREACHABLE macro for GCC compatibility 2014-11-28 19:21:01 +00:00
Bob Nystrom 3266491cf5 fix: correct break statement instruction size from 2 to 3 in endLoop to prevent code walker from misinterpreting arguments 2014-11-27 02:33:54 +00:00
Bob Nystrom d9a42f21ba fix: add missing -lm link flag and fix GCC warnings for getline and switch coverage
Add -lm flag to both debug and release linker commands in Makefile to resolve
undefined math library references. Define _GNU_SOURCE in main.c to make getline()
available under GCC. Add default cases to switch statements in runFile and
getNumArguments to suppress -Wswitch warnings. Fix u_int8_t to uint8_t type in
wrenNewFunction declaration and definition for POSIX compliance.
2014-11-26 22:03:05 +00:00
Bob Nystrom d60068db56 feat: add Fiber.try() method for catching errors across fiber boundaries
Implement a new `Fiber.try()` method that allows a calling fiber to catch runtime errors from a called fiber. When a fiber is invoked with `try()` instead of `call()`, any runtime error that occurs in the called fiber is returned as a string to the caller rather than terminating the program with a stack trace. The `callerIsTrying` flag on `ObjFiber` tracks this state, and the `runtimeError` function now checks this flag to redirect the error to the caller's stack. Also adds `Fiber.error` getter to retrieve the error string from a failed fiber, changes `Fiber.isDone` to return `true` for errored fibers, and migrates the fiber error field from a raw `char*` to an `ObjString*` for proper memory management. Includes comprehensive test cases for try behavior, re-entry prevention, and error state queries.
2014-10-15 13:36:42 +00:00