From 3af1a8af1e76701d2204a8b3307cd80abce47efc Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Mon, 22 Feb 2016 12:16:16 -0500 Subject: [PATCH] embryo: reformat the whole thing so many tabs --- src/lib/embryo/embryo_amx.c | 2564 +++++++++++++++++++++-------------------- src/lib/embryo/embryo_args.c | 29 +- src/lib/embryo/embryo_float.c | 95 +- src/lib/embryo/embryo_main.c | 3 +- src/lib/embryo/embryo_rand.c | 3 +- src/lib/embryo/embryo_str.c | 208 ++-- src/lib/embryo/embryo_time.c | 62 +- 7 files changed, 1500 insertions(+), 1464 deletions(-) diff --git a/src/lib/embryo/embryo_amx.c b/src/lib/embryo/embryo_amx.c index 6453d38..e8df24d 100644 --- a/src/lib/embryo/embryo_amx.c +++ b/src/lib/embryo/embryo_amx.c @@ -20,7 +20,6 @@ * 3. This notice may not be removed or altered from any source distribution. */ - #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -38,17 +37,16 @@ #include "Embryo.h" #include "embryo_private.h" - -#define JUMPABS(base, ip) ((Embryo_Cell *)(code + (*ip))) +#define JUMPABS(base, ip) ((Embryo_Cell *)(code + (*ip))) #ifdef WORDS_BIGENDIAN -static void _embryo_byte_swap_16 (unsigned short *v); -static void _embryo_byte_swap_32 (unsigned int *v); +static void _embryo_byte_swap_16(unsigned short *v); +static void _embryo_byte_swap_32(unsigned int *v); #endif -static int _embryo_native_call (Embryo_Program *ep, Embryo_Cell idx, Embryo_Cell *result, Embryo_Cell *params); -static int _embryo_func_get (Embryo_Program *ep, int idx, char *funcname); -static int _embryo_var_get (Embryo_Program *ep, int idx, char *varname, Embryo_Cell *ep_addr); -static int _embryo_program_init (Embryo_Program *ep, void *code); +static int _embryo_native_call(Embryo_Program *ep, Embryo_Cell idx, Embryo_Cell *result, Embryo_Cell *params); +static int _embryo_func_get(Embryo_Program *ep, int idx, char *funcname); +static int _embryo_var_get(Embryo_Program *ep, int idx, char *varname, Embryo_Cell *ep_addr); +static int _embryo_program_init(Embryo_Program *ep, void *code); #ifdef WORDS_BIGENDIAN static void @@ -69,28 +67,29 @@ _embryo_byte_swap_32(unsigned int *v) t = s[0]; s[0] = s[3]; s[3] = t; t = s[1]; s[1] = s[2]; s[2] = t; } + #endif static int _embryo_native_call(Embryo_Program *ep, Embryo_Cell idx, Embryo_Cell *result, Embryo_Cell *params) { - Embryo_Header *hdr; + Embryo_Header *hdr; Embryo_Func_Stub *func_entry; - Embryo_Native f; + Embryo_Native f; hdr = (Embryo_Header *)ep->base; func_entry = GETENTRY(hdr, natives, idx); if ((func_entry->address <= 0) || (func_entry->address > ep->native_calls_size)) { - ep->error = EMBRYO_ERROR_CALLBACK; - return ep->error; + ep->error = EMBRYO_ERROR_CALLBACK; + return ep->error; } f = ep->native_calls[func_entry->address - 1]; if (!f) { - ep->error = EMBRYO_ERROR_CALLBACK; - return ep->error; + ep->error = EMBRYO_ERROR_CALLBACK; + return ep->error; } ep->error = EMBRYO_ERROR_NONE; *result = f(ep, params); @@ -100,7 +99,7 @@ _embryo_native_call(Embryo_Program *ep, Embryo_Cell idx, Embryo_Cell *result, Em static int _embryo_func_get(Embryo_Program *ep, int idx, char *funcname) { - Embryo_Header *hdr; + Embryo_Header *hdr; Embryo_Func_Stub *func; hdr = (Embryo_Header *)ep->code; @@ -115,23 +114,23 @@ _embryo_func_get(Embryo_Program *ep, int idx, char *funcname) static int _embryo_var_get(Embryo_Program *ep, int idx, char *varname, Embryo_Cell *ep_addr) { - Embryo_Header *hdr; - Embryo_Func_Stub *var; + Embryo_Header *hdr; + Embryo_Func_Stub *var; - hdr=(Embryo_Header *)ep->base; - if (idx >= (Embryo_Cell)NUMENTRIES(hdr, pubvars, tags)) + hdr = (Embryo_Header *)ep->base; + if (idx >= (Embryo_Cell)NUMENTRIES(hdr, pubvars, tags)) return EMBRYO_ERROR_INDEX; - var = GETENTRY(hdr, pubvars, idx); - strcpy(varname, GETENTRYNAME(hdr, var)); - *ep_addr = var->address; - return EMBRYO_ERROR_NONE; + var = GETENTRY(hdr, pubvars, idx); + strcpy(varname, GETENTRYNAME(hdr, var)); + *ep_addr = var->address; + return EMBRYO_ERROR_NONE; } static int _embryo_program_init(Embryo_Program *ep, void *code) { - Embryo_Header *hdr; + Embryo_Header *hdr; if ((ep->flags & EMBRYO_FLAG_RELOC)) return 1; ep->code = (unsigned char *)code; @@ -156,77 +155,77 @@ _embryo_program_init(Embryo_Program *ep, void *code) if (hdr->magic != EMBRYO_MAGIC) return 0; if ((hdr->file_version < MIN_FILE_VERSION) || - (hdr->ep_version > CUR_FILE_VERSION)) return 0; + (hdr->ep_version > CUR_FILE_VERSION)) return 0; if ((hdr->defsize != sizeof(Embryo_Func_Stub)) && - (hdr->defsize != (2 * sizeof(unsigned int)))) return 0; + (hdr->defsize != (2 * sizeof(unsigned int)))) return 0; if (hdr->defsize == (2 * sizeof(unsigned int))) { - unsigned short *len; + unsigned short *len; - len = (unsigned short*)((unsigned char*)ep->code + hdr->nametable); + len = (unsigned short *)((unsigned char *)ep->code + hdr->nametable); #ifdef WORDS_BIGENDIAN - embryo_swap_16((unsigned short *)len); + embryo_swap_16((unsigned short *)len); #endif - if (*len > sNAMEMAX) return 0; + if (*len > sNAMEMAX) return 0; } if (hdr->stp <= 0) return 0; if ((hdr->flags & EMBRYO_FLAG_COMPACT)) return 0; #ifdef WORDS_BIGENDIAN - { - Embryo_Func_Stub *fs; - int i, num; - - /* also align all addresses in the public function, public variable and */ - /* public tag tables */ - fs = GETENTRY(hdr, publics, 0); - num = NUMENTRIES(hdr, publics, natives); - for (i = 0; i < num; i++) - { - embryo_swap_32(&(fs->address)); - fs = (Embryo_Func_Stub *)((unsigned char *)fs + hdr->defsize); - } - - fs = GETENTRY(hdr, pubvars, 0); - num = NUMENTRIES(hdr, pubvars, tags); - for (i = 0; i < num; i++) - { - embryo_swap_32(&(fs->address)); - fs = (Embryo_Func_Stub *)((unsigned char *)fs + hdr->defsize); - } - - fs = GETENTRY(hdr, tags, 0); - num = NUMENTRIES(hdr, tags, nametable); - for (i = 0; i < num; i++) - { - embryo_swap_32(&(fs->address)); - fs = (Embryo_Func_Stub *)((unsigned char *)fs + hdr->defsize); - } - } + { + Embryo_Func_Stub *fs; + int i, num; + + /* also align all addresses in the public function, public variable and */ + /* public tag tables */ + fs = GETENTRY(hdr, publics, 0); + num = NUMENTRIES(hdr, publics, natives); + for (i = 0; i < num; i++) + { + embryo_swap_32(&(fs->address)); + fs = (Embryo_Func_Stub *)((unsigned char *)fs + hdr->defsize); + } + + fs = GETENTRY(hdr, pubvars, 0); + num = NUMENTRIES(hdr, pubvars, tags); + for (i = 0; i < num; i++) + { + embryo_swap_32(&(fs->address)); + fs = (Embryo_Func_Stub *)((unsigned char *)fs + hdr->defsize); + } + + fs = GETENTRY(hdr, tags, 0); + num = NUMENTRIES(hdr, tags, nametable); + for (i = 0; i < num; i++) + { + embryo_swap_32(&(fs->address)); + fs = (Embryo_Func_Stub *)((unsigned char *)fs + hdr->defsize); + } + } #endif ep->flags = EMBRYO_FLAG_RELOC; #ifdef WORDS_BIGENDIAN -/* until we do more... this is only used for bigendian */ - { - Embryo_Cell cip, code_size, cip_end; - Embryo_Cell *code; - - code_size = hdr->dat - hdr->cod; - code = (Embryo_Cell *)((unsigned char *)ep->code + (int)hdr->cod); - cip_end = code_size / sizeof(Embryo_Cell); - for (cip = 0; cip < cip_end; cip++) - { +/* until we do more... this is only used for bigendian */ + { + Embryo_Cell cip, code_size, cip_end; + Embryo_Cell *code; + + code_size = hdr->dat - hdr->cod; + code = (Embryo_Cell *)((unsigned char *)ep->code + (int)hdr->cod); + cip_end = code_size / sizeof(Embryo_Cell); + for (cip = 0; cip < cip_end; cip++) + { /* move this here - later we probably want something that verifies opcodes * are valid and ok... */ #ifdef WORDS_BIGENDIAN - embryo_swap_32(&(code[cip])); + embryo_swap_32(&(code[cip])); #endif - } - } + } + } #endif - + /* init native api for handling floating point - default in embryo */ _embryo_args_init(ep); _embryo_fp_init(ep); @@ -252,8 +251,8 @@ embryo_program_new(void *data, int size) code_data = malloc(size); if (!code_data) { - free(ep); - return NULL; + free(ep); + return NULL; } memcpy(code_data, data, size); if (_embryo_program_init(ep, code_data)) return ep; @@ -274,8 +273,8 @@ embryo_program_const_new(void *data, int size) if (_embryo_program_init(ep, data)) { - ep->dont_free_code = 1; - return ep; + ep->dont_free_code = 1; + return ep; } free(ep); return NULL; @@ -285,7 +284,7 @@ EAPI Embryo_Program * embryo_program_load(const char *file) { Embryo_Program *ep; - Embryo_Header hdr; + Embryo_Header hdr; FILE *f; void *program = NULL; int program_size = 0; @@ -297,13 +296,13 @@ embryo_program_load(const char *file) fseek(f, 0L, SEEK_SET); if (program_size < (int)sizeof(Embryo_Header)) { - fclose(f); - return NULL; + fclose(f); + return NULL; } if (fread(&hdr, sizeof(Embryo_Header), 1, f) != 1) { - fclose(f); - return NULL; + fclose(f); + return NULL; } fseek(f, 0L, SEEK_SET); #ifdef WORDS_BIGENDIAN @@ -313,14 +312,14 @@ embryo_program_load(const char *file) program = malloc(program_size); if (!program) { - fclose(f); - return NULL; + fclose(f); + return NULL; } if (fread(program, program_size, 1, f) != 1) { - free(program); - fclose(f); - return NULL; + free(program); + fclose(f); + return NULL; } ep = embryo_program_new(program, program_size); free(program); @@ -338,22 +337,21 @@ embryo_program_free(Embryo_Program *ep) if (ep->native_calls) free(ep->native_calls); for (i = 0; i < ep->params_size; i++) { - if (ep->params[i].string) free(ep->params[i].string); - if (ep->params[i].cell_array) free(ep->params[i].cell_array); + if (ep->params[i].string) free(ep->params[i].string); + if (ep->params[i].cell_array) free(ep->params[i].cell_array); } if (ep->params) free(ep->params); free(ep); } - EAPI void -embryo_program_native_call_add(Embryo_Program *ep, const char *name, Embryo_Cell (*func) (Embryo_Program *ep, Embryo_Cell *params)) +embryo_program_native_call_add(Embryo_Program *ep, const char *name, Embryo_Cell (*func)(Embryo_Program *ep, Embryo_Cell *params)) { Embryo_Func_Stub *func_entry; - Embryo_Header *hdr; - int i, num; + Embryo_Header *hdr; + int i, num; - if ((!ep ) || (!name) || (!func)) return; + if ((!ep) || (!name) || (!func)) return; if (strlen(name) > sNAMEMAX) return; hdr = (Embryo_Header *)ep->code; @@ -364,44 +362,43 @@ embryo_program_native_call_add(Embryo_Program *ep, const char *name, Embryo_Cell ep->native_calls_size++; if (ep->native_calls_size > ep->native_calls_alloc) { - Embryo_Native *calls; - - ep->native_calls_alloc += 32; - calls = realloc(ep->native_calls, - ep->native_calls_alloc * sizeof(Embryo_Native)); - if (!calls) - { - ep->native_calls_size--; - ep->native_calls_alloc -= 32; - return; - } - ep->native_calls = calls; + Embryo_Native *calls; + + ep->native_calls_alloc += 32; + calls = realloc(ep->native_calls, + ep->native_calls_alloc * sizeof(Embryo_Native)); + if (!calls) + { + ep->native_calls_size--; + ep->native_calls_alloc -= 32; + return; + } + ep->native_calls = calls; } ep->native_calls[ep->native_calls_size - 1] = func; func_entry = GETENTRY(hdr, natives, 0); for (i = 0; i < num; i++) { - if (func_entry->address == 0) - { - char *entry_name; - - entry_name = GETENTRYNAME(hdr, func_entry); - if ((entry_name) && (!strcmp(entry_name, name))) - { - func_entry->address = ep->native_calls_size; - /* FIXME: embryo_cc is putting in multiple native */ - /* function call entries - so we need to fill in all */ - /* of them!!! */ - /* return; */ - } - } - func_entry = - (Embryo_Func_Stub *)((unsigned char *)func_entry + hdr->defsize); + if (func_entry->address == 0) + { + char *entry_name; + + entry_name = GETENTRYNAME(hdr, func_entry); + if ((entry_name) && (!strcmp(entry_name, name))) + { + func_entry->address = ep->native_calls_size; + /* FIXME: embryo_cc is putting in multiple native */ + /* function call entries - so we need to fill in all */ + /* of them!!! */ + /* return; */ + } + } + func_entry = + (Embryo_Func_Stub *)((unsigned char *)func_entry + hdr->defsize); } } - EAPI void embryo_program_vm_reset(Embryo_Program *ep) { @@ -427,15 +424,15 @@ embryo_program_vm_push(Embryo_Program *ep) ep->pushes++; if (ep->pushes > 1) { - embryo_program_vm_reset(ep); - return; + embryo_program_vm_reset(ep); + return; } hdr = (Embryo_Header *)ep->code; ep->base = calloc(1, hdr->stp); if (!ep->base) { - ep->pushes = 0; - return; + ep->pushes = 0; + return; } embryo_program_vm_reset(ep); } @@ -450,13 +447,12 @@ embryo_program_vm_pop(Embryo_Program *ep) ep->base = NULL; } - EAPI void embryo_swap_16(unsigned short *v #ifndef WORDS_BIGENDIAN EINA_UNUSED -#endif - ) +#endif + ) { #ifdef WORDS_BIGENDIAN _embryo_byte_swap_16(v); @@ -478,8 +474,8 @@ embryo_swap_32(unsigned int *v EAPI Embryo_Function embryo_program_function_find(Embryo_Program *ep, const char *name) { - int first, last, mid, result; - char pname[sNAMEMAX + 1]; + int first, last, mid, result; + char pname[sNAMEMAX + 1]; Embryo_Header *hdr; if (!ep) return EMBRYO_FUNCTION_NONE; @@ -489,26 +485,26 @@ embryo_program_function_find(Embryo_Program *ep, const char *name) /* binary search */ while (first <= last) { - mid = (first + last) / 2; - if (_embryo_func_get(ep, mid, pname) == EMBRYO_ERROR_NONE) - result = strcmp(pname, name); - else - return EMBRYO_FUNCTION_NONE; + mid = (first + last) / 2; + if (_embryo_func_get(ep, mid, pname) == EMBRYO_ERROR_NONE) + result = strcmp(pname, name); + else + return EMBRYO_FUNCTION_NONE; /* result = -1;*/ - if (result > 0) last = mid - 1; - else if (result < 0) first = mid + 1; - else return mid; + if (result > 0) last = mid - 1; + else if (result < 0) + first = mid + 1; + else return mid; } return EMBRYO_FUNCTION_NONE; } - EAPI Embryo_Cell embryo_program_variable_find(Embryo_Program *ep, const char *name) { - int first, last, mid, result; - char pname[sNAMEMAX + 1]; - Embryo_Cell paddr; + int first, last, mid, result; + char pname[sNAMEMAX + 1]; + Embryo_Cell paddr; Embryo_Header *hdr; if (!ep) return EMBRYO_CELL_NONE; @@ -519,15 +515,16 @@ embryo_program_variable_find(Embryo_Program *ep, const char *name) /* binary search */ while (first <= last) { - mid = (first + last) / 2; - if (_embryo_var_get(ep, mid, pname, &paddr) == EMBRYO_ERROR_NONE) - result = strcmp(pname, name); - else - return EMBRYO_CELL_NONE; + mid = (first + last) / 2; + if (_embryo_var_get(ep, mid, pname, &paddr) == EMBRYO_ERROR_NONE) + result = strcmp(pname, name); + else + return EMBRYO_CELL_NONE; /* result = -1;*/ - if (result > 0) last = mid - 1; - else if (result < 0) first = mid + 1; - else return paddr; + if (result > 0) last = mid - 1; + else if (result < 0) + first = mid + 1; + else return paddr; } return EMBRYO_CELL_NONE; } @@ -546,8 +543,8 @@ embryo_program_variable_count_get(Embryo_Program *ep) EAPI Embryo_Cell embryo_program_variable_get(Embryo_Program *ep, int num) { - Embryo_Cell paddr; - char pname[sNAMEMAX + 1]; + Embryo_Cell paddr; + char pname[sNAMEMAX + 1]; if (!ep) return EMBRYO_CELL_NONE; if (!ep->base) return EMBRYO_CELL_NONE; @@ -556,7 +553,6 @@ embryo_program_variable_get(Embryo_Program *ep, int num) return EMBRYO_CELL_NONE; } - EAPI void embryo_program_error_set(Embryo_Program *ep, Embryo_Error error) { @@ -571,7 +567,6 @@ embryo_program_error_get(Embryo_Program *ep) return ep->error; } - EAPI void embryo_program_data_set(Embryo_Program *ep, void *data) { @@ -590,45 +585,45 @@ EAPI const char * embryo_error_string_get(Embryo_Error error) { const char *messages[] = - { - /* EMBRYO_ERROR_NONE */ "(none)", - /* EMBRYO_ERROR_EXIT */ "Forced exit", - /* EMBRYO_ERROR_ASSERT */ "Assertion failed", - /* EMBRYO_ERROR_STACKERR */ "Stack/heap collision (insufficient stack size)", - /* EMBRYO_ERROR_BOUNDS */ "Array index out of bounds", - /* EMBRYO_ERROR_MEMACCESS */ "Invalid memory access", - /* EMBRYO_ERROR_INVINSTR */ "Invalid instruction", - /* EMBRYO_ERROR_STACKLOW */ "Stack underflow", - /* EMBRYO_ERROR_HEAPLOW */ "Heap underflow", - /* EMBRYO_ERROR_CALLBACK */ "No (valid) native function callback", - /* EMBRYO_ERROR_NATIVE */ "Native function failed", - /* EMBRYO_ERROR_DIVIDE */ "Divide by zero", - /* EMBRYO_ERROR_SLEEP */ "(sleep mode)", - /* 13 */ "(reserved)", - /* 14 */ "(reserved)", - /* 15 */ "(reserved)", - /* EMBRYO_ERROR_MEMORY */ "Out of memory", - /* EMBRYO_ERROR_FORMAT */ "Invalid/unsupported P-code file format", - /* EMBRYO_ERROR_VERSION */ "File is for a newer version of the Embryo_Program", - /* EMBRYO_ERROR_NOTFOUND */ "Native/Public function is not found", - /* EMBRYO_ERROR_INDEX */ "Invalid index parameter (bad entry point)", - /* EMBRYO_ERROR_DEBUG */ "Debugger cannot run", - /* EMBRYO_ERROR_INIT */ "Embryo_Program not initialized (or doubly initialized)", - /* EMBRYO_ERROR_USERDATA */ "Unable to set user data field (table full)", - /* EMBRYO_ERROR_INIT_JIT */ "Cannot initialize the JIT", - /* EMBRYO_ERROR_PARAMS */ "Parameter error", - }; - if (((int)error < 0) || + { + /* EMBRYO_ERROR_NONE */ + "(none)", + /* EMBRYO_ERROR_EXIT */ "Forced exit", + /* EMBRYO_ERROR_ASSERT */ "Assertion failed", + /* EMBRYO_ERROR_STACKERR */ "Stack/heap collision (insufficient stack size)", + /* EMBRYO_ERROR_BOUNDS */ "Array index out of bounds", + /* EMBRYO_ERROR_MEMACCESS */ "Invalid memory access", + /* EMBRYO_ERROR_INVINSTR */ "Invalid instruction", + /* EMBRYO_ERROR_STACKLOW */ "Stack underflow", + /* EMBRYO_ERROR_HEAPLOW */ "Heap underflow", + /* EMBRYO_ERROR_CALLBACK */ "No (valid) native function callback", + /* EMBRYO_ERROR_NATIVE */ "Native function failed", + /* EMBRYO_ERROR_DIVIDE */ "Divide by zero", + /* EMBRYO_ERROR_SLEEP */ "(sleep mode)", + /* 13 */ "(reserved)", + /* 14 */ "(reserved)", + /* 15 */ "(reserved)", + /* EMBRYO_ERROR_MEMORY */ "Out of memory", + /* EMBRYO_ERROR_FORMAT */ "Invalid/unsupported P-code file format", + /* EMBRYO_ERROR_VERSION */ "File is for a newer version of the Embryo_Program", + /* EMBRYO_ERROR_NOTFOUND */ "Native/Public function is not found", + /* EMBRYO_ERROR_INDEX */ "Invalid index parameter (bad entry point)", + /* EMBRYO_ERROR_DEBUG */ "Debugger cannot run", + /* EMBRYO_ERROR_INIT */ "Embryo_Program not initialized (or doubly initialized)", + /* EMBRYO_ERROR_USERDATA */ "Unable to set user data field (table full)", + /* EMBRYO_ERROR_INIT_JIT */ "Cannot initialize the JIT", + /* EMBRYO_ERROR_PARAMS */ "Parameter error", + }; + if (((int)error < 0) || ((int)error >= (int)(sizeof(messages) / sizeof(messages[0])))) return (const char *)"(unknown)"; return messages[error]; } - EAPI int embryo_data_string_length_get(Embryo_Program *ep, Embryo_Cell *str_cell) { - int len; + int len; Embryo_Header *hdr; if ((!ep) || (!ep->base)) return 0; @@ -637,42 +632,42 @@ embryo_data_string_length_get(Embryo_Program *ep, Embryo_Cell *str_cell) ((void *)str_cell >= (void *)(ep->base + hdr->stp)) || ((void *)str_cell < (void *)ep->base)) return 0; - for (len = 0; str_cell[len] != 0; len++); + for (len = 0; str_cell[len] != 0; len++) ; return len; } EAPI void embryo_data_string_get(Embryo_Program *ep, Embryo_Cell *str_cell, char *dst) { - int i; + int i; Embryo_Header *hdr; if (!dst) return; if ((!ep) || (!ep->base)) { - dst[0] = 0; - return; + dst[0] = 0; + return; } hdr = (Embryo_Header *)ep->base; if ((!str_cell) || ((void *)str_cell >= (void *)(ep->base + hdr->stp)) || ((void *)str_cell < (void *)ep->base)) { - dst[0] = 0; - return; + dst[0] = 0; + return; } for (i = 0; str_cell[i] != 0; i++) { #ifdef WORDS_BIGENDIAN - { - Embryo_Cell tmp; + { + Embryo_Cell tmp; - tmp = str_cell[i]; - _embryo_byte_swap_32(&tmp); - dst[i] = tmp; - } + tmp = str_cell[i]; + _embryo_byte_swap_32(&tmp); + dst[i] = tmp; + } #else - dst[i] = str_cell[i]; + dst[i] = str_cell[i]; #endif } dst[i] = 0; @@ -681,7 +676,7 @@ embryo_data_string_get(Embryo_Program *ep, Embryo_Cell *str_cell, char *dst) EAPI void embryo_data_string_set(Embryo_Program *ep, const char *src, Embryo_Cell *str_cell) { - int i; + int i; Embryo_Header *hdr; if (!ep) return; @@ -693,27 +688,27 @@ embryo_data_string_set(Embryo_Program *ep, const char *src, Embryo_Cell *str_cel return; if (!src) { - str_cell[0] = 0; - return; + str_cell[0] = 0; + return; } for (i = 0; src[i] != 0; i++) { - if ((void *)(&(str_cell[i])) >= (void *)(ep->base + hdr->stp)) return; - else if ((void *)(&(str_cell[i])) == (void *)(ep->base + hdr->stp - 1)) - { - str_cell[i] = 0; - return; - } + if ((void *)(&(str_cell[i])) >= (void *)(ep->base + hdr->stp)) return; + else if ((void *)(&(str_cell[i])) == (void *)(ep->base + hdr->stp - 1)) + { + str_cell[i] = 0; + return; + } #ifdef WORDS_BIGENDIAN - { - Embryo_Cell tmp; + { + Embryo_Cell tmp; - tmp = src[i]; - _embryo_byte_swap_32(&tmp); - str_cell[i] = tmp; - } + tmp = src[i]; + _embryo_byte_swap_32(&tmp); + str_cell[i] = tmp; + } #else - str_cell[i] = src[i]; + str_cell[i] = src[i]; #endif } str_cell[i] = 0; @@ -732,11 +727,10 @@ embryo_data_address_get(Embryo_Program *ep, Embryo_Cell addr) return (Embryo_Cell *)(data + (int)addr); } - EAPI Embryo_Cell embryo_data_heap_push(Embryo_Program *ep, int cells) { - Embryo_Cell addr; + Embryo_Cell addr; if ((!ep) || (!ep->base)) return EMBRYO_CELL_NONE; if (ep->stk - ep->hea - (cells * sizeof(Embryo_Cell)) < STKMARGIN) @@ -754,7 +748,6 @@ embryo_data_heap_pop(Embryo_Program *ep, Embryo_Cell down_to) if (ep->hea > down_to) ep->hea = down_to; } - EAPI int embryo_program_recursion_get(Embryo_Program *ep) { @@ -771,30 +764,31 @@ embryo_program_recursion_get(Embryo_Program *ep) #ifdef EMBRYO_EXEC_JUMPTABLE #define SWITCH(x) while (1) { goto *switchtable[x]; #define SWITCHEND break; } -#define CASE(x) SWITCHTABLE_##x: -#define BREAK break; +#define CASE(x) SWITCHTABLE_##x : +#define BREAK break; #else #define SWITCH(x) switch (x) { #define SWITCHEND } -#define CASE(x) case x: -#define BREAK break + +#define CASE(x) case x: +#define BREAK break #endif EAPI Embryo_Status embryo_program_run(Embryo_Program *ep, Embryo_Function fn) { - Embryo_Header *hdr; + Embryo_Header *hdr; Embryo_Func_Stub *func; - unsigned char *code, *data; - Embryo_Cell pri, alt, stk, frm, hea, hea_start; - Embryo_Cell reset_stk, reset_hea, *cip; - Embryo_UCell codesize; - int i; - unsigned char op; - Embryo_Cell offs; - int num; - int max_run_cycles; - int cycle_count; + unsigned char *code, *data; + Embryo_Cell pri, alt, stk, frm, hea, hea_start; + Embryo_Cell reset_stk, reset_hea, *cip; + Embryo_UCell codesize; + int i; + unsigned char op; + Embryo_Cell offs; + int num; + int max_run_cycles; + int cycle_count; #ifdef EMBRYO_EXEC_JUMPTABLE /* we limit the jumptable to 256 elements. why? above we forced "op" to be * a unsigned char - that means 256 max values. we limit opcode overflow @@ -804,186 +798,186 @@ embryo_program_run(Embryo_Program *ep, Embryo_Function fn) * keep them innocuous. */ static const void *switchtable[256] = - { - &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_LOAD_PRI, - &&SWITCHTABLE_EMBRYO_OP_LOAD_ALT, - &&SWITCHTABLE_EMBRYO_OP_LOAD_S_PRI, - &&SWITCHTABLE_EMBRYO_OP_LOAD_S_ALT, - &&SWITCHTABLE_EMBRYO_OP_LREF_PRI, - &&SWITCHTABLE_EMBRYO_OP_LREF_ALT, - &&SWITCHTABLE_EMBRYO_OP_LREF_S_PRI, - &&SWITCHTABLE_EMBRYO_OP_LREF_S_ALT, - &&SWITCHTABLE_EMBRYO_OP_LOAD_I, - &&SWITCHTABLE_EMBRYO_OP_LODB_I, - &&SWITCHTABLE_EMBRYO_OP_CONST_PRI, - &&SWITCHTABLE_EMBRYO_OP_CONST_ALT, - &&SWITCHTABLE_EMBRYO_OP_ADDR_PRI, - &&SWITCHTABLE_EMBRYO_OP_ADDR_ALT, - &&SWITCHTABLE_EMBRYO_OP_STOR_PRI, - &&SWITCHTABLE_EMBRYO_OP_STOR_ALT, - &&SWITCHTABLE_EMBRYO_OP_STOR_S_PRI, - &&SWITCHTABLE_EMBRYO_OP_STOR_S_ALT, - &&SWITCHTABLE_EMBRYO_OP_SREF_PRI, - &&SWITCHTABLE_EMBRYO_OP_SREF_ALT, - &&SWITCHTABLE_EMBRYO_OP_SREF_S_PRI, - &&SWITCHTABLE_EMBRYO_OP_SREF_S_ALT, - &&SWITCHTABLE_EMBRYO_OP_STOR_I, - &&SWITCHTABLE_EMBRYO_OP_STRB_I, - &&SWITCHTABLE_EMBRYO_OP_LIDX, - &&SWITCHTABLE_EMBRYO_OP_LIDX_B, - &&SWITCHTABLE_EMBRYO_OP_IDXADDR, - &&SWITCHTABLE_EMBRYO_OP_IDXADDR_B, - &&SWITCHTABLE_EMBRYO_OP_ALIGN_PRI, - &&SWITCHTABLE_EMBRYO_OP_ALIGN_ALT, - &&SWITCHTABLE_EMBRYO_OP_LCTRL, - &&SWITCHTABLE_EMBRYO_OP_SCTRL, - &&SWITCHTABLE_EMBRYO_OP_MOVE_PRI, - &&SWITCHTABLE_EMBRYO_OP_MOVE_ALT, - &&SWITCHTABLE_EMBRYO_OP_XCHG, - &&SWITCHTABLE_EMBRYO_OP_PUSH_PRI, - &&SWITCHTABLE_EMBRYO_OP_PUSH_ALT, - &&SWITCHTABLE_EMBRYO_OP_PUSH_R, - &&SWITCHTABLE_EMBRYO_OP_PUSH_C, - &&SWITCHTABLE_EMBRYO_OP_PUSH, - &&SWITCHTABLE_EMBRYO_OP_PUSH_S, - &&SWITCHTABLE_EMBRYO_OP_POP_PRI, - &&SWITCHTABLE_EMBRYO_OP_POP_ALT, - &&SWITCHTABLE_EMBRYO_OP_STACK, - &&SWITCHTABLE_EMBRYO_OP_HEAP, - &&SWITCHTABLE_EMBRYO_OP_PROC, - &&SWITCHTABLE_EMBRYO_OP_RET, - &&SWITCHTABLE_EMBRYO_OP_RETN, - &&SWITCHTABLE_EMBRYO_OP_CALL, - &&SWITCHTABLE_EMBRYO_OP_CALL_PRI, - &&SWITCHTABLE_EMBRYO_OP_JUMP, - &&SWITCHTABLE_EMBRYO_OP_JREL, - &&SWITCHTABLE_EMBRYO_OP_JZER, - &&SWITCHTABLE_EMBRYO_OP_JNZ, - &&SWITCHTABLE_EMBRYO_OP_JEQ, - &&SWITCHTABLE_EMBRYO_OP_JNEQ, - &&SWITCHTABLE_EMBRYO_OP_JLESS, - &&SWITCHTABLE_EMBRYO_OP_JLEQ, - &&SWITCHTABLE_EMBRYO_OP_JGRTR, - &&SWITCHTABLE_EMBRYO_OP_JGEQ, - &&SWITCHTABLE_EMBRYO_OP_JSLESS, - &&SWITCHTABLE_EMBRYO_OP_JSLEQ, - &&SWITCHTABLE_EMBRYO_OP_JSGRTR, - &&SWITCHTABLE_EMBRYO_OP_JSGEQ, - &&SWITCHTABLE_EMBRYO_OP_SHL, - &&SWITCHTABLE_EMBRYO_OP_SHR, - &&SWITCHTABLE_EMBRYO_OP_SSHR, - &&SWITCHTABLE_EMBRYO_OP_SHL_C_PRI, - &&SWITCHTABLE_EMBRYO_OP_SHL_C_ALT, - &&SWITCHTABLE_EMBRYO_OP_SHR_C_PRI, - &&SWITCHTABLE_EMBRYO_OP_SHR_C_ALT, - &&SWITCHTABLE_EMBRYO_OP_SMUL, - &&SWITCHTABLE_EMBRYO_OP_SDIV, - &&SWITCHTABLE_EMBRYO_OP_SDIV_ALT, - &&SWITCHTABLE_EMBRYO_OP_UMUL, - &&SWITCHTABLE_EMBRYO_OP_UDIV, - &&SWITCHTABLE_EMBRYO_OP_UDIV_ALT, - &&SWITCHTABLE_EMBRYO_OP_ADD, - &&SWITCHTABLE_EMBRYO_OP_SUB, - &&SWITCHTABLE_EMBRYO_OP_SUB_ALT, - &&SWITCHTABLE_EMBRYO_OP_AND, - &&SWITCHTABLE_EMBRYO_OP_OR, - &&SWITCHTABLE_EMBRYO_OP_XOR, - &&SWITCHTABLE_EMBRYO_OP_NOT, - &&SWITCHTABLE_EMBRYO_OP_NEG, - &&SWITCHTABLE_EMBRYO_OP_INVERT, - &&SWITCHTABLE_EMBRYO_OP_ADD_C, - &&SWITCHTABLE_EMBRYO_OP_SMUL_C, - &&SWITCHTABLE_EMBRYO_OP_ZERO_PRI, - &&SWITCHTABLE_EMBRYO_OP_ZERO_ALT, - &&SWITCHTABLE_EMBRYO_OP_ZERO, - &&SWITCHTABLE_EMBRYO_OP_ZERO_S, - &&SWITCHTABLE_EMBRYO_OP_SIGN_PRI, - &&SWITCHTABLE_EMBRYO_OP_SIGN_ALT, - &&SWITCHTABLE_EMBRYO_OP_EQ, - &&SWITCHTABLE_EMBRYO_OP_NEQ, - &&SWITCHTABLE_EMBRYO_OP_LESS, - &&SWITCHTABLE_EMBRYO_OP_LEQ, - &&SWITCHTABLE_EMBRYO_OP_GRTR, - &&SWITCHTABLE_EMBRYO_OP_GEQ, - &&SWITCHTABLE_EMBRYO_OP_SLESS, - &&SWITCHTABLE_EMBRYO_OP_SLEQ, - &&SWITCHTABLE_EMBRYO_OP_SGRTR, - &&SWITCHTABLE_EMBRYO_OP_SGEQ, - &&SWITCHTABLE_EMBRYO_OP_EQ_C_PRI, - &&SWITCHTABLE_EMBRYO_OP_EQ_C_ALT, - &&SWITCHTABLE_EMBRYO_OP_INC_PRI, - &&SWITCHTABLE_EMBRYO_OP_INC_ALT, - &&SWITCHTABLE_EMBRYO_OP_INC, - &&SWITCHTABLE_EMBRYO_OP_INC_S, - &&SWITCHTABLE_EMBRYO_OP_INC_I, - &&SWITCHTABLE_EMBRYO_OP_DEC_PRI, - &&SWITCHTABLE_EMBRYO_OP_DEC_ALT, - &&SWITCHTABLE_EMBRYO_OP_DEC, - &&SWITCHTABLE_EMBRYO_OP_DEC_S, - &&SWITCHTABLE_EMBRYO_OP_DEC_I, - &&SWITCHTABLE_EMBRYO_OP_MOVS, - &&SWITCHTABLE_EMBRYO_OP_CMPS, - &&SWITCHTABLE_EMBRYO_OP_FILL, - &&SWITCHTABLE_EMBRYO_OP_HALT, - &&SWITCHTABLE_EMBRYO_OP_BOUNDS, - &&SWITCHTABLE_EMBRYO_OP_SYSREQ_PRI, - &&SWITCHTABLE_EMBRYO_OP_SYSREQ_C, - &&SWITCHTABLE_EMBRYO_OP_FILE, - &&SWITCHTABLE_EMBRYO_OP_LINE, - &&SWITCHTABLE_EMBRYO_OP_SYMBOL, - &&SWITCHTABLE_EMBRYO_OP_SRANGE, - &&SWITCHTABLE_EMBRYO_OP_JUMP_PRI, - &&SWITCHTABLE_EMBRYO_OP_SWITCH, - &&SWITCHTABLE_EMBRYO_OP_CASETBL, - &&SWITCHTABLE_EMBRYO_OP_SWAP_PRI, - &&SWITCHTABLE_EMBRYO_OP_SWAP_ALT, - &&SWITCHTABLE_EMBRYO_OP_PUSHADDR, - &&SWITCHTABLE_EMBRYO_OP_NOP, - &&SWITCHTABLE_EMBRYO_OP_SYSREQ_D, - &&SWITCHTABLE_EMBRYO_OP_SYMTAG, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, - &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE, &&SWITCHTABLE_EMBRYO_OP_NONE - }; + { + && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_LOAD_PRI, + && SWITCHTABLE_EMBRYO_OP_LOAD_ALT, + && SWITCHTABLE_EMBRYO_OP_LOAD_S_PRI, + && SWITCHTABLE_EMBRYO_OP_LOAD_S_ALT, + && SWITCHTABLE_EMBRYO_OP_LREF_PRI, + && SWITCHTABLE_EMBRYO_OP_LREF_ALT, + && SWITCHTABLE_EMBRYO_OP_LREF_S_PRI, + && SWITCHTABLE_EMBRYO_OP_LREF_S_ALT, + && SWITCHTABLE_EMBRYO_OP_LOAD_I, + && SWITCHTABLE_EMBRYO_OP_LODB_I, + && SWITCHTABLE_EMBRYO_OP_CONST_PRI, + && SWITCHTABLE_EMBRYO_OP_CONST_ALT, + && SWITCHTABLE_EMBRYO_OP_ADDR_PRI, + && SWITCHTABLE_EMBRYO_OP_ADDR_ALT, + && SWITCHTABLE_EMBRYO_OP_STOR_PRI, + && SWITCHTABLE_EMBRYO_OP_STOR_ALT, + && SWITCHTABLE_EMBRYO_OP_STOR_S_PRI, + && SWITCHTABLE_EMBRYO_OP_STOR_S_ALT, + && SWITCHTABLE_EMBRYO_OP_SREF_PRI, + && SWITCHTABLE_EMBRYO_OP_SREF_ALT, + && SWITCHTABLE_EMBRYO_OP_SREF_S_PRI, + && SWITCHTABLE_EMBRYO_OP_SREF_S_ALT, + && SWITCHTABLE_EMBRYO_OP_STOR_I, + && SWITCHTABLE_EMBRYO_OP_STRB_I, + && SWITCHTABLE_EMBRYO_OP_LIDX, + && SWITCHTABLE_EMBRYO_OP_LIDX_B, + && SWITCHTABLE_EMBRYO_OP_IDXADDR, + && SWITCHTABLE_EMBRYO_OP_IDXADDR_B, + && SWITCHTABLE_EMBRYO_OP_ALIGN_PRI, + && SWITCHTABLE_EMBRYO_OP_ALIGN_ALT, + && SWITCHTABLE_EMBRYO_OP_LCTRL, + && SWITCHTABLE_EMBRYO_OP_SCTRL, + && SWITCHTABLE_EMBRYO_OP_MOVE_PRI, + && SWITCHTABLE_EMBRYO_OP_MOVE_ALT, + && SWITCHTABLE_EMBRYO_OP_XCHG, + && SWITCHTABLE_EMBRYO_OP_PUSH_PRI, + && SWITCHTABLE_EMBRYO_OP_PUSH_ALT, + && SWITCHTABLE_EMBRYO_OP_PUSH_R, + && SWITCHTABLE_EMBRYO_OP_PUSH_C, + && SWITCHTABLE_EMBRYO_OP_PUSH, + && SWITCHTABLE_EMBRYO_OP_PUSH_S, + && SWITCHTABLE_EMBRYO_OP_POP_PRI, + && SWITCHTABLE_EMBRYO_OP_POP_ALT, + && SWITCHTABLE_EMBRYO_OP_STACK, + && SWITCHTABLE_EMBRYO_OP_HEAP, + && SWITCHTABLE_EMBRYO_OP_PROC, + && SWITCHTABLE_EMBRYO_OP_RET, + && SWITCHTABLE_EMBRYO_OP_RETN, + && SWITCHTABLE_EMBRYO_OP_CALL, + && SWITCHTABLE_EMBRYO_OP_CALL_PRI, + && SWITCHTABLE_EMBRYO_OP_JUMP, + && SWITCHTABLE_EMBRYO_OP_JREL, + && SWITCHTABLE_EMBRYO_OP_JZER, + && SWITCHTABLE_EMBRYO_OP_JNZ, + && SWITCHTABLE_EMBRYO_OP_JEQ, + && SWITCHTABLE_EMBRYO_OP_JNEQ, + && SWITCHTABLE_EMBRYO_OP_JLESS, + && SWITCHTABLE_EMBRYO_OP_JLEQ, + && SWITCHTABLE_EMBRYO_OP_JGRTR, + && SWITCHTABLE_EMBRYO_OP_JGEQ, + && SWITCHTABLE_EMBRYO_OP_JSLESS, + && SWITCHTABLE_EMBRYO_OP_JSLEQ, + && SWITCHTABLE_EMBRYO_OP_JSGRTR, + && SWITCHTABLE_EMBRYO_OP_JSGEQ, + && SWITCHTABLE_EMBRYO_OP_SHL, + && SWITCHTABLE_EMBRYO_OP_SHR, + && SWITCHTABLE_EMBRYO_OP_SSHR, + && SWITCHTABLE_EMBRYO_OP_SHL_C_PRI, + && SWITCHTABLE_EMBRYO_OP_SHL_C_ALT, + && SWITCHTABLE_EMBRYO_OP_SHR_C_PRI, + && SWITCHTABLE_EMBRYO_OP_SHR_C_ALT, + && SWITCHTABLE_EMBRYO_OP_SMUL, + && SWITCHTABLE_EMBRYO_OP_SDIV, + && SWITCHTABLE_EMBRYO_OP_SDIV_ALT, + && SWITCHTABLE_EMBRYO_OP_UMUL, + && SWITCHTABLE_EMBRYO_OP_UDIV, + && SWITCHTABLE_EMBRYO_OP_UDIV_ALT, + && SWITCHTABLE_EMBRYO_OP_ADD, + && SWITCHTABLE_EMBRYO_OP_SUB, + && SWITCHTABLE_EMBRYO_OP_SUB_ALT, + && SWITCHTABLE_EMBRYO_OP_AND, + && SWITCHTABLE_EMBRYO_OP_OR, + && SWITCHTABLE_EMBRYO_OP_XOR, + && SWITCHTABLE_EMBRYO_OP_NOT, + && SWITCHTABLE_EMBRYO_OP_NEG, + && SWITCHTABLE_EMBRYO_OP_INVERT, + && SWITCHTABLE_EMBRYO_OP_ADD_C, + && SWITCHTABLE_EMBRYO_OP_SMUL_C, + && SWITCHTABLE_EMBRYO_OP_ZERO_PRI, + && SWITCHTABLE_EMBRYO_OP_ZERO_ALT, + && SWITCHTABLE_EMBRYO_OP_ZERO, + && SWITCHTABLE_EMBRYO_OP_ZERO_S, + && SWITCHTABLE_EMBRYO_OP_SIGN_PRI, + && SWITCHTABLE_EMBRYO_OP_SIGN_ALT, + && SWITCHTABLE_EMBRYO_OP_EQ, + && SWITCHTABLE_EMBRYO_OP_NEQ, + && SWITCHTABLE_EMBRYO_OP_LESS, + && SWITCHTABLE_EMBRYO_OP_LEQ, + && SWITCHTABLE_EMBRYO_OP_GRTR, + && SWITCHTABLE_EMBRYO_OP_GEQ, + && SWITCHTABLE_EMBRYO_OP_SLESS, + && SWITCHTABLE_EMBRYO_OP_SLEQ, + && SWITCHTABLE_EMBRYO_OP_SGRTR, + && SWITCHTABLE_EMBRYO_OP_SGEQ, + && SWITCHTABLE_EMBRYO_OP_EQ_C_PRI, + && SWITCHTABLE_EMBRYO_OP_EQ_C_ALT, + && SWITCHTABLE_EMBRYO_OP_INC_PRI, + && SWITCHTABLE_EMBRYO_OP_INC_ALT, + && SWITCHTABLE_EMBRYO_OP_INC, + && SWITCHTABLE_EMBRYO_OP_INC_S, + && SWITCHTABLE_EMBRYO_OP_INC_I, + && SWITCHTABLE_EMBRYO_OP_DEC_PRI, + && SWITCHTABLE_EMBRYO_OP_DEC_ALT, + && SWITCHTABLE_EMBRYO_OP_DEC, + && SWITCHTABLE_EMBRYO_OP_DEC_S, + && SWITCHTABLE_EMBRYO_OP_DEC_I, + && SWITCHTABLE_EMBRYO_OP_MOVS, + && SWITCHTABLE_EMBRYO_OP_CMPS, + && SWITCHTABLE_EMBRYO_OP_FILL, + && SWITCHTABLE_EMBRYO_OP_HALT, + && SWITCHTABLE_EMBRYO_OP_BOUNDS, + && SWITCHTABLE_EMBRYO_OP_SYSREQ_PRI, + && SWITCHTABLE_EMBRYO_OP_SYSREQ_C, + && SWITCHTABLE_EMBRYO_OP_FILE, + && SWITCHTABLE_EMBRYO_OP_LINE, + && SWITCHTABLE_EMBRYO_OP_SYMBOL, + && SWITCHTABLE_EMBRYO_OP_SRANGE, + && SWITCHTABLE_EMBRYO_OP_JUMP_PRI, + && SWITCHTABLE_EMBRYO_OP_SWITCH, + && SWITCHTABLE_EMBRYO_OP_CASETBL, + && SWITCHTABLE_EMBRYO_OP_SWAP_PRI, + && SWITCHTABLE_EMBRYO_OP_SWAP_ALT, + && SWITCHTABLE_EMBRYO_OP_PUSHADDR, + && SWITCHTABLE_EMBRYO_OP_NOP, + && SWITCHTABLE_EMBRYO_OP_SYSREQ_D, + && SWITCHTABLE_EMBRYO_OP_SYMTAG, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, + && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE, && SWITCHTABLE_EMBRYO_OP_NONE + }; #endif if (!ep) return EMBRYO_PROGRAM_FAIL; if (!(ep->flags & EMBRYO_FLAG_RELOC)) { - ep->error = EMBRYO_ERROR_INIT; - return EMBRYO_PROGRAM_FAIL; + ep->error = EMBRYO_ERROR_INIT; + return EMBRYO_PROGRAM_FAIL; } if (!ep->base) { - ep->error = EMBRYO_ERROR_INIT; - return EMBRYO_PROGRAM_FAIL; + ep->error = EMBRYO_ERROR_INIT; + return EMBRYO_PROGRAM_FAIL; } if (ep->run_count > 0) { - /* return EMBRYO_PROGRAM_BUSY; */ - /* FIXME: test C->vm->C->vm recursion more fully */ - /* it seems to work... just fine!!! - strange! */ + /* return EMBRYO_PROGRAM_BUSY; */ + /* FIXME: test C->vm->C->vm recursion more fully */ + /* it seems to work... just fine!!! - strange! */ } /* set up the registers */ @@ -1000,39 +994,39 @@ embryo_program_run(Embryo_Program *ep, Embryo_Function fn) /* get the start address */ if (fn == EMBRYO_FUNCTION_MAIN) { - if (hdr->cip < 0) - { - ep->error = EMBRYO_ERROR_INDEX; - return EMBRYO_PROGRAM_FAIL; - } - cip = (Embryo_Cell *)(code + (int)hdr->cip); + if (hdr->cip < 0) + { + ep->error = EMBRYO_ERROR_INDEX; + return EMBRYO_PROGRAM_FAIL; + } + cip = (Embryo_Cell *)(code + (int)hdr->cip); } else if (fn == EMBRYO_FUNCTION_CONT) { - /* all registers: pri, alt, frm, cip, hea, stk, reset_stk, reset_hea */ - frm = ep->frm; - stk = ep->stk; - hea = ep->hea; - pri = ep->pri; - alt = ep->alt; - reset_stk = ep->reset_stk; - reset_hea = ep->reset_hea; - cip = (Embryo_Cell *)(code + (int)ep->cip); + /* all registers: pri, alt, frm, cip, hea, stk, reset_stk, reset_hea */ + frm = ep->frm; + stk = ep->stk; + hea = ep->hea; + pri = ep->pri; + alt = ep->alt; + reset_stk = ep->reset_stk; + reset_hea = ep->reset_hea; + cip = (Embryo_Cell *)(code + (int)ep->cip); } else if (fn < 0) { - ep->error = EMBRYO_ERROR_INDEX; - return EMBRYO_PROGRAM_FAIL; + ep->error = EMBRYO_ERROR_INDEX; + return EMBRYO_PROGRAM_FAIL; } else { - if (fn >= (Embryo_Cell)NUMENTRIES(hdr, publics, natives)) - { - ep->error = EMBRYO_ERROR_INDEX; - return EMBRYO_PROGRAM_FAIL; - } - func = GETENTRY(hdr, publics, fn); - cip = (Embryo_Cell *)(code + (int)func->address); + if (fn >= (Embryo_Cell)NUMENTRIES(hdr, publics, natives)) + { + ep->error = EMBRYO_ERROR_INDEX; + return EMBRYO_PROGRAM_FAIL; + } + func = GETENTRY(hdr, publics, fn); + cip = (Embryo_Cell *)(code + (int)func->address); } /* check values just copied */ CHKSTACK(); @@ -1040,73 +1034,73 @@ embryo_program_run(Embryo_Program *ep, Embryo_Function fn) if (fn != EMBRYO_FUNCTION_CONT) { - int j; - - for (j = ep->params_size - 1; j >= 0; j--) - { - Embryo_Param *pr; - - pr = &(ep->params[j]); - if (pr->string) - { - int len; - Embryo_Cell ep_addr, *addr; - - len = strlen(pr->string); - ep_addr = embryo_data_heap_push(ep, len + 1); - if (ep_addr == EMBRYO_CELL_NONE) - { - ep->error = EMBRYO_ERROR_HEAPLOW; - return EMBRYO_PROGRAM_FAIL; - } - addr = embryo_data_address_get(ep, ep_addr); - if (addr) - embryo_data_string_set(ep, pr->string, addr); - else - { - ep->error = EMBRYO_ERROR_HEAPLOW; - return EMBRYO_PROGRAM_FAIL; - } - PUSH(ep_addr); - free(pr->string); - } - else if (pr->cell_array) - { - int len; - Embryo_Cell ep_addr, *addr; - - len = pr->cell_array_size; - ep_addr = embryo_data_heap_push(ep, len + 1); - if (ep_addr == EMBRYO_CELL_NONE) - { - ep->error = EMBRYO_ERROR_HEAPLOW; - return EMBRYO_PROGRAM_FAIL; - } - addr = embryo_data_address_get(ep, ep_addr); - if (addr) - memcpy(addr, pr->cell_array, - pr->cell_array_size * sizeof(Embryo_Cell)); - else - { - ep->error = EMBRYO_ERROR_HEAPLOW; - return EMBRYO_PROGRAM_FAIL; - } - PUSH(ep_addr); - free(pr->cell_array); - } - else - { - PUSH(pr->cell); - } - } - PUSH(ep->params_size * sizeof(Embryo_Cell)); - PUSH(0); - if (ep->params) - { - free(ep->params); - ep->params = NULL; - } - ep->params_size = ep->params_alloc = 0; + int j; + + for (j = ep->params_size - 1; j >= 0; j--) + { + Embryo_Param *pr; + + pr = &(ep->params[j]); + if (pr->string) + { + int len; + Embryo_Cell ep_addr, *addr; + + len = strlen(pr->string); + ep_addr = embryo_data_heap_push(ep, len + 1); + if (ep_addr == EMBRYO_CELL_NONE) + { + ep->error = EMBRYO_ERROR_HEAPLOW; + return EMBRYO_PROGRAM_FAIL; + } + addr = embryo_data_address_get(ep, ep_addr); + if (addr) + embryo_data_string_set(ep, pr->string, addr); + else + { + ep->error = EMBRYO_ERROR_HEAPLOW; + return EMBRYO_PROGRAM_FAIL; + } + PUSH(ep_addr); + free(pr->string); + } + else if (pr->cell_array) + { + int len; + Embryo_Cell ep_addr, *addr; + + len = pr->cell_array_size; + ep_addr = embryo_data_heap_push(ep, len + 1); + if (ep_addr == EMBRYO_CELL_NONE) + { + ep->error = EMBRYO_ERROR_HEAPLOW; + return EMBRYO_PROGRAM_FAIL; + } + addr = embryo_data_address_get(ep, ep_addr); + if (addr) + memcpy(addr, pr->cell_array, + pr->cell_array_size * sizeof(Embryo_Cell)); + else + { + ep->error = EMBRYO_ERROR_HEAPLOW; + return EMBRYO_PROGRAM_FAIL; + } + PUSH(ep_addr); + free(pr->cell_array); + } + else + { + PUSH(pr->cell); + } + } + PUSH(ep->params_size * sizeof(Embryo_Cell)); + PUSH(0); + if (ep->params) + { + free(ep->params); + ep->params = NULL; + } + ep->params_size = ep->params_alloc = 0; } /* check stack/heap before starting to run */ CHKMARGIN(); @@ -1116,771 +1110,791 @@ embryo_program_run(Embryo_Program *ep, Embryo_Function fn) max_run_cycles = ep->max_run_cycles; /* start running */ - for (cycle_count = 0;;) + for (cycle_count = 0;; ) { - if (max_run_cycles > 0) - { - if (cycle_count >= max_run_cycles) - { - TOOLONG(ep); - } - cycle_count++; - } - op = (Embryo_Opcode)*cip++; - SWITCH(op); - CASE(EMBRYO_OP_LOAD_PRI); - GETPARAM(offs); - pri = *(Embryo_Cell *)(data + (int)offs); - BREAK; - CASE(EMBRYO_OP_LOAD_ALT); - GETPARAM(offs); - alt = *(Embryo_Cell *)(data + (int)offs); - BREAK; - CASE(EMBRYO_OP_LOAD_S_PRI); - GETPARAM(offs); - pri = *(Embryo_Cell *)(data + (int)frm + (int)offs); - BREAK; - CASE(EMBRYO_OP_LOAD_S_ALT); - GETPARAM(offs); - alt = *(Embryo_Cell *)(data + (int)frm + (int)offs); - BREAK; - CASE(EMBRYO_OP_LREF_PRI); - GETPARAM(offs); - offs = *(Embryo_Cell *)(data + (int)offs); - pri = *(Embryo_Cell *)(data + (int)offs); - BREAK; - CASE(EMBRYO_OP_LREF_ALT); - GETPARAM(offs); - offs = *(Embryo_Cell *)(data + (int)offs); - alt = *(Embryo_Cell *)(data + (int)offs); - BREAK; - CASE(EMBRYO_OP_LREF_S_PRI); - GETPARAM(offs); - offs = *(Embryo_Cell *)(data + (int)frm + (int)offs); - pri = *(Embryo_Cell *)(data + (int)offs); - BREAK; - CASE(EMBRYO_OP_LREF_S_ALT); - GETPARAM(offs); - offs = *(Embryo_Cell *)(data + (int)frm + (int)offs); - alt = *(Embryo_Cell *)(data + (int)offs); - BREAK; - CASE(EMBRYO_OP_LOAD_I); - CHKMEM(pri); - pri = *(Embryo_Cell *)(data + (int)pri); - BREAK; - CASE(EMBRYO_OP_LODB_I); - GETPARAM(offs); - CHKMEM(pri); - switch (offs) - { - case 1: - pri = *(data + (int)pri); - break; - case 2: - pri = *(unsigned short *)(data + (int)pri); - break; - case 4: - pri = *(unsigned int *)(data + (int)pri); - break; - default: - ABORT(ep, EMBRYO_ERROR_INVINSTR); - break; - } - BREAK; - CASE(EMBRYO_OP_CONST_PRI); - GETPARAM(pri); - BREAK; - CASE(EMBRYO_OP_CONST_ALT); - GETPARAM(alt); - BREAK; - CASE(EMBRYO_OP_ADDR_PRI); - GETPARAM(pri); - pri += frm; - BREAK; - CASE(EMBRYO_OP_ADDR_ALT); - GETPARAM(alt); - alt += frm; - BREAK; - CASE(EMBRYO_OP_STOR_PRI); - GETPARAM(offs); - *(Embryo_Cell *)(data + (int)offs) = pri; - BREAK; - CASE(EMBRYO_OP_STOR_ALT); - GETPARAM(offs); - *(Embryo_Cell *)(data + (int)offs) = alt; - BREAK; - CASE(EMBRYO_OP_STOR_S_PRI); - GETPARAM(offs); - *(Embryo_Cell *)(data + (int)frm + (int)offs) = pri; - BREAK; - CASE(EMBRYO_OP_STOR_S_ALT); - GETPARAM(offs); - *(Embryo_Cell *)(data + (int)frm + (int)offs) = alt; - BREAK; - CASE(EMBRYO_OP_SREF_PRI); - GETPARAM(offs); - offs = *(Embryo_Cell *)(data + (int)offs); - *(Embryo_Cell *)(data + (int)offs) = pri; - BREAK; - CASE(EMBRYO_OP_SREF_ALT); - GETPARAM(offs); - offs = *(Embryo_Cell *)(data + (int)offs); - *(Embryo_Cell *)(data + (int)offs) = alt; - BREAK; - CASE(EMBRYO_OP_SREF_S_PRI); - GETPARAM(offs); - offs = *(Embryo_Cell *)(data + (int)frm + (int)offs); - *(Embryo_Cell *)(data + (int)offs) = pri; - BREAK; - CASE(EMBRYO_OP_SREF_S_ALT); - GETPARAM(offs); - offs = *(Embryo_Cell *)(data + (int)frm + (int)offs); - *(Embryo_Cell *)(data + (int)offs) = alt; - BREAK; - CASE(EMBRYO_OP_STOR_I); - CHKMEM(alt); - *(Embryo_Cell *)(data + (int)alt) = pri; - BREAK; - CASE(EMBRYO_OP_STRB_I); - GETPARAM(offs); - CHKMEM(alt); - switch (offs) - { - case 1: - *(data + (int)alt) = (unsigned char)pri; - break; - case 2: - *(unsigned short *)(data + (int)alt) = (unsigned short)pri; - break; - case 4: - *(unsigned int *)(data + (int)alt) = (unsigned int)pri; - break; - default: - ABORT(ep, EMBRYO_ERROR_INVINSTR); - break; - } - BREAK; - CASE(EMBRYO_OP_LIDX); - offs = (pri * sizeof(Embryo_Cell)) + alt; - CHKMEM(offs); - pri = *(Embryo_Cell *)(data + (int)offs); - BREAK; - CASE(EMBRYO_OP_LIDX_B); - GETPARAM(offs); - offs = (pri << (int)offs) + alt; - CHKMEM(offs); - pri = *(Embryo_Cell *)(data + (int)offs); - BREAK; - CASE(EMBRYO_OP_IDXADDR); - pri = (pri * sizeof(Embryo_Cell)) + alt; - BREAK; - CASE(EMBRYO_OP_IDXADDR_B); - GETPARAM(offs); - pri = (pri << (int)offs) + alt; - BREAK; - CASE(EMBRYO_OP_ALIGN_PRI); - GETPARAM(offs); + if (max_run_cycles > 0) + { + if (cycle_count >= max_run_cycles) + { + TOOLONG(ep); + } + cycle_count++; + } + op = (Embryo_Opcode) * cip++; + SWITCH(op); + CASE(EMBRYO_OP_LOAD_PRI); + GETPARAM(offs); + pri = *(Embryo_Cell *)(data + (int)offs); + BREAK; + CASE(EMBRYO_OP_LOAD_ALT); + GETPARAM(offs); + alt = *(Embryo_Cell *)(data + (int)offs); + BREAK; + CASE(EMBRYO_OP_LOAD_S_PRI); + GETPARAM(offs); + pri = *(Embryo_Cell *)(data + (int)frm + (int)offs); + BREAK; + CASE(EMBRYO_OP_LOAD_S_ALT); + GETPARAM(offs); + alt = *(Embryo_Cell *)(data + (int)frm + (int)offs); + BREAK; + CASE(EMBRYO_OP_LREF_PRI); + GETPARAM(offs); + offs = *(Embryo_Cell *)(data + (int)offs); + pri = *(Embryo_Cell *)(data + (int)offs); + BREAK; + CASE(EMBRYO_OP_LREF_ALT); + GETPARAM(offs); + offs = *(Embryo_Cell *)(data + (int)offs); + alt = *(Embryo_Cell *)(data + (int)offs); + BREAK; + CASE(EMBRYO_OP_LREF_S_PRI); + GETPARAM(offs); + offs = *(Embryo_Cell *)(data + (int)frm + (int)offs); + pri = *(Embryo_Cell *)(data + (int)offs); + BREAK; + CASE(EMBRYO_OP_LREF_S_ALT); + GETPARAM(offs); + offs = *(Embryo_Cell *)(data + (int)frm + (int)offs); + alt = *(Embryo_Cell *)(data + (int)offs); + BREAK; + CASE(EMBRYO_OP_LOAD_I); + CHKMEM(pri); + pri = *(Embryo_Cell *)(data + (int)pri); + BREAK; + CASE(EMBRYO_OP_LODB_I); + GETPARAM(offs); + CHKMEM(pri); + switch (offs) + { + case 1: + pri = *(data + (int)pri); + break; + + case 2: + pri = *(unsigned short *)(data + (int)pri); + break; + + case 4: + pri = *(unsigned int *)(data + (int)pri); + break; + + default: + ABORT(ep, EMBRYO_ERROR_INVINSTR); + break; + } + BREAK; + CASE(EMBRYO_OP_CONST_PRI); + GETPARAM(pri); + BREAK; + CASE(EMBRYO_OP_CONST_ALT); + GETPARAM(alt); + BREAK; + CASE(EMBRYO_OP_ADDR_PRI); + GETPARAM(pri); + pri += frm; + BREAK; + CASE(EMBRYO_OP_ADDR_ALT); + GETPARAM(alt); + alt += frm; + BREAK; + CASE(EMBRYO_OP_STOR_PRI); + GETPARAM(offs); + *(Embryo_Cell *)(data + (int)offs) = pri; + BREAK; + CASE(EMBRYO_OP_STOR_ALT); + GETPARAM(offs); + *(Embryo_Cell *)(data + (int)offs) = alt; + BREAK; + CASE(EMBRYO_OP_STOR_S_PRI); + GETPARAM(offs); + *(Embryo_Cell *)(data + (int)frm + (int)offs) = pri; + BREAK; + CASE(EMBRYO_OP_STOR_S_ALT); + GETPARAM(offs); + *(Embryo_Cell *)(data + (int)frm + (int)offs) = alt; + BREAK; + CASE(EMBRYO_OP_SREF_PRI); + GETPARAM(offs); + offs = *(Embryo_Cell *)(data + (int)offs); + *(Embryo_Cell *)(data + (int)offs) = pri; + BREAK; + CASE(EMBRYO_OP_SREF_ALT); + GETPARAM(offs); + offs = *(Embryo_Cell *)(data + (int)offs); + *(Embryo_Cell *)(data + (int)offs) = alt; + BREAK; + CASE(EMBRYO_OP_SREF_S_PRI); + GETPARAM(offs); + offs = *(Embryo_Cell *)(data + (int)frm + (int)offs); + *(Embryo_Cell *)(data + (int)offs) = pri; + BREAK; + CASE(EMBRYO_OP_SREF_S_ALT); + GETPARAM(offs); + offs = *(Embryo_Cell *)(data + (int)frm + (int)offs); + *(Embryo_Cell *)(data + (int)offs) = alt; + BREAK; + CASE(EMBRYO_OP_STOR_I); + CHKMEM(alt); + *(Embryo_Cell *)(data + (int)alt) = pri; + BREAK; + CASE(EMBRYO_OP_STRB_I); + GETPARAM(offs); + CHKMEM(alt); + switch (offs) + { + case 1: + *(data + (int)alt) = (unsigned char)pri; + break; + + case 2: + *(unsigned short *)(data + (int)alt) = (unsigned short)pri; + break; + + case 4: + *(unsigned int *)(data + (int)alt) = (unsigned int)pri; + break; + + default: + ABORT(ep, EMBRYO_ERROR_INVINSTR); + break; + } + BREAK; + CASE(EMBRYO_OP_LIDX); + offs = (pri * sizeof(Embryo_Cell)) + alt; + CHKMEM(offs); + pri = *(Embryo_Cell *)(data + (int)offs); + BREAK; + CASE(EMBRYO_OP_LIDX_B); + GETPARAM(offs); + offs = (pri << (int)offs) + alt; + CHKMEM(offs); + pri = *(Embryo_Cell *)(data + (int)offs); + BREAK; + CASE(EMBRYO_OP_IDXADDR); + pri = (pri * sizeof(Embryo_Cell)) + alt; + BREAK; + CASE(EMBRYO_OP_IDXADDR_B); + GETPARAM(offs); + pri = (pri << (int)offs) + alt; + BREAK; + CASE(EMBRYO_OP_ALIGN_PRI); + GETPARAM(offs); #ifdef WORDS_BIGENDIAN - if ((size_t)offs < sizeof(Embryo_Cell)) - pri ^= sizeof(Embryo_Cell) - offs; + if ((size_t)offs < sizeof(Embryo_Cell)) + pri ^= sizeof(Embryo_Cell) - offs; #endif - BREAK; - CASE(EMBRYO_OP_ALIGN_ALT); - GETPARAM(offs); + BREAK; + CASE(EMBRYO_OP_ALIGN_ALT); + GETPARAM(offs); #ifdef WORDS_BIGENDIAN - if ((size_t)offs < sizeof(Embryo_Cell)) - alt ^= sizeof(Embryo_Cell) - offs; + if ((size_t)offs < sizeof(Embryo_Cell)) + alt ^= sizeof(Embryo_Cell) - offs; #endif - BREAK; - CASE(EMBRYO_OP_LCTRL); - GETPARAM(offs); - switch (offs) - { - case 0: - pri = hdr->cod; - break; - case 1: - pri = hdr->dat; - break; - case 2: - pri = hea; - break; - case 3: - pri = ep->stp; - break; - case 4: - pri = stk; - break; - case 5: - pri = frm; - break; - case 6: - pri = (Embryo_Cell)((unsigned char *)cip - code); - break; - default: - ABORT(ep, EMBRYO_ERROR_INVINSTR); - break; - } - BREAK; - CASE(EMBRYO_OP_SCTRL); - GETPARAM(offs); - switch (offs) - { - case 0: - case 1: - case 2: - hea = pri; - break; - case 3: - /* cannot change these parameters */ - break; - case 4: - stk = pri; - break; - case 5: - frm = pri; - break; - case 6: - cip = (Embryo_Cell *)(code + (int)pri); - break; - default: - ABORT(ep, EMBRYO_ERROR_INVINSTR); - break; - } - BREAK; - CASE(EMBRYO_OP_MOVE_PRI); - pri = alt; - BREAK; - CASE(EMBRYO_OP_MOVE_ALT); - alt = pri; - BREAK; - CASE(EMBRYO_OP_XCHG); - offs = pri; /* offs is a temporary variable */ - pri = alt; - alt = offs; - BREAK; - CASE(EMBRYO_OP_PUSH_PRI); - PUSH(pri); - BREAK; - CASE(EMBRYO_OP_PUSH_ALT); - PUSH(alt); - BREAK; - CASE(EMBRYO_OP_PUSH_C); - GETPARAM(offs); - PUSH(offs); - BREAK; - CASE(EMBRYO_OP_PUSH_R); - GETPARAM(offs); - while (offs--) PUSH(pri); - BREAK; - CASE(EMBRYO_OP_PUSH); - GETPARAM(offs); - PUSH(*(Embryo_Cell *)(data + (int)offs)); - BREAK; - CASE(EMBRYO_OP_PUSH_S); - GETPARAM(offs); - PUSH(*(Embryo_Cell *)(data + (int)frm + (int)offs)); - BREAK; - CASE(EMBRYO_OP_POP_PRI); - POP(pri); - BREAK; - CASE(EMBRYO_OP_POP_ALT); - POP(alt); - BREAK; - CASE(EMBRYO_OP_STACK); - GETPARAM(offs); - alt = stk; - stk += offs; - CHKMARGIN(); - CHKSTACK(); - BREAK; - CASE(EMBRYO_OP_HEAP); - GETPARAM(offs); - alt = hea; - hea += offs; - CHKMARGIN(); - CHKHEAP(); - BREAK; - CASE(EMBRYO_OP_PROC); - PUSH(frm); - frm = stk; - CHKMARGIN(); - BREAK; - CASE(EMBRYO_OP_RET); - POP(frm); - POP(offs); - if ((Embryo_UCell)offs >= codesize) - ABORT(ep, EMBRYO_ERROR_MEMACCESS); - cip = (Embryo_Cell *)(code + (int)offs); - BREAK; - CASE(EMBRYO_OP_RETN); - POP(frm); - POP(offs); - if ((Embryo_UCell)offs >= codesize) - ABORT(ep, EMBRYO_ERROR_MEMACCESS); - cip = (Embryo_Cell *)(code + (int)offs); - stk += *(Embryo_Cell *)(data + (int)stk) + sizeof(Embryo_Cell); /* remove parameters from the stack */ - ep->stk = stk; - BREAK; - CASE(EMBRYO_OP_CALL); - PUSH(((unsigned char *)cip - code) + sizeof(Embryo_Cell));/* skip address */ - cip = JUMPABS(code, cip); /* jump to the address */ - BREAK; - CASE(EMBRYO_OP_CALL_PRI); - PUSH((unsigned char *)cip - code); - cip = (Embryo_Cell *)(code + (int)pri); - BREAK; - CASE(EMBRYO_OP_JUMP); - /* since the GETPARAM() macro modifies cip, you cannot - * do GETPARAM(cip) directly */ - cip = JUMPABS(code, cip); - BREAK; - CASE(EMBRYO_OP_JREL); - offs = *cip; - cip = (Embryo_Cell *)((unsigned char *)cip + (int)offs + sizeof(Embryo_Cell)); - BREAK; - CASE(EMBRYO_OP_JZER); - if (pri == 0) - cip = JUMPABS(code, cip); - else - cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); - BREAK; - CASE(EMBRYO_OP_JNZ); - if (pri != 0) - cip = JUMPABS(code, cip); - else - cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); - BREAK; - CASE(EMBRYO_OP_JEQ); - if (pri==alt) - cip = JUMPABS(code, cip); - else - cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); - BREAK; - CASE(EMBRYO_OP_JNEQ); - if (pri != alt) - cip = JUMPABS(code, cip); - else - cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); - BREAK; - CASE(EMBRYO_OP_JLESS); - if ((Embryo_UCell)pri < (Embryo_UCell)alt) - cip = JUMPABS(code, cip); - else - cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); - BREAK; - CASE(EMBRYO_OP_JLEQ); - if ((Embryo_UCell)pri <= (Embryo_UCell)alt) - cip = JUMPABS(code, cip); - else - cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); - BREAK; - CASE(EMBRYO_OP_JGRTR); - if ((Embryo_UCell)pri > (Embryo_UCell)alt) - cip = JUMPABS(code, cip); - else - cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); - BREAK; - CASE(EMBRYO_OP_JGEQ); - if ((Embryo_UCell)pri >= (Embryo_UCell)alt) - cip = JUMPABS(code, cip); - else - cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); - BREAK; - CASE(EMBRYO_OP_JSLESS); - if (pri < alt) - cip = JUMPABS(code, cip); - else - cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); - BREAK; - CASE(EMBRYO_OP_JSLEQ); - if (pri <= alt) - cip = JUMPABS(code, cip); - else - cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); - BREAK; - CASE(EMBRYO_OP_JSGRTR); - if (pri > alt) - cip = JUMPABS(code, cip); - else - cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); - BREAK; - CASE(EMBRYO_OP_JSGEQ); - if (pri >= alt) - cip = JUMPABS(code, cip); - else - cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); - BREAK; - CASE(EMBRYO_OP_SHL); - pri <<= alt; - BREAK; - CASE(EMBRYO_OP_SHR); - pri = (Embryo_UCell)pri >> (int)alt; - BREAK; - CASE(EMBRYO_OP_SSHR); - pri >>= alt; - BREAK; - CASE(EMBRYO_OP_SHL_C_PRI); - GETPARAM(offs); - pri <<= offs; - BREAK; - CASE(EMBRYO_OP_SHL_C_ALT); - GETPARAM(offs); - alt <<= offs; - BREAK; - CASE(EMBRYO_OP_SHR_C_PRI); - GETPARAM(offs); - pri = (Embryo_UCell)pri >> (int)offs; - BREAK; - CASE(EMBRYO_OP_SHR_C_ALT); - GETPARAM(offs); - alt = (Embryo_UCell)alt >> (int)offs; - BREAK; - CASE(EMBRYO_OP_SMUL); - pri *= alt; - BREAK; - CASE(EMBRYO_OP_SDIV); - if (alt == 0) ABORT(ep, EMBRYO_ERROR_DIVIDE); - /* divide must always round down; this is a bit - * involved to do in a machine-independent way. - */ - offs = ((pri % alt) + alt) % alt; /* true modulus */ - pri = (pri - offs) / alt; /* division result */ - alt = offs; - BREAK; - CASE(EMBRYO_OP_SDIV_ALT); - if (pri == 0) ABORT(ep, EMBRYO_ERROR_DIVIDE); - /* divide must always round down; this is a bit - * involved to do in a machine-independent way. - */ - offs = ((alt % pri) + pri) % pri; /* true modulus */ - pri = (alt - offs) / pri; /* division result */ - alt = offs; - BREAK; - CASE(EMBRYO_OP_UMUL); - pri = (Embryo_UCell)pri * (Embryo_UCell)alt; - BREAK; - CASE(EMBRYO_OP_UDIV); - if (alt == 0) ABORT(ep, EMBRYO_ERROR_DIVIDE); - offs = (Embryo_UCell)pri % (Embryo_UCell)alt; /* temporary storage */ - pri = (Embryo_UCell)pri / (Embryo_UCell)alt; - alt = offs; - BREAK; - CASE(EMBRYO_OP_UDIV_ALT); - if (pri == 0) ABORT(ep, EMBRYO_ERROR_DIVIDE); - offs = (Embryo_UCell)alt % (Embryo_UCell)pri; /* temporary storage */ - pri = (Embryo_UCell)alt / (Embryo_UCell)pri; - alt = offs; - BREAK; - CASE(EMBRYO_OP_ADD); - pri += alt; - BREAK; - CASE(EMBRYO_OP_SUB); - pri -= alt; - BREAK; - CASE(EMBRYO_OP_SUB_ALT); - pri = alt - pri; - BREAK; - CASE(EMBRYO_OP_AND); - pri &= alt; - BREAK; - CASE(EMBRYO_OP_OR); - pri |= alt; - BREAK; - CASE(EMBRYO_OP_XOR); - pri ^= alt; - BREAK; - CASE(EMBRYO_OP_NOT); - pri = !pri; - BREAK; - CASE(EMBRYO_OP_NEG); - pri = -pri; - BREAK; - CASE(EMBRYO_OP_INVERT); - pri = ~pri; - BREAK; - CASE(EMBRYO_OP_ADD_C); - GETPARAM(offs); - pri += offs; - BREAK; - CASE(EMBRYO_OP_SMUL_C); - GETPARAM(offs); - pri *= offs; - BREAK; - CASE(EMBRYO_OP_ZERO_PRI); - pri = 0; - BREAK; - CASE(EMBRYO_OP_ZERO_ALT); - alt = 0; - BREAK; - CASE(EMBRYO_OP_ZERO); - GETPARAM(offs); - *(Embryo_Cell *)(data + (int)offs) = 0; - BREAK; - CASE(EMBRYO_OP_ZERO_S); - GETPARAM(offs); - *(Embryo_Cell *)(data + (int)frm + (int)offs) = 0; - BREAK; - CASE(EMBRYO_OP_SIGN_PRI); - if ((pri & 0xff) >= 0x80) pri |= ~(Embryo_UCell)0xff; - BREAK; - CASE(EMBRYO_OP_SIGN_ALT); - if ((alt & 0xff) >= 0x80) alt |= ~(Embryo_UCell)0xff; - BREAK; - CASE(EMBRYO_OP_EQ); - pri = (pri == alt) ? 1 : 0; - BREAK; - CASE(EMBRYO_OP_NEQ); - pri = (pri != alt) ? 1 : 0; - BREAK; - CASE(EMBRYO_OP_LESS); - pri = ((Embryo_UCell)pri < (Embryo_UCell)alt) ? 1 : 0; - BREAK; - CASE(EMBRYO_OP_LEQ); - pri = ((Embryo_UCell)pri <= (Embryo_UCell)alt) ? 1 : 0; - BREAK; - CASE(EMBRYO_OP_GRTR); - pri = ((Embryo_UCell)pri > (Embryo_UCell)alt) ? 1 : 0; - BREAK; - CASE(EMBRYO_OP_GEQ); - pri = ((Embryo_UCell)pri >= (Embryo_UCell)alt) ? 1 : 0; - BREAK; - CASE(EMBRYO_OP_SLESS); - pri = (pri < alt) ? 1 : 0; - BREAK; - CASE(EMBRYO_OP_SLEQ); - pri = (pri <= alt) ? 1 : 0; - BREAK; - CASE(EMBRYO_OP_SGRTR); - pri = (pri > alt) ? 1 : 0; - BREAK; - CASE(EMBRYO_OP_SGEQ); - pri = (pri >= alt) ? 1 : 0; - BREAK; - CASE(EMBRYO_OP_EQ_C_PRI); - GETPARAM(offs); - pri = (pri == offs) ? 1 : 0; - BREAK; - CASE(EMBRYO_OP_EQ_C_ALT); - GETPARAM(offs); - pri = (alt == offs) ? 1 : 0; - BREAK; - CASE(EMBRYO_OP_INC_PRI); - pri++; - BREAK; - CASE(EMBRYO_OP_INC_ALT); - alt++; - BREAK; - CASE(EMBRYO_OP_INC); - GETPARAM(offs); - *(Embryo_Cell *)(data + (int)offs) += 1; - BREAK; - CASE(EMBRYO_OP_INC_S); - GETPARAM(offs); - *(Embryo_Cell *)(data + (int)frm + (int)offs) += 1; - BREAK; - CASE(EMBRYO_OP_INC_I); - *(Embryo_Cell *)(data + (int)pri) += 1; - BREAK; - CASE(EMBRYO_OP_DEC_PRI); - pri--; - BREAK; - CASE(EMBRYO_OP_DEC_ALT); - alt--; - BREAK; - CASE(EMBRYO_OP_DEC); - GETPARAM(offs); - *(Embryo_Cell *)(data + (int)offs) -= 1; - BREAK; - CASE(EMBRYO_OP_DEC_S); - GETPARAM(offs); - *(Embryo_Cell *)(data + (int)frm + (int)offs) -= 1; - BREAK; - CASE(EMBRYO_OP_DEC_I); - *(Embryo_Cell *)(data + (int)pri) -= 1; - BREAK; - CASE(EMBRYO_OP_MOVS); - GETPARAM(offs); - CHKMEM(pri); - CHKMEM(pri + offs); - CHKMEM(alt); - CHKMEM(alt + offs); - memcpy(data+(int)alt, data+(int)pri, (int)offs); - BREAK; - CASE(EMBRYO_OP_CMPS); - GETPARAM(offs); - CHKMEM(pri); - CHKMEM(pri + offs); - CHKMEM(alt); - CHKMEM(alt + offs); - pri = memcmp(data + (int)alt, data + (int)pri, (int)offs); - BREAK; - CASE(EMBRYO_OP_FILL); - GETPARAM(offs); - CHKMEM(alt); - CHKMEM(alt + offs); - for (i = (int)alt; - (size_t)offs >= sizeof(Embryo_Cell); - i += sizeof(Embryo_Cell), offs -= sizeof(Embryo_Cell)) - *(Embryo_Cell *)(data + i) = pri; - BREAK; - CASE(EMBRYO_OP_HALT); - GETPARAM(offs); - ep->retval = pri; - /* store complete status */ - ep->frm = frm; - ep->stk = stk; - ep->hea = hea; - ep->pri = pri; - ep->alt = alt; - ep->cip = (Embryo_Cell)((unsigned char*)cip - code); - if (offs == EMBRYO_ERROR_SLEEP) - { - ep->reset_stk = reset_stk; - ep->reset_hea = reset_hea; - ep->run_count--; - return EMBRYO_PROGRAM_SLEEP; - } - OK(ep, (int)offs); - CASE(EMBRYO_OP_BOUNDS); - GETPARAM(offs); - if ((Embryo_UCell)pri > (Embryo_UCell)offs) - ABORT(ep, EMBRYO_ERROR_BOUNDS); - BREAK; - CASE(EMBRYO_OP_SYSREQ_PRI); - /* save a few registers */ - ep->cip = (Embryo_Cell)((unsigned char *)cip - code); - ep->hea = hea; - ep->frm = frm; - ep->stk = stk; - num = _embryo_native_call(ep, pri, &pri, (Embryo_Cell *)(data + (int)stk)); - if (num != EMBRYO_ERROR_NONE) - { - if (num == EMBRYO_ERROR_SLEEP) - { - ep->pri = pri; - ep->alt = alt; - ep->reset_stk = reset_stk; - ep->reset_hea = reset_hea; - ep->run_count--; - return EMBRYO_PROGRAM_SLEEP; - } - ABORT(ep, num); - } - BREAK; - CASE(EMBRYO_OP_SYSREQ_C); - GETPARAM(offs); - /* save a few registers */ - ep->cip = (Embryo_Cell)((unsigned char *)cip - code); - ep->hea = hea; - ep->frm = frm; - ep->stk = stk; - num = _embryo_native_call(ep, offs, &pri, (Embryo_Cell *)(data + (int)stk)); - if (num != EMBRYO_ERROR_NONE) - { - if (num == EMBRYO_ERROR_SLEEP) - { - ep->pri = pri; - ep->alt = alt; - ep->reset_stk = reset_stk; - ep->reset_hea = reset_hea; - ep->run_count--; - return EMBRYO_PROGRAM_SLEEP; - } - { - Embryo_Header *hdr2; - int j, num2; - Embryo_Func_Stub *func_entry; - - hdr2 = (Embryo_Header *)ep->code; - num2 = NUMENTRIES(hdr2, natives, libraries); - func_entry = GETENTRY(hdr2, natives, 0); - for (j = 0; j < num2; j++) - { - char *entry_name; - - entry_name = GETENTRYNAME(hdr2, func_entry); - if (j == offs) - printf("EMBRYO: CALL [%i] %s() non-existent!\n", j, entry_name); - func_entry = - (Embryo_Func_Stub *)((unsigned char *)func_entry + hdr2->defsize); - } - } - ABORT(ep, num); - } - BREAK; - CASE(EMBRYO_OP_SYSREQ_D); - GETPARAM(offs); - /* save a few registers */ - ep->cip = (Embryo_Cell)((unsigned char *)cip - code); - ep->hea = hea; - ep->frm = frm; - ep->stk = stk; - num = _embryo_native_call(ep, offs, &pri, (Embryo_Cell *)(data + (int)stk)); - if (num != EMBRYO_ERROR_NONE) - { - if (num == EMBRYO_ERROR_SLEEP) - { - ep->pri = pri; - ep->alt = alt; - ep->reset_stk = reset_stk; - ep->reset_hea = reset_hea; - ep->run_count--; - return EMBRYO_PROGRAM_SLEEP; - } - ABORT(ep, ep->error); - } - BREAK; - CASE(EMBRYO_OP_JUMP_PRI); - cip = (Embryo_Cell *)(code + (int)pri); - BREAK; - CASE(EMBRYO_OP_SWITCH); - { - Embryo_Cell *cptr; - - /* +1, to skip the "casetbl" opcode */ - cptr = (Embryo_Cell *)(code + (*cip)) + 1; - /* number of records in the case table */ - num = (int)(*cptr); - /* preset to "none-matched" case */ - cip = (Embryo_Cell *)(code + *(cptr + 1)); - for (cptr += 2; - (num > 0) && (*cptr != pri); - num--, cptr += 2); - /* case found */ - if (num > 0) - cip = (Embryo_Cell *)(code + *(cptr + 1)); - } - BREAK; - CASE(EMBRYO_OP_SWAP_PRI); - offs = *(Embryo_Cell *)(data + (int)stk); - *(Embryo_Cell *)(data + (int)stk) = pri; - pri = offs; - BREAK; - CASE(EMBRYO_OP_SWAP_ALT); - offs = *(Embryo_Cell *)(data + (int)stk); - *(Embryo_Cell *)(data + (int)stk) = alt; - alt = offs; - BREAK; - CASE(EMBRYO_OP_PUSHADDR); - GETPARAM(offs); - PUSH(frm + offs); - BREAK; - CASE(EMBRYO_OP_NOP); - BREAK; - CASE(EMBRYO_OP_NONE); - CASE(EMBRYO_OP_FILE); - CASE(EMBRYO_OP_LINE); - CASE(EMBRYO_OP_SYMBOL); - CASE(EMBRYO_OP_SRANGE); - CASE(EMBRYO_OP_CASETBL); - CASE(EMBRYO_OP_SYMTAG); - BREAK; + BREAK; + CASE(EMBRYO_OP_LCTRL); + GETPARAM(offs); + switch (offs) + { + case 0: + pri = hdr->cod; + break; + + case 1: + pri = hdr->dat; + break; + + case 2: + pri = hea; + break; + + case 3: + pri = ep->stp; + break; + + case 4: + pri = stk; + break; + + case 5: + pri = frm; + break; + + case 6: + pri = (Embryo_Cell)((unsigned char *)cip - code); + break; + + default: + ABORT(ep, EMBRYO_ERROR_INVINSTR); + break; + } + BREAK; + CASE(EMBRYO_OP_SCTRL); + GETPARAM(offs); + switch (offs) + { + case 0: + case 1: + case 2: + hea = pri; + break; + + case 3: + /* cannot change these parameters */ + break; + + case 4: + stk = pri; + break; + + case 5: + frm = pri; + break; + + case 6: + cip = (Embryo_Cell *)(code + (int)pri); + break; + + default: + ABORT(ep, EMBRYO_ERROR_INVINSTR); + break; + } + BREAK; + CASE(EMBRYO_OP_MOVE_PRI); + pri = alt; + BREAK; + CASE(EMBRYO_OP_MOVE_ALT); + alt = pri; + BREAK; + CASE(EMBRYO_OP_XCHG); + offs = pri; /* offs is a temporary variable */ + pri = alt; + alt = offs; + BREAK; + CASE(EMBRYO_OP_PUSH_PRI); + PUSH(pri); + BREAK; + CASE(EMBRYO_OP_PUSH_ALT); + PUSH(alt); + BREAK; + CASE(EMBRYO_OP_PUSH_C); + GETPARAM(offs); + PUSH(offs); + BREAK; + CASE(EMBRYO_OP_PUSH_R); + GETPARAM(offs); + while (offs--) + PUSH(pri); + BREAK; + CASE(EMBRYO_OP_PUSH); + GETPARAM(offs); + PUSH(*(Embryo_Cell *)(data + (int)offs)); + BREAK; + CASE(EMBRYO_OP_PUSH_S); + GETPARAM(offs); + PUSH(*(Embryo_Cell *)(data + (int)frm + (int)offs)); + BREAK; + CASE(EMBRYO_OP_POP_PRI); + POP(pri); + BREAK; + CASE(EMBRYO_OP_POP_ALT); + POP(alt); + BREAK; + CASE(EMBRYO_OP_STACK); + GETPARAM(offs); + alt = stk; + stk += offs; + CHKMARGIN(); + CHKSTACK(); + BREAK; + CASE(EMBRYO_OP_HEAP); + GETPARAM(offs); + alt = hea; + hea += offs; + CHKMARGIN(); + CHKHEAP(); + BREAK; + CASE(EMBRYO_OP_PROC); + PUSH(frm); + frm = stk; + CHKMARGIN(); + BREAK; + CASE(EMBRYO_OP_RET); + POP(frm); + POP(offs); + if ((Embryo_UCell)offs >= codesize) + ABORT(ep, EMBRYO_ERROR_MEMACCESS); + cip = (Embryo_Cell *)(code + (int)offs); + BREAK; + CASE(EMBRYO_OP_RETN); + POP(frm); + POP(offs); + if ((Embryo_UCell)offs >= codesize) + ABORT(ep, EMBRYO_ERROR_MEMACCESS); + cip = (Embryo_Cell *)(code + (int)offs); + stk += *(Embryo_Cell *)(data + (int)stk) + sizeof(Embryo_Cell); /* remove parameters from the stack */ + ep->stk = stk; + BREAK; + CASE(EMBRYO_OP_CALL); + PUSH(((unsigned char *)cip - code) + sizeof(Embryo_Cell)); /* skip address */ + cip = JUMPABS(code, cip); /* jump to the address */ + BREAK; + CASE(EMBRYO_OP_CALL_PRI); + PUSH((unsigned char *)cip - code); + cip = (Embryo_Cell *)(code + (int)pri); + BREAK; + CASE(EMBRYO_OP_JUMP); + /* since the GETPARAM() macro modifies cip, you cannot + * do GETPARAM(cip) directly */ + cip = JUMPABS(code, cip); + BREAK; + CASE(EMBRYO_OP_JREL); + offs = *cip; + cip = (Embryo_Cell *)((unsigned char *)cip + (int)offs + sizeof(Embryo_Cell)); + BREAK; + CASE(EMBRYO_OP_JZER); + if (pri == 0) + cip = JUMPABS(code, cip); + else + cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); + BREAK; + CASE(EMBRYO_OP_JNZ); + if (pri != 0) + cip = JUMPABS(code, cip); + else + cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); + BREAK; + CASE(EMBRYO_OP_JEQ); + if (pri == alt) + cip = JUMPABS(code, cip); + else + cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); + BREAK; + CASE(EMBRYO_OP_JNEQ); + if (pri != alt) + cip = JUMPABS(code, cip); + else + cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); + BREAK; + CASE(EMBRYO_OP_JLESS); + if ((Embryo_UCell)pri < (Embryo_UCell)alt) + cip = JUMPABS(code, cip); + else + cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); + BREAK; + CASE(EMBRYO_OP_JLEQ); + if ((Embryo_UCell)pri <= (Embryo_UCell)alt) + cip = JUMPABS(code, cip); + else + cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); + BREAK; + CASE(EMBRYO_OP_JGRTR); + if ((Embryo_UCell)pri > (Embryo_UCell)alt) + cip = JUMPABS(code, cip); + else + cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); + BREAK; + CASE(EMBRYO_OP_JGEQ); + if ((Embryo_UCell)pri >= (Embryo_UCell)alt) + cip = JUMPABS(code, cip); + else + cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); + BREAK; + CASE(EMBRYO_OP_JSLESS); + if (pri < alt) + cip = JUMPABS(code, cip); + else + cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); + BREAK; + CASE(EMBRYO_OP_JSLEQ); + if (pri <= alt) + cip = JUMPABS(code, cip); + else + cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); + BREAK; + CASE(EMBRYO_OP_JSGRTR); + if (pri > alt) + cip = JUMPABS(code, cip); + else + cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); + BREAK; + CASE(EMBRYO_OP_JSGEQ); + if (pri >= alt) + cip = JUMPABS(code, cip); + else + cip = (Embryo_Cell *)((unsigned char *)cip + sizeof(Embryo_Cell)); + BREAK; + CASE(EMBRYO_OP_SHL); + pri <<= alt; + BREAK; + CASE(EMBRYO_OP_SHR); + pri = (Embryo_UCell)pri >> (int)alt; + BREAK; + CASE(EMBRYO_OP_SSHR); + pri >>= alt; + BREAK; + CASE(EMBRYO_OP_SHL_C_PRI); + GETPARAM(offs); + pri <<= offs; + BREAK; + CASE(EMBRYO_OP_SHL_C_ALT); + GETPARAM(offs); + alt <<= offs; + BREAK; + CASE(EMBRYO_OP_SHR_C_PRI); + GETPARAM(offs); + pri = (Embryo_UCell)pri >> (int)offs; + BREAK; + CASE(EMBRYO_OP_SHR_C_ALT); + GETPARAM(offs); + alt = (Embryo_UCell)alt >> (int)offs; + BREAK; + CASE(EMBRYO_OP_SMUL); + pri *= alt; + BREAK; + CASE(EMBRYO_OP_SDIV); + if (alt == 0) ABORT(ep, EMBRYO_ERROR_DIVIDE); + /* divide must always round down; this is a bit + * involved to do in a machine-independent way. + */ + offs = ((pri % alt) + alt) % alt; /* true modulus */ + pri = (pri - offs) / alt; /* division result */ + alt = offs; + BREAK; + CASE(EMBRYO_OP_SDIV_ALT); + if (pri == 0) ABORT(ep, EMBRYO_ERROR_DIVIDE); + /* divide must always round down; this is a bit + * involved to do in a machine-independent way. + */ + offs = ((alt % pri) + pri) % pri; /* true modulus */ + pri = (alt - offs) / pri; /* division result */ + alt = offs; + BREAK; + CASE(EMBRYO_OP_UMUL); + pri = (Embryo_UCell)pri * (Embryo_UCell)alt; + BREAK; + CASE(EMBRYO_OP_UDIV); + if (alt == 0) ABORT(ep, EMBRYO_ERROR_DIVIDE); + offs = (Embryo_UCell)pri % (Embryo_UCell)alt; /* temporary storage */ + pri = (Embryo_UCell)pri / (Embryo_UCell)alt; + alt = offs; + BREAK; + CASE(EMBRYO_OP_UDIV_ALT); + if (pri == 0) ABORT(ep, EMBRYO_ERROR_DIVIDE); + offs = (Embryo_UCell)alt % (Embryo_UCell)pri; /* temporary storage */ + pri = (Embryo_UCell)alt / (Embryo_UCell)pri; + alt = offs; + BREAK; + CASE(EMBRYO_OP_ADD); + pri += alt; + BREAK; + CASE(EMBRYO_OP_SUB); + pri -= alt; + BREAK; + CASE(EMBRYO_OP_SUB_ALT); + pri = alt - pri; + BREAK; + CASE(EMBRYO_OP_AND); + pri &= alt; + BREAK; + CASE(EMBRYO_OP_OR); + pri |= alt; + BREAK; + CASE(EMBRYO_OP_XOR); + pri ^= alt; + BREAK; + CASE(EMBRYO_OP_NOT); + pri = !pri; + BREAK; + CASE(EMBRYO_OP_NEG); + pri = -pri; + BREAK; + CASE(EMBRYO_OP_INVERT); + pri = ~pri; + BREAK; + CASE(EMBRYO_OP_ADD_C); + GETPARAM(offs); + pri += offs; + BREAK; + CASE(EMBRYO_OP_SMUL_C); + GETPARAM(offs); + pri *= offs; + BREAK; + CASE(EMBRYO_OP_ZERO_PRI); + pri = 0; + BREAK; + CASE(EMBRYO_OP_ZERO_ALT); + alt = 0; + BREAK; + CASE(EMBRYO_OP_ZERO); + GETPARAM(offs); + *(Embryo_Cell *)(data + (int)offs) = 0; + BREAK; + CASE(EMBRYO_OP_ZERO_S); + GETPARAM(offs); + *(Embryo_Cell *)(data + (int)frm + (int)offs) = 0; + BREAK; + CASE(EMBRYO_OP_SIGN_PRI); + if ((pri & 0xff) >= 0x80) pri |= ~(Embryo_UCell)0xff; + BREAK; + CASE(EMBRYO_OP_SIGN_ALT); + if ((alt & 0xff) >= 0x80) alt |= ~(Embryo_UCell)0xff; + BREAK; + CASE(EMBRYO_OP_EQ); + pri = (pri == alt) ? 1 : 0; + BREAK; + CASE(EMBRYO_OP_NEQ); + pri = (pri != alt) ? 1 : 0; + BREAK; + CASE(EMBRYO_OP_LESS); + pri = ((Embryo_UCell)pri < (Embryo_UCell)alt) ? 1 : 0; + BREAK; + CASE(EMBRYO_OP_LEQ); + pri = ((Embryo_UCell)pri <= (Embryo_UCell)alt) ? 1 : 0; + BREAK; + CASE(EMBRYO_OP_GRTR); + pri = ((Embryo_UCell)pri > (Embryo_UCell)alt) ? 1 : 0; + BREAK; + CASE(EMBRYO_OP_GEQ); + pri = ((Embryo_UCell)pri >= (Embryo_UCell)alt) ? 1 : 0; + BREAK; + CASE(EMBRYO_OP_SLESS); + pri = (pri < alt) ? 1 : 0; + BREAK; + CASE(EMBRYO_OP_SLEQ); + pri = (pri <= alt) ? 1 : 0; + BREAK; + CASE(EMBRYO_OP_SGRTR); + pri = (pri > alt) ? 1 : 0; + BREAK; + CASE(EMBRYO_OP_SGEQ); + pri = (pri >= alt) ? 1 : 0; + BREAK; + CASE(EMBRYO_OP_EQ_C_PRI); + GETPARAM(offs); + pri = (pri == offs) ? 1 : 0; + BREAK; + CASE(EMBRYO_OP_EQ_C_ALT); + GETPARAM(offs); + pri = (alt == offs) ? 1 : 0; + BREAK; + CASE(EMBRYO_OP_INC_PRI); + pri++; + BREAK; + CASE(EMBRYO_OP_INC_ALT); + alt++; + BREAK; + CASE(EMBRYO_OP_INC); + GETPARAM(offs); + *(Embryo_Cell *)(data + (int)offs) += 1; + BREAK; + CASE(EMBRYO_OP_INC_S); + GETPARAM(offs); + *(Embryo_Cell *)(data + (int)frm + (int)offs) += 1; + BREAK; + CASE(EMBRYO_OP_INC_I); + *(Embryo_Cell *)(data + (int)pri) += 1; + BREAK; + CASE(EMBRYO_OP_DEC_PRI); + pri--; + BREAK; + CASE(EMBRYO_OP_DEC_ALT); + alt--; + BREAK; + CASE(EMBRYO_OP_DEC); + GETPARAM(offs); + *(Embryo_Cell *)(data + (int)offs) -= 1; + BREAK; + CASE(EMBRYO_OP_DEC_S); + GETPARAM(offs); + *(Embryo_Cell *)(data + (int)frm + (int)offs) -= 1; + BREAK; + CASE(EMBRYO_OP_DEC_I); + *(Embryo_Cell *)(data + (int)pri) -= 1; + BREAK; + CASE(EMBRYO_OP_MOVS); + GETPARAM(offs); + CHKMEM(pri); + CHKMEM(pri + offs); + CHKMEM(alt); + CHKMEM(alt + offs); + memcpy(data + (int)alt, data + (int)pri, (int)offs); + BREAK; + CASE(EMBRYO_OP_CMPS); + GETPARAM(offs); + CHKMEM(pri); + CHKMEM(pri + offs); + CHKMEM(alt); + CHKMEM(alt + offs); + pri = memcmp(data + (int)alt, data + (int)pri, (int)offs); + BREAK; + CASE(EMBRYO_OP_FILL); + GETPARAM(offs); + CHKMEM(alt); + CHKMEM(alt + offs); + for (i = (int)alt; + (size_t)offs >= sizeof(Embryo_Cell); + i += sizeof(Embryo_Cell), offs -= sizeof(Embryo_Cell)) + *(Embryo_Cell *)(data + i) = pri; + BREAK; + CASE(EMBRYO_OP_HALT); + GETPARAM(offs); + ep->retval = pri; + /* store complete status */ + ep->frm = frm; + ep->stk = stk; + ep->hea = hea; + ep->pri = pri; + ep->alt = alt; + ep->cip = (Embryo_Cell)((unsigned char *)cip - code); + if (offs == EMBRYO_ERROR_SLEEP) + { + ep->reset_stk = reset_stk; + ep->reset_hea = reset_hea; + ep->run_count--; + return EMBRYO_PROGRAM_SLEEP; + } + OK(ep, (int)offs); + CASE(EMBRYO_OP_BOUNDS); + GETPARAM(offs); + if ((Embryo_UCell)pri > (Embryo_UCell)offs) + ABORT(ep, EMBRYO_ERROR_BOUNDS); + BREAK; + CASE(EMBRYO_OP_SYSREQ_PRI); + /* save a few registers */ + ep->cip = (Embryo_Cell)((unsigned char *)cip - code); + ep->hea = hea; + ep->frm = frm; + ep->stk = stk; + num = _embryo_native_call(ep, pri, &pri, (Embryo_Cell *)(data + (int)stk)); + if (num != EMBRYO_ERROR_NONE) + { + if (num == EMBRYO_ERROR_SLEEP) + { + ep->pri = pri; + ep->alt = alt; + ep->reset_stk = reset_stk; + ep->reset_hea = reset_hea; + ep->run_count--; + return EMBRYO_PROGRAM_SLEEP; + } + ABORT(ep, num); + } + BREAK; + CASE(EMBRYO_OP_SYSREQ_C); + GETPARAM(offs); + /* save a few registers */ + ep->cip = (Embryo_Cell)((unsigned char *)cip - code); + ep->hea = hea; + ep->frm = frm; + ep->stk = stk; + num = _embryo_native_call(ep, offs, &pri, (Embryo_Cell *)(data + (int)stk)); + if (num != EMBRYO_ERROR_NONE) + { + if (num == EMBRYO_ERROR_SLEEP) + { + ep->pri = pri; + ep->alt = alt; + ep->reset_stk = reset_stk; + ep->reset_hea = reset_hea; + ep->run_count--; + return EMBRYO_PROGRAM_SLEEP; + } + { + Embryo_Header *hdr2; + int j, num2; + Embryo_Func_Stub *func_entry; + + hdr2 = (Embryo_Header *)ep->code; + num2 = NUMENTRIES(hdr2, natives, libraries); + func_entry = GETENTRY(hdr2, natives, 0); + for (j = 0; j < num2; j++) + { + char *entry_name; + + entry_name = GETENTRYNAME(hdr2, func_entry); + if (j == offs) + printf("EMBRYO: CALL [%i] %s() non-existent!\n", j, entry_name); + func_entry = + (Embryo_Func_Stub *)((unsigned char *)func_entry + hdr2->defsize); + } + } + ABORT(ep, num); + } + BREAK; + CASE(EMBRYO_OP_SYSREQ_D); + GETPARAM(offs); + /* save a few registers */ + ep->cip = (Embryo_Cell)((unsigned char *)cip - code); + ep->hea = hea; + ep->frm = frm; + ep->stk = stk; + num = _embryo_native_call(ep, offs, &pri, (Embryo_Cell *)(data + (int)stk)); + if (num != EMBRYO_ERROR_NONE) + { + if (num == EMBRYO_ERROR_SLEEP) + { + ep->pri = pri; + ep->alt = alt; + ep->reset_stk = reset_stk; + ep->reset_hea = reset_hea; + ep->run_count--; + return EMBRYO_PROGRAM_SLEEP; + } + ABORT(ep, ep->error); + } + BREAK; + CASE(EMBRYO_OP_JUMP_PRI); + cip = (Embryo_Cell *)(code + (int)pri); + BREAK; + CASE(EMBRYO_OP_SWITCH); + { + Embryo_Cell *cptr; + + /* +1, to skip the "casetbl" opcode */ + cptr = (Embryo_Cell *)(code + (*cip)) + 1; + /* number of records in the case table */ + num = (int)(*cptr); + /* preset to "none-matched" case */ + cip = (Embryo_Cell *)(code + *(cptr + 1)); + for (cptr += 2; + (num > 0) && (*cptr != pri); + num--, cptr += 2) ; + /* case found */ + if (num > 0) + cip = (Embryo_Cell *)(code + *(cptr + 1)); + } + BREAK; + CASE(EMBRYO_OP_SWAP_PRI); + offs = *(Embryo_Cell *)(data + (int)stk); + *(Embryo_Cell *)(data + (int)stk) = pri; + pri = offs; + BREAK; + CASE(EMBRYO_OP_SWAP_ALT); + offs = *(Embryo_Cell *)(data + (int)stk); + *(Embryo_Cell *)(data + (int)stk) = alt; + alt = offs; + BREAK; + CASE(EMBRYO_OP_PUSHADDR); + GETPARAM(offs); + PUSH(frm + offs); + BREAK; + CASE(EMBRYO_OP_NOP); + BREAK; + CASE(EMBRYO_OP_NONE); + CASE(EMBRYO_OP_FILE); + CASE(EMBRYO_OP_LINE); + CASE(EMBRYO_OP_SYMBOL); + CASE(EMBRYO_OP_SRANGE); + CASE(EMBRYO_OP_CASETBL); + CASE(EMBRYO_OP_SYMTAG); + BREAK; + #ifndef EMBRYO_EXEC_JUMPTABLE default: - ABORT(ep, EMBRYO_ERROR_INVINSTR); + ABORT(ep, EMBRYO_ERROR_INVINSTR); #endif - SWITCHEND; + SWITCHEND; } ep->max_run_cycles = max_run_cycles; ep->run_count--; @@ -1910,7 +1924,6 @@ embryo_program_max_cycle_run_get(Embryo_Program *ep) return ep->max_run_cycles; } - EAPI int embryo_parameter_cell_push(Embryo_Program *ep, Embryo_Cell cell) { @@ -1919,10 +1932,10 @@ embryo_parameter_cell_push(Embryo_Program *ep, Embryo_Cell cell) ep->params_size++; if (ep->params_size > ep->params_alloc) { - ep->params_alloc += 8; - pr = realloc(ep->params, ep->params_alloc * sizeof(Embryo_Param)); - if (!pr) return 0; - ep->params = pr; + ep->params_alloc += 8; + pr = realloc(ep->params, ep->params_alloc * sizeof(Embryo_Param)); + if (!pr) return 0; + ep->params = pr; } pr = &(ep->params[ep->params_size - 1]); pr->string = NULL; @@ -1945,14 +1958,14 @@ embryo_parameter_string_push(Embryo_Program *ep, const char *str) ep->params_size++; if (ep->params_size > ep->params_alloc) { - ep->params_alloc += 8; - pr = realloc(ep->params, ep->params_alloc * sizeof(Embryo_Param)); - if (!pr) - { - free(str_dup); - return 0; - } - ep->params = pr; + ep->params_alloc += 8; + pr = realloc(ep->params, ep->params_alloc * sizeof(Embryo_Param)); + if (!pr) + { + free(str_dup); + return 0; + } + ep->params = pr; } pr = &(ep->params[ep->params_size - 1]); pr->string = str_dup; @@ -1974,14 +1987,14 @@ embryo_parameter_cell_array_push(Embryo_Program *ep, Embryo_Cell *cells, int num ep->params_size++; if (ep->params_size > ep->params_alloc) { - ep->params_alloc += 8; - pr = realloc(ep->params, ep->params_alloc * sizeof(Embryo_Param)); - if (!pr) - { - free(cell_array); - return 0; - } - ep->params = pr; + ep->params_alloc += 8; + pr = realloc(ep->params, ep->params_alloc * sizeof(Embryo_Param)); + if (!pr) + { + free(cell_array); + return 0; + } + ep->params = pr; } pr = &(ep->params[ep->params_size - 1]); pr->string = NULL; @@ -1991,3 +2004,4 @@ embryo_parameter_cell_array_push(Embryo_Program *ep, Embryo_Cell *cells, int num memcpy(pr->cell_array, cells, num * sizeof(Embryo_Cell)); return 1; } + diff --git a/src/lib/embryo/embryo_args.c b/src/lib/embryo/embryo_args.c index c0682e6..e741d8a 100644 --- a/src/lib/embryo/embryo_args.c +++ b/src/lib/embryo/embryo_args.c @@ -7,11 +7,11 @@ #include "Embryo.h" #include "embryo_private.h" -#define STRSET(ep, par, str) { \ - Embryo_Cell *___cptr; \ - if ((___cptr = embryo_data_address_get(ep, par))) { \ - embryo_data_string_set(ep, str, ___cptr); \ - } } +#define STRSET(ep, par, str) { \ + Embryo_Cell *___cptr; \ + if ((___cptr = embryo_data_address_get(ep, par))) { \ + embryo_data_string_set(ep, str, ___cptr); \ + } } /* exported args api */ @@ -25,7 +25,7 @@ _embryo_args_numargs(Embryo_Program *ep, Embryo_Cell *params EINA_UNUSED) hdr = (Embryo_Header *)ep->base; data = ep->base + (int)hdr->dat; bytes = *(Embryo_Cell *)(data + (int)ep->frm + - (2 * sizeof(Embryo_Cell))); + (2 * sizeof(Embryo_Cell))); return bytes / sizeof(Embryo_Cell); } @@ -40,7 +40,7 @@ _embryo_args_getarg(Embryo_Program *ep, Embryo_Cell *params) hdr = (Embryo_Header *)ep->base; data = ep->base + (int)hdr->dat; val = *(Embryo_Cell *)(data + (int)ep->frm + - (((int)params[1] + 3) * sizeof(Embryo_Cell))); + (((int)params[1] + 3) * sizeof(Embryo_Cell))); val += params[2] * sizeof(Embryo_Cell); val = *(Embryo_Cell *)(data + (int)val); return val; @@ -57,7 +57,7 @@ _embryo_args_setarg(Embryo_Program *ep, Embryo_Cell *params) hdr = (Embryo_Header *)ep->base; data = ep->base + (int)hdr->dat; val = *(Embryo_Cell *)(data + (int)ep->frm + - (((int)params[1] + 3) * sizeof(Embryo_Cell))); + (((int)params[1] + 3) * sizeof(Embryo_Cell))); val += params[2] * sizeof(Embryo_Cell); if ((val < 0) || ((val >= ep->hea) && (val < ep->stk))) return 0; *(Embryo_Cell *)(data + (int)val) = params[3]; @@ -77,20 +77,20 @@ _embryo_args_getsarg(Embryo_Program *ep, Embryo_Cell *params) /* params[2] = buf */ /* params[3] = buflen */ if (params[0] != (3 * sizeof(Embryo_Cell))) return 0; - if (params[3] <= 0) return 0; /* buflen must be > 0 */ + if (params[3] <= 0) return 0; /* buflen must be > 0 */ hdr = (Embryo_Header *)ep->base; data = ep->base + (int)hdr->dat; base_cell = *(Embryo_Cell *)(data + (int)ep->frm + - (((int)params[1] + 3) * sizeof(Embryo_Cell))); + (((int)params[1] + 3) * sizeof(Embryo_Cell))); s = alloca(params[3]); while (i < params[3]) { - int offset = base_cell + (i * sizeof(Embryo_Cell)); + int offset = base_cell + (i * sizeof(Embryo_Cell)); - s[i] = *(Embryo_Cell *)(data + offset); - if (!s[i++]) break; + s[i] = *(Embryo_Cell *)(data + offset); + if (!s[i++]) break; } s[i - 1] = 0; @@ -104,10 +104,11 @@ _embryo_args_getsarg(Embryo_Program *ep, Embryo_Cell *params) void _embryo_args_init(Embryo_Program *ep) { - embryo_program_native_call_add(ep, "numargs", _embryo_args_numargs); + embryo_program_native_call_add(ep, "numargs", _embryo_args_numargs); embryo_program_native_call_add(ep, "getarg", _embryo_args_getarg); embryo_program_native_call_add(ep, "setarg", _embryo_args_setarg); embryo_program_native_call_add(ep, "getfarg", _embryo_args_getarg); embryo_program_native_call_add(ep, "setfarg", _embryo_args_setarg); embryo_program_native_call_add(ep, "getsarg", _embryo_args_getsarg); } + diff --git a/src/lib/embryo/embryo_float.c b/src/lib/embryo/embryo_float.c index 8491477..23c6a5c 100644 --- a/src/lib/embryo/embryo_float.c +++ b/src/lib/embryo/embryo_float.c @@ -36,7 +36,6 @@ * Carsten Haitzler, */ - #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -49,7 +48,7 @@ #include "Embryo.h" #include "embryo_private.h" -#define PI 3.1415926535897932384626433832795f +#define PI 3.1415926535897932384626433832795f #ifndef MAXFLOAT #define MAXFLOAT 3.40282347e+38f #endif @@ -62,11 +61,13 @@ _embryo_fp_degrees_to_radians(float angle, int radix) switch (radix) { case 1: /* degrees, sexagesimal system (technically: degrees/minutes/seconds) */ - return (angle * PI / 180.0f); + return angle * PI / 180.0f; + case 2: /* grades, centesimal system */ - return (angle * PI / 200.0f); + return angle * PI / 200.0f; + default: /* assume already radian */ - break; + break; } return angle; } @@ -187,20 +188,23 @@ _embryo_fp_round(Embryo_Program *ep EINA_UNUSED, Embryo_Cell *params) switch (params[2]) { case 1: /* round downwards (truncate) */ - f = (floorf(f)); - break; + f = (floorf(f)); + break; + case 2: /* round upwards */ - f = (ceilf(f)); - break; + f = (ceilf(f)); + break; + case 3: /* round towards zero */ - if (f >= 0.0) f = (floorf(f)); - else f = (ceilf(f)); - break; + if (f >= 0.0) f = (floorf(f)); + else f = (ceilf(f)); + break; + default: /* standard, round to nearest */ - f = (floorf(f + 0.5)); - break; + f = (floorf(f + 0.5)); + break; } - return (Embryo_Cell)f; + return (Embryo_Cell)f; } static Embryo_Cell @@ -214,7 +218,8 @@ _embryo_fp_cmp(Embryo_Program *ep EINA_UNUSED, Embryo_Cell *params) f = EMBRYO_CELL_TO_FLOAT(params[1]); ff = EMBRYO_CELL_TO_FLOAT(params[2]); if (f == ff) return 0; - else if (f > ff) return 1; + else if (f > ff) + return 1; return -1; } @@ -229,8 +234,8 @@ _embryo_fp_sqroot(Embryo_Program *ep, Embryo_Cell *params) f = sqrtf(f); if (f < 0) { - embryo_program_error_set(ep, EMBRYO_ERROR_DOMAIN); - return 0; + embryo_program_error_set(ep, EMBRYO_ERROR_DOMAIN); + return 0; } return EMBRYO_FLOAT_TO_CELL(f); } @@ -261,18 +266,19 @@ _embryo_fp_log(Embryo_Program *ep, Embryo_Cell *params) ff = EMBRYO_CELL_TO_FLOAT(params[2]); if ((f <= 0.0) || (ff <= 0.0)) { - embryo_program_error_set(ep, EMBRYO_ERROR_DOMAIN); - return 0; + embryo_program_error_set(ep, EMBRYO_ERROR_DOMAIN); + return 0; } - if (ff == 10.0) f = log10f(f); - else if (ff == 2.0) f = log2f(f); - else + if (ff == 10.0) f = log10f(f); + else if (ff == 2.0) + f = log2f(f); + else { tf = logf(ff); if (tf == 0.0) f = 0.0; else f = (logf(f) / tf); } - return EMBRYO_FLOAT_TO_CELL(f); + return EMBRYO_FLOAT_TO_CELL(f); } static Embryo_Cell @@ -453,30 +459,31 @@ _embryo_fp_hypot(Embryo_Program *ep EINA_UNUSED, Embryo_Cell *params) void _embryo_fp_init(Embryo_Program *ep) { - embryo_program_native_call_add(ep, "float", _embryo_fp); - embryo_program_native_call_add(ep, "atof", _embryo_fp_str); + embryo_program_native_call_add(ep, "float", _embryo_fp); + embryo_program_native_call_add(ep, "atof", _embryo_fp_str); embryo_program_native_call_add(ep, "float_mul", _embryo_fp_mul); embryo_program_native_call_add(ep, "float_div", _embryo_fp_div); embryo_program_native_call_add(ep, "float_add", _embryo_fp_add); embryo_program_native_call_add(ep, "float_sub", _embryo_fp_sub); - embryo_program_native_call_add(ep, "fract", _embryo_fp_fract); - embryo_program_native_call_add(ep, "round", _embryo_fp_round); + embryo_program_native_call_add(ep, "fract", _embryo_fp_fract); + embryo_program_native_call_add(ep, "round", _embryo_fp_round); embryo_program_native_call_add(ep, "float_cmp", _embryo_fp_cmp); - embryo_program_native_call_add(ep, "sqrt", _embryo_fp_sqroot); - embryo_program_native_call_add(ep, "pow", _embryo_fp_power); - embryo_program_native_call_add(ep, "log", _embryo_fp_log); - embryo_program_native_call_add(ep, "sin", _embryo_fp_sin); - embryo_program_native_call_add(ep, "cos", _embryo_fp_cos); - embryo_program_native_call_add(ep, "tan", _embryo_fp_tan); - embryo_program_native_call_add(ep, "abs", _embryo_fp_abs); + embryo_program_native_call_add(ep, "sqrt", _embryo_fp_sqroot); + embryo_program_native_call_add(ep, "pow", _embryo_fp_power); + embryo_program_native_call_add(ep, "log", _embryo_fp_log); + embryo_program_native_call_add(ep, "sin", _embryo_fp_sin); + embryo_program_native_call_add(ep, "cos", _embryo_fp_cos); + embryo_program_native_call_add(ep, "tan", _embryo_fp_tan); + embryo_program_native_call_add(ep, "abs", _embryo_fp_abs); /* Added in embryo 1.2 */ - embryo_program_native_call_add(ep, "asin", _embryo_fp_asin); - embryo_program_native_call_add(ep, "acos", _embryo_fp_acos); - embryo_program_native_call_add(ep, "atan", _embryo_fp_atan); - embryo_program_native_call_add(ep, "atan2", _embryo_fp_atan2); - embryo_program_native_call_add(ep, "log1p", _embryo_fp_log1p); - embryo_program_native_call_add(ep, "cbrt", _embryo_fp_cbrt); - embryo_program_native_call_add(ep, "exp", _embryo_fp_exp); - embryo_program_native_call_add(ep, "exp2", _embryo_fp_exp2); - embryo_program_native_call_add(ep, "hypot", _embryo_fp_hypot); + embryo_program_native_call_add(ep, "asin", _embryo_fp_asin); + embryo_program_native_call_add(ep, "acos", _embryo_fp_acos); + embryo_program_native_call_add(ep, "atan", _embryo_fp_atan); + embryo_program_native_call_add(ep, "atan2", _embryo_fp_atan2); + embryo_program_native_call_add(ep, "log1p", _embryo_fp_log1p); + embryo_program_native_call_add(ep, "cbrt", _embryo_fp_cbrt); + embryo_program_native_call_add(ep, "exp", _embryo_fp_exp); + embryo_program_native_call_add(ep, "exp2", _embryo_fp_exp2); + embryo_program_native_call_add(ep, "hypot", _embryo_fp_hypot); } + diff --git a/src/lib/embryo/embryo_main.c b/src/lib/embryo/embryo_main.c index e80834c..37fc811 100644 --- a/src/lib/embryo/embryo_main.c +++ b/src/lib/embryo/embryo_main.c @@ -10,7 +10,7 @@ #include "embryo_private.h" static Embryo_Version _version = { VMAJ, VMIN, VMIC, VREV }; -EAPI Embryo_Version *embryo_version = &_version; +EAPI Embryo_Version * embryo_version = &_version; static int _embryo_init_count = 0; int _embryo_default_log_dom = -1; @@ -67,3 +67,4 @@ embryo_shutdown(void) return _embryo_init_count; } + diff --git a/src/lib/embryo/embryo_rand.c b/src/lib/embryo/embryo_rand.c index 0f13d87..a21d437 100644 --- a/src/lib/embryo/embryo_rand.c +++ b/src/lib/embryo/embryo_rand.c @@ -33,6 +33,7 @@ _embryo_rand_randf(Embryo_Program *ep EINA_UNUSED, Embryo_Cell *params EINA_UNUS void _embryo_rand_init(Embryo_Program *ep) { - embryo_program_native_call_add(ep, "rand", _embryo_rand_rand); + embryo_program_native_call_add(ep, "rand", _embryo_rand_rand); embryo_program_native_call_add(ep, "randf", _embryo_rand_randf); } + diff --git a/src/lib/embryo/embryo_str.c b/src/lib/embryo/embryo_str.c index 649bd49..de39437 100644 --- a/src/lib/embryo/embryo_str.c +++ b/src/lib/embryo/embryo_str.c @@ -23,20 +23,20 @@ #include "Embryo.h" #include "embryo_private.h" -#define STRGET(ep, str, par) { \ - Embryo_Cell *___cptr; \ - str = NULL; \ - if ((___cptr = embryo_data_address_get(ep, par))) { \ - int ___l; \ - ___l = embryo_data_string_length_get(ep, ___cptr); \ - (str) = alloca(___l + 1); \ - if (str) embryo_data_string_get(ep, ___cptr, str); \ - } } -#define STRSET(ep, par, str) { \ - Embryo_Cell *___cptr; \ - if ((___cptr = embryo_data_address_get(ep, par))) { \ - embryo_data_string_set(ep, str, ___cptr); \ - } } +#define STRGET(ep, str, par) { \ + Embryo_Cell *___cptr; \ + str = NULL; \ + if ((___cptr = embryo_data_address_get(ep, par))) { \ + int ___l; \ + ___l = embryo_data_string_length_get(ep, ___cptr); \ + (str) = alloca(___l + 1); \ + if (str) embryo_data_string_get(ep, ___cptr, str); \ + } } +#define STRSET(ep, par, str) { \ + Embryo_Cell *___cptr; \ + if ((___cptr = embryo_data_address_get(ep, par))) { \ + embryo_data_string_set(ep, str, ___cptr); \ + } } /* exported string api */ @@ -249,8 +249,8 @@ _embryo_str_strcut(Embryo_Program *ep, Embryo_Cell *params) if (params[4] >= l1) params[4] = l1; if (params[4] == params[3]) { - STRSET(ep, params[1], ""); - return 0; + STRSET(ep, params[1], ""); + return 0; } s2 = alloca(params[4] - params[3] + 1); strncpy(s2, s1 + params[3], params[4] - params[3]); @@ -270,8 +270,9 @@ _str_snprintf(Embryo_Program *ep, char *s1, char *s2, int max_len, int pnum, Emb { if ((!inesc) && (!insub)) { - if (s1[i] == '\\') inesc = 1; - else if (s1[i] == '%') insub = 1; + if (s1[i] == '\\') inesc = 1; + else if (s1[i] == '%') + insub = 1; if ((!inesc) && (!insub)) { s2[o] = s1[i]; @@ -287,17 +288,19 @@ _str_snprintf(Embryo_Program *ep, char *s1, char *s2, int max_len, int pnum, Emb switch (s1[i]) { case 't': - s2[o] = '\t'; - o++; - break; + s2[o] = '\t'; + o++; + break; + case 'n': - s2[o] = '\n'; - o++; - break; + s2[o] = '\n'; + o++; + break; + default: - s2[o] = s1[i]; - o++; - break; + s2[o] = s1[i]; + o++; + break; } inesc = 0; } @@ -307,49 +310,76 @@ _str_snprintf(Embryo_Program *ep, char *s1, char *s2, int max_len, int pnum, Emb switch (s1[i]) { case '%': - s2[o] = '%'; - o++; - break; + s2[o] = '%'; + o++; + break; + case 'c': - cptr = embryo_data_address_get(ep, params[p]); - if (cptr) s2[o] = (char)(*cptr); - p++; - o++; - break; + cptr = embryo_data_address_get(ep, params[p]); + if (cptr) s2[o] = (char)(*cptr); + p++; + o++; + break; + case 'i': case 'd': case 'x': case 'X': + { + char fmt[10] = ""; + char tmp[256] = ""; + int l; + + if (s1[i] == 'i') strcpy(fmt, "%i"); + else if (s1[i] == 'd') + strcpy(fmt, "%d"); + else if (s1[i] == 'x') + strcpy(fmt, "%x"); + else if (s1[i] == 'X') + strcpy(fmt, "%08x"); + cptr = embryo_data_address_get(ep, params[p]); + if (cptr) snprintf(tmp, sizeof(tmp), fmt, (int)(*cptr)); + l = strlen(tmp); + if ((o + l) > max_len) { - char fmt[10] = ""; - char tmp[256] = ""; - int l; - - if (s1[i] == 'i') strcpy(fmt, "%i"); - else if (s1[i] == 'd') strcpy(fmt, "%d"); - else if (s1[i] == 'x') strcpy(fmt, "%x"); - else if (s1[i] == 'X') strcpy(fmt, "%08x"); - cptr = embryo_data_address_get(ep, params[p]); - if (cptr) snprintf(tmp, sizeof(tmp), fmt, (int)(*cptr)); - l = strlen(tmp); - if ((o + l) > max_len) - { - l = max_len - o; - if (l < 0) l = 0; - tmp[l] = 0; - } - strcpy(s2 + o, tmp); - o += l; - p++; + l = max_len - o; + if (l < 0) l = 0; + tmp[l] = 0; } - break; + strcpy(s2 + o, tmp); + o += l; + p++; + } + break; + case 'f': + { + char tmp[256] = ""; + int l; + + cptr = embryo_data_address_get(ep, params[p]); + if (cptr) snprintf(tmp, sizeof(tmp), "%f", (double)EMBRYO_CELL_TO_FLOAT(*cptr)); + l = strlen(tmp); + if ((o + l) > max_len) { - char tmp[256] = ""; - int l; + l = max_len - o; + if (l < 0) l = 0; + tmp[l] = 0; + } + strcpy(s2 + o, tmp); + o += l; + p++; + } + break; + + case 's': + { + char *tmp; + int l; - cptr = embryo_data_address_get(ep, params[p]); - if (cptr) snprintf(tmp, sizeof(tmp), "%f", (double)EMBRYO_CELL_TO_FLOAT(*cptr)); + STRGET(ep, tmp, params[p]); + if (tmp) + { l = strlen(tmp); if ((o + l) > max_len) { @@ -359,32 +389,13 @@ _str_snprintf(Embryo_Program *ep, char *s1, char *s2, int max_len, int pnum, Emb } strcpy(s2 + o, tmp); o += l; - p++; } - break; - case 's': - { - char *tmp; - int l; + p++; + } + break; - STRGET(ep, tmp, params[p]); - if (tmp) - { - l = strlen(tmp); - if ((o + l) > max_len) - { - l = max_len - o; - if (l < 0) l = 0; - tmp[l] = 0; - } - strcpy(s2 + o, tmp); - o += l; - } - p++; - } - break; default: - break; + break; } insub = 0; } @@ -503,21 +514,22 @@ _embryo_str_strrchr(Embryo_Program *ep, Embryo_Cell *params) void _embryo_str_init(Embryo_Program *ep) { - embryo_program_native_call_add(ep, "atoi", _embryo_str_atoi); - embryo_program_native_call_add(ep, "fnmatch", _embryo_str_fnmatch); - embryo_program_native_call_add(ep, "strcmp", _embryo_str_strcmp); - embryo_program_native_call_add(ep, "strncmp", _embryo_str_strncmp); - embryo_program_native_call_add(ep, "strcpy", _embryo_str_strcpy); - embryo_program_native_call_add(ep, "strncpy", _embryo_str_strncpy); - embryo_program_native_call_add(ep, "strlen", _embryo_str_strlen); - embryo_program_native_call_add(ep, "strcat", _embryo_str_strcat); - embryo_program_native_call_add(ep, "strncat", _embryo_str_strncat); - embryo_program_native_call_add(ep, "strprep", _embryo_str_strprep); + embryo_program_native_call_add(ep, "atoi", _embryo_str_atoi); + embryo_program_native_call_add(ep, "fnmatch", _embryo_str_fnmatch); + embryo_program_native_call_add(ep, "strcmp", _embryo_str_strcmp); + embryo_program_native_call_add(ep, "strncmp", _embryo_str_strncmp); + embryo_program_native_call_add(ep, "strcpy", _embryo_str_strcpy); + embryo_program_native_call_add(ep, "strncpy", _embryo_str_strncpy); + embryo_program_native_call_add(ep, "strlen", _embryo_str_strlen); + embryo_program_native_call_add(ep, "strcat", _embryo_str_strcat); + embryo_program_native_call_add(ep, "strncat", _embryo_str_strncat); + embryo_program_native_call_add(ep, "strprep", _embryo_str_strprep); embryo_program_native_call_add(ep, "strnprep", _embryo_str_strnprep); - embryo_program_native_call_add(ep, "strcut", _embryo_str_strcut); + embryo_program_native_call_add(ep, "strcut", _embryo_str_strcut); embryo_program_native_call_add(ep, "snprintf", _embryo_str_snprintf); - embryo_program_native_call_add(ep, "strstr", _embryo_str_strstr); - embryo_program_native_call_add(ep, "strchr", _embryo_str_strchr); - embryo_program_native_call_add(ep, "strrchr", _embryo_str_strrchr); - embryo_program_native_call_add(ep, "printf", _embryo_str_printf); + embryo_program_native_call_add(ep, "strstr", _embryo_str_strstr); + embryo_program_native_call_add(ep, "strchr", _embryo_str_strchr); + embryo_program_native_call_add(ep, "strrchr", _embryo_str_strrchr); + embryo_program_native_call_add(ep, "printf", _embryo_str_printf); } + diff --git a/src/lib/embryo/embryo_time.c b/src/lib/embryo/embryo_time.c index 8725377..2caab43 100644 --- a/src/lib/embryo/embryo_time.c +++ b/src/lib/embryo/embryo_time.c @@ -27,9 +27,9 @@ static Embryo_Cell _embryo_time_seconds(Embryo_Program *ep EINA_UNUSED, Embryo_Cell *params EINA_UNUSED) { - struct timeval timev; + struct timeval timev; double t; - float f; + float f; gettimeofday(&timev, NULL); t = (double)(timev.tv_sec - ((timev.tv_sec / (60 * 60 * 24)) * (60 * 60 * 24))) @@ -41,10 +41,10 @@ _embryo_time_seconds(Embryo_Program *ep EINA_UNUSED, Embryo_Cell *params EINA_UN static Embryo_Cell _embryo_time_date(Embryo_Program *ep, Embryo_Cell *params) { - static time_t last_tzset = 0; - struct timeval timev; - struct tm *tm; - time_t tt; + static time_t last_tzset = 0; + struct timeval timev; + struct tm *tm; + time_t tt; if (params[0] != (8 * sizeof(Embryo_Cell))) return 0; gettimeofday(&timev, NULL); @@ -52,35 +52,34 @@ _embryo_time_date(Embryo_Program *ep, Embryo_Cell *params) if ((tt > (last_tzset + 1)) || (tt < (last_tzset - 1))) { - last_tzset = tt; - tzset(); + last_tzset = tt; + tzset(); } tm = localtime(&tt); if (tm) { - Embryo_Cell *cptr; - double t; - float f; - - cptr = embryo_data_address_get(ep, params[1]); - if (cptr) *cptr = tm->tm_year + 1900; - cptr = embryo_data_address_get(ep, params[2]); - if (cptr) *cptr = tm->tm_mon + 1; - cptr = embryo_data_address_get(ep, params[3]); - if (cptr) *cptr = tm->tm_mday; - cptr = embryo_data_address_get(ep, params[4]); - if (cptr) *cptr = tm->tm_yday; - cptr = embryo_data_address_get(ep, params[5]); - if (cptr) *cptr = (tm->tm_wday + 6) % 7; - cptr = embryo_data_address_get(ep, params[6]); - if (cptr) *cptr = tm->tm_hour; - cptr = embryo_data_address_get(ep, params[7]); - if (cptr) *cptr = tm->tm_min; - cptr = embryo_data_address_get(ep, params[8]); - t = (double)tm->tm_sec + (((double)timev.tv_usec) / 1000000); - f = (float)t; - if (cptr) *cptr = EMBRYO_FLOAT_TO_CELL(f); + Embryo_Cell *cptr; + double t; + float f; + cptr = embryo_data_address_get(ep, params[1]); + if (cptr) *cptr = tm->tm_year + 1900; + cptr = embryo_data_address_get(ep, params[2]); + if (cptr) *cptr = tm->tm_mon + 1; + cptr = embryo_data_address_get(ep, params[3]); + if (cptr) *cptr = tm->tm_mday; + cptr = embryo_data_address_get(ep, params[4]); + if (cptr) *cptr = tm->tm_yday; + cptr = embryo_data_address_get(ep, params[5]); + if (cptr) *cptr = (tm->tm_wday + 6) % 7; + cptr = embryo_data_address_get(ep, params[6]); + if (cptr) *cptr = tm->tm_hour; + cptr = embryo_data_address_get(ep, params[7]); + if (cptr) *cptr = tm->tm_min; + cptr = embryo_data_address_get(ep, params[8]); + t = (double)tm->tm_sec + (((double)timev.tv_usec) / 1000000); + f = (float)t; + if (cptr) *cptr = EMBRYO_FLOAT_TO_CELL(f); } return 0; } @@ -91,5 +90,6 @@ void _embryo_time_init(Embryo_Program *ep) { embryo_program_native_call_add(ep, "seconds", _embryo_time_seconds); - embryo_program_native_call_add(ep, "date", _embryo_time_date); + embryo_program_native_call_add(ep, "date", _embryo_time_date); } + -- 2.7.4