Made output even more deterministic

This commit is contained in:
Jeremiah Orians 2018-06-08 15:43:36 -04:00
parent 688b546281
commit 94a986bf44
No known key found for this signature in database
GPG Key ID: 7457821534D2ACCD
5 changed files with 67 additions and 21 deletions

View File

@ -36,6 +36,7 @@ Added Hex2_linker test
Added M1-macro test
Added prototypes to allow functions to be independently built
Added support for debug format output to help debugging
Added function specific counters to make output even more deterministic
** Changed
Improving Documentation to help new programmers get functional
@ -59,6 +60,7 @@ fixed "\"" bug in string output generation
** Removed
Removed need for memset in numerate_number
Removed minimal build target as it no longer serves a purpose
Removed independent counters for for, while and if jumps
* 0.1 - 2018-02-23
** Added

View File

@ -27,6 +27,8 @@ struct token_list* global_constant_list;
struct token_list* break_locals;
struct type* current_target;
char* break_target;
char* current_function;
int current_count;
/* Imported functions */
char* parse_string(char* string);
@ -762,13 +764,14 @@ struct token_list* collect_local(struct token_list* out, struct token_list* func
struct token_list* statement(struct token_list* out, struct token_list* function);
/* Evaluate if statements */
int if_count;
struct token_list* process_if(struct token_list* out, struct token_list* function)
{
char* number_string = numerate_number(if_count);
if_count = if_count + 1;
char* number_string = numerate_number(current_count);
current_count = current_count + 1;
out = emit("# IF_", out);
out = emit(current_function, out);
out = emit("_", out);
out = emit(number_string, out);
out = emit("\n", out);
@ -777,6 +780,8 @@ struct token_list* process_if(struct token_list* out, struct token_list* functio
out = expression(out, function);
out = emit("TEST\nJUMP_EQ %ELSE_", out);
out = emit(current_function, out);
out = emit("_", out);
out = emit(number_string, out);
out = emit("\n", out);
@ -784,8 +789,12 @@ struct token_list* process_if(struct token_list* out, struct token_list* functio
out = statement(out, function);
out = emit("JUMP %_END_IF_", out);
out = emit(current_function, out);
out = emit("_", out);
out = emit(number_string, out);
out = emit("\n:ELSE_", out);
out = emit(current_function, out);
out = emit("_", out);
out = emit(number_string, out);
out = emit("\n", out);
@ -795,23 +804,26 @@ struct token_list* process_if(struct token_list* out, struct token_list* functio
out = statement(out, function);
}
out = emit(":_END_IF_", out);
out = emit(current_function, out);
out = emit("_", out);
out = emit(number_string, out);
out = emit("\n", out);
return out;
}
int for_count;
struct token_list* process_for(struct token_list* out, struct token_list* function)
{
char* number_string = numerate_number(for_count);
for_count = for_count + 1;
char* number_string = numerate_number(current_count);
current_count = current_count + 1;
char* nested_break = break_target;
struct token_list* nested_locals = break_locals;
break_locals = function->locals;
break_target = prepend_string("FOR_END_", number_string);
break_target = prepend_string("FOR_END_", prepend_string(current_function, prepend_string("_", number_string)));
out = emit("# FOR_initialization_", out);
out = emit(current_function, out);
out = emit("_", out);
out = emit(number_string, out);
out = emit("\n", out);
@ -824,6 +836,8 @@ struct token_list* process_for(struct token_list* out, struct token_list* functi
}
out = emit(":FOR_", out);
out = emit(current_function, out);
out = emit("_", out);
out = emit(number_string, out);
out = emit("\n", out);
@ -831,10 +845,16 @@ struct token_list* process_for(struct token_list* out, struct token_list* functi
out = expression(out, function);
out = emit("TEST\nJUMP_EQ %FOR_END_", out);
out = emit(current_function, out);
out = emit("_", out);
out = emit(number_string, out);
out = emit("\nJUMP %FOR_THEN_", out);
out = emit(current_function, out);
out = emit("_", out);
out = emit(number_string, out);
out = emit("\n:FOR_ITER_", out);
out = emit(current_function, out);
out = emit("_", out);
out = emit(number_string, out);
out = emit("\n", out);
@ -842,8 +862,12 @@ struct token_list* process_for(struct token_list* out, struct token_list* functi
out = expression(out, function);
out = emit("JUMP %FOR_", out);
out = emit(current_function, out);
out = emit("_", out);
out = emit(number_string, out);
out = emit("\n:FOR_THEN_", out);
out = emit(current_function, out);
out = emit("_", out);
out = emit(number_string, out);
out = emit("\n", out);
@ -851,8 +875,12 @@ struct token_list* process_for(struct token_list* out, struct token_list* functi
out = statement(out, function);
out = emit("JUMP %FOR_ITER_", out);
out = emit(current_function, out);
out = emit("_", out);
out = emit(number_string, out);
out = emit("\n:FOR_END_", out);
out = emit(current_function, out);
out = emit("_", out);
out = emit(number_string, out);
out = emit("\n", out);
@ -878,18 +906,19 @@ struct token_list* process_asm(struct token_list* out)
}
/* Process do while loops */
int do_count;
struct token_list* process_do(struct token_list* out, struct token_list* function)
{
char* number_string = numerate_number(do_count);
do_count = do_count + 1;
char* number_string = numerate_number(current_count);
current_count = current_count + 1;
char* nested_break = break_target;
struct token_list* nested_locals = break_locals;
break_locals = function->locals;
break_target = prepend_string("DO_END_", number_string);
break_target = prepend_string("DO_END_", prepend_string(current_function, prepend_string("_", number_string)));
out = emit(":DO_", out);
out = emit(current_function, out);
out = emit("_", out);
out = emit(number_string, out);
out = emit("\n", out);
@ -903,8 +932,12 @@ struct token_list* process_do(struct token_list* out, struct token_list* functio
require_match("ERROR in process_do\nMISSING ;\n", ";");
out = emit("TEST\nJUMP_NE %DO_", out);
out = emit(current_function, out);
out = emit("_", out);
out = emit(number_string, out);
out = emit("\n:DO_END_", out);
out = emit(current_function, out);
out = emit("_", out);
out = emit(number_string, out);
out = emit("\n", out);
@ -915,19 +948,20 @@ struct token_list* process_do(struct token_list* out, struct token_list* functio
/* Process while loops */
int while_count;
struct token_list* process_while(struct token_list* out, struct token_list* function)
{
char* number_string = numerate_number(while_count);
while_count = while_count + 1;
char* number_string = numerate_number(current_count);
current_count = current_count + 1;
char* nested_break = break_target;
struct token_list* nested_locals = break_locals;
break_locals = function->locals;
break_target = prepend_string("END_WHILE_", number_string);
break_target = prepend_string("END_WHILE_", prepend_string(current_function, prepend_string("_", number_string)));
out = emit(":WHILE_", out);
out = emit(current_function, out);
out = emit("_", out);
out = emit(number_string, out);
out = emit("\n", out);
@ -936,8 +970,12 @@ struct token_list* process_while(struct token_list* out, struct token_list* func
out = expression(out, function);
out = emit("TEST\nJUMP_EQ %END_WHILE_", out);
out = emit(current_function, out);
out = emit("_", out);
out = emit(number_string, out);
out = emit("\n# THEN_while_", out);
out = emit(current_function, out);
out = emit("_", out);
out = emit(number_string, out);
out = emit("\n", out);
@ -945,8 +983,12 @@ struct token_list* process_while(struct token_list* out, struct token_list* func
out = statement(out, function);
out = emit("JUMP %WHILE_", out);
out = emit(current_function, out);
out = emit("_", out);
out = emit(number_string, out);
out = emit("\n:END_WHILE_", out);
out = emit(current_function, out);
out = emit("_", out);
out = emit(number_string, out);
out = emit("\n", out);
@ -1133,6 +1175,8 @@ void collect_arguments(struct token_list* function)
struct token_list* declare_function(struct token_list* out, struct type* type)
{
char* essential = global_token->prev->s;
current_function = essential;
current_count = 0;
struct token_list* func = sym_declare(global_token->prev->s, calloc(1, sizeof(struct type)), global_function_list);
func->type = type;
collect_arguments(func);

View File

@ -9,7 +9,7 @@ d27eb315d694324650b11a421d6990eee60ac5921a5625bbccb43d806f09e156 test/results/t
8cc38294fb1261843cfc3956fad5a451c95bbc2ed687435d4e2d59df2c4a8567 test/results/test08-binary
cc8f252877a85c0d7832094ff574d7173ac33940917bc1591358b8970651a81c test/results/test09-binary
3857aee4183de41bd00b014d616a5d73f4bfc57aa60a6073bb4113d6ff2fb8d5 test/results/test10-binary
876996566d53244f154bcf1b817be87d288923f3dd888a66b8bf8b098a4692cd test/results/test100-binary
817813ed37dc0e7140c03aa06becdc47014ff880d0cb4b1775d21198cf70bd80 test/results/test100-binary
dce2f0b35323cf6a2b01f74a9335100f2d8626028af545832dbdb503573db0e5 test/results/test11-binary
88602970fa07b5da7a42b4f2b2486fe03accc6796e05453c4ab934e986790bef test/results/test12-binary
c85a57b5b1d65288efd47a3b12c6fca1efade9e7ec91e65efda5531d2c40d293 test/results/test13-binary
@ -20,7 +20,7 @@ ca2c1321cbcbf3f551860fc0857d0a816660ba541987f9ed7f92f8553cd6b06b test/results/t
6405e331d3626c0ed1eca16eecc7fb628d8e1dc54dff3a6106e5f5bb063c896c test/results/test18-binary
33f7802c581d3b6382a1b63211564529419769a9788b5a5cac856e45b9eac57c test/results/test19-binary
6fa44153ee3f27f0df49b282c0bb3017dbfaea906073c8c02b8bf5ad4d4a7860 test/results/test20-binary
782561480823004892208672da16834bd76d622affb493d6a1f34f830890948e test/results/test21-binary
a84ac16eef799668eb1fd5c69cbc7cf0c1f053a6d87db43a16f41172ddd375cb test/results/test22-binary
1a25d3e0aae5f026e41e47b6f7f7b92b2883c37d55b6c24ba89f4bf8897453ae test/results/test23-binary
ee3cff3ae8eb6a83c0985b84b86b8cd4abad76fe114108d78f9d983a74ed8f6b test/results/test21-binary
165b210c76138b6e6e8d7d0b011c2ab6f18f9313ba83daf0edccdb9c0c441af1 test/results/test22-binary
ef5ffd13dccf9ae519e9b7f884be40de6b49a18e4de2281f222291d604f9c519 test/results/test23-binary
ba3d9623c6512bc327cf934d994e5327e5fad3f7500896e2d8458467fae9b9e9 test/results/test99-binary

View File

@ -1 +1 @@
a9ec50a9ccc9cd53afb5db93e8be0014d021d2f12b593fbc4dc3f7f674cae8d9 test/test100/proof
a406760f8cacb2ada90b58377dd7064da194886eb0543a3262705786b78ac6b1 test/test100/proof

View File

@ -1 +1 @@
a84ac16eef799668eb1fd5c69cbc7cf0c1f053a6d87db43a16f41172ddd375cb test/test22/proof
165b210c76138b6e6e8d7d0b011c2ab6f18f9313ba83daf0edccdb9c0c441af1 test/test22/proof