diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-09-05 14:25:38 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-09-06 21:57:26 +0200 |
commit | 88099fdaf55a24854508b7a75d690fa76be6f44a (patch) | |
tree | d333186871ec1719bc03319f358583b655da46f2 /lib | |
parent | b0153864c0cef2f4ba6202a0242f93d607ccbae9 (diff) |
treewide: refactor internal AST structures
- unify operand and value tag structures
- use a contiguous array for storing opcodes
- use relative offsets for next and children ops
- defer function creation to runtime
- rework "this" context handling by storing context pointer in scope tags
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fs.c | 28 |
1 files changed, 14 insertions, 14 deletions
@@ -32,7 +32,7 @@ static struct json_object *dir_proto; static int last_error = 0; static struct json_object * -ut_fs_error(struct ut_state *s, struct ut_opcode *op, struct json_object *args) +ut_fs_error(struct ut_state *s, uint32_t off, struct json_object *args) { struct json_object *errmsg; @@ -47,7 +47,7 @@ ut_fs_error(struct ut_state *s, struct ut_opcode *op, struct json_object *args) static struct json_object * -ut_fs_close(struct ut_state *s, struct ut_opcode *op, struct json_object *args) +ut_fs_close(struct ut_state *s, uint32_t off, struct json_object *args) { FILE **fp = (FILE **)ops->get_type(s->ctx, "fs.file"); @@ -61,7 +61,7 @@ ut_fs_close(struct ut_state *s, struct ut_opcode *op, struct json_object *args) } static struct json_object * -ut_fs_read(struct ut_state *s, struct ut_opcode *op, struct json_object *args) +ut_fs_read(struct ut_state *s, uint32_t off, struct json_object *args) { struct json_object *limit = json_object_array_get_idx(args, 0); struct json_object *rv = NULL; @@ -153,7 +153,7 @@ ut_fs_read(struct ut_state *s, struct ut_opcode *op, struct json_object *args) } static struct json_object * -ut_fs_write(struct ut_state *s, struct ut_opcode *op, struct json_object *args) +ut_fs_write(struct ut_state *s, uint32_t off, struct json_object *args) { struct json_object *data = json_object_array_get_idx(args, 0); size_t len, wsize; @@ -182,9 +182,9 @@ ut_fs_write(struct ut_state *s, struct ut_opcode *op, struct json_object *args) } static struct json_object * -ut_fs_seek(struct ut_state *s, struct ut_opcode *op, struct json_object *args) +ut_fs_seek(struct ut_state *s, uint32_t off, struct json_object *args) { - struct json_object *off = json_object_array_get_idx(args, 0); + struct json_object *ofs = json_object_array_get_idx(args, 0); struct json_object *how = json_object_array_get_idx(args, 1); int whence, res; long offset; @@ -194,12 +194,12 @@ ut_fs_seek(struct ut_state *s, struct ut_opcode *op, struct json_object *args) if (!fp || !*fp) err_return(EBADF); - if (!off) + if (!ofs) offset = 0; - else if (!json_object_is_type(off, json_type_int)) + else if (!json_object_is_type(ofs, json_type_int)) err_return(EINVAL); else - offset = (long)json_object_get_int64(off); + offset = (long)json_object_get_int64(ofs); if (!how) whence = 0; @@ -217,7 +217,7 @@ ut_fs_seek(struct ut_state *s, struct ut_opcode *op, struct json_object *args) } static struct json_object * -ut_fs_tell(struct ut_state *s, struct ut_opcode *op, struct json_object *args) +ut_fs_tell(struct ut_state *s, uint32_t off, struct json_object *args) { long offset; @@ -235,7 +235,7 @@ ut_fs_tell(struct ut_state *s, struct ut_opcode *op, struct json_object *args) } static struct json_object * -ut_fs_open(struct ut_state *s, struct ut_opcode *op, struct json_object *args) +ut_fs_open(struct ut_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); @@ -263,7 +263,7 @@ ut_fs_open(struct ut_state *s, struct ut_opcode *op, struct json_object *args) static struct json_object * -ut_fs_readdir(struct ut_state *s, struct ut_opcode *op, struct json_object *args) +ut_fs_readdir(struct ut_state *s, uint32_t off, struct json_object *args) { DIR **dp = (DIR **)ops->get_type(s->ctx, "fs.dir"); struct dirent *e; @@ -281,7 +281,7 @@ ut_fs_readdir(struct ut_state *s, struct ut_opcode *op, struct json_object *args } static struct json_object * -ut_fs_closedir(struct ut_state *s, struct ut_opcode *op, struct json_object *args) +ut_fs_closedir(struct ut_state *s, uint32_t off, struct json_object *args) { DIR **dp = (DIR **)ops->get_type(s->ctx, "fs.dir"); @@ -295,7 +295,7 @@ ut_fs_closedir(struct ut_state *s, struct ut_opcode *op, struct json_object *arg } static struct json_object * -ut_fs_opendir(struct ut_state *s, struct ut_opcode *op, struct json_object *args) +ut_fs_opendir(struct ut_state *s, uint32_t off, struct json_object *args) { struct json_object *path = json_object_array_get_idx(args, 0); struct json_object *diro; |