The Sol Programming Language!
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. #include <string.h>
  2. #include <stdlib.h>
  3. #include "ast.h"
  4. extern int yydebug;
  5. char *sol_BytecodeNames[] = {
  6. "BC_NULL",
  7. "BC_ST_EXPR",
  8. "BC_ST_LIST",
  9. "BC_ST_RET",
  10. "BC_ST_CONT",
  11. "BC_ST_BREAK",
  12. "BC_EX_LIT",
  13. "BC_EX_LISTGEN",
  14. "BC_EX_MAPGEN",
  15. "BC_EX_BINOP",
  16. "BC_EX_UNOP",
  17. "BC_EX_INDEX",
  18. "BC_EX_SETINDEX",
  19. "BC_EX_ASSIGN",
  20. "BC_EX_REF",
  21. "BC_EX_CALL",
  22. "BC_EX_FUNCDECL",
  23. "BC_EX_IFELSE",
  24. "BC_EX_LOOP",
  25. "BC_EX_ITER",
  26. "BC_LIT_INT",
  27. "BC_LIT_FLOAT",
  28. "BC_LIT_STRING",
  29. "BC_LIT_BUFFER",
  30. "BC_LIT_NONE",
  31. "BC_INT",
  32. "BC_FLOAT",
  33. "BC_STRING",
  34. "BC_BUFFER",
  35. "BC_LIST_ST",
  36. "BC_LIST_EX",
  37. "BC_LIST_AS",
  38. "BC_LIST_ID",
  39. "BC_LIST_PM",
  40. "BC_ENDLIST",
  41. };
  42. void sol_ser_stmt(FILE *io, stmt_node *st) {
  43. if(!st) {
  44. fputc(BC_NULL, io);
  45. return;
  46. }
  47. switch(st->type) {
  48. case ST_EXPR:
  49. fputc(BC_ST_EXPR, io);
  50. sol_ser_expr(io, st->expr);
  51. break;
  52. case ST_LIST:
  53. fputc(BC_ST_LIST, io);
  54. sol_ser_stl(io, st->stmtlist);
  55. break;
  56. case ST_RET:
  57. fputc(BC_ST_RET, io);
  58. sol_ser_expr(io, st->ret->ret);
  59. break;
  60. case ST_CONT:
  61. fputc(BC_ST_CONT, io);
  62. sol_ser_expr(io, st->cont->val);
  63. break;
  64. case ST_BREAK:
  65. fputc(BC_ST_BREAK, io);
  66. sol_ser_expr(io, st->brk->val);
  67. break;
  68. default:
  69. printf("WARNING: Unknown statement type to serialize: %d\n", st->type);
  70. break;
  71. }
  72. }
  73. void sol_ser_stl(FILE *io, stmtlist_node *stl) {
  74. fputc(BC_LIST_ST, io);
  75. while(stl) {
  76. sol_ser_stmt(io, stl->stmt);
  77. stl = stl->next;
  78. }
  79. fputc(BC_ENDLIST, io);
  80. }
  81. void sol_ser_expr(FILE *io, expr_node *ex) {
  82. if(!ex) {
  83. fputc(BC_NULL, io);
  84. return;
  85. }
  86. switch(ex->type) {
  87. case EX_LIT:
  88. fputc(BC_EX_LIT, io);
  89. sol_ser_lit(io, ex->lit);
  90. break;
  91. case EX_LISTGEN:
  92. fputc(BC_EX_LISTGEN, io);
  93. sol_ser_exl(io, ex->listgen->list);
  94. break;
  95. case EX_MAPGEN:
  96. fputc(BC_EX_MAPGEN, io);
  97. sol_ser_asl(io, ex->mapgen->map);
  98. break;
  99. case EX_BINOP:
  100. fputc(BC_EX_BINOP, io);
  101. fputc(ex->binop->type - OP_ADD, io);
  102. sol_ser_expr(io, ex->binop->left);
  103. sol_ser_expr(io, ex->binop->right);
  104. break;
  105. case EX_UNOP:
  106. fputc(BC_EX_UNOP, io);
  107. fputc(ex->unop->type - OP_NEG, io);
  108. sol_ser_expr(io, ex->unop->expr);
  109. break;
  110. case EX_INDEX:
  111. fputc(BC_EX_INDEX, io);
  112. sol_ser_expr(io, ex->index->expr);
  113. sol_ser_expr(io, ex->index->index);
  114. break;
  115. case EX_SETINDEX:
  116. fputc(BC_EX_SETINDEX, io);
  117. sol_ser_expr(io, ex->setindex->expr);
  118. sol_ser_expr(io, ex->setindex->index);
  119. sol_ser_expr(io, ex->setindex->value);
  120. break;
  121. case EX_ASSIGN:
  122. fputc(BC_EX_ASSIGN, io);
  123. sol_ser_str(io, ex->assign->ident);
  124. sol_ser_expr(io, ex->assign->value);
  125. break;
  126. case EX_REF:
  127. fputc(BC_EX_REF, io);
  128. sol_ser_str(io, ex->ref->ident);
  129. break;
  130. case EX_CALL:
  131. fputc(BC_EX_CALL, io);
  132. sol_ser_expr(io, ex->call->expr);
  133. sol_ser_exl(io, ex->call->args);
  134. sol_ser_str(io, ex->call->method);
  135. break;
  136. case EX_FUNCDECL:
  137. fputc(BC_EX_FUNCDECL, io);
  138. sol_ser_str(io, ex->funcdecl->name);
  139. sol_ser_pl(io, ex->funcdecl->params);
  140. sol_ser_expr(io, ex->funcdecl->anno);
  141. sol_ser_stmt(io, ex->funcdecl->body);
  142. fwrite(&ex->funcdecl->flags, sizeof(unsigned short), 1, io);
  143. break;
  144. case EX_IFELSE:
  145. fputc(BC_EX_IFELSE, io);
  146. sol_ser_expr(io, ex->ifelse->cond);
  147. sol_ser_stmt(io, ex->ifelse->iftrue);
  148. sol_ser_stmt(io, ex->ifelse->iffalse);
  149. break;
  150. case EX_LOOP:
  151. fputc(BC_EX_LOOP, io);
  152. sol_ser_expr(io, ex->loop->cond);
  153. sol_ser_stmt(io, ex->loop->loop);
  154. break;
  155. case EX_ITER:
  156. fputc(BC_EX_ITER, io);
  157. sol_ser_str(io, ex->iter->var);
  158. sol_ser_expr(io, ex->iter->iter);
  159. sol_ser_stmt(io, ex->iter->loop);
  160. break;
  161. default:
  162. printf("WARNING: Unknown expression type to serialize: %d\n", ex->type);
  163. break;
  164. }
  165. }
  166. void sol_ser_exl(FILE *io, exprlist_node *exn) {
  167. fputc(BC_LIST_EX, io);
  168. while(exn) {
  169. sol_ser_expr(io, exn->expr);
  170. exn = exn->next;
  171. }
  172. fputc(BC_ENDLIST, io);
  173. }
  174. void sol_ser_asl(FILE *io, assoclist_node *asl) {
  175. fputc(BC_LIST_AS, io);
  176. while(asl) {
  177. if(asl->item) {
  178. sol_ser_expr(io, asl->item->key);
  179. sol_ser_expr(io, asl->item->value);
  180. }
  181. asl = asl->next;
  182. }
  183. fputc(BC_ENDLIST, io);
  184. }
  185. void sol_ser_idl(FILE *io, identlist_node *idl) {
  186. fputc(BC_LIST_ID, io);
  187. while(idl) {
  188. sol_ser_str(io, idl->ident);
  189. idl = idl->next;
  190. }
  191. fputc(BC_ENDLIST, io);
  192. }
  193. void sol_ser_pl(FILE *io, paramlist_node *pl) {
  194. if(!pl) {
  195. fputc(BC_NULL, io);
  196. return;
  197. }
  198. fputc(BC_LIST_PM, io);
  199. sol_ser_idl(io, pl->args);
  200. sol_ser_exl(io, pl->annos);
  201. sol_ser_idl(io, pl->clkeys);
  202. sol_ser_exl(io, pl->clvalues);
  203. sol_ser_str(io, pl->rest);
  204. fputc(BC_ENDLIST, io);
  205. }
  206. void sol_ser_lit(FILE *io, lit_node *lit) {
  207. if(!lit) {
  208. fputc(BC_NULL, io);
  209. return;
  210. }
  211. switch(lit->type) {
  212. case LIT_INT:
  213. fputc(BC_LIT_INT, io);
  214. sol_ser_int(io, lit->ival);
  215. break;
  216. case LIT_FLOAT:
  217. fputc(BC_LIT_FLOAT, io);
  218. sol_ser_float(io, lit->fval);
  219. break;
  220. case LIT_STRING:
  221. fputc(BC_LIT_STRING, io);
  222. sol_ser_str(io, lit->str);
  223. break;
  224. case LIT_BUFFER:
  225. fputc(BC_LIT_BUFFER, io);
  226. sol_ser_buf(io, lit->buf);
  227. break;
  228. case LIT_NONE:
  229. fputc(BC_LIT_NONE, io);
  230. break;
  231. default:
  232. printf("WARNING: Unknown literal type to serialize: %d\n", lit->type);
  233. break;
  234. }
  235. }
  236. void sol_ser_str(FILE *io, const char *s) {
  237. size_t len;
  238. if(!s) {
  239. fputc(BC_NULL, io);
  240. return;
  241. }
  242. fputc(BC_STRING, io);
  243. len = strlen(s);
  244. fwrite(&len, sizeof(size_t), 1, io);
  245. fwrite(s, sizeof(char), len, io);
  246. }
  247. void sol_ser_buf(FILE *io, unsigned long *buf) {
  248. fputc(BC_BUFFER, io);
  249. fwrite(buf, sizeof(unsigned long), 1, io);
  250. fwrite(BYTES_OF(buf), sizeof(char), LENGTH_OF(buf), io);
  251. }
  252. void sol_ser_int(FILE *io, long i) {
  253. fputc(BC_INT, io);
  254. fwrite(&i, sizeof(long), 1, io);
  255. }
  256. void sol_ser_float(FILE *io, double f) {
  257. fputc(BC_FLOAT, io);
  258. fwrite(&f, sizeof(double), 1, io);
  259. }
  260. void *sol_deser_checked(FILE *io, bytecode b) {
  261. int c = fgetc(io);
  262. if(c != b && c != BC_NULL) {
  263. printf("WARNING: Deserialization failed; expected %d, got %d\n", b, c);
  264. }
  265. ungetc(c, io);
  266. return sol_deser(io);
  267. }
  268. void *sol_deser_stmt(FILE *io) {
  269. int c = fgetc(io);
  270. switch(c) {
  271. default:
  272. printf("WARNING: Deserialization failed; expected stmt type, got %d\n", c);
  273. break;
  274. case BC_NULL:
  275. case BC_ST_EXPR:
  276. case BC_ST_LIST:
  277. case BC_ST_RET:
  278. case BC_ST_CONT:
  279. case BC_ST_BREAK:
  280. ;
  281. }
  282. ungetc(c, io);
  283. return sol_deser(io);
  284. }
  285. void *sol_deser_expr(FILE *io) {
  286. int c = fgetc(io);
  287. switch(c) {
  288. default:
  289. printf("WARNING: Deserialization failed; expected expr type, got %d\n", c);
  290. break;
  291. case BC_NULL:
  292. case BC_EX_LIT:
  293. case BC_EX_LISTGEN:
  294. case BC_EX_MAPGEN:
  295. case BC_EX_BINOP:
  296. case BC_EX_UNOP:
  297. case BC_EX_INDEX:
  298. case BC_EX_SETINDEX:
  299. case BC_EX_ASSIGN:
  300. case BC_EX_REF:
  301. case BC_EX_CALL:
  302. case BC_EX_FUNCDECL:
  303. case BC_EX_IFELSE:
  304. case BC_EX_LOOP:
  305. case BC_EX_ITER:
  306. ;
  307. }
  308. ungetc(c, io);
  309. return sol_deser(io);
  310. }
  311. void *sol_deser_lit(FILE *io) {
  312. int c = fgetc(io);
  313. switch(c) {
  314. default:
  315. printf("WARNING: Deserialization failed; expected lit type, got %d\n", c);
  316. break;
  317. case BC_NULL:
  318. case BC_LIT_INT:
  319. case BC_LIT_FLOAT:
  320. case BC_LIT_STRING:
  321. case BC_LIT_BUFFER:
  322. case BC_LIT_NONE:
  323. ;
  324. }
  325. ungetc(c, io);
  326. return sol_deser(io);
  327. }
  328. void *sol_deser(FILE *io) {
  329. bytecode b = fgetc(io);
  330. void *obj = NULL, *node = NULL;
  331. if(yydebug) {
  332. fprintf(stderr, "Encountered BC %s", sol_BytecodeNames[b]);
  333. }
  334. switch(b) {
  335. case BC_NULL:
  336. return NULL;
  337. break;
  338. case BC_ST_EXPR:
  339. obj = NEW(stmt_node);
  340. AS_ST(obj)->type = ST_EXPR;
  341. AS_ST(obj)->expr = sol_deser_expr(io);
  342. return obj;
  343. break;
  344. case BC_ST_LIST:
  345. obj = NEW(stmt_node);
  346. AS_ST(obj)->type = ST_LIST;
  347. AS_ST(obj)->stmtlist = sol_deser_checked(io, BC_LIST_ST);
  348. return obj;
  349. case BC_ST_RET:
  350. obj = NEW(stmt_node);
  351. AS_ST(obj)->type = ST_RET;
  352. AS_ST(obj)->ret = NEW(ret_node);
  353. AS_ST(obj)->ret->ret = sol_deser_expr(io);
  354. return obj;
  355. case BC_ST_CONT:
  356. obj = NEW(stmt_node);
  357. AS_ST(obj)->type = ST_CONT;
  358. AS_ST(obj)->cont = NEW(cont_node);
  359. AS_ST(obj)->cont->val = sol_deser_expr(io);
  360. return obj;
  361. case BC_ST_BREAK:
  362. obj = NEW(stmt_node);
  363. AS_ST(obj)->type = ST_BREAK;
  364. AS_ST(obj)->brk = NEW(break_node);
  365. AS_ST(obj)->brk->val = sol_deser_expr(io);
  366. return obj;
  367. case BC_EX_LIT:
  368. obj = NEW(expr_node);
  369. AS_EX(obj)->type = EX_LIT;
  370. AS_EX(obj)->lit = sol_deser_lit(io);
  371. return obj;
  372. case BC_EX_LISTGEN:
  373. obj = NEW(expr_node);
  374. AS_EX(obj)->type = EX_LISTGEN;
  375. AS_EX(obj)->listgen = NEW(listgen_node);
  376. AS_EX(obj)->listgen->list = sol_deser_checked(io, BC_LIST_EX);
  377. return obj;
  378. case BC_EX_MAPGEN:
  379. obj = NEW(expr_node);
  380. AS_EX(obj)->type = EX_MAPGEN;
  381. AS_EX(obj)->mapgen = NEW(mapgen_node);
  382. AS_EX(obj)->mapgen->map = sol_deser_checked(io, BC_LIST_AS);
  383. return obj;
  384. case BC_EX_BINOP:
  385. obj = NEW(expr_node);
  386. AS_EX(obj)->type = EX_BINOP;
  387. AS_EX(obj)->binop = NEW(binop_node);
  388. AS_EX(obj)->binop->type = OP_ADD + fgetc(io);
  389. AS_EX(obj)->binop->left = sol_deser_expr(io);
  390. AS_EX(obj)->binop->right = sol_deser_expr(io);
  391. return obj;
  392. case BC_EX_UNOP:
  393. obj = NEW(expr_node);
  394. AS_EX(obj)->type = EX_UNOP;
  395. AS_EX(obj)->unop = NEW(unop_node);
  396. AS_EX(obj)->unop->type = OP_NEG + fgetc(io);
  397. AS_EX(obj)->unop->expr = sol_deser_expr(io);
  398. return obj;
  399. case BC_EX_INDEX:
  400. obj = NEW(expr_node);
  401. AS_EX(obj)->type = EX_INDEX;
  402. AS_EX(obj)->index = NEW(index_node);
  403. AS_EX(obj)->index->expr = sol_deser_expr(io);
  404. AS_EX(obj)->index->index = sol_deser_expr(io);
  405. return obj;
  406. case BC_EX_SETINDEX:
  407. obj = NEW(expr_node);
  408. AS_EX(obj)->type = EX_SETINDEX;
  409. AS_EX(obj)->setindex = NEW(setindex_node);
  410. AS_EX(obj)->setindex->expr = sol_deser_expr(io);
  411. AS_EX(obj)->setindex->index = sol_deser_expr(io);
  412. AS_EX(obj)->setindex->value = sol_deser_expr(io);
  413. return obj;
  414. case BC_EX_ASSIGN:
  415. obj = NEW(expr_node);
  416. AS_EX(obj)->type = EX_ASSIGN;
  417. AS_EX(obj)->assign = NEW(assign_node);
  418. AS_EX(obj)->assign->ident = sol_deser_checked(io, BC_STRING);
  419. AS_EX(obj)->assign->value = sol_deser_expr(io);
  420. return obj;
  421. case BC_EX_REF:
  422. obj = NEW(expr_node);
  423. AS_EX(obj)->type = EX_REF;
  424. AS_EX(obj)->ref = NEW(ref_node);
  425. AS_EX(obj)->ref->ident = sol_deser_checked(io, BC_STRING);
  426. return obj;
  427. case BC_EX_CALL:
  428. obj = NEW(expr_node);
  429. AS_EX(obj)->type = EX_CALL;
  430. AS_EX(obj)->call = NEW(call_node);
  431. AS_EX(obj)->call->expr = sol_deser_expr(io);
  432. AS_EX(obj)->call->args = sol_deser_checked(io, BC_LIST_EX);
  433. AS_EX(obj)->call->method = sol_deser_checked(io, BC_STRING);
  434. return obj;
  435. case BC_EX_FUNCDECL:
  436. obj = NEW(expr_node);
  437. AS_EX(obj)->type = EX_FUNCDECL;
  438. AS_EX(obj)->funcdecl = NEW(funcdecl_node);
  439. AS_EX(obj)->funcdecl->name = sol_deser_checked(io, BC_STRING);
  440. AS_EX(obj)->funcdecl->params = sol_deser_checked(io, BC_LIST_PM);
  441. AS_EX(obj)->funcdecl->anno = sol_deser_expr(io);
  442. AS_EX(obj)->funcdecl->body = sol_deser_stmt(io);
  443. fread(&node, sizeof(unsigned short), 1, io);
  444. AS_EX(obj)->funcdecl->flags = (unsigned short) node;
  445. return obj;
  446. case BC_EX_IFELSE:
  447. obj = NEW(expr_node);
  448. AS_EX(obj)->type = EX_IFELSE;
  449. AS_EX(obj)->ifelse = NEW(ifelse_node);
  450. AS_EX(obj)->ifelse->cond = sol_deser_expr(io);
  451. AS_EX(obj)->ifelse->iftrue = sol_deser_stmt(io);
  452. AS_EX(obj)->ifelse->iffalse = sol_deser_stmt(io);
  453. return obj;
  454. case BC_EX_LOOP:
  455. obj = NEW(expr_node);
  456. AS_EX(obj)->type = EX_LOOP;
  457. AS_EX(obj)->loop = NEW(loop_node);
  458. AS_EX(obj)->loop->cond = sol_deser_expr(io);
  459. AS_EX(obj)->loop->loop = sol_deser_stmt(io);
  460. return obj;
  461. case BC_EX_ITER:
  462. obj = NEW(expr_node);
  463. AS_EX(obj)->type = EX_ITER;
  464. AS_EX(obj)->iter = NEW(iter_node);
  465. AS_EX(obj)->iter->var = sol_deser_checked(io, BC_STRING);
  466. AS_EX(obj)->iter->iter = sol_deser_expr(io);
  467. AS_EX(obj)->iter->loop = sol_deser_stmt(io);
  468. return obj;
  469. case BC_LIT_INT:
  470. obj = NEW(lit_node);
  471. AS(obj, lit_node)->type = LIT_INT;
  472. node = sol_deser_checked(io, BC_INT);
  473. AS(obj, lit_node)->ival = *AS(node, long);
  474. free(node);
  475. return obj;
  476. case BC_LIT_FLOAT:
  477. obj = NEW(lit_node);
  478. AS(obj, lit_node)->type = LIT_FLOAT;
  479. node = sol_deser_checked(io, BC_FLOAT);
  480. AS(obj, lit_node)->fval = *AS(node, double);
  481. free(node);
  482. return obj;
  483. case BC_LIT_STRING:
  484. obj = NEW(lit_node);
  485. AS(obj, lit_node)->type = LIT_STRING;
  486. AS(obj, lit_node)->str = sol_deser_checked(io, BC_STRING);
  487. return obj;
  488. case BC_LIT_BUFFER:
  489. obj = NEW(lit_node);
  490. AS(obj, lit_node)->type = LIT_BUFFER;
  491. AS(obj, lit_node)->buf = sol_deser_checked(io, BC_BUFFER);
  492. return obj;
  493. case BC_LIT_NONE:
  494. obj = NEW(lit_node);
  495. AS(obj, lit_node)->type = LIT_NONE;
  496. return obj;
  497. case BC_INT:
  498. obj = NEW(long);
  499. fread(obj, sizeof(long), 1, io);
  500. return obj;
  501. case BC_FLOAT:
  502. obj = NEW(double);
  503. fread(obj, sizeof(double), 1, io);
  504. return obj;
  505. case BC_STRING:
  506. node = NEW(size_t);
  507. fread(node, sizeof(size_t), 1, io);
  508. obj = malloc(*AS(node, size_t) + 1);
  509. fread(obj, sizeof(char), *AS(node, size_t), io);
  510. AS(obj, char)[*AS(node, size_t)] = 0;
  511. free(node);
  512. return obj;
  513. case BC_BUFFER:
  514. node = NEW(unsigned long);
  515. fread(node, sizeof(unsigned long), 1, io);
  516. obj = malloc(sizeof(unsigned long) + sizeof(char) * (*AS(node, unsigned long)));
  517. LENGTH_OF(obj) = *AS(node, unsigned long);
  518. fread(BYTES_OF(obj), sizeof(char), LENGTH_OF(obj), io);
  519. free(node);
  520. return obj;
  521. case BC_LIST_ST:
  522. while((b = fgetc(io)) != BC_ENDLIST) {
  523. ungetc(b, io);
  524. if(!node) {
  525. node = NEW(stmtlist_node);
  526. obj = node;
  527. } else {
  528. AS(node, stmtlist_node)->next = NEW(stmtlist_node);
  529. node = AS(node, stmtlist_node)->next;
  530. }
  531. AS(node, stmtlist_node)->stmt = sol_deser_stmt(io);
  532. AS(node, stmtlist_node)->next = NULL;
  533. }
  534. return obj;
  535. case BC_LIST_EX:
  536. while((b = fgetc(io)) != BC_ENDLIST) {
  537. ungetc(b, io);
  538. if(!node) {
  539. node = NEW(exprlist_node);
  540. obj = node;
  541. } else {
  542. AS(node, exprlist_node)->next = NEW(exprlist_node);
  543. node = AS(node, exprlist_node)->next;
  544. }
  545. AS(node, exprlist_node)->expr = sol_deser_expr(io);
  546. AS(node, exprlist_node)->next = NULL;
  547. }
  548. return obj;
  549. case BC_LIST_AS:
  550. while((b = fgetc(io)) != BC_ENDLIST) {
  551. ungetc(b, io);
  552. if(!node) {
  553. node = NEW(assoclist_node);
  554. obj = node;
  555. } else {
  556. AS(node, assoclist_node)->next = NEW(assoclist_node);
  557. node = AS(node, assoclist_node)->next;
  558. }
  559. AS(node, assoclist_node)->item = NEW(associtem_node);
  560. AS(node, assoclist_node)->item->key = sol_deser_expr(io);
  561. AS(node, assoclist_node)->item->value = sol_deser_expr(io);
  562. AS(node, assoclist_node)->next = NULL;
  563. }
  564. return obj;
  565. case BC_LIST_ID:
  566. while((b = fgetc(io)) != BC_ENDLIST) {
  567. ungetc(b, io);
  568. if(!node) {
  569. node = NEW(identlist_node);
  570. obj = node;
  571. } else {
  572. AS(node, identlist_node)->next = NEW(identlist_node);
  573. node = AS(node, identlist_node)->next;
  574. }
  575. AS(node, identlist_node)->ident = sol_deser_checked(io, BC_STRING);
  576. AS(node, identlist_node)->next = NULL;
  577. }
  578. return obj;
  579. case BC_LIST_PM:
  580. obj = NEW(paramlist_node);
  581. AS(obj, paramlist_node)->args = sol_deser_checked(io, BC_LIST_ID);
  582. AS(obj, paramlist_node)->annos = sol_deser_checked(io, BC_LIST_EX);
  583. AS(obj, paramlist_node)->clkeys = sol_deser_checked(io, BC_LIST_ID);
  584. AS(obj, paramlist_node)->clvalues = sol_deser_checked(io, BC_LIST_EX);
  585. AS(obj, paramlist_node)->rest = sol_deser_checked(io, BC_STRING);
  586. if(fgetc(io) != BC_ENDLIST) {
  587. printf("WARNING: Missed ENDLIST for paramlist_node\n");
  588. }
  589. return obj;
  590. default:
  591. printf("WARNING: Illegal bytecode %d\n", b);
  592. break;
  593. }
  594. return NULL;
  595. }