示例#1
0
/* 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);	
}
示例#2
0
 DScope DragonVariable::GetScope(const DString &name)
 {
   auto &scopes = GetScopes();
   auto iter = scopes.find(name);
   return iter == scopes.end()
     ? GetGlobalScope() : iter->second;
 }
示例#3
0
int DoStoreNT(BLIST *scope)
/*
 * Changes all stores of selected arrays to non-temporal (cache-through) form
 */
{
   BLIST *bl;
   int i;
   int nchanges=0;
   short st;
   INSTQ *ip;
   enum inst store;
   extern int NWNT;
   extern char **ARRWNT;
   BLIST *killme;
   /*short k;*/

   if (!scope)
      killme = scope = GetGlobalScope();
   for (i=0; i < NWNT; i++)
   {
      st = FindVarFromName(ARRWNT[i]);
      /*k = st + TNREG - 1;*/
      assert(st);
      for (bl=scope; bl; bl = bl->next)
      {
         for (ip=bl->blk->ainst1; ip; ip = ip->next)
         {
            store = 0;
            if (ip->inst[0] == VFST)
               store = VFSTNT;
            else if (ip->inst[0] == VDST)
               store = VDSTNT;
            if (store && STpts2[ip->inst[1]-1] == st)
            {
               ip->inst[0] = store;
               nchanges++;
            }
         }
      }
   }
   if (killme)
      KillBlockList(killme);
   return(nchanges);
}