X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=macro.c;h=0807e74b033f38080fd0ceb2ad4b21bcf3c00f4a;hp=e136c5a10145f86b1da550203aca567031372bde;hb=91beff6462d791d651b66ed0e1a4e1a82157fb6d;hpb=daf2f61a3664329ae7f9609e1e14da2b8780fd10 diff --git a/macro.c b/macro.c index e136c5a..0807e74 100644 --- a/macro.c +++ b/macro.c @@ -3,7 +3,7 @@ // MACRO.C - Macro Definition and Invocation // Copyright (C) 199x Landon Dyer, 2011 Reboot and Friends // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986 -// Source Utilised with the Kind Permission of Landon Dyer +// Source utilised with the kind permission of Landon Dyer // #include "macro.h" @@ -17,8 +17,6 @@ #include "token.h" -static void SetupDefaultMacros(void); - LONG curuniq; // Current macro's unique number //TOKEN ** argp; // Free spot in argptrs[] int macnum; // Unique number for macro definition @@ -36,27 +34,26 @@ static int rptlevel; // .rept nesting level // -// Initialize Macro Processor +// Initialize macro processor // void InitMacro(void) { macuniq = 0; macnum = 1; -// argp = NULL; argp = 0; - SetupDefaultMacros(); } // -// Exit from a Macro; +// Exit from a macro; // -- pop any intervening include files and repeat blocks; // -- restore argument stack; // -- pop the macro. // int ExitMacro(void) { -#warning !!! Bad macro exiting !!! +WARNING(!!! Bad macro exiting !!!) + /* This is a problem. Currently, the argument logic just keeps the current arguments and doesn't save anything if a new macro is called in the middle @@ -83,14 +80,12 @@ of another (nested macros). Need to fix that somehow. argp -= imacro->im_nargs; DEBUG printf("%d (nargs = %d)\n", argp, imacro->im_nargs); - fpop(); - mjump_align = 0; - return 0; + return fpop(); } // -// Add a Formal Argument to a Macro Definition +// Add a formal argument to a macro definition // int defmac2(char * argname) { @@ -114,8 +109,8 @@ int defmac2(char * argname) // int defmac1(char * ln, int notEndFlag) { - PTR p; - LONG len; +// PTR p; +// LONG len; if (list_flag) { @@ -252,7 +247,7 @@ int defr1(char * ln, int kwno) rptlevel++; default: //MORE stupidity here... -#warning "!!! Casting (char *) as LONG !!!" +WARNING(!!! Casting (char *) as LONG !!!) addln: // Allocate length of line + 1('\0') + LONG len = strlen(ln) + 1 + sizeof(LONG); @@ -337,7 +332,7 @@ int lncatch(int (* lnfunc)(), char * dirlist) for(;;) { - if (tokln() == TKEOF) + if (TokenizeLine() == TKEOF) { errors("encountered end-of-file looking for '%s'", dirlist); fatal("cannot continue"); @@ -354,19 +349,11 @@ int lncatch(int (* lnfunc)(), char * dirlist) if ((tok[2] == ':' || tok[2] == DCOLON)) { if (tok[3] == SYMBOL) // label: symbol -#if 0 - p = (char *)tok[4]; -#else p = string[tok[4]]; -#endif } else { -#if 0 - p = (char *)tok[1]; // symbol -#else p = string[tok[1]]; // Symbol -#endif } } @@ -451,12 +438,6 @@ int InvokeMacro(SYM * mac, WORD siz) // argp = 0; DEBUG printf("InvokeMacro: argp: %d -> ", argp); - if ((!strcmp(mac->sname, "mjump") || !strcmp(mac->sname, "mpad")) && !in_main) - { - error("macro cannot be used outside of .gpumain"); - return ERROR; - } - INOBJ * inobj = a_inobj(SRC_IMACRO); // Alloc and init IMACRO IMACRO * imacro = inobj->inobj.imacro; imacro->im_siz = siz; @@ -466,7 +447,7 @@ int InvokeMacro(SYM * mac, WORD siz) TOKEN * dest; int stringNum = 0; int argumentNum = 0; - int i; +// int i; for(dry_run=1; ; dry_run--) { @@ -570,12 +551,13 @@ int InvokeMacro(SYM * mac, WORD siz) Shamus: This construct is meant to deal with nested macros, so the simple minded way we deal with them now won't work. :-/ Have to think about how to fix. -What we could do is simply move the argp with each call, and move it back by the -number of arguments in the macro that's ending. That would solve the problem nicely. +What we could do is simply move the argp with each call, and move it back by +the number of arguments in the macro that's ending. That would solve the +problem nicely. [Which we do now. But that uncovered another problem: the token strings are all -stale by the time a nested macro gets to the end. But they're supposed to be symbols, -which means if we put symbol references into the argument token streams, we can -alleviate this problem.] +stale by the time a nested macro gets to the end. But they're supposed to be +symbols, which means if we put symbol references into the argument token +streams, we can alleviate this problem.] */ #if 0 argptr = (TOKEN **)malloc((nargs + 1) * sizeof(LONG)); @@ -623,47 +605,3 @@ alleviate this problem.] return OK; } - -// -// Setup inbuilt macros (SubQMod) -// -static void SetupDefaultMacros(void) -{ - curmac = NewSymbol("mjump", MACRO, 0); - curmac->svalue = 0; - curmac->sattr = (WORD)(macnum++); - argno = 0; - defmac2("cc"); - defmac2("addr"); - defmac2("jreg"); -// curmln = NULL; - curmac->lineList = NULL; - defmac1(" nop", -1); - defmac1(" movei #\\addr,\\jreg", -1); - defmac1(" jump \\cc,(\\jreg)", -1); - defmac1(" nop", -1); - defmac1(" nop", -1); - - curmac = NewSymbol("mjr", MACRO, 0); - curmac->svalue = 0; - curmac->sattr = (WORD)(macnum++); - argno = 0; - defmac2("cc"); - defmac2("addr"); -// curmln = NULL; - curmac->lineList = NULL; - defmac1(" jr \\cc,\\addr", -1); - defmac1(" nop", -1); - defmac1(" nop", -1); - - curmac = NewSymbol("mpad", MACRO, 0); - curmac->svalue = 0; - curmac->sattr = (WORD)(macnum++); - argno = 0; - defmac2("size"); -// curmln = NULL; - curmac->lineList = NULL; - defmac1(" .rept (\\size/2)", -1); - defmac1(" nop", -1); - defmac1(" .endr", -1); -}