__inline void StoreValue(int object_id,local_var_type *local_vars,int data_type,int data, val_type new_data) { class_node *class_data; object_node *o; if (kod_stat.debugging) { if (new_data.v.tag == TAG_INVALID) eprintf("[%s] StoreValue trying to assign with uninitialized data (INVALID %i)\n", BlakodDebugInfo(),new_data.v.data); } switch (data_type) { case LOCAL_VAR : if (data < 0 || data >= local_vars->num_locals) { eprintf("[%s] StoreValue can't write to illegal local var %i\n", BlakodDebugInfo(),data); return; } local_vars->locals[data].int_val = new_data.int_val; break; case PROPERTY : o = GetObjectByID(object_id); if (o == NULL) { eprintf("[%s] StoreValue can't find object %i\n", BlakodDebugInfo(),object_id); return; } class_data = GetClassByID(o->class_id); if (class_data == NULL) { eprintf("[%s] StoreValue can't find class id %i\n", BlakodDebugInfo(),o->class_id); return; } /* equal to num_properties is ok, because self = prop 0 */ if (data < 0 || data > class_data->num_properties) { eprintf("[%s] StoreValue can't write to illegal property %i (max %i)\n", BlakodDebugInfo(),data,class_data->num_properties); return; } o->p[data].val.int_val = new_data.int_val; break; default : eprintf("[%s] StoreValue can't identify type %i\n", BlakodDebugInfo(),data_type); break; } }
void bprintf(const char *fmt,...) { char s[BUFFER_SIZE]; va_list marker; sprintf(s,"%s | [%s] ",TimeStr(GetTime()),BlakodDebugInfo()); va_start(marker,fmt); vsprintf(s+strlen(s),fmt,marker); va_end(marker); if (s[strlen(s)-1] != '\n') strcat(s,"\r\n"); WriteStrChannel(CHANNEL_E,s); }
void bprintf(const char *fmt,...) { char s[1000]; va_list marker; sprintf(s,"%s | [%s] ",TimeStr(GetTime()),BlakodDebugInfo()); va_start(marker,fmt); vsprintf(s+strlen(s),fmt,marker); va_end(marker); TermConvertBuffer(s,sizeof(s)); /* makes \n's into CR/LF pairs */ if (s[strlen(s)-1] != '\n') strcat(s,"\r\n"); WriteStrChannel(CHANNEL_E,s); }
/* returns either RETURN_PROPAGATE or RETURN_NO_PROPAGATE. If no propagate, * then the return value in ret_val is good. */ int InterpretAtMessage(int object_id,class_node* c,message_node* m, int num_sent_parms, parm_node sent_parms[],val_type *ret_val) { opcode_type opcode; char opcode_char; char num_locals,num_parms; local_var_type local_vars; int parm_id; val_type parm_init_value; int i,j; char *inst_start; Bool found_parm; num_locals = get_byte(); num_parms = get_byte(); local_vars.num_locals = num_locals+num_parms; if (local_vars.num_locals > MAX_LOCALS) { dprintf("InterpretAtMessage found too many locals and parms for OBJECT %i CLASS %s MESSAGE %s (%s) aborting and returning NIL\n", object_id, c? c->class_name : "(unknown)", m? GetNameByID(m->message_id) : "(unknown)", BlakodDebugInfo()); (*ret_val).int_val = NIL; return RETURN_NO_PROPAGATE; } if (ConfigBool(DEBUG_INITLOCALS)) { parm_init_value.v.tag = TAG_INVALID; parm_init_value.v.data = 1; for (i = 0; i < local_vars.num_locals; i++) { local_vars.locals[i] = parm_init_value; } } /* both table and call parms are sorted */ j = 0; for (i=0;i<num_parms;i++) { parm_id = get_int(); /* match this with parameters */ parm_init_value.int_val = get_int(); /* look if we have a value for this parm */ found_parm = False; j = 0; /* don't assume sorted for now */ while (j < num_sent_parms) { if (sent_parms[j].name_id == parm_id) { /* assuming no RetrieveValue needed here, since InterpretCall does that for us */ local_vars.locals[i].int_val = sent_parms[j].value; found_parm = True; j++; break; } j++; } if (!found_parm) local_vars.locals[i].int_val = parm_init_value.int_val; } for(;;) /* returns when gets a blakod return */ { num_interpreted++; /* infinite loop check */ if (num_interpreted > ConfigInt(BLAKOD_MAX_STATEMENTS)) { bprintf("InterpretAtMessage interpreted too many instructions--infinite loop?\n"); dprintf("Infinite loop at depth %i\n", message_depth); dprintf(" OBJECT %i CLASS %s MESSAGE %s (%s) aborting and returning NIL\n", object_id, c? c->class_name : "(unknown)", m? GetNameByID(m->message_id) : "(unknown)", BlakodDebugInfo()); dprintf(" Local variables:\n"); for (i=0;i<local_vars.num_locals;i++) { dprintf(" %3i : %s %5i\n", i, GetTagName(local_vars.locals[i]), local_vars.locals[i].v.data); } (*ret_val).int_val = NIL; return RETURN_NO_PROPAGATE; } opcode_char = get_byte(); //memcpy(&opcode,&opcode_char,1); { char *ch=(char*)&opcode; *ch = opcode_char ; } /* use continues instead of breaks here since there is nothing after the switch, for efficiency */ switch (opcode.command) { case UNARY_ASSIGN : InterpretUnaryAssign(object_id,&local_vars,opcode); continue; case BINARY_ASSIGN : InterpretBinaryAssign(object_id,&local_vars,opcode); continue; case GOTO : inst_start = bkod - 1; /* we've read one byte of instruction so far */ InterpretGoto(object_id,&local_vars,opcode,inst_start); continue; case CALL : InterpretCall(object_id,&local_vars,opcode); continue; case RETURN : if (opcode.dest == PROPAGATE) return RETURN_PROPAGATE; else { int data; data = get_int(); *ret_val = RetrieveValue(object_id,&local_vars,opcode.source1,data); return RETURN_NO_PROPAGATE; } /* can't get here */ continue; default : bprintf("InterpretAtMessage found INVALID OPCODE command %i. die.\n", opcode.command); FlushDefaultChannels(); continue; } } }