• R/O
  • SSH
  • HTTPS

jpl: Commit


Commit MetaInfo

Revision474 (tree)
Time2019-03-09 10:00:55
Authorjakobthomsen

Log Message

wrap state in closure

Change Summary

Incremental Difference

--- trunk/experimental2/compiler.compiled.c (revision 473)
+++ trunk/experimental2/compiler.compiled.c (revision 474)
@@ -366,10 +366,10 @@
366366 mem_init();
367367 struct stack callstack = stack_alloc();
368368 stack_push(&callstack, 0); // end marker
369- uint64_t state = 1; // main function
370- while(state)
369+ uint64_t state = tuple2_alloc(1/*main*/, 0/*arg*/);
370+ while(memory[tuple2_access0(state)].value)
371371 {
372- switch(state)
372+ switch(memory[tuple2_access0(state)].value)
373373 {
374374 case 2:
375375 {
@@ -748,13 +748,13 @@
748748 printf(" mem_init();\n");
749749 printf(" struct stack callstack = stack_alloc();\n");
750750 printf(" stack_push(&callstack, 0); // end marker\n");
751- printf(" uint64_t state = 1; // main function\n");
752- printf(" while(state)\n");
751+ printf(" uint64_t state = tuple2_alloc(1/*main*/, 0/*arg*/);\n");
752+ printf(" while(memory[tuple2_access0(state)].value)\n");
753753 printf(" {\n");
754- printf(" switch(state)\n");
754+ printf(" switch(memory[tuple2_access0(state)].value)\n");
755755 printf(" {\n");
756756 uint64_t closure = stack_pop(&callstack);
757- state = memory[tuple2_access0(closure)].value;
757+ memory[tuple2_access0(state)].value = memory[tuple2_access0(closure)].value;
758758 tuple2_free(closure);
759759
760760 break;
@@ -764,12 +764,13 @@
764764
765765 // outro
766766 printf(" default:\n");
767- printf(" fprintf(stderr, \"no such state %%d\\n\", (int)state);\n");
768- printf(" return (int)state;\n");
769- printf(" // exit((int)state);\n");
767+ printf(" fprintf(stderr, \"no such state %%d\\n\", (int)memory[tuple2_access0(state)].value);\n");
768+ printf(" return (int)memory[tuple2_access0(state)].value;\n");
769+ printf(" // exit((int)memory[tuple2_access0(state)].value);\n");
770770 printf(" }\n");
771771 printf(" }\n");
772772 printf("\n");
773+ printf(" tuple2_free(state);\n");
773774 printf(" stack_free(&callstack);\n");
774775 printf(" mem_show();\n");
775776 printf(" mem_check();\n");
@@ -778,7 +779,7 @@
778779 printf("}\n");
779780 printf("\n");
780781 uint64_t closure = stack_pop(&callstack);
781- state = memory[tuple2_access0(closure)].value;
782+ memory[tuple2_access0(state)].value = memory[tuple2_access0(closure)].value;
782783 tuple2_free(closure);
783784
784785 break;
@@ -789,7 +790,7 @@
789790 // intro
790791 uint64_t closure = tuple2_alloc(-1LL, 0);
791792 stack_push(&callstack, closure);
792- state = 2;
793+ memory[tuple2_access0(state)].value = 2;
793794 break;
794795 }
795796 case -1LL:
@@ -800,7 +801,7 @@
800801 while(isspace(ungetc(getchar(), stdin))) (void)getchar(); // skip WS
801802 if(!isdigit(ungetc(getchar(), stdin)))
802803 {
803- state = 0;
804+ memory[tuple2_access0(state)].value = 0;
804805 break;
805806 }
806807 printf(" case ");
@@ -837,7 +838,7 @@
837838 if(125 == c)
838839 {
839840 printf("uint64_t closure = stack_pop(&callstack);\n");
840- printf(" state = memory[tuple2_access0(closure)].value;\n");
841+ printf(" memory[tuple2_access0(state)].value = memory[tuple2_access0(closure)].value;\n");
841842 printf(" tuple2_free(closure);\n");
842843 break;
843844 }
@@ -846,7 +847,7 @@
846847 uint64_t dest = --tmpaddr;
847848 printf("uint64_t closure = tuple2_alloc(%lldLL, 0);\n", (long long)dest); // use negative to display numbers concisely
848849 printf(" stack_push(&callstack, closure);\n");
849- printf(" state = %c", c);
850+ printf(" memory[tuple2_access0(state)].value = %c", c);
850851 while(isdigit(ungetc(getchar(), stdin))) putchar(getchar()); // echo label
851852 printf(";\n");
852853 printf(" break;\n");
@@ -867,29 +868,30 @@
867868 printf(" }\n");
868869 //break;
869870 }
870- state = 0;
871+ memory[tuple2_access0(state)].value = 0;
871872
872873 // outro
873874 uint64_t closure = tuple2_alloc(-2LL, 0);
874875 stack_push(&callstack, closure);
875- state = 3;
876+ memory[tuple2_access0(state)].value = 3;
876877 break;
877878 }
878879 case -2LL:
879880 {
880881 uint64_t closure = stack_pop(&callstack);
881- state = memory[tuple2_access0(closure)].value;
882+ memory[tuple2_access0(state)].value = memory[tuple2_access0(closure)].value;
882883 tuple2_free(closure);
883884
884885 break;
885886 }
886887 default:
887- fprintf(stderr, "no such state %d\n", (int)state);
888- return (int)state;
889- // exit((int)state);
888+ fprintf(stderr, "no such state %d\n", (int)memory[tuple2_access0(state)].value);
889+ return (int)memory[tuple2_access0(state)].value;
890+ // exit((int)memory[tuple2_access0(state)].value);
890891 }
891892 }
892893
894+ tuple2_free(state);
893895 stack_free(&callstack);
894896 mem_show();
895897 mem_check();
--- trunk/experimental2/compiler.source.c (revision 473)
+++ trunk/experimental2/compiler.source.c (revision 474)
@@ -376,10 +376,10 @@
376376 printf(" mem_init();\n");
377377 printf(" struct stack callstack = stack_alloc();\n");
378378 printf(" stack_push(&callstack, 0); // end marker\n");
379- printf(" uint64_t state = 1; // main function\n");
380- printf(" while(state)\n");
379+ printf(" uint64_t state = tuple2_alloc(1/*main*/, 0/*arg*/);\n");
380+ printf(" while(memory[tuple2_access0(state)].value)\n");
381381 printf(" {\n");
382- printf(" switch(state)\n");
382+ printf(" switch(memory[tuple2_access0(state)].value)\n");
383383 printf(" {\n");
384384 `
385385 }
@@ -388,12 +388,13 @@
388388 `
389389 // outro
390390 printf(" default:\n");
391- printf(" fprintf(stderr, \"no such state %%d\\n\", (int)state);\n");
392- printf(" return (int)state;\n");
393- printf(" // exit((int)state);\n");
391+ printf(" fprintf(stderr, \"no such state %%d\\n\", (int)memory[tuple2_access0(state)].value);\n");
392+ printf(" return (int)memory[tuple2_access0(state)].value;\n");
393+ printf(" // exit((int)memory[tuple2_access0(state)].value);\n");
394394 printf(" }\n");
395395 printf(" }\n");
396396 printf("\n");
397+ printf(" tuple2_free(state);\n");
397398 printf(" stack_free(&callstack);\n");
398399 printf(" mem_show();\n");
399400 printf(" mem_check();\n");
@@ -415,7 +416,7 @@
415416 while(isspace(ungetc(getchar(), stdin))) (void)getchar(); // skip WS
416417 if(!isdigit(ungetc(getchar(), stdin)))
417418 {
418- state = 0;
419+ memory[tuple2_access0(state)].value = 0;
419420 break;
420421 }
421422 printf(" case ");
@@ -452,7 +453,7 @@
452453 if(125 == c)
453454 {
454455 printf("uint64_t closure = stack_pop(&callstack);\n");
455- printf(" state = memory[tuple2_access0(closure)].value;\n");
456+ printf(" memory[tuple2_access0(state)].value = memory[tuple2_access0(closure)].value;\n");
456457 printf(" tuple2_free(closure);\n");
457458 break;
458459 }
@@ -461,7 +462,7 @@
461462 uint64_t dest = --tmpaddr;
462463 printf("uint64_t closure = tuple2_alloc(%lldLL, 0);\n", (long long)dest); // use negative to display numbers concisely
463464 printf(" stack_push(&callstack, closure);\n");
464- printf(" state = %c", c);
465+ printf(" memory[tuple2_access0(state)].value = %c", c);
465466 while(isdigit(ungetc(getchar(), stdin))) putchar(getchar()); // echo label
466467 printf(";\n");
467468 printf(" break;\n");
@@ -482,7 +483,7 @@
482483 printf(" }\n");
483484 //break;
484485 }
485- state = 0;
486+ memory[tuple2_access0(state)].value = 0;
486487
487488 // outro
488489 `
Show on old repository browser