Changeset 168c2a5ec263be75f797e77bdf8a7e3011663c1a
- Timestamp:
- 04/19/10 17:59:02 (2 years ago)
- Parents:
- 8ff7a1b2cf2221d84f8514c3f63e025ca2cb4144
- Children:
- 11b18d6c8033bdf184ee5924e576f0de3e5861aa
- git-committer:
- Philip Herron <redbrain@omicron.(none)> / 2010-04-19T17:59:02Z+0100
- Files:
-
- 13 modified
-
include/crules/objects.h (modified) (1 diff)
-
include/crules/runtime.h (modified) (2 diffs)
-
src/bb_builtin.c (modified) (1 diff)
-
src/builtin_hash_table.c (modified) (11 diffs)
-
src/builtin_stack.c (modified) (5 diffs)
-
src/obj_class.c (modified) (3 diffs)
-
src/obj_list.c (modified) (2 diffs)
-
src/obj_number.c (modified) (1 diff)
-
src/obj_string.c (modified) (2 diffs)
-
src/rr_context.c (modified) (21 diffs)
-
src/rr_runtime.c (modified) (43 diffs)
-
src/ss_lexical.l (modified) (1 diff)
-
src/ss_parser.y (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
include/crules/objects.h
r56c74af r168c2a5 101 101 crl_context_table * ); 102 102 103 extern crl_symbol_obj * crl_obj_list_print( crl_symbol_obj * , crl_symbol_obj * , 104 crl_context_table * ); 105 106 extern crl_symbol_obj * crl_obj_list_delete( crl_symbol_obj * , crl_symbol_obj * , 107 crl_context_table * ); 108 109 // -------------------------------------------------------------------------- 110 111 extern crl_symbol_obj * crl_obj_string_init( crl_symbol_obj * , crl_symbol_obj * , 112 crl_context_table * ); 113 114 extern crl_symbol_obj * crl_obj_string_push( crl_symbol_obj * , crl_symbol_obj * , 115 crl_context_table * ); 116 117 extern crl_symbol_obj * crl_obj_string_pop( crl_symbol_obj * , crl_symbol_obj * , 118 crl_context_table * ); 119 120 extern crl_symbol_obj * crl_obj_string_remove( crl_symbol_obj * , crl_symbol_obj * , 121 crl_context_table * ); 122 123 extern crl_symbol_obj * crl_obj_string_append( crl_symbol_obj * , crl_symbol_obj * , 124 crl_context_table * ); 125 126 extern crl_symbol_obj * crl_obj_string_length( crl_symbol_obj * , crl_symbol_obj * , 127 crl_context_table * ); 128 129 extern crl_symbol_obj * crl_obj_string_print( crl_symbol_obj * , crl_symbol_obj * , 130 crl_context_table * ); 131 132 extern crl_symbol_obj * crl_obj_string_delete( crl_symbol_obj * , crl_symbol_obj * , 133 crl_context_table * ); 134 103 135 #endif //__OBJECTS_H_ -
include/crules/runtime.h
r56c74af r168c2a5 32 32 // -------------------------------------------------------------------------- 33 33 34 extern bool crl_runtime_keyword_delete( crl_symbol_obj * , crl_context_table * );35 36 34 extern crl_symbol_obj * crl_runtime_loop_for( crl_symbol_obj * , crl_context_table * ); 37 35 … … 42 40 extern crl_symbol_obj * crl_runtime_eval_key_break( crl_context_table * ); 43 41 44 extern bool crl_runtime_list_format( crl_table_t * , crl_context_table * );45 46 42 extern bool crl_runtime_assignment( crl_symbol_obj *,crl_context_table * ); 47 48 extern bool crl_runtime_list_print( crl_table_t * , crl_context_table *, FILE * );49 43 50 44 extern bool crl_runtime_eval_bool_item( crl_symbol_obj * ); -
src/bb_builtin.c
r56c74af r168c2a5 61 61 struct crl_builtin_function_def_t builtin_module_function_table[] = { 62 62 { "print", PARAM_VARADIC, &crl_builtin_call_print }, 63 { NULL, 0 NULL },63 { NULL, 0, NULL }, 64 64 }; -
src/builtin_hash_table.c
r1a9fc2c r168c2a5 30 30 #include <string.h> 31 31 32 #include <unistd.h>33 #include <sys/types.h>34 35 32 #include <crules/crules.h> 36 33 #include <crules/opcodes.h> … … 45 42 #define threshold_alloc(x) (((x)+16)*3/2) 46 43 47 /* Declare the tables */ 48 crl_table *crl_functors= NULL, *crl_rules= NULL; 49 //The runtime table stack! 50 crl_context_table *crl_runtime_ctx_table; 51 52 static void crl_hash_grow_table( crl_table * ); 44 static void crl_dd_hash_grow_table( crl_table_t * ); 53 45 54 46 /** … … 61 53 * a Digest.., but should avoid conflicts better 62 54 **/ 63 crl_hash_t crl_ hash_hash( const char *string )55 crl_hash_t crl_dd_hash_hash( const char *string ) 64 56 { 65 57 crl_hash_t hash= 0x811C9DC5; … … 75 67 } 76 68 77 crl_table_entry *78 crl_ hash_lookup_table( crl_table*tbl, crl_hash_t h )69 crl_table_entry * 70 crl_dd_hash_lookup_table( crl_table_t *tbl, crl_hash_t h ) 79 71 { 80 72 crl_table_entry* retval; … … 102 94 103 95 crl_symbol_obj** 104 crl_ hash_insert( crl_hash_t h, crl_symbol_obj* obj,105 crl_table*tbl )96 crl_dd_hash_insert( crl_hash_t h, crl_symbol_obj* obj, 97 crl_table_t *tbl ) 106 98 { 107 99 crl_symbol_obj **retval; 108 100 if( tbl->nr >= tbl->size ) 109 crl_ hash_grow_table( tbl );101 crl_dd_hash_grow_table( tbl ); 110 102 111 crl_table_entry *entry= crl_ hash_lookup_table( tbl, h );103 crl_table_entry *entry= crl_dd_hash_lookup_table( tbl, h ); 112 104 if( entry->symbol ) 113 105 retval= &( entry->symbol ); … … 122 114 123 115 static 124 void crl_ hash_grow_table( crl_table* tbl )116 void crl_dd_hash_grow_table( crl_table_t * tbl ) 125 117 { 126 118 unsigned int prev_size= tbl->size, size= 0, i= 0; … … 141 133 142 134 if( s ) 143 crl_ hash_insert( h, s, tbl );135 crl_dd_hash_insert( h, s, tbl ); 144 136 } 145 137 if( prev_array ) … … 147 139 } 148 140 149 void crl_ hash_init_table( crl_table** tbl )141 void crl_dd_hash_init_table( crl_table_t ** tbl ) 150 142 { 151 143 if( tbl ) 152 144 { 153 crl_table *tb= *tbl;145 crl_table_t *tb= *tbl; 154 146 tb->size= 0; tb->nr= 0; 155 147 tb->array= NULL; … … 161 153 } 162 154 163 crl_table * crl_hash_clone_table( crl_table** table )155 crl_table_t * crl_dd_hash_clone_table( crl_table_t ** table ) 164 156 { 165 crl_table * retval = NULL;157 crl_table_t * retval = NULL; 166 158 if( table ) 167 159 { 168 retval = (crl_table *)169 crl_malloc( sizeof(crl_table ) );170 crl_ hash_init_table( &retval );160 retval = (crl_table_t*) 161 crl_malloc( sizeof(crl_table_t) ); 162 crl_dd_hash_init_table( &retval ); 171 163 172 164 crl_table_entry* array = (crl_table_entry*) … … 184 176 185 177 if( s ) 186 crl_ hash_insert( h, s, retval );178 crl_dd_hash_insert( h, s, retval ); 187 179 } 188 180 … … 196 188 return retval; 197 189 } 198 199 /**200 * Initilizes the memory tables and different201 * symbol tables202 **/203 bool crl_init_tables( void )204 {205 crl_debug("Initilizing...\n");206 207 crl_branch_context *ctx= (crl_branch_context*)208 crl_malloc(sizeof( crl_branch_context ));209 crl_context_init_context( &ctx );210 211 crl_runtime_ctx_table= (crl_context_table*)212 crl_malloc(sizeof( crl_context_table ));213 crl_context_init_table( &crl_runtime_ctx_table );214 crl_context_push( ctx, crl_runtime_ctx_table );215 216 crl_debug("System tables initilized!\n");217 218 crl_builtin_init( crl_runtime_ctx_table );219 220 pid_t pid;221 /* get the process id */222 if( (pid = getpid( ) ) < 0 )223 {224 crl_warning( "unable to get program pid" );225 }226 else227 {228 crl_debug( "started with pid <%d>!\n", pid );229 }230 return true;231 } -
src/builtin_stack.c
r56c74af r168c2a5 42 42 #define threshold_alloc(x) (((x)+16)*3/2) 43 43 44 void crl_dd_stack_push( crl_stack *stack, void *obj )44 void crl_dd_stack_push( crl_stack_t *stack, void *obj ) 45 45 { 46 46 unsigned int idx= stack->length, tsize= 0; … … 64 64 65 65 inline 66 void* crl_dd_stack_pop( crl_stack *stack )66 void* crl_dd_stack_pop( crl_stack_t *stack ) 67 67 { 68 68 void *obj; … … 77 77 78 78 inline 79 void crl_dd_stack_init( crl_stack **stack )79 void crl_dd_stack_init( crl_stack_t **stack ) 80 80 { 81 81 if( stack ) … … 96 96 **/ 97 97 inline 98 void crl_dd_stack_free( crl_stack *stack )98 void crl_dd_stack_free( crl_stack_t *stack ) 99 99 { 100 100 if( stack ) … … 107 107 108 108 inline 109 unsigned int crl_dd_stack_get_size( crl_stack *stack )109 unsigned int crl_dd_stack_get_size( crl_stack_t *stack ) 110 110 { 111 111 unsigned int retval; -
src/obj_class.c
r4c5f389 r168c2a5 51 51 crl_context_table *object_ctx = (crl_context_table*) 52 52 crl_malloc( sizeof(crl_context_table) ); 53 crl_ context_init_table( &object_ctx );54 crl_ context_push( (obj->context), object_ctx );53 crl_rr_context_init_table( &object_ctx ); 54 crl_rr_context_push( (obj->context), object_ctx ); 55 55 56 crl_symbol_obj** functor = crl_ context_lookup_function( ident, &object_ctx );56 crl_symbol_obj** functor = crl_rr_context_lookup_function( ident, &object_ctx ); 57 57 if( functor ) 58 58 { … … 66 66 } 67 67 68 crl_ context_pop( object_ctx );68 crl_rr_context_pop( object_ctx ); 69 69 crl_garbage_free_context_table( &object_ctx ); 70 70 … … 78 78 crl_branch_context * obj_ctx = obj->context; 79 79 80 crl_table_entry *ent = crl_hash_lookup_table( obj_ctx->symbol_table, crl_hash_hash(ident) ); 80 crl_table_entry *ent = crl_dd_hash_lookup_table( obj_ctx->symbol_table, 81 crl_dd_hash_hash( ident ) ); 81 82 if( ent ) 82 83 { -
src/obj_list.c
re4fe6e3 r168c2a5 1 1 /** 2 * obj ect_list.c -> Part of Crules Programming language2 * obj_list.c -> Part of Crules Programming language 3 3 * 4 4 * Crules is the legal property of its developers. Please refer to the … … 104 104 105 105 struct crl_builtin_function_def_t list_module_function_table[] = { 106 { "__init__", 1, &crl_obj_list_init } 106 { "__init__", 1, &crl_obj_list_init }, 107 107 { "push", 1, &crl_obj_list_push }, 108 108 { "pop", 0, &crl_obj_list_pop }, -
src/obj_number.c
r6ff5ad1 r168c2a5 41 41 crl_symbol_obj* 42 42 crl_obj_number_to_string( crl_symbol_obj * caller, 43 crl_symbol_obj * self, 43 44 crl_context_table * context ) 44 45 { -
src/obj_string.c
r8cc1949 r168c2a5 1 1 /** 2 * string_object.c -> Part of Crules Programming language2 * obj_string.c -> Part of Crules Programming language 3 3 * 4 4 * Crules is the legal property of its developers. Please refer to the … … 19 19 **/ 20 20 21 #ifdef HAVE_CONFIG_H 22 # include "config.h" 23 #else 24 # define CMAKE 1 25 # include "config.h.cmake" 26 #endif 27 28 #include <stdio.h> 29 #include <stdlib.h> 30 #include <string.h> 31 32 #include <crules/crules.h> 33 #include <crules/opcodes.h> 34 #include <crules/symbols.h> 35 #include <crules/objects.h> 36 #include <crules/backend.h> 37 #include <crules/runtime.h> 38 #include <crules/garbage.h> 39 #include <crules/operators.h> 40 41 crl_symbol_obj * 42 crl_obj_string_init( crl_symbol_obj * caller, 43 crl_symbol_obj * self, 44 crl_context_table * context ) 45 { 46 return NULL; 47 } 48 49 crl_symbol_obj * 50 crl_obj_string_push( crl_symbol_obj * caller, 51 crl_symbol_obj * self, 52 crl_context_table * context ) 53 { 54 return NULL; 55 } 56 57 crl_symbol_obj * 58 crl_obj_string_pop( crl_symbol_obj * caller, 59 crl_symbol_obj * self, 60 crl_context_table * context ) 61 { 62 return NULL; 63 } 64 65 crl_symbol_obj * 66 crl_obj_string_remove( crl_symbol_obj * caller, 67 crl_symbol_obj * self, 68 crl_context_table * context ) 69 { 70 return NULL; 71 } 72 73 crl_symbol_obj * 74 crl_obj_string_append( crl_symbol_obj * caller, 75 crl_symbol_obj * self, 76 crl_context_table * context ) 77 { 78 return NULL; 79 } 80 81 crl_symbol_obj * 82 crl_obj_string_length( crl_symbol_obj * caller, 83 crl_symbol_obj * self, 84 crl_context_table * context ) 85 { 86 return NULL; 87 } 88 89 crl_symbol_obj * 90 crl_obj_string_print( crl_symbol_obj * caller, 91 crl_symbol_obj * self, 92 crl_context_table * context ) 93 { 94 return NULL; 95 } 96 97 crl_symbol_obj * 98 crl_obj_string_delete( crl_symbol_obj * caller, 99 crl_symbol_obj * self, 100 crl_context_table * context ) 101 { 102 return NULL; 103 } 104 105 struct crl_builtin_function_def_t string_module_function_table[] = { 106 { "__init__", 1, &crl_obj_string_init }, 107 { "push", 1, &crl_obj_string_push }, 108 { "pop", 0, &crl_obj_string_pop }, 109 { "remove", 1, &crl_obj_string_remove }, 110 { "append", 1, &crl_obj_string_append }, 111 { "length", 0, &crl_obj_string_length }, 112 { "print", 0, &crl_obj_string_print }, 113 { "delete", 0, &crl_obj_string_delete }, 114 { NULL, 0, NULL }, 115 }; -
src/rr_context.c
r97bcdcf r168c2a5 29 29 #include <stdlib.h> 30 30 #include <string.h> 31 32 #include <unistd.h> 33 #include <sys/types.h> 31 34 32 35 #include <crules/crules.h> … … 39 42 #include <crules/operators.h> 40 43 44 //The runtime table stack! 45 crl_context_table *crl_runtime_ctx_table; 41 46 //threshold size alloctor to scale up faster 42 47 #define threshold_alloc(x) (((x)+16)*3/2) 43 48 44 void crl_ context_push( crl_branch_context * ctx,49 void crl_rr_context_push( crl_branch_context * ctx, 45 50 crl_context_table * stack ) 46 51 { … … 65 70 66 71 crl_branch_context * 67 crl_ context_pop( crl_context_table * stack )72 crl_rr_context_pop( crl_context_table * stack ) 68 73 { 69 74 crl_branch_context *ctx; … … 81 86 } 82 87 83 void crl_ context_init_table( crl_context_table ** table )88 void crl_rr_context_init_table( crl_context_table ** table ) 84 89 { 85 90 if( table ) … … 97 102 98 103 unsigned int 99 crl_ context_get_table_size( crl_context_table * stack )104 crl_rr_context_get_table_size( crl_context_table * stack ) 100 105 { 101 106 unsigned int retval; … … 109 114 110 115 crl_table_entry * 111 crl_ context_lookup_symbol( const char* identifier,112 crl_context_table ** stack )116 crl_rr_context_lookup_symbol( const char* identifier, 117 crl_context_table ** stack ) 113 118 { 114 119 crl_table_entry *retval; 115 120 if( stack ) 116 121 { 117 crl_hash_t h= crl_ hash_hash( identifier );122 crl_hash_t h= crl_dd_hash_hash( identifier ); 118 123 crl_debug("looking up symbol '%s' - hash 0x%X\n", 119 124 identifier, h); 120 125 121 signed int idx= crl_ context_get_table_size( (*stack) );126 signed int idx= crl_rr_context_get_table_size( (*stack) ); 122 127 crl_debug("stack frame size :: '%i'!\n", idx ); 123 128 crl_branch_context* ctx= NULL; idx--; … … 130 135 131 136 if( ctx->symbol_table->array ) 132 ent= crl_ hash_lookup_table( ctx->symbol_table, h );137 ent= crl_dd_hash_lookup_table( ctx->symbol_table, h ); 133 138 134 139 if( ent ) … … 154 159 155 160 crl_symbol_obj** 156 crl_ context_lookup_function( const char* identifier,157 crl_context_table ** stack )161 crl_rr_context_lookup_function( const char* identifier, 162 crl_context_table ** stack ) 158 163 { 159 164 crl_symbol_obj **retval = NULL; 160 165 if( stack ) 161 166 { 162 crl_hash_t h= crl_ hash_hash( identifier );167 crl_hash_t h= crl_dd_hash_hash( identifier ); 163 168 crl_debug( "looking up function '%s' - hash 0x%X\n", 164 169 identifier, h ); 165 170 166 signed int idx= crl_ context_get_table_size( (*stack) );171 signed int idx= crl_rr_context_get_table_size( (*stack) ); 167 172 crl_debug("stack frame size :: '%i'!\n", idx ); 168 173 crl_branch_context* ctx= NULL; idx--; … … 175 180 176 181 if( ctx->function_table->array ) 177 ent= crl_ hash_lookup_table( ctx->function_table, h );182 ent= crl_dd_hash_lookup_table( ctx->function_table, h ); 178 183 179 184 if( ent ) … … 199 204 200 205 crl_obj_state_t ** 201 crl_ context_lookup_object( const char* identifier,206 crl_rr_context_lookup_object( const char* identifier, 202 207 crl_context_table ** stack ) 203 208 { … … 205 210 if( stack ) 206 211 { 207 crl_hash_t h= crl_ hash_hash( identifier );212 crl_hash_t h= crl_dd_hash_hash( identifier ); 208 213 crl_debug( "looking up function '%s' - hash 0x%X\n", 209 214 identifier, h ); 210 215 211 signed int idx= crl_ context_get_table_size( (*stack) );216 signed int idx= crl_rr_context_get_table_size( (*stack) ); 212 217 crl_debug("stack frame size :: '%i'!\n", idx ); 213 218 crl_branch_context* ctx= NULL; idx--; … … 220 225 221 226 if( ctx->object_table->array ) 222 ent= crl_ hash_lookup_table( ctx->object_table, h );227 ent= crl_dd_hash_lookup_table( ctx->object_table, h ); 223 228 224 229 if( ent ) … … 249 254 { 250 255 bool retval = true; 251 crl_symbol_obj** f = crl_ context_lookup_function( functor->identifier, context );256 crl_symbol_obj** f = crl_rr_context_lookup_function( functor->identifier, context ); 252 257 if( !f ) 253 258 { 254 259 // not defined! 255 crl_symbol_obj **s= crl_ hash_insert( crl_hash_hash( functor->identifier ),256 functor, ((*context)->curr->function_table) );260 crl_symbol_obj **s= crl_dd_hash_insert( crl_dd_hash_hash( functor->identifier ), 261 functor, ((*context)->curr->function_table) ); 257 262 // this shouldn't happen! 258 263 if( s ) … … 277 282 278 283 crl_assert( object->op_a_t == TYPE_STRING ); 279 crl_obj_state_t ** o = crl_ context_lookup_object( object->op_a.string,280 context );284 crl_obj_state_t ** o = crl_rr_context_lookup_object( object->op_a.string, 285 context ); 281 286 bool retval = true; 282 287 if( !o ) … … 285 290 crl_obj_state_t *obj_state = (crl_obj_state_t*) 286 291 crl_malloc( sizeof(crl_obj_state_t) ); 292 287 293 obj_state->identifier = crl_strdup( object->op_a.string ); 288 294 obj_state->state = CLASS_UNINIT; … … 291 297 crl_malloc( sizeof(crl_branch_context) ); 292 298 293 crl_ context_init_context( &object_ctx );294 crl_ context_push( object_ctx, (*context) );299 crl_rr_context_init( &object_ctx ); 300 crl_rr_context_push( object_ctx, (*context) ); 295 301 296 302 if( !(retval = crl_runtime_exec_toplevel( object->op_b.symbol_table, (*context) )) ) … … 298 304 299 305 crl_debug("poping object stack frame!\n"); 300 obj_state->context = crl_ context_pop( (*context) );306 obj_state->context = crl_rr_context_pop( (*context) ); 301 307 302 308 crl_symbol_obj *object_def; … … 305 311 object_def->op_a.object_state = obj_state; 306 312 307 crl_symbol_obj **s= crl_ hash_insert( crl_hash_hash( object->op_a.string ),313 crl_symbol_obj **s= crl_dd_hash_insert( crl_dd_hash_hash( object->op_a.string ), 308 314 object_def, ((*context)->curr->object_table) ); 309 315 // this shouldn't happen! … … 330 336 (*branch)->loop_ctx= false; 331 337 332 (*branch)->symbol_table= (crl_table *)333 crl_malloc( sizeof( crl_table ) );334 (*branch)->function_table= (crl_table *)335 crl_malloc( sizeof( crl_table ) );336 (*branch)->object_table= (crl_table *)337 crl_malloc( sizeof( crl_table ) );338 339 crl_ hash_init_table( &((*branch)->symbol_table) );340 crl_ hash_init_table( &((*branch)->function_table) );341 crl_ hash_init_table( &((*branch)->object_table) );338 (*branch)->symbol_table= (crl_table_t *) 339 crl_malloc( sizeof( crl_table_t ) ); 340 (*branch)->function_table= (crl_table_t *) 341 crl_malloc( sizeof( crl_table_t ) ); 342 (*branch)->object_table= (crl_table_t *) 343 crl_malloc( sizeof( crl_table_t ) ); 344 345 crl_dd_hash_init_table( &((*branch)->symbol_table) ); 346 crl_dd_hash_init_table( &((*branch)->function_table) ); 347 crl_dd_hash_init_table( &((*branch)->object_table) ); 342 348 } 343 349 else … … 373 379 retval->loop_ctx = (*ctx)->loop_ctx; 374 380 375 retval->symbol_table = crl_ hash_clone_table( &((*ctx)->symbol_table) );376 retval->function_table = crl_ hash_clone_table( &((*ctx)->function_table) );377 retval->object_table = crl_ hash_clone_table( &((*ctx)->object_table) );381 retval->symbol_table = crl_dd_hash_clone_table( &((*ctx)->symbol_table) ); 382 retval->function_table = crl_dd_hash_clone_table( &((*ctx)->function_table) ); 383 retval->object_table = crl_dd_hash_clone_table( &((*ctx)->object_table) ); 378 384 } 379 385 return retval; … … 396 402 return retval; 397 403 } 404 405 /** 406 * Initilizes the memory tables and different 407 * symbol tables 408 **/ 409 bool crl_init_tables( void ) 410 { 411 crl_debug("Initilizing...\n"); 412 413 crl_branch_context *ctx= (crl_branch_context*) 414 crl_malloc(sizeof( crl_branch_context )); 415 crl_context_init_context( &ctx ); 416 417 crl_runtime_ctx_table= (crl_context_table*) 418 crl_malloc(sizeof( crl_context_table )); 419 crl_rr_context_init_table( &crl_runtime_ctx_table ); 420 crl_rr_context_push( ctx, crl_runtime_ctx_table ); 421 422 crl_debug("System tables initilized!\n"); 423 424 /* Init object types and modules! */ 425 // .... 426 427 pid_t pid; 428 /* get the process id */ 429 if( (pid = getpid( ) ) < 0 ) 430 { 431 crl_warning( "unable to get program pid" ); 432 } 433 else 434 { 435 crl_debug( "started with pid <%d>!\n", pid ); 436 } 437 return true; 438 } -
src/rr_runtime.c
r97bcdcf r168c2a5 1 #/**1 /** 2 2 * rr_runtime.c -> Part of Crules Programming language 3 3 * … … 63 63 64 64 /** 65 * @param list is the list to be checked if it is valid or not!66 *67 * @param context holds the stack tables of symbols68 *69 * @returns true or false depending if the list symbols are,70 * valid and within scope of the context71 **/72 bool crl_runtime_list_format( crl_table *list,73 crl_context_table *context )74 {75 crl_debug("formating list...\n");76 unsigned int i= 0; bool chk= true;77 crl_table_entry* ei= NULL;78 79 crl_symbol_obj *t= NULL;80 for( ; i<list->nr; ++i )81 {82 ei= crl_list_access_idx( i, &list );83 t= crl_runtime_evaluate_expression( ei->symbol, context );84 crl_garbage_mark_obj( &(ei->symbol) );85 ei->symbol= t;86 }87 return chk;88 }89 90 /**91 65 * @param sym is the symbol representing the whole assignment 92 66 * should be a symbol of type OP_ASSIGN with operands A and B of … … 113 87 { 114 88 crl_assert( accessor->op_a_t == TYPE_STRING ); 115 var= crl_ context_lookup_symbol( accessor->op_a.string, &context );89 var= crl_rr_context_lookup_symbol( accessor->op_a.string, &context ); 116 90 117 91 if( !var ) 118 92 { 119 93 crl_symbol_obj *item= sym->op_b.symbol_table; 120 crl_symbol_obj **s= crl_ hash_insert( crl_hash_hash( accessor->op_a.string ),94 crl_symbol_obj **s= crl_dd_hash_insert( crl_dd_hash_hash( accessor->op_a.string ), 121 95 item, context->curr->symbol_table ); 122 96 exec= true; … … 141 115 } 142 116 } 143 else if( accessor->type == SYMBOL_INDEX_REF )144 {145 crl_assert( accessor->op_a_t == TYPE_STRING );146 crl_assert( accessor->op_b_t == TYPE_SYMBOL );147 148 var= crl_context_lookup_symbol( accessor->op_a.string, &context );149 if( var )150 {151 crl_symbol_obj* ev= crl_runtime_evaluate_expression( accessor->op_b.symbol_table,152 context );153 if( var->symbol->op_a_t == TYPE_LIST )154 {155 if( ev->op_a_t == TYPE_INTEGER )156 {157 crl_table_entry *e= crl_list_access_idx( ev->op_a.integer,158 &(var->symbol->op_a.list_table) );159 if( !e )160 {161 crl_fatal("symbol list <%s> item at index <%i> is undefined!\n",162 accessor->op_a.string, ev->op_a.integer );163 }164 165 crl_symbol_obj *p= e->symbol;166 crl_symbol_obj *item= sym->op_b.symbol_table;167 if( !(e->symbol= item ) )168 {169 exec= false;170 crl_error("error assigning the symbol!\n");171 }172 crl_garbage_mark_obj( &p );173 }174 else175 {176 crl_error("Invalid index accessor type <0x%x>!\n",177 ev->op_a_t ); exec= false;178 }179 }180 else if( var->symbol->op_a_t == TYPE_STRING )181 {182 crl_fatal("string index access not implemented yet!\n");183 }184 else185 {186 crl_error("Invalid symbol to access index <0x%X>!\n",187 var->symbol->op_a_t );188 }189 crl_garbage_mark_obj( &ev );190 }191 else192 {193 crl_error("undefined symbol <%s>!\n",194 accessor->op_a.string ); exec= false;195 }196 }197 117 else 198 118 { … … 206 126 } 207 127 208 /**209 * @param list is the list to be printed210 * @param context is the symbol table of symbols211 * @param fd the file-descriptor to print to212 *213 * @return returns true or false depending if the operation was valid or not!214 **/215 bool crl_runtime_list_print( crl_table* list,216 crl_context_table *context,217 FILE * fd )218 {219 bool retval= false;220 if( list )221 {222 unsigned int i=0, sz= list->nr;223 fprintf(fd, "[ ");224 for ( ; i<sz; ++i )225 {226 crl_table_entry *e= crl_list_access_idx( i, &list );227 if( e )228 {229 crl_symbol_obj *sym= e->symbol;230 crl_runtime_object_print( sym, context, fd, false );231 232 if( i < sz-1 )233 fprintf(fd, ", ");234 }235 else236 crl_fatal("Undefined list symbol at index %i\n", i);237 }238 fprintf( fd, " ] " );239 retval= true;240 }241 else242 {243 crl_error("null list in print_list!\n");244 retval= false;245 }246 return retval;247 }248 249 128 crl_symbol_obj* 250 129 crl_runtime_eval_key_break( crl_context_table *ctx ) … … 252 131 crl_symbol_obj* retval= NULL; 253 132 //look for the loop return address! 254 signed int len= crl_ context_get_table_size( ctx );133 signed int len= crl_rr_context_get_table_size( ctx ); 255 134 crl_branch_context *c; len--; bool f= false; 256 135 … … 278 157 crl_symbol_obj* retval= NULL; 279 158 //look for the loop return address! 280 signed int len= crl_ context_get_table_size( ctx );159 signed int len= crl_rr_context_get_table_size( ctx ); 281 160 crl_branch_context *c; len--; bool f= false; 282 161 … … 311 190 crl_branch_context *loop_ctx= (crl_branch_context*) 312 191 crl_malloc(sizeof( crl_branch_context )); 313 crl_ context_init_context( &loop_ctx );192 crl_rr_context_init( &loop_ctx ); 314 193 loop_ctx->loop_ctx= true; 315 crl_ context_push( loop_ctx, context );194 crl_rr_context_push( loop_ctx, context ); 316 195 317 196 crl_symbol_obj *f_ctx = sym->op_a.symbol_table; … … 379 258 380 259 crl_debug("freeing local stack frame!\n"); 381 crl_branch_context* ctx= crl_ context_pop( context );260 crl_branch_context* ctx= crl_rr_context_pop( context ); 382 261 crl_garbage_free_context_branch( &ctx ); 383 262 crl_debug("done freeing stack frame!\n"); … … 403 282 crl_branch_context *branch_ctx= (crl_branch_context*) 404 283 crl_malloc(sizeof( crl_branch_context )); 405 crl_ context_init_context( &branch_ctx );284 crl_rr_context_init( &branch_ctx ); 406 285 branch_ctx->loop_ctx= true; 407 crl_ context_push( branch_ctx, context );286 crl_rr_context_push( branch_ctx, context ); 408 287 409 288 while( i_eval == true ) … … 458 337 459 338 crl_debug("freeing local stack frame!\n"); 460 crl_branch_context* ctx= crl_ context_pop( context );339 crl_branch_context* ctx= crl_rr_context_pop( context ); 461 340 crl_garbage_free_context_branch( &ctx ); 462 341 crl_debug("done freeing stack frame!\n"); … … 473 352 crl_context_table *context ) 474 353 { 475 crl_assert( sym->type == SYMBOL_INDEX_REF ); 476 crl_assert( sym->op_a_t == TYPE_STRING ); 477 crl_assert( sym->op_b_t == TYPE_SYMBOL ); 478 crl_symbol_obj *retval = NULL; 479 480 crl_table_entry* var= crl_context_lookup_symbol( sym->op_a.string, &context ); 481 if( var ) 482 { 483 if( var->symbol->op_a_t == TYPE_LIST ) 484 { 485 crl_symbol_obj *o= var->symbol; 486 crl_symbol_obj *eval= crl_runtime_evaluate_expression( sym->op_b.symbol_table, 487 context ); 488 if( eval ) 489 { 490 if( eval->op_a_t == TYPE_INTEGER ) 491 { 492 crl_table_entry* e= crl_list_access_idx( eval->op_a.integer, 493 &(o->op_a.list_table) ); 494 if( e ) 495 retval= e->symbol; 496 else 497 { 498 crl_fatal("symbol list <%s> with item at index <%i> is undefined!\n", 499 sym->op_a.string, eval->op_a.integer ); 500 } 501 } 502 else 503 { 504 crl_error("invalid index object accessor type <0x%X>!\n", 505 eval->op_a_t ); 506 retval= NULL; 507 } 508 } 509 else 510 { 511 crl_error("index expression evaluation error!\n"); 512 retval= NULL; 513 } 514 } 515 else if( var->symbol->op_a_t == TYPE_STRING ) 516 { 517 retval= NULL; 518 } 519 else 520 { 521 crl_error("invalid object type <0x%x> for index access!\n", 522 var->symbol->op_a_t ); 523 retval= NULL; 524 } 525 } 526 else 527 { 528 crl_error("symbol object <%s> is undefined!\n", sym->op_a.string ); 529 retval= NULL; 530 } 531 return retval; 354 crl_fatal("not implemented yet!\n"); 355 return NULL; 532 356 } 533 357 … … 582 406 583 407 case TYPE_LIST: 584 crl_ runtime_list_print( sym->op_a.list_table, context, fd);408 crl_fatal("not imeplemented yet!\n"); 585 409 exec= true; 586 410 break; … … 624 448 { 625 449 crl_assert( sym->op_a_t == TYPE_STRING ); 626 crl_table_entry* var= crl_ context_lookup_symbol( sym->op_a.string, &context );450 crl_table_entry* var= crl_rr_context_lookup_symbol( sym->op_a.string, &context ); 627 451 if( var ) 628 452 { … … 670 494 sizeof(unsigned short) ); 671 495 672 crl_table *lst= NULL;496 crl_table_t *lst= NULL; 673 497 switch( (*sym)->op_a_t ) 674 498 { … … 693 517 694 518 case TYPE_LIST: 695 if( !(lst= crl_list_clone( &((*sym)->op_a.list_table ))) ) 696 crl_error("error cloning list!\n"); 697 retval->op_a.list_table= lst; 519 crl_fatal("not implemented yet!\n"); 698 520 break; 699 521 … … 709 531 710 532 case TYPE_OBJECT: 711 retval->op_a.object_state = crl_ context_clone_obj_state( &((*sym)->op_a.object_state) );533 retval->op_a.object_state = crl_rr_context_clone_obj_state( &((*sym)->op_a.object_state) ); 712 534 break; 713 535 714 536 case TYPE_BUILTIN: 715 retval->op_a.callback = crl_builtin_clone_callback( &(*sym)->op_a.callback);537 crl_fatal("not implemented yet!\n"); 716 538 break; 717 539 … … 752 574 753 575 case TYPE_LIST: 754 if( !(lst= crl_list_clone( &((*sym)->op_b.list_table ))) ) 755 crl_error("error cloning list!\n"); 756 retval->op_b.list_table= lst; 576 crl_fatal("not implemented yet!\n"); 757 577 break; 758 578 … … 770 590 if( (*sym)->op_b.stack_table ) 771 591 { 772 crl_stack * t= (crl_stack*)773 crl_malloc( sizeof(crl_stack ) );774 crl_ stack_init( &t );592 crl_stack_t* t= (crl_stack_t*) 593 crl_malloc( sizeof(crl_stack_t) ); 594 crl_dd_stack_init( &t ); 775 595 unsigned int len= 776 crl_ stack_get_size( (*sym)->op_b.stack_table );596 crl_dd_stack_get_size( (*sym)->op_b.stack_table ); 777 597 unsigned int idx= 0; 778 598 for( ; idx<len; ++idx ) … … 780 600 crl_symbol_obj *o= (*sym)->op_b.stack_table->array[ idx ]; 781 601 crl_symbol_obj *r= crl_runtime_obj_clone( &o, false ); 782 crl_ stack_push( t, r );602 crl_dd_stack_push( t, r ); 783 603 } 784 604 retval->op_b.stack_table= t; … … 787 607 788 608 case TYPE_OBJECT: 789 retval->op_b.object_state = crl_ context_clone_obj_state( &((*sym)->op_b.object_state) );609 retval->op_b.object_state = crl_rr_context_clone_obj_state( &((*sym)->op_b.object_state) ); 790 610 break; 791 611 792 612 case TYPE_BUILTIN: 793 retval->op_b.callback = crl_builtin_clone_callback( &(*sym)->op_b.callback);613 crl_fatal("not imeplemented yet!\n"); 794 614 break; 795 615 … … 1059 879 { 1060 880 crl_debug("expression is a singleton item!\n"); 1061 if( sym->op_a_t == TYPE_LIST )1062 {1063 if( crl_runtime_list_format( sym->op_a.list_table, context ) == false )1064 {1065 crl_fatal("problem formating the list assignment!\n");1066 retval = NULL;1067 }1068 }1069 881 retval= crl_runtime_obj_clone( &sym, false ); 1070 882 } … … 1073 885 crl_debug("singleton symbol refernce!\n"); 1074 886 crl_assert( sym->op_a_t == TYPE_STRING ); 1075 crl_table_entry* ei= crl_ context_lookup_symbol( sym->op_a.string,887 crl_table_entry* ei= crl_rr_context_lookup_symbol( sym->op_a.string, 1076 888 &context ); 1077 889 if( ei ) … … 1112 924 { 1113 925 char *object_ident = sym->op_a.symbol_table->op_a.string; 1114 crl_obj_state_t ** o = crl_ context_lookup_object( object_ident, &context );926 crl_obj_state_t ** o = crl_rr_context_lookup_object( object_ident, &context ); 1115 927 if( o ) 1116 928 { … … 1133 945 retval->type = SYMBOL_PRIMARY; 1134 946 retval->op_a_t = TYPE_OBJECT; 1135 retval->op_a.object_state = crl_ context_clone_obj_state( o );947 retval->op_a.object_state = crl_rr_context_clone_obj_state( o ); 1136 948 1137 949 // its now initilized! … … 1238 1050 if( sym->op_a_t == TYPE_LIST ) 1239 1051 { 1240 if( crl_runtime_list_format( sym->op_a.list_table, context ) == false ) 1241 { 1242 crl_fatal("problem formating the list assignment!\n"); 1243 retval = NULL; 1244 } 1052 crl_fatal("not imeplemented yet!\n"); 1245 1053 } 1246 1054 retval= crl_runtime_obj_clone( &sym, false ); … … 1250 1058 crl_debug("singleton symbol refernce!\n"); 1251 1059 crl_assert( sym->op_a_t == TYPE_STRING ); 1252 crl_table_entry* ei= crl_ context_lookup_symbol( sym->op_a.string,1060 crl_table_entry* ei= crl_rr_context_lookup_symbol( sym->op_a.string, 1253 1061 &context ); 1254 1062 if( ei ) … … 1289 1097 { 1290 1098 char *object_ident = sym->op_a.symbol_table->op_a.string; 1291 crl_obj_state_t ** o = crl_ context_lookup_object( object_ident, &context );1099 crl_obj_state_t ** o = crl_rr_context_lookup_object( object_ident, &context ); 1292 1100 if( o ) 1293 1101 { … … 1310 1118 retval->type = SYMBOL_PRIMARY; 1311 1119 retval->op_a_t = TYPE_OBJECT; 1312 retval->op_a.object_state = crl_ context_clone_obj_state( o );1120 retval->op_a.object_state = crl_rr_context_clone_obj_state( o ); 1313 1121 1314 1122 // its now initilized! … … 1346 1154 crl_branch_context *argument_ctx= (crl_branch_context*) 1347 1155 crl_malloc(sizeof( crl_branch_context )); 1348 crl_ context_init_context( &argument_ctx );1156 crl_rr_context_init( &argument_ctx ); 1349 1157 argument_ctx->return_ctx= true; 1350 crl_ context_push( argument_ctx, function_ctx );1158 crl_rr_context_push( argument_ctx, function_ctx ); 1351 1159 1352 1160 if( (*functor_def)->op_b_t == TYPE_PARAMETERS ) 1353 1161 { 1354 unsigned int n_parameters = crl_ stack_get_size( (*functor_def)->op_b.stack_table );1162 unsigned int n_parameters = crl_dd_stack_get_size( (*functor_def)->op_b.stack_table ); 1355 1163 unsigned int n_arguments = 0; 1356 1164 … … 1358 1166 if( call->op_b_t == TYPE_ARGUMENTS ) 1359 1167 { 1360 n_arguments = crl_ stack_get_size( call->op_b.stack_table );1168 n_arguments = crl_dd_stack_get_size( call->op_b.stack_table ); 1361 1169 if( n_arguments >= n_parameters ) 1362 1170 { … … 1378 1186 crl_assert( o->type == SYMBOL_PRIMARY ); 1379 1187 1380 crl_symbol_obj** s= crl_ hash_insert( crl_hash_hash( param_idx ) ,1381 o , function_ctx->curr->symbol_table );1188 crl_symbol_obj** s= crl_dd_hash_insert( crl_dd_hash_hash( param_idx ) , 1189 o , function_ctx->curr->symbol_table ); 1382 1190 if( s ) 1383 1191 { … … 1405 1213 1406 1214 crl_debug("Function returned!\n"); 1407 crl_branch_context* arg_ctx_t= crl_ context_pop( function_ctx );1215 crl_branch_context* arg_ctx_t= crl_rr_context_pop( function_ctx ); 1408 1216 if( ctx_retval ) 1409 1217 { … … 1423 1231 { 1424 1232 crl_assert( sym->op_a_t == TYPE_STRING ); crl_symbol_obj* retval= NULL; 1425 crl_symbol_obj** proc= crl_ context_lookup_function( sym->op_a.string, &context );1233 crl_symbol_obj** proc= crl_rr_context_lookup_function( sym->op_a.string, &context ); 1426 1234 1427 1235 if( proc ) … … 1429 1237 crl_context_table *goto_ctx_table= (crl_context_table*) 1430 1238 crl_malloc(sizeof( crl_context_table )); 1431 crl_ context_init_table( &goto_ctx_table );1432 1433 unsigned int context_length= crl_ context_get_table_size( context );1239 crl_rr_context_init_table( &goto_ctx_table ); 1240 1241 unsigned int context_length= crl_rr_context_get_table_size( context ); 1434 1242 unsigned int ctx_idx= 0; crl_branch_context* ctx_t; 1435 1243 … … 1444 1252 else 1445 1253 { 1446 crl_ context_push( ctx_t, goto_ctx_table );1254 crl_rr_context_push( ctx_t, goto_ctx_table ); 1447 1255 } 1448 1256 } … … 1453 1261 unsigned int i = 0; 1454 1262 for( ; i<ctx_idx; ++i ) 1455 crl_ context_pop( goto_ctx_table );1263 crl_rr_context_pop( goto_ctx_table ); 1456 1264 1457 1265 crl_garbage_free_context_table( &goto_ctx_table ); … … 1478 1286 { 1479 1287 //look for the return address! 1480 signed int len= crl_ context_get_table_size( ctx );1288 signed int len= crl_rr_context_get_table_size( ctx ); 1481 1289 crl_branch_context *c; len--; bool f= false; 1482 1290 … … 1516 1324 crl_malloc(sizeof( crl_branch_context )); 1517 1325 1518 crl_ context_init_context( &branch_ctx );1519 crl_ context_push( branch_ctx, context );1326 crl_rr_context_init( &branch_ctx ); 1327 crl_rr_context_push( branch_ctx, context ); 1520 1328 1521 1329 retval= crl_runtime_exec_branch( sym, context ); … … 1525 1333 1526 1334 crl_debug("freeing local stack frame!\n"); 1527 crl_branch_context* ctx= crl_ context_pop( context );1335 crl_branch_context* ctx= crl_rr_context_pop( context ); 1528 1336 crl_garbage_free_context_branch( &ctx ); 1529 1337 crl_debug("done freeing stack frame!\n"); 1530 1338 1531 1339 return retval; 1532 }1533 1534 /**1535 * Limited to deleting variables cannot delete functions!1536 *1537 * Note semanticaly the symbol is marked as garbage, this is1538 * a nice hint to the garbage collector if you want to memory1539 * consious on low memory systems, remember normal ref-counting1540 * and conservative collection continue's, so if it is seen as garbage1541 * the collector will eventually delete it.1542 **/1543 bool crl_runtime_keyword_delete( crl_symbol_obj *sym,1544 crl_context_table *context )1545 {1546 crl_assert( sym->type == KEY_DELETE ); bool retval = true;1547 crl_debug("atempting to mark symbol <%s> as garbage!\n", sym->op_a.string );1548 1549 crl_table_entry *var= crl_context_lookup_symbol( sym->op_a.string, &context );1550 if( var )1551 {1552 if( var->symbol )1553 {1554 crl_symbol_obj *s = var->symbol;1555 var->symbol = NULL;1556 crl_garbage_mark_obj( &s );1557 }1558 }1559 return (retval);1560 1340 } 1561 1341 … … 1620 1400 case KEY_BREAK: 1621 1401 rex= crl_runtime_eval_key_break( context ); 1622 break;1623 1624 case KEY_DELETE:1625 crl_runtime_keyword_delete( sym, context );1626 1402 break; 1627 1403 … … 1704 1480 break; 1705 1481 1706 case KEY_DELETE:1707 crl_runtime_keyword_delete( sym, context );1708 break;1709 1710 1482 case SYMBOL_REFERENCE: 1711 1483 if( crl_interactive ) … … 1740 1512 1741 1513 case STRUCTURE_FUNCTION_DEF: 1742 if( crl_ context_push_function_def( sym, &context ) == false )1514 if( crl_rr_context_push_function_def( sym, &context ) == false ) 1743 1515 crl_fatal("error pushing function definition!\n"); 1744 1516 break; 1745 1517 1746 1518 case STRUCTURE_OBJECT_DEF: 1747 if( crl_ context_push_object_def( sym, &context ) == false)1519 if( crl_rr_context_push_object_def( sym, &context ) == false) 1748 1520 crl_fatal("error pushing object definition"); 1749 1521 break; -
src/ss_lexical.l
r8ff7a1b r168c2a5 105 105 continue { return CONTINUE; } 106 106 return { return RETURN; } 107 delete { return DELETE; }108 107 for { return FOR; } 109 108 while { return WHILE; } -
src/ss_parser.y
r8ff7a1b r168c2a5 76 76 %token CONTINUE "conintue" 77 77 %token RETURN "return" 78 %token DELETE "delete"79 78 %token WHILE "while" 80 79 %token FOR "for" … … 133 132 %type<symbol> return_keyword 134 133 %type<symbol> continue_keyword 135 %type<symbol> delete_keyword136 134 %type<symbol> procedure 137 135 %type<symbol> pblock … … 875 873 | return_keyword ';' 876 874 | continue_keyword ';' 877 | delete_keyword ';'878 875 | control_structure 879 876 ; 880 881 delete_keyword: DELETE IDENTIFIER882 {883 crl_symbol_obj *sym;884 crl_symbol_init( sym );885 sym->type= KEY_DELETE;886 sym->op_a_t = TYPE_STRING;887 sym->op_a.string = $2;888 $$= sym;889 }890 877 891 878 continue_keyword: CONTINUE
