Commit Graph
968 Commits
Author SHA1 Message Date
jclc 8858161484 skip UTF-8 BOM 2018-04-04 05:11:59 +03:00
Michel Hermier e4901c51d8 Add wrenStringEqualStrLength and wrenStringsEqual. 2018-03-29 09:12:32 +02:00
Michel Hermier 3c39f7e0af Make symboltable use ObjString.
* Avoid to have 2 different string representation in the code.
* Reduce memory creation in meta API, by reusing created strings.
2018-03-28 18:12:50 +02:00
Michel Hermier 3e9bf0277b Move Obj* type definition to wren_common.h.
Uniformize structure naming, and should help file includes.
2018-03-28 17:51:34 +02:00
Bob Nystrom af9fda5e60 Merge branch 'master' of https://github.com/munificent/wren 2018-03-26 07:50:49 -07:00
Bob Nystrom 8c7174d1c6 Merge branch 'fix-assert' of https://github.com/maxdeviant/wren into maxdeviant-fix-assert 2018-03-26 07:50:16 -07:00
Bob Nystrom 8852e5accc Merge pull request #500 from mhermier/critical_fixes
[critical] Fix getNumArguments and wrenBindMethodCode opcodes data.
2018-03-26 07:49:54 -07:00
Bob Nystrom 8210452970 Relative imports!
This is a breaking change because existing imports in user Wren code
that assume the path is relative to the entrypoint file will now likely
fail.

Also, stack trace output and host API calls that take a module string
now need the resolved module string, not the short name that appears in
the import.
2018-03-24 11:10:36 -07:00
Bob Nystrom 5539c59750 Add a minimal path manipulation C module.
This is just for the VM's own internal use, for resolving relative
imports.

Also added a tiny unit test framework for writing tests of low-level
C functionality that isn't exposed directly by the language or VM.
2018-03-24 10:58:07 -07:00
Bob Nystrom 8a71735e0f Expose an API to let the host resolve relative import strings.
This is a breaking API change: wrenInterpret() now takes an additional
parameter for the module name to interpret the code in.
2018-03-23 07:54:09 -07:00
Bob Nystrom c5befa72cf Don't use module import string when loading imported variables.
This is an interim step towards supporting relative imports. Previously,
the IMPORT_VARIABLE instruction had a constant string operand for the
import string of the module to import the variable from. However, with
relative imports, the import string needs to be resolved by the host
all into a canonical import string. At that point, the original import
string in the source is no longer useful.

This changes that to have IMPORT_VARIABLE access the imported ObjModule
directly. It works in two pieces:

1. When a module is compiled, it ends with an END_MODULE instruction.
   That instruction stores the current ObjModule in vm->lastModule.

2. The IMPORT_VARIABLE instruction uses vm->lastModule as the module to
   load the variable from. Since no interesting code can execute between
   when a module body completes and the subsequent IMPORT_VARIABLE
   statements, we know vm->lastModule will be the one we imported.
2018-03-20 06:54:51 -07:00
snocl 92cb88366b Fix REPL being broken by latest commit. 2018-03-19 21:50:12 +01:00
Bob Nystrom 2c88e19497 Compile imports to closures, not fibers.
This is simpler and marginally faster. We don't need the overhead of
fibers since you can't have long or recursive import chains anyway.

More importantly, this makes the behavior more well-defined when you do
things like yield from an imported module. (Not that you should do that,
but if you do, it shouldn't do weird things.)
2018-03-17 09:33:33 -07:00
Bob Nystrom 43cf652003 Simplify wrenCompileSource(). 2018-03-17 09:13:51 -07:00
Marshall Bowers e493e6679b Fix variable in assert
Fixes #493
2018-01-18 00:46:58 -05:00
Michel Hermier a2cf3c34ad Fix getNumArguments and wrenBindMethodCode opcodes data.
Some instructions data in these 2 functions are out of syncs, and can try to
patch the code in bad manner.
2018-01-11 12:20:35 +01:00
Bob Nystrom c4d08bcb81 Fix missing return error. 2017-10-31 22:07:07 -07:00
Bob Nystrom 8d37b20783 Compile imports to actual instructions instead of core library calls. 2017-10-31 15:58:59 -07:00
Bob Nystrom 1661f5368f Allow passing a value when first starting a fiber.
If the function the fiber is created from takes a parameter, the value
passed to the first call() or transfer() gets bound to that parameter.

Also, this now correctly handles fibers with functions that take
parameters. It used to leave the stack in a busted state. Now, it's a
runtime error to create a fiber with a function that takes any more
than one parameter.
2017-10-19 20:45:13 -07:00
Bob Nystrom 9661a5b999 Fix a couple of bugs in the REPL.
- Not sure what was going on, but fix #456. It makes more sense for the
  REPL to invoke the compiled code as a fiber than a function anyway.

- Flush stdout before reading from stdin since System.print() no longer
  does that automatically.
2017-10-13 07:58:57 -07:00
Bob Nystrom 91853a7fa9 Fix comment on foreign allocate function.
Fix #453.
2017-10-12 06:37:49 -07:00
Bob Nystrom 2021e086bf Don't automatically flush on every System.write().
It's handy because it ensures writes are flushed to the terminal before
any calls to read from stdin, but it's also gratuitously slow.

Instead, added a Stdout class with an explicit flush() method that can
be called by the user.

Fix #445.
2017-10-09 07:16:05 -07:00
Bob Nystrom c4b0f83cb3 "ClassCompiler" -> "ClassInfo".
Fix #469.
2017-10-09 06:47:42 -07:00
Bob Nystrom 973b43eb7f Simplify statement compiler code a little. 2017-10-08 10:47:31 -07:00
Bob Nystrom c38d97b973 Properly detect a missing "}" in a block.
Fix #429.
2017-10-08 10:03:42 -07:00
Bob Nystrom 18449102e8 Parenthesize macro arguments in ALLOCATE_FLEX and ALLOCATE_ARRAY.
Fix #457.
2017-10-08 09:45:06 -07:00
Bob Nystrom fec54d5021 Avoid undefined pointer difference behavior.
Fix #458.
2017-10-08 09:42:35 -07:00
Bob Nystrom eba0b97aa2 Merge pull request #472 from KyleCharters/master
Add Num .round
2017-10-06 07:51:55 -07:00
Bob Nystrom 8963a870ff Abort all fibers along a call chain when one aborts. 2017-10-06 07:39:00 -07:00
Bob Nystrom 0f19984017 Merge branch '201703_bubble_exceptions' of https://github.com/JonesAndrew/wren into JonesAndrew-201703_bubble_exceptions 2017-10-06 06:58:27 -07:00
Kyle Charters 84f2252c68 Add Num .round 2017-09-20 20:27:02 -04:00
Brian Slesinsky a7418d64e6 Remove obsolete comment 2017-05-29 12:02:50 -07:00
Bob Nystrom 889cae5ff1 Free imported module source strings after compiling them.
Fix #430.
2017-04-08 12:38:36 -07:00
Andew Jones 7d631276cb Catch errors in the first try() 2017-03-30 21:57:29 -04:00
Bob Nystrom 417ed7aeed Add wren.hpp. 2017-03-25 10:05:33 -07:00
Bob Nystrom 44a95e65c6 Set the token type after an invalid character error.
Otherwise, it still has the previous token's type. This can cause it
to get stuck in a loop in some places in the compiler.

Fix #428.
2017-03-23 21:19:20 -07:00
Bob Nystrom 02bcefcbe4 Add test for user data.
Also moved the VM parameter in the error callback to be first like it
is in other callbacks.
2017-03-22 07:26:19 -07:00
Bob Nystrom 907db83e1c Merge branch 'user-data' of https://github.com/foobit/wren into foobit-user-data 2017-03-22 07:12:26 -07:00
Bob Nystrom 8d313be3ce Make it an error to skip or take a negative count. 2017-03-15 07:22:44 -07:00
Bob Nystrom 9f93119377 Merge branch 'take_and_skip' of https://github.com/bjorn/wren into bjorn-take_and_skip 2017-03-15 07:15:00 -07:00
Bob Nystrom c84b8109a4 Tweak comments. 2017-03-15 07:10:23 -07:00
Bob Nystrom 627e9edc23 Merge branch 'fix362' of https://github.com/bytemaster/wren into bytemaster-fix362 2017-03-15 07:09:31 -07:00
Bob Nystrom 9fcdf3dc0a Merge branch '201703_split_replace' of https://github.com/JonesAndrew/wren into JonesAndrew-201703_split_replace 2017-03-15 07:04:56 -07:00
Andew Jones 32aa43d1df Split and replace in wren. 2017-03-07 21:15:06 -05:00
Bob Nystrom 18f8f48bb6 Docs for configuring the VM. 2017-02-12 11:04:38 -08:00
Thorbjørn Lindeijer f5d9443d0a Added Sequence.take and Sequence.skip
These lazy iterator producing methods are useful when working with
arbitrary sequences and you need to skip or take some number of elements
at the start.
2017-02-10 21:43:59 +01:00
Bob Nystrom 3faec25c4c Merge branch 'num-features' of https://github.com/underscorediscovery/wren into underscorediscovery-num-features 2017-01-20 07:20:55 -08:00
scott cdce553f5a fixed new api issue in cli 2017-01-19 22:58:52 -05:00
scott dc2f2d9e41 support for user defined state data associated with the WrenVM object 2017-01-19 22:54:25 -05:00
Bob Nystrom 5ddd783ff5 Use strtoll() for hex literals to handle 64-bit ones even on 32-bit. 2017-01-12 21:53:21 -08:00