summaryrefslogtreecommitdiffhomepage
AgeCommit message (Collapse)Author
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-10eval: fix function return value handling in expressionsJo-Philipp Wich
Since ut_invoke() takes care of unwrapping magic null, we don't need any special treatment for T_RETURN tags when processing expressions. Also drop T_BREAK case while we're at it since it cannot happen in this context. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-10eval: fix [] subscript operatorJo-Philipp Wich
Fixes: c735882 ("parser, eval: use an ut_op flag to denote postfix access") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-10main: fix dumping ASTJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-10build: test whether json_object_array_shrink() is availableJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-10eval: rename "main" to "entry"Jo-Philipp Wich
Fixes the following gcc error: .../eval.c:1435:22: error: 'main' is usually a function [-Werror=main] struct json_object *main, *scope, *args, *rv; ^~~~ cc1: all warnings being treated as errors Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-10build: update .gitignoreJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-10lib: add ubus moduleJo-Philipp Wich
Also move shared library output files to the lib/ directory Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-10build: add missing module headerJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-09fs: implement popen()Jo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-08fs: rename readdir() and closedir() to read() and close() respectivelyJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-08fs: fix file seek() return valueJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-08fs: fix crash when closing file handle twiceJo-Philipp Wich
We need to clear the file handle pointer after closing the file to avoid invoking the dtor later. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-08fs: implement seek() and tell() for directory handlesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-08ast: only invoke extended type dtor if data pointer is setJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-08lib: make type() report extended types as "ressource"Jo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-08tests: add further arithmetic and syntax test casesJo-Philipp Wich
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-07tests: add object/array literal and arithmetic test casesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-07eval: ensure that dividing Infinity by Infinity yields NaNJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-07eval: ensure that x / NaN yields NaNJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-07tests: introduce testcasesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-07main: fix segfault when passed source file is emptyJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-07eval: fix segmentation when attempting to concat a string with nullJo-Philipp Wich
A typo in the code lead to a null pointer dereference. 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-07eval: adjust results for arithmetic division by nan, infinityJo-Philipp Wich
Follow ECMAScript logic. Division by zero yields infinity, division by infinity yields zero. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-07lexer: fix encoding of unicode surrogate pairsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-06fs: use ARRAY_SIZE macroJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-06fs: add further filesystem functionsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-06parser: do not reallocate function opcodesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-06parser: make final semicolon optionalJo-Philipp Wich
Modify the grammar to allow omitting the last semicolon after the last statement of a compound statement. 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-02lib: introduce filesystem moduleJo-Philipp Wich
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-02eval, lib: add loadable module infrastructureJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-02eval: properly increase/decrease refcounts when dealing with scopesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-02eval: traverse prototype chain when resolving object propertiesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-02eval, lib: use tagged JSON objects to register C functionsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-02eval: treat exception values as falseJo-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: add proper null value handlingJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-08-25eval.c: fix segfault when attempting to resolve invalid lhsJo-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-25eval.c: properly propagate exceptions when resolving referencesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-08-25lexer.h: add T_RESSOURCE op typeJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-08-25lib.c: move ut_add_function() to headerJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-08-25treewide: add dedicated T_CFUNC typeJo-Philipp Wich
Tag C function values with a dedicated T_CFUNC type to clearly differentiate them from runtime declared functions. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-08-25main.c: do not dump operands of extended opcodesJo-Philipp Wich
Extendend opcodes might have non-opcode operands which we cannot safely dereference. Signed-off-by: Jo-Philipp Wich <jo@mein.io>