summaryrefslogtreecommitdiffhomepage
path: root/vm.c
AgeCommit message (Collapse)Author
2021-05-18syntax: implement `delete` as proper operatorJo-Philipp Wich
Turn `delete` into a proper operator mimicking ECMAScript semantics. Also ensure to transparently turn deprecated `delete(obj, propname)` function calls into `delete obj.propname` expressions during compilation. When strict mode is active, legacy delete() calls throw a syntax error instead. Finally drop the `delete()` function from the stdlib as it is shadowed by the delete operator syntax now. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-05-10vm: implement mechanism to change output file descriptorJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-05-07vm: truncate long values after 60 chars in trace outputJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-05-04Merge pull request #8 from jow-/introduce-use-strictJo-Philipp Wich
syntax: implement support for 'use strict' pragma
2021-05-04syntax: implement support for 'use strict' pragmaJo-Philipp Wich
Support per-file and per-function `"use strict";` statement to opt into strict variable handling from ucode source code. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-05-04vm, compiler: get rid of unused struct membersJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-27treewide: ISO C / pedantic complianceJo-Philipp Wich
- Shuffle typedefs to avoid need for non-compliant forward declarations - Fix non-compliant empty struct initializers - Remove use of braced expressions - Remove use of anonymous unions - Avoid `void *` pointer arithmetic - Fix several warnings reported by gcc -pedantic mode and clang 11 compilation Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-27vm: improve context for early errorsJo-Philipp Wich
Print "Before start of program" for errors that are raised before entering main(), e.g. on module preloading failure. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-26treewide: address various sign-compare warningsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-26types: support creating ressource values without associated typeJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-25treewide: rework internal data type systemJo-Philipp Wich
Instead of relying on json_object values internally, use custom types to represent the different ucode value types which brings a number of advantages compared to the previous approach: - Due to the use of tagged pointers, small integer, string and bool values can be stored directly in the pointer addresses, vastly reducing required heap memory - Ability to create circular data structures such as `let o; o = { test: o };` - Ability to register custom `tostring()` function through prototypes - Initial mark/sweep GC implementation to tear down circular object graphs on VM deinit The change also paves the way for possible future extensions such as constant variables and meta methods for custom ressource types. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-29vm: add trace mode instruction dump output fixesJo-Philipp Wich
- Fix an off-by-one when printing push/pop stack indexes - Properly print negative hexadecimal values Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-26vm: fix another for-loop memory leakJo-Philipp Wich
Fixes: 20a3763 ("vm: fix loop variable memory leak in NEXTK/NEXTKV instruction") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-25vm: fix further memory leaks in trace modeJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-25vm: fix loop variable memory leak in NEXTK/NEXTKV instructionJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-23vm: fix leaking source context strings in trace modeJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-11vm: gracefully handle property setting on non-array, non-object valuesJo-Philipp Wich
Before this fix, the VM aborted due to an assert in libjson-c when an attempt was made to set a property on a non-object value. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08vm: use uc_prototype_lookup() to obtain require function pointerJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-08vm: fix global scope refcount imbalanceJo-Philipp Wich
The uc_vm_execute() API function decreases the refcount of the globals object when finishing but does not increase it initially which leads to a double free at main.c:155 Fix the issue by both increasing and decreasing the refcount. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-02-25vm: use portable printf format for pointer differencesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-02-17treewide: rewrite ucode interpreterJo-Philipp Wich
Replace the former AST walking interpreter implementation with a single pass bytecode compiler and a corresponding virtual machine. The rewrite lays the groundwork for a couple of improvements with will be subsequently implemented: - Ability to precompile ucode sources into binary byte code - Strippable debug information - Reduced runtime memory usage Signed-off-by: Jo-Philipp Wich <jo@mein.io>