Age | Commit message (Collapse) | Author |
|
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>
|
|
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>
|
|
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>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Also handle calls to C functions.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Since we're invoking ut_execute_op() to obtain the assignment value, the
operand pool might have been reallocated at a different memory address,
invalidating the label opcode pointer.
Obtain a reference to the underlying json label value and re-obtain
the assignment opcode pointer with each iteration to avoid dereferencing
stale pointers.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Store the invocation scope and function context in the call stack frame
and not in the function object to properly deal with recursive invocations.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
When a for() loop body, initializer, test or increment expression compiles
further code, e.g. by invoking invoke() or require(), the opcode pool will
be reallocated, potentially changing the addresses of all opcodes.
This might lead to an invalid memory access when previously cached opcode
pointers are accessed later on.
Solve this issue by obtaining the relative offsets of the corresponding
opcodes, avoiding the need for pointer dereferences.
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>
|
|
Get rid of the distinction between lexer/parser errors and runtime
exceptions, use exceptions everywhere instead.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
- Keep an open FILE* reference to processed source files in order to
be able to rewind and extract error context later
- Build a proper call stack when invoking utpl functions
- Report call stack in exceptions
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Refactor the central ut_parse_op() function to use a jump table for
invoking the proper operand handler function in order to reduce the
compiled code size.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Rewrite the lexer into a restartable state machine to support parsing from
file streams without the need to read the entire source text into memory
first.
As a side effect, the length of labels and strings is unlimited now.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
When an expression such as `foo.bar(a.b, c.d)` is evaluated, the state
context pointer will point to `c` while we need `foo` when invoking
functions.
Since the context pointer is only relevant for function calls and since
for function call opcodes, the lhs expression is always the first operand,
there is no need to store the context of subsequent ops.
Adjust the ut_get_operands() procedure to restore state->ctx to the result
of the first evaluated operand.
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>
|
|
- Implement proper closure scoping for function
- Avoid circular references when managing scopes pointers
- Eliminate ut_putval() in favor to json_object_put()
- Fix function return value handling
- Change internal function structure
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>
|
|
We cannot use direct pointers since the opcode array might be reallocated
resulting in potentially changed memory addresses.
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>
|
|
This reverts commit 206630d7141f32594e9110081f6710446f5aebd3.
Revert this commit to fix a double-free.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Instead of propagating failures to the caller, print a generic error
message and terminate program execution through abort().
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>
|
|
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>
|
|
The -m option instructs the interpreter to automatically require the named
module and to register the module context as global variable.
The following two commands are equivalent, with the former one serving as
a shortcut for the latter:
utpl -m fs -s '{{ fs.open("test.txt").read("all") }}'
utpl -s '{% fs = require("fs"); print(fs.open("test.txt").read("all")) %}'
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
This reverts commit 54bb15b2be3656e91386b80074f45591b20fed3f.
Relying on setjmp() / longjmp() causes too many headaches trying to track
and properly release intermediate values.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|