Avoids using multiple calls to fprintf() to print a single compile
error. This should make it easier to allow the host to provide a
callback function to print errors.
The compiler used to maintain all of the data that defines a function,
which it incrementally built up. Then, when it was done, it copied all
of that to a new ObjFn. In theory, that was to trim down some memory
and avoid unneeded fields in ObjFn.
In practice, the performance benefit is negligible and the memory saving
is nullified by the fact that it copies anyway.
This moves all of that mutable state directly into ObjFn. The compiler
creates a new empty ObjFn at the beginning and then just fills it in
in place.
This shaves off about 40 lines of code, is simpler, and doesn't seem to
impact perf.
My first attempt to embed VM in project ended with crash. Fortunately I'm not so easly scared and managed to found out that despite comment in "wren.h" no check for null is performed. I took the liberty of fixing that.
Btw. nice project, keep up the good work!
This is simpler than having special opcodes for them. It's also a bit
faster, and gets some non-critical code out of the interpreter loop.
Also, this is good prep work for being able to write some of the module
loading process in Wren to make things more flexible for embedders and
the CLI.
This is not implemented on Sequence because, at least for lists and
strings, I think users expect an eager result. Multiplying a string
should give you back a string, not a lazy sequence of repeated
characters.
This also mirrors "+" on strings and lists, which is eager. I like the
idea of having a general guideline that operators are eager.
Repetition is useful for arbitrary sequences, but for that maybe we
should add a "repeat()" method.
Instead of copying the uv_fs_stat struct to a list of Wren numbers, we
store it directly in the Stat object. This is important because we'll
need to implement later methods like isDirectory() in C so we can use
S_ISDIR(). For that, we need to have access to the original stat data.
Gets rid of the slightly ugly loadInstruction output parameter that
gets passed around. Now a reference to a variable is a first-class
concept in the compiler.