summaryrefslogtreecommitdiffhomepage
AgeCommit message (Collapse)Author
2023-02-01Merge pull request #140 from nbd168/rtnlJo-Philipp Wich
rtnl: add support for registering an uloop based listener
2023-01-31rtnl: add support for registering an uloop based listenerFelix Fietkau
Similar to nl80211 uloop listener Signed-off-by: Felix Fietkau <nbd@nbd.name>
2023-01-23Merge pull request #138 from nbd168/nl80211Jo-Philipp Wich
nl80211: add support for registering an uloop based listener
2023-01-23types: fix array unshift operations and add test coverageJo-Philipp Wich
- Fix `ucv_array_unshift()` improperly rejecting operation on empty arrays - Fix `uc_unshift()` improperly reversing maintaining argument order - Add missing test coverage for `push()`, `pop()`, `unshift()` and `shift()` array operations. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-01-20fs: implement `fs.pipe()`Jo-Philipp Wich
The `pipe()` function takes no arguments and will return a two element array containing open read- and write file descriptors for a newly created pipe. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-01-19nl80211: add support for registering an uloop based listenerFelix Fietkau
Can be used to capture nl80211 messages in an event driven program Signed-off-by: Felix Fietkau <nbd@nbd.name>
2023-01-19nl80211: refactor command bitmask handlingFelix Fietkau
- add missing overflow check - make array size dynamic - set all bits if command id is not specified - add helper function for filling command bits Signed-off-by: Felix Fietkau <nbd@nbd.name>
2023-01-16style: add .editorconfig fileJo-Philipp Wich
Add an `.editorconfig` file to the source root in order to document the preferred source code indentation style. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-01-09Merge pull request #137 from ynezz/ynezz/isattyJo-Philipp Wich
fs: add `isatty()` function
2023-01-09fs: add `isatty()` functionPetr Štetiar
Expose the `isatty(3)` libc function in the fs module to allow checking whether a file descriptor refers to a terminal. Signed-off-by: Petr Štetiar <ynezz@true.cz>
2023-01-09Merge pull request #136 from blogic/masterJo-Philipp Wich
nl80211: add support for NL80211_ATTR_MPATH_INFO
2023-01-09nl80211: add support for NL80211_ATTR_MPATH_INFOJohn Crispin
Signed-off-by: John Crispin <john@phrozen.org>
2023-01-07Merge pull request #134 from nbd168/thisvalJo-Philipp Wich
include: add uc_fn_thisval()
2023-01-06include: add uc_fn_thisval()Felix Fietkau
Can be used to get rid of a layer of pointer indirection in resource type handlers. Signed-off-by: Felix Fietkau <nbd@nbd.name>
2023-01-06build: make rtnl/nl80211 depend on linux instead of !APPLEFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2022-12-13README.md: various spelling and documentation fixesJo-Philipp Wich
Fixes: #132 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-12-02tests: fixup testcasesJo-Philipp Wich
Adjust expected testcase outputs after double format change in the previous commit. Fixes: 4c654df ("types: adjust double printing format") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-12-02types: adjust double printing formatJo-Philipp Wich
Change the printf format for formatting doubles from `%g` to `%.14g`. This matches the behaviour of Lua 5.1.5 with LNUM used on OpenWrt and ensures that expressions such as `print(31764740.0 / 100)` yield the expected `317647.4` result and not a truncated (rounded down) value of `317647`. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-29Merge pull request #131 from jow-/fix-logical-assignment-operators-2Jo-Philipp Wich
2022-11-29compiler: fix bytecode for logical assignments of propertiesJo-Philipp Wich
The compiler emitted incorrect bytecode for logical assignment operations on property expressions. The generated instructions left the stack in an unclean state when the assignment condition was not fulfilled, causing a stack layout mismatch between compiler and vm, leading to undefined variable accesses and other non-deterministic behavior. Solve this issue by rewriting the bytecode generation to yield an instruction sequence that does not leave garbage on the stack. The implementation is not optimal yet, as an expression in the form `obj.prop ||= val` will load `obj.prop` twice. This is acceptable for now as the load operation has no side effect, but should be solved in a better way by introducing new instructions that allow for swapping stack slots, allowing the vm to operate on a copy of the loaded value. Also rewrite the corresponding test case to trigger a runtime error on code versions before this fix. Fixes: fdc9b6a ("compiler: fix `??=`, `||=` and `&&=` logical assignment semantics") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-29Merge pull request #130 from jow-/fs-add-realpathJo-Philipp Wich
fs: add `realpath()` function
2022-11-29fs: add `realpath()` functionJo-Philipp Wich
Expose the `realpath(3)` libc function in the fs module to allow for canonicalizing file paths. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-29Merge pull request #129 from jow-/math-add-isnanJo-Philipp Wich
math: add isnan() function
2022-11-29math: add isnan() functionJo-Philipp Wich
Add a new `isnan()` convenience function to the math library which can be used to test if a given value is a NaN double. The same test can be realized without the math library by using a function similar to the following one: function isNaN(x) { return x != x; } Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-29Merge pull request #127 from jow-/uloop-done-in-tasksJo-Philipp Wich
uloop: terminate parent uloop in task child processes
2022-11-29Merge pull request #128 from jow-/lib-json-improve-trailing-garbage-handlingJo-Philipp Wich
lib: uc_json(): accept trailing whitespace when parsing strings
2022-11-29tests: relax sleep() testJo-Philipp Wich
Invoking `sleep(1000)` in the CI container often sleeps slightly longer than exactly 1000ms, causing the test output to mismatch. Relax the test requirement to simply ensure that t2 > t1. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-29lib: uc_json(): accept trailing whitespace when parsing stringsJo-Philipp Wich
Only raise a trailing garbage error if the given JSON source string is followed by a non white space character. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-29uloop: terminate parent uloop in task child processesJo-Philipp Wich
Ensure that the main process uloop is terminated within task child processes. Before this fix, using uloop in a task function would trigger invalid memory accesses in the parent process by notifying non-existing fd slots in the parent through the inherited shared epoll descriptor. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-23Merge pull request #126 from jow-/uci-autoload-packageJo-Philipp Wich
uci: auto-load package in `ctx.foreach()` and `ctx.get_first()`
2022-11-23Merge pull request #125 from jow-/arrow-functions-blocks-no-returnJo-Philipp Wich
compiler: ensure that arrow functions with block bodies return no value
2022-11-23uci: auto-load package in `ctx.foreach()` and `ctx.get_first()`Jo-Philipp Wich
Functions that use `uci_lookup_ptr()` internally, such as `ctx.get()`, `ctx.set()` or `ctx.delete()`, implicitly load the given configuration name while the higher level functions `ctx.foreach()` or `ctx.get_first()` do not. This behaviour violates the principle of least surprise and might lead to non-deterministic program behavior as the outcome of these functions depends on prior uci operations performed on the cursor. Fix this issue by invoking `uci_load()` internally in case the given uci package name cannot be found in the cursor's package cache. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-22compiler: ensure that arrow functions with block bodies return no valueJo-Philipp Wich
Follow ES6 semantics and ensure that arrow functions with a block body don't implicitly return the value of the last executed statement. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-22Merge pull request #123 from jow-/fix-logical-assignment-operatorsJo-Philipp Wich
compiler: fix `??=`, `||=` and `&&=` logical assignment sementics
2022-11-15compiler: fix `??=`, `||=` and `&&=` logical assignment semanticsJo-Philipp Wich
When compiling logical assignment expressions, ensure that the right hand side of the assignment is not evaluated when the assignment condition is unfulfilled. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-11-04Merge pull request #120 from joshschmelzle/masterJo-Philipp Wich
add cmake to install requires for debian
2022-11-04add cmake to install requires for debianjsz
2022-10-18Merge pull request #118 from jow-/fs-read-getdelimJo-Philipp Wich
fs: expose `getdelim()` functionality through `fd.read()`
2022-10-18fs: expose `getdelim()` functionality through `fd.read()`Jo-Philipp Wich
When `fd.read()` is invoked with a single-character string argument, invoke `getdelim()` internally to read the input until the give character or EOF. This is useful for reading character delimited input data. For example `fd.read('\n')` will read any data up to the first newline (or EOF) while `fd.read('\0x00')` will read until the first null byte. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-10-08Merge pull request #115 from jow-/fs-use-getlineJo-Philipp Wich
fs: use `getline()` for line wise read operations
2022-10-08Merge pull request #113 from jow-/fix-regex-literal-parsingJo-Philipp Wich
lexer: fixes for regex literal parsing
2022-10-07fs: use `getline()` for line wise read operationsJo-Philipp Wich
Use `getline()` instead of a custom `fgets()` wrapper logic to perform line wise reads from open file handles. This is required to properly deal with lines containing embedded null bytes. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-10-05lexer: fixes for regex literal parsingJo-Philipp Wich
- Ensure that regexp extension escapes are consistently handled; substitute `\d`, `\D`, `\s`, `\S`, `\w` and `\W` with `[[:digit:]]`, `[^[:digit:]]`, `[[:space:]]`, `[^[:space:]]`, `[[:alnum:]_]` and `[^[:alnum:]_]` character classes respectively since not all POSIX regexp implementations implement all of those extensions - Preserve `\b`, `\B`, `\<` and `\>` boundary matches Fixes: a45f2a3 ("lexer: improve regex literal handling") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-10-05Merge pull request #110 from jow-/lib-add-sliceJo-Philipp Wich
lib: implement slice() function
2022-10-04lib: implement slice() functionJo-Philipp Wich
Implement a new function `slice()` to complement the existing `splice()` function and model it's semantics after the ES6 `Array.slice()` version. Fixes: #106 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-10-04Merge pull request #108 from jow-/optimizationsJo-Philipp Wich
Various improvements
2022-10-04main: implement print modeJo-Philipp Wich
Introduce a new `-p` flag which works like `-e` but prints the final expression result. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-10-04compiler: optimize function return opcode generationJo-Philipp Wich
Track last emitted statement type in compiled code and only generate final `return null` opcodes if there is no preceeding `return` statement. Also use this statement tracking to avoid emitting invalid return opcodes for arrow function bodies with trailing empty statements. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-10-04lexer: improve regex literal handlingJo-Philipp Wich
- Do not treat slashes within bracket expressions as delimitters - Do not escape slashes when stringifying regex sources - Allow all escape sequence types in regex literals Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-09-30vm: maintain export symbol tables per programJo-Philipp Wich
Instead of having one global export table per VM instance maintain one table per program instance. This is required to avoid clobbering the export list in case `import` using code is loaded at runtime through `require()`, `loadfile()` etc. Signed-off-by: Jo-Philipp Wich <jo@mein.io>