From 18493ea076c61336bc9aad929074add0d7c9cc7e Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Fri, 10 Mar 2017 00:17:34 -0500 Subject: [PATCH] Retab some files, delete some other files --- .idea/interpreter.iml | 2 - .idea/misc.xml | 4 - .idea/modules.xml | 8 -- .idea/vcs.xml | 6 -- .idea/workspace.xml | 215 ------------------------------------------ compile.c | 68 ++++++------- datatypes.h | 26 ++--- disasm.c | 6 +- ds.c | 62 ++++++------ macros.gst | 5 - parse.c | 48 +++++----- stl.c | 82 ++++++++-------- temp.script | 10 -- util.h | 4 +- vm.c | 172 ++++++++++++++++----------------- 15 files changed, 234 insertions(+), 484 deletions(-) delete mode 100644 .idea/interpreter.iml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/workspace.xml delete mode 100644 macros.gst delete mode 100644 temp.script diff --git a/.idea/interpreter.iml b/.idea/interpreter.iml deleted file mode 100644 index f08604bb..00000000 --- a/.idea/interpreter.iml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 79b3c948..00000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 3e8301f0..00000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7f..00000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index a9666335..00000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,215 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - DEFINITION_ORDER - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1487818367037 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/compile.c b/compile.c index d4984ce5..2775a3a0 100644 --- a/compile.c +++ b/compile.c @@ -495,7 +495,7 @@ static Slot compile_operator(GstCompiler *c, FormOptions opts, GstValue *form, uint32_t count = gst_tuple_length(form); /* Check for some early exit conditions */ if (count == 2 && (flags & OP_1_REPEAT)) { - return compile_value(c, opts, form[1]); + return compile_value(c, opts, form[1]); } if (opts.resultUnused) { ret = nil_slot(); @@ -550,8 +550,8 @@ static Slot compile_operator(GstCompiler *c, FormOptions opts, GstValue *form, uint32_t i; FormOptions subOpts = form_options_default(); Slot lhs = compile_value(c, subOpts, form[1]); - Slot rhs = compile_value(c, subOpts, form[2]); - gst_buffer_push_u16(c->vm, buffer, op2); + Slot rhs = compile_value(c, subOpts, form[2]); + gst_buffer_push_u16(c->vm, buffer, op2); gst_buffer_push_u16(c->vm, buffer, ret.index); gst_buffer_push_u16(c->vm, buffer, lhs.index); gst_buffer_push_u16(c->vm, buffer, rhs.index); @@ -559,7 +559,7 @@ static Slot compile_operator(GstCompiler *c, FormOptions opts, GstValue *form, compiler_drop_slot(c, scope, rhs); for (i = 3; i < count; ++i) { rhs = compile_value(c, subOpts, form[i]); - gst_buffer_push_u16(c->vm, buffer, op2); + gst_buffer_push_u16(c->vm, buffer, op2); gst_buffer_push_u16(c->vm, buffer, ret.index); gst_buffer_push_u16(c->vm, buffer, ret.index); gst_buffer_push_u16(c->vm, buffer, rhs.index); @@ -582,7 +582,7 @@ static Slot compile_operator(GstCompiler *c, FormOptions opts, GstValue *form, /* Quickly define some specials */ #define MAKE_SPECIAL(name, op0, op1, op2, opn, flags) \ static Slot compile_##name (GstCompiler *c, FormOptions opts, GstValue *form) {\ - return compile_operator(c, opts, form, (op0), (op1), (op2), (opn), (flags));\ + return compile_operator(c, opts, form, (op0), (op1), (op2), (opn), (flags));\ } MAKE_SPECIAL(addition, 0, -1, GST_OP_ADD, -1, OP_FOLD | OP_DEFAULT_INT | OP_1_REPEAT) @@ -615,18 +615,18 @@ static Slot compile_set(GstCompiler *c, FormOptions opts, GstValue *form) { subOpts = form_options_default(); } key = compiler_realize_slot(c, compile_value(c, subOpts, form[2])); - val = compiler_realize_slot(c, compile_value(c, subOpts, form[3])); + val = compiler_realize_slot(c, compile_value(c, subOpts, form[3])); gst_buffer_push_u16(c->vm, buffer, GST_OP_SET); gst_buffer_push_u16(c->vm, buffer, ds.index); gst_buffer_push_u16(c->vm, buffer, key.index); - gst_buffer_push_u16(c->vm, buffer, val.index); + gst_buffer_push_u16(c->vm, buffer, val.index); compiler_drop_slot(c, c->tail, key); compiler_drop_slot(c, c->tail, val); if (opts.resultUnused) { compiler_drop_slot(c, c->tail, ds); return nil_slot(); } else { - return ds; + return ds; } } @@ -881,8 +881,8 @@ static Slot compile_try(GstCompiler *c, FormOptions opts, GstValue *form) { /* Add subscope for error variable */ GstScope *subScope = compiler_push_scope(c, 1); errorIndex = compiler_declare_symbol(c, subScope, form[1]); - /* Leave space for try instruction */ - countAtTry = buffer->count; + /* Leave space for try instruction */ + countAtTry = buffer->count; buffer->count += sizeof(uint32_t) + 2 * sizeof(uint16_t); /* Compile the body */ body = compile_value(c, opts, form[2]); @@ -1052,23 +1052,23 @@ static SpecialFormHelper get_special(GstValue *form) { } } break; - case 'e': - { - if (gst_string_length(name) == 5 && - name[1] == 'r' && - name[2] == 'r' && - name[3] == 'o' && - name[4] == 'r') { - return compile_error; - } - } + case 'e': + { + if (gst_string_length(name) == 5 && + name[1] == 'r' && + name[2] == 'r' && + name[3] == 'o' && + name[4] == 'r') { + return compile_error; + } + } case 'g': { - if (gst_string_length(name) == 3 && - name[1] == 'e' && - name[2] == 't') { - return compile_get; - } + if (gst_string_length(name) == 3 && + name[1] == 'e' && + name[2] == 't') { + return compile_get; + } } case 'd': { @@ -1102,7 +1102,7 @@ static SpecialFormHelper get_special(GstValue *form) { return compile_not; } } - break; + break; case 'q': { if (gst_string_length(name) == 5 && @@ -1134,7 +1134,7 @@ static SpecialFormHelper get_special(GstValue *form) { name[2] == 'p' && name[3] == 'l' && name[4] == 'e') { - return compile_make_tuple; + return compile_make_tuple; } } case 'w': @@ -1198,14 +1198,14 @@ static Slot compile_object(GstCompiler *c, FormOptions opts, GstObject *obj) { ret = compiler_get_target(c, opts); tracker_init(c, &tracker); for (i = 0; i < cap; ++i) { - bucket = obj->buckets[i]; - while (bucket != NULL) { + bucket = obj->buckets[i]; + while (bucket != NULL) { Slot slot = compile_value(c, subOpts, bucket->key); compiler_tracker_push(c, &tracker, compiler_realize_slot(c, slot)); slot = compile_value(c, subOpts, bucket->value); compiler_tracker_push(c, &tracker, compiler_realize_slot(c, slot)); - bucket = bucket->next; - } + bucket = bucket->next; + } } compiler_tracker_free(c, scope, &tracker); gst_buffer_push_u16(c->vm, buffer, GST_OP_DIC); @@ -1335,10 +1335,10 @@ GstFunction *gst_compiler_compile(GstCompiler *c, GstValue form) { GstFuncEnv *env = gst_alloc(c->vm, sizeof(GstFuncEnv)); GstFunction *func = gst_alloc(c->vm, sizeof(GstFunction)); if (envSize) { - env->values = gst_alloc(c->vm, sizeof(GstValue) * envSize); - gst_memcpy(env->values, c->env->data, envSize * sizeof(GstValue)); + env->values = gst_alloc(c->vm, sizeof(GstValue) * envSize); + gst_memcpy(env->values, c->env->data, envSize * sizeof(GstValue)); } else { - env->values = NULL; + env->values = NULL; } env->stackOffset = envSize; env->thread = NULL; diff --git a/datatypes.h b/datatypes.h index aee2e98c..01993082 100644 --- a/datatypes.h +++ b/datatypes.h @@ -74,14 +74,14 @@ struct GstValue { /* A lightweight thread in gst. Does not correspond to * operating system threads. Used in coroutines. */ struct GstThread { - uint32_t count; - uint32_t capacity; - GstValue *data; - enum { - GST_THREAD_PENDING = 0, - GST_THREAD_ALIVE, - GST_TRHEAD_DEAD - } status; + uint32_t count; + uint32_t capacity; + GstValue *data; + enum { + GST_THREAD_PENDING = 0, + GST_THREAD_ALIVE, + GST_TRHEAD_DEAD + } status; }; /* A dynamic array type. Useful for implementing a stack. */ @@ -147,8 +147,8 @@ struct GstBucket { /* Contains information about userdata */ struct GstUserdataHeader { - uint32_t size; - GstObject *meta; + uint32_t size; + GstObject *meta; }; /* VM return status from c function */ @@ -206,9 +206,9 @@ enum GstOpCode { GST_OP_TUP, /* Create tuple */ GST_OP_SET, /* Assocaitive set */ GST_OP_GET, /* Associative get */ - GST_OP_ERR, /* Throw error */ - GST_OP_TRY, /* Begin try block */ - GST_OP_UTY, /* End try block */ + GST_OP_ERR, /* Throw error */ + GST_OP_TRY, /* Begin try block */ + GST_OP_UTY, /* End try block */ GST_OP_RET, /* Return from function */ GST_OP_RTN, /* Return nil */ GST_OP_PSH, /* Push a stack frame */ diff --git a/disasm.c b/disasm.c index 74902422..18d24ef6 100644 --- a/disasm.c +++ b/disasm.c @@ -76,10 +76,10 @@ void gst_dasm(FILE * out, uint16_t *byteCode, uint32_t len) { break; case GST_OP_SUB: current += dasm_fixed_op(out, current, "sub", 3); - break; + break; case GST_OP_MUL: current += dasm_fixed_op(out, current, "mul", 3); - break; + break; case GST_OP_DIV: current += dasm_fixed_op(out, current, "div", 3); break; @@ -194,7 +194,7 @@ void gst_dasm(FILE * out, uint16_t *byteCode, uint32_t len) { current += dasm_fixed_op(out, current, "returnNil", 0); break; case GST_OP_PSH: - current += dasm_varg_op(out, current, "push", 1); + current += dasm_varg_op(out, current, "push", 1); break; case GST_OP_CAL: current += dasm_fixed_op(out, current, "call", 1); diff --git a/ds.c b/ds.c index 518453b7..7aa76064 100644 --- a/ds.c +++ b/ds.c @@ -149,11 +149,11 @@ GstValue gst_array_peek(GstArray *array) { /* Create a new emoty tuple of the given size. Expected to be * mutated immediately */ GstValue *gst_tuple(Gst *vm, uint32_t length) { - char *data = gst_alloc(vm, 2 * sizeof(uint32_t) + length * sizeof(GstValue)); - GstValue *tuple = (GstValue *)(data + (2 * sizeof(uint32_t))); - gst_tuple_length(tuple) = length; - gst_tuple_hash(tuple) = 0; - return tuple; + char *data = gst_alloc(vm, 2 * sizeof(uint32_t) + length * sizeof(GstValue)); + GstValue *tuple = (GstValue *)(data + (2 * sizeof(uint32_t))); + gst_tuple_length(tuple) = length; + gst_tuple_hash(tuple) = 0; + return tuple; } /****/ @@ -162,12 +162,12 @@ GstValue *gst_tuple(Gst *vm, uint32_t length) { /* Create new userdata */ void *gst_userdata(Gst *vm, uint32_t size, GstObject *meta) { - char *data = gst_alloc(vm, sizeof(GstUserdataHeader) + size); - GstUserdataHeader *header = (GstUserdataHeader *)data; - void *user = data + sizeof(GstUserdataHeader); - header->size = size; - header->meta = meta; - return user; + char *data = gst_alloc(vm, sizeof(GstUserdataHeader) + size); + GstUserdataHeader *header = (GstUserdataHeader *)data; + void *user = data + sizeof(GstUserdataHeader); + header->size = size; + header->meta = meta; + return user; } /****/ @@ -231,34 +231,34 @@ GstValue gst_object_get(GstObject *o, GstValue key) { /* Get a value of the object with a cstring key */ GstValue gst_object_get_cstring(GstObject *obj, const char *key) { const char *end = key; - while (*end++); - uint32_t len = end - key; - uint32_t hash = gst_cstring_calchash((uint8_t *)key, len); - uint32_t index = hash % obj->capacity; + while (*end++); + uint32_t len = end - key; + uint32_t hash = gst_cstring_calchash((uint8_t *)key, len); + uint32_t index = hash % obj->capacity; GstBucket *bucket = obj->buckets[index]; while (bucket) { if (bucket->key.type == GST_STRING) { uint8_t *s = bucket->key.data.string; - if (gst_string_length(s) == len) { - if (!gst_string_hash(s)) - gst_string_hash(s) = gst_string_calchash(s); - if (gst_string_hash(s) == hash) { - uint32_t i; - for (i = 0; i < len; ++i) - if (s[i] != key[i]) - goto notequal; - return bucket->value; - } - } + if (gst_string_length(s) == len) { + if (!gst_string_hash(s)) + gst_string_hash(s) = gst_string_calchash(s); + if (gst_string_hash(s) == hash) { + uint32_t i; + for (i = 0; i < len; ++i) + if (s[i] != key[i]) + goto notequal; + return bucket->value; + } + } } - notequal: - bucket = bucket->next; +notequal: + bucket = bucket->next; } /* Return nil */ { - GstValue ret; - ret.type = GST_NIL; - return ret; + GstValue ret; + ret.type = GST_NIL; + return ret; } } diff --git a/macros.gst b/macros.gst deleted file mode 100644 index b5204027..00000000 --- a/macros.gst +++ /dev/null @@ -1,5 +0,0 @@ -# Some basic macros - -(defmacro for [bindings ...] - -) diff --git a/parse.c b/parse.c index deb34494..7ab7fb0f 100644 --- a/parse.c +++ b/parse.c @@ -20,13 +20,13 @@ struct GstParseState { ParseType type; union { struct { - uint8_t endDelimiter; + uint8_t endDelimiter; GstArray *array; } form; struct { GstValue key; int keyFound; - GstObject *object; + GstObject *object; } object; struct { GstBuffer *buffer; @@ -362,22 +362,22 @@ static int form_state(GstParser *p, uint8_t c) { x.type = GST_ARRAY; x.data.array = array; } else if (c == ')') { - x.type = GST_TUPLE; - x.data.tuple = gst_tuple(p->vm, array->count); - gst_memcpy(x.data.tuple, array->data, array->count * sizeof(GstValue)); + x.type = GST_TUPLE; + x.data.tuple = gst_tuple(p->vm, array->count); + gst_memcpy(x.data.tuple, array->data, array->count * sizeof(GstValue)); } else { /* c == '{' */ uint32_t i; - if (array->count % 2 != 0) { - p_error(p, "object literal must have even number of elements"); - return 1; - } - x.type = GST_OBJECT; - x.data.object = gst_object(p->vm, array->count); - for (i = 0; i < array->count; i += 2) { - gst_object_put(p->vm, x.data.object, array->data[i], array->data[i + 1]); - } + if (array->count % 2 != 0) { + p_error(p, "object literal must have even number of elements"); + return 1; + } + x.type = GST_OBJECT; + x.data.object = gst_object(p->vm, array->count); + for (i = 0; i < array->count; i += 2) { + gst_object_put(p->vm, x.data.object, array->data[i], array->data[i + 1]); + } } - parser_pop(p); + parser_pop(p); parser_append(p, x); return 1; } @@ -392,17 +392,17 @@ static void dispatch_char(GstParser *p, uint8_t c) { /* Handle comments */ if (p->flags & GST_PARSER_FLAG_INCOMMENT) { if (c == '\n') { - p->flags = GST_PARSER_FLAG_EXPECTING_COMMENT; + p->flags = GST_PARSER_FLAG_EXPECTING_COMMENT; } - return; + return; } else if (p->flags & GST_PARSER_FLAG_EXPECTING_COMMENT) { if (c == '#') { - p->flags = GST_PARSER_FLAG_INCOMMENT; - return; + p->flags = GST_PARSER_FLAG_INCOMMENT; + return; } else if (!is_whitespace(c)) { - p->flags = 0; + p->flags = 0; } else { - return; + return; } } @@ -443,10 +443,10 @@ int gst_parse_cstring(GstParser *p, const char *string) { int gst_parse_string(GstParser *p, uint8_t *string) { uint32_t i; p->status = GST_PARSER_PENDING; - for (i = 0; i < gst_string_length(string); ++i) { - if (p->status != GST_PARSER_PENDING) break; + for (i = 0; i < gst_string_length(string); ++i) { + if (p->status != GST_PARSER_PENDING) break; dispatch_char(p, string[i]); - } + } return i; } diff --git a/stl.c b/stl.c index bf6dd4b2..fbca725b 100644 --- a/stl.c +++ b/stl.c @@ -24,41 +24,41 @@ int gst_stl_print(Gst *vm) { /* Get class value */ int gst_stl_getclass(Gst *vm) { - GstValue class = gst_get_class(gst_arg(vm, 0)); - gst_c_return(vm, class); + GstValue class = gst_get_class(gst_arg(vm, 0)); + gst_c_return(vm, class); } /* Set class value */ int gst_stl_setclass(Gst *vm) { - GstValue x = gst_arg(vm, 0); - GstValue class = gst_arg(vm, 1); - const char *err = gst_set_class(x, class); - if (err != NULL) - gst_c_throwc(vm, err); - gst_c_return(vm, x); + GstValue x = gst_arg(vm, 0); + GstValue class = gst_arg(vm, 1); + const char *err = gst_set_class(x, class); + if (err != NULL) + gst_c_throwc(vm, err); + gst_c_return(vm, x); } /* Call a function */ int gst_stl_callforeach(Gst *vm) { - GstValue func = gst_arg(vm, 0); - uint32_t argCount = gst_count_args(vm); - uint32_t i; - if (argCount) { - for (i = 0; i < argCount - 1; ++i) - gst_call(vm, func, 1, vm->thread->data + vm->thread->count + 1 + i); - return GST_RETURN_OK; + GstValue func = gst_arg(vm, 0); + uint32_t argCount = gst_count_args(vm); + uint32_t i; + if (argCount) { + for (i = 0; i < argCount - 1; ++i) + gst_call(vm, func, 1, vm->thread->data + vm->thread->count + 1 + i); + return GST_RETURN_OK; } else { - gst_c_throwc(vm, "expected at least one argument"); + gst_c_throwc(vm, "expected at least one argument"); } } /* Exit */ int gst_stl_exit(Gst *vm) { int ret; - GstValue exitValue = gst_arg(vm, 0); - ret = (exitValue.type == GST_NUMBER) ? exitValue.data.number : 0; - exit(ret); - return GST_RETURN_OK; + GstValue exitValue = gst_arg(vm, 0); + ret = (exitValue.type == GST_NUMBER) ? exitValue.data.number : 0; + exit(ret); + return GST_RETURN_OK; } /* Load core */ @@ -76,25 +76,25 @@ void gst_stl_load_core(GstCompiler *c) { /* Parse a source string into an AST */ int gst_stl_parse(Gst *vm) { - uint8_t *source = gst_to_string(vm, gst_arg(vm, 0)); - GstParser p; + uint8_t *source = gst_to_string(vm, gst_arg(vm, 0)); + GstParser p; /* init state */ gst_parser(&p, vm); /* Get and parse input until we have a full form */ gst_parse_string(&p, source); - if (p.status == GST_PARSER_PENDING) { - gst_c_throwc(vm, "incomplete source"); - } else if (p.status == GST_PARSER_ERROR) { + if (p.status == GST_PARSER_PENDING) { + gst_c_throwc(vm, "incomplete source"); + } else if (p.status == GST_PARSER_ERROR) { gst_c_throwc(vm, p.error); - } else { - gst_c_return(vm, p.value); + } else { + gst_c_return(vm, p.value); } } /* Load parsing */ void gst_stl_load_parse(GstCompiler *c) { - gst_compiler_add_global_cfunction(c, "parse", gst_stl_parse); + gst_compiler_add_global_cfunction(c, "parse", gst_stl_parse); } /****/ @@ -110,25 +110,25 @@ int gst_stl_compile(Gst *vm) { /* init state */ gst_compiler(&c, vm); /* Check for environment variables */ - if (env.type == GST_OBJECT) { - /* Iterate through environment, adding globals */ - } else if (env.type != GST_NIL) { - gst_c_throwc(vm, "invalid type for environment"); - } - /* Prepare return value */ - ret.type = GST_FUNCTION; + if (env.type == GST_OBJECT) { + /* Iterate through environment, adding globals */ + } else if (env.type != GST_NIL) { + gst_c_throwc(vm, "invalid type for environment"); + } + /* Prepare return value */ + ret.type = GST_FUNCTION; ret.data.function = gst_compiler_compile(&c, ast); /* Check for errors */ if (c.error == NULL) { - gst_c_return(vm, ret); + gst_c_return(vm, ret); } else { - gst_c_throwc(vm, c.error); + gst_c_throwc(vm, c.error); } } /* Load compilation */ void gst_stl_load_compile(GstCompiler *c) { - gst_compiler_add_global_cfunction(c, "compile", gst_stl_compile); + gst_compiler_add_global_cfunction(c, "compile", gst_stl_compile); } /****/ @@ -143,7 +143,7 @@ void gst_stl_load_compile(GstCompiler *c) { /* Load all libraries */ void gst_stl_load(GstCompiler *c) { - gst_stl_load_core(c); - gst_stl_load_parse(c); - gst_stl_load_compile(c); + gst_stl_load_core(c); + gst_stl_load_parse(c); + gst_stl_load_compile(c); } diff --git a/temp.script b/temp.script deleted file mode 100644 index 01f70ac4..00000000 --- a/temp.script +++ /dev/null @@ -1,10 +0,0 @@ -(do - -(:= fib (fn (n) - (if (< n 2) - 1 - (+ (fib (- n 1)) (fib (- n 2)))))) - -(print 10) -(print (fib 33)) -) diff --git a/util.h b/util.h index 90b5464a..622f4cac 100644 --- a/util.h +++ b/util.h @@ -52,8 +52,8 @@ #define GST_FRAME_SIZE 5 /* Macros for referencing that a stack frame given a stack */ -#define gst_frame_callee(s) (*(s - 1)) -#define gst_frame_size(s) ((s - 2)->data.hws[0]) +#define gst_frame_callee(s) (*(s - 1)) +#define gst_frame_size(s) ((s - 2)->data.hws[0]) #define gst_frame_prevsize(s) ((s - 2)->data.hws[1]) #define gst_frame_errloc(s) ((s - 2)->data.hws[2]) #define gst_frame_ret(s) ((s - 2)->data.hws[3]) diff --git a/vm.c b/vm.c index a095e2d4..1970c599 100644 --- a/vm.c +++ b/vm.c @@ -54,7 +54,7 @@ static void gst_load(Gst *vm, GstValue callee) { gst_frame_pc(stack) = pc; /* Nil arguments */ for (i = 0; i < locals; ++i) - stack[i].type = GST_NIL; + stack[i].type = GST_NIL; } /* Contextual macro to state in function with VM */ @@ -65,7 +65,7 @@ static void gst_load(Gst *vm, GstValue callee) { /* Write local state back to VM */ #define GST_STATE_WRITE() do { \ - *vm->thread = thread; \ + *vm->thread = thread; \ } while (0) /* Start running the VM from where it left off. Continue running @@ -77,8 +77,8 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) { GstValue temp, v1, v2; uint16_t *pc; - /* Intialize local state */ - GST_STATE_SYNC(); + /* Intialize local state */ + GST_STATE_SYNC(); pc = gst_frame_pc(stack); /* Main interpreter loop */ @@ -87,7 +87,7 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) { switch (*pc) { default: - gst_error(vm, "unknown opcode"); + gst_error(vm, "unknown opcode"); break; #define OP_BINARY_MATH(op) \ @@ -122,23 +122,23 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) { pc += 3; break; - case GST_OP_NEG: /* Unary negation */ - v1 = stack[pc[2]]; - gst_assert(vm, v1.type == GST_NUMBER, GST_EXPECTED_NUMBER_LOP); - temp.type = GST_NUMBER; - temp.data.number = -v1.data.number; - stack[pc[1]] = temp; - pc += 3; - break; + case GST_OP_NEG: /* Unary negation */ + v1 = stack[pc[2]]; + gst_assert(vm, v1.type == GST_NUMBER, GST_EXPECTED_NUMBER_LOP); + temp.type = GST_NUMBER; + temp.data.number = -v1.data.number; + stack[pc[1]] = temp; + pc += 3; + break; - case GST_OP_INV: /* Unary multiplicative inverse */ - v1 = stack[pc[2]]; - gst_assert(vm, v1.type == GST_NUMBER, GST_EXPECTED_NUMBER_LOP); - temp.type = GST_NUMBER; - temp.data.number = 1 / v1.data.number; - stack[pc[1]] = temp; - pc += 3; - break; + case GST_OP_INV: /* Unary multiplicative inverse */ + v1 = stack[pc[2]]; + gst_assert(vm, v1.type == GST_NUMBER, GST_EXPECTED_NUMBER_LOP); + temp.type = GST_NUMBER; + temp.data.number = 1 / v1.data.number; + stack[pc[1]] = temp; + pc += 3; + break; case GST_OP_FLS: /* Load False */ temp.type = GST_BOOLEAN; @@ -211,7 +211,7 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) { break; case GST_OP_CST: /* Load constant value */ - v1 = gst_frame_callee(stack); + v1 = gst_frame_callee(stack); gst_assert(vm, v1.type == GST_FUNCTION, GST_EXPECTED_FUNCTION); if (pc[2] > v1.data.function->def->literalsLen) gst_error(vm, GST_NO_UPVALUE); @@ -336,40 +336,40 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) { break; case GST_OP_GET: /* Associative get */ - { - const char *err; - err = gst_get(stack[pc[2]], stack[pc[3]], stack + pc[1]); - if (err != NULL) - gst_error(vm, err); - pc += 4; + { + const char *err; + err = gst_get(stack[pc[2]], stack[pc[3]], stack + pc[1]); + if (err != NULL) + gst_error(vm, err); + pc += 4; break; - } + } case GST_OP_SET: /* Associative set */ - { - const char *err; - err = gst_set(vm, stack[pc[1]], stack[pc[2]], stack[pc[3]]); - if (err != NULL) - gst_error(vm, err); - pc += 4; + { + const char *err; + err = gst_set(vm, stack[pc[1]], stack[pc[2]], stack[pc[3]]); + if (err != NULL) + gst_error(vm, err); + pc += 4; break; - } + } - case GST_OP_ERR: /* Throw error */ - vm->ret = stack[pc[1]]; - goto vm_error; - break; + case GST_OP_ERR: /* Throw error */ + vm->ret = stack[pc[1]]; + goto vm_error; + break; - case GST_OP_TRY: /* Begin try block */ - gst_frame_errloc(stack) = pc[1]; - gst_frame_errjmp(stack) = pc + *(uint32_t *)(pc + 2); - pc += 4; - break; + case GST_OP_TRY: /* Begin try block */ + gst_frame_errloc(stack) = pc[1]; + gst_frame_errjmp(stack) = pc + *(uint32_t *)(pc + 2); + pc += 4; + break; - case GST_OP_UTY: /* End try block */ - gst_frame_errjmp(stack) = NULL; - pc++; - break; + case GST_OP_UTY: /* End try block */ + gst_frame_errjmp(stack) = NULL; + pc++; + break; case GST_OP_RTN: /* Return nil */ vm->ret.type = GST_NIL; @@ -377,10 +377,10 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) { case GST_OP_RET: /* Return */ vm->ret = stack[pc[1]]; - goto ret; + goto ret; - case GST_OP_PSH: /* Push stack frame */ - { + case GST_OP_PSH: /* Push stack frame */ + { GstValue *nextStack; uint32_t expectedArity, normalArity, arity, varArgs, i, locals, nextCount; @@ -439,34 +439,34 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) { if (varArgs) { GstValue *tuple; uint32_t j; - tuple = gst_tuple(vm, arity - expectedArity); - for (j = expectedArity; j < arity; ++j) - tuple[j - expectedArity] = stack[pc[3 + j]]; - nextStack[expectedArity].type = GST_TUPLE; - nextStack[expectedArity].data.tuple = tuple; + tuple = gst_tuple(vm, arity - expectedArity); + for (j = expectedArity; j < arity; ++j) + tuple[j - expectedArity] = stack[pc[3 + j]]; + nextStack[expectedArity].type = GST_TUPLE; + nextStack[expectedArity].data.tuple = tuple; } /* Increment pc */ pc += 3 + arity; - } - break; + } + break; case GST_OP_CAL: /* Call */ case GST_OP_TCL: /* Tail call */ if (pc[0] == GST_OP_CAL) { gst_frame_ret(stack) = pc[1]; gst_frame_pc(stack) = pc + 2; - thread.count += gst_frame_size(stack) + GST_FRAME_SIZE; - stack = thread.data + thread.count; + thread.count += gst_frame_size(stack) + GST_FRAME_SIZE; + stack = thread.data + thread.count; } else { uint32_t i; GstValue *nextStack = stack + gst_frame_size(stack) + GST_FRAME_SIZE; uint32_t nextSize = gst_frame_size(nextStack); /* Check for closures */ if (gst_frame_env(stack) != NULL) { - gst_frame_env(stack)->thread = NULL; + gst_frame_env(stack)->thread = NULL; gst_frame_env(stack)->stackOffset = gst_frame_size(stack); - gst_frame_env(stack)->values = gst_alloc(vm, sizeof(GstValue) * gst_frame_size(stack)); + gst_frame_env(stack)->values = gst_alloc(vm, sizeof(GstValue) * gst_frame_size(stack)); gst_memcpy(gst_frame_env(stack)->values, thread.data + thread.count, gst_frame_size(stack) * sizeof(GstValue)); @@ -477,8 +477,8 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) { gst_frame_env(stack) = NULL; gst_frame_errjmp(stack) = NULL; /* Replace current stack frame with next */ - for (i = 0; i < nextSize; ++i) - stack[i] = nextStack[i]; + for (i = 0; i < nextSize; ++i) + stack[i] = nextStack[i]; } v1 = gst_frame_callee(stack); if (v1.type == GST_FUNCTION) { @@ -486,7 +486,7 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) { } else if (v1.type == GST_CFUNCTION) { int status; GST_STATE_WRITE(); - status = v1.data.cfunction(vm); + status = v1.data.cfunction(vm); GST_STATE_SYNC(); if (status == GST_RETURN_OK) goto ret; @@ -500,9 +500,9 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) { /* Macro for popping stack frame */ #define pop_frame(onUnderflow) do { \ if (gst_frame_env(stack) != NULL) { \ - gst_frame_env(stack)->thread = NULL; \ + gst_frame_env(stack)->thread = NULL; \ gst_frame_env(stack)->stackOffset = gst_frame_size(stack); \ - gst_frame_env(stack)->values = gst_alloc(vm, sizeof(GstValue) * gst_frame_size(stack)); \ + gst_frame_env(stack)->values = gst_alloc(vm, sizeof(GstValue) * gst_frame_size(stack)); \ gst_memcpy(gst_frame_env(stack)->values, \ thread.data + thread.count, \ gst_frame_size(stack) * sizeof(GstValue)); \ @@ -518,7 +518,7 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) { /* Label for return */ ret: /* Check for closure */ - pop_frame(GST_RETURN_OK); + pop_frame(GST_RETURN_OK); pc = gst_frame_pc(stack); stack[gst_frame_ret(stack)] = vm->ret; break; @@ -526,7 +526,7 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) { /* Handle errors from c functions and vm opcodes */ vm_error: while (gst_frame_errjmp(stack) == NULL) - pop_frame(GST_RETURN_ERROR); + pop_frame(GST_RETURN_ERROR); pc = gst_frame_errjmp(stack); stack[gst_frame_errloc(stack)] = vm->ret; break; @@ -546,13 +546,13 @@ static int gst_continue_size(Gst *vm, uint32_t stackBase) { /* Continue running the VM after it has stopped */ int gst_continue(Gst *vm) { - return gst_continue_size(vm, vm->thread->count); + return gst_continue_size(vm, vm->thread->count); } /* Run the vm with a given function */ int gst_run(Gst *vm, GstValue func) { - gst_load(vm, func); - return gst_continue(vm); + gst_load(vm, func); + return gst_continue(vm); } /* Raw function call implementation for use from c code. Beware code @@ -595,8 +595,8 @@ int gst_call(Gst *vm, GstValue callee, uint32_t arity, GstValue *args) { thread.capacity = newCap; } - /* Save modified thread object */ - thread.count = nextCount; + /* Save modified thread object */ + thread.count = nextCount; *vm->thread = thread; /* Set up the new stack frame */ @@ -620,11 +620,11 @@ int gst_call(Gst *vm, GstValue callee, uint32_t arity, GstValue *args) { if (varArgs) { GstValue *tuple; uint32_t j; - tuple = gst_tuple(vm, arity - expectedArity); - for (j = expectedArity; j < arity; ++j) - tuple[j - expectedArity] = args[j]; - stack[expectedArity].type = GST_TUPLE; - stack[expectedArity].data.tuple = tuple; + tuple = gst_tuple(vm, arity - expectedArity); + for (j = expectedArity; j < arity; ++j) + tuple[j - expectedArity] = args[j]; + stack[expectedArity].type = GST_TUPLE; + stack[expectedArity].data.tuple = tuple; } /* Call the function */ @@ -635,9 +635,9 @@ int gst_call(Gst *vm, GstValue callee, uint32_t arity, GstValue *args) { GST_STATE_SYNC(); /* Check for closures */ if (gst_frame_env(stack) != NULL) { - gst_frame_env(stack)->thread = NULL; + gst_frame_env(stack)->thread = NULL; gst_frame_env(stack)->stackOffset = gst_frame_size(stack); - gst_frame_env(stack)->values = gst_alloc(vm, sizeof(GstValue) * gst_frame_size(stack)); + gst_frame_env(stack)->values = gst_alloc(vm, sizeof(GstValue) * gst_frame_size(stack)); gst_memcpy(gst_frame_env(stack)->values, thread.data + thread.count, gst_frame_size(stack) * sizeof(GstValue)); @@ -652,9 +652,9 @@ GstValue gst_arg(Gst *vm, uint16_t index) { GstValue *stack = vm->thread->data + vm->thread->count; uint16_t frameSize = gst_frame_size(stack); if (frameSize <= index) { - GstValue ret; - ret.type = GST_NIL; - return ret; + GstValue ret; + ret.type = GST_NIL; + return ret; } return stack[index]; } @@ -663,7 +663,7 @@ GstValue gst_arg(Gst *vm, uint16_t index) { void gst_set_arg(Gst* vm, uint16_t index, GstValue x) { GstValue *stack = vm->thread->data + vm->thread->count; uint16_t frameSize = gst_frame_size(stack); - if (frameSize <= index) return; + if (frameSize <= index) return; stack[index] = x; }