expr.c 15 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <bio.h>
  4. #include <ctype.h>
  5. #include <mach.h>
  6. #define Extern extern
  7. #include "acid.h"
  8. static int fsize[] =
  9. {
  10. ['A'] 4,
  11. ['B'] 4,
  12. ['C'] 1,
  13. ['D'] 4,
  14. ['F'] 8,
  15. ['G'] 8,
  16. ['O'] 4,
  17. ['Q'] 4,
  18. ['R'] 4,
  19. ['S'] 4,
  20. ['U'] 4,
  21. ['V'] 8,
  22. ['X'] 4,
  23. ['Y'] 8,
  24. ['W'] 8,
  25. ['Z'] 8,
  26. ['a'] 4,
  27. ['b'] 1,
  28. ['c'] 1,
  29. ['d'] 2,
  30. ['f'] 4,
  31. ['g'] 4,
  32. ['o'] 2,
  33. ['q'] 2,
  34. ['r'] 2,
  35. ['s'] 4,
  36. ['u'] 2,
  37. ['x'] 2,
  38. };
  39. int
  40. fmtsize(Value *v)
  41. {
  42. int ret;
  43. switch(v->fmt) {
  44. default:
  45. return fsize[v->fmt];
  46. case 'i':
  47. case 'I':
  48. if(v->type != TINT || machdata == 0)
  49. error("no size for i fmt pointer ++/--");
  50. ret = (*machdata->instsize)(cormap, v->ival);
  51. if(ret < 0) {
  52. ret = (*machdata->instsize)(symmap, v->ival);
  53. if(ret < 0)
  54. error("%r");
  55. }
  56. return ret;
  57. }
  58. }
  59. void
  60. chklval(Node *lp)
  61. {
  62. if(lp->op != ONAME)
  63. error("need l-value");
  64. }
  65. void
  66. olist(Node *n, Node *res)
  67. {
  68. expr(n->left, res);
  69. expr(n->right, res);
  70. }
  71. void
  72. oeval(Node *n, Node *res)
  73. {
  74. expr(n->left, res);
  75. if(res->type != TCODE)
  76. error("bad type for eval");
  77. expr(res->cc, res);
  78. }
  79. void
  80. ocast(Node *n, Node *res)
  81. {
  82. if(n->sym->lt == 0)
  83. error("%s is not a complex type", n->sym->name);
  84. expr(n->left, res);
  85. res->comt = n->sym->lt;
  86. res->fmt = 'a';
  87. }
  88. void
  89. oindm(Node *n, Node *res)
  90. {
  91. Map *m;
  92. Node l;
  93. m = cormap;
  94. if(m == 0)
  95. m = symmap;
  96. expr(n->left, &l);
  97. if(l.type != TINT)
  98. error("bad type for *");
  99. if(m == 0)
  100. error("no map for *");
  101. indir(m, l.ival, l.fmt, res);
  102. res->comt = l.comt;
  103. }
  104. void
  105. oindc(Node *n, Node *res)
  106. {
  107. Map *m;
  108. Node l;
  109. m = symmap;
  110. if(m == 0)
  111. m = cormap;
  112. expr(n->left, &l);
  113. if(l.type != TINT)
  114. error("bad type for @");
  115. if(m == 0)
  116. error("no map for @");
  117. indir(m, l.ival, l.fmt, res);
  118. res->comt = l.comt;
  119. }
  120. void
  121. oframe(Node *n, Node *res)
  122. {
  123. char *p;
  124. Node *lp;
  125. long ival;
  126. Frtype *f;
  127. p = n->sym->name;
  128. while(*p && *p == '$')
  129. p++;
  130. lp = n->left;
  131. if(localaddr(cormap, p, lp->sym->name, &ival, rget) < 0)
  132. error("colon: %r");
  133. res->ival = ival;
  134. res->op = OCONST;
  135. res->fmt = 'X';
  136. res->type = TINT;
  137. /* Try and set comt */
  138. for(f = n->sym->local; f; f = f->next) {
  139. if(f->var == lp->sym) {
  140. res->comt = f->type;
  141. res->fmt = 'a';
  142. break;
  143. }
  144. }
  145. }
  146. void
  147. oindex(Node *n, Node *res)
  148. {
  149. Node l, r;
  150. expr(n->left, &l);
  151. expr(n->right, &r);
  152. if(r.type != TINT)
  153. error("bad type for []");
  154. switch(l.type) {
  155. default:
  156. error("lhs[] has bad type");
  157. case TINT:
  158. indir(cormap, l.ival+(r.ival*fsize[l.fmt]), l.fmt, res);
  159. res->comt = l.comt;
  160. res->fmt = l.fmt;
  161. break;
  162. case TLIST:
  163. nthelem(l.l, r.ival, res);
  164. break;
  165. case TSTRING:
  166. res->ival = 0;
  167. if(r.ival >= 0 && r.ival < l.string->len) {
  168. int xx8; /* to get around bug in vc */
  169. xx8 = r.ival;
  170. res->ival = l.string->string[xx8];
  171. }
  172. res->op = OCONST;
  173. res->type = TINT;
  174. res->fmt = 'c';
  175. break;
  176. }
  177. }
  178. void
  179. oappend(Node *n, Node *res)
  180. {
  181. Node r, l;
  182. expr(n->left, &l);
  183. expr(n->right, &r);
  184. if(l.type != TLIST)
  185. error("must append to list");
  186. append(res, &l, &r);
  187. }
  188. void
  189. odelete(Node *n, Node *res)
  190. {
  191. Node l, r;
  192. expr(n->left, &l);
  193. expr(n->right, &r);
  194. if(l.type != TLIST)
  195. error("must delete from list");
  196. if(r.type != TINT)
  197. error("delete index must be integer");
  198. delete(l.l, r.ival, res);
  199. }
  200. void
  201. ohead(Node *n, Node *res)
  202. {
  203. Node l;
  204. expr(n->left, &l);
  205. if(l.type != TLIST)
  206. error("head needs list");
  207. res->op = OCONST;
  208. if(l.l) {
  209. res->type = l.l->type;
  210. res->Store = l.l->Store;
  211. }
  212. else {
  213. res->type = TLIST;
  214. res->l = 0;
  215. }
  216. }
  217. void
  218. otail(Node *n, Node *res)
  219. {
  220. Node l;
  221. expr(n->left, &l);
  222. if(l.type != TLIST)
  223. error("tail needs list");
  224. res->op = OCONST;
  225. res->type = TLIST;
  226. if(l.l)
  227. res->l = l.l->next;
  228. else
  229. res->l = 0;
  230. }
  231. void
  232. oconst(Node *n, Node *res)
  233. {
  234. res->op = OCONST;
  235. res->type = n->type;
  236. res->Store = n->Store;
  237. res->comt = n->comt;
  238. }
  239. void
  240. oname(Node *n, Node *res)
  241. {
  242. Value *v;
  243. v = n->sym->v;
  244. if(v->set == 0)
  245. error("%s used but not set", n->sym->name);
  246. res->op = OCONST;
  247. res->type = v->type;
  248. res->Store = v->Store;
  249. res->comt = v->comt;
  250. }
  251. void
  252. octruct(Node *n, Node *res)
  253. {
  254. res->op = OCONST;
  255. res->type = TLIST;
  256. res->l = construct(n->left);
  257. }
  258. void
  259. oasgn(Node *n, Node *res)
  260. {
  261. Node *lp, r;
  262. Value *v;
  263. lp = n->left;
  264. switch(lp->op) {
  265. case OINDM:
  266. windir(cormap, lp->left, n->right, res);
  267. break;
  268. case OINDC:
  269. windir(symmap, lp->left, n->right, res);
  270. break;
  271. default:
  272. chklval(lp);
  273. v = lp->sym->v;
  274. expr(n->right, &r);
  275. v->set = 1;
  276. v->type = r.type;
  277. v->Store = r.Store;
  278. res->op = OCONST;
  279. res->type = v->type;
  280. res->Store = v->Store;
  281. res->comt = v->comt;
  282. }
  283. }
  284. void
  285. oadd(Node *n, Node *res)
  286. {
  287. Node l, r;
  288. expr(n->left, &l);
  289. expr(n->right, &r);
  290. res->fmt = l.fmt;
  291. res->op = OCONST;
  292. res->type = TFLOAT;
  293. switch(l.type) {
  294. default:
  295. error("bad lhs type +");
  296. case TINT:
  297. switch(r.type) {
  298. case TINT:
  299. res->type = TINT;
  300. res->ival = l.ival+r.ival;
  301. break;
  302. case TFLOAT:
  303. res->fval = l.ival+r.fval;
  304. break;
  305. default:
  306. error("bad rhs type +");
  307. }
  308. break;
  309. case TFLOAT:
  310. switch(r.type) {
  311. case TINT:
  312. res->fval = l.fval+r.ival;
  313. break;
  314. case TFLOAT:
  315. res->fval = l.fval+r.fval;
  316. break;
  317. default:
  318. error("bad rhs type +");
  319. }
  320. break;
  321. case TSTRING:
  322. if(r.type == TSTRING) {
  323. res->type = TSTRING;
  324. res->fmt = 's';
  325. res->string = stradd(l.string, r.string);
  326. break;
  327. }
  328. error("bad rhs for +");
  329. case TLIST:
  330. res->type = TLIST;
  331. switch(r.type) {
  332. case TLIST:
  333. res->l = addlist(l.l, r.l);
  334. break;
  335. default:
  336. r.left = 0;
  337. r.right = 0;
  338. res->l = addlist(l.l, construct(&r));
  339. break;
  340. }
  341. }
  342. }
  343. void
  344. osub(Node *n, Node *res)
  345. {
  346. Node l, r;
  347. expr(n->left, &l);
  348. expr(n->right, &r);
  349. res->fmt = l.fmt;
  350. res->op = OCONST;
  351. res->type = TFLOAT;
  352. switch(l.type) {
  353. default:
  354. error("bad lhs type -");
  355. case TINT:
  356. switch(r.type) {
  357. case TINT:
  358. res->type = TINT;
  359. res->ival = l.ival-r.ival;
  360. break;
  361. case TFLOAT:
  362. res->fval = l.ival-r.fval;
  363. break;
  364. default:
  365. error("bad rhs type -");
  366. }
  367. break;
  368. case TFLOAT:
  369. switch(r.type) {
  370. case TINT:
  371. res->fval = l.fval-r.ival;
  372. break;
  373. case TFLOAT:
  374. res->fval = l.fval-r.fval;
  375. break;
  376. default:
  377. error("bad rhs type -");
  378. }
  379. break;
  380. }
  381. }
  382. void
  383. omul(Node *n, Node *res)
  384. {
  385. Node l, r;
  386. expr(n->left, &l);
  387. expr(n->right, &r);
  388. res->fmt = l.fmt;
  389. res->op = OCONST;
  390. res->type = TFLOAT;
  391. switch(l.type) {
  392. default:
  393. error("bad lhs type *");
  394. case TINT:
  395. switch(r.type) {
  396. case TINT:
  397. res->type = TINT;
  398. res->ival = l.ival*r.ival;
  399. break;
  400. case TFLOAT:
  401. res->fval = l.ival*r.fval;
  402. break;
  403. default:
  404. error("bad rhs type *");
  405. }
  406. break;
  407. case TFLOAT:
  408. switch(r.type) {
  409. case TINT:
  410. res->fval = l.fval*r.ival;
  411. break;
  412. case TFLOAT:
  413. res->fval = l.fval*r.fval;
  414. break;
  415. default:
  416. error("bad rhs type *");
  417. }
  418. break;
  419. }
  420. }
  421. void
  422. odiv(Node *n, Node *res)
  423. {
  424. Node l, r;
  425. expr(n->left, &l);
  426. expr(n->right, &r);
  427. res->fmt = l.fmt;
  428. res->op = OCONST;
  429. res->type = TFLOAT;
  430. switch(l.type) {
  431. default:
  432. error("bad lhs type /");
  433. case TINT:
  434. switch(r.type) {
  435. case TINT:
  436. res->type = TINT;
  437. if(r.ival == 0)
  438. error("zero divide");
  439. res->ival = l.ival/r.ival;
  440. break;
  441. case TFLOAT:
  442. if(r.fval == 0)
  443. error("zero divide");
  444. res->fval = l.ival/r.fval;
  445. break;
  446. default:
  447. error("bad rhs type /");
  448. }
  449. break;
  450. case TFLOAT:
  451. switch(r.type) {
  452. case TINT:
  453. res->fval = l.fval/r.ival;
  454. break;
  455. case TFLOAT:
  456. res->fval = l.fval/r.fval;
  457. break;
  458. default:
  459. error("bad rhs type /");
  460. }
  461. break;
  462. }
  463. }
  464. void
  465. omod(Node *n, Node *res)
  466. {
  467. Node l, r;
  468. expr(n->left, &l);
  469. expr(n->right, &r);
  470. res->fmt = l.fmt;
  471. res->op = OCONST;
  472. res->type = TINT;
  473. if(l.type != TINT || r.type != TINT)
  474. error("bad expr type %");
  475. res->ival = l.ival%r.ival;
  476. }
  477. void
  478. olsh(Node *n, Node *res)
  479. {
  480. Node l, r;
  481. expr(n->left, &l);
  482. expr(n->right, &r);
  483. res->fmt = l.fmt;
  484. res->op = OCONST;
  485. res->type = TINT;
  486. if(l.type != TINT || r.type != TINT)
  487. error("bad expr type <<");
  488. res->ival = l.ival<<r.ival;
  489. }
  490. void
  491. orsh(Node *n, Node *res)
  492. {
  493. Node l, r;
  494. expr(n->left, &l);
  495. expr(n->right, &r);
  496. res->fmt = l.fmt;
  497. res->op = OCONST;
  498. res->type = TINT;
  499. if(l.type != TINT || r.type != TINT)
  500. error("bad expr type >>");
  501. res->ival = (unsigned)l.ival>>r.ival;
  502. }
  503. void
  504. olt(Node *n, Node *res)
  505. {
  506. Node l, r;
  507. expr(n->left, &l);
  508. expr(n->right, &r);
  509. res->fmt = l.fmt;
  510. res->op = OCONST;
  511. res->type = TINT;
  512. switch(l.type) {
  513. default:
  514. error("bad lhs type <");
  515. case TINT:
  516. switch(r.type) {
  517. case TINT:
  518. res->ival = l.ival < r.ival;
  519. break;
  520. case TFLOAT:
  521. res->ival = l.ival < r.fval;
  522. break;
  523. default:
  524. error("bad rhs type <");
  525. }
  526. break;
  527. case TFLOAT:
  528. switch(r.type) {
  529. case TINT:
  530. res->ival = l.fval < r.ival;
  531. break;
  532. case TFLOAT:
  533. res->ival = l.fval < r.fval;
  534. break;
  535. default:
  536. error("bad rhs type <");
  537. }
  538. break;
  539. }
  540. }
  541. void
  542. ogt(Node *n, Node *res)
  543. {
  544. Node l, r;
  545. expr(n->left, &l);
  546. expr(n->right, &r);
  547. res->fmt = 'D';
  548. res->op = OCONST;
  549. res->type = TINT;
  550. switch(l.type) {
  551. default:
  552. error("bad lhs type >");
  553. case TINT:
  554. switch(r.type) {
  555. case TINT:
  556. res->ival = l.ival > r.ival;
  557. break;
  558. case TFLOAT:
  559. res->ival = l.ival > r.fval;
  560. break;
  561. default:
  562. error("bad rhs type >");
  563. }
  564. break;
  565. case TFLOAT:
  566. switch(r.type) {
  567. case TINT:
  568. res->ival = l.fval > r.ival;
  569. break;
  570. case TFLOAT:
  571. res->ival = l.fval > r.fval;
  572. break;
  573. default:
  574. error("bad rhs type >");
  575. }
  576. break;
  577. }
  578. }
  579. void
  580. oleq(Node *n, Node *res)
  581. {
  582. Node l, r;
  583. expr(n->left, &l);
  584. expr(n->right, &r);
  585. res->fmt = 'D';
  586. res->op = OCONST;
  587. res->type = TINT;
  588. switch(l.type) {
  589. default:
  590. error("bad expr type <=");
  591. case TINT:
  592. switch(r.type) {
  593. case TINT:
  594. res->ival = l.ival <= r.ival;
  595. break;
  596. case TFLOAT:
  597. res->ival = l.ival <= r.fval;
  598. break;
  599. default:
  600. error("bad expr type <=");
  601. }
  602. break;
  603. case TFLOAT:
  604. switch(r.type) {
  605. case TINT:
  606. res->ival = l.fval <= r.ival;
  607. break;
  608. case TFLOAT:
  609. res->ival = l.fval <= r.fval;
  610. break;
  611. default:
  612. error("bad expr type <=");
  613. }
  614. break;
  615. }
  616. }
  617. void
  618. ogeq(Node *n, Node *res)
  619. {
  620. Node l, r;
  621. expr(n->left, &l);
  622. expr(n->right, &r);
  623. res->fmt = 'D';
  624. res->op = OCONST;
  625. res->type = TINT;
  626. switch(l.type) {
  627. default:
  628. error("bad lhs type >=");
  629. case TINT:
  630. switch(r.type) {
  631. case TINT:
  632. res->ival = l.ival >= r.ival;
  633. break;
  634. case TFLOAT:
  635. res->ival = l.ival >= r.fval;
  636. break;
  637. default:
  638. error("bad rhs type >=");
  639. }
  640. break;
  641. case TFLOAT:
  642. switch(r.type) {
  643. case TINT:
  644. res->ival = l.fval >= r.ival;
  645. break;
  646. case TFLOAT:
  647. res->ival = l.fval >= r.fval;
  648. break;
  649. default:
  650. error("bad rhs type >=");
  651. }
  652. break;
  653. }
  654. }
  655. void
  656. oeq(Node *n, Node *res)
  657. {
  658. Node l, r;
  659. expr(n->left, &l);
  660. expr(n->right, &r);
  661. res->fmt = 'D';
  662. res->op = OCONST;
  663. res->type = TINT;
  664. res->ival = 0;
  665. switch(l.type) {
  666. default:
  667. break;
  668. case TINT:
  669. switch(r.type) {
  670. case TINT:
  671. res->ival = l.ival == r.ival;
  672. break;
  673. case TFLOAT:
  674. res->ival = l.ival == r.fval;
  675. break;
  676. default:
  677. break;
  678. }
  679. break;
  680. case TFLOAT:
  681. switch(r.type) {
  682. case TINT:
  683. res->ival = l.fval == r.ival;
  684. break;
  685. case TFLOAT:
  686. res->ival = l.fval == r.fval;
  687. break;
  688. default:
  689. break;
  690. }
  691. break;
  692. case TSTRING:
  693. if(r.type == TSTRING) {
  694. res->ival = scmp(r.string, l.string);
  695. break;
  696. }
  697. break;
  698. case TLIST:
  699. if(r.type == TLIST) {
  700. res->ival = listcmp(l.l, r.l);
  701. break;
  702. }
  703. break;
  704. }
  705. if(n->op == ONEQ)
  706. res->ival = !res->ival;
  707. }
  708. void
  709. oland(Node *n, Node *res)
  710. {
  711. Node l, r;
  712. expr(n->left, &l);
  713. expr(n->right, &r);
  714. res->fmt = l.fmt;
  715. res->op = OCONST;
  716. res->type = TINT;
  717. if(l.type != TINT || r.type != TINT)
  718. error("bad expr type &");
  719. res->ival = l.ival&r.ival;
  720. }
  721. void
  722. oxor(Node *n, Node *res)
  723. {
  724. Node l, r;
  725. expr(n->left, &l);
  726. expr(n->right, &r);
  727. res->fmt = l.fmt;
  728. res->op = OCONST;
  729. res->type = TINT;
  730. if(l.type != TINT || r.type != TINT)
  731. error("bad expr type ^");
  732. res->ival = l.ival^r.ival;
  733. }
  734. void
  735. olor(Node *n, Node *res)
  736. {
  737. Node l, r;
  738. expr(n->left, &l);
  739. expr(n->right, &r);
  740. res->fmt = l.fmt;
  741. res->op = OCONST;
  742. res->type = TINT;
  743. if(l.type != TINT || r.type != TINT)
  744. error("bad expr type |");
  745. res->ival = l.ival|r.ival;
  746. }
  747. void
  748. ocand(Node *n, Node *res)
  749. {
  750. Node l, r;
  751. res->fmt = l.fmt;
  752. res->op = OCONST;
  753. res->type = TINT;
  754. res->ival = 0;
  755. expr(n->left, &l);
  756. if(bool(&l) == 0)
  757. return;
  758. expr(n->right, &r);
  759. if(bool(&r) == 0)
  760. return;
  761. res->ival = 1;
  762. }
  763. void
  764. onot(Node *n, Node *res)
  765. {
  766. Node l;
  767. res->op = OCONST;
  768. res->type = TINT;
  769. res->ival = 0;
  770. expr(n->left, &l);
  771. if(bool(&l) == 0)
  772. res->ival = 1;
  773. }
  774. void
  775. ocor(Node *n, Node *res)
  776. {
  777. Node l, r;
  778. res->op = OCONST;
  779. res->type = TINT;
  780. res->ival = 0;
  781. expr(n->left, &l);
  782. if(bool(&l)) {
  783. res->ival = 1;
  784. return;
  785. }
  786. expr(n->right, &r);
  787. if(bool(&r)) {
  788. res->ival = 1;
  789. return;
  790. }
  791. }
  792. void
  793. oeinc(Node *n, Node *res)
  794. {
  795. Value *v;
  796. chklval(n->left);
  797. v = n->left->sym->v;
  798. res->op = OCONST;
  799. res->type = v->type;
  800. switch(v->type) {
  801. case TINT:
  802. if(n->op == OEDEC)
  803. v->ival -= fmtsize(v);
  804. else
  805. v->ival += fmtsize(v);
  806. break;
  807. case TFLOAT:
  808. if(n->op == OEDEC)
  809. v->fval--;
  810. else
  811. v->fval++;
  812. break;
  813. default:
  814. error("bad type for pre --/++");
  815. }
  816. res->Store = v->Store;
  817. }
  818. void
  819. opinc(Node *n, Node *res)
  820. {
  821. Value *v;
  822. chklval(n->left);
  823. v = n->left->sym->v;
  824. res->op = OCONST;
  825. res->type = v->type;
  826. res->Store = v->Store;
  827. switch(v->type) {
  828. case TINT:
  829. if(n->op == OPDEC)
  830. v->ival -= fmtsize(v);
  831. else
  832. v->ival += fmtsize(v);
  833. break;
  834. case TFLOAT:
  835. if(n->op == OPDEC)
  836. v->fval--;
  837. else
  838. v->fval++;
  839. break;
  840. default:
  841. error("bad type for post --/++");
  842. }
  843. }
  844. void
  845. ocall(Node *n, Node *res)
  846. {
  847. Lsym *s;
  848. Rplace *rsav;
  849. res->op = OCONST; /* Default return value */
  850. res->type = TLIST;
  851. res->l = 0;
  852. chklval(n->left);
  853. s = n->left->sym;
  854. if(n->builtin && !s->builtin){
  855. error("no builtin %s", s->name);
  856. return;
  857. }
  858. if(s->builtin && (n->builtin || s->proc == 0)) {
  859. (*s->builtin)(res, n->right);
  860. return;
  861. }
  862. if(s->proc == 0)
  863. error("no function %s", s->name);
  864. rsav = ret;
  865. call(s->name, n->right, s->proc->left, s->proc->right, res);
  866. ret = rsav;
  867. }
  868. void
  869. ofmt(Node *n, Node *res)
  870. {
  871. expr(n->left, res);
  872. res->fmt = n->right->ival;
  873. }
  874. void
  875. owhat(Node *n, Node *res)
  876. {
  877. res->op = OCONST; /* Default return value */
  878. res->type = TLIST;
  879. res->l = 0;
  880. whatis(n->sym);
  881. }
  882. void (*expop[])(Node*, Node*) =
  883. {
  884. [ONAME] oname,
  885. [OCONST] oconst,
  886. [OMUL] omul,
  887. [ODIV] odiv,
  888. [OMOD] omod,
  889. [OADD] oadd,
  890. [OSUB] osub,
  891. [ORSH] orsh,
  892. [OLSH] olsh,
  893. [OLT] olt,
  894. [OGT] ogt,
  895. [OLEQ] oleq,
  896. [OGEQ] ogeq,
  897. [OEQ] oeq,
  898. [ONEQ] oeq,
  899. [OLAND] oland,
  900. [OXOR] oxor,
  901. [OLOR] olor,
  902. [OCAND] ocand,
  903. [OCOR] ocor,
  904. [OASGN] oasgn,
  905. [OINDM] oindm,
  906. [OEDEC] oeinc,
  907. [OEINC] oeinc,
  908. [OPINC] opinc,
  909. [OPDEC] opinc,
  910. [ONOT] onot,
  911. [OIF] 0,
  912. [ODO] 0,
  913. [OLIST] olist,
  914. [OCALL] ocall,
  915. [OCTRUCT] octruct,
  916. [OWHILE] 0,
  917. [OELSE] 0,
  918. [OHEAD] ohead,
  919. [OTAIL] otail,
  920. [OAPPEND] oappend,
  921. [ORET] 0,
  922. [OINDEX] oindex,
  923. [OINDC] oindc,
  924. [ODOT] odot,
  925. [OLOCAL] 0,
  926. [OFRAME] oframe,
  927. [OCOMPLEX] 0,
  928. [ODELETE] odelete,
  929. [OCAST] ocast,
  930. [OFMT] ofmt,
  931. [OEVAL] oeval,
  932. [OWHAT] owhat,
  933. };