summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt14
-rw-r--r--README.md48
-rw-r--r--ast.c170
-rw-r--r--ast.h94
-rw-r--r--eval.c666
-rw-r--r--eval.h10
-rw-r--r--lexer.c90
-rw-r--r--lexer.h4
-rw-r--r--lib.c462
-rw-r--r--lib.h10
-rw-r--r--lib/fs.c130
-rw-r--r--lib/math.c46
-rw-r--r--lib/ubus.c54
-rw-r--r--lib/uci.c96
-rw-r--r--main.c44
-rw-r--r--module.h10
-rw-r--r--parser.y108
17 files changed, 1028 insertions, 1028 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b6d6d84..9edfc6a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.6)
include(CheckFunctionExists)
include(CheckSymbolExists)
-PROJECT(utpl C)
+PROJECT(ucode C)
ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -Wmissing-declarations -Wno-error=unused-variable -ffunction-sections -D_GNU_SOURCE)
OPTION(FS_SUPPORT "Filesystem plugin support" ON)
@@ -10,7 +10,7 @@ OPTION(MATH_SUPPORT "Math plugin support" ON)
OPTION(UBUS_SUPPORT "Ubus plugin support" ON)
OPTION(UCI_SUPPORT "UCI plugin support" ON)
-SET(LIB_SEARCH_PATH "/usr/lib/utpl/*.so:/usr/share/utpl/*.utpl:./*.so:./*.utpl" CACHE STRING "Default library search path")
+SET(LIB_SEARCH_PATH "/usr/lib/ucode/*.so:/usr/share/ucode/*.uc:./*.so:./*.uc" CACHE STRING "Default library search path")
ADD_DEFINITIONS(-DLIB_SEARCH_PATH="${LIB_SEARCH_PATH}")
IF(NOT APPLE)
@@ -48,12 +48,12 @@ ADD_CUSTOM_COMMAND(
SET_PROPERTY(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "lemon;parser.h;parser.out")
SET_SOURCE_FILES_PROPERTIES("parser.c" PROPERTIES GENERATED TRUE COMPILE_FLAGS -Wno-error=unused-but-set-variable)
-ADD_EXECUTABLE(utpl main.c ast.c lexer.c parser.c eval.c lib.c)
-TARGET_LINK_LIBRARIES(utpl ${json})
+ADD_EXECUTABLE(ucode main.c ast.c lexer.c parser.c eval.c lib.c)
+TARGET_LINK_LIBRARIES(ucode ${json})
CHECK_FUNCTION_EXISTS(dlopen DLOPEN_FUNCTION_EXISTS)
IF (NOT DLOPEN_FUNCTION_EXISTS)
- TARGET_LINK_LIBRARIES(utpl dl)
+ TARGET_LINK_LIBRARIES(ucode dl)
ENDIF()
SET(CMAKE_REQUIRED_LIBRARIES json-c)
@@ -100,5 +100,5 @@ IF(UCI_SUPPORT)
TARGET_LINK_LIBRARIES(uci_lib uci)
ENDIF()
-INSTALL(TARGETS utpl RUNTIME DESTINATION bin)
-INSTALL(TARGETS ${LIBRARIES} LIBRARY DESTINATION lib/utpl)
+INSTALL(TARGETS ucode RUNTIME DESTINATION bin)
+INSTALL(TARGETS ${LIBRARIES} LIBRARY DESTINATION lib/ucode)
diff --git a/README.md b/README.md
index 97fbe94..527505a 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
## ABOUT
-An utpl template consists of arbitrary plain text which is outputted as-is
+An ucode template consists of arbitrary plain text which is outputted as-is
while control flow or expression logic is embedded in blocks that may appear
anywhere throughout the template.
@@ -18,7 +18,7 @@ Statement blocks are enclosed in an opening `{%` and a closing `%}` tag and
may contain any number of script code statements, even entire programs.
It is allowed to omit the closing `%}` of a statement block to parse the
-entire remaining source text after the opening tag as utpl script.
+entire remaining source text after the opening tag as ucode script.
By default, statement blocks produce no output and the entire block is
reduced to an empty string during template evaluation but contained script
@@ -39,7 +39,7 @@ is used as output when processing the block.
For example the template `Hello world, {{ getenv("USER") }}!` would result in
the output "Hello world, user!" where `user` would correspond to the name of
-the current user executing the utpl interpreter.
+the current user executing the ucode interpreter.
### 3. COMMENT BLOCKS
@@ -121,18 +121,18 @@ This is a first lineThis is item 1.This is item 2.This is item 3.This is the las
## SCRIPT LANGUAGE
-The utpl script language used within statement and expression blocks uses
+The ucode script language used within statement and expression blocks uses
untyped variables and employs a simplified JavaScript like syntax.
-Utpl script implements function scoping and differentiates between local and
+Ucode script implements function scoping and differentiates between local and
global variables. Each function has its own private scope while executing and
local variables declared inside a function are not accessible in the outer
calling scope.
### 1. Data types
-Utpl supports seven different basic types as well as an additional special
-function type. The supported types are:
+Ucode supports seven different basic types as well as two additional special
+types; function values and ressource values. The supported types are:
- Boolean values (`true` or `false`)
- Integer values (`-9223372036854775808` to `+9223372036854775807`)
@@ -142,7 +142,7 @@ function type. The supported types are:
- Object values (e.g. `{ foo: true, "bar": 123 }`)
- Null value (`null`)
-Utpl utilizes reference counting to manage memory used for variables and values
+Ucode utilizes reference counting to manage memory used for variables and values
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
@@ -154,7 +154,7 @@ through numeric operations, or explicitely, e.g. by invoking functions such as
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 `local`, it is declared in the local function scope only
+name with the keyword `let`, it is declared in the local function scope only
and not visible outside anymore.
```javascript
@@ -163,7 +163,7 @@ and not visible outside anymore.
a = 1; // global variable assignment
function test() {
- local b = 2; // declare `b` as local variable
+ let b = 2; // declare `b` as local variable
a = 2; // overwrite global a
}
@@ -177,7 +177,7 @@ and not visible outside anymore.
### 3. Control statements
-Similar to JavaScript, utpl supports `if`, `for` and `while` statements to
+Similar to JavaScript, ucode supports `if`, `for` and `while` statements to
control execution flow.
#### 3.1. Conditional statement
@@ -216,7 +216,7 @@ curly braces may be omitted:
#### 3.2. Loop statements
-Utpl script supports three different flavors of loop control statements; a
+Ucode script supports three different flavors of loop control statements; a
`while` loop that executes enclosed statements as long as the loop condition is
fulfilled, a `for in` loop that iterates keys of objects or items of arrays and
a counting `for` loop that is a variation of the `while` loop.
@@ -257,7 +257,7 @@ a counting `for` loop that is a variation of the `while` loop.
#### 3.3. Alternative syntax
Since conditional statements and loops are often used for template formatting
-purposes, e.g. to repeat a specific markup for each item of a list, utpl
+purposes, e.g. to repeat a specific markup for each item of a list, ucode
supports an alternative syntax that does not require curly braces to group
statements but that uses explicit end keywords to denote the end of the control
statement body for better readability instead.
@@ -291,7 +291,7 @@ For each control statement type, a corresponding alternative end keyword is defi
### 4. Functions
-Utpl scripts may define functions to group repeating operations into reusable
+Ucode scripts may define functions to group repeating operations into reusable
operations. Functions can be both declared with a name, in which case they're
automatically registered in the current scope, or anonymously which allows
assigning the resulting value to a variable, e.g. to build arrays or objects of
@@ -304,7 +304,7 @@ functions:
return n * 2;
}
- local utilities = {
+ let utilities = {
concat: function(a, b) {
return "" + a + b;
},
@@ -340,7 +340,7 @@ keyword:
### 5. Operators
-Similar to JavaScript and C, utpl scripts support a range of different
+Similar to JavaScript and C, ucode scripts support a range of different
operators to manipulate values and variables.
#### 5.1. Arithmetic operations
@@ -512,7 +512,7 @@ The result of assignment expressions is the assigned value.
### 6. Functions
-Utpl scripts may call a number of builtin functions to manipulate values or
+Ucode scripts may call a number of builtin functions to manipulate values or
to output information.
#### 6.1. `abs(x)`
@@ -893,11 +893,11 @@ values({ foo: true, bar: false }); // [true, false]
Formats the given arguments according to the given format string and outputs the
result to stdout.
-Utpl supports a restricted subset of the formats allowed by the underlying
+Ucode supports a restricted subset of the formats allowed by the underlying
libc's `printf()` implementation, namely it allows the `d`, `i`, `o`, `u`, `x`,
`X`, `e`, `E`, `f`, `F`, `g`, `G`, `c` and `s` conversions.
-Additionally, an utpl specific `J` format is implemented, which causes the
+Additionally, an ucode specific `J` format is implemented, which causes the
corresponding value to be formatted as JSON string.
Other format specifiers such as `n` or `z` are not accepted and returned
@@ -995,16 +995,16 @@ If the given path argument is not absolute, it is interpreted relative to the
directory of the current template file, that is the file that is invoking the
`include()` function.
-If the utpl interpreter executes program code from stdin, the given path is
+If the ucode interpreter executes program code from stdin, the given path is
interpreted relative to the current working directory of the process.
```javascript
-// Load and execute "foo.utpl" immediately
-include("./foo.utpl")
+// Load and execute "foo.uc" immediately
+include("./foo.uc")
-// Execute the "untrusted.utpl" in a sandboxed scope and make the "foo" and
+// Execute the "untrusted.ucode" in a sandboxed scope and make the "foo" and
// "bar" variables as well as the "print" function available to it
-include("./untrusted.utpl", {
+include("./untrusted.uc", {
foo: true,
bar: 123,
print: print
diff --git a/ast.c b/ast.c
index 562a87b..bbaa733 100644
--- a/ast.c
+++ b/ast.c
@@ -26,13 +26,13 @@
#include <math.h>
#include <regex.h>
-static size_t ut_ext_types_count = 0;
-static struct ut_extended_type *ut_ext_types = NULL;
+static size_t uc_ext_types_count = 0;
+static struct uc_extended_type *uc_ext_types = NULL;
uint32_t
-ut_new_op(struct ut_state *s, int type, struct json_object *val, ...)
+uc_new_op(struct uc_state *s, int type, struct json_object *val, ...)
{
- struct ut_op *newop;
+ struct uc_op *newop;
uint32_t child;
int n_op = 0;
va_list ap;
@@ -65,9 +65,9 @@ ut_new_op(struct ut_state *s, int type, struct json_object *val, ...)
}
uint32_t
-ut_wrap_op(struct ut_state *s, uint32_t parent, ...)
+uc_wrap_op(struct uc_state *s, uint32_t parent, ...)
{
- struct ut_op *op = ut_get_op(s, parent);
+ struct uc_op *op = uc_get_op(s, parent);
uint32_t child;
int n_op = 0;
va_list ap;
@@ -83,12 +83,12 @@ ut_wrap_op(struct ut_state *s, uint32_t parent, ...)
}
uint32_t
-ut_append_op(struct ut_state *s, uint32_t a, uint32_t b)
+uc_append_op(struct uc_state *s, uint32_t a, uint32_t b)
{
- struct ut_op *tail = ut_get_op(s, a);
+ struct uc_op *tail = uc_get_op(s, a);
while (tail && tail->tree.next)
- tail = ut_get_op(s, tail->tree.next);
+ tail = uc_get_op(s, tail->tree.next);
tail->tree.next = b;
@@ -114,7 +114,7 @@ double_rounded_to_string(struct json_object *v, struct printbuf *pb, int level,
}
struct json_object *
-ut_new_double(double v)
+uc_new_double(double v)
{
struct json_object *d = json_object_new_double(v);
@@ -135,7 +135,7 @@ null_obj_to_string(struct json_object *v, struct printbuf *pb, int level, int fl
}
struct json_object *
-ut_new_null(void)
+uc_new_null(void)
{
struct json_object *d = json_object_new_boolean(false);
@@ -152,16 +152,16 @@ ut_new_null(void)
static void
obj_free(struct json_object *v, void *ud)
{
- struct ut_op *op = json_object_get_userdata(v);
+ struct uc_op *op = json_object_get_userdata(v);
json_object_put(op->tag.proto);
free(ud);
}
struct json_object *
-ut_new_object(struct json_object *proto) {
+uc_new_object(struct json_object *proto) {
struct json_object *val = xjs_new_object();
- struct ut_op *op = xalloc(sizeof(*op));
+ struct uc_op *op = xalloc(sizeof(*op));
op->val = val;
op->type = T_LBRACE;
@@ -175,7 +175,7 @@ ut_new_object(struct json_object *proto) {
static void
re_free(struct json_object *v, void *ud)
{
- struct ut_op *op = ud;
+ struct uc_op *op = ud;
regfree((regex_t *)op->tag.data);
free(op);
@@ -185,7 +185,7 @@ static int
re_to_string(struct json_object *v, struct printbuf *pb, int level, int flags)
{
bool strict = (level > 0) || (flags & JSON_C_TO_STRING_STRICT);
- struct ut_op *op = json_object_get_userdata(v);
+ struct uc_op *op = json_object_get_userdata(v);
struct json_object *s;
const char *p;
size_t len;
@@ -210,9 +210,9 @@ re_to_string(struct json_object *v, struct printbuf *pb, int level, int flags)
}
struct json_object *
-ut_new_regexp(const char *source, bool icase, bool newline, bool global, char **err) {
+uc_new_regexp(const char *source, bool icase, bool newline, bool global, char **err) {
int cflags = REG_EXTENDED, res;
- struct ut_op *op;
+ struct uc_op *op;
regex_t *re;
size_t len;
@@ -260,11 +260,11 @@ ut_new_regexp(const char *source, bool icase, bool newline, bool global, char **
static void
func_free(struct json_object *v, void *ud)
{
- struct ut_op *op = ud;
- struct ut_function *fn = op->tag.data;
+ struct uc_op *op = ud;
+ struct uc_function *fn = op->tag.data;
json_object_put(fn->args);
- ut_release_scope(fn->parent_scope);
+ uc_release_scope(fn->parent_scope);
free(op);
}
@@ -273,8 +273,8 @@ static int
func_to_string(struct json_object *v, struct printbuf *pb, int level, int flags)
{
bool strict = (level > 0) || (flags & JSON_C_TO_STRING_STRICT), rest;
- struct ut_op *op = json_object_get_userdata(v);
- struct ut_function *fn = op->tag.data;
+ struct uc_op *op = json_object_get_userdata(v);
+ struct uc_function *fn = op->tag.data;
size_t i, len;
if (op->is_arrow)
@@ -303,17 +303,17 @@ func_to_string(struct json_object *v, struct printbuf *pb, int level, int flags)
}
struct json_object *
-ut_new_func(struct ut_state *s, struct ut_op *decl, struct ut_scope *scope)
+uc_new_func(struct uc_state *s, struct uc_op *decl, struct uc_scope *scope)
{
struct json_object *val = xjs_new_object();
- struct ut_op *op, *name, *args, *arg;
- struct ut_function *fn;
+ struct uc_op *op, *name, *args, *arg;
+ struct uc_function *fn;
size_t sz;
sz = ALIGN(sizeof(*op)) + ALIGN(sizeof(*fn));
- name = ut_get_op(s, decl->tree.operand[0]);
- args = ut_get_op(s, decl->tree.operand[1]);
+ name = uc_get_op(s, decl->tree.operand[0]);
+ args = uc_get_op(s, decl->tree.operand[1]);
if (name)
sz += ALIGN(json_object_get_string_len(name->val) + 1);
@@ -329,7 +329,7 @@ ut_new_func(struct ut_state *s, struct ut_op *decl, struct ut_scope *scope)
if (args) {
fn->args = xjs_new_array();
- for (arg = args; arg; arg = ut_get_op(s, arg->tree.next)) {
+ for (arg = args; arg; arg = uc_get_op(s, arg->tree.next)) {
json_object_array_add(fn->args, json_object_get(arg->val));
/* if the last argument is a rest one (...arg), add extra null entry */
@@ -341,7 +341,7 @@ ut_new_func(struct ut_state *s, struct ut_op *decl, struct ut_scope *scope)
}
fn->source = s->function ? s->function->source : NULL;
- fn->parent_scope = ut_acquire_scope(scope);
+ fn->parent_scope = uc_acquire_scope(scope);
op->val = val;
op->type = T_FUNC;
@@ -366,7 +366,7 @@ exception_to_string(struct json_object *v, struct printbuf *pb, int level, int f
}
static void
-add_stacktrace(struct json_object *a, struct ut_function *function, size_t off) {
+add_stacktrace(struct json_object *a, struct uc_function *function, size_t off) {
struct json_object *o = xjs_new_object();
size_t line = 1, rlen = 0, len;
bool truncated = false;
@@ -400,11 +400,11 @@ add_stacktrace(struct json_object *a, struct ut_function *function, size_t off)
}
__attribute__((format(printf, 3, 4))) struct json_object *
-ut_new_exception(struct ut_state *s, uint32_t off, const char *fmt, ...)
+uc_new_exception(struct uc_state *s, uint32_t off, const char *fmt, ...)
{
- struct ut_callstack *callstack, *prevcall, here = {};
+ struct uc_callstack *callstack, *prevcall, here = {};
struct json_object *a;
- struct ut_op *op;
+ struct uc_op *op;
va_list ap;
char *p;
int len;
@@ -449,10 +449,10 @@ ut_new_exception(struct ut_state *s, uint32_t off, const char *fmt, ...)
static void
scope_free(struct json_object *v, void *ud)
{
- struct ut_scope *sc = ud;
+ struct uc_scope *sc = ud;
if (sc->parent) {
- ut_release_scope(json_object_get_userdata(sc->parent));
+ uc_release_scope(json_object_get_userdata(sc->parent));
sc->parent = NULL;
}
@@ -460,7 +460,7 @@ scope_free(struct json_object *v, void *ud)
}
void
-ut_release_scope(struct ut_scope *sc)
+uc_release_scope(struct uc_scope *sc)
{
if (sc->refs == 0)
abort();
@@ -471,41 +471,41 @@ ut_release_scope(struct ut_scope *sc)
json_object_put(sc->scope);
}
-struct ut_scope *
-ut_acquire_scope(struct ut_scope *sc)
+struct uc_scope *
+uc_acquire_scope(struct uc_scope *sc)
{
sc->refs++;
return sc;
}
-struct ut_scope *
-ut_new_scope(struct ut_state *s, struct ut_scope *parent)
+struct uc_scope *
+uc_new_scope(struct uc_state *s, struct uc_scope *parent)
{
- struct ut_scope *sc;
+ struct uc_scope *sc;
sc = xalloc(sizeof(*sc));
sc->scope = xjs_new_object();
if (parent)
- sc->parent = ut_acquire_scope(parent)->scope;
+ sc->parent = uc_acquire_scope(parent)->scope;
json_object_set_userdata(sc->scope, sc, scope_free);
sc->next = s->scopelist;
s->scopelist = sc;
- return ut_acquire_scope(sc);
+ return uc_acquire_scope(sc);
}
-struct ut_scope *
-ut_parent_scope(struct ut_scope *scope)
+struct uc_scope *
+uc_parent_scope(struct uc_scope *scope)
{
return json_object_get_userdata(scope->parent);
}
static void
-ut_reset(struct ut_state *s)
+uc_reset(struct uc_state *s)
{
json_object_put(s->exception);
s->exception = NULL;
@@ -516,10 +516,10 @@ ut_reset(struct ut_state *s)
}
void
-ut_free(struct ut_state *s)
+uc_free(struct uc_state *s)
{
- struct ut_source *src, *src_next;
- struct ut_scope *sc, *sc_next;
+ struct uc_source *src, *src_next;
+ struct uc_scope *sc, *sc_next;
struct json_object *scj;
size_t n;
@@ -534,7 +534,7 @@ ut_free(struct ut_state *s)
s->pool = NULL;
s->poolsize = 0;
- ut_reset(s);
+ uc_reset(s);
json_object_put(s->rval);
@@ -560,27 +560,27 @@ ut_free(struct ut_state *s)
}
}
- while (ut_ext_types_count > 0)
- json_object_put(ut_ext_types[--ut_ext_types_count].proto);
+ while (uc_ext_types_count > 0)
+ json_object_put(uc_ext_types[--uc_ext_types_count].proto);
- free(ut_ext_types);
+ free(uc_ext_types);
free(s);
}
struct json_object *
-ut_parse(struct ut_state *s, FILE *fp)
+uc_parse(struct uc_state *s, FILE *fp)
{
- struct ut_op *op;
+ struct uc_op *op;
void *pParser;
uint32_t off;
- ut_reset(s);
+ uc_reset(s);
pParser = ParseAlloc(xalloc);
while (s->lex.state != UT_LEX_EOF) {
- off = ut_get_token(s, fp);
- op = ut_get_op(s, off);
+ off = uc_get_token(s, fp);
+ op = uc_get_op(s, off);
if (s->exception)
goto out;
@@ -601,28 +601,28 @@ out:
}
bool
-ut_register_extended_type(const char *name, struct json_object *proto, void (*freefn)(void *))
+uc_register_extended_type(const char *name, struct json_object *proto, void (*freefn)(void *))
{
- ut_ext_types = xrealloc(ut_ext_types, (ut_ext_types_count + 1) * sizeof(*ut_ext_types));
- ut_ext_types[ut_ext_types_count].name = name;
- ut_ext_types[ut_ext_types_count].free = freefn;
- ut_ext_types[ut_ext_types_count].proto = proto;
- ut_ext_types_count++;
+ uc_ext_types = xrealloc(uc_ext_types, (uc_ext_types_count + 1) * sizeof(*uc_ext_types));
+ uc_ext_types[uc_ext_types_count].name = name;
+ uc_ext_types[uc_ext_types_count].free = freefn;
+ uc_ext_types[uc_ext_types_count].proto = proto;
+ uc_ext_types_count++;
return true;
}
static int
-ut_extended_type_to_string(struct json_object *v, struct printbuf *pb, int level, int flags)
+uc_extended_type_to_string(struct json_object *v, struct printbuf *pb, int level, int flags)
{
bool strict = (level > 0) || (flags & JSON_C_TO_STRING_STRICT);
- struct ut_op *op = json_object_get_userdata(v);
- struct ut_extended_type *et;
+ struct uc_op *op = json_object_get_userdata(v);
+ struct uc_extended_type *et;
if (!op)
return 0;
- et = &ut_ext_types[op->tag.type - 1];
+ et = &uc_ext_types[op->tag.type - 1];
return sprintbuf(pb, "%s<%s %p>%s",
strict ? "\"" : "",
@@ -631,15 +631,15 @@ ut_extended_type_to_string(struct json_object *v, struct printbuf *pb, int level
}
static void
-ut_extended_type_free(struct json_object *v, void *ud)
+uc_extended_type_free(struct json_object *v, void *ud)
{
- struct ut_op *op = json_object_get_userdata(v);
- struct ut_extended_type *et;
+ struct uc_op *op = json_object_get_userdata(v);
+ struct uc_extended_type *et;
if (!op)
return;
- et = &ut_ext_types[op->tag.type - 1];
+ et = &uc_ext_types[op->tag.type - 1];
if (et->free && op->tag.data)
et->free(op->tag.data);
@@ -649,15 +649,15 @@ ut_extended_type_free(struct json_object *v, void *ud)
}
struct json_object *
-ut_set_extended_type(struct json_object *v, const char *name, void *data)
+uc_set_extended_type(struct json_object *v, const char *name, void *data)
{
- struct ut_extended_type *et = NULL;
- struct ut_op *op;
+ struct uc_extended_type *et = NULL;
+ struct uc_op *op;
size_t n;
- for (n = 0; n < ut_ext_types_count; n++) {
- if (!strcmp(name, ut_ext_types[n].name)) {
- et = &ut_ext_types[n];
+ for (n = 0; n < uc_ext_types_count; n++) {
+ if (!strcmp(name, uc_ext_types[n].name)) {
+ et = &uc_ext_types[n];
break;
}
}
@@ -672,22 +672,22 @@ ut_set_extended_type(struct json_object *v, const char *name, void *data)
op->tag.type = n + 1;
op->tag.data = data;
- json_object_set_serializer(op->val, ut_extended_type_to_string, op, ut_extended_type_free);
+ json_object_set_serializer(op->val, uc_extended_type_to_string, op, uc_extended_type_free);
return op->val;
}
void **
-ut_get_extended_type(struct json_object *v, const char *name)
+uc_get_extended_type(struct json_object *v, const char *name)
{
- struct ut_op *op = json_object_get_userdata(v);
+ struct uc_op *op = json_object_get_userdata(v);
size_t n = op ? op->tag.type : 0;
- struct ut_extended_type *et;
+ struct uc_extended_type *et;
- if (!op || op->type != T_RESSOURCE || n == 0 || n > ut_ext_types_count)
+ if (!op || op->type != T_RESSOURCE || n == 0 || n > uc_ext_types_count)
return NULL;
- et = &ut_ext_types[n - 1];
+ et = &uc_ext_types[n - 1];
if (name && strcmp(et->name, name))
return NULL;
diff --git a/ast.h b/ast.h
index 337b81a..126aa65 100644
--- a/ast.h
+++ b/ast.h
@@ -39,7 +39,7 @@
#define JSON_C_TO_STRING_STRICT (1<<31)
-enum ut_lex_state {
+enum uc_lex_state {
UT_LEX_IDENTIFY_BLOCK,
UT_LEX_BLOCK_COMMENT_START,
UT_LEX_BLOCK_EXPRESSION_START,
@@ -51,7 +51,7 @@ enum ut_lex_state {
UT_LEX_EOF
};
-struct ut_op {
+struct uc_op {
uint16_t type;
uint16_t is_first:1;
uint16_t is_op:1;
@@ -80,40 +80,40 @@ struct ut_op {
};
};
-struct ut_scope {
- struct ut_scope *next;
+struct uc_scope {
+ struct uc_scope *next;
struct json_object *scope, *parent;
size_t refs;
};
-struct ut_source {
- struct ut_source *next;
+struct uc_source {
+ struct uc_source *next;
char *filename;
uint32_t off;
FILE *fp;
};
-struct ut_function {
+struct uc_function {
char *name;
union {
struct json_object *args;
void *cfn;
};
- struct ut_scope *parent_scope;
- struct ut_source *source;
+ struct uc_scope *parent_scope;
+ struct uc_source *source;
uint32_t entry;
};
-struct ut_callstack {
- struct ut_callstack *next;
- struct ut_function *function;
- struct ut_scope *scope;
+struct uc_callstack {
+ struct uc_callstack *next;
+ struct uc_function *function;
+ struct uc_scope *scope;
struct json_object *ctx;
uint32_t off;
};
-struct ut_state {
- struct ut_op *pool;
+struct uc_state {
+ struct uc_op *pool;
uint32_t poolsize;
uint32_t main;
uint8_t srand_called:1;
@@ -121,7 +121,7 @@ struct ut_state {
uint8_t lstrip_blocks:1;
uint8_t strict_declarations:1;
struct {
- enum ut_lex_state state;
+ enum uc_lex_state state;
uint8_t eof:1;
uint8_t skip_leading_whitespace:1;
uint8_t skip_leading_newline:1;
@@ -141,20 +141,20 @@ struct ut_state {
size_t lastoff;
} lex;
struct json_object *ctx, *rval, *exception;
- struct ut_scope *scopelist, *scope;
- struct ut_source *sources, *source;
- struct ut_callstack *callstack;
- struct ut_function *function;
+ struct uc_scope *scopelist, *scope;
+ struct uc_source *sources, *source;
+ struct uc_callstack *callstack;
+ struct uc_function *function;
size_t calldepth;
};
-struct ut_extended_type {
+struct uc_extended_type {
const char *name;
struct json_object *proto;
void (*free)(void *);
};
-static inline struct ut_op *ut_get_op(struct ut_state *s, uint32_t off)
+static inline struct uc_op *uc_get_op(struct uc_state *s, uint32_t off)
{
if (off == 0 || off > s->poolsize)
return NULL;
@@ -162,53 +162,53 @@ static inline struct ut_op *ut_get_op(struct ut_state *s, uint32_t off)
return &s->pool[off - 1];
}
-static inline struct ut_op *ut_get_child(struct ut_state *s, uint32_t off, int n)
+static inline struct uc_op *uc_get_child(struct uc_state *s, uint32_t off, int n)
{
- struct ut_op *op = ut_get_op(s, off);
+ struct uc_op *op = uc_get_op(s, off);
if (!op || n >= ARRAY_SIZE(op->tree.operand) || !op->tree.operand[n])
return NULL;
- return ut_get_op(s, op->tree.operand[n]);
+ return uc_get_op(s, op->tree.operand[n]);
}
-static inline uint32_t ut_get_off(struct ut_state *s, struct ut_op *op) {
+static inline uint32_t uc_get_off(struct uc_state *s, struct uc_op *op) {
return op ? (op - s->pool + 1) : 0;
};
-static inline bool ut_is_type(struct json_object *val, int type) {
- struct ut_op *tag = json_object_get_userdata(val);
+static inline bool uc_is_type(struct json_object *val, int type) {
+ struct uc_op *tag = json_object_get_userdata(val);
return (tag && tag->type == type);
};
-uint32_t ut_new_op(struct ut_state *s, int type, struct json_object *val, ...);
-uint32_t ut_wrap_op(struct ut_state *s, uint32_t parent, ...);
-uint32_t ut_append_op(struct ut_state *s, uint32_t a, uint32_t b);
-struct json_object *ut_parse(struct ut_state *s, FILE *fp);
-void ut_free(struct ut_state *s);
+uint32_t uc_new_op(struct uc_state *s, int type, struct json_object *val, ...);
+uint32_t uc_wrap_op(struct uc_state *s, uint32_t parent, ...);
+uint32_t uc_append_op(struct uc_state *s, uint32_t a, uint32_t b);
+struct json_object *uc_parse(struct uc_state *s, FILE *fp);
+void uc_free(struct uc_state *s);
-struct json_object *ut_new_func(struct ut_state *s, struct ut_op *decl, struct ut_scope *scope);
-struct json_object *ut_new_object(struct json_object *proto);
-struct json_object *ut_new_double(double v);
-struct json_object *ut_new_null(void);
-struct json_object *ut_new_regexp(const char *source, bool icase, bool newline, bool global, char **err);
+struct json_object *uc_new_func(struct uc_state *s, struct uc_op *decl, struct uc_scope *scope);
+struct json_object *uc_new_object(struct json_object *proto);
+struct json_object *uc_new_double(double v);
+struct json_object *uc_new_null(void);
+struct json_object *uc_new_regexp(const char *source, bool icase, bool newline, bool global, char **err);
__attribute__((format(printf, 3, 0)))
-struct json_object *ut_new_exception(struct ut_state *s, uint32_t off, const char *fmt, ...);
+struct json_object *uc_new_exception(struct uc_state *s, uint32_t off, const char *fmt, ...);
-struct ut_scope *ut_new_scope(struct ut_state *s, struct ut_scope *parent);
-struct ut_scope *ut_parent_scope(struct ut_scope *scope);
-struct ut_scope *ut_acquire_scope(struct ut_scope *scope);
-void ut_release_scope(struct ut_scope *scope);
+struct uc_scope *uc_new_scope(struct uc_state *s, struct uc_scope *parent);
+struct uc_scope *uc_parent_scope(struct uc_scope *scope);
+struct uc_scope *uc_acquire_scope(struct uc_scope *scope);
+void uc_release_scope(struct uc_scope *scope);
-bool ut_register_extended_type(const char *name, struct json_object *proto, void (*freefn)(void *));
-struct json_object *ut_set_extended_type(struct json_object *v, const char *name, void *data);
-void **ut_get_extended_type(struct json_object *val, const char *name);
+bool uc_register_extended_type(const char *name, struct json_object *proto, void (*freefn)(void *));
+struct json_object *uc_set_extended_type(struct json_object *v, const char *name, void *data);
+void **uc_get_extended_type(struct json_object *val, const char *name);
void *ParseAlloc(void *(*mfunc)(size_t));
-void Parse(void *pParser, int type, uint32_t off, struct ut_state *s);
+void Parse(void *pParser, int type, uint32_t off, struct uc_state *s);
void ParseFree(void *pParser, void (*ffunc)(void *));
diff --git a/eval.c b/eval.c
index 50986e0..3473235 100644
--- a/eval.c
+++ b/eval.c
@@ -27,9 +27,9 @@
#include <regex.h>
bool
-ut_val_is_truish(struct json_object *val)
+uc_val_is_truish(struct json_object *val)
{
- struct ut_op *tag = json_object_get_userdata(val);
+ struct uc_op *tag = json_object_get_userdata(val);
double d;
switch (tag ? tag->type : 0) {
@@ -63,7 +63,7 @@ ut_val_is_truish(struct json_object *val)
}
enum json_type
-ut_cast_number(struct json_object *v, int64_t *n, double *d)
+uc_cast_number(struct json_object *v, int64_t *n, double *d)
{
bool is_double = false;
const char *s;
@@ -134,25 +134,25 @@ ut_cast_number(struct json_object *v, int64_t *n, double *d)
}
static struct json_object *
-ut_execute_op(struct ut_state *state, uint32_t off);
+uc_execute_op(struct uc_state *state, uint32_t off);
static struct json_object *
-ut_execute_op_sequence(struct ut_state *state, uint32_t off);
+uc_execute_op_sequence(struct uc_state *state, uint32_t off);
static struct json_object *
-ut_execute_list(struct ut_state *state, uint32_t off);
+uc_execute_list(struct uc_state *state, uint32_t off);
static char *
-ut_ref_to_str(struct ut_state *state, uint32_t off)
+uc_ref_to_str(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
- struct ut_op *op2 = ut_get_child(state, off, 1);
+ struct uc_op *op = uc_get_op(state, off);
+ struct uc_op *op2 = uc_get_child(state, off, 1);
const char *l;
char *s, *p;
switch (op ? op->type : 0) {
case T_DOT:
- s = ut_ref_to_str(state, op->tree.operand[0]);
+ s = uc_ref_to_str(state, op->tree.operand[0]);
l = ((op2 ? op2->type : 0) == T_LABEL) ? json_object_get_string(op2->val) : "???";
if (asprintf(&p, "%s.%s", s ? s : "(...)", l) == -1)
@@ -169,7 +169,7 @@ ut_ref_to_str(struct ut_state *state, uint32_t off)
/* fall through */
case T_LPAREN:
- s = ut_ref_to_str(state, op->tree.operand[0]);
+ s = uc_ref_to_str(state, op->tree.operand[0]);
switch (op2 ? op2->type : 0) {
case T_STRING:
@@ -204,12 +204,12 @@ ut_ref_to_str(struct ut_state *state, uint32_t off)
}
static struct json_object *
-ut_getref(struct ut_state *state, uint32_t off, struct json_object **key)
+uc_getref(struct uc_state *state, uint32_t off, struct json_object **key)
{
- struct ut_op *op = ut_get_op(state, off);
+ struct uc_op *op = uc_get_op(state, off);
uint32_t off1 = op ? op->tree.operand[0] : 0;
uint32_t off2 = op ? op->tree.operand[1] : 0;
- struct ut_scope *sc, *next;
+ struct uc_scope *sc, *next;
struct json_object *val;
if (key)
@@ -217,21 +217,21 @@ ut_getref(struct ut_state *state, uint32_t off, struct json_object **key)
if (op && op->type == T_DOT) {
if (key)
- *key = off2 ? json_object_get(ut_get_op(state, off2)->val) : NULL;
+ *key = off2 ? json_object_get(uc_get_op(state, off2)->val) : NULL;
- return ut_execute_op_sequence(state, off1);
+ return uc_execute_op_sequence(state, off1);
}
else if (op && op->type == T_LBRACK && op->is_postfix) {
if (key) {
- val = off2 ? ut_execute_op_sequence(state, off2) : NULL;
+ val = off2 ? uc_execute_op_sequence(state, off2) : NULL;
- if (ut_is_type(val, T_EXCEPTION))
+ if (uc_is_type(val, T_EXCEPTION))
return val;
*key = val;
}
- return ut_execute_op_sequence(state, off1);
+ return uc_execute_op_sequence(state, off1);
}
else if (op && op->type == T_LABEL) {
sc = state->scope;
@@ -240,11 +240,11 @@ ut_getref(struct ut_state *state, uint32_t off, struct json_object **key)
if (json_object_object_get_ex(sc->scope, json_object_get_string(op->val), NULL))
break;
- next = ut_parent_scope(sc);
+ next = uc_parent_scope(sc);
if (!next) {
if (state->strict_declarations) {
- return ut_new_exception(state, op->off,
+ return uc_new_exception(state, op->off,
"Reference error: access to undeclared variable %s",
json_object_get_string(op->val));
}
@@ -269,26 +269,26 @@ ut_getref(struct ut_state *state, uint32_t off, struct json_object **key)
}
static struct json_object *
-ut_getref_required(struct ut_state *state, uint32_t off, struct json_object **key)
+uc_getref_required(struct uc_state *state, uint32_t off, struct json_object **key)
{
- struct ut_op *op1 = ut_get_child(state, off, 0);
+ struct uc_op *op1 = uc_get_child(state, off, 0);
struct json_object *scope, *skey, *rv;
char *lhs;
- scope = ut_getref(state, off, &skey);
+ scope = uc_getref(state, off, &skey);
if (!json_object_is_type(scope, json_type_array) &&
!json_object_is_type(scope, json_type_object)) {
- if (!ut_is_type(scope, T_EXCEPTION)) {
- lhs = op1 ? ut_ref_to_str(state, ut_get_off(state, op1)) : NULL;
+ if (!uc_is_type(scope, T_EXCEPTION)) {
+ lhs = op1 ? uc_ref_to_str(state, uc_get_off(state, op1)) : NULL;
if (lhs) {
- rv = ut_new_exception(state, op1->off, "Type error: `%s` is %s",
+ rv = uc_new_exception(state, op1->off, "Type error: `%s` is %s",
lhs, scope ? "not an array or object" : "null");
free(lhs);
}
else {
- rv = ut_new_exception(state, op1->off, "Type error: left-hand side is not an array or object");
+ rv = uc_new_exception(state, op1->off, "Type error: left-hand side is not an array or object");
}
json_object_put(scope);
@@ -308,9 +308,9 @@ ut_getref_required(struct ut_state *state, uint32_t off, struct json_object **ke
}
static struct json_object *
-ut_getproto(struct json_object *obj)
+uc_getproto(struct json_object *obj)
{
- struct ut_op *op = json_object_get_userdata(obj);
+ struct uc_op *op = json_object_get_userdata(obj);
if (!op || (op->type != T_LBRACE && op->type <= __T_MAX) || !op->val)
return NULL;
@@ -319,7 +319,7 @@ ut_getproto(struct json_object *obj)
}
static struct json_object *
-ut_getval(struct json_object *scope, struct json_object *key)
+uc_getval(struct json_object *scope, struct json_object *key)
{
struct json_object *o, *v;
int64_t idx;
@@ -349,7 +349,7 @@ ut_getval(struct json_object *scope, struct json_object *key)
return json_object_get(json_object_array_get_idx(scope, idx));
}
- for (o = scope; o; o = ut_getproto(o)) {
+ for (o = scope; o; o = uc_getproto(o)) {
if (!json_object_is_type(o, json_type_object))
continue;
@@ -361,7 +361,7 @@ ut_getval(struct json_object *scope, struct json_object *key)
}
static struct json_object *
-ut_setval(struct json_object *scope, struct json_object *key, struct json_object *val)
+uc_setval(struct json_object *scope, struct json_object *key, struct json_object *val)
{
int64_t idx;
@@ -388,22 +388,22 @@ ut_setval(struct json_object *scope, struct json_object *key, struct json_object
}
static struct json_object *
-ut_execute_assign(struct ut_state *state, uint32_t off)
+uc_execute_assign(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
+ struct uc_op *op = uc_get_op(state, off);
uint32_t label = op ? op->tree.operand[0] : 0;
uint32_t value = op ? op->tree.operand[1] : 0;
struct json_object *scope, *key, *val;
- scope = ut_getref_required(state, label, &key);
+ scope = uc_getref_required(state, label, &key);
if (!key)
return scope;
- val = ut_execute_op_sequence(state, value);
+ val = uc_execute_op_sequence(state, value);
- if (!ut_is_type(val, T_EXCEPTION))
- ut_setval(scope, key, val);
+ if (!uc_is_type(val, T_EXCEPTION))
+ uc_setval(scope, key, val);
json_object_put(scope);
json_object_put(key);
@@ -412,22 +412,22 @@ ut_execute_assign(struct ut_state *state, uint32_t off)
}
static struct json_object *
-ut_execute_local(struct ut_state *state, uint32_t off)
+uc_execute_local(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off), *asop, *alop;
+ struct uc_op *op = uc_get_op(state, off), *asop, *alop;
uint32_t as = op ? op->tree.operand[0] : 0;
struct json_object *val, *rv = NULL;
while (as) {
- asop = ut_get_op(state, as);
+ asop = uc_get_op(state, as);
as = asop ? asop->tree.next : 0;
switch (asop ? asop->type : 0) {
case T_ASSIGN:
- alop = ut_get_op(state, asop->tree.operand[0]);
- val = ut_execute_op_sequence(state, asop->tree.operand[1]);
+ alop = uc_get_op(state, asop->tree.operand[0]);
+ val = uc_execute_op_sequence(state, asop->tree.operand[1]);
- if (ut_is_type(val, T_EXCEPTION))
+ if (uc_is_type(val, T_EXCEPTION))
return val;
break;
@@ -443,7 +443,7 @@ ut_execute_local(struct ut_state *state, uint32_t off)
if (alop) {
json_object_put(rv);
- rv = ut_setval(state->scope->scope, alop->val, val);
+ rv = uc_setval(state->scope->scope, alop->val, val);
}
}
@@ -451,13 +451,13 @@ ut_execute_local(struct ut_state *state, uint32_t off)
}
static struct json_object *
-ut_execute_op_sequence(struct ut_state *state, uint32_t off);
+uc_execute_op_sequence(struct uc_state *state, uint32_t off);
static bool
-ut_test_condition(struct ut_state *state, uint32_t off)
+uc_test_condition(struct uc_state *state, uint32_t off)
{
- struct json_object *val = ut_execute_op_sequence(state, off);
- bool istrue = ut_val_is_truish(val);
+ struct json_object *val = uc_execute_op_sequence(state, off);
+ bool istrue = uc_val_is_truish(val);
json_object_put(val);
@@ -465,34 +465,34 @@ ut_test_condition(struct ut_state *state, uint32_t off)
}
static struct json_object *
-ut_execute_if(struct ut_state *state, uint32_t off)
+uc_execute_if(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
+ struct uc_op *op = uc_get_op(state, off);
uint32_t cond = op ? op->tree.operand[0] : 0;
uint32_t Then = op ? op->tree.operand[1] : 0;
uint32_t Else = op ? op->tree.operand[2] : 0;
- bool res = ut_test_condition(state, cond);
+ bool res = uc_test_condition(state, cond);
if (state->exception)
return json_object_get(state->exception);
else if (res)
- return ut_execute_op_sequence(state, Then);
+ return uc_execute_op_sequence(state, Then);
else if (Else)
- return ut_execute_op_sequence(state, Else);
+ return uc_execute_op_sequence(state, Else);
return NULL;
}
static struct json_object *
-ut_execute_for(struct ut_state *state, uint32_t off)
+uc_execute_for(struct uc_state *state, uint32_t off)
{
struct json_object *kscope, *vscope, *val, *item, *ik, *iv = NULL, *rv = NULL;
- struct ut_op *loop = ut_get_op(state, off);
- struct ut_op *init = ut_get_child(state, off, 0);
+ struct uc_op *loop = uc_get_op(state, off);
+ struct uc_op *init = uc_get_child(state, off, 0);
uint32_t test = loop ? loop->tree.operand[1] : 0;
uint32_t incr = loop ? loop->tree.operand[2] : 0;
uint32_t body = loop ? loop->tree.operand[3] : 0;
- struct ut_op *ikvar, *ivvar, *tag;
+ struct uc_op *ikvar, *ivvar, *tag;
size_t arridx, arrlen;
bool local = false;
@@ -500,28 +500,28 @@ ut_execute_for(struct ut_state *state, uint32_t off)
if (loop->is_for_in) {
if (init->type == T_LOCAL) {
local = true;
- init = ut_get_op(state, init->tree.operand[0]);
+ init = uc_get_op(state, init->tree.operand[0]);
}
- ikvar = ut_get_op(state, init->tree.operand[0]);
+ ikvar = uc_get_op(state, init->tree.operand[0]);
ik = ikvar->val;
- kscope = local ? state->scope->scope : ut_getref(state, ut_get_off(state, ikvar), NULL);
+ kscope = local ? state->scope->scope : uc_getref(state, uc_get_off(state, ikvar), NULL);
- if (ut_is_type(kscope, T_EXCEPTION))
+ if (uc_is_type(kscope, T_EXCEPTION))
return kscope;
if (ikvar->tree.next) {
- ivvar = ut_get_op(state, ikvar->tree.next);
+ ivvar = uc_get_op(state, ikvar->tree.next);
iv = ivvar->val;
- vscope = local ? kscope : ut_getref(state, ut_get_off(state, ivvar), NULL);
+ vscope = local ? kscope : uc_getref(state, uc_get_off(state, ivvar), NULL);
- if (ut_is_type(vscope, T_EXCEPTION))
+ if (uc_is_type(vscope, T_EXCEPTION))
return vscope;
}
- val = ut_execute_op_sequence(state, init->tree.operand[1]);
+ val = uc_execute_op_sequence(state, init->tree.operand[1]);
- if (ut_is_type(val, T_EXCEPTION))
+ if (uc_is_type(val, T_EXCEPTION))
return val;
if (json_object_is_type(val, json_type_array)) {
@@ -530,16 +530,16 @@ ut_execute_for(struct ut_state *state, uint32_t off)
item = json_object_array_get_idx(val, arridx);
if (iv) {
- ut_setval(kscope, ik, xjs_new_int64(arridx));
- ut_setval(vscope, iv, item);
+ uc_setval(kscope, ik, xjs_new_int64(arridx));
+ uc_setval(vscope, iv, item);
}
else {
- ut_setval(kscope, ik, item);
+ uc_setval(kscope, ik, item);
}
json_object_put(rv);
- rv = ut_execute_op_sequence(state, body);
+ rv = uc_execute_op_sequence(state, body);
tag = json_object_get_userdata(rv);
switch (tag ? tag->type : 0) {
@@ -559,14 +559,14 @@ ut_execute_for(struct ut_state *state, uint32_t off)
}
else if (json_object_is_type(val, json_type_object)) {
json_object_object_foreach(val, key, item) {
- json_object_put(ut_setval(kscope, ik, xjs_new_string(key)));
+ json_object_put(uc_setval(kscope, ik, xjs_new_string(key)));
if (iv)
- ut_setval(vscope, iv, item);
+ uc_setval(vscope, iv, item);
json_object_put(rv);
- rv = ut_execute_op_sequence(state, body);
+ rv = uc_execute_op_sequence(state, body);
tag = json_object_get_userdata(rv);
switch (tag ? tag->type : 0) {
@@ -592,18 +592,18 @@ ut_execute_for(struct ut_state *state, uint32_t off)
}
if (init) {
- val = ut_execute_op_sequence(state, ut_get_off(state, init));
+ val = uc_execute_op_sequence(state, uc_get_off(state, init));
- if (ut_is_type(val, T_EXCEPTION))
+ if (uc_is_type(val, T_EXCEPTION))
return val;
json_object_put(val);
}
- while (test ? ut_test_condition(state, test) : true) {
+ while (test ? uc_test_condition(state, test) : true) {
json_object_put(rv);
- rv = ut_execute_op_sequence(state, body);
+ rv = uc_execute_op_sequence(state, body);
tag = json_object_get_userdata(rv);
switch (tag ? tag->type : 0) {
@@ -618,9 +618,9 @@ ut_execute_for(struct ut_state *state, uint32_t off)
}
if (incr) {
- val = ut_execute_op_sequence(state, incr);
+ val = uc_execute_op_sequence(state, incr);
- if (ut_is_type(val, T_EXCEPTION)) {
+ if (uc_is_type(val, T_EXCEPTION)) {
json_object_put(rv);
return val;
@@ -636,22 +636,22 @@ ut_execute_for(struct ut_state *state, uint32_t off)
}
static struct json_object *
-ut_execute_while(struct ut_state *state, uint32_t off)
+uc_execute_while(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
+ struct uc_op *op = uc_get_op(state, off);
uint32_t test = op ? op->tree.operand[0] : 0;
uint32_t body = op ? op->tree.operand[1] : 0;
struct json_object *v, *rv = NULL;
- struct ut_op *tag = NULL;
+ struct uc_op *tag = NULL;
bool cond;
while (1) {
json_object_put(rv);
- v = test ? ut_execute_op_sequence(state, test) : NULL;
- cond = test ? ut_val_is_truish(v) : true;
+ v = test ? uc_execute_op_sequence(state, test) : NULL;
+ cond = test ? uc_val_is_truish(v) : true;
- if (ut_is_type(v, T_EXCEPTION))
+ if (uc_is_type(v, T_EXCEPTION))
return v;
json_object_put(v);
@@ -659,7 +659,7 @@ ut_execute_while(struct ut_state *state, uint32_t off)
if (!cond)
return NULL;
- rv = ut_execute_op_sequence(state, body);
+ rv = uc_execute_op_sequence(state, body);
tag = json_object_get_userdata(rv);
switch (tag ? tag->type : 0) {
@@ -680,21 +680,21 @@ ut_execute_while(struct ut_state *state, uint32_t off)
}
static struct json_object *
-ut_execute_and_or(struct ut_state *state, uint32_t off)
+uc_execute_and_or(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
+ struct uc_op *op = uc_get_op(state, off);
struct json_object *val = NULL;
int i;
for (i = 0; i < ARRAY_SIZE(op->tree.operand) && op->tree.operand[i]; i++) {
json_object_put(val);
- val = ut_execute_op_sequence(state, op->tree.operand[i]);
+ val = uc_execute_op_sequence(state, op->tree.operand[i]);
- if (ut_is_type(val, T_EXCEPTION))
+ if (uc_is_type(val, T_EXCEPTION))
break;
- if (ut_val_is_truish(val) == (op->type == T_OR))
+ if (uc_val_is_truish(val) == (op->type == T_OR))
break;
}
@@ -702,7 +702,7 @@ ut_execute_and_or(struct ut_state *state, uint32_t off)
}
bool
-ut_cmp(int how, struct json_object *v1, struct json_object *v2)
+uc_cmp(int how, struct json_object *v1, struct json_object *v2)
{
enum json_type t1 = json_object_get_type(v1);
enum json_type t2 = json_object_get_type(v2);
@@ -718,8 +718,8 @@ ut_cmp(int how, struct json_object *v1, struct json_object *v2)
delta = (void *)v1 - (void *)v2;
}
else {
- t1 = ut_cast_number(v1, &n1, &d1);
- t2 = ut_cast_number(v2, &n2, &d2);
+ t1 = uc_cast_number(v1, &n1, &d1);
+ t2 = uc_cast_number(v2, &n2, &d2);
if (t1 == json_type_double || t2 == json_type_double) {
d1 = (t1 == json_type_double) ? d1 : (double)n1;
@@ -763,26 +763,26 @@ ut_cmp(int how, struct json_object *v1, struct json_object *v2)
}
static struct json_object *
-_ut_get_operands(struct ut_state *state, struct ut_op *op, size_t n, struct json_object **v)
+_uc_get_operands(struct uc_state *state, struct uc_op *op, size_t n, struct json_object **v)
{
struct json_object *ctx = NULL;
- struct ut_op *child;
+ struct uc_op *child;
size_t i, j;
for (i = 0; i < n; i++) {
- child = op ? ut_get_op(state, op->tree.operand[i]) : NULL;
+ child = op ? uc_get_op(state, op->tree.operand[i]) : NULL;
if (child && child->is_list)
- v[i] = ut_execute_list(state, ut_get_off(state, child));
+ v[i] = uc_execute_list(state, uc_get_off(state, child));
else if (child)
- v[i] = ut_execute_op_sequence(state, ut_get_off(state, child));
+ v[i] = uc_execute_op_sequence(state, uc_get_off(state, child));
else
v[i] = NULL;
if (i == 0)
ctx = json_object_get(state->ctx);
- if (ut_is_type(v[i], T_EXCEPTION)) {
+ if (uc_is_type(v[i], T_EXCEPTION)) {
json_object_put(ctx);
for (j = 0; j < i; j++)
@@ -798,21 +798,21 @@ _ut_get_operands(struct ut_state *state, struct ut_op *op, size_t n, struct json
return NULL;
}
-#define ut_get_operands(state, op, vals) \
+#define uc_get_operands(state, op, vals) \
do { \
- struct json_object *ex = _ut_get_operands(state, op, ARRAY_SIZE(vals), vals); \
+ struct json_object *ex = _uc_get_operands(state, op, ARRAY_SIZE(vals), vals); \
if (ex) return ex; \
} while(0)
static struct json_object *
-ut_execute_rel(struct ut_state *state, uint32_t off)
+uc_execute_rel(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
+ struct uc_op *op = uc_get_op(state, off);
struct json_object *v[2], *rv;
- ut_get_operands(state, op, v);
+ uc_get_operands(state, op, v);
- rv = xjs_new_boolean(ut_cmp(op->type, v[0], v[1]));
+ rv = xjs_new_boolean(uc_cmp(op->type, v[0], v[1]));
json_object_put(v[0]);
json_object_put(v[1]);
@@ -821,10 +821,10 @@ ut_execute_rel(struct ut_state *state, uint32_t off)
}
static bool
-ut_eq(struct json_object *v1, struct json_object *v2)
+uc_eq(struct json_object *v1, struct json_object *v2)
{
- struct ut_op *tag1 = json_object_get_userdata(v1);
- struct ut_op *tag2 = json_object_get_userdata(v2);
+ struct uc_op *tag1 = json_object_get_userdata(v1);
+ struct uc_op *tag2 = json_object_get_userdata(v2);
enum json_type t1 = json_object_get_type(v1);
enum json_type t2 = json_object_get_type(v2);
@@ -862,15 +862,15 @@ ut_eq(struct json_object *v1, struct json_object *v2)
}
static struct json_object *
-ut_execute_equality(struct ut_state *state, uint32_t off)
+uc_execute_equality(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
+ struct uc_op *op = uc_get_op(state, off);
struct json_object *v[2], *rv;
bool equal = false;
- ut_get_operands(state, op, v);
+ uc_get_operands(state, op, v);
- equal = ut_eq(v[0], v[1]);
+ equal = uc_eq(v[0], v[1]);
rv = xjs_new_boolean((op->type == T_EQS) ? equal : !equal);
json_object_put(v[0]);
@@ -880,22 +880,22 @@ ut_execute_equality(struct ut_state *state, uint32_t off)
}
static struct json_object *
-ut_execute_in(struct ut_state *state, uint32_t off)
+uc_execute_in(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
+ struct uc_op *op = uc_get_op(state, off);
struct json_object *v[2], *item;
size_t arrlen, arridx;
bool found = false;
const char *key;
- ut_get_operands(state, op, v);
+ uc_get_operands(state, op, v);
if (json_object_is_type(v[1], json_type_array)) {
for (arridx = 0, arrlen = json_object_array_length(v[1]);
arridx < arrlen; arridx++) {
item = json_object_array_get_idx(v[1], arridx);
- if (ut_cmp(T_EQ, v[0], item)) {
+ if (uc_cmp(T_EQ, v[0], item)) {
found = true;
break;
}
@@ -913,30 +913,30 @@ ut_execute_in(struct ut_state *state, uint32_t off)
}
static struct json_object *
-ut_execute_inc_dec(struct ut_state *state, uint32_t off)
+uc_execute_inc_dec(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
+ struct uc_op *op = uc_get_op(state, off);
struct json_object *val, *nval, *scope, *key;
uint32_t label = op ? op->tree.operand[0] : 0;
int64_t n;
double d;
- scope = ut_getref_required(state, label, &key);
+ scope = uc_getref_required(state, label, &key);
if (!key)
return scope;
- val = ut_getval(scope, key);
+ val = uc_getval(scope, key);
json_object_put(scope);
json_object_put(key);
- if (ut_cast_number(val, &n, &d) == json_type_double)
- nval = ut_new_double(d + (op->type == T_INC ? 1.0 : -1.0));
+ if (uc_cast_number(val, &n, &d) == json_type_double)
+ nval = uc_new_double(d + (op->type == T_INC ? 1.0 : -1.0));
else
nval = xjs_new_int64(n + (op->type == T_INC ? 1 : -1));
- json_object_put(ut_setval(scope, key, nval));
+ json_object_put(uc_setval(scope, key, nval));
/* postfix inc/dec, return old val */
if (op->is_postfix)
@@ -948,16 +948,16 @@ ut_execute_inc_dec(struct ut_state *state, uint32_t off)
}
static struct json_object *
-ut_execute_list(struct ut_state *state, uint32_t off)
+uc_execute_list(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
+ struct uc_op *op = uc_get_op(state, off);
struct json_object *ex, *val, *arr = xjs_new_array();
size_t i;
while (op) {
- val = ut_execute_op(state, ut_get_off(state, op));
+ val = uc_execute_op(state, uc_get_off(state, op));
- if (ut_is_type(val, T_EXCEPTION)) {
+ if (uc_is_type(val, T_EXCEPTION)) {
json_object_put(arr);
return val;
@@ -965,7 +965,7 @@ ut_execute_list(struct ut_state *state, uint32_t off)
if (op->is_ellip) {
if (!json_object_is_type(val, json_type_array)) {
- ex = ut_new_exception(state, op->off, "Type error: (%s) is not iterable",
+ ex = uc_new_exception(state, op->off, "Type error: (%s) is not iterable",
json_object_get_string(val));
json_object_put(arr);
@@ -983,24 +983,24 @@ ut_execute_list(struct ut_state *state, uint32_t off)
json_object_array_add(arr, val);
}
- op = ut_get_op(state, op->tree.next);
+ op = uc_get_op(state, op->tree.next);
}
return arr;
}
static struct json_object *
-ut_execute_object(struct ut_state *state, uint32_t off)
+uc_execute_object(struct uc_state *state, uint32_t off)
{
- struct json_object *ex, *v, *obj = ut_new_object(NULL);
- struct ut_op *key;
+ struct json_object *ex, *v, *obj = uc_new_object(NULL);
+ struct uc_op *key;
char *istr;
size_t i;
- for (key = ut_get_child(state, off, 0); key; key = ut_get_op(state, key->tree.next)) {
- v = ut_execute_op_sequence(state, key->tree.operand[0]);
+ for (key = uc_get_child(state, off, 0); key; key = uc_get_op(state, key->tree.next)) {
+ v = uc_execute_op_sequence(state, key->tree.operand[0]);
- if (ut_is_type(v, T_EXCEPTION)) {
+ if (uc_is_type(v, T_EXCEPTION)) {
json_object_put(obj);
return v;
@@ -1029,7 +1029,7 @@ ut_execute_object(struct ut_state *state, uint32_t off)
break;
default:
- ex = ut_new_exception(state, key->off, "Type error: (%s) is not iterable",
+ ex = uc_new_exception(state, key->off, "Type error: (%s) is not iterable",
json_object_get_string(v));
json_object_put(obj);
@@ -1047,25 +1047,25 @@ ut_execute_object(struct ut_state *state, uint32_t off)
}
struct json_object *
-ut_invoke(struct ut_state *state, uint32_t off, struct json_object *this,
+uc_invoke(struct uc_state *state, uint32_t off, struct json_object *this,
struct json_object *func, struct json_object *argvals)
{
- struct ut_op *op, *tag = json_object_get_userdata(func);
+ struct uc_op *op, *tag = json_object_get_userdata(func);
struct json_object *arr, *rv = NULL;
- struct ut_callstack callstack = {};
- struct ut_function *fn, *prev_fn;
+ struct uc_callstack callstack = {};
+ struct uc_function *fn, *prev_fn;
size_t arridx, arglen;
- struct ut_scope *sc;
- ut_c_fn *fptr;
+ struct uc_scope *sc;
+ uc_c_fn *fptr;
bool rest;
if (!tag)
return NULL;
- op = ut_get_op(state, off);
+ op = uc_get_op(state, off);
if (state->calldepth >= 1000)
- return ut_new_exception(state, op->off, "Runtime error: Too much recursion");
+ return uc_new_exception(state, op->off, "Runtime error: Too much recursion");
callstack.next = state->callstack;
callstack.function = state->function;
@@ -1086,16 +1086,16 @@ ut_invoke(struct ut_state *state, uint32_t off, struct json_object *this,
/* is native function */
if (tag->type == T_CFUNC) {
- fptr = (ut_c_fn *)fn->cfn;
+ fptr = (uc_c_fn *)fn->cfn;
rv = fptr ? fptr(state, off, argvals) : NULL;
}
- /* is utpl function */
+ /* is ucode function */
else {
- callstack.scope = ut_new_scope(state, fn->parent_scope);
+ callstack.scope = uc_new_scope(state, fn->parent_scope);
sc = state->scope;
- state->scope = ut_acquire_scope(callstack.scope);
+ state->scope = uc_acquire_scope(callstack.scope);
if (fn->args) {
arglen = json_object_array_length(fn->args);
@@ -1106,7 +1106,7 @@ ut_invoke(struct ut_state *state, uint32_t off, struct json_object *this,
if (rest && arridx == arglen - 2) {
arr = xjs_new_array();
- ut_setval(callstack.scope->scope,
+ uc_setval(callstack.scope->scope,
json_object_array_get_idx(fn->args, arridx),
arr);
@@ -1116,21 +1116,21 @@ ut_invoke(struct ut_state *state, uint32_t off, struct json_object *this,
break;
}
- ut_setval(callstack.scope->scope, json_object_array_get_idx(fn->args, arridx),
+ uc_setval(callstack.scope->scope, json_object_array_get_idx(fn->args, arridx),
argvals ? json_object_array_get_idx(argvals, arridx) : NULL);
}
}
- rv = ut_execute_op_sequence(state, fn->entry);
+ rv = uc_execute_op_sequence(state, fn->entry);
tag = json_object_get_userdata(rv);
switch (tag ? tag->type : 0) {
case T_BREAK:
case T_CONTINUE:
json_object_put(rv);
- rv = ut_new_exception(state, ut_get_off(state, tag),
+ rv = uc_new_exception(state, uc_get_off(state, tag),
"Syntax error: %s statement must be inside loop",
- ut_get_tokenname(tag->type));
+ uc_get_tokenname(tag->type));
break;
case T_RETURN:
@@ -1140,11 +1140,11 @@ ut_invoke(struct ut_state *state, uint32_t off, struct json_object *this,
}
/* we left the function, pop the function scope... */
- ut_release_scope(state->scope);
+ uc_release_scope(state->scope);
state->scope = sc;
/* ... and release it */
- ut_release_scope(callstack.scope);
+ uc_release_scope(callstack.scope);
}
@@ -1158,21 +1158,21 @@ ut_invoke(struct ut_state *state, uint32_t off, struct json_object *this,
}
static struct json_object *
-ut_execute_call(struct ut_state *state, uint32_t off)
+uc_execute_call(struct uc_state *state, uint32_t off)
{
- struct ut_op *decl, *op = ut_get_op(state, off);
- struct ut_op *op1 = ut_get_child(state, off, 0);
+ struct uc_op *decl, *op = uc_get_op(state, off);
+ struct uc_op *op1 = uc_get_child(state, off, 0);
struct json_object *v[2], *rv;
char *lhs;
- ut_get_operands(state, op, v);
+ uc_get_operands(state, op, v);
decl = json_object_get_userdata(v[0]);
if (!decl || (decl->type != T_FUNC && decl->type != T_CFUNC)) {
- lhs = ut_ref_to_str(state, ut_get_off(state, op1));
+ lhs = uc_ref_to_str(state, uc_get_off(state, op1));
- rv = ut_new_exception(state, op1->off, "Type error: %s is not a function",
+ rv = uc_new_exception(state, op1->off, "Type error: %s is not a function",
lhs ? lhs : "left-hand side expression");
free(lhs);
@@ -1181,7 +1181,7 @@ ut_execute_call(struct ut_state *state, uint32_t off)
if (v[1] == NULL)
v[1] = xjs_new_array();
- rv = ut_invoke(state, off, NULL, v[0], v[1]);
+ rv = uc_invoke(state, off, NULL, v[0], v[1]);
}
json_object_put(v[0]);
@@ -1191,7 +1191,7 @@ ut_execute_call(struct ut_state *state, uint32_t off)
}
static void
-ut_write_str(struct json_object *v)
+uc_write_str(struct json_object *v)
{
const char *p;
size_t len;
@@ -1222,11 +1222,11 @@ ut_write_str(struct json_object *v)
}
static struct json_object *
-ut_execute_exp(struct ut_state *state, uint32_t off)
+uc_execute_exp(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
- struct json_object *val = ut_execute_op_sequence(state, op ? op->tree.operand[0] : 0);
- struct ut_op *tag = val ? json_object_get_userdata(val) : NULL;
+ struct uc_op *op = uc_get_op(state, off);
+ struct json_object *val = uc_execute_op_sequence(state, op ? op->tree.operand[0] : 0);
+ struct uc_op *tag = val ? json_object_get_userdata(val) : NULL;
switch (tag ? tag->type : 0) {
case T_EXCEPTION:
@@ -1234,7 +1234,7 @@ ut_execute_exp(struct ut_state *state, uint32_t off)
break;
default:
- ut_write_str(val);
+ uc_write_str(val);
break;
}
@@ -1244,18 +1244,18 @@ ut_execute_exp(struct ut_state *state, uint32_t off)
}
static struct json_object *
-ut_execute_unary_plus_minus(struct ut_state *state, uint32_t off)
+uc_execute_unary_plus_minus(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
- struct ut_op *op1 = ut_get_child(state, off, 0);
+ struct uc_op *op = uc_get_op(state, off);
+ struct uc_op *op1 = uc_get_child(state, off, 0);
struct json_object *v[1];
enum json_type t;
int64_t n;
double d;
- ut_get_operands(state, op, v);
+ uc_get_operands(state, op, v);
- t = ut_cast_number(v[0], &n, &d);
+ t = uc_cast_number(v[0], &n, &d);
json_object_put(v[0]);
@@ -1267,14 +1267,14 @@ ut_execute_unary_plus_minus(struct ut_state *state, uint32_t off)
return xjs_new_int64((op->type == T_SUB) ? -n : n);
default:
- return ut_new_double((op->type == T_SUB) ? -d : d);
+ return uc_new_double((op->type == T_SUB) ? -d : d);
}
}
static struct json_object *
-ut_execute_arith(struct ut_state *state, uint32_t off)
+uc_execute_arith(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
+ struct uc_op *op = uc_get_op(state, off);
struct json_object *v[2], *rv;
enum json_type t1, t2;
const char *s1, *s2;
@@ -1284,9 +1284,9 @@ ut_execute_arith(struct ut_state *state, uint32_t off)
char *s;
if (!op->tree.operand[1])
- return ut_execute_unary_plus_minus(state, off);
+ return uc_execute_unary_plus_minus(state, off);
- ut_get_operands(state, op, v);
+ uc_get_operands(state, op, v);
if (op->type == T_ADD &&
(json_object_is_type(v[0], json_type_string) ||
@@ -1308,8 +1308,8 @@ ut_execute_arith(struct ut_state *state, uint32_t off)
return rv;
}
- t1 = ut_cast_number(v[0], &n1, &d1);
- t2 = ut_cast_number(v[1], &n2, &d2);
+ t1 = uc_cast_number(v[0], &n1, &d1);
+ t2 = uc_cast_number(v[1], &n2, &d2);
json_object_put(v[0]);
json_object_put(v[1]);
@@ -1320,26 +1320,26 @@ ut_execute_arith(struct ut_state *state, uint32_t off)
switch (op->type) {
case T_ADD:
- return ut_new_double(d1 + d2);
+ return uc_new_double(d1 + d2);
case T_SUB:
- return ut_new_double(d1 - d2);
+ return uc_new_double(d1 - d2);
case T_MUL:
- return ut_new_double(d1 * d2);
+ return uc_new_double(d1 * d2);
case T_DIV:
if (d2 == 0.0)
- return ut_new_double(INFINITY);
+ return uc_new_double(INFINITY);
else if (isnan(d2))
- return ut_new_double(NAN);
+ return uc_new_double(NAN);
else if (!isfinite(d2))
- return ut_new_double(isfinite(d1) ? 0.0 : NAN);
+ return uc_new_double(isfinite(d1) ? 0.0 : NAN);
- return ut_new_double(d1 / d2);
+ return uc_new_double(d1 / d2);
case T_MOD:
- return ut_new_double(NAN);
+ return uc_new_double(NAN);
}
}
@@ -1355,7 +1355,7 @@ ut_execute_arith(struct ut_state *state, uint32_t off)
case T_DIV:
if (n2 == 0)
- return ut_new_double(INFINITY);
+ return uc_new_double(INFINITY);
return xjs_new_int64(n1 / n2);
@@ -1363,23 +1363,23 @@ ut_execute_arith(struct ut_state *state, uint32_t off)
return xjs_new_int64(n1 % n2);
}
- return ut_new_double(NAN);
+ return uc_new_double(NAN);
}
static struct json_object *
-ut_execute_bitop(struct ut_state *state, uint32_t off)
+uc_execute_bitop(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
+ struct uc_op *op = uc_get_op(state, off);
struct json_object *v[2];
int64_t n1, n2;
double d;
- ut_get_operands(state, op, v);
+ uc_get_operands(state, op, v);
- if (ut_cast_number(v[0], &n1, &d) == json_type_double)
+ if (uc_cast_number(v[0], &n1, &d) == json_type_double)
n1 = isnan(d) ? 0 : (int64_t)d;
- if (ut_cast_number(v[1], &n2, &d) == json_type_double)
+ if (uc_cast_number(v[1], &n2, &d) == json_type_double)
n2 = isnan(d) ? 0 : (int64_t)d;
json_object_put(v[0]);
@@ -1407,24 +1407,24 @@ ut_execute_bitop(struct ut_state *state, uint32_t off)
}
static struct json_object *
-ut_execute_not(struct ut_state *state, uint32_t off)
+uc_execute_not(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
+ struct uc_op *op = uc_get_op(state, off);
- return xjs_new_boolean(!ut_test_condition(state, op ? op->tree.operand[0] : 0));
+ return xjs_new_boolean(!uc_test_condition(state, op ? op->tree.operand[0] : 0));
}
static struct json_object *
-ut_execute_compl(struct ut_state *state, uint32_t off)
+uc_execute_compl(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
+ struct uc_op *op = uc_get_op(state, off);
struct json_object *v[1];
int64_t n;
double d;
- ut_get_operands(state, op, v);
+ uc_get_operands(state, op, v);
- if (ut_cast_number(v[0], &n, &d) == json_type_double)
+ if (uc_cast_number(v[0], &n, &d) == json_type_double)
n = isnan(d) ? 0 : (int64_t)d;
json_object_put(v[0]);
@@ -1433,12 +1433,12 @@ ut_execute_compl(struct ut_state *state, uint32_t off)
}
static struct json_object *
-ut_execute_return(struct ut_state *state, uint32_t off)
+uc_execute_return(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
+ struct uc_op *op = uc_get_op(state, off);
struct json_object *v[1], *rv;
- ut_get_operands(state, op, v);
+ uc_get_operands(state, op, v);
json_object_put(state->rval);
state->rval = v[0];
@@ -1451,9 +1451,9 @@ ut_execute_return(struct ut_state *state, uint32_t off)
}
static struct json_object *
-ut_execute_break_cont(struct ut_state *state, uint32_t off)
+uc_execute_break_cont(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
+ struct uc_op *op = uc_get_op(state, off);
struct json_object *rv = xjs_new_int64(0);
json_object_set_userdata(rv, op, NULL);
@@ -1462,40 +1462,40 @@ ut_execute_break_cont(struct ut_state *state, uint32_t off)
}
static struct json_object *
-ut_execute_function(struct ut_state *state, uint32_t off)
+uc_execute_function(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
- struct ut_op *op1 = ut_get_child(state, off, 0);
- struct json_object *obj = ut_new_func(state, op, state->scope);
+ struct uc_op *op = uc_get_op(state, off);
+ struct uc_op *op1 = uc_get_child(state, off, 0);
+ struct json_object *obj = uc_new_func(state, op, state->scope);
if (op1)
- ut_setval(state->scope->scope, op1->val, obj);
+ uc_setval(state->scope->scope, op1->val, obj);
return obj;
}
static struct json_object *
-ut_execute_this(struct ut_state *state, uint32_t off)
+uc_execute_this(struct uc_state *state, uint32_t off)
{
return json_object_get(state->callstack->ctx);
}
static struct json_object *
-ut_execute_try_catch(struct ut_state *state, uint32_t off)
+uc_execute_try_catch(struct uc_state *state, uint32_t off)
{
- struct ut_op *tag, *op = ut_get_op(state, off);
+ struct uc_op *tag, *op = uc_get_op(state, off);
struct json_object *rv;
- rv = ut_execute_op_sequence(state, op->tree.operand[0]);
+ rv = uc_execute_op_sequence(state, op->tree.operand[0]);
- if (ut_is_type(rv, T_EXCEPTION)) {
+ if (uc_is_type(rv, T_EXCEPTION)) {
if (op->tree.operand[1]) {
/* remove the T_EXCEPTION type from the object to avoid handling
* it as a new exception in the catch block */
tag = json_object_get_userdata(rv);
tag->type = T_LBRACE;
- json_object_put(ut_setval(state->scope->scope, ut_get_child(state, off, 1)->val,
+ json_object_put(uc_setval(state->scope->scope, uc_get_child(state, off, 1)->val,
json_object_get(rv)));
}
@@ -1503,42 +1503,42 @@ ut_execute_try_catch(struct ut_state *state, uint32_t off)
state->exception = NULL;
json_object_put(rv);
- rv = ut_execute_op_sequence(state, op->tree.operand[2]);
+ rv = uc_execute_op_sequence(state, op->tree.operand[2]);
}
return rv;
}
static bool
-ut_match_case(struct ut_state *state, struct json_object *v, struct ut_op *Case)
+uc_match_case(struct uc_state *state, struct json_object *v, struct uc_op *Case)
{
- struct json_object *caseval = ut_execute_op_sequence(state, Case->tree.operand[0]);
- bool rv = ut_eq(v, caseval);
+ struct json_object *caseval = uc_execute_op_sequence(state, Case->tree.operand[0]);
+ bool rv = uc_eq(v, caseval);
json_object_put(caseval);
return rv;
}
static struct json_object *
-ut_execute_switch_case(struct ut_state *state, uint32_t off)
+uc_execute_switch_case(struct uc_state *state, uint32_t off)
{
- struct ut_op *Default = NULL, *Case = NULL, *jmp = NULL;
- struct ut_op *op = ut_get_op(state, off);
+ struct uc_op *Default = NULL, *Case = NULL, *jmp = NULL;
+ struct uc_op *op = uc_get_op(state, off);
struct json_object *v[1], *rv = NULL;
- ut_get_operands(state, op, v);
+ uc_get_operands(state, op, v);
/* First try to find matching case... */
- for (Case = ut_get_child(state, off, 1);
+ for (Case = uc_get_child(state, off, 1);
Case != NULL;
- Case = ut_get_op(state, Case->tree.next))
+ Case = uc_get_op(state, Case->tree.next))
{
/* remember default case and throw on dupes */
if (Case->type == T_DEFAULT) {
if (Default) {
json_object_put(v[0]);
- return ut_new_exception(state, Case->off,
+ return uc_new_exception(state, Case->off,
"Syntax error: more than one switch default case");
}
@@ -1547,7 +1547,7 @@ ut_execute_switch_case(struct ut_state *state, uint32_t off)
}
/* Found a matching case, remember jump offset */
- if (ut_match_case(state, v[0], Case)) {
+ if (uc_match_case(state, v[0], Case)) {
jmp = Case;
break;
}
@@ -1556,21 +1556,21 @@ ut_execute_switch_case(struct ut_state *state, uint32_t off)
/* jump to matching case (or default) and continue until break */
for (Case = jmp ? jmp : Default;
Case != NULL;
- Case = ut_get_op(state, Case->tree.next))
+ Case = uc_get_op(state, Case->tree.next))
{
json_object_put(rv);
if (Case == Default)
- rv = ut_execute_op_sequence(state, Default->tree.operand[0]);
+ rv = uc_execute_op_sequence(state, Default->tree.operand[0]);
else
- rv = ut_execute_op_sequence(state, Case->tree.operand[1]);
+ rv = uc_execute_op_sequence(state, Case->tree.operand[1]);
- if (ut_is_type(rv, T_BREAK)) {
+ if (uc_is_type(rv, T_BREAK)) {
json_object_put(rv);
rv = NULL;
break;
}
- else if (ut_is_type(rv, T_RETURN) || ut_is_type(rv, T_EXCEPTION) || ut_is_type(rv, T_CONTINUE)) {
+ else if (uc_is_type(rv, T_RETURN) || uc_is_type(rv, T_EXCEPTION) || uc_is_type(rv, T_CONTINUE)) {
break;
}
}
@@ -1581,37 +1581,37 @@ ut_execute_switch_case(struct ut_state *state, uint32_t off)
}
static struct json_object *
-ut_execute_atom(struct ut_state *state, uint32_t off)
+uc_execute_atom(struct uc_state *state, uint32_t off)
{
- return json_object_get(ut_get_op(state, off)->val);
+ return json_object_get(uc_get_op(state, off)->val);
}
static struct json_object *
-ut_execute_text(struct ut_state *state, uint32_t off)
+uc_execute_text(struct uc_state *state, uint32_t off)
{
- printf("%s", json_object_get_string(ut_get_op(state, off)->val));
+ printf("%s", json_object_get_string(uc_get_op(state, off)->val));
return NULL;
}
static struct json_object *
-ut_execute_label(struct ut_state *state, uint32_t off)
+uc_execute_label(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
+ struct uc_op *op = uc_get_op(state, off);
struct json_object *scope, *key, *val;
- scope = ut_getref(state, off, &key);
+ scope = uc_getref(state, off, &key);
json_object_put(state->ctx);
state->ctx = NULL;
if (state->strict_declarations && scope == NULL) {
- return ut_new_exception(state, op->off,
+ return uc_new_exception(state, op->off,
"Reference error: %s is not defined",
json_object_get_string(op->val));
}
- val = ut_getval(scope, key);
+ val = uc_getval(scope, key);
json_object_put(scope);
json_object_put(key);
@@ -1619,11 +1619,11 @@ ut_execute_label(struct ut_state *state, uint32_t off)
}
static struct json_object *
-ut_execute_dot(struct ut_state *state, uint32_t off)
+uc_execute_dot(struct uc_state *state, uint32_t off)
{
struct json_object *scope, *key, *val;
- scope = ut_getref_required(state, off, &key);
+ scope = uc_getref_required(state, off, &key);
json_object_put(state->ctx);
state->ctx = json_object_get(scope);
@@ -1631,7 +1631,7 @@ ut_execute_dot(struct ut_state *state, uint32_t off)
if (!key)
return scope;
- val = ut_getval(scope, key);
+ val = uc_getval(scope, key);
json_object_put(scope);
json_object_put(key);
@@ -1639,104 +1639,104 @@ ut_execute_dot(struct ut_state *state, uint32_t off)
}
static struct json_object *
-ut_execute_lbrack(struct ut_state *state, uint32_t off)
+uc_execute_lbrack(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
+ struct uc_op *op = uc_get_op(state, off);
/* postfix access */
if (op->is_postfix)
- return ut_execute_dot(state, off);
+ return uc_execute_dot(state, off);
- return ut_execute_list(state, op->tree.operand[0]);
+ return uc_execute_list(state, op->tree.operand[0]);
}
static struct json_object *
-ut_execute_exp_list(struct ut_state *state, uint32_t off)
+uc_execute_exp_list(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
+ struct uc_op *op = uc_get_op(state, off);
- return ut_execute_op_sequence(state, op->tree.operand[0]);
+ return uc_execute_op_sequence(state, op->tree.operand[0]);
}
-static struct json_object *(*fns[__T_MAX])(struct ut_state *, uint32_t) = {
- [T_NUMBER] = ut_execute_atom,
- [T_DOUBLE] = ut_execute_atom,
- [T_STRING] = ut_execute_atom,
- [T_REGEXP] = ut_execute_atom,
- [T_BOOL] = ut_execute_atom,
- [T_NULL] = ut_execute_atom,
- [T_THIS] = ut_execute_this,
- [T_FUNC] = ut_execute_function,
- [T_ARROW] = ut_execute_function,
- [T_TEXT] = ut_execute_text,
- [T_ASSIGN] = ut_execute_assign,
- [T_LOCAL] = ut_execute_local,
- [T_LABEL] = ut_execute_label,
- [T_DOT] = ut_execute_dot,
- [T_LBRACK] = ut_execute_lbrack,
- [T_LBRACE] = ut_execute_object,
- [T_IF] = ut_execute_if,
- [T_ELIF] = ut_execute_if,
- [T_QMARK] = ut_execute_if,
- [T_FOR] = ut_execute_for,
- [T_WHILE] = ut_execute_while,
- [T_AND] = ut_execute_and_or,
- [T_OR] = ut_execute_and_or,
- [T_LT] = ut_execute_rel,
- [T_LE] = ut_execute_rel,
- [T_GT] = ut_execute_rel,
- [T_GE] = ut_execute_rel,
- [T_EQ] = ut_execute_rel,
- [T_NE] = ut_execute_rel,
- [T_EQS] = ut_execute_equality,
- [T_NES] = ut_execute_equality,
- [T_IN] = ut_execute_in,
- [T_INC] = ut_execute_inc_dec,
- [T_DEC] = ut_execute_inc_dec,
- [T_LPAREN] = ut_execute_call,
- [T_LEXP] = ut_execute_exp,
- [T_ADD] = ut_execute_arith,
- [T_SUB] = ut_execute_arith,
- [T_MUL] = ut_execute_arith,
- [T_DIV] = ut_execute_arith,
- [T_MOD] = ut_execute_arith,
- [T_LSHIFT] = ut_execute_bitop,
- [T_RSHIFT] = ut_execute_bitop,
- [T_BAND] = ut_execute_bitop,
- [T_BXOR] = ut_execute_bitop,
- [T_BOR] = ut_execute_bitop,
- [T_COMPL] = ut_execute_compl,
- [T_NOT] = ut_execute_not,
- [T_RETURN] = ut_execute_return,
- [T_BREAK] = ut_execute_break_cont,
- [T_CONTINUE] = ut_execute_break_cont,
- [T_TRY] = ut_execute_try_catch,
- [T_SWITCH] = ut_execute_switch_case,
- [T_COMMA] = ut_execute_exp_list,
+static struct json_object *(*fns[__T_MAX])(struct uc_state *, uint32_t) = {
+ [T_NUMBER] = uc_execute_atom,
+ [T_DOUBLE] = uc_execute_atom,
+ [T_STRING] = uc_execute_atom,
+ [T_REGEXP] = uc_execute_atom,
+ [T_BOOL] = uc_execute_atom,
+ [T_NULL] = uc_execute_atom,
+ [T_THIS] = uc_execute_this,
+ [T_FUNC] = uc_execute_function,
+ [T_ARROW] = uc_execute_function,
+ [T_TEXT] = uc_execute_text,
+ [T_ASSIGN] = uc_execute_assign,
+ [T_LOCAL] = uc_execute_local,
+ [T_LABEL] = uc_execute_label,
+ [T_DOT] = uc_execute_dot,
+ [T_LBRACK] = uc_execute_lbrack,
+ [T_LBRACE] = uc_execute_object,
+ [T_IF] = uc_execute_if,
+ [T_ELIF] = uc_execute_if,
+ [T_QMARK] = uc_execute_if,
+ [T_FOR] = uc_execute_for,
+ [T_WHILE] = uc_execute_while,
+ [T_AND] = uc_execute_and_or,
+ [T_OR] = uc_execute_and_or,
+ [T_LT] = uc_execute_rel,
+ [T_LE] = uc_execute_rel,
+ [T_GT] = uc_execute_rel,
+ [T_GE] = uc_execute_rel,
+ [T_EQ] = uc_execute_rel,
+ [T_NE] = uc_execute_rel,
+ [T_EQS] = uc_execute_equality,
+ [T_NES] = uc_execute_equality,
+ [T_IN] = uc_execute_in,
+ [T_INC] = uc_execute_inc_dec,
+ [T_DEC] = uc_execute_inc_dec,
+ [T_LPAREN] = uc_execute_call,
+ [T_LEXP] = uc_execute_exp,
+ [T_ADD] = uc_execute_arith,
+ [T_SUB] = uc_execute_arith,
+ [T_MUL] = uc_execute_arith,
+ [T_DIV] = uc_execute_arith,
+ [T_MOD] = uc_execute_arith,
+ [T_LSHIFT] = uc_execute_bitop,
+ [T_RSHIFT] = uc_execute_bitop,
+ [T_BAND] = uc_execute_bitop,
+ [T_BXOR] = uc_execute_bitop,
+ [T_BOR] = uc_execute_bitop,
+ [T_COMPL] = uc_execute_compl,
+ [T_NOT] = uc_execute_not,
+ [T_RETURN] = uc_execute_return,
+ [T_BREAK] = uc_execute_break_cont,
+ [T_CONTINUE] = uc_execute_break_cont,
+ [T_TRY] = uc_execute_try_catch,
+ [T_SWITCH] = uc_execute_switch_case,
+ [T_COMMA] = uc_execute_exp_list,
};
static struct json_object *
-ut_execute_op(struct ut_state *state, uint32_t off)
+uc_execute_op(struct uc_state *state, uint32_t off)
{
- struct ut_op *op = ut_get_op(state, off);
+ struct uc_op *op = uc_get_op(state, off);
if (!fns[op->type])
- return ut_new_exception(state, op->off, "Runtime error: Unrecognized opcode %d", op->type);
+ return uc_new_exception(state, op->off, "Runtime error: Unrecognized opcode %d", op->type);
return fns[op->type](state, off);
}
static struct json_object *
-ut_execute_op_sequence(struct ut_state *state, uint32_t off)
+uc_execute_op_sequence(struct uc_state *state, uint32_t off)
{
struct json_object *v = NULL;
- struct ut_op *tag = NULL;
- struct ut_op *op = NULL;
+ struct uc_op *tag = NULL;
+ struct uc_op *op = NULL;
while (off) {
json_object_put(v);
- v = ut_execute_op(state, off);
+ v = uc_execute_op(state, off);
tag = v ? json_object_get_userdata(v) : NULL;
switch (tag ? tag->type : 0) {
@@ -1747,7 +1747,7 @@ ut_execute_op_sequence(struct ut_state *state, uint32_t off)
return v;
}
- op = ut_get_op(state, off);
+ op = uc_get_op(state, off);
off = op ? op->tree.next : 0;
}
@@ -1755,7 +1755,7 @@ ut_execute_op_sequence(struct ut_state *state, uint32_t off)
}
static void
-ut_globals_init(struct ut_state *state, struct json_object *scope)
+uc_globals_init(struct uc_state *state, struct json_object *scope)
{
struct json_object *arr = xjs_new_array();
const char *p, *last;
@@ -1775,7 +1775,7 @@ ut_globals_init(struct ut_state *state, struct json_object *scope)
}
static void
-ut_register_variable(struct json_object *scope, const char *key, struct json_object *val)
+uc_register_variable(struct json_object *scope, const char *key, struct json_object *val)
{
char *name = strdup(key);
char *p;
@@ -1792,13 +1792,13 @@ ut_register_variable(struct json_object *scope, const char *key, struct json_obj
}
struct json_object *
-ut_run(struct ut_state *state, struct json_object *env, struct json_object *modules)
+uc_run(struct uc_state *state, struct json_object *env, struct json_object *modules)
{
struct json_object *args, *rv;
- struct ut_function fn = {};
+ struct uc_function fn = {};
size_t i;
- state->scope = ut_new_scope(state, NULL);
+ state->scope = uc_new_scope(state, NULL);
state->ctx = NULL;
fn.source = state->source;
@@ -1806,11 +1806,11 @@ ut_run(struct ut_state *state, struct json_object *env, struct json_object *modu
if (env) {
json_object_object_foreach(env, key, val)
- ut_register_variable(state->scope->scope, key, json_object_get(val));
+ uc_register_variable(state->scope->scope, key, json_object_get(val));
}
- ut_globals_init(state, state->scope->scope);
- ut_lib_init(state, state->scope->scope);
+ uc_globals_init(state, state->scope->scope);
+ uc_lib_init(state, state->scope->scope);
if (modules) {
args = xjs_new_array();
@@ -1818,14 +1818,14 @@ ut_run(struct ut_state *state, struct json_object *env, struct json_object *modu
for (i = 0; i < json_object_array_length(modules); i++) {
json_object_array_put_idx(args, 0, json_object_get(json_object_array_get_idx(modules, i)));
- rv = ut_invoke(state, 0, NULL,
+ rv = uc_invoke(state, 0, NULL,
json_object_object_get(state->scope->scope, "require"),
args);
- if (ut_is_type(rv, T_EXCEPTION))
+ if (uc_is_type(rv, T_EXCEPTION))
goto out;
- ut_register_variable(state->scope->scope,
+ uc_register_variable(state->scope->scope,
json_object_get_string(json_object_array_get_idx(modules, i)),
rv);
}
@@ -1833,10 +1833,10 @@ ut_run(struct ut_state *state, struct json_object *env, struct json_object *modu
json_object_put(args);
}
- rv = ut_execute_source(state, state->source, state->scope);
+ rv = uc_execute_source(state, state->source, state->scope);
out:
- ut_release_scope(state->scope);
+ uc_release_scope(state->scope);
return rv;
}
diff --git a/eval.h b/eval.h
index 7cfd0e0..d18ec16 100644
--- a/eval.h
+++ b/eval.h
@@ -25,18 +25,18 @@
#include "ast.h"
bool
-ut_cmp(int how, struct json_object *v1, struct json_object *v2);
+uc_cmp(int how, struct json_object *v1, struct json_object *v2);
bool
-ut_val_is_truish(struct json_object *val);
+uc_val_is_truish(struct json_object *val);
enum json_type
-ut_cast_number(struct json_object *v, int64_t *n, double *d);
+uc_cast_number(struct json_object *v, int64_t *n, double *d);
struct json_object *
-ut_invoke(struct ut_state *, uint32_t, struct json_object *, struct json_object *, struct json_object *);
+uc_invoke(struct uc_state *, uint32_t, struct json_object *, struct json_object *, struct json_object *);
struct json_object *
-ut_run(struct ut_state *state, struct json_object *env, struct json_object *modules);
+uc_run(struct uc_state *state, struct json_object *env, struct json_object *modules);
#endif
diff --git a/lexer.c b/lexer.c
index 1982dea..2867e76 100644
--- a/lexer.c
+++ b/lexer.c
@@ -48,7 +48,7 @@ struct token {
char pat[4];
};
int plen;
- uint32_t (*parse)(struct ut_state *s);
+ uint32_t (*parse)(struct uc_state *s);
};
#define dec(o) \
@@ -58,11 +58,11 @@ struct token {
(((x) >= 'a') ? (10 + (x) - 'a') : \
(((x) >= 'A') ? (10 + (x) - 'A') : dec(x)))
-static uint32_t parse_comment(struct ut_state *);
-static uint32_t parse_string(struct ut_state *);
-static uint32_t parse_regexp(struct ut_state *);
-static uint32_t parse_number(struct ut_state *);
-static uint32_t parse_label(struct ut_state *);
+static uint32_t parse_comment(struct uc_state *);
+static uint32_t parse_string(struct uc_state *);
+static uint32_t parse_regexp(struct uc_state *);
+static uint32_t parse_number(struct uc_state *);
+static uint32_t parse_label(struct uc_state *);
static const struct token tokens[] = {
{ T_ASLEFT, { .pat = "<<=" }, 3 },
@@ -221,10 +221,10 @@ utf8enc(char **out, int *rem, int code)
/* length of the longest token in our lookup table */
#define UT_LEX_MAX_TOKEN_LEN 3
-static uint32_t emit_op(struct ut_state *s, uint32_t pos, int type, struct json_object *val)
+static uint32_t emit_op(struct uc_state *s, uint32_t pos, int type, struct json_object *val)
{
- uint32_t off = ut_new_op(s, type, val, UINT32_MAX);
- struct ut_op *op = ut_get_op(s, off);
+ uint32_t off = uc_new_op(s, type, val, UINT32_MAX);
+ struct uc_op *op = uc_get_op(s, off);
op->off = pos;
@@ -282,7 +282,7 @@ static uint32_t emit_op(struct ut_state *s, uint32_t pos, int type, struct json_
return off;
}
-static void lookbehind_append(struct ut_state *s, const char *data, size_t len)
+static void lookbehind_append(struct uc_state *s, const char *data, size_t len)
{
if (len) {
s->lex.lookbehind = xrealloc(s->lex.lookbehind, s->lex.lookbehindlen + len);
@@ -291,13 +291,13 @@ static void lookbehind_append(struct ut_state *s, const char *data, size_t len)
}
}
-static void lookbehind_reset(struct ut_state *s) {
+static void lookbehind_reset(struct uc_state *s) {
free(s->lex.lookbehind);
s->lex.lookbehind = NULL;
s->lex.lookbehindlen = 0;
}
-static uint32_t lookbehind_to_text(struct ut_state *s, uint32_t pos, int type, const char *strip_trailing_chars) {
+static uint32_t lookbehind_to_text(struct uc_state *s, uint32_t pos, int type, const char *strip_trailing_chars) {
uint32_t rv = 0;
if (s->lex.lookbehind) {
@@ -314,30 +314,30 @@ static uint32_t lookbehind_to_text(struct ut_state *s, uint32_t pos, int type, c
return rv;
}
-static inline size_t buf_remaining(struct ut_state *s) {
+static inline size_t buf_remaining(struct uc_state *s) {
return (s->lex.bufend - s->lex.bufstart);
}
-static inline bool _buf_startswith(struct ut_state *s, const char *str, size_t len) {
+static inline bool _buf_startswith(struct uc_state *s, const char *str, size_t len) {
return (buf_remaining(s) >= len && !strncmp(s->lex.bufstart, str, len));
}
#define buf_startswith(s, str) _buf_startswith(s, str, sizeof(str) - 1)
-static void buf_consume(struct ut_state *s, ssize_t len) {
+static void buf_consume(struct uc_state *s, ssize_t len) {
s->lex.bufstart += len;
s->source->off += len;
}
static uint32_t
-parse_comment(struct ut_state *s)
+parse_comment(struct uc_state *s)
{
const struct token *tok = s->lex.tok;
const char *ptr, *end;
size_t elen;
if (!buf_remaining(s)) {
- ut_new_exception(s, s->lex.lastoff, "Syntax error: Unterminated comment");
+ uc_new_exception(s, s->lex.lastoff, "Syntax error: Unterminated comment");
return 0;
}
@@ -364,7 +364,7 @@ parse_comment(struct ut_state *s)
return 0;
}
-static void append_utf8(struct ut_state *s, int code) {
+static void append_utf8(struct uc_state *s, int code) {
char ustr[8], *up;
int rem;
@@ -376,7 +376,7 @@ static void append_utf8(struct ut_state *s, int code) {
}
static uint32_t
-parse_string(struct ut_state *s)
+parse_string(struct uc_state *s)
{
const struct token *tok = s->lex.tok;
char q = tok->pat[0];
@@ -385,7 +385,7 @@ parse_string(struct ut_state *s)
int code;
if (!buf_remaining(s)) {
- ut_new_exception(s, s->lex.lastoff, "Syntax error: Unterminated string");
+ uc_new_exception(s, s->lex.lastoff, "Syntax error: Unterminated string");
return 0;
}
@@ -452,7 +452,7 @@ parse_string(struct ut_state *s)
case 'u':
if (s->lex.esclen < 5) {
if (!isxdigit(*ptr)) {
- ut_new_exception(s, s->source->off + s->lex.esclen + 1, "Syntax error: Invalid escape sequence");
+ uc_new_exception(s, s->source->off + s->lex.esclen + 1, "Syntax error: Invalid escape sequence");
return 0;
}
@@ -507,7 +507,7 @@ parse_string(struct ut_state *s)
case 'x':
if (s->lex.esclen < 3) {
if (!isxdigit(*ptr)) {
- ut_new_exception(s, s->source->off + s->lex.esclen + 1, "Syntax error: Invalid escape sequence");
+ uc_new_exception(s, s->source->off + s->lex.esclen + 1, "Syntax error: Invalid escape sequence");
return 0;
}
@@ -561,7 +561,7 @@ parse_string(struct ut_state *s)
dec(s->lex.esc[3]);
if (code > 255) {
- ut_new_exception(s, s->source->off + s->lex.esclen + 1, "Syntax error: Invalid escape sequence");
+ uc_new_exception(s, s->source->off + s->lex.esclen + 1, "Syntax error: Invalid escape sequence");
return 0;
}
@@ -625,10 +625,10 @@ enum {
};
static uint32_t
-parse_regexp(struct ut_state *s)
+parse_regexp(struct uc_state *s)
{
struct json_object *pattern;
- struct ut_op *op;
+ struct uc_op *op;
uint32_t rv;
char *err;
@@ -653,14 +653,14 @@ parse_regexp(struct ut_state *s)
rv = parse_string(s);
if (rv != 0 && rv != UINT32_MAX) {
- s->lex.lookbehind = (char *)ut_get_op(s, rv);
+ s->lex.lookbehind = (char *)uc_get_op(s, rv);
s->lex.esc[0] = UT_LEX_PARSE_REGEX_FLAGS;
}
break;
case UT_LEX_PARSE_REGEX_FLAGS:
- op = (struct ut_op *)s->lex.lookbehind;
+ op = (struct uc_op *)s->lex.lookbehind;
while (s->lex.bufstart < s->lex.bufend) {
switch (s->lex.bufstart[0]) {
@@ -682,7 +682,7 @@ parse_regexp(struct ut_state *s)
default:
s->lex.lookbehind = NULL;
- pattern = ut_new_regexp(json_object_get_string(op->val),
+ pattern = uc_new_regexp(json_object_get_string(op->val),
op->is_reg_icase,
op->is_reg_newline,
op->is_reg_global,
@@ -694,13 +694,13 @@ parse_regexp(struct ut_state *s)
op->val = pattern;
if (!pattern) {
- ut_new_exception(s, op->off, "Syntax error: %s", err);
+ uc_new_exception(s, op->off, "Syntax error: %s", err);
free(err);
return 0;
}
- return ut_get_off(s, op);
+ return uc_get_off(s, op);
}
}
@@ -722,7 +722,7 @@ parse_regexp(struct ut_state *s)
*/
static uint32_t
-parse_label(struct ut_state *s)
+parse_label(struct uc_state *s)
{
const struct token *tok = s->lex.tok;
const struct keyword *word;
@@ -740,7 +740,7 @@ parse_label(struct ut_state *s)
switch (word->type) {
case T_DOUBLE:
- rv = emit_op(s, s->source->off - word->plen, word->type, ut_new_double(word->d));
+ rv = emit_op(s, s->source->off - word->plen, word->type, uc_new_double(word->d));
break;
case T_BOOL:
@@ -779,7 +779,7 @@ parse_label(struct ut_state *s)
*/
static inline bool
-is_numeric_char(struct ut_state *s, char c)
+is_numeric_char(struct uc_state *s, char c)
{
char prev = s->lex.lookbehindlen ? s->lex.lookbehind[s->lex.lookbehindlen-1] : 0;
@@ -790,7 +790,7 @@ is_numeric_char(struct ut_state *s, char c)
}
static uint32_t
-parse_number(struct ut_state *s)
+parse_number(struct uc_state *s)
{
uint32_t rv = 0;
long long int n;
@@ -806,17 +806,17 @@ parse_number(struct ut_state *s)
d = strtod(s->lex.lookbehind, &e);
if (e > s->lex.lookbehind && *e == 0)
- rv = emit_op(s, s->source->off - (e - s->lex.lookbehind), T_DOUBLE, ut_new_double(d));
+ rv = emit_op(s, s->source->off - (e - s->lex.lookbehind), T_DOUBLE, uc_new_double(d));
else
- ut_new_exception(s, s->source->off - (s->lex.lookbehindlen - (e - s->lex.lookbehind) - 1),
+ uc_new_exception(s, s->source->off - (s->lex.lookbehindlen - (e - s->lex.lookbehind) - 1),
"Syntax error: Invalid number literal");
}
else if (*e == 0) {
rv = emit_op(s, s->source->off - (e - s->lex.lookbehind), T_NUMBER, xjs_new_int64(n));
- ut_get_op(s, rv)->is_overflow = (errno == ERANGE);
+ uc_get_op(s, rv)->is_overflow = (errno == ERANGE);
}
else {
- ut_new_exception(s, s->source->off - (s->lex.lookbehindlen - (e - s->lex.lookbehind) - 1),
+ uc_new_exception(s, s->source->off - (s->lex.lookbehindlen - (e - s->lex.lookbehind) - 1),
"Syntax error: Invalid number literal");
}
@@ -835,7 +835,7 @@ parse_number(struct ut_state *s)
}
static uint32_t
-lex_step(struct ut_state *s, FILE *fp)
+lex_step(struct uc_state *s, FILE *fp)
{
uint32_t masks[] = { 0, le32toh(0x000000ff), le32toh(0x0000ffff), le32toh(0x00ffffff), le32toh(0xffffffff) };
union { uint32_t n; char str[4]; } search;
@@ -1003,7 +1003,7 @@ lex_step(struct ut_state *s, FILE *fp)
/* we're at eof */
if (s->lex.eof)
- ut_new_exception(s, s->lex.lastoff, "Syntax error: Unterminated template block");
+ uc_new_exception(s, s->lex.lastoff, "Syntax error: Unterminated template block");
break;
@@ -1054,7 +1054,7 @@ lex_step(struct ut_state *s, FILE *fp)
(tok->type == T_LSTM || tok->type == T_RSTM || tok->type == T_LEXP)) ||
(s->lex.within_statement_block &&
(tok->type == T_LEXP || tok->type == T_REXP || tok->type == T_LSTM))) {
- ut_new_exception(s, s->source->off - tok->plen, "Syntax error: Template blocks may not be nested");
+ uc_new_exception(s, s->source->off - tok->plen, "Syntax error: Template blocks may not be nested");
return 0;
}
@@ -1099,7 +1099,7 @@ lex_step(struct ut_state *s, FILE *fp)
/* no token matched and we do have remaining data, junk */
if (buf_remaining(s)) {
- ut_new_exception(s, s->source->off, "Syntax error: Unexpected character");
+ uc_new_exception(s, s->source->off, "Syntax error: Unexpected character");
return 0;
}
@@ -1112,7 +1112,7 @@ lex_step(struct ut_state *s, FILE *fp)
}
/* premature EOF */
- ut_new_exception(s, s->source->off, "Syntax error: Unterminated template block");
+ uc_new_exception(s, s->source->off, "Syntax error: Unterminated template block");
break;
@@ -1143,7 +1143,7 @@ lex_step(struct ut_state *s, FILE *fp)
}
uint32_t
-ut_get_token(struct ut_state *s, FILE *fp)
+uc_get_token(struct uc_state *s, FILE *fp)
{
uint32_t rv;
@@ -1161,7 +1161,7 @@ ut_get_token(struct ut_state *s, FILE *fp)
}
const char *
-ut_get_tokenname(int type)
+uc_get_tokenname(int type)
{
static char buf[sizeof("'endfunction'")];
size_t i;
diff --git a/lexer.h b/lexer.h
index 08984fc..e45d3e3 100644
--- a/lexer.h
+++ b/lexer.h
@@ -28,9 +28,9 @@ bool
utf8enc(char **out, int *rem, int code);
uint32_t
-ut_get_token(struct ut_state *s, FILE *fp);
+uc_get_token(struct uc_state *s, FILE *fp);
const char *
-ut_get_tokenname(int type);
+uc_get_tokenname(int type);
#endif /* __LEXER_H_ */
diff --git a/lib.c b/lib.c
index cdae0e0..f143a96 100644
--- a/lib.c
+++ b/lib.c
@@ -113,7 +113,7 @@ format_context_line(char **msg, size_t *msglen, const char *line, size_t off)
}
static void
-format_error_context(char **msg, size_t *msglen, struct ut_source *src, struct json_object *stacktrace, size_t off)
+format_error_context(char **msg, size_t *msglen, struct uc_source *src, struct json_object *stacktrace, size_t off)
{
struct json_object *e, *fn, *file, *line, *byte;
size_t len, rlen, idx;
@@ -186,9 +186,9 @@ format_error_context(char **msg, size_t *msglen, struct ut_source *src, struct j
}
struct json_object *
-ut_parse_error(struct ut_state *s, uint32_t off, uint64_t *tokens, int max_token)
+uc_parse_error(struct uc_state *s, uint32_t off, uint64_t *tokens, int max_token)
{
- struct ut_op *op = ut_get_op(s, off);
+ struct uc_op *op = uc_get_op(s, off);
struct json_object *rv;
size_t msglen = 0;
bool first = true;
@@ -198,19 +198,19 @@ ut_parse_error(struct ut_state *s, uint32_t off, uint64_t *tokens, int max_token
for (i = 0; i <= max_token; i++) {
if (tokens[i / 64] & ((uint64_t)1 << (i % 64))) {
if (first) {
- sprintf_append(&msg, &msglen, "Expecting %s", ut_get_tokenname(i));
+ sprintf_append(&msg, &msglen, "Expecting %s", uc_get_tokenname(i));
first = false;
}
else if (i < max_token) {
- sprintf_append(&msg, &msglen, ", %s", ut_get_tokenname(i));
+ sprintf_append(&msg, &msglen, ", %s", uc_get_tokenname(i));
}
else {
- sprintf_append(&msg, &msglen, " or %s", ut_get_tokenname(i));
+ sprintf_append(&msg, &msglen, " or %s", uc_get_tokenname(i));
}
}
}
- rv = ut_new_exception(s,
+ rv = uc_new_exception(s,
op ? op->off : s->lex.lastoff,
"Syntax error: Unexpected token\n%s", msg);
free(msg);
@@ -219,10 +219,10 @@ ut_parse_error(struct ut_state *s, uint32_t off, uint64_t *tokens, int max_token
}
char *
-ut_format_error(struct ut_state *state, FILE *fp)
+uc_format_error(struct uc_state *state, FILE *fp)
{
- struct ut_source *src;
- struct ut_op *tag;
+ struct uc_source *src;
+ struct uc_op *tag;
size_t msglen = 0;
char *msg = NULL;
@@ -241,13 +241,13 @@ ut_format_error(struct ut_state *state, FILE *fp)
}
static double
-ut_cast_double(struct json_object *v)
+uc_cast_double(struct json_object *v)
{
enum json_type t;
int64_t n;
double d;
- t = ut_cast_number(v, &n, &d);
+ t = uc_cast_number(v, &n, &d);
errno = 0;
if (t == json_type_double) {
@@ -263,13 +263,13 @@ ut_cast_double(struct json_object *v)
}
static int64_t
-ut_cast_int64(struct json_object *v)
+uc_cast_int64(struct json_object *v)
{
enum json_type t;
int64_t n;
double d;
- t = ut_cast_number(v, &n, &d);
+ t = uc_cast_number(v, &n, &d);
errno = 0;
if (t == json_type_double) {
@@ -287,30 +287,30 @@ ut_cast_int64(struct json_object *v)
}
static int
-ut_c_fn_to_string(struct json_object *v, struct printbuf *pb, int level, int flags)
+uc_c_fn_to_string(struct json_object *v, struct printbuf *pb, int level, int flags)
{
- struct ut_op *op = json_object_get_userdata(v);
- struct ut_function *fn = (void *)op + ALIGN(sizeof(*op));
+ struct uc_op *op = json_object_get_userdata(v);
+ struct uc_function *fn = (void *)op + ALIGN(sizeof(*op));
return sprintbuf(pb, "%sfunction %s(...) { [native code] }%s",
level ? "\"" : "", fn->name, level ? "\"" : "");
}
static void
-ut_c_fn_free(struct json_object *v, void *ud)
+uc_c_fn_free(struct json_object *v, void *ud)
{
- struct ut_op *op = ud;
+ struct uc_op *op = ud;
json_object_put(op->tag.proto);
free(ud);
}
static bool
-ut_register_function(struct ut_state *state, struct json_object *scope, const char *name, ut_c_fn *cfn)
+uc_register_function(struct uc_state *state, struct json_object *scope, const char *name, uc_c_fn *cfn)
{
struct json_object *val = xjs_new_object();
- struct ut_function *fn;
- struct ut_op *op;
+ struct uc_function *fn;
+ struct uc_op *op;
op = xalloc(ALIGN(sizeof(*op)) + ALIGN(sizeof(*fn)) + ALIGN(strlen(name) + 1));
op->val = val;
@@ -323,13 +323,13 @@ ut_register_function(struct ut_state *state, struct json_object *scope, const ch
op->tag.data = fn;
- json_object_set_serializer(val, ut_c_fn_to_string, op, ut_c_fn_free);
+ json_object_set_serializer(val, uc_c_fn_to_string, op, uc_c_fn_free);
return json_object_object_add(scope, name, op->val);
}
static struct json_object *
-ut_print_common(struct ut_state *s, uint32_t off, struct json_object *args, FILE *fh)
+uc_print_common(struct uc_state *s, uint32_t off, struct json_object *args, FILE *fh)
{
struct json_object *item;
size_t arridx, arrlen;
@@ -359,13 +359,13 @@ ut_print_common(struct ut_state *s, uint32_t off, struct json_object *args, FILE
static struct json_object *
-ut_print(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_print(struct uc_state *s, uint32_t off, struct json_object *args)
{
- return ut_print_common(s, off, args, stdout);
+ return uc_print_common(s, off, args, stdout);
}
static struct json_object *
-ut_length(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_length(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *arg = json_object_array_get_idx(args, 0);
@@ -385,7 +385,7 @@ ut_length(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_index(struct ut_state *s, uint32_t off, struct json_object *args, bool right)
+uc_index(struct uc_state *s, uint32_t off, struct json_object *args, bool right)
{
struct json_object *stack = json_object_array_get_idx(args, 0);
struct json_object *needle = json_object_array_get_idx(args, 1);
@@ -395,7 +395,7 @@ ut_index(struct ut_state *s, uint32_t off, struct json_object *args, bool right)
switch (json_object_get_type(stack)) {
case json_type_array:
for (arridx = 0, len = json_object_array_length(stack); arridx < len; arridx++) {
- if (ut_cmp(T_EQ, json_object_array_get_idx(stack, arridx), needle)) {
+ if (uc_cmp(T_EQ, json_object_array_get_idx(stack, arridx), needle)) {
ret = arridx;
if (!right)
@@ -427,19 +427,19 @@ ut_index(struct ut_state *s, uint32_t off, struct json_object *args, bool right)
}
static struct json_object *
-ut_lindex(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_lindex(struct uc_state *s, uint32_t off, struct json_object *args)
{
- return ut_index(s, off, args, false);
+ return uc_index(s, off, args, false);
}
static struct json_object *
-ut_rindex(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_rindex(struct uc_state *s, uint32_t off, struct json_object *args)
{
- return ut_index(s, off, args, true);
+ return uc_index(s, off, args, true);
}
static struct json_object *
-ut_push(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_push(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *arr = json_object_array_get_idx(args, 0);
struct json_object *item = NULL;
@@ -458,7 +458,7 @@ ut_push(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_pop(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_pop(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *arr = json_object_array_get_idx(args, 0);
struct json_object *item = NULL;
@@ -481,7 +481,7 @@ ut_pop(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_shift(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_shift(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *arr = json_object_array_get_idx(args, 0);
struct json_object *item = NULL;
@@ -506,7 +506,7 @@ ut_shift(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_unshift(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_unshift(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *arr = json_object_array_get_idx(args, 0);
struct json_object *item = NULL;
@@ -531,7 +531,7 @@ ut_unshift(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_chr(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_chr(struct uc_state *s, uint32_t off, struct json_object *args)
{
size_t len = json_object_array_length(args);
size_t idx;
@@ -544,7 +544,7 @@ ut_chr(struct ut_state *s, uint32_t off, struct json_object *args)
str = xalloc(len);
for (idx = 0; idx < len; idx++) {
- n = ut_cast_int64(json_object_array_get_idx(args, idx));
+ n = uc_cast_int64(json_object_array_get_idx(args, idx));
if (n < 0)
n = 0;
@@ -558,7 +558,7 @@ ut_chr(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_delete(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_delete(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *obj = json_object_array_get_idx(args, 0);
struct json_object *rv = NULL;
@@ -581,16 +581,16 @@ ut_delete(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_die(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_die(struct uc_state *s, uint32_t off, struct json_object *args)
{
const char *msg = json_object_get_string(json_object_array_get_idx(args, 0));
- struct ut_function *prev_fn;
+ struct uc_function *prev_fn;
struct json_object *ex;
prev_fn = s->function;
s->function = s->callstack->function;
- ex = ut_new_exception(s, s->callstack->off, "%s", msg ? msg : "Died");
+ ex = uc_new_exception(s, s->callstack->off, "%s", msg ? msg : "Died");
s->function = prev_fn;
@@ -598,7 +598,7 @@ ut_die(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_exists(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_exists(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *obj = json_object_array_get_idx(args, 0);
const char *key = json_object_get_string(json_object_array_get_idx(args, 1));
@@ -610,15 +610,15 @@ ut_exists(struct ut_state *s, uint32_t off, struct json_object *args)
}
__attribute__((noreturn)) static struct json_object *
-ut_exit(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_exit(struct uc_state *s, uint32_t off, struct json_object *args)
{
- int64_t n = ut_cast_int64(json_object_array_get_idx(args, 0));
+ int64_t n = uc_cast_int64(json_object_array_get_idx(args, 0));
exit(n);
}
static struct json_object *
-ut_getenv(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_getenv(struct uc_state *s, uint32_t off, struct json_object *args)
{
const char *key = json_object_get_string(json_object_array_get_idx(args, 0));
char *val = key ? getenv(key) : NULL;
@@ -627,7 +627,7 @@ ut_getenv(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_filter(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_filter(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *obj = json_object_array_get_idx(args, 0);
struct json_object *func = json_object_array_get_idx(args, 1);
@@ -646,16 +646,16 @@ ut_filter(struct ut_state *s, uint32_t off, struct json_object *args)
json_object_array_put_idx(cmpargs, 0, json_object_get(json_object_array_get_idx(obj, arridx)));
json_object_array_put_idx(cmpargs, 1, xjs_new_int64(arridx));
- rv = ut_invoke(s, off, NULL, func, cmpargs);
+ rv = uc_invoke(s, off, NULL, func, cmpargs);
- if (ut_is_type(rv, T_EXCEPTION)) {
+ if (uc_is_type(rv, T_EXCEPTION)) {
json_object_put(cmpargs);
json_object_put(arr);
return rv;
}
- if (ut_val_is_truish(rv))
+ if (uc_val_is_truish(rv))
json_object_array_add(arr, json_object_get(json_object_array_get_idx(obj, arridx)));
json_object_put(rv);
@@ -667,36 +667,36 @@ ut_filter(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_hex(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_hex(struct uc_state *s, uint32_t off, struct json_object *args)
{
const char *val = json_object_get_string(json_object_array_get_idx(args, 0));
int64_t n;
char *e;
if (!val || !isxdigit(*val))
- return ut_new_double(NAN);
+ return uc_new_double(NAN);
n = strtoll(val, &e, 16);
if (e == val || *e)
- return ut_new_double(NAN);
+ return uc_new_double(NAN);
return xjs_new_int64(n);
}
static struct json_object *
-ut_int(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_int(struct uc_state *s, uint32_t off, struct json_object *args)
{
- int64_t n = ut_cast_int64(json_object_array_get_idx(args, 0));
+ int64_t n = uc_cast_int64(json_object_array_get_idx(args, 0));
if (errno == EINVAL || errno == EOVERFLOW)
- return ut_new_double(NAN);
+ return uc_new_double(NAN);
return xjs_new_int64(n);
}
static struct json_object *
-ut_join(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_join(struct uc_state *s, uint32_t off, struct json_object *args)
{
const char *sep = json_object_get_string(json_object_array_get_idx(args, 0));
struct json_object *arr = json_object_array_get_idx(args, 1);
@@ -752,7 +752,7 @@ out:
}
static struct json_object *
-ut_keys(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_keys(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *obj = json_object_array_get_idx(args, 0);
struct json_object *arr = NULL;
@@ -769,7 +769,7 @@ ut_keys(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_lc(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_lc(struct uc_state *s, uint32_t off, struct json_object *args)
{
const char *str = json_object_get_string(json_object_array_get_idx(args, 0));
size_t len = str ? strlen(str) : 0;
@@ -794,7 +794,7 @@ ut_lc(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_map(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_map(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *obj = json_object_array_get_idx(args, 0);
struct json_object *func = json_object_array_get_idx(args, 1);
@@ -813,9 +813,9 @@ ut_map(struct ut_state *s, uint32_t off, struct json_object *args)
json_object_array_put_idx(cmpargs, 0, json_object_get(json_object_array_get_idx(obj, arridx)));
json_object_array_put_idx(cmpargs, 1, xjs_new_int64(arridx));
- rv = ut_invoke(s, off, NULL, func, cmpargs);
+ rv = uc_invoke(s, off, NULL, func, cmpargs);
- if (ut_is_type(rv, T_EXCEPTION)) {
+ if (uc_is_type(rv, T_EXCEPTION)) {
json_object_put(cmpargs);
json_object_put(arr);
@@ -831,7 +831,7 @@ ut_map(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_ord(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_ord(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *obj = json_object_array_get_idx(args, 0);
struct json_object *rv, *pos;
@@ -874,10 +874,10 @@ ut_ord(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_type(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_type(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *v = json_object_array_get_idx(args, 0);
- struct ut_op *tag = json_object_get_userdata(v);
+ struct uc_op *tag = json_object_get_userdata(v);
switch (tag ? tag->type : 0) {
case T_FUNC:
@@ -913,7 +913,7 @@ ut_type(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_reverse(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_reverse(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *obj = json_object_array_get_idx(args, 0);
struct json_object *rv = NULL;
@@ -945,7 +945,7 @@ ut_reverse(struct ut_state *s, uint32_t off, struct json_object *args)
static struct {
- struct ut_state *s;
+ struct uc_state *s;
uint32_t off;
struct json_object *fn;
struct json_object *args;
@@ -961,7 +961,7 @@ sort_fn(const void *k1, const void *k2)
int ret;
if (!sort_ctx.fn)
- return !ut_cmp(T_LT, *v1, *v2);
+ return !uc_cmp(T_LT, *v1, *v2);
if (sort_ctx.ex)
return 0;
@@ -969,15 +969,15 @@ sort_fn(const void *k1, const void *k2)
json_object_array_put_idx(sort_ctx.args, 0, json_object_get(*v1));
json_object_array_put_idx(sort_ctx.args, 1, json_object_get(*v2));
- rv = ut_invoke(sort_ctx.s, sort_ctx.off, NULL, sort_ctx.fn, sort_ctx.args);
+ rv = uc_invoke(sort_ctx.s, sort_ctx.off, NULL, sort_ctx.fn, sort_ctx.args);
- if (ut_is_type(rv, T_EXCEPTION)) {
+ if (uc_is_type(rv, T_EXCEPTION)) {
sort_ctx.ex = rv;
return 0;
}
- ret = !ut_val_is_truish(rv);
+ ret = !uc_val_is_truish(rv);
json_object_put(rv);
@@ -985,7 +985,7 @@ sort_fn(const void *k1, const void *k2)
}
static struct json_object *
-ut_sort(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_sort(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *arr = json_object_array_get_idx(args, 0);
struct json_object *fn = json_object_array_get_idx(args, 1);
@@ -1007,11 +1007,11 @@ ut_sort(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_splice(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_splice(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *arr = json_object_array_get_idx(args, 0);
- int64_t ofs = ut_cast_int64(json_object_array_get_idx(args, 1));
- int64_t remlen = ut_cast_int64(json_object_array_get_idx(args, 2));
+ int64_t ofs = uc_cast_int64(json_object_array_get_idx(args, 1));
+ int64_t remlen = uc_cast_int64(json_object_array_get_idx(args, 2));
size_t arrlen, addlen, idx;
if (!json_object_is_type(arr, json_type_array))
@@ -1080,7 +1080,7 @@ ut_splice(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_split(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_split(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *str = json_object_array_get_idx(args, 0);
struct json_object *sep = json_object_array_get_idx(args, 1);
@@ -1088,7 +1088,7 @@ ut_split(struct ut_state *s, uint32_t off, struct json_object *args)
const char *p, *sepstr, *splitstr;
int eflags = 0, res;
regmatch_t pmatch;
- struct ut_op *tag;
+ struct uc_op *tag;
size_t seplen;
if (!sep || !json_object_is_type(str, json_type_string))
@@ -1097,7 +1097,7 @@ ut_split(struct ut_state *s, uint32_t off, struct json_object *args)
arr = xjs_new_array();
splitstr = json_object_get_string(str);
- if (ut_is_type(sep, T_REGEXP)) {
+ if (uc_is_type(sep, T_REGEXP)) {
tag = json_object_get_userdata(sep);
while (true) {
@@ -1140,11 +1140,11 @@ ut_split(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_substr(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_substr(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *str = json_object_array_get_idx(args, 0);
- int64_t ofs = ut_cast_int64(json_object_array_get_idx(args, 1));
- int64_t sublen = ut_cast_int64(json_object_array_get_idx(args, 2));
+ int64_t ofs = uc_cast_int64(json_object_array_get_idx(args, 1));
+ int64_t sublen = uc_cast_int64(json_object_array_get_idx(args, 2));
const char *p;
size_t len;
@@ -1204,7 +1204,7 @@ ut_substr(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_time(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_time(struct uc_state *s, uint32_t off, struct json_object *args)
{
time_t t = time(NULL);
@@ -1212,7 +1212,7 @@ ut_time(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_uc(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_uc(struct uc_state *s, uint32_t off, struct json_object *args)
{
const char *str = json_object_get_string(json_object_array_get_idx(args, 0));
size_t len = str ? strlen(str) : 0;
@@ -1237,7 +1237,7 @@ ut_uc(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_uchr(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_uchr(struct uc_state *s, uint32_t off, struct json_object *args)
{
size_t len = json_object_array_length(args);
size_t idx, ulen;
@@ -1246,7 +1246,7 @@ ut_uchr(struct ut_state *s, uint32_t off, struct json_object *args)
int rem;
for (idx = 0, ulen = 0; idx < len; idx++) {
- n = ut_cast_int64(json_object_array_get_idx(args, idx));
+ n = uc_cast_int64(json_object_array_get_idx(args, idx));
if (errno == EINVAL || errno == EOVERFLOW || n < 0 || n > 0x10FFFF)
ulen += 3;
@@ -1263,7 +1263,7 @@ ut_uchr(struct ut_state *s, uint32_t off, struct json_object *args)
str = xalloc(ulen);
for (idx = 0, p = str, rem = ulen; idx < len; idx++) {
- n = ut_cast_int64(json_object_array_get_idx(args, idx));
+ n = uc_cast_int64(json_object_array_get_idx(args, idx));
if (errno == EINVAL || errno == EOVERFLOW || n < 0 || n > 0x10FFFF)
n = 0xFFFD;
@@ -1276,7 +1276,7 @@ ut_uchr(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_values(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_values(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *obj = json_object_array_get_idx(args, 0);
struct json_object *arr;
@@ -1295,7 +1295,7 @@ ut_values(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_trim_common(struct ut_state *s, uint32_t off, struct json_object *args, bool start, bool end)
+uc_trim_common(struct uc_state *s, uint32_t off, struct json_object *args, bool start, bool end)
{
struct json_object *str = json_object_array_get_idx(args, 0);
struct json_object *chr = json_object_array_get_idx(args, 1);
@@ -1335,25 +1335,25 @@ ut_trim_common(struct ut_state *s, uint32_t off, struct json_object *args, bool
}
static struct json_object *
-ut_trim(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_trim(struct uc_state *s, uint32_t off, struct json_object *args)
{
- return ut_trim_common(s, off, args, true, true);
+ return uc_trim_common(s, off, args, true, true);
}
static struct json_object *
-ut_ltrim(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_ltrim(struct uc_state *s, uint32_t off, struct json_object *args)
{
- return ut_trim_common(s, off, args, true, false);
+ return uc_trim_common(s, off, args, true, false);
}
static struct json_object *
-ut_rtrim(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_rtrim(struct uc_state *s, uint32_t off, struct json_object *args)
{
- return ut_trim_common(s, off, args, false, true);
+ return uc_trim_common(s, off, args, false, true);
}
static size_t
-ut_printf_common(struct ut_state *s, uint32_t off, struct json_object *args, char **res)
+uc_printf_common(struct uc_state *s, uint32_t off, struct json_object *args, char **res)
{
struct json_object *fmt = json_object_array_get_idx(args, 0);
char *fp, sfmt[sizeof("%0- 123456789.123456789%")];
@@ -1449,7 +1449,7 @@ ut_printf_common(struct ut_state *s, uint32_t off, struct json_object *args, cha
t = json_type_int;
if (argidx < arglen)
- arg.n = ut_cast_int64(json_object_array_get_idx(args, argidx++));
+ arg.n = uc_cast_int64(json_object_array_get_idx(args, argidx++));
else
arg.n = 0;
@@ -1464,7 +1464,7 @@ ut_printf_common(struct ut_state *s, uint32_t off, struct json_object *args, cha
t = json_type_double;
if (argidx < arglen)
- arg.d = ut_cast_double(json_object_array_get_idx(args, argidx++));
+ arg.d = uc_cast_double(json_object_array_get_idx(args, argidx++));
else
arg.d = 0;
@@ -1474,7 +1474,7 @@ ut_printf_common(struct ut_state *s, uint32_t off, struct json_object *args, cha
t = json_type_int;
if (argidx < arglen)
- arg.n = ut_cast_int64(json_object_array_get_idx(args, argidx++)) & 0xff;
+ arg.n = uc_cast_int64(json_object_array_get_idx(args, argidx++)) & 0xff;
else
arg.n = 0;
@@ -1545,13 +1545,13 @@ next:
}
static struct json_object *
-ut_sprintf(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_sprintf(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *rv;
char *str = NULL;
size_t len;
- len = ut_printf_common(s, off, args, &str);
+ len = uc_printf_common(s, off, args, &str);
rv = xjs_new_string_len(str, len);
free(str);
@@ -1560,12 +1560,12 @@ ut_sprintf(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_printf(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_printf(struct uc_state *s, uint32_t off, struct json_object *args)
{
char *str = NULL;
size_t len;
- len = ut_printf_common(s, off, args, &str);
+ len = uc_printf_common(s, off, args, &str);
len = fwrite(str, 1, len, stdout);
free(str);
@@ -1574,12 +1574,12 @@ ut_printf(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_require_so(struct ut_state *s, uint32_t off, const char *path)
+uc_require_so(struct uc_state *s, uint32_t off, const char *path)
{
- void (*init)(const struct ut_ops *, struct ut_state *, struct json_object *);
- struct ut_op *op = ut_get_op(s, off);
- struct ut_function fn = {}, *prev_fn;
- struct ut_source *src, *prev_src;
+ void (*init)(const struct uc_ops *, struct uc_state *, struct json_object *);
+ struct uc_op *op = uc_get_op(s, off);
+ struct uc_function fn = {}, *prev_fn;
+ struct uc_source *src, *prev_src;
struct json_object *scope;
struct stat st;
void *dlh;
@@ -1591,12 +1591,12 @@ ut_require_so(struct ut_state *s, uint32_t off, const char *path)
dlh = dlopen(path, RTLD_LAZY|RTLD_LOCAL);
if (!dlh)
- return ut_new_exception(s, op->off, "Unable to dlopen file %s: %s", path, dlerror());
+ return uc_new_exception(s, op->off, "Unable to dlopen file %s: %s", path, dlerror());
- init = dlsym(dlh, "ut_module_init");
+ init = dlsym(dlh, "uc_module_init");
if (!init)
- return ut_new_exception(s, op->off, "Module %s provides no 'ut_module_init' function", path);
+ return uc_new_exception(s, op->off, "Module %s provides no 'uc_module_init' function", path);
src = xalloc(sizeof(*src));
src->filename = xstrdup(path);
@@ -1622,17 +1622,17 @@ ut_require_so(struct ut_state *s, uint32_t off, const char *path)
}
struct json_object *
-ut_execute_source(struct ut_state *s, struct ut_source *src, struct ut_scope *scope)
+uc_execute_source(struct uc_state *s, struct uc_source *src, struct uc_scope *scope)
{
struct json_object *entry, *rv;
- rv = ut_parse(s, src->fp);
+ rv = uc_parse(s, src->fp);
- if (!ut_is_type(rv, T_EXCEPTION)) {
- entry = ut_new_func(s, ut_get_op(s, s->main), scope ? scope : s->scope);
+ if (!uc_is_type(rv, T_EXCEPTION)) {
+ entry = uc_new_func(s, uc_get_op(s, s->main), scope ? scope : s->scope);
json_object_put(rv);
- rv = ut_invoke(s, s->main, NULL, entry, NULL);
+ rv = uc_invoke(s, s->main, NULL, entry, NULL);
json_object_put(entry);
}
@@ -1641,11 +1641,11 @@ ut_execute_source(struct ut_state *s, struct ut_source *src, struct ut_scope *sc
}
static struct json_object *
-ut_require_utpl(struct ut_state *s, uint32_t off, const char *path, struct ut_scope *scope)
+uc_require_utpl(struct uc_state *s, uint32_t off, const char *path, struct uc_scope *scope)
{
- struct ut_op *op = ut_get_op(s, off);
- struct ut_function fn = {}, *prev_fn;
- struct ut_source *src, *prev_src;
+ struct uc_op *op = uc_get_op(s, off);
+ struct uc_function fn = {}, *prev_fn;
+ struct uc_source *src, *prev_src;
struct json_object *rv;
struct stat st;
FILE *fp;
@@ -1656,7 +1656,7 @@ ut_require_utpl(struct ut_state *s, uint32_t off, const char *path, struct ut_sc
fp = fopen(path, "rb");
if (!fp)
- return ut_new_exception(s, op->off, "Unable to open file %s: %s", path, strerror(errno));
+ return uc_new_exception(s, op->off, "Unable to open file %s: %s", path, strerror(errno));
src = xalloc(sizeof(*src));
src->fp = fp;
@@ -1672,7 +1672,7 @@ ut_require_utpl(struct ut_state *s, uint32_t off, const char *path, struct ut_sc
prev_fn = s->function;
s->function = &fn;
- rv = ut_execute_source(s, src, scope);
+ rv = uc_execute_source(s, src, scope);
s->function = prev_fn;
s->source = prev_src;
@@ -1681,7 +1681,7 @@ ut_require_utpl(struct ut_state *s, uint32_t off, const char *path, struct ut_sc
}
static struct json_object *
-ut_require_path(struct ut_state *s, uint32_t off, const char *path_template, const char *name)
+uc_require_path(struct uc_state *s, uint32_t off, const char *path_template, const char *name)
{
struct json_object *rv = NULL;
const char *p, *q, *last;
@@ -1711,9 +1711,9 @@ ut_require_path(struct ut_state *s, uint32_t off, const char *path_template, con
}
if (!strcmp(p, ".so"))
- rv = ut_require_so(s, off, path);
- else if (!strcmp(p, ".utpl"))
- rv = ut_require_utpl(s, off, path, NULL);
+ rv = uc_require_so(s, off, path);
+ else if (!strcmp(p, ".uc"))
+ rv = uc_require_utpl(s, off, path, NULL);
invalid:
free(path);
@@ -1722,12 +1722,12 @@ invalid:
}
static struct json_object *
-ut_require(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_require(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *val = json_object_array_get_idx(args, 0);
struct json_object *search, *se, *res;
- struct ut_op *op = ut_get_op(s, off);
- struct ut_scope *sc, *scparent;
+ struct uc_op *op = uc_get_op(s, off);
+ struct uc_scope *sc, *scparent;
size_t arridx, arrlen;
const char *name;
@@ -1736,7 +1736,7 @@ ut_require(struct ut_state *s, uint32_t off, struct json_object *args)
/* find root scope */
for (sc = s->scope; sc; ) {
- scparent = ut_parent_scope(sc);
+ scparent = uc_parent_scope(sc);
if (!scparent)
break;
@@ -1748,7 +1748,7 @@ ut_require(struct ut_state *s, uint32_t off, struct json_object *args)
search = sc ? json_object_object_get(sc->scope, "REQUIRE_SEARCH_PATH") : NULL;
if (!json_object_is_type(search, json_type_array))
- return ut_new_exception(s, op ? op->off : 0,
+ return uc_new_exception(s, op ? op->off : 0,
"Global require search path not set");
for (arridx = 0, arrlen = json_object_array_length(search); arridx < arrlen; arridx++) {
@@ -1757,18 +1757,18 @@ ut_require(struct ut_state *s, uint32_t off, struct json_object *args)
if (!json_object_is_type(se, json_type_string))
continue;
- res = ut_require_path(s, off, json_object_get_string(se), name);
+ res = uc_require_path(s, off, json_object_get_string(se), name);
if (res)
return res;
}
- return ut_new_exception(s, op ? op->off : 0,
+ return uc_new_exception(s, op ? op->off : 0,
"No module named '%s' could be found", name);
}
static struct json_object *
-ut_iptoarr(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_iptoarr(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *ip = json_object_array_get_idx(args, 0);
struct json_object *res;
@@ -1821,7 +1821,7 @@ check_byte(struct json_object *v)
}
static struct json_object *
-ut_arrtoip(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_arrtoip(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *arr = json_object_array_get_idx(args, 0);
union {
@@ -1869,17 +1869,17 @@ ut_arrtoip(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_match(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_match(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *subject = json_object_array_get_idx(args, 0);
struct json_object *pattern = json_object_array_get_idx(args, 1);
- struct ut_op *tag = json_object_get_userdata(pattern);
+ struct uc_op *tag = json_object_get_userdata(pattern);
struct json_object *rv = NULL, *m;
int eflags = 0, res, i;
regmatch_t pmatch[10];
const char *p;
- if (!ut_is_type(pattern, T_REGEXP) || !subject)
+ if (!uc_is_type(pattern, T_REGEXP) || !subject)
return NULL;
p = json_object_get_string(subject);
@@ -1917,7 +1917,7 @@ ut_match(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_replace_cb(struct ut_state *s, uint32_t off, struct json_object *func,
+uc_replace_cb(struct uc_state *s, uint32_t off, struct json_object *func,
const char *subject, regmatch_t *pmatch, size_t plen,
char **sp, size_t *sl)
{
@@ -1931,9 +1931,9 @@ ut_replace_cb(struct ut_state *s, uint32_t off, struct json_object *func,
pmatch[i].rm_eo - pmatch[i].rm_so));
}
- rv = ut_invoke(s, off, NULL, func, cbargs);
+ rv = uc_invoke(s, off, NULL, func, cbargs);
- if (ut_is_type(rv, T_EXCEPTION)) {
+ if (uc_is_type(rv, T_EXCEPTION)) {
json_object_put(cbargs);
return rv;
@@ -1948,7 +1948,7 @@ ut_replace_cb(struct ut_state *s, uint32_t off, struct json_object *func,
}
static void
-ut_replace_str(struct ut_state *s, uint32_t off, struct json_object *str,
+uc_replace_str(struct uc_state *s, uint32_t off, struct json_object *str,
const char *subject, regmatch_t *pmatch, size_t plen,
char **sp, size_t *sl)
{
@@ -2013,12 +2013,12 @@ ut_replace_str(struct ut_state *s, uint32_t off, struct json_object *str,
}
static struct json_object *
-ut_replace(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_replace(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *subject = json_object_array_get_idx(args, 0);
struct json_object *pattern = json_object_array_get_idx(args, 1);
struct json_object *replace = json_object_array_get_idx(args, 2);
- struct ut_op *tag = json_object_get_userdata(pattern);
+ struct uc_op *tag = json_object_get_userdata(pattern);
struct json_object *rv = NULL;
const char *sb, *p, *l;
regmatch_t pmatch[10];
@@ -2029,7 +2029,7 @@ ut_replace(struct ut_state *s, uint32_t off, struct json_object *args)
if (!pattern || !subject || !replace)
return NULL;
- if (ut_is_type(pattern, T_REGEXP)) {
+ if (uc_is_type(pattern, T_REGEXP)) {
p = json_object_get_string(subject);
while (true) {
@@ -2040,8 +2040,8 @@ ut_replace(struct ut_state *s, uint32_t off, struct json_object *args)
snprintf_append(&sp, &sl, "%s", pmatch[0].rm_so, p);
- if (ut_is_type(replace, T_FUNC) || ut_is_type(replace, T_CFUNC)) {
- rv = ut_replace_cb(s, off, replace, p, pmatch, ARRAY_SIZE(pmatch), &sp, &sl);
+ if (uc_is_type(replace, T_FUNC) || uc_is_type(replace, T_CFUNC)) {
+ rv = uc_replace_cb(s, off, replace, p, pmatch, ARRAY_SIZE(pmatch), &sp, &sl);
if (rv) {
free(sp);
@@ -2050,7 +2050,7 @@ ut_replace(struct ut_state *s, uint32_t off, struct json_object *args)
}
}
else {
- ut_replace_str(s, off, replace, p, pmatch, ARRAY_SIZE(pmatch), &sp, &sl);
+ uc_replace_str(s, off, replace, p, pmatch, ARRAY_SIZE(pmatch), &sp, &sl);
}
p += pmatch[0].rm_eo;
@@ -2075,8 +2075,8 @@ ut_replace(struct ut_state *s, uint32_t off, struct json_object *args)
pmatch[0].rm_so = sb - l;
pmatch[0].rm_eo = pmatch[0].rm_so + pl;
- if (ut_is_type(replace, T_FUNC) || ut_is_type(replace, T_CFUNC)) {
- rv = ut_replace_cb(s, off, replace, l, pmatch, 1, &sp, &sl);
+ if (uc_is_type(replace, T_FUNC) || uc_is_type(replace, T_CFUNC)) {
+ rv = uc_replace_cb(s, off, replace, l, pmatch, 1, &sp, &sl);
if (rv) {
free(sp);
@@ -2085,7 +2085,7 @@ ut_replace(struct ut_state *s, uint32_t off, struct json_object *args)
}
}
else {
- ut_replace_str(s, off, replace, l, pmatch, 1, &sp, &sl);
+ uc_replace_str(s, off, replace, l, pmatch, 1, &sp, &sl);
}
l = sb + pl;
@@ -2103,17 +2103,17 @@ ut_replace(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_json(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_json(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *rv, *src = json_object_array_get_idx(args, 0);
- struct ut_op *op = ut_get_op(s, off);
+ struct uc_op *op = uc_get_op(s, off);
struct json_tokener *tok = NULL;
enum json_tokener_error err;
const char *str;
size_t len;
if (!json_object_is_type(src, json_type_string))
- return ut_new_exception(s, op->off, "Passed value is not a string");
+ return uc_new_exception(s, op->off, "Passed value is not a string");
tok = xjs_new_tokener();
str = json_object_get_string(src);
@@ -2124,16 +2124,16 @@ ut_json(struct ut_state *s, uint32_t off, struct json_object *args)
if (err == json_tokener_continue) {
json_object_put(rv);
- rv = ut_new_exception(s, op->off, "Unexpected end of string in JSON data");
+ rv = uc_new_exception(s, op->off, "Unexpected end of string in JSON data");
}
else if (err != json_tokener_success) {
json_object_put(rv);
- rv = ut_new_exception(s, op->off, "Failed to parse JSON string: %s",
+ rv = uc_new_exception(s, op->off, "Failed to parse JSON string: %s",
json_tokener_error_desc(err));
}
else if (json_tokener_get_parse_end(tok) < len) {
json_object_put(rv);
- rv = ut_new_exception(s, op->off, "Trailing garbage after JSON data");
+ rv = uc_new_exception(s, op->off, "Trailing garbage after JSON data");
}
json_tokener_free(tok);
@@ -2175,27 +2175,27 @@ include_path(const char *curpath, const char *incpath)
}
static struct json_object *
-ut_include(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_include(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *rv, *path = json_object_array_get_idx(args, 0);
struct json_object *scope = json_object_array_get_idx(args, 1);
- struct ut_op *op = ut_get_op(s, off);
- struct ut_scope *sc;
+ struct uc_op *op = uc_get_op(s, off);
+ struct uc_scope *sc;
char *p;
if (!json_object_is_type(path, json_type_string))
- return ut_new_exception(s, op->off, "Passed filename is not a string");
+ return uc_new_exception(s, op->off, "Passed filename is not a string");
if (scope && !json_object_is_type(scope, json_type_object))
- return ut_new_exception(s, op->off, "Passed scope value is not an object");
+ return uc_new_exception(s, op->off, "Passed scope value is not an object");
p = include_path(s->callstack->function->source->filename, json_object_get_string(path));
if (!p)
- return ut_new_exception(s, op->off, "Include file not found");
+ return uc_new_exception(s, op->off, "Include file not found");
if (scope) {
- sc = ut_new_scope(s, NULL);
+ sc = uc_new_scope(s, NULL);
json_object_object_foreach(scope, key, val)
json_object_object_add(sc->scope, key, json_object_get(val));
@@ -2204,14 +2204,14 @@ ut_include(struct ut_state *s, uint32_t off, struct json_object *args)
sc = s->scope;
}
- rv = ut_require_utpl(s, off, p, sc);
+ rv = uc_require_utpl(s, off, p, sc);
free(p);
if (scope)
json_object_put(sc->scope);
- if (ut_is_type(rv, T_EXCEPTION))
+ if (uc_is_type(rv, T_EXCEPTION))
return rv;
json_object_put(rv);
@@ -2220,17 +2220,17 @@ ut_include(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_warn(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_warn(struct uc_state *s, uint32_t off, struct json_object *args)
{
- return ut_print_common(s, off, args, stderr);
+ return uc_print_common(s, off, args, stderr);
}
static struct json_object *
-ut_system(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_system(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *cmdline = json_object_array_get_idx(args, 0);
struct json_object *timeout = json_object_array_get_idx(args, 1);
- struct ut_op *op = ut_get_op(s, off);
+ struct uc_op *op = uc_get_op(s, off);
sigset_t sigmask, sigomask;
const char **arglist, *fn;
struct timespec ts;
@@ -2259,11 +2259,11 @@ ut_system(struct ut_state *s, uint32_t off, struct json_object *args)
break;
default:
- return ut_new_exception(s, op->off, "Passed command is neither string nor array");
+ return uc_new_exception(s, op->off, "Passed command is neither string nor array");
}
if (timeout && (!json_object_is_type(timeout, json_type_int) || json_object_get_int64(timeout) < 0))
- return ut_new_exception(s, op->off, "Invalid timeout specified");
+ return uc_new_exception(s, op->off, "Invalid timeout specified");
tms = timeout ? json_object_get_int64(timeout) : 0;
@@ -2334,75 +2334,75 @@ fail:
sigprocmask(SIG_SETMASK, &sigomask, NULL);
free(arglist);
- return ut_new_exception(s, op->off, "%s(): %s", fn, strerror(errno));
+ return uc_new_exception(s, op->off, "%s(): %s", fn, strerror(errno));
}
-const struct ut_ops ut = {
- .register_function = ut_register_function,
- .register_type = ut_register_extended_type,
- .set_type = ut_set_extended_type,
- .get_type = ut_get_extended_type,
- .new_object = ut_new_object,
- .new_double = ut_new_double,
- .invoke = ut_invoke,
- .cast_number = ut_cast_number,
+const struct uc_ops ut = {
+ .register_function = uc_register_function,
+ .register_type = uc_register_extended_type,
+ .set_type = uc_set_extended_type,
+ .get_type = uc_get_extended_type,
+ .new_object = uc_new_object,
+ .new_double = uc_new_double,
+ .invoke = uc_invoke,
+ .cast_number = uc_cast_number,
};
-static const struct { const char *name; ut_c_fn *func; } functions[] = {
- { "chr", ut_chr },
- { "delete", ut_delete },
- { "die", ut_die },
- { "exists", ut_exists },
- { "exit", ut_exit },
- { "filter", ut_filter },
- { "getenv", ut_getenv },
- { "hex", ut_hex },
- { "index", ut_lindex },
- { "int", ut_int },
- { "join", ut_join },
- { "keys", ut_keys },
- { "lc", ut_lc },
- { "length", ut_length },
- { "ltrim", ut_ltrim },
- { "map", ut_map },
- { "ord", ut_ord },
- { "pop", ut_pop },
- { "print", ut_print },
- { "push", ut_push },
- { "reverse", ut_reverse },
- { "rindex", ut_rindex },
- { "rtrim", ut_rtrim },
- { "shift", ut_shift },
- { "sort", ut_sort },
- { "splice", ut_splice },
- { "split", ut_split },
- { "substr", ut_substr },
- { "time", ut_time },
- { "trim", ut_trim },
- { "type", ut_type },
- { "uchr", ut_uchr },
- { "uc", ut_uc },
- { "unshift", ut_unshift },
- { "values", ut_values },
- { "sprintf", ut_sprintf },
- { "printf", ut_printf },
- { "require", ut_require },
- { "iptoarr", ut_iptoarr },
- { "arrtoip", ut_arrtoip },
- { "match", ut_match },
- { "replace", ut_replace },
- { "json", ut_json },
- { "include", ut_include },
- { "warn", ut_warn },
- { "system", ut_system },
+static const struct { const char *name; uc_c_fn *func; } functions[] = {
+ { "chr", uc_chr },
+ { "delete", uc_delete },
+ { "die", uc_die },
+ { "exists", uc_exists },
+ { "exit", uc_exit },
+ { "filter", uc_filter },
+ { "getenv", uc_getenv },
+ { "hex", uc_hex },
+ { "index", uc_lindex },
+ { "int", uc_int },
+ { "join", uc_join },
+ { "keys", uc_keys },
+ { "lc", uc_lc },
+ { "length", uc_length },
+ { "ltrim", uc_ltrim },
+ { "map", uc_map },
+ { "ord", uc_ord },
+ { "pop", uc_pop },
+ { "print", uc_print },
+ { "push", uc_push },
+ { "reverse", uc_reverse },
+ { "rindex", uc_rindex },
+ { "rtrim", uc_rtrim },
+ { "shift", uc_shift },
+ { "sort", uc_sort },
+ { "splice", uc_splice },
+ { "split", uc_split },
+ { "substr", uc_substr },
+ { "time", uc_time },
+ { "trim", uc_trim },
+ { "type", uc_type },
+ { "uchr", uc_uchr },
+ { "uc", uc_uc },
+ { "unshift", uc_unshift },
+ { "values", uc_values },
+ { "sprintf", uc_sprintf },
+ { "printf", uc_printf },
+ { "require", uc_require },
+ { "iptoarr", uc_iptoarr },
+ { "arrtoip", uc_arrtoip },
+ { "match", uc_match },
+ { "replace", uc_replace },
+ { "json", uc_json },
+ { "include", uc_include },
+ { "warn", uc_warn },
+ { "system", uc_system },
};
void
-ut_lib_init(struct ut_state *state, struct json_object *scope)
+uc_lib_init(struct uc_state *state, struct json_object *scope)
{
int i;
for (i = 0; i < sizeof(functions) / sizeof(functions[0]); i++)
- ut_register_function(state, scope, functions[i].name, functions[i].func);
+ uc_register_function(state, scope, functions[i].name, functions[i].func);
}
diff --git a/lib.h b/lib.h
index aaaff55..409cfc4 100644
--- a/lib.h
+++ b/lib.h
@@ -20,14 +20,14 @@
#include "ast.h"
#include "lexer.h"
-typedef struct json_object *(ut_c_fn)(struct ut_state *, uint32_t, struct json_object *);
+typedef struct json_object *(uc_c_fn)(struct uc_state *, uint32_t, struct json_object *);
-void ut_lib_init(struct ut_state *state, struct json_object *scope);
+void uc_lib_init(struct uc_state *state, struct json_object *scope);
-struct json_object *ut_execute_source(struct ut_state *s, struct ut_source *src, struct ut_scope *scope);
+struct json_object *uc_execute_source(struct uc_state *s, struct uc_source *src, struct uc_scope *scope);
-struct json_object *ut_parse_error(struct ut_state *s, uint32_t off, uint64_t *tokens, int max_token);
+struct json_object *uc_parse_error(struct uc_state *s, uint32_t off, uint64_t *tokens, int max_token);
-char *ut_format_error(struct ut_state *state, FILE *fp);
+char *uc_format_error(struct uc_state *state, FILE *fp);
#endif /* __LIB_H_ */
diff --git a/lib/fs.c b/lib/fs.c
index 4eb1436..1e148c3 100644
--- a/lib/fs.c
+++ b/lib/fs.c
@@ -27,12 +27,12 @@
#define err_return(err) do { last_error = err; return NULL; } while(0)
-static const struct ut_ops *ops;
+static const struct uc_ops *ops;
static int last_error = 0;
static struct json_object *
-ut_fs_error(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_error(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *errmsg;
@@ -46,7 +46,7 @@ ut_fs_error(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_fs_read_common(struct ut_state *s, uint32_t off, struct json_object *args, const char *type)
+uc_fs_read_common(struct uc_state *s, uint32_t off, struct json_object *args, const char *type)
{
struct json_object *limit = json_object_array_get_idx(args, 0);
struct json_object *rv = NULL;
@@ -138,7 +138,7 @@ ut_fs_read_common(struct ut_state *s, uint32_t off, struct json_object *args, co
}
static struct json_object *
-ut_fs_write_common(struct ut_state *s, uint32_t off, struct json_object *args, const char *type)
+uc_fs_write_common(struct uc_state *s, uint32_t off, struct json_object *args, const char *type)
{
struct json_object *data = json_object_array_get_idx(args, 0);
size_t len, wsize;
@@ -168,7 +168,7 @@ ut_fs_write_common(struct ut_state *s, uint32_t off, struct json_object *args, c
static struct json_object *
-ut_fs_pclose(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_pclose(struct uc_state *s, uint32_t off, struct json_object *args)
{
FILE **fp = (FILE **)ops->get_type(s->ctx, "fs.proc");
int rc;
@@ -192,19 +192,19 @@ ut_fs_pclose(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_fs_pread(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_pread(struct uc_state *s, uint32_t off, struct json_object *args)
{
- return ut_fs_read_common(s, off, args, "fs.proc");
+ return uc_fs_read_common(s, off, args, "fs.proc");
}
static struct json_object *
-ut_fs_pwrite(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_pwrite(struct uc_state *s, uint32_t off, struct json_object *args)
{
- return ut_fs_write_common(s, off, args, "fs.proc");
+ return uc_fs_write_common(s, off, args, "fs.proc");
}
static struct json_object *
-ut_fs_popen(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_popen(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *comm = json_object_array_get_idx(args, 0);
struct json_object *mode = json_object_array_get_idx(args, 1);
@@ -232,7 +232,7 @@ ut_fs_popen(struct ut_state *s, uint32_t off, struct json_object *args)
static struct json_object *
-ut_fs_close(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_close(struct uc_state *s, uint32_t off, struct json_object *args)
{
FILE **fp = (FILE **)ops->get_type(s->ctx, "fs.file");
@@ -246,19 +246,19 @@ ut_fs_close(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_fs_read(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_read(struct uc_state *s, uint32_t off, struct json_object *args)
{
- return ut_fs_read_common(s, off, args, "fs.file");
+ return uc_fs_read_common(s, off, args, "fs.file");
}
static struct json_object *
-ut_fs_write(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_write(struct uc_state *s, uint32_t off, struct json_object *args)
{
- return ut_fs_write_common(s, off, args, "fs.file");
+ return uc_fs_write_common(s, off, args, "fs.file");
}
static struct json_object *
-ut_fs_seek(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_seek(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *ofs = json_object_array_get_idx(args, 0);
struct json_object *how = json_object_array_get_idx(args, 1);
@@ -293,7 +293,7 @@ ut_fs_seek(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_fs_tell(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_tell(struct uc_state *s, uint32_t off, struct json_object *args)
{
long offset;
@@ -311,7 +311,7 @@ ut_fs_tell(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_fs_open(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_open(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *path = json_object_array_get_idx(args, 0);
struct json_object *mode = json_object_array_get_idx(args, 1);
@@ -339,7 +339,7 @@ ut_fs_open(struct ut_state *s, uint32_t off, struct json_object *args)
static struct json_object *
-ut_fs_readdir(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_readdir(struct uc_state *s, uint32_t off, struct json_object *args)
{
DIR **dp = (DIR **)ops->get_type(s->ctx, "fs.dir");
struct dirent *e;
@@ -357,7 +357,7 @@ ut_fs_readdir(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_fs_telldir(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_telldir(struct uc_state *s, uint32_t off, struct json_object *args)
{
DIR **dp = (DIR **)ops->get_type(s->ctx, "fs.dir");
long position;
@@ -374,7 +374,7 @@ ut_fs_telldir(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_fs_seekdir(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_seekdir(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *ofs = json_object_array_get_idx(args, 0);
DIR **dp = (DIR **)ops->get_type(s->ctx, "fs.dir");
@@ -394,7 +394,7 @@ ut_fs_seekdir(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_fs_closedir(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_closedir(struct uc_state *s, uint32_t off, struct json_object *args)
{
DIR **dp = (DIR **)ops->get_type(s->ctx, "fs.dir");
@@ -408,7 +408,7 @@ ut_fs_closedir(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_fs_opendir(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_opendir(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *path = json_object_array_get_idx(args, 0);
struct json_object *diro;
@@ -433,7 +433,7 @@ ut_fs_opendir(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_fs_readlink(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_readlink(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *path = json_object_array_get_idx(args, 0);
struct json_object *res;
@@ -473,7 +473,7 @@ ut_fs_readlink(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_fs_stat_common(struct ut_state *s, uint32_t off, struct json_object *args, bool use_lstat)
+uc_fs_stat_common(struct uc_state *s, uint32_t off, struct json_object *args, bool use_lstat)
{
struct json_object *path = json_object_array_get_idx(args, 0);
struct json_object *res, *o;
@@ -557,19 +557,19 @@ ut_fs_stat_common(struct ut_state *s, uint32_t off, struct json_object *args, bo
}
static struct json_object *
-ut_fs_stat(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_stat(struct uc_state *s, uint32_t off, struct json_object *args)
{
- return ut_fs_stat_common(s, off, args, false);
+ return uc_fs_stat_common(s, off, args, false);
}
static struct json_object *
-ut_fs_lstat(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_lstat(struct uc_state *s, uint32_t off, struct json_object *args)
{
- return ut_fs_stat_common(s, off, args, true);
+ return uc_fs_stat_common(s, off, args, true);
}
static struct json_object *
-ut_fs_mkdir(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_mkdir(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *path = json_object_array_get_idx(args, 0);
struct json_object *mode = json_object_array_get_idx(args, 1);
@@ -585,7 +585,7 @@ ut_fs_mkdir(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_fs_rmdir(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_rmdir(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *path = json_object_array_get_idx(args, 0);
@@ -599,7 +599,7 @@ ut_fs_rmdir(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_fs_symlink(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_symlink(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *dest = json_object_array_get_idx(args, 0);
struct json_object *path = json_object_array_get_idx(args, 1);
@@ -615,7 +615,7 @@ ut_fs_symlink(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_fs_unlink(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_unlink(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *path = json_object_array_get_idx(args, 0);
@@ -629,7 +629,7 @@ ut_fs_unlink(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_fs_getcwd(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_getcwd(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *res;
char *buf = NULL, *tmp;
@@ -664,7 +664,7 @@ ut_fs_getcwd(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_fs_chdir(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_fs_chdir(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *path = json_object_array_get_idx(args, 0);
@@ -677,41 +677,41 @@ ut_fs_chdir(struct ut_state *s, uint32_t off, struct json_object *args)
return json_object_new_boolean(true);
}
-static const struct { const char *name; ut_c_fn *func; } proc_fns[] = {
- { "read", ut_fs_pread },
- { "write", ut_fs_pwrite },
- { "close", ut_fs_pclose },
+static const struct { const char *name; uc_c_fn *func; } proc_fns[] = {
+ { "read", uc_fs_pread },
+ { "write", uc_fs_pwrite },
+ { "close", uc_fs_pclose },
};
-static const struct { const char *name; ut_c_fn *func; } file_fns[] = {
- { "read", ut_fs_read },
- { "write", ut_fs_write },
- { "seek", ut_fs_seek },
- { "tell", ut_fs_tell },
- { "close", ut_fs_close },
+static const struct { const char *name; uc_c_fn *func; } file_fns[] = {
+ { "read", uc_fs_read },
+ { "write", uc_fs_write },
+ { "seek", uc_fs_seek },
+ { "tell", uc_fs_tell },
+ { "close", uc_fs_close },
};
-static const struct { const char *name; ut_c_fn *func; } dir_fns[] = {
- { "read", ut_fs_readdir },
- { "seek", ut_fs_seekdir },
- { "tell", ut_fs_telldir },
- { "close", ut_fs_closedir },
+static const struct { const char *name; uc_c_fn *func; } dir_fns[] = {
+ { "read", uc_fs_readdir },
+ { "seek", uc_fs_seekdir },
+ { "tell", uc_fs_telldir },
+ { "close", uc_fs_closedir },
};
-static const struct { const char *name; ut_c_fn *func; } global_fns[] = {
- { "error", ut_fs_error },
- { "open", ut_fs_open },
- { "opendir", ut_fs_opendir },
- { "popen", ut_fs_popen },
- { "readlink", ut_fs_readlink },
- { "stat", ut_fs_stat },
- { "lstat", ut_fs_lstat },
- { "mkdir", ut_fs_mkdir },
- { "rmdir", ut_fs_rmdir },
- { "symlink", ut_fs_symlink },
- { "unlink", ut_fs_unlink },
- { "getcwd", ut_fs_getcwd },
- { "chdir", ut_fs_chdir },
+static const struct { const char *name; uc_c_fn *func; } global_fns[] = {
+ { "error", uc_fs_error },
+ { "open", uc_fs_open },
+ { "opendir", uc_fs_opendir },
+ { "popen", uc_fs_popen },
+ { "readlink", uc_fs_readlink },
+ { "stat", uc_fs_stat },
+ { "lstat", uc_fs_lstat },
+ { "mkdir", uc_fs_mkdir },
+ { "rmdir", uc_fs_rmdir },
+ { "symlink", uc_fs_symlink },
+ { "unlink", uc_fs_unlink },
+ { "getcwd", uc_fs_getcwd },
+ { "chdir", uc_fs_chdir },
};
@@ -730,7 +730,7 @@ static void close_dir(void *ud) {
closedir((DIR *)ud);
}
-void ut_module_init(const struct ut_ops *ut, struct ut_state *s, struct json_object *scope)
+void uc_module_init(const struct uc_ops *ut, struct uc_state *s, struct json_object *scope)
{
struct json_object *proc_proto, *file_proto, *dir_proto;
diff --git a/lib/math.c b/lib/math.c
index efbc21c..6dbca08 100644
--- a/lib/math.c
+++ b/lib/math.c
@@ -19,7 +19,7 @@
#include <math.h>
#include <sys/time.h>
-static const struct ut_ops *ops;
+static const struct uc_ops *ops;
static double
to_double(struct json_object *v)
@@ -40,7 +40,7 @@ to_int64(struct json_object *v)
}
static struct json_object *
-ut_abs(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_abs(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *v = json_object_array_get_idx(args, 0);
enum json_type t;
@@ -59,7 +59,7 @@ ut_abs(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_atan2(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_atan2(struct uc_state *s, uint32_t off, struct json_object *args)
{
double d1 = to_double(json_object_array_get_idx(args, 0));
double d2 = to_double(json_object_array_get_idx(args, 1));
@@ -71,7 +71,7 @@ ut_atan2(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_cos(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_cos(struct uc_state *s, uint32_t off, struct json_object *args)
{
double d = to_double(json_object_array_get_idx(args, 0));
@@ -82,7 +82,7 @@ ut_cos(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_exp(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_exp(struct uc_state *s, uint32_t off, struct json_object *args)
{
double d = to_double(json_object_array_get_idx(args, 0));
@@ -93,7 +93,7 @@ ut_exp(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_log(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_log(struct uc_state *s, uint32_t off, struct json_object *args)
{
double d = to_double(json_object_array_get_idx(args, 0));
@@ -104,7 +104,7 @@ ut_log(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_sin(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_sin(struct uc_state *s, uint32_t off, struct json_object *args)
{
double d = to_double(json_object_array_get_idx(args, 0));
@@ -115,7 +115,7 @@ ut_sin(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_sqrt(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_sqrt(struct uc_state *s, uint32_t off, struct json_object *args)
{
double d = to_double(json_object_array_get_idx(args, 0));
@@ -126,7 +126,7 @@ ut_sqrt(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_pow(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_pow(struct uc_state *s, uint32_t off, struct json_object *args)
{
double x = to_double(json_object_array_get_idx(args, 0));
double y = to_double(json_object_array_get_idx(args, 1));
@@ -138,7 +138,7 @@ ut_pow(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_rand(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_rand(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct timeval tv;
@@ -153,7 +153,7 @@ ut_rand(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_srand(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_srand(struct uc_state *s, uint32_t off, struct json_object *args)
{
int64_t n = to_int64(json_object_array_get_idx(args, 0));
@@ -164,20 +164,20 @@ ut_srand(struct ut_state *s, uint32_t off, struct json_object *args)
return NULL;
}
-static const struct { const char *name; ut_c_fn *func; } global_fns[] = {
- { "abs", ut_abs },
- { "atan2", ut_atan2 },
- { "cos", ut_cos },
- { "exp", ut_exp },
- { "log", ut_log },
- { "sin", ut_sin },
- { "sqrt", ut_sqrt },
- { "pow", ut_pow },
- { "rand", ut_rand },
- { "srand", ut_srand },
+static const struct { const char *name; uc_c_fn *func; } global_fns[] = {
+ { "abs", uc_abs },
+ { "atan2", uc_atan2 },
+ { "cos", uc_cos },
+ { "exp", uc_exp },
+ { "log", uc_log },
+ { "sin", uc_sin },
+ { "sqrt", uc_sqrt },
+ { "pow", uc_pow },
+ { "rand", uc_rand },
+ { "srand", uc_srand },
};
-void ut_module_init(const struct ut_ops *ut, struct ut_state *s, struct json_object *scope)
+void uc_module_init(const struct uc_ops *ut, struct uc_state *s, struct json_object *scope)
{
ops = ut;
diff --git a/lib/ubus.c b/lib/ubus.c
index b707e51..13f5858 100644
--- a/lib/ubus.c
+++ b/lib/ubus.c
@@ -23,7 +23,7 @@
#define err_return(err) do { last_error = err; return NULL; } while(0)
-static const struct ut_ops *ops;
+static const struct uc_ops *ops;
static enum ubus_msg_status last_error = 0;
@@ -34,7 +34,7 @@ struct ubus_connection {
};
static struct json_object *
-ut_ubus_error(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_ubus_error(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *errmsg;
@@ -48,10 +48,10 @@ ut_ubus_error(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_blob_to_json(struct blob_attr *attr, bool table, const char **name);
+uc_blob_to_json(struct blob_attr *attr, bool table, const char **name);
static struct json_object *
-ut_blob_array_to_json(struct blob_attr *attr, size_t len, bool table)
+uc_blob_array_to_json(struct blob_attr *attr, size_t len, bool table)
{
struct json_object *o = table ? json_object_new_object() : json_object_new_array();
struct json_object *v;
@@ -64,7 +64,7 @@ ut_blob_array_to_json(struct blob_attr *attr, size_t len, bool table)
__blob_for_each_attr(pos, attr, rem) {
name = NULL;
- v = ut_blob_to_json(pos, table, &name);
+ v = uc_blob_to_json(pos, table, &name);
if (table && name)
json_object_object_add(o, name, v);
@@ -78,7 +78,7 @@ ut_blob_array_to_json(struct blob_attr *attr, size_t len, bool table)
}
static struct json_object *
-ut_blob_to_json(struct blob_attr *attr, bool table, const char **name)
+uc_blob_to_json(struct blob_attr *attr, bool table, const char **name)
{
void *data;
int len;
@@ -120,10 +120,10 @@ ut_blob_to_json(struct blob_attr *attr, bool table, const char **name)
return json_object_new_string(data);
case BLOBMSG_TYPE_ARRAY:
- return ut_blob_array_to_json(data, len, false);
+ return uc_blob_array_to_json(data, len, false);
case BLOBMSG_TYPE_TABLE:
- return ut_blob_array_to_json(data, len, true);
+ return uc_blob_array_to_json(data, len, true);
default:
return NULL;
@@ -132,7 +132,7 @@ ut_blob_to_json(struct blob_attr *attr, bool table, const char **name)
static struct json_object *
-ut_ubus_connect(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_ubus_connect(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *socket = json_object_array_get_idx(args, 0);
struct json_object *timeout = json_object_array_get_idx(args, 1);
@@ -173,7 +173,7 @@ ut_ubus_connect(struct ut_state *s, uint32_t off, struct json_object *args)
}
static void
-ut_ubus_signatures_cb(struct ubus_context *c, struct ubus_object_data *o, void *p)
+uc_ubus_signatures_cb(struct ubus_context *c, struct ubus_object_data *o, void *p)
{
struct json_object *arr = p;
struct json_object *sig;
@@ -181,14 +181,14 @@ ut_ubus_signatures_cb(struct ubus_context *c, struct ubus_object_data *o, void *
if (!o->signature)
return;
- sig = ut_blob_array_to_json(blob_data(o->signature), blob_len(o->signature), true);
+ sig = uc_blob_array_to_json(blob_data(o->signature), blob_len(o->signature), true);
if (sig)
json_object_array_add(arr, sig);
}
static void
-ut_ubus_objects_cb(struct ubus_context *c, struct ubus_object_data *o, void *p)
+uc_ubus_objects_cb(struct ubus_context *c, struct ubus_object_data *o, void *p)
{
struct json_object *arr = p;
struct json_object *obj;
@@ -200,7 +200,7 @@ ut_ubus_objects_cb(struct ubus_context *c, struct ubus_object_data *o, void *p)
}
static struct json_object *
-ut_ubus_list(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_ubus_list(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct ubus_connection **c = (struct ubus_connection **)ops->get_type(s->ctx, "ubus.connection");
struct json_object *objname = json_object_array_get_idx(args, 0);
@@ -220,7 +220,7 @@ ut_ubus_list(struct ut_state *s, uint32_t off, struct json_object *args)
rv = ubus_lookup((*c)->ctx,
objname ? json_object_get_string(objname) : NULL,
- objname ? ut_ubus_signatures_cb : ut_ubus_objects_cb,
+ objname ? uc_ubus_signatures_cb : uc_ubus_objects_cb,
res);
if (rv != UBUS_STATUS_OK)
@@ -230,15 +230,15 @@ ut_ubus_list(struct ut_state *s, uint32_t off, struct json_object *args)
}
static void
-ut_ubus_call_cb(struct ubus_request *req, int type, struct blob_attr *msg)
+uc_ubus_call_cb(struct ubus_request *req, int type, struct blob_attr *msg)
{
struct json_object **res = (struct json_object **)req->priv;
- *res = msg ? ut_blob_array_to_json(blob_data(msg), blob_len(msg), true) : NULL;
+ *res = msg ? uc_blob_array_to_json(blob_data(msg), blob_len(msg), true) : NULL;
}
static struct json_object *
-ut_ubus_call(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_ubus_call(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct ubus_connection **c = (struct ubus_connection **)ops->get_type(s->ctx, "ubus.connection");
struct json_object *objname = json_object_array_get_idx(args, 0);
@@ -267,7 +267,7 @@ ut_ubus_call(struct ut_state *s, uint32_t off, struct json_object *args)
err_return(rv);
rv = ubus_invoke((*c)->ctx, id, json_object_get_string(funname), (*c)->buf.head,
- ut_ubus_call_cb, &res, (*c)->timeout * 1000);
+ uc_ubus_call_cb, &res, (*c)->timeout * 1000);
if (rv != UBUS_STATUS_OK)
err_return(rv);
@@ -276,7 +276,7 @@ ut_ubus_call(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_ubus_disconnect(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_ubus_disconnect(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct ubus_connection **c = (struct ubus_connection **)ops->get_type(s->ctx, "ubus.connection");
@@ -290,15 +290,15 @@ ut_ubus_disconnect(struct ut_state *s, uint32_t off, struct json_object *args)
}
-static const struct { const char *name; ut_c_fn *func; } global_fns[] = {
- { "error", ut_ubus_error },
- { "connect", ut_ubus_connect },
+static const struct { const char *name; uc_c_fn *func; } global_fns[] = {
+ { "error", uc_ubus_error },
+ { "connect", uc_ubus_connect },
};
-static const struct { const char *name; ut_c_fn *func; } conn_fns[] = {
- { "list", ut_ubus_list },
- { "call", ut_ubus_call },
- { "disconnect", ut_ubus_disconnect },
+static const struct { const char *name; uc_c_fn *func; } conn_fns[] = {
+ { "list", uc_ubus_list },
+ { "call", uc_ubus_call },
+ { "disconnect", uc_ubus_disconnect },
};
@@ -313,7 +313,7 @@ static void close_connection(void *ud) {
free(conn);
}
-void ut_module_init(const struct ut_ops *ut, struct ut_state *s, struct json_object *scope)
+void uc_module_init(const struct uc_ops *ut, struct uc_state *s, struct json_object *scope)
{
struct json_object *conn_proto;
diff --git a/lib/uci.c b/lib/uci.c
index a56531a..86bf247 100644
--- a/lib/uci.c
+++ b/lib/uci.c
@@ -21,7 +21,7 @@
#define err_return(err) do { last_error = err; return NULL; } while(0)
-static const struct ut_ops *ops;
+static const struct uc_ops *ops;
static int last_error = 0;
@@ -32,7 +32,7 @@ enum pkg_cmd {
};
static struct json_object *
-ut_uci_error(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_uci_error(struct uc_state *s, uint32_t off, struct json_object *args)
{
char buf[sizeof("Unknown error: -9223372036854775808")];
struct json_object *errmsg;
@@ -65,7 +65,7 @@ ut_uci_error(struct ut_state *s, uint32_t off, struct json_object *args)
static struct json_object *
-ut_uci_cursor(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_uci_cursor(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct json_object *cdir = json_object_array_get_idx(args, 0);
struct json_object *sdir = json_object_array_get_idx(args, 1);
@@ -108,7 +108,7 @@ ut_uci_cursor(struct ut_state *s, uint32_t off, struct json_object *args)
static struct json_object *
-ut_uci_load(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_uci_load(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct uci_context **c = (struct uci_context **)ops->get_type(s->ctx, "uci.cursor");
struct json_object *conf = json_object_array_get_idx(args, 0);
@@ -134,7 +134,7 @@ ut_uci_load(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_uci_unload(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_uci_unload(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct uci_context **c = (struct uci_context **)ops->get_type(s->ctx, "uci.cursor");
struct json_object *conf = json_object_array_get_idx(args, 0);
@@ -255,7 +255,7 @@ package_to_json(struct uci_package *p)
}
static struct json_object *
-ut_uci_get_any(struct ut_state *s, uint32_t off, struct json_object *args, bool all)
+uc_uci_get_any(struct uc_state *s, uint32_t off, struct json_object *args, bool all)
{
struct uci_context **c = (struct uci_context **)ops->get_type(s->ctx, "uci.cursor");
struct json_object *conf = json_object_array_get_idx(args, 0);
@@ -315,19 +315,19 @@ ut_uci_get_any(struct ut_state *s, uint32_t off, struct json_object *args, bool
}
static struct json_object *
-ut_uci_get(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_uci_get(struct uc_state *s, uint32_t off, struct json_object *args)
{
- return ut_uci_get_any(s, off, args, false);
+ return uc_uci_get_any(s, off, args, false);
}
static struct json_object *
-ut_uci_get_all(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_uci_get_all(struct uc_state *s, uint32_t off, struct json_object *args)
{
- return ut_uci_get_any(s, off, args, true);
+ return uc_uci_get_any(s, off, args, true);
}
static struct json_object *
-ut_uci_get_first(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_uci_get_first(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct uci_context **c = (struct uci_context **)ops->get_type(s->ctx, "uci.cursor");
struct json_object *conf = json_object_array_get_idx(args, 0);
@@ -385,7 +385,7 @@ ut_uci_get_first(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_uci_add(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_uci_add(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct uci_context **c = (struct uci_context **)ops->get_type(s->ctx, "uci.cursor");
struct json_object *conf = json_object_array_get_idx(args, 0);
@@ -464,7 +464,7 @@ json_to_value(struct json_object *val, const char **p, bool *is_list)
}
static struct json_object *
-ut_uci_set(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_uci_set(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct uci_context **c = (struct uci_context **)ops->get_type(s->ctx, "uci.cursor");
struct json_object *conf = json_object_array_get_idx(args, 0);
@@ -564,7 +564,7 @@ ut_uci_set(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_uci_delete(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_uci_delete(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct uci_context **c = (struct uci_context **)ops->get_type(s->ctx, "uci.cursor");
struct json_object *conf = json_object_array_get_idx(args, 0);
@@ -599,7 +599,7 @@ ut_uci_delete(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_uci_rename(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_uci_rename(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct uci_context **c = (struct uci_context **)ops->get_type(s->ctx, "uci.cursor");
struct json_object *conf = json_object_array_get_idx(args, 0);
@@ -659,7 +659,7 @@ ut_uci_rename(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_uci_reorder(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_uci_reorder(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct uci_context **c = (struct uci_context **)ops->get_type(s->ctx, "uci.cursor");
struct json_object *conf = json_object_array_get_idx(args, 0);
@@ -699,7 +699,7 @@ ut_uci_reorder(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_uci_pkg_command(struct ut_state *s, uint32_t off, struct json_object *args, enum pkg_cmd cmd)
+uc_uci_pkg_command(struct uc_state *s, uint32_t off, struct json_object *args, enum pkg_cmd cmd)
{
struct uci_context **c = (struct uci_context **)ops->get_type(s->ctx, "uci.cursor");
struct json_object *conf = json_object_array_get_idx(args, 0);
@@ -746,21 +746,21 @@ ut_uci_pkg_command(struct ut_state *s, uint32_t off, struct json_object *args, e
}
static struct json_object *
-ut_uci_save(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_uci_save(struct uc_state *s, uint32_t off, struct json_object *args)
{
- return ut_uci_pkg_command(s, off, args, CMD_SAVE);
+ return uc_uci_pkg_command(s, off, args, CMD_SAVE);
}
static struct json_object *
-ut_uci_commit(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_uci_commit(struct uc_state *s, uint32_t off, struct json_object *args)
{
- return ut_uci_pkg_command(s, off, args, CMD_COMMIT);
+ return uc_uci_pkg_command(s, off, args, CMD_COMMIT);
}
static struct json_object *
-ut_uci_revert(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_uci_revert(struct uc_state *s, uint32_t off, struct json_object *args)
{
- return ut_uci_pkg_command(s, off, args, CMD_REVERT);
+ return uc_uci_pkg_command(s, off, args, CMD_REVERT);
}
static struct json_object *
@@ -853,7 +853,7 @@ changes_to_json(struct uci_context *ctx, const char *package)
}
static struct json_object *
-ut_uci_changes(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_uci_changes(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct uci_context **c = (struct uci_context **)ops->get_type(s->ctx, "uci.cursor");
struct json_object *conf = json_object_array_get_idx(args, 0);
@@ -892,7 +892,7 @@ ut_uci_changes(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_uci_foreach(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_uci_foreach(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct uci_context **c = (struct uci_context **)ops->get_type(s->ctx, "uci.cursor");
struct json_object *conf = json_object_array_get_idx(args, 0);
@@ -938,7 +938,7 @@ ut_uci_foreach(struct ut_state *s, uint32_t off, struct json_object *args)
rv = ops->invoke(s, off, NULL, func, fnargs);
/* forward exceptions from callback function */
- if (ut_is_type(rv, T_EXCEPTION)) {
+ if (uc_is_type(rv, T_EXCEPTION)) {
json_object_put(fnargs);
return rv;
@@ -959,7 +959,7 @@ ut_uci_foreach(struct ut_state *s, uint32_t off, struct json_object *args)
}
static struct json_object *
-ut_uci_configs(struct ut_state *s, uint32_t off, struct json_object *args)
+uc_uci_configs(struct uc_state *s, uint32_t off, struct json_object *args)
{
struct uci_context **c = (struct uci_context **)ops->get_type(s->ctx, "uci.cursor");
struct json_object *a;
@@ -987,28 +987,28 @@ ut_uci_configs(struct ut_state *s, uint32_t off, struct json_object *args)
}
-static const struct { const char *name; ut_c_fn *func; } cursor_fns[] = {
- { "load", ut_uci_load },
- { "unload", ut_uci_unload },
- { "get", ut_uci_get },
- { "get_all", ut_uci_get_all },
- { "get_first", ut_uci_get_first },
- { "add", ut_uci_add },
- { "set", ut_uci_set },
- { "rename", ut_uci_rename },
- { "save", ut_uci_save },
- { "delete", ut_uci_delete },
- { "commit", ut_uci_commit },
- { "revert", ut_uci_revert },
- { "reorder", ut_uci_reorder },
- { "changes", ut_uci_changes },
- { "foreach", ut_uci_foreach },
- { "configs", ut_uci_configs },
+static const struct { const char *name; uc_c_fn *func; } cursor_fns[] = {
+ { "load", uc_uci_load },
+ { "unload", uc_uci_unload },
+ { "get", uc_uci_get },
+ { "get_all", uc_uci_get_all },
+ { "get_first", uc_uci_get_first },
+ { "add", uc_uci_add },
+ { "set", uc_uci_set },
+ { "rename", uc_uci_rename },
+ { "save", uc_uci_save },
+ { "delete", uc_uci_delete },
+ { "commit", uc_uci_commit },
+ { "revert", uc_uci_revert },
+ { "reorder", uc_uci_reorder },
+ { "changes", uc_uci_changes },
+ { "foreach", uc_uci_foreach },
+ { "configs", uc_uci_configs },
};
-static const struct { const char *name; ut_c_fn *func; } global_fns[] = {
- { "error", ut_uci_error },
- { "cursor", ut_uci_cursor },
+static const struct { const char *name; uc_c_fn *func; } global_fns[] = {
+ { "error", uc_uci_error },
+ { "cursor", uc_uci_cursor },
};
@@ -1016,7 +1016,7 @@ static void close_uci(void *ud) {
uci_free_context((struct uci_context *)ud);
}
-void ut_module_init(const struct ut_ops *ut, struct ut_state *s, struct json_object *scope)
+void uc_module_init(const struct uc_ops *ut, struct uc_state *s, struct json_object *scope)
{
struct json_object *uci_proto;
diff --git a/main.c b/main.c
index 49fb2cc..5cbab74 100644
--- a/main.c
+++ b/main.c
@@ -38,10 +38,10 @@ print_usage(char *app)
{
printf(
"== Usage ==\n\n"
- " # %s [-d] [-l] [-r] [-S] [-e '[prefix=]{\"var\": ...}'] [-E [prefix=]env.json] {-i <file> | -s \"utpl script...\"}\n"
+ " # %s [-d] [-l] [-r] [-S] [-e '[prefix=]{\"var\": ...}'] [-E [prefix=]env.json] {-i <file> | -s \"ucode script...\"}\n"
" -h, --help Print this help\n"
- " -i file Specify an utpl script to parse\n"
- " -s \"utpl script...\" Specify an utpl code fragment to parse\n"
+ " -i file Specify an ucode script to parse\n"
+ " -s \"ucode script...\" Specify an ucode fragment to parse\n"
" -d Instead of executing the script, dump the resulting AST as dot\n"
" -l Do not strip leading block whitespace\n"
" -r Do not trim trailing block newlines\n"
@@ -53,9 +53,9 @@ print_usage(char *app)
}
#ifndef NDEBUG
-static void dump(struct ut_state *s, uint32_t off, int level);
+static void dump(struct uc_state *s, uint32_t off, int level);
-static void dump_node(struct ut_op *op) {
+static void dump_node(struct uc_op *op) {
const char *p;
switch (op->type) {
@@ -74,7 +74,7 @@ static void dump_node(struct ut_op *op) {
case T_STRING:
case T_LABEL:
case T_TEXT:
- printf("n%p [label=\"%s<", op, ut_get_tokenname(op->type));
+ printf("n%p [label=\"%s<", op, uc_get_tokenname(op->type));
for (p = json_object_get_string(op->val); *p; p++)
switch (*p) {
@@ -98,7 +98,7 @@ static void dump_node(struct ut_op *op) {
break;
default:
- printf("n%p [label=\"%s", op, ut_get_tokenname(op->type));
+ printf("n%p [label=\"%s", op, uc_get_tokenname(op->type));
if (op->is_postfix)
printf(", postfix");
@@ -107,20 +107,20 @@ static void dump_node(struct ut_op *op) {
}
}
-static void dump(struct ut_state *s, uint32_t off, int level) {
- struct ut_op *prev, *cur, *child;
+static void dump(struct uc_state *s, uint32_t off, int level) {
+ struct uc_op *prev, *cur, *child;
int i;
if (level == 0) {
printf("digraph G {\nmain [shape=box];\n");
}
- for (prev = NULL, cur = ut_get_op(s, off); cur; prev = cur, cur = ut_get_op(s, cur->tree.next)) {
+ for (prev = NULL, cur = uc_get_op(s, off); cur; prev = cur, cur = uc_get_op(s, cur->tree.next)) {
dump_node(cur);
if (cur->type < __T_MAX) {
for (i = 0; i < ARRAY_SIZE(cur->tree.operand); i++) {
- child = ut_get_op(s, cur->tree.operand[i]);
+ child = uc_get_op(s, cur->tree.operand[i]);
if (cur->tree.operand[i]) {
dump(s, cur->tree.operand[i], level + 1);
@@ -134,7 +134,7 @@ static void dump(struct ut_state *s, uint32_t off, int level) {
}
if (level == 0) {
- printf("main -> n%p [style=dotted];\n", ut_get_op(s, off));
+ printf("main -> n%p [style=dotted];\n", uc_get_op(s, off));
printf("}\n");
}
@@ -142,7 +142,7 @@ static void dump(struct ut_state *s, uint32_t off, int level) {
#endif /* NDEBUG */
static int
-parse(struct ut_state *state, struct ut_source *src, bool dumponly,
+parse(struct uc_state *state, struct uc_source *src, bool dumponly,
bool skip_shebang, struct json_object *env, struct json_object *modules)
{
struct json_object *rv;
@@ -169,20 +169,20 @@ parse(struct ut_state *state, struct ut_source *src, bool dumponly,
if (dumponly) {
#ifdef NDEBUG
- rv = ut_new_exception(state, 0, "Debug support not compiled in");
+ rv = uc_new_exception(state, 0, "Debug support not compiled in");
#else /* NDEBUG */
- rv = ut_parse(state, src->fp);
+ rv = uc_parse(state, src->fp);
- if (!ut_is_type(rv, T_EXCEPTION))
+ if (!uc_is_type(rv, T_EXCEPTION))
dump(state, state->main, 0);
#endif /* NDEBUG */
}
else {
- rv = ut_run(state, env, modules);
+ rv = uc_run(state, env, modules);
}
- if (ut_is_type(rv, T_EXCEPTION)) {
- msg = ut_format_error(state, src->fp);
+ if (uc_is_type(rv, T_EXCEPTION)) {
+ msg = uc_format_error(state, src->fp);
fprintf(stderr, "%s\n\n", msg);
free(msg);
rc = 1;
@@ -258,8 +258,8 @@ int
main(int argc, char **argv)
{
struct json_object *env = NULL, *modules = NULL, *o, *p;
- struct ut_state *state = NULL;
- struct ut_source source = {};
+ struct uc_state *state = NULL;
+ struct uc_source source = {};
char *stdin = NULL, *c;
bool dumponly = false;
bool shebang = false;
@@ -427,7 +427,7 @@ out:
json_object_put(modules);
json_object_put(env);
- ut_free(state);
+ uc_free(state);
free(stdin);
return rv;
diff --git a/module.h b/module.h
index ab15893..6d11a16 100644
--- a/module.h
+++ b/module.h
@@ -20,24 +20,24 @@
#include "ast.h"
#include "lib.h"
-struct ut_ops {
- bool (*register_function)(struct ut_state *, struct json_object *, const char *, ut_c_fn *);
+struct uc_ops {
+ bool (*register_function)(struct uc_state *, struct json_object *, const char *, uc_c_fn *);
bool (*register_type)(const char *, struct json_object *, void (*)(void *));
struct json_object *(*set_type)(struct json_object *, const char *, void *);
void **(*get_type)(struct json_object *, const char *);
struct json_object *(*new_object)(struct json_object *);
struct json_object *(*new_double)(double);
- struct json_object *(*invoke)(struct ut_state *, uint32_t, struct json_object *, struct json_object *, struct json_object *);
+ struct json_object *(*invoke)(struct uc_state *, uint32_t, struct json_object *, struct json_object *, struct json_object *);
enum json_type (*cast_number)(struct json_object *, int64_t *, double *);
};
-extern const struct ut_ops ut;
+extern const struct uc_ops ut;
#define register_functions(state, ops, functions, scope) \
if (scope) \
for (int i = 0; i < ARRAY_SIZE(functions); i++) \
ops->register_function(state, scope, functions[i].name, functions[i].func)
-void ut_module_init(const struct ut_ops *, struct ut_state *, struct json_object *);
+void uc_module_init(const struct uc_ops *, struct uc_state *, struct json_object *);
#endif /* __MODULE_H_ */
diff --git a/parser.y b/parser.y
index 45958b0..a992162 100644
--- a/parser.y
+++ b/parser.y
@@ -15,7 +15,7 @@
*/
%token_type {uint32_t}
-%extra_argument {struct ut_state *s}
+%extra_argument {struct uc_state *s}
%nonassoc T_LEXP T_REXP T_LSTM T_RSTM.
@@ -59,32 +59,32 @@
#define YYNOERRORRECOVERY
#define new_op(type, val, ...) \
- ut_new_op(s, type, val, ##__VA_ARGS__, UINT32_MAX)
+ uc_new_op(s, type, val, ##__VA_ARGS__, UINT32_MAX)
#define wrap_op(op, ...) \
- ut_wrap_op(s, op, ##__VA_ARGS__, UINT32_MAX)
+ uc_wrap_op(s, op, ##__VA_ARGS__, UINT32_MAX)
#define append_op(op1, op2) \
- ut_append_op(s, op1, op2)
+ uc_append_op(s, op1, op2)
#define no_empty_obj(op) \
- ut_no_empty_obj(s, op)
+ uc_no_empty_obj(s, op)
static inline uint32_t
-ut_no_empty_obj(struct ut_state *s, uint32_t off)
+uc_no_empty_obj(struct uc_state *s, uint32_t off)
{
- struct ut_op *op = ut_get_op(s, off);
+ struct uc_op *op = uc_get_op(s, off);
return (!op || op->type != T_LBRACE || op->tree.operand[0]) ? off : 0;
}
static inline uint32_t
-ut_add_else(struct ut_state *s, uint32_t off, uint32_t add)
+uc_add_else(struct uc_state *s, uint32_t off, uint32_t add)
{
- struct ut_op *tail = ut_get_op(s, off);
+ struct uc_op *tail = uc_get_op(s, off);
while (tail && tail->tree.operand[2])
- tail = ut_get_op(s, tail->tree.operand[2]);
+ tail = uc_get_op(s, tail->tree.operand[2]);
tail->tree.operand[2] = add;
@@ -92,21 +92,21 @@ ut_add_else(struct ut_state *s, uint32_t off, uint32_t add)
}
static inline uint32_t
-ut_expect_token(struct ut_state *s, uint32_t off, int token)
+uc_expect_token(struct uc_state *s, uint32_t off, int token)
{
uint64_t tokens[(__T_MAX + 63) & -64] = {};
tokens[token / 64] |= ((uint64_t)1 << (token % 64));
- ut_parse_error(s, off, tokens, token);
+ uc_parse_error(s, off, tokens, token);
return 0;
}
static inline uint32_t
-_ut_check_op_seq_types(struct ut_state *s, uint32_t off, ...)
+_uc_check_op_seq_types(struct uc_state *s, uint32_t off, ...)
{
uint64_t tokens[(__T_MAX + 63) & -64] = {};
- struct ut_op *arg = ut_get_op(s, off);
+ struct uc_op *arg = uc_get_op(s, off);
int token, max_token = 0;
va_list ap;
@@ -121,26 +121,26 @@ _ut_check_op_seq_types(struct ut_state *s, uint32_t off, ...)
while (arg) {
if (!(tokens[arg->type / 64] & ((uint64_t)1 << (arg->type % 64)))) {
- ut_parse_error(s, off, tokens, max_token);
+ uc_parse_error(s, off, tokens, max_token);
return 0;
}
- arg = ut_get_op(s, arg->tree.next);
+ arg = uc_get_op(s, arg->tree.next);
}
return off;
}
-#define ut_check_op_seq_types(s, off, ...) _ut_check_op_seq_types(s, off, __VA_ARGS__, 0)
+#define uc_check_op_seq_types(s, off, ...) _uc_check_op_seq_types(s, off, __VA_ARGS__, 0)
static inline uint32_t
-ut_reject_local(struct ut_state *s, uint32_t off)
+uc_reject_local(struct uc_state *s, uint32_t off)
{
- struct ut_op *op = ut_get_op(s, off);
+ struct uc_op *op = uc_get_op(s, off);
if (op->type == T_LOCAL) {
- ut_new_exception(s, op->off, "Syntax error: Unexpected token\nDeclaration not allowed in this context");
+ uc_new_exception(s, op->off, "Syntax error: Unexpected token\nDeclaration not allowed in this context");
return 0;
}
@@ -149,45 +149,45 @@ ut_reject_local(struct ut_state *s, uint32_t off)
}
static inline uint32_t
-ut_check_for_in(struct ut_state *s, uint32_t off)
+uc_check_for_in(struct uc_state *s, uint32_t off)
{
- struct ut_op *op = ut_get_op(s, off);
- struct ut_op *arg;
+ struct uc_op *op = uc_get_op(s, off);
+ struct uc_op *arg;
uint32_t idx = 0;
- arg = (op->type == T_LOCAL) ? ut_get_op(s, op->tree.operand[0]) : op;
+ arg = (op->type == T_LOCAL) ? uc_get_op(s, op->tree.operand[0]) : op;
if (arg->type == T_LABEL) {
- idx = ut_get_off(s, arg);
+ idx = uc_get_off(s, arg);
if (!arg->tree.next) {
- ut_new_exception(s, arg->off + json_object_get_string_len(arg->val),
+ uc_new_exception(s, arg->off + json_object_get_string_len(arg->val),
"Syntax error: Unexpected token\nExpecting ',' or 'in'");
return 0;
}
- arg = ut_get_op(s, arg->tree.next);
+ arg = uc_get_op(s, arg->tree.next);
}
- if (arg->type != T_IN || arg->tree.next || ut_get_op(s, arg->tree.operand[0])->type != T_LABEL) {
+ if (arg->type != T_IN || arg->tree.next || uc_get_op(s, arg->tree.operand[0])->type != T_LABEL) {
if (arg->type == T_IN && arg->tree.next)
- arg = ut_get_op(s, arg->tree.next);
+ arg = uc_get_op(s, arg->tree.next);
- ut_new_exception(s, arg->off, "Syntax error: Invalid for-in expression");
+ uc_new_exception(s, arg->off, "Syntax error: Invalid for-in expression");
return 0;
}
/* transform T_LABEL->T_IN(T_LABEL, ...) into T_IN(T_LABEL->T_LABEL, ...) */
if (idx) {
- ut_get_op(s, idx)->tree.next = 0;
+ uc_get_op(s, idx)->tree.next = 0;
arg->tree.operand[0] = append_op(idx, arg->tree.operand[0]);
if (op->type == T_LOCAL)
- op->tree.operand[0] = ut_get_off(s, arg);
+ op->tree.operand[0] = uc_get_off(s, arg);
else
- off = ut_get_off(s, arg);
+ off = uc_get_off(s, arg);
}
return off;
@@ -206,7 +206,7 @@ ut_check_for_in(struct ut_state *s, uint32_t off)
}
}
- ut_parse_error(s, TOKEN, tokens, max_token);
+ uc_parse_error(s, TOKEN, tokens, max_token);
}
@@ -249,13 +249,13 @@ sel_stmt(A) ::= T_IF(B) T_LPAREN exp(C) T_RPAREN stmt(D) T_ELSE stmt(E).
sel_stmt(A) ::= T_IF(B) T_LPAREN exp(C) T_RPAREN stmt(D). [T_IF]
{ A = wrap_op(B, C, no_empty_obj(D)); }
sel_stmt(A) ::= T_IF(B) T_LPAREN exp(C) T_RPAREN T_COLON chunks(D) sel_elifs(E) T_ELSE chunks(F) T_ENDIF.
- { A = ut_add_else(s, wrap_op(B, C, D, E), F); }
+ { A = uc_add_else(s, wrap_op(B, C, D, E), F); }
sel_stmt(A) ::= T_IF(B) T_LPAREN exp(C) T_RPAREN T_COLON chunks(D) T_ELSE chunks(E) T_ENDIF.
{ A = wrap_op(B, C, D, E); }
sel_stmt(A) ::= T_IF(B) T_LPAREN exp(C) T_RPAREN T_COLON chunks(D) T_ENDIF. [T_IF]
{ A = wrap_op(B, C, D); }
-sel_elifs(A) ::= sel_elifs(B) sel_elif(C). { A = ut_add_else(s, B, C); }
+sel_elifs(A) ::= sel_elifs(B) sel_elif(C). { A = uc_add_else(s, B, C); }
sel_elifs(A) ::= sel_elif(B). { A = B; }
sel_elif(A) ::= T_ELIF(B) T_LPAREN exp(C) T_RPAREN T_COLON chunks(D).
@@ -266,9 +266,9 @@ iter_stmt(A) ::= T_WHILE(B) T_LPAREN exp(C) T_RPAREN stmt(D).
iter_stmt(A) ::= T_WHILE(B) T_LPAREN exp(C) T_RPAREN T_COLON chunks(D) T_ENDWHILE.
{ A = wrap_op(B, C, D); }
iter_stmt(A) ::= T_FOR(B) paren_exp(C) stmt(D).
- { A = wrap_op(B, ut_check_for_in(s, C), NULL, NULL, no_empty_obj(D)); ut_get_op(s, A)->is_for_in = 1; }
+ { A = wrap_op(B, uc_check_for_in(s, C), NULL, NULL, no_empty_obj(D)); uc_get_op(s, A)->is_for_in = 1; }
iter_stmt(A) ::= T_FOR(B) paren_exp(C) T_COLON chunks(D) T_ENDFOR.
- { A = wrap_op(B, ut_check_for_in(s, C), NULL, NULL, no_empty_obj(D)); ut_get_op(s, A)->is_for_in = 1; }
+ { A = wrap_op(B, uc_check_for_in(s, C), NULL, NULL, no_empty_obj(D)); uc_get_op(s, A)->is_for_in = 1; }
iter_stmt(A) ::= T_FOR(B) T_LPAREN decl_or_exp(C) exp_stmt(D) T_RPAREN stmt(E).
{ A = wrap_op(B, C, D, NULL, no_empty_obj(E)); }
iter_stmt(A) ::= T_FOR(B) T_LPAREN decl_or_exp(C) exp_stmt(D) exp(E) T_RPAREN stmt(F).
@@ -311,8 +311,8 @@ switch_case(A) ::= T_CASE(B) exp(C) T_COLON stmts(D). { A = wrap_op(B, C, D); }
switch_case(A) ::= T_CASE(B) exp(C) T_COLON. { A = wrap_op(B, C); }
switch_case(A) ::= T_DEFAULT(B) T_COLON stmts(C). { A = wrap_op(B, C); }
-args(A) ::= sargs(B) T_COMMA T_ELLIP T_LABEL(C). { A = append_op(B, C); ut_get_op(s, C)->is_ellip = 1; }
-args(A) ::= T_ELLIP T_LABEL(B). { A = B; ut_get_op(s, B)->is_ellip = 1; }
+args(A) ::= sargs(B) T_COMMA T_ELLIP T_LABEL(C). { A = append_op(B, C); uc_get_op(s, C)->is_ellip = 1; }
+args(A) ::= T_ELLIP T_LABEL(B). { A = B; uc_get_op(s, B)->is_ellip = 1; }
args(A) ::= sargs(B). { A = B; }
sargs(A) ::= sargs(B) T_COMMA T_LABEL(C). { A = append_op(B, C); }
@@ -327,7 +327,7 @@ ret_stmt(A) ::= T_RETURN(B) T_SCOL. { A = B; }
break_stmt(A) ::= T_BREAK(B) T_SCOL. { A = B; }
break_stmt(A) ::= T_CONTINUE(B) T_SCOL. { A = B; }
-decl_stmt(A) ::= T_LOCAL(B) decls(C) T_SCOL. { A = wrap_op(B, ut_check_op_seq_types(s, C, T_ASSIGN, T_LABEL)); }
+decl_stmt(A) ::= T_LOCAL(B) decls(C) T_SCOL. { A = wrap_op(B, uc_check_op_seq_types(s, C, T_ASSIGN, T_LABEL)); }
decls(A) ::= decls(B) T_COMMA decl(C). { A = append_op(B, C); }
decls(A) ::= decl(B). { A = B; }
@@ -358,13 +358,13 @@ assign_exp(A) ::= unary_exp(B) T_ASBOR arrow_exp(C). { A = new_op(T_BOR, NULL, B
assign_exp(A) ::= arrow_exp(B). { A = B; }
arrow_exp(A) ::= unary_exp(B) T_ARROW(C) arrowfn_body(D).
- { A = wrap_op(C, 0, ut_check_op_seq_types(s, B, T_LABEL), D); }
+ { A = wrap_op(C, 0, uc_check_op_seq_types(s, B, T_LABEL), D); }
arrow_exp(A) ::= T_LPAREN T_RPAREN T_ARROW(C) arrowfn_body(D).
{ A = wrap_op(C, 0, 0, D); }
arrow_exp(A) ::= T_LPAREN T_ELLIP T_LABEL(B) T_RPAREN T_ARROW(C) arrowfn_body(D).
- { A = wrap_op(C, 0, B, D); ut_get_op(s, B)->is_ellip = 1; }
+ { A = wrap_op(C, 0, B, D); uc_get_op(s, B)->is_ellip = 1; }
arrow_exp(A) ::= T_LPAREN exp(B) T_COMMA T_ELLIP T_LABEL(C) T_RPAREN T_ARROW(D) arrowfn_body(E).
- { A = append_op(B, C); A = wrap_op(D, 0, ut_check_op_seq_types(s, A, T_LABEL), E); ut_get_op(s, C)->is_ellip = 1; }
+ { A = append_op(B, C); A = wrap_op(D, 0, uc_check_op_seq_types(s, A, T_LABEL), E); uc_get_op(s, C)->is_ellip = 1; }
arrow_exp(A) ::= ternary_exp(B). { A = B; }
ternary_exp(A) ::= or_exp(B) T_QMARK(C) assign_exp(D) T_COLON ternary_exp(E).
@@ -420,14 +420,14 @@ unary_exp(A) ::= T_COMPL(B) unary_exp(C). { A = wrap_op(B, C); }
unary_exp(A) ::= T_NOT(B) unary_exp(C). { A = wrap_op(B, C); }
unary_exp(A) ::= postfix_exp(B). { A = B; }
-postfix_exp(A) ::= unary_exp(B) T_INC(C). { A = wrap_op(C, B); ut_get_op(s, A)->is_postfix = 1; }
-postfix_exp(A) ::= unary_exp(B) T_DEC(C). { A = wrap_op(C, B); ut_get_op(s, A)->is_postfix = 1; }
+postfix_exp(A) ::= unary_exp(B) T_INC(C). { A = wrap_op(C, B); uc_get_op(s, A)->is_postfix = 1; }
+postfix_exp(A) ::= unary_exp(B) T_DEC(C). { A = wrap_op(C, B); uc_get_op(s, A)->is_postfix = 1; }
postfix_exp(A) ::= unary_exp(B) T_LPAREN(C) T_RPAREN. { A = wrap_op(C, B); }
postfix_exp(A) ::= unary_exp(B) T_LPAREN(C) arg_exps(D) T_RPAREN.
{ A = wrap_op(C, B, D); }
postfix_exp(A) ::= postfix_exp(B) T_DOT(C) T_LABEL(D). { A = wrap_op(C, B, D); }
postfix_exp(A) ::= postfix_exp(B) T_LBRACK(C) exp(D) T_RBRACK.
- { A = wrap_op(C, B, D); ut_get_op(s, A)->is_postfix = 1; }
+ { A = wrap_op(C, B, D); uc_get_op(s, A)->is_postfix = 1; }
postfix_exp(A) ::= primary_exp(B). { A = B; }
primary_exp(A) ::= T_BOOL(B). { A = B; }
@@ -440,7 +440,7 @@ primary_exp(A) ::= T_NULL(B). { A = B; }
primary_exp(A) ::= T_THIS(B). { A = B; }
primary_exp(A) ::= array(B). { A = B; }
primary_exp(A) ::= object(B). { A = B; }
-primary_exp(A) ::= paren_exp(B). { A = ut_reject_local(s, B); }
+primary_exp(A) ::= paren_exp(B). { A = uc_reject_local(s, B); }
primary_exp(A) ::= T_FUNC(B) T_LPAREN T_RPAREN empty_object.
{ A = B; }
primary_exp(A) ::= T_FUNC(B) T_LPAREN args(C) T_RPAREN empty_object.
@@ -459,8 +459,8 @@ array(A) ::= T_LBRACK(B) items(C) T_RBRACK. { A = wrap_op(B, C); }
items(A) ::= items(B) T_COMMA item(C). { A = append_op(B, C); }
items(A) ::= item(B). { A = B; }
-item(A) ::= T_ELLIP assign_exp(B). { A = ut_get_op(s, B)->tree.next ? new_op(T_COMMA, NULL, B) : B; ut_get_op(s, A)->is_ellip = 1; }
-item(A) ::= assign_exp(B). { A = ut_get_op(s, B)->tree.next ? new_op(T_COMMA, NULL, B) : B; }
+item(A) ::= T_ELLIP assign_exp(B). { A = uc_get_op(s, B)->tree.next ? new_op(T_COMMA, NULL, B) : B; uc_get_op(s, A)->is_ellip = 1; }
+item(A) ::= assign_exp(B). { A = uc_get_op(s, B)->tree.next ? new_op(T_COMMA, NULL, B) : B; }
object(A) ::= empty_object(B). { A = B; }
object(A) ::= T_LBRACE(B) tuples(C) T_RBRACE. { A = wrap_op(B, C); }
@@ -474,8 +474,8 @@ tuple(A) ::= T_LABEL(B) T_COLON exp(C). { A = wrap_op(B, C); }
tuple(A) ::= T_STRING(B) T_COLON exp(C). { A = wrap_op(B, C); }
tuple(A) ::= T_ELLIP(B) assign_exp(C). { A = wrap_op(B, C); }
-arg_exps(A) ::= arg_exps(B) T_COMMA arg_exp(C). { A = append_op(B, C); ut_get_op(s, A)->is_list = 1; }
-arg_exps(A) ::= arg_exp(B). { A = B; ut_get_op(s, A)->is_list = 1; }
+arg_exps(A) ::= arg_exps(B) T_COMMA arg_exp(C). { A = append_op(B, C); uc_get_op(s, A)->is_list = 1; }
+arg_exps(A) ::= arg_exp(B). { A = B; uc_get_op(s, A)->is_list = 1; }
-arg_exp(A) ::= T_ELLIP assign_exp(B). { A = ut_get_op(s, B)->tree.next ? new_op(T_COMMA, NULL, B) : B; ut_get_op(s, A)->is_ellip = 1; }
-arg_exp(A) ::= assign_exp(B). { A = ut_get_op(s, B)->tree.next ? new_op(T_COMMA, NULL, B) : B; }
+arg_exp(A) ::= T_ELLIP assign_exp(B). { A = uc_get_op(s, B)->tree.next ? new_op(T_COMMA, NULL, B) : B; uc_get_op(s, A)->is_ellip = 1; }
+arg_exp(A) ::= assign_exp(B). { A = uc_get_op(s, B)->tree.next ? new_op(T_COMMA, NULL, B) : B; }