Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ uc_compiler_emit_inc_dec(uc_compiler_t *compiler, uc_tokentype_t toktype, bool i

insn = (toktype == TK_INC) ? I_PLUS : I_MINUS;

/* add / substract 1 */
/* add / subtract 1 */
uc_compiler_emit_insn(compiler, 0, I_LOAD8);
uc_compiler_emit_u8(compiler, 0, 1);

Expand Down Expand Up @@ -1127,7 +1127,7 @@ uc_compiler_emit_inc_dec(uc_compiler_t *compiler, uc_tokentype_t toktype, bool i
break;
}

/* for post increment or decrement, add/substract 1 to yield final value */
/* for post increment or decrement, add/subtract 1 to yield final value */
if (is_postfix) {
uc_compiler_emit_insn(compiler, 0, I_LOAD8);
uc_compiler_emit_u8(compiler, 0, 1);
Expand Down Expand Up @@ -1578,7 +1578,7 @@ uc_compiler_compile_paren(uc_compiler_t *compiler)
uc_compiler_parse_advance(compiler);
}

/* If we encouter a dot, treat potential subsequent keyword as label */
/* If we encounter a dot, treat potential subsequent keyword as label */
if (uc_compiler_parse_check(compiler, TK_DOT) ||
uc_compiler_parse_check(compiler, TK_QDOT))
compiler->parser->lex.no_keyword = true;
Expand All @@ -1587,7 +1587,7 @@ uc_compiler_compile_paren(uc_compiler_t *compiler)
}
}

/* The lhs we parsed so far is elligible for an arrow function arg list,
/* The lhs we parsed so far is eligible for an arrow function arg list,
* try to continue compiling into arrow function... */
if (maybe_arrowfn) {
/* If we can parse the remainder as arrow function, we're done */
Expand Down Expand Up @@ -2158,7 +2158,7 @@ uc_compiler_compile_object(uc_compiler_t *compiler)
/* parse property name expression */
uc_compiler_parse_precedence(compiler, P_ASSIGN);

/* cosume closing bracket and colon */
/* consume closing bracket and colon */
uc_compiler_parse_consume(compiler, TK_RBRACK);
uc_compiler_parse_consume(compiler, TK_COLON);

Expand Down Expand Up @@ -2284,7 +2284,7 @@ uc_compiler_compile_declexpr(uc_compiler_t *compiler, bool constant)
/* if followed by '=', parse initializer expression */
if (uc_compiler_parse_match(compiler, TK_ASSIGN))
uc_compiler_parse_precedence(compiler, P_ASSIGN);
/* otherwise, for writable variables, load implicit null */
/* otherwise, for writeable variables, load implicit null */
else if (!constant)
uc_compiler_emit_insn(compiler, compiler->parser->prev.pos, I_LNULL);
/* for constant variables, a missing initializer is a syntax error */
Expand Down Expand Up @@ -2857,7 +2857,7 @@ uc_compiler_compile_switch(uc_compiler_t *compiler)
uc_compiler_compile_declaration(compiler);
}

/* a statement or expression preceeding any `default` or `case` is a
/* a statement or expression preceding any `default` or `case` is a
* syntax error */
else {
uc_compiler_syntax_error(compiler, compiler->parser->curr.pos,
Expand Down Expand Up @@ -3406,7 +3406,7 @@ uc_compiler_compile_module_source(uc_compiler_t *compiler, uc_source_t *source,
if (n_imports > 0xfffe)
uc_compiler_syntax_error(compiler, 0, "Too many imports");

/* emit non-wilcard import instructions */
/* emit non-wildcard import instructions */
for (i = 0; i < ucv_array_length(imports); i++) {
import = ucv_array_get(imports, i);

Expand Down
37 changes: 37 additions & 0 deletions docs/tutorials/01-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,40 @@ different options:
```
ucode -c -o compiled.uc program.uc
```

## Note

Extra parameters can be passed to ucode scripts and programs from the command
line as follows:
```
ucode foo.uc foo bar
```

Or if the shebang line `#!/usr/bin/env ucode` is the first line in the script:
```
./foo.uc foo bar
```

The parameters provided at command execution are available internally to the
script via the following global variable:
```
ARGV
```

The script or program has access to its own name at runtime via the following
global variable:
```
SCRIPT_NAME
```

For example, this ucode script:
```
print(ARGV, "\n");
print(SCRIPT_NAME, "\n");
```

when run as `> ucode ./foo.uc foo bar` outputs:
```
[ "foo", "bar" ]
./foo.uc
```
24 changes: 12 additions & 12 deletions docs/tutorials/02-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ calling scope.
### 1. Data types

Ucode supports seven different basic types as well as two additional special
types; function values and ressource values. The supported types are:
types; function values and resource values. The supported types are:

- Boolean values (`true` or `false`)
- Integer values (`-9223372036854775808` to `+9223372036854775807`)
Expand All @@ -163,15 +163,15 @@ and frees data automatically as soon as values go out of scope.

Numeric values are either stored as signed 64bit integers or as IEEE 756 double
value. Conversion between integer and double values can happen implicitly, e.g.
through numeric operations, or explicitely, e.g. by invoking functions such as
through numeric operations, or explicitly, e.g. by invoking functions such as
`int()`.

### 2. Variables

Variable names must start with a letter or an underscore and may only contain
the characters `A`..`Z`, `a`..`z`, `0`..`9` or `_`. By prefixing a variable
name with the keyword `let`, it is declared in the local block scope only
and not visible outside anymore.
and not visible outside any more.

Variables may also be declared using the `const` keyword. Such variables follow
the same scoping rules as `let` declared ones but they cannot be modified after
Expand Down Expand Up @@ -426,7 +426,7 @@ operators to manipulate values and variables.
#### 5.1. Arithmetic operations

The operators `+`, `-`, `*`, `/`, `%`, `++` and `--` allow to perform
additions, substractions, multiplications, divisions, modulo, increment or
additions, subtractions, multiplications, divisions, modulo, increment or
decrement operations respectively where the result depends on the type of
involved values.

Expand Down Expand Up @@ -510,7 +510,7 @@ operand values to whole integers:
#### 5.3. Relational operations

The operators `==`, `!=`, `<`, `<=`, `>` and `>=` test whether their operands
are equal, inequal, lower than, lower than/equal to, higher than or higher
are equal, unequal, lower than, lower than/equal to, higher than or higher
than/equal to each other respectively.

If both operands are strings, their respective byte values are compared, if
Expand All @@ -522,7 +522,7 @@ resulting values are compared with each other.
This means that comparing values of different types will coerce them both to
numbers.

The result of the relational operation is a boolean indicating truishness.
The result of the relational operation is a boolean indicating truthiness.

```javascript
{%
Expand All @@ -543,14 +543,14 @@ The operators `&&`, `||`, `??` and `!` test whether their operands are all true,
partially true, null or false respectively.

In the case of `&&` the rightmost value is returned while `||` results in the
first truish and `??` in the first non-null value.
first truthy value and `??` in the first non-null value.

The unary `!` operator will result in `true` if the operand is not trueish,
The unary `!` operator will result in `true` if the operand is falsy,
otherwise it will result in `false`.

Operands are evaluated from left to right while testing truishness, which means
Operands are evaluated from left to right while testing truthiness, which means
that expressions with side effects, such as function calls, are only executed
if the preceeding condition was satisifed.
if the preceding condition was satisfied.

```javascript
{%
Expand Down Expand Up @@ -622,7 +622,7 @@ in the table below.
| 19 | Grouping `( … )` | n/a |
| 18 | Property access `… . …` | left-to-right |
| 18 | Optional chaining `… ?. …` | left-to-right |
| 18 | Computed propery access `… [ … ]` | n/a |
| 18 | Computed property access `… [ … ]` | n/a |
| 18 | Function call `… (…)` | n/a |
| 17 | Postfix increment `… ++` | n/a |
| 17 | Postfix decrement `… --` | n/a |
Expand All @@ -638,7 +638,7 @@ in the table below.
| 14 | Division `… / …` | left-to-right |
| 14 | Remainder `… % …` | left-to-right |
| 13 | Addition `… + …` | left-to-right |
| 13 | Substraction `… - …` | left-to-right |
| 13 | Subtraction `… - …` | left-to-right |
| 12 | Bitwise left shift `… << …` | left-to-right |
| 12 | Bitwise right shift `… >> …` | left-to-right |
| 11 | Less than `… < …` | left-to-right |
Expand Down
2 changes: 1 addition & 1 deletion lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ uc_lexer_is_keyword(uc_value_t *label)

/*
* Stores the given codepoint as a utf8 multibyte sequence into the given
* output buffer and substracts the required amount of bytes from the given
* output buffer and subtracts the required amount of bytes from the given
* length pointer.
*
* Returns false if the multibyte sequence would not fit into the buffer,
Expand Down
8 changes: 4 additions & 4 deletions lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -3464,7 +3464,7 @@ uc_json_from_object(uc_vm_t *vm, uc_value_t *obj, json_object **jso)
if (eof && !trail) {
ucv_put(rbuf);

/* Didn't parse a complete object yet, possibly a non-delimitted atomic value
/* Didn't parse a complete object yet, possibly a non-delimited atomic value
such as `null`, `true` etc. - nudge parser by sending final zero byte.
See json-c issue #681 <https://github.com/json-c/json-c/issues/681> */
if (json_tokener_get_error(tok) == json_tokener_continue)
Expand Down Expand Up @@ -3764,7 +3764,7 @@ uc_include_common(uc_vm_t *vm, size_t nargs, bool raw_mode)
* // Execute the "untrusted.ucode" in a sandboxed scope and make the "foo" and
* // "bar" variables as well as the "print" function available to it.
* // By assigning an empty prototype object to the scope, included code has no
* // access to other global values anymore.
* // access to other global values any more.
* include("./untrusted.uc", proto({
* foo: true,
* bar: 123,
Expand Down Expand Up @@ -4191,7 +4191,7 @@ uc_sleep(uc_vm_t *vm, size_t nargs)

/**
* Raise an exception with the given message parameter when the value in `cond`
* is not truish.
* is not truthy.
*
* When `message` is omitted, the default value is `Assertion failed`.
*
Expand Down Expand Up @@ -5131,7 +5131,7 @@ uc_timegm(uc_vm_t *vm, size_t nargs)
* Reads the current second and microsecond value of the system clock.
*
* By default, the realtime clock is queried which might skew forwards or
* backwards due to NTP changes, system sleep modes etc. If a truish value is
* backwards due to NTP changes, system sleep modes etc. If a truthy value is
* passed as argument, the monotonic system clock is queried instead, which will
* return the monotonically increasing time since some arbitrary point in the
* past (usually the system boot time).
Expand Down
2 changes: 1 addition & 1 deletion lib/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ uc_getinfo(uc_vm_t *vm, size_t nargs)
* The source line number where the local variable goes out of scope.
*
* @property {number} byteto
* The source line offset where the local vatiable goes out of scope.
* The source line offset where the local variable goes out of scope.
*/
static uc_value_t *
uc_xlocal(uc_vm_t *vm, uc_value_t *level, uc_value_t *var, uc_value_t **set)
Expand Down
10 changes: 5 additions & 5 deletions lib/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1575,13 +1575,13 @@ uc_fs_readlink(uc_vm_t *vm, size_t nargs)
* @property {boolean} perm.setgid - Whether the setgid bit is set.
* @property {boolean} perm.sticky - Whether the sticky bit is set.
* @property {boolean} perm.user_read - Whether the file is readable by the owner.
* @property {boolean} perm.user_write - Whether the file is writable by the owner.
* @property {boolean} perm.user_write - Whether the file is writeable by the owner.
* @property {boolean} perm.user_exec - Whether the file is executable by the owner.
* @property {boolean} perm.group_read - Whether the file is readable by the group.
* @property {boolean} perm.group_write - Whether the file is writable by the group.
* @property {boolean} perm.group_write - Whether the file is writeable by the group.
* @property {boolean} perm.group_exec - Whether the file is executable by the group.
* @property {boolean} perm.other_read - Whether the file is readable by others.
* @property {boolean} perm.other_write - Whether the file is writable by others.
* @property {boolean} perm.other_write - Whether the file is writeable by others.
* @property {boolean} perm.other_exec - Whether the file is executable by others.
* @property {number} inode - The inode number.
* @property {number} mode - The file mode.
Expand Down Expand Up @@ -1735,7 +1735,7 @@ uc_fs_lstat(uc_vm_t *vm, size_t nargs)
*
* Returns `true` if the directory was successfully created.
*
* Returns `null` if an error occurred, e.g. due to inexistent path.
* Returns `null` if an error occurred, e.g. due to non-existent path.
*
* @function module:fs#mkdir
*
Expand Down Expand Up @@ -2489,7 +2489,7 @@ uc_fs_mkstemp(uc_vm_t *vm, size_t nargs)
* | Mode | Description |
* |------|---------------------------------------|
* | "r" | Tests whether the file is readable. |
* | "w" | Tests whether the file is writable. |
* | "w" | Tests whether the file is writeable. |
* | "x" | Tests whether the file is executable. |
* | "f" | Tests whether the file exists. |
*
Expand Down
8 changes: 4 additions & 4 deletions lib/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,8 @@ parse_channels(uc_value_t *channels)
/**
* Configure ulog logger.
*
* This functions configures the ulog mechanism and is analogeous to using the
* `openlog()` function in conjuncton with `syslog()`.
* This functions configures the ulog mechanism and is analogous to using the
* `openlog()` function in conjunction with `syslog()`.
*
* The `ulog_open()` function is OpenWrt specific and may not be present on
* other systems. Use `openlog()` and `syslog()` instead for portability to
Expand Down Expand Up @@ -746,7 +746,7 @@ uc_ulog_log_common(uc_vm_t *vm, size_t nargs, int priority)
*
* If the `ulog_open()` function has not been called explicitly before, `ulog()`
* implicitly configures certain defaults, see
* {@link module:log#ulog_open|ulog_open()} for a detailled description.
* {@link module:log#ulog_open|ulog_open()} for a detailed description.
*
* If the `format` argument is not a string and not `null`, it will be
* implicitly converted to a string and logged as-is, without further format
Expand Down Expand Up @@ -865,7 +865,7 @@ uc_ulog_close(uc_vm_t *vm, size_t nargs)
* // Set threshold to "warning" or more severe
* ulog_threshold(LOG_WARNING);
*
* // This message will be supressed
* // This message will be suppressed
* ulog(LOG_DEBUG, "Testing thresholds");
*
* // Using priority name
Expand Down
8 changes: 4 additions & 4 deletions lib/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ uc_exp(uc_vm_t *vm, size_t nargs)
* On success, returns the natural logarithm of `x`.
*
* - If `x` is `1`, the result is `+0`.
* - If `x` is positive nfinity, positive infinity is returned.
* - If `x` is positive infinity, positive infinity is returned.
* - If `x` is zero, then a pole error occurs, and the function
* returns negative infinity.
* - If `x` is negative (including negative infinity), then a domain
Expand All @@ -231,7 +231,7 @@ uc_exp(uc_vm_t *vm, size_t nargs)
* @function module:math#log
*
* @param {number} x
* Value to calulate natural logarithm of.
* Value to calculate natural logarithm of.
*
* @returns {number}
*/
Expand Down Expand Up @@ -275,7 +275,7 @@ uc_sin(uc_vm_t *vm, size_t nargs)
}

/**
* Calculates the nonnegative square root of `x`.
* Calculates the non-negative square root of `x`.
*
* Returns the resulting square root value.
*
Expand Down Expand Up @@ -326,7 +326,7 @@ uc_sqrt(uc_vm_t *vm, size_t nargs)
* - If `x` is `+1`, the result is `1.0` (even if `y` is `NaN`).
* - If `y` is `0`, the result is `1.0` (even if `x` is `NaN`).
* - If `x` is a finite value less than `0`, and `y` is a finite
* noninteger, a domain error occurs, and `NaN` is returned.
* non-integer, a domain error occurs, and `NaN` is returned.
* - If the absolute value of `x` is less than `1`, and `y` is negative
* infinity, the result is positive infinity.
* - If the absolute value of `x` is greater than `1`, and `y` is
Expand Down
Loading