/* Parse a macro */ VyObject ParseMacro(VyParseTree* code){ /* Parse the function arguments */ VyParseTree* args = GetListData(code, 1); int numArguments = 0; char* error = NULL; Argument** arguments = ParseFunctionArguments(args, &numArguments, &error); if(error != NULL){ return ToObject(CreateError(error, code)); } /* Take the rest of the expressions in the lambda as code */ VyParseTree* exprList = MakeListTree(); int i; for(i = 2; i < ListTreeSize(code); i++){ AddToList(exprList, GetListData(code, i)); } /* Take variables from the current function scope and the local scope */ Scope* funcScope = GetCurrentFunctionScope(); Scope* localScope = GetLocalScope(); /* Make sure the local scope isn't the global scope */ if(localScope == GetGlobalScope()) { localScope = NULL; } /* Merge the two scopes to get the current function scope */ Scope* closureScope = MergeScopes(funcScope, localScope); /* Create the function from the data gathered */ VyMacro** mac = CreateMacro(arguments, numArguments, exprList, closureScope); return ToObject(mac); }
/* string macro initialization * this proc is called once per module */ void StringInit( void ) /*********************/ { int i; struct dsym *macro; DebugMsg(( "StringInit() enter\n" )); #ifdef DEBUG_OUT catstrcnt = 0; substrcnt = 0; sizstrcnt = 0; instrcnt = 0; equcnt = 0; #endif /* add @CatStr() macro func */ macro = CreateMacro( "@CatStr" ); macro->sym.isdefined = TRUE; macro->sym.predefined = TRUE; macro->sym.func_ptr = CatStrFunc; macro->sym.isfunc = TRUE; /* v2.08: @CatStr() changed to VARARG */ macro->sym.mac_vararg = TRUE; macro->e.macroinfo->parmcnt = 1; macro->e.macroinfo->parmlist = LclAlloc( sizeof( struct mparm_list ) * 1 ); macro->e.macroinfo->parmlist[0].deflt = NULL; macro->e.macroinfo->parmlist[0].required = FALSE; /* add @InStr() macro func */ macro = CreateMacro( "@InStr" ); macro->sym.isdefined = TRUE; macro->sym.predefined = TRUE; macro->sym.func_ptr = InStrFunc; macro->sym.isfunc = TRUE; macro->e.macroinfo->parmcnt = 3; macro->e.macroinfo->autoexp = 1; /* param 1 (pos) is expanded */ macro->e.macroinfo->parmlist = LclAlloc(sizeof( struct mparm_list) * 3); for (i = 0; i < 3; i++) { macro->e.macroinfo->parmlist[i].deflt = NULL; //macro->e.macroinfo->parmlist[i].label = parmnames[i]; macro->e.macroinfo->parmlist[i].required = (i != 0); } /* add @SizeStr() macro func */ macro = CreateMacro( "@SizeStr" ); macro->sym.isdefined = TRUE; macro->sym.predefined = TRUE; macro->sym.func_ptr = SizeStrFunc; macro->sym.isfunc = TRUE; macro->e.macroinfo->parmcnt = 1; macro->e.macroinfo->parmlist = LclAlloc(sizeof( struct mparm_list)); macro->e.macroinfo->parmlist[0].deflt = NULL; //macro->e.macroinfo->parmlist[0].label = parmnames[0]; /* macro->e.macroinfo->parmlist[0].required = TRUE; */ /* the string parameter is NOT required, '@SizeStr()' is valid */ macro->e.macroinfo->parmlist[0].required = FALSE; /* add @SubStr() macro func */ macro = CreateMacro( "@SubStr" ); macro->sym.isdefined = TRUE; macro->sym.predefined = TRUE; macro->sym.func_ptr = SubStrFunc; macro->sym.isfunc = TRUE; macro->e.macroinfo->parmcnt = 3; macro->e.macroinfo->autoexp = 2 + 4; /* param 2 (pos) and 3 (size) are expanded */ macro->e.macroinfo->parmlist = LclAlloc(sizeof( struct mparm_list) * 3); for (i = 0; i < 3; i++) { macro->e.macroinfo->parmlist[i].deflt = NULL; //macro->e.macroinfo->parmlist[i].label = parmnames[i]; macro->e.macroinfo->parmlist[i].required = (i < 2); } return; }
void GetStructEntries( FILE *infile, Structs *structure, ListNode *vec_secs, ListNode *primitives, ListNode *macros ) { int hasvec = 0; int hassecondary = 0; char sort[STRUCTITEMSIZE + VECTOR_STR_SIZE + SECONDARY_STR_SIZE], var_name[VAR_NAME_SIZE]; Macros *macitem; Primitives *prim; if( skiplayout(infile) != START_STRUCT_ENTRY ) { fprintf( stderr, "GetStructEntries: Expecting %c\n", START_STRUCT_ENTRY ); exit( EXIT_FAILURE ); } fscanf( infile, "%s", buffer); while( *buffer != END_STRUCT_ENTRY) { hasvec = 0; hassecondary = 0; if( strcmp( buffer, VECTOR) == 0) /* have a vector declaration */ { hasvec = 1; fscanf( infile, "%s", buffer); } prim = FindPrimitive( buffer, primitives ); if( prim != NULL ) { strcpy( buffer, INT_STR ); } fscanf( infile, "%s", var_name); if( strcmp( var_name, SECONDARY) == 0) /* have a secondary */ { hassecondary = 1; fscanf( infile, "%s", var_name); } if( hassecondary ) { strcpy( sort, SECONDARY_STR); if( hasvec ) strcat( sort, VECTOR_STR ); strcat( sort, buffer); } else if( hasvec ) { strcpy( sort, VECTOR_STR); strcat( sort, buffer); } else { strcpy( sort, buffer); } if( hasvec || hassecondary ) { AddVec_Sec( vec_secs, sort, buffer, hasvec, hassecondary); } AddChildrenSort( structure, sort); AddChildrenName( structure, var_name); macitem = CreateMacro( StructName( structure), var_name, ListSize( StructChildren_sorts(structure))); AddToMacroList( macitem, macros ); fscanf( infile, "%s", buffer); } }