summaryrefslogtreecommitdiffhomepage
path: root/tests
AgeCommit message (Collapse)Author
2022-01-26vallist: uc_number_parse(): parse empty strings as `0`, not `NaN`Jo-Philipp Wich
Fixes: b605dbf ("treewide: rework numeric value handling") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-01-26vm: fix `null` loose equality/inequality checksJo-Philipp Wich
The current implementation incorrectly yielded `true` for `0 == null` but only `null` must be equal to `null`. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-01-26tests: reorganize testcase filesJo-Philipp Wich
- Rename 03_bugs to 04_bugs - Rename 26_invalid_sparse_array_set to 27_invalid_sparse_array_set Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-01-26run_tests.sh: add ability to define environment variables for testcasesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-01-26run_tests.sh: fix exitcode evaluationJo-Philipp Wich
The `touch` command result incorrectly shadowed the testcase exit code. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-01-18program: implement support for precompiling source filesJo-Philipp Wich
- Introduce new command line flags `-o` and `-O` to write compiled program code into the specified output file - Add support for transparently executing precompiled files, the lexical analyzing and com,pilation phase is skipped in this case Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-01-04treewide: rework numeric value handlingJo-Philipp Wich
- Parse integer literals as unsigned numeric values in order to be able to represent the entire unsigned 64bit value range - Stop parsing minus-prefixed integer literals as negative numbers but treat them as separate minus operator followed by a positive integer instead - Only store unsigned numeric constants in bytecode - Rework numeric comparison logic to be able to handle full 64bit unsigned integers - If possible, yield unsigned 64 bit results for additions - Simplify numeric value conversion API - Compile code with -fwrapv for defined signed overflow semantics Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-12-01syntax: disallow keywords in object property shorthand notationJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-10-11syntax: introduce optional chaining operatorsJo-Philipp Wich
Introduce new operators `?.`, `?.[…]` and `?.(…)` to simplify looking up deeply nested property chain in a secure manner. The `?.` operator behaves like the `.` property access operator but yields `null` if the left hand side is `null` or not an object. Like `?.`, the `?.[…]` operator behaves like the `[…]` computed property access but yields `null` if the left hand side is `null` or neither an object or array. Finally the `?.(…)` operator behaves like the function call operator `(…)` but yields `null` if the left hand side is `null` or not a callable function. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-09-21types: fix invalid memory access on setting non-contiguous array indexesJo-Philipp Wich
When setting an array index which is beyond the end of the last currently preallocated chunk and not evenly divisible by the chunk size, the array entries list was not properly reallocated, resulting in invalid memory writes. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-09-19compiler: properly handle jumps to offset 0Jo-Philipp Wich
When compiling certain expressions as first statement of an ucode program, e.g. a while loop in raw mode, a jump instruction to offset zero is emitted which was incorrectly treated as placeholder by the compiler. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-09-19tests: support specifying cmdline args in testcase filesJo-Philipp Wich
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-11main: introduce new flag `-x` to allow disabling specific functionsJo-Philipp Wich
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-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: extend API to allow returning result value from VM executionJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-05-25lexer: implement raw code modeJo-Philipp Wich
Enabling raw code mode allows writing ucode scripts without any template tag decorations (that is, without the need to provide an initial opening '{%' tag). 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-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-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-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-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-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-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-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-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-24tests: allow executing run_tests.sh from any directoryJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
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-23tests: create custom tests from current tests casesPetr Štetiar
Signed-off-by: Petr Štetiar <ynezz@true.cz>
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-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-23compiler: fix another try/catch miscompilationJo-Philipp Wich
When skipping over the catch block of a try/catch statement, make sure to emit the jump after the try scope variables have been popped off the stack in order to prevent a stack position mismatch between compiler and vm. Fixes: 9ad9afb ("compiler: fix try/catch miscompilation") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-19value: fix accessing array indexes with non-numeric valuesJo-Philipp Wich
Since libjson-c's json_object_get_int64() returns 0 for any input value that has no integer representation, any kind of invalid array index incorrectly yielded the first array element. Fix this issue by explicitly converting string values and by rejecting any other kind of value. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-12compiler: fix parsing of arrow functions with single expression bodyJo-Philipp Wich
Ensure that an arrow function body expression is parsed with P_ASSIGN precedence to not greedily consume comma expressions. This ensures that an expression like () => 1, 2 is parsed as function [() => 1], integer [2] and not as function [() => 1, 2]. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-11lexer: fix infinite loop in lineinfo encoding when consuming large chunksJo-Philipp Wich
A logic flaw in the lineinfo encoding function led to an infinite tight loop when a buffer chunk with 128 byte or more got consumed, which may happen when parsing very long literals. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-03-11lexer: properly handle string escape sequences at buffer boundaryJo-Philipp Wich
While parsing string literals, actually consume the backslash introducing an escape sequence to prevent it from ending up in the produced string if the scanner is at the end of the buffer and the remaining buffer contents are flushed after the consumer loop. Signed-off-by: Jo-Philipp Wich <jo@mein.io>