summaryrefslogtreecommitdiffhomepage
AgeCommit message (Collapse)Author
2021-09-14ci: adjust build prereqs for GitHub as wellJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-09-14ci: add libnl-tiny to prereqsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-30vm: fix toplevel function call protocolJo-Philipp Wich
In success case, always push the function return value onto the stack even if no call frames are remaining after the function returned. This is needed for host program code invoking ucode functions within a VM context that already ran to completion. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-28fs: fix chown() and rename() error return valuesJo-Philipp Wich
Fixes: dfb7379 ("fs: implement chmod(), chown(), rename() and glob() functions") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-28tests: disable fuzz tests for nowJo-Philipp Wich
The Fuzz test implementation so far is just boilerplate and fails due to imposed memory limits on the CI runner. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-27types: mark further GC rootsJo-Philipp Wich
Mark reachable native function and ucode function objects during incremental GC steps in order to avoid freeing them prematurely. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-27types: fix comparison of differently signed integersJo-Philipp Wich
Fixes: c79ff39 ("types: handle conversion errors when dealing with negative error indexes") Fixes: 3315b1f ("types: allow negative array indexes") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-27types: handle conversion errors when dealing with negative error indexesJo-Philipp Wich
Also apply the same logic to array set operations. Fixes: 3315b1f ("types: allow negative array indexes") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-27types: allow negative array indexesJo-Philipp Wich
Support array[-1], array[-2] etc. to retrieve elements relative to the end of the array values. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11Merge pull request #15 from jow-/c-apiJo-Philipp Wich
C API wip
2021-07-11treewide: harmonize function namingJo-Philipp Wich
- Ensure that most functions follow the subject_verb naming schema - Move type related function from value.c to types.c - Rename value.c to vallist.c Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11module: remove unused definesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11examples: add libucode usage examplesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11types, vm: adjust GC apiJo-Philipp Wich
Provide separate public ucv_gc() and ucv_freeall() functions to perform an incremental and complete GC run respectively. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11treewide: move header files into dedicated directoryJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11build: install header filesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11main: introduce new flag `-x` to allow disabling specific functionsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11vm: fix invalid memory access on GC'ing uninitialized VM contextJo-Philipp Wich
When attempting to invoke uc_vm_free() or uc_gc() on a uc_vm_t struct that has not been initialized by uc_vm_init(), the circular double linked value list is not set up, causing the GC to read invalid memory locations when attempting to traverse the object list. Back out early when the list heads are not properly set up in order to prevent this issue. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11main: refactor option parsing and VM setupJo-Philipp Wich
Set VM options and environment variables and load modules on the fly while parsing the cli options instead of aggregating all the values in memory first. This vastly reduces the amount of arguments we need to pass to the parse() function. Also rename parse() to compile() while we're at it. Also slightly adjust the usage output. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11treewide: consolidate typedef namingJo-Philipp Wich
Ensure that all custom typedef and vector declaration type names end with a "_t" suffix. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11vm: add API to control trace modeJo-Philipp Wich
Add a public getter and setter to read and set the VM trace level respectively. Use the new API to control the trace mode with a newly introduced `-t` command line switch. Drop support for honouring the `TRACE` environment variable as host programs embedding ucode might want to prevent that behaviour or handle it differently. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11vm: make root exception handler configurableJo-Philipp Wich
So far, the VM simply printed exception information to stderr if the exception was not catched in managed code. Host programs embedding ucode might want to customize that behaviour, so refactor the current defualt behaviour into a callback function and add a public getter and setter to allow changing the exception handler callback. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11vm: fix invalid memory access on toplevel function callsJo-Philipp Wich
When a function is invoked directly, e.g. through uc_vm_invoke(), the call stack is empty, so avoid accessing the first call frame unless we actually need to, which is only the case if the function is invoked with spread args which can only happen with calls from manged code. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11vm: fix handling exceptions in top-level function callsJo-Philipp Wich
When a toplevel function call raises an exception, the call stack will be empty when invoking the exception handler, ensure to handle this case appropriately. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11lib, vm: reimplement exit() as exception typeJo-Philipp Wich
Instead of invoking exit(3) from uc_exit(), use a new EXCEPTION_EXIT exception type to instruct the VM to shutdown cleanly. This is required to not terminate the host program in case libucode is embedded and loaded scripts invoke the exit() function. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11vm: extend API to allow returning result value from VM executionJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11vm: remove module preloading logicJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11main: preload modules ourselvesJo-Philipp Wich
Module preloading is a cli frontend specific feature, it does not belong into the VM API, therfore do the module preloading directly in main.c to allow removing the corresponding VM code in a subsequent commit. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11vm: add uc_vm_invoke() helperJo-Philipp Wich
The uc_vm_invoke() function simplifies calling a named ucode function with arbitrary arguments. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11vm: cosmetic fix for outputting exceptions without source contextJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11vm: move global scope allocation into uc_vm_init()Jo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11vm: add getter and setter for vm globals scopeJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11lib: rename uc_add_proto_functions() to uc_add_functions()Jo-Philipp Wich
The naming is an artifact from before the introduction of the new type system. In the current code, there is nothing special about prototypes, they're simple object values. Also introduce a new singular uc_add_function() convenience macro while we're at it. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11lib: expose stdlib function arrayJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11treewide: eliminate dead code and unused functionsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11treewide: replace a number of unnecessary type castsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11treewide: move ressource type registry into vm instanceJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-11build: split into libucode and ucode cliJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-10types: properly deal with circular data in GC mark phaseJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-09lexer: rename UT_ prefixed constants to UC_Jo-Philipp Wich
This is a cosmetic change to bring the code in line with the common prefix format of the other code in the tree. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-09types: fix wrong assert() on tearing down object treesJo-Philipp Wich
Only assert non-zero refcount for objects which haven't been marked for freeing yet. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-08vm: fix potential invalid memory access in uc_vm_get_error_context()Jo-Philipp Wich
If there's only native function calls on the call stack, the code incorrectly accessed an invalid memory location. Avoid that issue by stopping the search for non-native callframes before the last frame. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-07lib: fix refcount imbalance in uc_require_path()Jo-Philipp Wich
Ensure to increase the refcount of the module scope value when caching it in the global module registry to avoid a double free on VM teardown. Fixes: 96f140b ("lib, vm: ensure that require() compiles modules only once") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-07lib, vm: ensure that require() compiles modules only onceJo-Philipp Wich
Cache the result of a successful require operation in a global.modules object and return the cached value for subsequent require calls on the same module name. This ensures that a given module is only compiled and executed once, regardless of how many times it is used. A reload of the module can be forced by deleting the corresponding key in the global module table. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-07-05compiler: don't segfault on invalid declaration expressionsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-06-29lexer: transition into EOF state on unrecognized characterJo-Philipp Wich
The compiler will keep fetching tokens until hitting EOF, so ensure that the lexer produces EOF after an unrecognized character error. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-06-08compiler: improve mapping of binary operator tokens to instructionsJo-Philipp Wich
Instead of relying on a switch/case mapping of token values to corresponding VM instructions, infer the instruction number arithmetically. This shrinks the compiled size on x86/64 by about 250 bytes. Also emit I_LE and I_GE instructions for `<=` and `>=` comparisons instead of transforming these into I_GT and I_LT negations. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-06-08vm: add support for I_LE and I_GE instructionsJo-Philipp Wich
Since we need to ensure that NaN values are properly handled, we cannot transform `x <= y` and `x >= y` into `!(x > y)` and `!(x < y)` respectively. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-06-08treewide: let uc_cmp() use instruction instead of token numbersJo-Philipp Wich
This allows us to drop some token->instruction mapping case switches in the VM. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-06-08lexer, vm: reorder token and instruction numbersJo-Philipp Wich
Ensure that relational operators in the lexer token and vm instruction lists are both ordered in the same way according to the general operator precedence of the grammar. Signed-off-by: Jo-Philipp Wich <jo@mein.io>