summaryrefslogtreecommitdiffhomepage
path: root/ast.h
AgeCommit message (Collapse)Author
2020-10-19eval: record correct source contexts in call stackJo-Philipp Wich
Also handle calls to C functions. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-10-18ast, eval: add recursion limitJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-10-18eval: fix segmentation faults with self-invoking functionsJo-Philipp Wich
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>
2020-10-14treewide: unify error handlingJo-Philipp Wich
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>
2020-10-14treewide: rework source file and callstack handlingJo-Philipp Wich
- 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>
2020-10-14lexer: rewriteJo-Philipp Wich
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>
2020-10-06treewide: rework exception context formattingJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-10-06ast, eval: track current file name across function invocationsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-10-05ast: add helpers to set error token bitsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-10-04treewide: rework function scopingJo-Philipp Wich
- 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>
2020-10-02ast: store function declarations as opcode offsetsJo-Philipp Wich
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>
2020-10-02treewide: rework handling of memory allocation failuresJo-Philipp Wich
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>
2020-10-02main: track current template filename during executionJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-26lib: implement '%J' printf formatJo-Philipp Wich
The `%J` format allows outputting values as valid JSON string. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-24syntax: add regular expression supportJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-24main: support invoking utpl interpreter through shebangJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-21treewide: ensure to properly propagate exceptionsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-20treewide: rework extended type handlingJo-Philipp Wich
Register prototype object directly together with the type instead of setting it manually whenever an extended type value is instantiated. This also allows freeing the various prototype objects in dlopened modules. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-20Revert "treewide: rework exception handling"Jo-Philipp Wich
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>
2020-09-16treewide: implement strict assignment modeJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-16treewide: rework exception handlingJo-Philipp Wich
Use setjmp() and longjmp() to deal with runtime exceptions. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-13syntax: fix for() loop quirks and variable scopingJo-Philipp Wich
- Support `for (var x in ...)` syntax - Support `for (var i = 0; i < ...; i++)` syntax - Properly handle "for" loops without condition and increment expression - Reject for-in loops with invalid lhs Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-11ast: implement inline ut_is_type() helperJo-Philipp Wich
The ut_is_type() function simplifies checking the extended tag type of a given JSON object value. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-10treewide: implement default lstrip_blocks and trim_blocks behaviourJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-10treewide: eliminate unused function argumentsJo-Philipp Wich
Also introduce convenience macro for registering function arrays in modules. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-08parser, eval: use an ut_op flag to denote postfix accessJo-Philipp Wich
The current code still abused the JSON value pointer to denote postfix access for certain operations which led to a crash when freeing the parser state due to an attempt to put a (void *)1 pointer. Since we do have the ability to set flags on operations since the AST rework, use this much cleaner approach and avoid the invalid pointer hackery. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-07ast, eval, lexer: keep track of overflows when parsing numbersJo-Philipp Wich
This allows number literals that exceed the range INT64_MIN..INT64_MAX to be truncated to the respective min and max values in a defined manner. It also makes it possible to have the expression `{{ -9223372036854775808 }}` actually result in `-9223372036854775808`. Since negation and number declaration are separate operations, the value would be first truncated to `9223372036854775807` and then negated, making it impossible to write a literal INT64_MIN value without tracking the overflow. Also fix the number parsing logic to not trucate intergers to 32bit. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-06treewide: refactor internal AST structuresJo-Philipp Wich
- unify operand and value tag structures - use a contiguous array for storing opcodes - use relative offsets for next and children ops - defer function creation to runtime - rework "this" context handling by storing context pointer in scope tags Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-02treewide: rename double and null value constructor functionsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-02ast, eval: add tagged object handlingJo-Philipp Wich
In order to implement prototype chains later on, introduce a tagged object value type and use it when processing object declarations. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-02ast: add functionality to deal with extended data typesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-08-25treewide: introduce this keywordJo-Philipp Wich
Support a new keyword `this` which allows functions to access the context they're called upon. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-08-21Initial commitJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>