Age | Commit message (Collapse) | Author |
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Support per-file and per-function `"use strict";` statement to opt into
strict variable handling from ucode source code.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
- Ensure that split by string produces an initial empty string in the
result array when the string to split starts with the split substring
- Ensure that split by string produces a trailing empty string in the
result array when the string to split ends with the split substring
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
- Shuffle typedefs to avoid need for non-compliant forward declarations
- Fix non-compliant empty struct initializers
- Remove use of braced expressions
- Remove use of anonymous unions
- Avoid `void *` pointer arithmetic
- Fix several warnings reported by gcc -pedantic mode and clang 11 compilation
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Print "Before start of program" for errors that are raised before entering
main(), e.g. on module preloading failure.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
This is required for out-of-tree builds where the *.so file location
cannot be derived from the path of the ucode executable.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Instead of relying on json_object values internally, use custom types to
represent the different ucode value types which brings a number of
advantages compared to the previous approach:
- Due to the use of tagged pointers, small integer, string and bool
values can be stored directly in the pointer addresses, vastly
reducing required heap memory
- Ability to create circular data structures such as
`let o; o = { test: o };`
- Ability to register custom `tostring()` function through prototypes
- Initial mark/sweep GC implementation to tear down circular object
graphs on VM deinit
The change also paves the way for possible future extensions such as
constant variables and meta methods for custom ressource types.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
* add cram based tests
* test under either valgrind or LLVM sanitizers
* add libFuzzer template
Signed-off-by: Petr Štetiar <ynezz@true.cz>
|
|
Otherwise tests always pass in ctest.
Signed-off-by: Petr Štetiar <ynezz@true.cz>
|
|
Signed-off-by: Petr Štetiar <ynezz@true.cz>
|
|
Fixes: 97bf297 ("compiler: ensure that alternative if/for/while syntax has own block scope")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
The `if ...: endif`, `for ...: endfor`, `while ...: endwhile` etc. syntax
statements are supposed to have their own lexical scope, like curly brace
blocks in normal statements.
Without this, local variable declarations within such blocks would
incorrectly shift stack offsets for the remainder of the program.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Fixes: aa9621d ("compiler: rework switch statement code generation")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
When patching jump targets for break statments while compiling for-loop
statments, jump beyond the instructions popping intermediate loop variables
off the stack to fix a stack position mismatch between compiler and vm.
Before that change, local loop body variables got popped twice, breaking
the expected stack layout.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
When skipping over the catch block of a try/catch statement, make sure to
emit the jump after the try scope variables have been popped off the stack
in order to prevent a stack position mismatch between compiler and vm.
Fixes: 9ad9afb ("compiler: fix try/catch miscompilation")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Since libjson-c's json_object_get_int64() returns 0 for any input value
that has no integer representation, any kind of invalid array index
incorrectly yielded the first array element.
Fix this issue by explicitly converting string values and by rejecting
any other kind of value.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Ensure that an arrow function body expression is parsed with P_ASSIGN
precedence to not greedily consume comma expressions.
This ensures that an expression like
() => 1, 2
is parsed as function [() => 1], integer [2] and not as
function [() => 1, 2].
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
A logic flaw in the lineinfo encoding function led to an infinite tight
loop when a buffer chunk with 128 byte or more got consumed, which may
happen when parsing very long literals.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
While parsing string literals, actually consume the backslash introducing an
escape sequence to prevent it from ending up in the produced string if the
scanner is at the end of the buffer and the remaining buffer contents are
flushed after the consumer loop.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
When a module registering custom ressource types, such as "fs.so", is
required multiple times we need to ensure that only one instance of a
given ressource type is registered, otherwise objects created after
subsequent requires will cease to function since the internal type
prototype mismatches.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Before this fix, the VM aborted due to an assert in libjson-c when an
attempt was made to set a property on a non-object value.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Simplify handling of default case in switch statements. Instead of jumping
over the default block, simply record the start address of the block since
the initial switch jump is patched into the first non-default case already.
This also leads to slightly smaller bytecode.
Previously, when a case branch fell through into a default block, it did
hit the default skip jump which jumped back into the first case which then
fell through into the default skip jump, leading to an endless loop.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
When skipping catch blocks with exception variables, jump beyond the
instruction popping the exception variable off the stack to fix a
stack position mismatch between compiler and vm.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Replace the former AST walking interpreter implementation with a single pass
bytecode compiler and a corresponding virtual machine.
The rewrite lays the groundwork for a couple of improvements with will be
subsequently implemented:
- Ability to precompile ucode sources into binary byte code
- Strippable debug information
- Reduced runtime memory usage
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
- Eliminate dead code left after regex literal parsing changes
- Properly handle short octal sequences at end of string
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Ensure that the single char escapes `\a`, `\b`, `\e`, `\f`, `\n`,
`\r`, `\t` and `\v` keep working. Since they're not part of the POSIX
extended regular expression spec, they're not handled by the RE engine
so we need to substitute them by their actual byte value while parsing
the literal.
Fixes: ac5cb87 ("syntax: fix string and regex literal parsing quirks")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
- Do not interprete escape sequences in regexp literals
- Do not improperly substitute control escape sequences such as
`\n` or `\a` after a backslash
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Fixes: 8b4d0d5 ("tests: prefer `let` over `local`")
Fixes: a162cf7 ("treewide: rebrand to ucode")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Promote the use of `let` to move ucode examples closer to ES syntax.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Do not emit dummy T_ASSIGN nodes for plain variable declarations without
initialization (`let foo` or `local foo`).
This also allows simplifying `ut_check_for_in()` since we only need to
deal with one common structure for both `for (... in ...)` and
`for (local ... in ...)` cases.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Ensure that a call like `fn((1, 2), 3)` invokes the function with arguments
`2, 3` and not `1, 2, 3`.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Tune the grammar and rework the VM to properly yield the last result of
list expressions in various contexts.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
In the alternative `if` syntax mode, support a specific `elif` keyword instead
of requiring an `else` branch followed by a disjunct `if` statement.
The advantage is that templates do not require error-prone redundant `endif`
keywords in else-if ladders.
After this change, the following example:
{% if (...): %}
One condition
{% else if (...): %}
Another condition
{% else if (...): %}
A third condition
{% else %}
Final condition
{% endif; endif; endif %}
... can be simplified into:
{% if (...): %}
One condition
{% elif (...): %}
Another condition
{% elif (...): %}
A third condition
{% else %}
Final condition
{% endif %}
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Also handle calls to C functions.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|