summaryrefslogtreecommitdiffhomepage
AgeCommit message (Collapse)Author
2021-05-04vm, compiler: get rid of unused struct membersJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-05-04Merge pull request #6 from jow-/printf-improvementsJo-Philipp Wich
String format improvements
2021-05-04lib: add support for pretty printing JSON to printf() and sprintf()Jo-Philipp Wich
Honour precision specifiers when parsing `J` format strings to enable or disable JSON pretty printing. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-05-04lib: gracefully handle truncated format strings in uc_printf_common()Jo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-29lexer: fix infinite loop on parsing unterminated commentsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-29lexer: fix infinite loop on parsing unterminated expression blocksJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-29lexer: fix infinite loop when parsing regexp literal at EOFJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-29compiler: fix segfault on parsing invalid pre/post increment expressionsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-29lib: fix reporting source context lines at EOFJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-29compiler, lexer: improve lexical state handlingJo-Philipp Wich
- Instead of disambiguating division operator vs. regexp literal by looking at the preceeding token, raise a "no regexp" flag within the appropriate parser states to tell the lexer how to treat a forward slash when parsing the next token - Introduce another "no keyword" flag which disables parsing labels into keywords when reading the next token and set it in the appropriate parser states. This allows using reserved names in object declarations and property access expressions Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-27lib: fix uc_split() quirksJo-Philipp Wich
- Ensure that split by string produces an initial empty string in the result array when the string to split starts with the split substring - Ensure that split by string produces a trailing empty string in the result array when the string to split ends with the split substring Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-27Merge pull request #5 from jow-/new-type-systemJo-Philipp Wich
New type system
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-27build: output error messages on test failuresJo-Philipp Wich
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-27tests: pass ucode library path through environmentJo-Philipp Wich
This is required for out-of-tree builds where the *.so file location cannot be derived from the path of the ucode executable. 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-26types: fix potential memory leaks and null pointer accessesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-26types: fix potential leak of key in ucv_object_add()Jo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-26main: fix ineffective EOF check in parse()Jo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-26lib: uc_system(): fix invalid free() of non-heap memoryJo-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-04-24treewide: fix issues reported by clang code analyzerJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-24tests: allow executing run_tests.sh from any directoryJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-23Add initial GitLab and GitHub CI supportPetr Štetiar
Uses currently proof-of-concept openwrt-ci[1] in order to: * improve the quality of the codebase in various areas * decrease code review time and help merging contributions faster * get automagic feedback loop on various platforms and tools - out of tree build with OpenWrt SDK on following targets: * ath79-generic * imx6-generic * malta-be * mvebu-cortexa53 - out of tree native build on x86/64 with GCC (versions 8, 9, 10) and Clang 11 - out of tree native x86/64 static code analysis with cppcheck and scan-build from Clang 11 1. https://gitlab.com/ynezz/openwrt-ci/ Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-23tests: add more testsPetr Štetiar
* add cram based tests * test under either valgrind or LLVM sanitizers * add libFuzzer template Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-23tests: custom: return exit code if tests failsPetr Štetiar
Otherwise tests always pass in ctest. Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-23cmake: do not output binaries into lib directoryPetr Štetiar
It doesn't work properly with out of tree builds etc. Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-23tests: create custom tests from current tests casesPetr Štetiar
Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-23main: provide just binary name in help outputPetr Štetiar
Otherwise it prints out complete path which is probably not desired and we would need to filter out paths in the test's output etc. Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-23lexer: fix incomplete struct initializersPetr Štetiar
Fixes bunch of following warnings: lexer.c:68:37: warning: missing field 'parse' initializer [-Wmissing-field-initializers] lexer.c:138:34: warning: missing field '' initializer [-Wmissing-field-initializers] Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-23cmake: enable extra compiler checksPetr Štetiar
Let's enforce additional automatic checks enforced by the compiler in order to catch possible errors during compilation. Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-23cmake: fix includes and librariesPetr Štetiar
So it can be built out of the tree. Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-23cmake: make 3.0 minimum versionPetr Štetiar
Probably using 3.0+ features anyway and should silence following warning: CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake. Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions. Signed-off-by: Petr Štetiar <ynezz@true.cz>
2021-04-21lib: implement sleep(ms) functionJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-01lib: allow parsing non-array, non-object value in json()Jo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-31compiler: actually expand block scope fix to for/while alt syntaxJo-Philipp Wich
Fixes: 97bf297 ("compiler: ensure that alternative if/for/while syntax has own block scope") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-31compiler: ensure that alternative if/for/while syntax has own block scopeJo-Philipp Wich
The `if ...: endif`, `for ...: endfor`, `while ...: endwhile` etc. syntax statements are supposed to have their own lexical scope, like curly brace blocks in normal statements. Without this, local variable declarations within such blocks would incorrectly shift stack offsets for the remainder of the program. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-30tests: add missing test case for fixed switch codegenJo-Philipp Wich
Fixes: aa9621d ("compiler: rework switch statement code generation") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-29compiler: rework switch statement code generationJo-Philipp Wich
- Initialize stack slots belonging to skipped local variable declarations - Group switch case value tests after switch statement body 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-25lib: prevent use-after-free after uc_shift()Jo-Philipp Wich
Make sure to increase the refcount of items being moved since the subsequent put operation will decrease it, prematurely freeing moved items which will lead to use-after-free errors later on. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-25object: free prototype object when registering existing ressource typeJo-Philipp Wich
Fixes: a478510 ("object: prevent registering the same ressource type multiple times") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-24compiler: fix for/break miscompilationJo-Philipp Wich
When patching jump targets for break statments while compiling for-loop statments, jump beyond the instructions popping intermediate loop variables off the stack to fix a stack position mismatch between compiler and vm. Before that change, local loop body variables got popped twice, breaking the expected stack layout. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-24lib: fix value refcount of uc_unshift() return valueJo-Philipp Wich
The ref count of the unshifted value returned by uc_unshift() must be increased in order to prevent a subsequent double free within the VM when the value eventually goes out of scope. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-23run_tests.sh: allow passing tests to run as argumentsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>