commit 74be65f0a0d7b7fd37ee4aae722320df5a2fd624 parent 0fa648a0db80ed4c9ee179239de9e2133715ccf5 Author: Paul Longtine <paullongtine@gmail.com> Date: Sun Mar 27 11:59:12 2016 More doc, implemented variable ownership, on the path to good livin' Diffstat: doc/SPECIFICATION | 115 +++++++++++++++++++---------------- src/vm/inc/ns.h | 5 +- src/vm/inc/proc.h | 3 +- src/vm/inc/var.h | 10 +--- src/vm/src/bc.c | 4 +- src/vm/src/ins_def.c | 13 ++-- src/vm/src/ns.c | 92 +++++++++++++++++----------- src/vm/src/stk.c | 2 +- src/vm/src/var.c | 16 ++--- src/vm/src/var_ops.c | 28 ++++----- src/vm/tests/cases/bc/Makefile | 2 +- src/vm/tests/cases/ns/expected_output | 13 +++- src/vm/tests/cases/ns/test.c | 56 +++++++++++++++-- src/vm/tests/cases/stk/test.c | 10 +-- src/vm/tests/tools/test.sh | 2 +- 15 files changed, 235 insertions(+), 136 deletions(-)
diff --git a/doc/SPECIFICATION b/doc/SPECIFICATION @@ -40,40 +40,53 @@ that stuff for you. -------------------------------------------------------------------------------- General Architecture Overview -------------------------------------------------------------------------------- -RUNTIME CONTEXT +RUNTIME ELEMENTS - The runtime context keeps track of a invidual threads metadata, such as: + RUNTIME CONTEXT DEFINITION + +The runtime context keeps track of a invidual threads metadata, such as: * The operating stack The operating stack where current running instructions push/pop to. + - refer to STACK DEFINITION * Namespace instance Data structure that holds the references to variable containers, also provi ing the interface for Namespace Levels. + - refer to NAMESPACE DEFINITION * Arguement stack Arguements to function calls are pushed on to this stack, flushed on call. + - refer to STACK DEFINITION, FUNCTION DEFINTION * Program counter - The abstract interface with bytecode instructions that handles the program - space. + An interface around bytecode to keep track of traversing line-numbered + instructions. + - refer to PROGRAM COUNTER DEFINITION + +This context gives definition to an 'environment' where code is executed. + + NAMESPACE DEFINITION + +A key part to any operational computer language is the notion of a 'Namespace'. +This notion of a 'Namespace' refers to the ability to declare a name, along with +needed metadata, and call upon the same name to retrieve the values assosaited +with that name. -RUNTIME CODE STRUCTURE/NAMESPACE +In this definition, the namespace will provide the following key mechanisms: - Code in the runtime is organized on a per-function basis. + * Declaring a name -'Function' in this case means a callable block of code that returns a typed -value. A function is a wrapper around a collection of instructions that operate -within the context of the function, i.e. the functions parameters, the concept -of scopes, references, etc. + * Assigning a name to a value -Parameters are handled by the callee, pushing variables to an arguement stack -pre-call. Variables on the arguement stack are loaded into local references on -the new local namespace. Parameters are locally allocated as the first n labels -of the new local namespace. + * Retreiving a name's value -Scopes are handled by referencing to either the Global Scope, Local Scope. -Local Scope is denoted by '1' in the scope arguement when handling variables, + * Handle a name's scope + + * Implicitly move in/out of scopes + +Scopes are handled by referencing to either the Global Scope or the Local Scope. +The Local Scope is denoted by '1' in the scope arguement when refering to names, and this scope is initialized when evaluating any new block of code. When a diff erent block of code is called, a new scope is added as a new Namespace level. Namespace levels act as context switches within function contexts. For example, @@ -93,55 +106,54 @@ level increases, like so: Level 1: Namespace level. Level 2: Namespace level, where Local Level is at 2, denoted by '1'. -Global scope variables (denoted by a '0' in the scope arguement) are persistient +Global scope names (denoted by a '0' in the scope arguement) are persistient through the runtime as they handle all function definitions, objects, and -variables declared in the global scope. The "Local Level" is at where references -that have a scope arguement of '1' refer to when accessing variables. +names declared in the global scope. The "Local Level" is at where references +that have a scope arguement of '1' refer to when accessing names. + + VARIABLE DEFINITION + +Variables in this definiton provide the following mechanims: - +---------+ - |Function | -> Functions are defined with a reference, called with the same - +---------+ reference. A special stack called the "arguement stack", built - pre-call the are used as arguements. - When calling a function, the order must align with the parameter - types. + * Provide a distinguishable area of typed data - +---------------+ - |Class | - | +---------+ | -> Classes are defined as wrappers around functions. Special - | |Function | | functions such as the Constructor function and the Deconst - | +---------+ | ructor exist to initialze/clean up properties. - +---------------+ + * Provide a generic container around typed data, to allow for labeling -See section F + * Declare a set of fundemental datatypes, and methods to: + * Allocate the proper space of memory for the given data type, - A stack is used to keep a local group of values to manipulate. Values are -pushed on to the stack and are operated upon, and the values in the stack can -be assigned or re-assigned to variables. This is what is known as the "Current -operating stack". + * Deallocate the space of memory a variables data may take up, and - Bytecode Instructions + * Set in place a notion of ownership - Bytecode instructions are single byte, 3 (max) arguement calls to various -subroutines that manipulate various components of the running system. i.e. -(current operating stack, program counter, etc). The instruction types come in -the following forms: +For a given variable V, V defines the following attributes -* 0 arguement instruction: + V -> Ownership + V -> Type + V -> Pointer to typed space in memory - <opcode> +Each variable then can be handled as a generic container. -* 1 arguement instruction: +In the previous section, the notion of Namespace levels was introduced. Much +like how names are scoped, generic variable containers must communicate their +scope in terms of location within a given set of scopes. This is what is called +'Ownership'. In a given runtime, variable containers can exist in the following +structures: A stack instance, Bytecode arguements, and Namespaces - <opcode> <arg 0> +The concept of ownership differentiates variables existing on one or more of the +structures. This is set in place to prevent accidental deallocation of variable +containers that are not copied, but instead passed as references to these +structures. -* 2 arguement instruction: + BYTECODE SPEC - <opcode> <arg 0> <arg 1> +Bytecode is organised in the following manner: -* 3 arguement instruction: + <opcode> (arg 0... (arg n < 3 ) ) - <opcode> <arg 0> <arg 1> <arg 2> +Where the <opcode> is a single byte denoting which subroutine to call with the +following arguements when executed. Interpreting Bytecode Instructions @@ -150,8 +162,11 @@ arguements, which can be in the following forms: * Static (single byte) * Name (single word) - * Address (depending on runtime state) + * Address (depending on runtime state, usually a word) * Dynamic (size terminated by NULL, followed by (size)*bytes of data) + * i.e. FF FF 00 <0xFFFF bytes of data>, + 01 00 <0x1 bytes of data>, + 06 00 <0x6 bytes of data>, etc Below is the specification of all the instructions with a short description for each instruction, and instruction category: diff --git a/src/vm/inc/ns.h b/src/vm/inc/ns.h @@ -12,6 +12,7 @@ typedef unsigned int ns_addr; typedef struct ns_cont { + int level; ns_addr size; var_cont** names; struct ns_cont* next; @@ -29,8 +30,9 @@ ns_t* ns_init(ns_addr); /* Initialize namespace container of size * ns_addr - name limit + * int - level */ -ns_cont* ns_cont_init(ns_addr); +ns_cont* ns_cont_init(ns_addr, int); /* Cleans up memory */ @@ -86,7 +88,6 @@ void ns_set(ns_t*, int, ns_addr, var_cont*); void ns_cont_set(ns_cont*, var_cont*, ns_addr); /* Gets variable from address - * ns_t* - namespace instance * int - mux value [0] * ns_addr - Variable name diff --git a/src/vm/inc/proc.h b/src/vm/inc/proc.h @@ -45,6 +45,7 @@ var_cont* proc_callfun(rt_t*, var_cont*); * This function is used to support an interface to multithreaded instances */ void proc_decvar(rt_t*, b_type, int, ns_addr); + /* Set a variable subroutine * rt_t* - Runtime context * int - Scope @@ -59,6 +60,8 @@ void proc_setvar(rt_t*, int, ns_addr, var_cont*); * rt_t* - Runtime context * int - Scope * ns_addr - Name of variable + * + * This function is used to support an interface to multithreaded instances */ var_cont* proc_getvar(rt_t*, int, ns_addr); diff --git a/src/vm/inc/var.h b/src/vm/inc/var.h @@ -13,12 +13,6 @@ typedef unsigned int bc_addr; typedef unsigned int ns_addr; typedef enum { - NAMESPACE, - CONSTANT, - TEMPORARY -} var_state; - -typedef enum { VOID, // 0 ADDR, // 1 TYPE, // 2 @@ -36,7 +30,7 @@ typedef enum { } b_type; typedef struct var_cont { - var_state state; + int ownership; b_type type; void* data; } var_cont; @@ -84,7 +78,7 @@ typedef struct var_data_array { /* Initialze variable with type */ -var_cont* var_new(var_state, b_type); +var_cont* var_new(b_type); void* var_data_alloc_TYPE(b_type); void* var_data_alloc_PLIST(size_t); diff --git a/src/vm/src/bc.c b/src/vm/src/bc.c @@ -125,18 +125,22 @@ void process_args(bc_cont* ins) if (arg_types[x] == BTOI) { ins->varg[x] = raw_to_int(ins->sarg[x], 0, ins->args[x]); + ins->varg[x]->ownership = 0; } else if (arg_types[x] == BTOT) { ins->varg[x] = byte_to_type(ins->args[x][0]); + ins->varg[x]->ownership = 0; } else if (arg_types[x] == DTOL) { ins->varg[x] = raw_to_plist(ins->sarg[x], ins->args[x]); + ins->varg[x]->ownership = 0; } else if (arg_types[x] == DTOV) { ins->varg[x] = raw_to_var(ins->sarg[x], ins->args[x]); + ins->varg[x]->ownership = 0; } } } diff --git a/src/vm/src/ins_def.c b/src/vm/src/ins_def.c @@ -206,22 +206,25 @@ void _ins_def_CTV (rt_t* ctx, bc_cont* line) { int scope = var_data_get_G_INT(line->varg[0]); int name = var_data_get_G_INT(line->varg[1]); - var_cont* var = line->varg[2]; - proc_setvar(ctx, scope, name, var); + var_cont* new = var_data_cpy(line->varg[2]); + + proc_setvar(ctx, scope, name, new); pc_inc(ctx->pc, 1); } void _ins_def_CTS (rt_t* ctx, bc_cont* line) { - stk_push(ctx->stack, line->varg[0]); + var_cont* new = var_data_cpy(line->varg[0]); + + stk_push(ctx->stack, new); pc_inc(ctx->pc, 1); } void _ins_def_TYPEOF (rt_t* ctx, bc_cont* line) { var_cont* var = stk_at(ctx->stack, 0); - var_cont* new = var_new(TYPE, TEMPORARY); + var_cont* new = var_new(TYPE); var_data_type* data = var_data_alloc_TYPE(var->type); @@ -525,7 +528,7 @@ void _ins_def_DEFUN (rt_t* ctx, bc_cont* line) b_type* args = var_data_get_PLIST(line->varg[2]); size_t alen = line->sarg[2]; - var_cont* func = var_new(NAMESPACE, FUNC); + var_cont* func = var_new(FUNC); var_data_func* data = var_data_alloc_FUNC(type); diff --git a/src/vm/src/ns.c b/src/vm/src/ns.c @@ -6,8 +6,9 @@ /* Initialize namespace container of size * ns_addr - name limit + * int - Namespace level */ -ns_cont* ns_cont_init(ns_addr size) +ns_cont* ns_cont_init(ns_addr size, int level) { ns_cont* new = (ns_cont*)malloc(sizeof(ns_cont)); M_ASSERT(new); @@ -16,6 +17,7 @@ ns_cont* ns_cont_init(ns_addr size) M_ASSERT(new->names); new->size = size; + new->level = level; for (int i = 0; i < size; i++) { @@ -35,15 +37,15 @@ ns_t* ns_init(ns_addr size) ns_t* ns = (ns_t*)malloc(sizeof(ns_t)); M_ASSERT(ns); - ns->root = ns_cont_init(size); - ns->last = NULL; + ns->root = ns_cont_init(size, 0); + ns->last = ns->root; return ns; } -/* Cleans up memory, returns variable with label exclude +/* Cleans up memory, returns variable with label to_return */ -var_cont* ns_cont_del(ns_cont* container, ns_addr exclude) +var_cont* ns_cont_del(ns_cont* container, ns_addr to_return) { N_ASSERT(container, "ns_cont_del\n"); N_ASSERT(container->names, "ns_cont_del\n"); @@ -52,10 +54,24 @@ var_cont* ns_cont_del(ns_cont* container, ns_addr exclude) for (int i = 0; i < container->size; i++) { - if (container->names[i] != NULL && i != exclude) - var_del(container->names[i]); - else if (i == exclude) - rv = container->names[i]; + if (container->names[i] != NULL && i != to_return) + { + if (container->names[i]->ownership == container->level) + { + var_del(container->names[i]); + } + } + else if (i == to_return) + { + if (container->names[i] != NULL) + { + rv = container->names[i]; + if (rv->ownership == container->level) + { + rv->ownership = -1; + } + } + } } free(container->names); @@ -71,9 +87,18 @@ void ns_del(ns_t* ns) { N_ASSERT(ns, "ns_del\n"); + var_cont* var; if (ns->last != NULL) + { while (ns->last->next != NULL) - var_del(ns_pop(ns)); + { + var = ns_pop(ns); + if (var != NULL) + { + var_del(var); + } + } + } free(ns); } @@ -86,18 +111,10 @@ void ns_push(ns_t* ns, ns_addr size) { N_ASSERT(ns, "ns_push\n"); - ns_cont* new = ns_cont_init(size); + ns_cont* new = ns_cont_init(size, ns->last->level + 1); - if (ns->last == NULL) - { - new->next = ns->root; - ns->last = new; - } - else - { - new->next = ns->last; - ns->last = new; - } + new->next = ns->last; + ns->last = new; } /* Pops last namespace level @@ -142,13 +159,14 @@ void ns_dec(ns_t* ns, b_type type, int scope, ns_addr address) * ns_addr - Variable name */ -void ns_cont_dec(ns_cont* ns, b_type type, ns_addr address) +void ns_cont_dec(ns_cont* container, b_type type, ns_addr address) { - N_ASSERT(ns, "ns_cont_dec\n"); + N_ASSERT(container, "ns_cont_dec\n"); - SIZE_ASSERT( ns->size > address ); + SIZE_ASSERT( container->size > address ); - ns->names[ address ] = var_new(NAMESPACE, type); + container->names[ address ] = var_new(type); + container->names[ address ]->ownership = container->level; } /* Sets variable to value, at root or last namespace @@ -176,13 +194,21 @@ void ns_set(ns_t* ns, int scope, ns_addr address, var_cont* var) * var_cont* - Variable * ns_addr - Variable name */ -void ns_cont_set(ns_cont* ns, var_cont* var, ns_addr address) +void ns_cont_set(ns_cont* container, var_cont* var, ns_addr address) { - N_ASSERT(ns, "ns_cont_set\n"); + N_ASSERT(container, "ns_cont_set\n"); N_ASSERT(var, "ns_cont_set\n"); - SIZE_ASSERT( ns->size > address ); + SIZE_ASSERT( container->size > address ); + N_ASSERT(container->names[ address ], "Attempt to set an undeclared variable\n"); + + if (var->ownership < 0) + { + var->ownership = container->level; + } + + container->names[ address ]->ownership = var->ownership; - var_set(ns->names[ address ], var->data, var->type); + var_set(container->names[ address ], var->data, var->type); } /* Gets variable from address @@ -208,10 +234,10 @@ var_cont* ns_get(ns_t* ns, int scope, ns_addr address) * ns_t* - namespace instance * ns_addr - Variable name */ -var_cont* ns_cont_get(ns_cont* ns, ns_addr address) +var_cont* ns_cont_get(ns_cont* container, ns_addr address) { - N_ASSERT(ns, "ns_cont_get\n"); - SIZE_ASSERT( ns->size > address ); + N_ASSERT(container, "ns_cont_get\n"); + SIZE_ASSERT( container->size > address ); - return ns->names[ address ]; + return container->names[ address ]; } diff --git a/src/vm/src/stk.c b/src/vm/src/stk.c @@ -59,7 +59,7 @@ void stk_line_del(stk_line* stack) { if (stack->data[i] != NULL) { - if (stack->data[i]->state == TEMPORARY) + if (stack->data[i]->ownership < 0) var_del(stack->data[i]); } } diff --git a/src/vm/src/var.c b/src/vm/src/var.c @@ -81,14 +81,14 @@ void* var_data_alloc_G_STR(size_t size) return rv; } -var_cont* var_new(var_state state, b_type type) +var_cont* var_new(b_type type) { var_cont* new = (var_cont*)malloc(sizeof(var_cont)); M_ASSERT(new); - new->type = type; + new->ownership = -1; - new->state = state; + new->type = type; new->data = NULL; @@ -285,7 +285,7 @@ var_cont* var_data_cpy(var_cont* var) { N_ASSERT(var, "var_data_cpy\n"); - var_cont* rv = var_new(var->state, var->type); + var_cont* rv = var_new(var->type); if (var->type == G_INT) { @@ -318,7 +318,7 @@ var_cont* var_data_cpy(var_cont* var) */ var_cont* raw_to_int(int size, int start, byte_t* bytes) { - var_cont* rv = var_new(CONSTANT, G_INT); + var_cont* rv = var_new(G_INT); int i, data; @@ -338,7 +338,7 @@ var_cont* raw_to_int(int size, int start, byte_t* bytes) */ var_cont* byte_to_type(byte_t byte) { - var_cont* rv = var_new(CONSTANT, TYPE); + var_cont* rv = var_new(TYPE); var_set(rv, var_data_alloc_TYPE((b_type)byte), TYPE); @@ -352,7 +352,7 @@ var_cont* byte_to_type(byte_t byte) */ var_cont* raw_to_plist(int n, byte_t* bytes) { - var_cont* rv = var_new(CONSTANT, PLIST); + var_cont* rv = var_new(PLIST); var_set(rv, var_data_alloc_PLIST(n), PLIST); @@ -375,7 +375,7 @@ var_cont* raw_to_plist(int n, byte_t* bytes) */ var_cont* raw_to_str(int n, int offset, byte_t* bytes) { - var_cont* rv = var_new(CONSTANT, G_STR); + var_cont* rv = var_new(G_STR); var_data_str* data = var_data_alloc_G_STR(n); int i; for (i = offset; n > i; i++) diff --git a/src/vm/src/var_ops.c b/src/vm/src/var_ops.c @@ -8,7 +8,7 @@ var_cont* var_add_float(var_cont* A, var_cont* B) { - var_cont* var = var_new(NAMESPACE, G_FLOAT); + var_cont* var = var_new(G_FLOAT); double AV = var_data_get_G_FLOAT(A); double BV = var_data_get_G_FLOAT(B); @@ -22,7 +22,7 @@ var_cont* var_add_float(var_cont* A, var_cont* B) } var_cont* var_add_int(var_cont* A, var_cont* B) { - var_cont* var = var_new(NAMESPACE, G_INT); + var_cont* var = var_new(G_INT); int AV = var_data_get_G_INT(A); int BV = var_data_get_G_INT(B); @@ -55,7 +55,7 @@ var_cont* var_add(var_cont* A, var_cont* B) var_cont* var_sub_float(var_cont* A, var_cont* B) { - var_cont* var = var_new(NAMESPACE, G_FLOAT); + var_cont* var = var_new(G_FLOAT); double AV = var_data_get_G_FLOAT(A); double BV = var_data_get_G_FLOAT(B); @@ -69,7 +69,7 @@ var_cont* var_sub_float(var_cont* A, var_cont* B) } var_cont* var_sub_int(var_cont* A, var_cont* B) { - var_cont* var = var_new(NAMESPACE, G_INT); + var_cont* var = var_new(G_INT); int AV = var_data_get_G_INT(A); int BV = var_data_get_G_INT(B); @@ -102,7 +102,7 @@ var_cont* var_sub(var_cont* A, var_cont* B) var_cont* var_mult_float(var_cont* A, var_cont* B) { - var_cont* var = var_new(NAMESPACE, G_FLOAT); + var_cont* var = var_new(G_FLOAT); double AV = var_data_get_G_FLOAT(A); double BV = var_data_get_G_FLOAT(B); @@ -116,7 +116,7 @@ var_cont* var_mult_float(var_cont* A, var_cont* B) } var_cont* var_mult_int(var_cont* A, var_cont* B) { - var_cont* var = var_new(NAMESPACE, G_INT); + var_cont* var = var_new(G_INT); int AV = var_data_get_G_INT(A); int BV = var_data_get_G_INT(B); @@ -149,7 +149,7 @@ var_cont* var_mult(var_cont* A, var_cont* B) var_cont* var_div_float(var_cont* A, var_cont* B) { - var_cont* var = var_new(NAMESPACE, G_FLOAT); + var_cont* var = var_new(G_FLOAT); double AV = var_data_get_G_FLOAT(A); double BV = var_data_get_G_FLOAT(B); @@ -163,7 +163,7 @@ var_cont* var_div_float(var_cont* A, var_cont* B) } var_cont* var_div_int(var_cont* A, var_cont* B) { - var_cont* var = var_new(NAMESPACE, G_INT); + var_cont* var = var_new(G_INT); int AV = var_data_get_G_INT(A); int BV = var_data_get_G_INT(B); @@ -196,7 +196,7 @@ var_cont* var_div(var_cont* A, var_cont* B) var_cont* var_gthan_float(var_cont* A, var_cont* B) { - var_cont* var = var_new(NAMESPACE, G_INT); + var_cont* var = var_new(G_INT); double AV = var_data_get_G_FLOAT(A); double BV = var_data_get_G_FLOAT(B); @@ -210,7 +210,7 @@ var_cont* var_gthan_float(var_cont* A, var_cont* B) } var_cont* var_gthan_int(var_cont* A, var_cont* B) { - var_cont* var = var_new(NAMESPACE, G_INT); + var_cont* var = var_new(G_INT); int AV = var_data_get_G_INT(A); int BV = var_data_get_G_INT(B); @@ -244,7 +244,7 @@ var_cont* var_gthan(var_cont* A, var_cont* B) var_cont* var_lthan_float(var_cont* A, var_cont* B) { - var_cont* var = var_new(NAMESPACE, G_INT); + var_cont* var = var_new(G_INT); double AV = var_data_get_G_FLOAT(A); double BV = var_data_get_G_FLOAT(B); @@ -258,7 +258,7 @@ var_cont* var_lthan_float(var_cont* A, var_cont* B) } var_cont* var_lthan_int(var_cont* A, var_cont* B) { - var_cont* var = var_new(NAMESPACE, G_INT); + var_cont* var = var_new(G_INT); int AV = var_data_get_G_INT(A); int BV = var_data_get_G_INT(B); @@ -291,7 +291,7 @@ var_cont* var_lthan(var_cont* A, var_cont* B) var_cont* var_eq_float(var_cont* A, var_cont* B) { - var_cont* var = var_new(NAMESPACE, G_INT); + var_cont* var = var_new(G_INT); double AV = var_data_get_G_FLOAT(A); double BV = var_data_get_G_FLOAT(B); @@ -305,7 +305,7 @@ var_cont* var_eq_float(var_cont* A, var_cont* B) } var_cont* var_eq_int(var_cont* A, var_cont* B) { - var_cont* var = var_new(NAMESPACE, G_INT); + var_cont* var = var_new(G_INT); int AV = var_data_get_G_INT(A); int BV = var_data_get_G_INT(B); diff --git a/src/vm/tests/cases/bc/Makefile b/src/vm/tests/cases/bc/Makefile @@ -26,5 +26,5 @@ $(OUT): $(OBJ) $(CC) $(CFLAGS) -o $@ $^ clean: - rm $(SRC_DIR)/*.o + rm *.o rm $(OUT) diff --git a/src/vm/tests/cases/ns/expected_output b/src/vm/tests/cases/ns/expected_output @@ -1,3 +1,10 @@ -2 -5 -10 +testing: -1, 42 +testing_on_namespace: 0, 42 +testing_on_namespace: 1, 42 +testing_on_namespace: 0, 42 +testing_on_namespace: 0, 42 +Namespace info: 5, 2 +testing_on_namespace: 0, 42 +Namespace info: 5, 1 +testing_on_namespace: 0, 42 +Namespace info: 10, 0 diff --git a/src/vm/tests/cases/ns/test.c b/src/vm/tests/cases/ns/test.c @@ -6,19 +6,65 @@ int main( void ) { ns_t* test = ns_init(10); + var_cont* testing_on_namespace; + var_cont* testing = var_new(G_INT); + var_set(testing, var_data_alloc_G_INT(42), G_INT); + + printf("testing: %i, %i\n", testing->ownership, + var_data_get_G_INT(testing)); + + ns_dec(test, G_INT, 0, 2); + ns_set(test, 0, 2, testing); + + testing_on_namespace = ns_get(test, 0, 2); + printf("testing_on_namespace: %i, %i\n", testing_on_namespace->ownership, + var_data_get_G_INT(testing)); + ns_push(test, 5); - ns_push(test, 2); + var_cont* testing_2 = var_new(G_INT); + var_set(testing_2, var_data_alloc_G_INT(24), G_INT); - printf("%d\n", test->last->size); + ns_dec(test, G_INT, 0, 1); + ns_set(test, 0, 1, testing_2); + + testing_on_namespace = ns_get(test, 0, 1); + printf("testing_on_namespace: %i, %i\n", testing_on_namespace->ownership, + var_data_get_G_INT(testing)); + + ns_dec(test, G_INT, 0, 2); + ns_set(test, 0, 2, testing); + + testing_on_namespace = ns_get(test, 0, 2); + printf("testing_on_namespace: %i, %i\n", testing_on_namespace->ownership, + var_data_get_G_INT(testing)); + + ns_push(test, 5); + + ns_dec(test, G_INT, 0, 2); + ns_set(test, 0, 2, testing); + + testing_on_namespace = ns_get(test, 0, 2); + printf("testing_on_namespace: %i, %i\n", testing_on_namespace->ownership, + var_data_get_G_INT(testing)); + + printf("Namespace info: %d, %i\n", test->last->size, test->last->level); ns_pop(test); - - printf("%d\n", test->last->size); + + testing_on_namespace = ns_get(test, 0, 2); + printf("testing_on_namespace: %i, %i\n", testing_on_namespace->ownership, + var_data_get_G_INT(testing)); + + printf("Namespace info: %d, %i\n", test->last->size, test->last->level); ns_pop(test); - printf("%d\n", test->last->size); + testing_on_namespace = ns_get(test, 0, 2); + printf("testing_on_namespace: %i, %i\n", testing_on_namespace->ownership, + var_data_get_G_INT(testing)); + + printf("Namespace info: %d, %i\n", test->last->size, test->last->level); ns_del(test); diff --git a/src/vm/tests/cases/stk/test.c b/src/vm/tests/cases/stk/test.c @@ -16,11 +16,11 @@ void printstk(stk_t* stk) void playstk(stk_t* new) { - stk_push(new, var_new(TEMPORARY, VOID)); - stk_push(new, var_new(TEMPORARY, G_INT)); - stk_push(new, var_new(TEMPORARY, G_FLOAT)); - stk_push(new, var_new(TEMPORARY, G_CHAR)); - stk_push(new, var_new(TEMPORARY, G_STR)); + stk_push(new, var_new(VOID)); + stk_push(new, var_new(G_INT)); + stk_push(new, var_new(G_FLOAT)); + stk_push(new, var_new(G_CHAR)); + stk_push(new, var_new(G_STR)); printf("init: \n"); printstk(new); diff --git a/src/vm/tests/tools/test.sh b/src/vm/tests/tools/test.sh @@ -10,7 +10,7 @@ do total=$((total + 1)) cd $i - make + make &> /dev/null printf "\nTESTCASE: $(basename $PWD)\n"