• R/O
  • SSH
  • HTTPS

jpl: Commit


Commit MetaInfo

Revision476 (tree)
Time2019-03-09 11:02:40
Authorjakobthomsen

Log Message

work on call with result

Change Summary

Incremental Difference

--- trunk/experimental2/compiler.compiled.c (revision 475)
+++ trunk/experimental2/compiler.compiled.c (revision 476)
@@ -364,7 +364,7 @@
364364 {
365365 uint64_t tmpaddr = 0; // assign temporary addresses highest first (pre-decrement)
366366 mem_init();
367- struct stack callstack = stack_alloc();
367+ uint64_t result = 0; struct stack callstack = stack_alloc();
368368 stack_push(&callstack, 0); // end marker
369369 uint64_t state = tuple2_alloc(1/*main*/, 0/*arg*/);
370370 while(memory[tuple2_access0(state)].value)
@@ -746,6 +746,7 @@
746746 printf("{\n");
747747 printf(" uint64_t tmpaddr = 0; // assign temporary addresses highest first (pre-decrement)\n");
748748 printf(" mem_init();\n");
749+ printf(" uint64_t result = 0;");
749750 printf(" struct stack callstack = stack_alloc();\n");
750751 printf(" stack_push(&callstack, 0); // end marker\n");
751752 printf(" uint64_t state = tuple2_alloc(1/*main*/, 0/*arg*/);\n");
@@ -753,9 +754,9 @@
753754 printf(" {\n");
754755 printf(" switch(memory[tuple2_access0(state)].value)\n");
755756 printf(" {\n");
756- uint64_t closure = stack_pop(&callstack);
757- memory[tuple2_access0(state)].value = memory[tuple2_access0(closure)].value;
758- tuple2_free(closure);
757+ tuple2_free(state);
758+ state = stack_pop(&callstack);
759+ stack_push(&callstack, result);
759760
760761 break;
761762 }
@@ -771,16 +772,17 @@
771772 printf(" }\n");
772773 printf("\n");
773774 printf(" tuple2_free(state);\n");
775+ printf(" result = stack_pop(&callstack);\n");
774776 printf(" stack_free(&callstack);\n");
775777 printf(" mem_show();\n");
776778 printf(" mem_check();\n");
777779 printf("\n");
778- printf(" return 0;\n");
780+ printf(" return (int)result;\n");
779781 printf("}\n");
780782 printf("\n");
781- uint64_t closure = stack_pop(&callstack);
782- memory[tuple2_access0(state)].value = memory[tuple2_access0(closure)].value;
783- tuple2_free(closure);
783+ tuple2_free(state);
784+ state = stack_pop(&callstack);
785+ stack_push(&callstack, result);
784786
785787 break;
786788 }
@@ -788,13 +790,15 @@
788790 {
789791
790792 // intro
791- uint64_t closure = tuple2_alloc(-1LL, 0);
792- stack_push(&callstack, closure);
793- memory[tuple2_access0(state)].value = 2;
793+ memory[tuple2_access0(state)].value = -1LL;
794+ stack_push(&callstack, state);
795+ state = tuple2_alloc(2, 0);
796+ result = 0;
794797 break;
795798 }
796799 case -1LL:
797800 {
801+ result = stack_pop(&callstack);
798802
799803 while(true)
800804 {
@@ -837,25 +841,34 @@
837841 {
838842 if(125 == c)
839843 {
840- printf("uint64_t closure = stack_pop(&callstack);\n");
841- printf(" memory[tuple2_access0(state)].value = memory[tuple2_access0(closure)].value;\n");
842- printf(" tuple2_free(closure);\n");
844+ printf("tuple2_free(state);\n");
845+ printf(" state = stack_pop(&callstack);\n");
846+ printf(" stack_push(&callstack, result);\n");
843847 break;
844848 }
845849 else if(isdigit(c))
846850 {
847851 uint64_t dest = --tmpaddr;
848- printf("uint64_t closure = tuple2_alloc(%lldLL, 0);\n", (long long)dest); // use negative to display numbers concisely
849- printf(" stack_push(&callstack, closure);\n");
850- printf(" memory[tuple2_access0(state)].value = %c", c);
852+ printf("memory[tuple2_access0(state)].value = %lldLL;\n", (long long)dest); // use negative to display numbers concisely
853+ printf(" stack_push(&callstack, state);\n");
854+ printf(" state = tuple2_alloc(%c", c);
851855 while(isdigit(ungetc(getchar(), stdin))) putchar(getchar()); // echo label
852- printf(";\n");
856+ printf(", 0);\n");
857+ printf(" result = 0;\n");
853858 printf(" break;\n");
854859 printf(" }\n");
855860 //printf(" case %lluLLU:\n", (unsigned long long)--tmpaddr);
856861 printf(" case %lldLL:\n", (long long)dest); // use negative to display numbers concisely
857862 printf(" {\n");
863+ printf(" result = stack_pop(&callstack);\n");
858864 }
865+ else if(64 == c)
866+ {
867+ printf(" result = ");
868+ while(isspace(ungetc(getchar(), stdin))) (void)getchar(); // skip WS
869+ while(isdigit(ungetc(getchar(), stdin))) putchar(getchar()); // echo number
870+ printf(";\n");
871+ }
859872 else if(!isspace(c))
860873 {
861874 fprintf(stderr, "unexpected char '%c'\n", c);
@@ -871,16 +884,19 @@
871884 memory[tuple2_access0(state)].value = 0;
872885
873886 // outro
874- uint64_t closure = tuple2_alloc(-2LL, 0);
875- stack_push(&callstack, closure);
876- memory[tuple2_access0(state)].value = 3;
887+ memory[tuple2_access0(state)].value = -2LL;
888+ stack_push(&callstack, state);
889+ state = tuple2_alloc(3, 0);
890+ result = 0;
877891 break;
878892 }
879893 case -2LL:
880894 {
881-uint64_t closure = stack_pop(&callstack);
882- memory[tuple2_access0(state)].value = memory[tuple2_access0(closure)].value;
883- tuple2_free(closure);
895+ result = stack_pop(&callstack);
896+ result = 0;
897+tuple2_free(state);
898+ state = stack_pop(&callstack);
899+ stack_push(&callstack, result);
884900
885901 break;
886902 }
@@ -892,10 +908,11 @@
892908 }
893909
894910 tuple2_free(state);
911+ result = stack_pop(&callstack);
895912 stack_free(&callstack);
896913 mem_show();
897914 mem_check();
898915
899- return 0;
916+ return (int)result;
900917 }
901918
Show on old repository browser