void dotrap(void) { Var *trapreq; Word *starval; while(refdec(&ntrap) >= 0) { if(flag['S']) exits(truestatus()?"":getstatus()); starval=vlook("*")->val; trapreq=vlook("sysint"); if(trapreq->fn){ start(trapreq->fn, trapreq->pc, (Var*)0); runq->local=newvar(strdup("*"), runq->local); runq->local->val=copywords(starval, (Word*)0); runq->local->changed=1; runq->redir=runq->startredir=0; } else { /* * run the stack down until we uncover the * command reading loop. Xreturn will exit * if there is none (i.e. if this is not * an interactive rc.) */ while(!runq->iflag) Xreturn(); } } }
void dotrap(void) { int i; struct var *trapreq; struct word *starval; starval = vlook("*")->val; while(ntrap) for(i = 0;i!=NSIG;i++) while(trap[i]){ --trap[i]; --ntrap; if(getpid()!=mypid) Exit(getstatus()); trapreq = vlook(Signame[i]); if(trapreq->fn){ start(trapreq->fn, trapreq->pc, (struct var *)0); runq->local = newvar(strdup("*"), runq->local); runq->local->val = copywords(starval, (struct word *)0); runq->local->changed = 1; runq->redir = runq->startredir = 0; } else if(i==SIGINT || i==SIGQUIT){ /* * run the stack down until we uncover the * command reading loop. Xreturn will exit * if there is none (i.e. if this is not * an interactive rc.) */ while(!runq->iflag) Xreturn(); } else Exit(getstatus()); } }
Pattern *s2bits (char *s) { int i,j; char id; Pattern *p=newpattern(); for (i=0; i<16; i++) { switch(s[i]) { case '1': p->maskset|=(1<<(15-i)); case '0': p->maskbits|=(1<<(15-i)); break; default: id=s[i]; j=newvar(p); p->v[j].id=id; p->v[j].hi=15-i; while(s[++i]==id); i--; p->v[j].lo=15-i; break; } } return p; }
var* gvlook(char *name) { int h = hash(name, NVAR); var *v; for(v = gvar[h];v;v = v->next) if(strcmp(v->name, name)==0) return v; return gvar[h] = newvar(strdup(name), gvar[h]); }
void execfunc(var *func) { word *starval; popword(); starval = runq->argv->words; runq->argv->words = 0; poplist(); start(func->fn, func->pc, runq->local); runq->local = newvar(strdup("*"), runq->local); runq->local->val = starval; runq->local->changed = 1; }
int dealvar(char *s) { int i; for (i=0; i <= varindex; ++i) { if (!strcmp(s,vars[i].name)) { push(vars[i].val); return 0; } } newvar(s); return 0; }
void Xlocal(void) { if(count(runq->argv->words)!=1){ Xerror1("variable name must be singleton\n"); return; } deglob(runq->argv->words->word); runq->local = newvar(strdup(runq->argv->words->word), runq->local); runq->local->val = copywords(runq->argv->next->words, (word *)0); runq->local->changed = 1; poplist(); poplist(); }
void settype (Type *t, Pattern *p, char id) { int i; switch(t->t_id) { case T_SI: case T_SI8: case T_SI16: case T_SI32: i=newvar(p); p->v[i].t=t; p->v[i].id=id; return; } p->v[findvar(p, id)].t=t; }
void definition(char *s) /* collect definition for s and install */ /* char *s; definitions picked up lexically */ { char *p; struct symtab *stp; p = delimstr("definition"); stp = lookup(s); if (stp == NULL) /* it's not there already */ stp = newvar(tostring(s), DEFNAME); else { if (stp->s_type != DEFNAME) { yyerror("%s used as variable and definition", s); return; } free(stp->s_val.p); } stp->s_val.p = p; }
void Xexit(void) { struct var *trapreq; struct word *starval; static int beenhere = 0; if(getpid()==mypid && !beenhere){ trapreq = vlook("sigexit"); if(trapreq->fn){ beenhere = 1; --runq->pc; starval = vlook("*")->val; start(trapreq->fn, trapreq->pc, (struct var *)0); runq->local = newvar(strdup("*"), runq->local); runq->local->val = copywords(starval, (struct word *)0); runq->local->changed = 1; runq->redir = runq->startredir = 0; return; } } Exit(getstatus()); }
void make_operand(expr* e,struct vmarg* arg){ /*if(!e) { arg->type = nil_a; return; }*/ // printf("name:%s and type:%d\n",e->name); switch(e->type){ case var_e:{ arg->val = e->sym->offset; newvar(e->sym->offset,e->sym->name); switch(e->sym->space){ case programvar: arg->type = global_a; break; case functionlocal: arg->type = local_a; break; case formalarg: arg->type = formal_a; break; default: assert(0); } break; /*n from case newtable_e */ } case tableitem_e:{ arg->val = e->sym->offset; switch(e->sym->space){ case programvar: arg->type = global_a; break; case functionlocal: arg->type = local_a; break; case formalarg: arg->type = formal_a; break; default: assert(0); } break; /*n from case newtable_e */ } case boolexpr_e:{ arg->val = e->sym->offset; newvar(e->sym->offset,e->sym->name); switch(e->sym->space){ case programvar: arg->type = global_a; break; case functionlocal: arg->type = local_a; break; case formalarg: arg->type = formal_a; break; default: assert(0); } break; /*n from case newtable_e */ } case assignexpr_e:{ arg->val = e->sym->offset; newvar(e->sym->offset,e->sym->name); switch(e->sym->space){ case programvar: arg->type = global_a; break; case functionlocal: arg->type = local_a; break; case formalarg: arg->type = formal_a; break; default: assert(0); } break; /*n from case newtable_e */ } case newtable_e:{ arg->val = e->sym->offset; switch(e->sym->space){ case programvar: arg->type = global_a; break; case functionlocal: arg->type = local_a; break; case formalarg: arg->type = formal_a; break; default: assert(0); } break; /*n from case newtable_e */ } /* Constants */ case constbool_e:{ unsigned int temp = (unsigned int)e->boolConst; arg->val =e->boolConst; arg->type = bool_a; break; } case conststring_e:{ arg->val = consts_newstring(e->strConst); arg->type = string_a; break; } case constnum_e:{ arg->val = consts_newnumber(e->numConst); arg->type = number_a; break; } case nil_e: arg->type = nil_a; break; /* Functions */ case programfunc_e:{ // printf("in tcode address is:%d\n",e->sym->taddress); arg->val = userfuncs_newfunc(e->sym); arg->type = userfunc_a; break; } case libraryfunc_e:{ arg->type = libfunc_a; arg->val = libfuncs_newused(e->sym->name); break; } default: assert(0); } }
/// Copy contents to new variable template<> AMI_DLLEXPORT BasicVariable::ptr Variable<double>::NewCopy() const { boost::shared_ptr<double> newval( new double(Value())); Variable<double>::ptr newvar(new Variable<double>(newval)); return newvar; }
/** * コードを生成する * @param FILE *ofp 出力先 * @param char *file ファイル名 * @param FEnvCPtr fenvc 関数の型環境 * @param EnvCPtr envc 変数の型環境 * @param ExpPtr ep 式 * @return int 成否 */ int codegen(FILE *ofp, const char *file, FEnvCPtr fenv, EnvCPtr env, ExpPtr ep) { TyType t; TyTypesPtr ts; EnvCPtr env1 = NULL; ExpsPtr es = NULL; FuncT ft = {0}; char l[LABEL_NAME_MAX_SIZE] = ""; char m[LABEL_NAME_MAX_SIZE] = ""; char dty[2] = ""; if(NULL == ep) { return 0; } switch(ep->t) { case VAR_EXP: t = find_var_c(ep->of.var, env); switch(t) { case FLOAT_TYPE: pr_instr(ofp, "fload %d", varnum(ep->of.var, env)); break; default: pr_instr(ofp, "iload %d", varnum(ep->of.var, env)); break; } break; case INT_EXP: pr_instr(ofp, "ldc %d", ep->of.intval); break; case FLOAT_EXP: pr_instr(ofp, "ldc %f", ep->of.floatval); break; case PRIM_EXP: codegen(ofp, file, fenv, env, ep->of.Prim.exp1); codegen(ofp, file, fenv, env, ep->of.Prim.exp2); switch(ep->of.Prim.op) { case PLUS_OP: pr_instr(ofp, "iadd"); break; case FPLUS_OP: pr_instr(ofp, "fadd"); break; case MINUS_OP: pr_instr(ofp, "isub"); break; case FMINUS_OP: pr_instr(ofp, "fsub"); break; case MUL_OP: pr_instr(ofp, "imul"); break; case FMUL_OP: pr_instr(ofp, "fmul"); break; } break; case LET_EXP: codegen(ofp, file, fenv, env, ep->of.Let.exp1); switch((norm(ep->of.Let.tvar.ttp))->t) { case FLOAT_TYPE: pr_instr(ofp, "fstore %d", newvar()); break; default: pr_instr(ofp, "istore %d", newvar()); break; } env1 = envc_alloc(); strncpy_s(env1->var, MAX_VAR_NAME_LENGTH, ep->of.Let.tvar.var, strlen(ep->of.Let.tvar.var)); env1->t = (norm(ep->of.Let.tvar.ttp))->t; env1->next = env; codegen(ofp, file, fenv, env1, ep->of.Let.exp2); break; case IF_EXP: newlabel(l, "else"); newlabel(m, "endif"); codegen(ofp, file, fenv, env, ep->of.If.bp->exp1); codegen(ofp, file, fenv, env, ep->of.If.bp->exp2); switch((norm(ep->of.If.bp->ttp))->t) { case FLOAT_TYPE: pr_instr(ofp, "fcmpl"); pr_instr(ofp, "ifne %s", l); break; default: pr_instr(ofp, "if_icmpne %s", l); break; } codegen(ofp, file, fenv, env, ep->of.If.exp1); pr_instr(ofp, "goto %s", m); fprintf_s(ofp, "%s:\n", l); codegen(ofp, file, fenv, env, ep->of.If.exp2); fprintf_s(ofp, "%s:\n", m); break; case APP_EXP: for(es = ep->of.App.exps; NULL != es; es = es->next) { codegen(ofp, file, fenv, env, es->elm); } ft = find_func_c(ep->of.App.var, fenv); fprintf_s(ofp, "\tinvokestatic %s/%s(", file, ep->of.App.var); for(ts = ft.tys; NULL != ts; ts = ts->next) { desc_of_ty(dty, ts->t); fprintf_s(ofp, "%s", dty); printf("dty -> %s\n", dty); } desc_of_ty(dty, ft.fty); fprintf_s(ofp, ")%s\n", dty); break; } return 1; }
void VariableRegistry::updateFromCodecDatum(const Datum &codec) { mprintf(M_SYSTEM_MESSAGE_DOMAIN, "Received new codec, updating variable registry."); if(!codec.isDictionary()) { merror(M_SYSTEM_MESSAGE_DOMAIN, "Invalid codec received. Registry is unchanged."); return; } boost::mutex::scoped_lock s_lock(lock); master_variable_list.clear(); // add the placeholders //addPlaceholders(); ////////////////////////////////////////////////////////////////// // now add what's in the codec ScarabDatum *datum = codec.getScarabDatum(); ScarabDatum ** keys = datum->data.dict->keys; int size = datum->data.dict->tablesize; int maxCodecCode = -1; // find the maximum codec value for(int i = 0; i < size; ++i) { if(keys[i]) { long long code = keys[i]->data.integer; maxCodecCode = (maxCodecCode < code) ? code : maxCodecCode; } } // add each variable in order to the registry for(int i = N_RESERVED_CODEC_CODES; i<=maxCodecCode; ++i) { ScarabDatum *key = scarab_new_integer(i); ScarabDatum *serializedVariable = scarab_dict_get(datum, key); scarab_free_datum(key); if(!serializedVariable) { shared_ptr<EmptyVariable> empty_var(new EmptyVariable); master_variable_list.push_back(empty_var); continue; } else { if(serializedVariable->type != SCARAB_DICT) { // these must be placeholder datums in the package // that we should ignore. mwarning(M_SYSTEM_MESSAGE_DOMAIN, "Bad variable received from network stream"); shared_ptr<EmptyVariable> empty_var(new EmptyVariable); master_variable_list.push_back(empty_var); continue; } VariableProperties *props = new VariableProperties(serializedVariable); if(props == NULL){ mwarning(M_SYSTEM_MESSAGE_DOMAIN, "Bad variable received from network stream"); shared_ptr<EmptyVariable> empty_var(new EmptyVariable); master_variable_list.push_back(empty_var); continue; } shared_ptr<Variable> newvar(new GlobalVariable(props)); newvar->setCodecCode(i); //necessary? .. Yup master_variable_list.push_back(newvar); std::string tag = newvar->getVariableName(); if(!tag.empty()){ master_variable_dictionary[tag] = newvar; } } } }