summaryrefslogtreecommitdiffhomepage
AgeCommit message (Collapse)Author
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-20eval: fix leaking calculated object keysJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-20eval: fix double free of env valuesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-20ast: fix context value leakJo-Philipp Wich
Free any remaining context value when freeing the runtime state. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-20main: fix memory leak with -e optionJo-Philipp Wich
Release the parsed intermediate object after copying its values into the global env object. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-20eval: implement -m option to preload modulesJo-Philipp Wich
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>
2020-09-20eval: improve reference error reportingJo-Philipp Wich
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-17eval: sanitize variable namesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-16eval: implement -e and -E options to set global vars from JSONJo-Philipp Wich
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-15tests: add test for "this" contextJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-15eval: only set "this" scope for functions being object membersJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-14tests: add initial runtime testsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-14eval: increase refcount when reading function contextJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-13tests: extend for-loop tests to cover local variantsJo-Philipp Wich
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-13eval: use ut_getscope() in ut_execute_local()Jo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-13eval: make key argument to ut_getref() optionalJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-12eval: improve error messages on null dereferenceJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-12eval: keep references to function contextsJo-Philipp Wich
Otherwise the "this" context might be gc'ed before the function can access it. This bug manifested itself with long chained expressions such as: require("fs").open("file.txt").read(10) The file handle produced by open() was gc'ed before invoking read() on it due to the evaluation not increasing its refcount. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-11lib: add iptoarr() and arrtoip() functionsJo-Philipp Wich
These functions allow converting IP addresses to and from arrays of byte values respectively. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-11syntax: introduce !== and === operatorsJo-Philipp Wich
Also treat "in" as relational operator. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-11fs: implement getcwd() and chdir()Jo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-11lib: move math functions to new moduleJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-11eval: eliminate use of ceil()Jo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-11lib: expose ut_new_double() and ut_cast_number() in the module interfaceJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-09-11lib: implement uci pluginJo-Philipp Wich
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-11lib: expose ut_invoke() in the module interfaceJo-Philipp Wich
This allows invoking other functions from module code. 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-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>