53 if(v->type != TINT || machdata == 0)
54 error("no size for i fmt pointer ++/--");
55 ret = (*machdata->instsize)(cormap, v->ival);
57 ret = (*machdata->instsize)(symmap, v->ival);
69 error("need l-value");
73 olist(Node *n, Node *res)
80 oeval(Node *n, Node *res)
83 if(res->type != TCODE)
84 error("bad type for eval");
89 ocast(Node *n, Node *res)
92 error("%s is not a complex type", n->sym->name);
95 res->comt = n->sym->lt;
100 oindm(Node *n, Node *res)
110 error("bad type for *");
112 error("no map for *");
113 indir(m, l.ival, l.fmt, res);
118 oindc(Node *n, Node *res)
128 error("bad type for @");
130 error("no map for @");
131 indir(m, l.ival, l.fmt, res);
136 oframe(Node *n, Node *res)
144 while(*p && *p == '$')
147 if(localaddr(cormap, p, lp->sym->name, &ival, rget) < 0)
155 /* Try and set comt */
156 for(f = n->sym->local; f; f = f->next) {
157 if(f->var == lp->sym) {
166 oindex(Node *n, Node *res)
174 error("bad type for []");
178 error("lhs[] has bad type");
180 indir(cormap, l.ival+(r.ival*fsize[l.fmt]), l.fmt, res);
185 nthelem(l.l, r.ival, res);
189 if(r.ival >= 0 && r.ival < l.string->len) {
190 int xx8; /* to get around bug in vc */
192 res->ival = l.string->string[xx8];
202 oappend(Node *n, Node *res)
211 error("must append to list");
212 empty = (l.l == nil && (n->left->op == ONAME));
217 v->Store = res->Store;
223 odelete(Node *n, Node *res)
230 error("must delete from list");
232 error("delete index must be integer");
234 delete(l.l, r.ival, res);
238 ohead(Node *n, Node *res)
244 error("head needs list");
247 res->type = l.l->type;
248 res->Store = l.l->Store;
257 otail(Node *n, Node *res)
263 error("tail needs list");
273 oconst(Node *n, Node *res)
277 res->Store = n->Store;
282 oname(Node *n, Node *res)
288 error("%s used but not set", n->sym->name);
291 res->Store = v->Store;
296 octruct(Node *n, Node *res)
300 res->l = construct(n->left);
304 oasgn(Node *n, Node *res)
312 windir(cormap, lp->left, n->right, res);
315 windir(symmap, lp->left, n->right, res);
326 res->Store = v->Store;
332 oadd(Node *n, Node *res)
336 if(n->right == nil){ /* unary + */
347 error("bad lhs type +");
352 res->ival = l.ival+r.ival;
355 res->fval = l.ival+r.fval;
358 error("bad rhs type +");
364 res->fval = l.fval+r.ival;
367 res->fval = l.fval+r.fval;
370 error("bad rhs type +");
374 if(r.type == TSTRING) {
377 res->string = stradd(l.string, r.string);
383 res->string = straddrune(l.string, r.ival);
386 error("bad rhs for +");
391 res->l = addlist(l.l, r.l);
396 res->l = addlist(l.l, construct(&r));
403 osub(Node *n, Node *res)
414 error("bad lhs type -");
419 res->ival = l.ival-r.ival;
422 res->fval = l.ival-r.fval;
425 error("bad rhs type -");
431 res->fval = l.fval-r.ival;
434 res->fval = l.fval-r.fval;
437 error("bad rhs type -");
444 omul(Node *n, Node *res)
455 error("bad lhs type *");
460 res->ival = l.ival*r.ival;
463 res->fval = l.ival*r.fval;
466 error("bad rhs type *");
472 res->fval = l.fval*r.ival;
475 res->fval = l.fval*r.fval;
478 error("bad rhs type *");
485 odiv(Node *n, Node *res)
496 error("bad lhs type /");
502 error("zero divide");
503 res->ival = l.ival/r.ival;
507 error("zero divide");
508 res->fval = l.ival/r.fval;
511 error("bad rhs type /");
517 res->fval = l.fval/r.ival;
520 res->fval = l.fval/r.fval;
523 error("bad rhs type /");
530 omod(Node *n, Node *res)
539 if(l.type != TINT || r.type != TINT)
540 error("bad expr type %%");
541 res->ival = l.ival%r.ival;
545 olsh(Node *n, Node *res)
554 if(l.type != TINT || r.type != TINT)
555 error("bad expr type <<");
556 res->ival = l.ival<<r.ival;
560 orsh(Node *n, Node *res)
569 if(l.type != TINT || r.type != TINT)
570 error("bad expr type >>");
571 res->ival = (uvlong)l.ival>>r.ival;
575 olt(Node *n, Node *res)
587 error("bad lhs type <");
591 res->ival = l.ival < r.ival;
594 res->ival = l.ival < r.fval;
597 error("bad rhs type <");
603 res->ival = l.fval < r.ival;
606 res->ival = l.fval < r.fval;
609 error("bad rhs type <");
616 ogt(Node *n, Node *res)
627 error("bad lhs type >");
631 res->ival = l.ival > r.ival;
634 res->ival = l.ival > r.fval;
637 error("bad rhs type >");
643 res->ival = l.fval > r.ival;
646 res->ival = l.fval > r.fval;
649 error("bad rhs type >");
656 oleq(Node *n, Node *res)
667 error("bad expr type <=");
671 res->ival = l.ival <= r.ival;
674 res->ival = l.ival <= r.fval;
677 error("bad expr type <=");
683 res->ival = l.fval <= r.ival;
686 res->ival = l.fval <= r.fval;
689 error("bad expr type <=");
696 ogeq(Node *n, Node *res)
707 error("bad lhs type >=");
711 res->ival = l.ival >= r.ival;
714 res->ival = l.ival >= r.fval;
717 error("bad rhs type >=");
723 res->ival = l.fval >= r.ival;
726 res->ival = l.fval >= r.fval;
729 error("bad rhs type >=");
736 oeq(Node *n, Node *res)
752 res->ival = l.ival == r.ival;
755 res->ival = l.ival == r.fval;
764 res->ival = l.fval == r.ival;
767 res->ival = l.fval == r.fval;
774 if(r.type == TSTRING) {
775 res->ival = scmp(r.string, l.string);
780 if(r.type == TLIST) {
781 res->ival = listcmp(l.l, r.l);
787 res->ival = !res->ival;
792 oland(Node *n, Node *res)
801 if(l.type != TINT || r.type != TINT)
802 error("bad expr type &");
803 res->ival = l.ival&r.ival;
807 oxor(Node *n, Node *res)
816 if(l.type != TINT || r.type != TINT)
817 error("bad expr type ^");
818 res->ival = l.ival^r.ival;
822 olor(Node *n, Node *res)
831 if(l.type != TINT || r.type != TINT)
832 error("bad expr type |");
833 res->ival = l.ival|r.ival;
837 ocand(Node *n, Node *res)
855 onot(Node *n, Node *res)
869 ocor(Node *n, Node *res)
890 oeinc(Node *n, Node *res)
901 v->ival -= fmtsize(v);
903 v->ival += fmtsize(v);
912 error("bad type for pre --/++");
914 res->Store = v->Store;
918 opinc(Node *n, Node *res)
926 res->Store = v->Store;
930 v->ival -= fmtsize(v);
932 v->ival += fmtsize(v);
941 error("bad type for post --/++");
946 ocall(Node *n, Node *res)
951 res->op = OCONST; /* Default return value */
958 if(n->builtin && !s->builtin){
959 error("no builtin %s", s->name);
962 if(s->builtin && (n->builtin || s->proc == 0)) {
963 (*s->builtin)(res, n->right);
967 error("no function %s", s->name);
970 call(s->name, n->right, s->proc->left, s->proc->right, res);
975 ofmt(Node *n, Node *res)
978 res->fmt = n->right->ival;
982 owhat(Node *n, Node *res)
984 res->op = OCONST; /* Default return value */
990 void (*expop[])(Node*, Node*) =