hash_init() { int i; hashtab = challoc(sizeof(*hashtab) * maxhash); chain = challoc(sizeof(*chain) * maxhash); value = challoc(sizeof(*value) * maxhash); for (i = 0; i < maxhash; i++) { hashtab[i] = -1L; value[i] = -2; chain[i] = 0; } }
structure() { VERT v, *head; if (progress) fprintf(stderr," getreach:\n"); getreach(); if (routerr) return; if (progress) fprintf(stderr," getflow:\n"); getflow(); if (progress) fprintf(stderr," getthen:\n"); getthen(START); head = challoc(nodenum * sizeof(*head)); for (v = 0; v < nodenum; ++v) head[v] = UNDEFINED; for (v = START; DEFINED(v); v = RSIB(v)) fixhd(v,UNDEFINED,head); /* fixhd must be called before getloop so that it gets applied to IFVX which becomes NXT(w) for UNTVX w */ if (progress) fprintf(stderr," getloop:\n"); getloop(); if (progress) fprintf(stderr," getbranch:\n"); getbranch(head); chfree(head,nodenum * sizeof(*head)); head = 0; }
void writeToLog(char *message, char priority) { FILE *logFile = fopen("log.txt","a"); //Create if necessary fseek(logFile,0,SEEK_END); //Goto end of file char *output = challoc(256,'\0'); switch(priority) { case LOG_ERROR: //Error strcpy(output,"(!!): "); break; case LOG_WARN: //Warning strcpy(output,"(WW): "); break; case LOG_INFO: //Info strcpy(output,"(II): "); break; default: strcpy(output,"(\?\?): "); break; } strcat(output,message); strcat(output,"\n"); fwrite(output,1,strlen(output),logFile); fclose(logFile); return; }
var var_as_double(bombyx_env_t *env, double a) { var v = {0}; v.type = VAR_DOUBLE; v.data_size = sizeof(double); v.data = challoc(env->pool_of_doubles); *(double *)v.data = a; return v; }
output() { VERT w; int i; brace = challoc(nodenum * sizeof(*brace)); for (i = 0; i < nodenum; ++i) brace[i] = FALSE; if (progress) fprintf(stderr,"ndbrace:\n"); for (w = START; DEFINED(w); w = RSIB(w)) ndbrace(w); if (progress) fprintf(stderr,"outrat:\n"); for (w = START; DEFINED(w); w = RSIB(w)) outrat(w,0,YESTAB); OUTSTR("END\n"); chfree(brace,nodenum * sizeof(*brace)); brace = 0; }
map_table_t *json_to_map(bombyx_env_t *env, json_t *json) { size_t index; json_t *value; const char *key; map_table_t *map; // TODO: minimum map size (100?) if (json_is_object(json)) { map = map_table_create(json_object_size(json)); json_object_foreach(json, key, value) { var v = {0}; if (json_is_object(value)) { // process recursively v.type = VAR_MAP; v.data = json_to_map(env, value); v.data_size = sizeof(map_table_t); } else if (json_is_array(value)) { v.type = VAR_ARRAY; v.data = json_to_array(env, value); v.data_size = sizeof(array_t); } else if (json_is_string(value)) { v.type = VAR_STRING; v.data = strdup(json_string_value(value)); v.data_size = json_string_length(value) + 1; } else if (json_is_number(value)) { v.type = VAR_DOUBLE; v.data = challoc(env->pool_of_doubles); v.data_size = sizeof(double); *(double *)v.data = json_number_value(value); } map_add(env, map, (char *)key, v); } }
/* * VMCode is simply a continuous block of memory containing the instruction * information contained in ICodeOperation structs. This gives faster execution * since access locality is improved. The interpreter loop for VMCode is tighter * and does fewer checks and so is also faster than the ICode interpreter. */ int *VMCodeGen(ICodeOperationVector *code) { int *out = challoc(sizeof(int) * VMCode_instruction_size * ICodeOperationVector_size(code)); int *out_ptr = out; int icode_idx; for(icode_idx = 0; icode_idx < ICodeOperationVector_size(code); icode_idx++) { ICodeOperation *op = ICodeOperationVector_get(code, icode_idx); memcpy(out_ptr, op, sizeof(ICodeOperation)); out_ptr += sizeof(ICodeOperation); } return out; }
prog_init() { endline = endcom = 0; endchar = -1; comchar = -1; graph = challoc(sizeof(*graph) * maxnode); }