# HG changeset patch # User lost # Date 1231134033 0 # Node ID d5fe306f1ab16b8d71caa7075821a0c876d5e705 # Parent aa9d9fedfdf49033d7ce69419475ac7addde7ff5 Fixed numerous bugs in macro handling diff -r aa9d9fedfdf4 -r d5fe306f1ab1 src/expr.h --- a/src/expr.h Mon Jan 05 05:40:16 2009 +0000 +++ b/src/expr.h Mon Jan 05 05:40:33 2009 +0000 @@ -107,10 +107,10 @@ #define lwasm_expr_is_simple(s) ((s) -> head == (s) -> tail) // is the expression constant? -#define lwasm_expr_is_constant(s) (lwasm_expr_is_simple(s) && (s) -> head -> term -> term_type == LWASM_TERM_INT) +#define lwasm_expr_is_constant(s) (lwasm_expr_is_simple(s) && (!((s) -> head) || (s) -> head -> term -> term_type == LWASM_TERM_INT)) // get the constant value of an expression or 0 if not constant -#define lwasm_expr_get_value(s) (lwasm_expr_is_constant(s) ? (s) -> head -> term -> value : 0) +#define lwasm_expr_get_value(s) (lwasm_expr_is_constant(s) ? ((s) -> head ? (s) -> head -> term -> value : 0) : 0) #undef __expr_E__ diff -r aa9d9fedfdf4 -r d5fe306f1ab1 src/instab.c --- a/src/instab.c Mon Jan 05 05:40:16 2009 +0000 +++ b/src/instab.c Mon Jan 05 05:40:33 2009 +0000 @@ -353,8 +353,8 @@ { "endc", { -1, -1, -1, -1}, pseudo_endc, 1 }, { "else", { -1, -1, -1, -1}, pseudo_else, 1 }, - { "macro", { -1, -1, -1, -1}, pseudo_macro, 1, 0 }, - { "endm", { -1, -1, -1, -1}, pseudo_endm, 1, 1 }, + { "macro", { -1, -1, -1, -1}, pseudo_macro, 1, 0, 1 }, + { "endm", { -1, -1, -1, -1}, pseudo_endm, 1, 1, 1 }, { "setdp", { -1, -1, -1, -1}, pseudo_setdp }, { "set", { -1, -1, -1, -1}, pseudo_set, 0, 0, 1 }, diff -r aa9d9fedfdf4 -r d5fe306f1ab1 src/lwasm.h --- a/src/lwasm.h Mon Jan 05 05:40:16 2009 +0000 +++ b/src/lwasm.h Mon Jan 05 05:40:33 2009 +0000 @@ -68,6 +68,7 @@ int nocodelen; // for "RMB" type instructions int addrset; // set if this instruction sets the assembly address int symaddr; // set if this instruction sets a symbol addr with EQU or the like + int badop; // bad operation - ignore it }; // for keeping track of symbols diff -r aa9d9fedfdf4 -r d5fe306f1ab1 src/macro.c --- a/src/macro.c Mon Jan 05 05:40:16 2009 +0000 +++ b/src/macro.c Mon Jan 05 05:40:33 2009 +0000 @@ -146,7 +146,7 @@ macrotab_t *m; char **args = NULL; // macro arguments - int nargs; // number of arguments + int nargs = 0; // number of arguments char *p2, *p3; @@ -183,6 +183,7 @@ if (p2[1]) p2++; } + p2++; } // have arg here @@ -238,6 +239,7 @@ nl -> nocodelen = 0; nl -> addrset = 0; nl -> symaddr = -1; + nl -> badop = 0; if (as -> linestail) as -> linestail -> next = nl; as -> linestail = nl; @@ -256,13 +258,13 @@ n = *p2 - '0'; if (n == 0) { - for (p3 = m -> name; p3; p3++) + for (p3 = m -> name; *p3; p3++) macro_add_to_buff(&linebuff, &bloc, &blen, *p3); continue; } if (n < 1 || n > nargs) continue; - for (p3 = args[n]; p3; p3++) + for (p3 = args[n - 1]; *p3; p3++) macro_add_to_buff(&linebuff, &bloc, &blen, *p3); continue; } @@ -283,13 +285,13 @@ if (n == 0) { - for (p3 = m -> name; p3; p3++) + for (p3 = m -> name; *p3; p3++) macro_add_to_buff(&linebuff, &bloc, &blen, *p3); continue; } if (n < 1 || n > nargs) continue; - for (p3 = args[n]; p3; p3++) + for (p3 = args[n - 1]; *p3; p3++) macro_add_to_buff(&linebuff, &bloc, &blen, *p3); continue; } @@ -312,11 +314,14 @@ as -> context = oldcontext; // clean up - while (nargs) + if (args) { - lwasm_free(args[--nargs]); + while (nargs) + { + lwasm_free(args[--nargs]); + } + lwasm_free(args); } - lwasm_free(args); // indicate a macro was expanded return 0; diff -r aa9d9fedfdf4 -r d5fe306f1ab1 src/pass1.c --- a/src/pass1.c Mon Jan 05 05:40:16 2009 +0000 +++ b/src/pass1.c Mon Jan 05 05:40:33 2009 +0000 @@ -142,6 +142,7 @@ nl -> nocodelen = 0; nl -> addrset = 0; nl -> symaddr = -1; + nl -> badop = 0; if (as -> linestail) as -> linestail -> next = nl; as -> linestail = nl;