リビジョン | 538 (tree) |
---|---|
日時 | 2019-03-26 07:11:46 |
作者 | jakobthomsen |
implement blocks
@@ -134,7 +134,6 @@ | ||
134 | 134 | memory[*list + 1] = 0; |
135 | 135 | memory[1] = *list; |
136 | 136 | *list = next; |
137 | - | |
138 | 137 | } |
139 | 138 | |
140 | 139 | void list_free(uint64_t *memory, uint64_t *list) |
@@ -152,7 +151,6 @@ | ||
152 | 151 | memory[1] = *list; |
153 | 152 | *list = next; |
154 | 153 | } |
155 | - | |
156 | 154 | } |
157 | 155 | |
158 | 156 | void init(struct state *state, uint64_t *memory); |
@@ -314,7 +312,7 @@ | ||
314 | 312 | } |
315 | 313 | if(!defref) |
316 | 314 | { |
317 | - fprintf(stderr, "no such function! "); | |
315 | + fprintf(stderr, "no such function "); | |
318 | 316 | printid(stderr, 0xA1C929000000000LLU); |
319 | 317 | fprintf(stderr, "\n"); |
320 | 318 | exit(-1); |
@@ -640,8 +638,6 @@ | ||
640 | 638 | |
641 | 639 | printf(" *list = next;\n"); |
642 | 640 | |
643 | - printf("\n"); | |
644 | - | |
645 | 641 | printf("}\n"); |
646 | 642 | |
647 | 643 | printf("\n"); |
@@ -676,8 +672,6 @@ | ||
676 | 672 | |
677 | 673 | printf(" }\n"); |
678 | 674 | |
679 | - printf("\n"); | |
680 | - | |
681 | 675 | printf("}\n"); |
682 | 676 | |
683 | 677 | printf("\n"); |
@@ -733,14 +727,19 @@ | ||
733 | 727 | |
734 | 728 | break; |
735 | 729 | } |
736 | - case 0xADCB6E827AAAAC0LLU: | |
730 | + case 0xADCB6E81F821B80LLU: | |
737 | 731 | { |
738 | 732 | |
739 | - uint64_t *tmpaddr = &memory[memory[state.stackbase + 0]]; | |
740 | - uint64_t *fndefs = &memory[memory[state.stackbase + 1]]; | |
741 | - uint32_t c = 0; | |
742 | - while((c = (uint32_t)getchar()) <= 255) | |
733 | + memory[state.stackbase + 2] = 0x0LLU; | |
734 | + | |
735 | + memory[state.stackbase + 3] = 0x0LLU; | |
736 | + | |
737 | + uint64_t *blocklist = &memory[state.stackbase + 2]; | |
738 | + while((memory[state.stackbase + 3] = (uint64_t)getchar()) <= 255) | |
743 | 739 | { |
740 | + uint32_t c = (uint32_t)memory[state.stackbase + 3]; | |
741 | + uint64_t *tmpaddr = &memory[memory[state.stackbase + 0]]; | |
742 | + uint64_t *fndefs = &memory[memory[state.stackbase + 1]]; | |
744 | 743 | if(isalpha(c)) |
745 | 744 | { |
746 | 745 | ungetc(c, stdin); |
@@ -784,21 +783,54 @@ | ||
784 | 783 | while((c = getchar()) != '\n') |
785 | 784 | ; // skip line |
786 | 785 | } |
787 | - else if('}' == c) | |
786 | + else if('{' == c) | |
788 | 787 | { |
788 | + const uint64_t preaddr = --*tmpaddr; | |
789 | + const uint64_t postaddr = --*tmpaddr; | |
790 | + list_push(memory, blocklist, remain_size); | |
791 | + list_push(memory, blocklist, preaddr); | |
792 | + list_push(memory, blocklist, postaddr); | |
793 | + | |
794 | + printf(" state.addr = 0x%0llXLLU;\n", (unsigned long long)preaddr); | |
789 | 795 | printf("\n"); |
790 | - printf(" state.addr = memory[--state.stackbase];\n"); | |
791 | - printf(" state.stackbase = memory[state.stackbase - 1];\n"); | |
792 | - printf("\n"); | |
793 | 796 | printf(" break;\n"); |
794 | 797 | printf(" }\n"); |
798 | + printf(" case 0x%0llXLLU:\n", (unsigned long long)preaddr); | |
799 | + printf(" {\n"); | |
800 | + } | |
801 | + else if('}' == c) | |
802 | + { | |
803 | + if(*blocklist) | |
804 | + { | |
805 | + uint64_t preaddr = 0; | |
806 | + uint64_t postaddr = 0; | |
807 | + list_pop(memory, blocklist, &postaddr); | |
808 | + list_pop(memory, blocklist, &preaddr); | |
809 | + list_pop(memory, blocklist, &remain_size); | |
795 | 810 | |
796 | - break; | |
811 | + printf(" state.addr = 0x%0llXLLU;\n", (unsigned long long)postaddr); | |
812 | + printf("\n"); | |
813 | + printf(" break;\n"); | |
814 | + printf(" }\n"); | |
815 | + printf(" case 0x%0llXLLU:\n", (unsigned long long)postaddr); | |
816 | + printf(" {\n"); | |
817 | + } | |
818 | + else | |
819 | + { | |
820 | + printf("\n"); | |
821 | + printf(" state.addr = memory[--state.stackbase];\n"); | |
822 | + printf(" state.stackbase = memory[state.stackbase - 1];\n"); | |
823 | + printf("\n"); | |
824 | + printf(" break;\n"); | |
825 | + printf(" }\n"); | |
826 | + | |
827 | + break; | |
828 | + } | |
797 | 829 | } |
798 | 830 | else if(isalpha(c)) |
799 | 831 | { |
800 | 832 | ungetc(c, stdin); |
801 | - const uint64_t id = parseid(); | |
833 | + uint64_t id = parseid(); | |
802 | 834 | |
803 | 835 | /*if(0xB60BB09EF000000LLU == id) // result |
804 | 836 | { |
@@ -1015,7 +1047,7 @@ | ||
1015 | 1047 | skipws(); |
1016 | 1048 | matchid(")"); |
1017 | 1049 | } |
1018 | - else | |
1050 | + else // CALL | |
1019 | 1051 | { |
1020 | 1052 | uint64_t callee_id = 0; |
1021 | 1053 | uint64_t callee_arg_count = 0; |
@@ -1076,12 +1108,11 @@ | ||
1076 | 1108 | uint64_t arg_offset = 0; |
1077 | 1109 | for(uint64_t i = 0; i < callee_arg_count; i++) |
1078 | 1110 | { |
1079 | - uint64_t par_size = 1; // XXX TODO: MAP SIZE XXX | |
1080 | 1111 | skipws(); |
1081 | 1112 | matchid("#"); |
1082 | 1113 | uint64_t argnr = parsenr(); |
1083 | 1114 | printf(" memory[state.stackbase + %llu] = state.stackbase + %llu;\n", (unsigned long long)(stackbase_offset + arg_offset), (unsigned long long)(argnr)); |
1084 | - arg_offset += par_size; | |
1115 | + ++arg_offset; | |
1085 | 1116 | } |
1086 | 1117 | printf(" state.stackbase += %llu;\n", (unsigned long long)stackbase_offset); |
1087 | 1118 |
@@ -1314,7 +1345,7 @@ | ||
1314 | 1345 | memory[state.stackbase + 7] = state.stackbase + 3; |
1315 | 1346 | memory[state.stackbase + 8] = state.stackbase + 4; |
1316 | 1347 | state.stackbase += 7; |
1317 | - state.addr = 0xADCB6E827AAAAC0LLU; | |
1348 | + state.addr = 0xADCB6E81F821B80LLU; | |
1318 | 1349 | |
1319 | 1350 | break; |
1320 | 1351 | } |
@@ -124,7 +124,7 @@ | ||
124 | 124 | } |
125 | 125 | if(!defref) |
126 | 126 | { |
127 | - fprintf(stderr, "no such function! "); | |
127 | + fprintf(stderr, "no such function "); | |
128 | 128 | printid(stderr, 0xA1C929000000000LLU); |
129 | 129 | fprintf(stderr, "\n"); |
130 | 130 | exit(-1); |
@@ -310,7 +310,6 @@ | ||
310 | 310 | print(" memory[*list + 1] = 0;\n") // clear previously stored element (TODO: call destructor in case of nested lists!) |
311 | 311 | print(" memory[1] = *list;\n") // update free-list |
312 | 312 | print(" *list = next;\n") // continue |
313 | - print("\n") | |
314 | 313 | print("}\n") |
315 | 314 | print("\n") |
316 | 315 | print("void list_free(uint64_t *memory, uint64_t *list)\n") // TODO: destructor-argument for nested lists |
@@ -328,7 +327,6 @@ | ||
328 | 327 | print(" memory[1] = *list;\n") // update free-list |
329 | 328 | print(" *list = next;\n") // continue |
330 | 329 | print(" }\n") |
331 | - print("\n") | |
332 | 330 | print("}\n") |
333 | 331 | print("\n") |
334 | 332 | print("void init(struct state *state, uint64_t *memory);\n") |
@@ -371,14 +369,20 @@ | ||
371 | 369 | ` |
372 | 370 | } |
373 | 371 | |
374 | -parseloop(2) | |
372 | +parsedefs(2) 2 | |
375 | 373 | { |
374 | +==2== // scope | |
375 | + let # = 0 | |
376 | +==3== // c | |
377 | + let # = 0 | |
378 | +==4== | |
376 | 379 | ` |
377 | - uint64_t *tmpaddr = &memory[memory[state.stackbase + 0]]; | |
378 | - uint64_t *fndefs = &memory[memory[state.stackbase + 1]]; | |
379 | - uint32_t c = 0; | |
380 | - while((c = (uint32_t)getchar()) <= 255) | |
380 | + uint64_t *blocklist = &memory[state.stackbase + 2]; | |
381 | + while((memory[state.stackbase + 3] = (uint64_t)getchar()) <= 255) | |
381 | 382 | { |
383 | + uint32_t c = (uint32_t)memory[state.stackbase + 3]; | |
384 | + uint64_t *tmpaddr = &memory[memory[state.stackbase + 0]]; | |
385 | + uint64_t *fndefs = &memory[memory[state.stackbase + 1]]; | |
382 | 386 | if(isalpha(c)) |
383 | 387 | { |
384 | 388 | ungetc(c, stdin); |
@@ -422,21 +426,54 @@ | ||
422 | 426 | while((c = getchar()) != '\n') |
423 | 427 | ; // skip line |
424 | 428 | } |
425 | - else if('}' == c) | |
429 | + else if('{' == c) | |
426 | 430 | { |
431 | + const uint64_t preaddr = --*tmpaddr; | |
432 | + const uint64_t postaddr = --*tmpaddr; | |
433 | + list_push(memory, blocklist, remain_size); | |
434 | + list_push(memory, blocklist, preaddr); | |
435 | + list_push(memory, blocklist, postaddr); | |
436 | + | |
437 | + printf(" state.addr = 0x%0llXLLU;\n", (unsigned long long)preaddr); | |
427 | 438 | printf("\n"); |
428 | - printf(" state.addr = memory[--state.stackbase];\n"); | |
429 | - printf(" state.stackbase = memory[state.stackbase - 1];\n"); | |
430 | - printf("\n"); | |
431 | 439 | printf(" break;\n"); |
432 | 440 | printf(" }\n"); |
441 | + printf(" case 0x%0llXLLU:\n", (unsigned long long)preaddr); | |
442 | + printf(" {\n"); | |
443 | + } | |
444 | + else if('}' == c) | |
445 | + { | |
446 | + if(*blocklist) | |
447 | + { | |
448 | + uint64_t preaddr = 0; | |
449 | + uint64_t postaddr = 0; | |
450 | + list_pop(memory, blocklist, &postaddr); | |
451 | + list_pop(memory, blocklist, &preaddr); | |
452 | + list_pop(memory, blocklist, &remain_size); | |
433 | 453 | |
434 | - break; | |
454 | + printf(" state.addr = 0x%0llXLLU;\n", (unsigned long long)postaddr); | |
455 | + printf("\n"); | |
456 | + printf(" break;\n"); | |
457 | + printf(" }\n"); | |
458 | + printf(" case 0x%0llXLLU:\n", (unsigned long long)postaddr); | |
459 | + printf(" {\n"); | |
460 | + } | |
461 | + else | |
462 | + { | |
463 | + printf("\n"); | |
464 | + printf(" state.addr = memory[--state.stackbase];\n"); | |
465 | + printf(" state.stackbase = memory[state.stackbase - 1];\n"); | |
466 | + printf("\n"); | |
467 | + printf(" break;\n"); | |
468 | + printf(" }\n"); | |
469 | + | |
470 | + break; | |
471 | + } | |
435 | 472 | } |
436 | 473 | else if(isalpha(c)) |
437 | 474 | { |
438 | 475 | ungetc(c, stdin); |
439 | - const uint64_t id = parseid(); | |
476 | + uint64_t id = parseid(); | |
440 | 477 | |
441 | 478 | /*if(0xB60BB09EF000000LLU == id) // result |
442 | 479 | { |
@@ -653,7 +690,7 @@ | ||
653 | 690 | skipws(); |
654 | 691 | matchid(")"); |
655 | 692 | } |
656 | - else | |
693 | + else // CALL | |
657 | 694 | { |
658 | 695 | uint64_t callee_id = 0; |
659 | 696 | uint64_t callee_arg_count = 0; |
@@ -714,12 +751,11 @@ | ||
714 | 751 | uint64_t arg_offset = 0; |
715 | 752 | for(uint64_t i = 0; i < callee_arg_count; i++) |
716 | 753 | { |
717 | - uint64_t par_size = 1; // XXX TODO: MAP SIZE XXX | |
718 | 754 | skipws(); |
719 | 755 | matchid("#"); |
720 | 756 | uint64_t argnr = parsenr(); |
721 | 757 | printf(" memory[state.stackbase + %llu] = state.stackbase + %llu;\n", (unsigned long long)(stackbase_offset + arg_offset), (unsigned long long)(argnr)); |
722 | - arg_offset += par_size; | |
758 | + ++arg_offset; | |
723 | 759 | } |
724 | 760 | printf(" state.stackbase += %llu;\n", (unsigned long long)stackbase_offset); |
725 | 761 |
@@ -814,7 +850,7 @@ | ||
814 | 850 | print(" {\n") |
815 | 851 | print(" switch(state.addr)\n") |
816 | 852 | print(" {\n") |
817 | - parseloop(#3 #4) | |
853 | + parsedefs(#3 #4) | |
818 | 854 | print(" default:\n") |
819 | 855 | print(" {\n") |
820 | 856 | print(" fprintf(stderr, \"no such addr %%llu\\n\", (unsigned long long)state.addr);\n") |