summaryrefslogtreecommitdiffhomepage
AgeCommit message (Collapse)Author
2021-05-15fs: implement chmod(), chown(), rename() and glob() functionsJo-Philipp Wich
- The chmod() function expects a path string as first and an integer mode value as second argument. - The chown() function takes a path string as first argument, and either a string, an integer or null as second user and third group argument respectively. If either user or group are given as string, they're resolved to an uid/gid using getpwnam()/getgrnam() internally. If either lookup fails, the ownership change is not performed. If either user or group are null or -1, they're left unchanged. - The rename() function takes two path strings, the old path being the first argument and the new path the second one. - The glob() function takes an arbitrary number of glob patterns and resolves matching files for each one. In case of multiple patterns, no efforts are made to remove duplicates or to globally sort the combined match list. The list of matches for each individual pattern is sorted. Returns an array containing all matched file paths. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-05-14lexer: skip interpreter line in any source bufferJo-Philipp Wich
Skip interpreter lines in any source buffer and handle the skipping in the lexer itself, to avoid reporting wrongly shifted token offsets to the compiler, resulting in wrong error locations and source contexts. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-05-14build: lower minimum required CMake version to v3.13Jo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-05-14main: expose argv as global ARGV array to ucode scriptsJo-Philipp Wich
This allows accessing the arguments of the invoked command line. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-05-11tests: rename misnamed testcases for consistencyJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-05-11compiler: fix local for-loop initializer variable declarationsJo-Philipp Wich
In a loop statement like `for (let x = 1, y = 2; ...)` the initialization statement was incorrectly interpreted as `let x = 1; y = 2` instead of the correct `let ..., y = 2`, triggering reference error exceptions in strict mode. Solve the issue by continue parsing the rest of the comma expression seqence as declaration list expression when the initializer is compiled in local mode. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-05-11compiler: properly parse slashes in parenthesized division expressionsJo-Philipp Wich
Due to the special code path parsing the leading label portion of a parenthesized expression, slashes following a label were improperly treated as regular expression literal delimitters, emitting a syntax error when an otherwise valid expression such as `a / 1` was being parsed as first sub expression of a parenthesized expression. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-05-11lib: implement regexp(), a function to construct regexp instances at runtimeJo-Philipp Wich
Provide a new ucode function regexp() which allows constructing regular expression instances from separate source and flag strings. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-05-10Merge pull request #10 from jow-/introduce-render-fnJo-Philipp Wich
Introduce render() function
2021-05-10lib: implement render(), an include variant capturing output in a stringJo-Philipp Wich
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-07lib: fix uc_sort()Jo-Philipp Wich
The internally used qsort(3) expects [-n, 0, n] return values from the comparator function instead of a true/false value to denote lower than or equal results. 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-05compiler: properly handle break/continue in nested scopesJo-Philipp Wich
When emitting byte code for break or continue statements, ensure that local variables in all containing scopes up to the loop body scope are popped, not just those in the same scope the statement is located in. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-05-04compiler: properly handle keyword in parenthesized property access expressionJo-Philipp Wich
Due to the special code path parsing the leading label portion of a parenthesized expression, keywords following a property access operator (TK_DOT, `.`) weren't properly handled, emitting a syntax error when an otherwise valid expression such as `value.default` was being parsed as first sub expression of a parenthesized expression. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-05-04compiler: fix stack mismatch on compiling `use strict` statementsJo-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-04Merge pull request #9 from jow-/remove-unused-struct-membersJo-Philipp Wich
vm, compiler: get rid of unused struct members
2021-05-04Merge pull request #7 from jow-/introduce-assertJo-Philipp Wich
lib: implement assert()
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-05-04lib: implement assert()Jo-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>