Exemplo n.º 1
0
// Goto slot invoked by the designer context menu. Either navigates
// to an existing slot function or create a new one.
bool navigateToSlot(const QString &uiFileName,
                    const QString & /* objectName */,
                    const QString & /* signalSignature */,
                    const QStringList & /* parameterNames */,
                    QString *errorMessage)
{

    // Find the generated header.
    const QString generatedHeaderFile = generatedHeaderOf(uiFileName);
    if (generatedHeaderFile.isEmpty()) {
        *errorMessage = QCoreApplication::translate("Designer", "The generated header of the form '%1' could not be found.\nRebuilding the project might help.").arg(uiFileName);
        return false;
    }
    const CPlusPlus::Snapshot snapshot = CPlusPlus::CppModelManagerInterface::instance()->snapshot();
    const DocumentPtr generatedHeaderDoc = snapshot.document(generatedHeaderFile);
    if (!generatedHeaderDoc) {
        *errorMessage = QCoreApplication::translate("Designer", "The generated header '%1' could not be found in the code model.\nRebuilding the project might help.").arg(generatedHeaderFile);
        return false;
    }

    // Look for setupUi
    SearchFunction searchFunc(setupUiC);
    const SearchFunction::FunctionList funcs = searchFunc(generatedHeaderDoc);
    if (funcs.size() != 1) {
        *errorMessage = QString::fromLatin1("Internal error: The function '%1' could not be found in in %2").arg(QLatin1String(setupUiC), generatedHeaderFile);
        return false;
    }
    return true;
}
Exemplo n.º 2
0
void doFunDec(Type type, TreeNode *p) {
	//printf("doFunDec\n");
	//printf("TreeNode->state:%s\n", p->state);
	TreeNode *p1 = p->firstChild;
	char * funcname = (char *)malloc(sizeof(char*)*(strlen((p1->value).idValue)+1));
	strcpy(funcname, p1->value.idValue);	//得到函数名
	if (searchFunc(funcname) != NULL) {
		printf("Error type 4 at line %d '&&': function redefined\n", p->line);	//函数重复定义
		return;	
	}
	funcTableElement *elem = (funcTableElement *)malloc(sizeof(funcTableElement));
	elem->name = funcname;
	elem->type = type;
	elem->argListHeader = NULL;
	switch (p->productionRule) {
		case 1: {
			TreeNode *p3 = p1->rightBrother->rightBrother;
			elem->argListHeader = doVarList(p3);
			insertFunc(elem);
			//if (funcTableHeader == NULL) printf("null in doFunDec");
			break;
			}
		case 2: {
			insertFunc(elem);
			break;
			}
	}
}
/// Searches all registered check points for the given substring and returns their counts in the input list
void CCodeCheckpointDebugMgr::SearchCheckpoints(RecordNameCountPairs& outputList, string& searchStr) const
{
	SearchRecordForString searchFunc(outputList, searchStr);

	std::for_each(m_watchedPoints.begin(), m_watchedPoints.end(), searchFunc);
	std::for_each(m_unwatchedPoints.begin(), m_unwatchedPoints.end(), searchFunc);
}
Exemplo n.º 4
0
Tnode *searchFunc(char *NAME,Tnode *root)
{
	if(!strcmp(NAME,"main"))
		return mroot;
	
	switch(root->NODETYPE)
	{
		case CONTINUE		:	tempnode = searchFunc(NAME,root->Ptr1);
								if(tempnode != NULL)
									return tempnode;
								
								else return searchFunc(NAME,root->Ptr2);
		
		case FUNCBLOCK		:	if(!strcmp(NAME,root->NAME))
									return root;
								
								else return NULL;
	}
}
Exemplo n.º 5
0
static obj find_var(obj id){
	for(obj e=env; e; e = cdr(e)){
		obj v = search_assoc(car(e), id);
		if (v) return v;
	}
	obj rr = search_assoc(curr_interp->gl_vars, id);	//global
	if(rr) return rr;
	
	obj (*func)(obj) = searchFunc(id, infnbind);
	if(!func) return nil;
	return tag(func);
}
Exemplo n.º 6
0
inline obj eval_symbol(obj exp){	//assuming a symbol
	obj rr = find_var(exp);
	if(rr) return rr;
	rr = search_assoc(curr_interp->types, exp);	//type id
	if(rr) return rr;
	if(strcmp(ustr(exp), "glist")==0) return retain(curr_interp->gl_vars);
	obj (*func)(obj) = searchFunc(exp, specials);
	if(func) return tag(tSpecial, func);
	print(exp);
	myPrintf(" ");
	error(":undefined identifer");
	return nil;
}
Exemplo n.º 7
0
static obj func_def(obj name, obj params, obj expr) {
	assert(type(name)==tSymbol);
	obj* func = lfind_var(name);
	if(! *func) {
		obj (*fn)(obj) = searchFunc(name, infnbind);
		if(fn) let(func, tag(fn));
	}
	list lam = list3(retain(params), retain(expr), retain(env));
    if(*func){
        if(type(*func)==tClosure){			// free if complete overload, in the future
            lam = merge(lam, retain(ul(*func)));
        } else if(type(*func)==tInternalFn){
            lam = merge(lam, list3(retain(*func), nil, nil));
        }
    }
	return retain(*let(func, render(tClosure, lam)));
}
Exemplo n.º 8
0
int evalBody(Tnode *root,struct Lsymbol **Lhead)
{
	int t;
	struct Gsymbol *gnode;
	struct Lsymbol *lnode;
	
	if(root == NULL)
		return;
	
	switch(root->NODETYPE)
	{
		case CONTINUE		:	evalBody(root->Ptr1,Lhead);
								return evalBody(root->Ptr2,Lhead);
		
		case FUNCCALL		:	gnode = Glookup(root->NAME);
								Arghead = gnode->ARGLIST;
								
								struct Lsymbol *Ltable;
								Ltable = NULL;
								
								if(Arghead != NULL)
									funcParamInstall(root->Ptr1,Lhead,&Ltable);
								
								tempnode = searchFunc(root->NAME,funcroot);
								return interpreter(tempnode,&Ltable);
		
		case IDADDR			:	lnode = Llookup(root->NAME,Lhead);
								gnode = Glookup(root->NAME);
								
								if(lnode != NULL)
									binding = lnode->BINDING;
								else binding = gnode->BINDING;
								
								return *binding;
		
		case RET			:	return evalBody(root->Ptr1,Lhead);
		
		case ITERATIVE		:	while(evalBody(root->Ptr1,Lhead))
									evalBody(root->Ptr2,Lhead);
								return;
		
		case CONDITIONAL	:	if(evalBody(root->Ptr1,Lhead))
									evalBody(root->Ptr2,Lhead);
								else
									evalBody(root->Ptr3,Lhead);
								return;
		
		case ASSIGN			:	lnode = Llookup(root->NAME,Lhead);
								gnode = Glookup(root->NAME);
								
								if(lnode != NULL)
									*lnode->BINDING = evalBody(root->Ptr1,Lhead);
								else *gnode->BINDING = evalBody(root->Ptr1,Lhead);
								
								return;
		
		case ARRAYASSIGN	:	gnode = Glookup(root->NAME);
								gnode->BINDING[evalBody(root->Ptr1,Lhead)] = evalBody(root->Ptr2,Lhead);
								return;
		
		case RD				:	scanf("%d",&var);
								lnode = Llookup(root->NAME,Lhead);
								gnode = Glookup(root->NAME);
								
								if(lnode != NULL)
									*lnode->BINDING = var;
								else *gnode->BINDING = var;
								return;
		
		case ARRAYRD		:	scanf("%d",&var);
								gnode = Glookup(root->NAME);
								gnode->BINDING[evalBody(root->Ptr1,Lhead)] = var;
								return;
		
		case WRIT			:	printf("%d\n",evalBody(root->Ptr1,Lhead));
								return;
		
		case ADD			:	return evalBody(root->Ptr1,Lhead) + evalBody(root->Ptr2,Lhead);
		
		case SUB			:	return evalBody(root->Ptr1,Lhead) - evalBody(root->Ptr2,Lhead);
		
		case MUL			:	return evalBody(root->Ptr1,Lhead) * evalBody(root->Ptr2,Lhead);
		
		case DIV			:	return evalBody(root->Ptr1,Lhead) / evalBody(root->Ptr2,Lhead);
		
		case MOD			:	return evalBody(root->Ptr1,Lhead) % evalBody(root->Ptr2,Lhead);
		
		case GT				:	return evalBody(root->Ptr1,Lhead) > evalBody(root->Ptr2,Lhead);
		
		case LT				:	return evalBody(root->Ptr1,Lhead) < evalBody(root->Ptr2,Lhead);
		
		case GTE			:	return evalBody(root->Ptr1,Lhead) >= evalBody(root->Ptr2,Lhead);
		
		case LTE			:	return evalBody(root->Ptr1,Lhead) <= evalBody(root->Ptr2,Lhead);
		
		case EQ				:	return evalBody(root->Ptr1,Lhead) == evalBody(root->Ptr2,Lhead);
		
		case NE				:	return evalBody(root->Ptr1,Lhead) != evalBody(root->Ptr2,Lhead);
		
		case And			:	return evalBody(root->Ptr1,Lhead) && evalBody(root->Ptr2,Lhead);
		
		case Or				:	return evalBody(root->Ptr1,Lhead) || evalBody(root->Ptr2,Lhead);
		
		case Not			:	return !evalBody(root->Ptr1,Lhead);
		
		case True			:	return 1;
		
		case False			:	return 0;
		
		case IDFR			:	lnode = Llookup(root->NAME,Lhead);
								gnode = Glookup(root->NAME);
								
								if(lnode != NULL)
									return *lnode->BINDING;
								else return *gnode->BINDING;
		
		case ARRAYIDFR		:	gnode = Glookup(root->NAME);
								return gnode->BINDING[evalBody(root->Ptr1,Lhead)];
		
		case NUM			:	return root->VALUE;
		
		default				:	printf("How did flag get this value!");
	}
}
Exemplo n.º 9
0
Type doExp(TreeNode *p) {
//	printf("doExp\n");
//	printf("TreeNode->state:%s\n", p->state);
//	printf("TreeNode->productionRule: %d\n", p->productionRule);
	if(strcmp(p->state, "Exp") == 0) {
		TreeNode *tempNode = p->firstChild;//产生式右边第一个符号
		switch (p->productionRule) {
			case 1:{TreeNode *temp2Node = tempNode->rightBrother->rightBrother;
				   //Type type = (Type)malloc(sizeof(struct Type_));
				   Type t1 = doExp(tempNode);
				   Type t2 = doExp(temp2Node);	
				   if (tempNode->productionRule > 16 || tempNode->productionRule < 14) {	//不符合唯一的三个能当右值的产生式
					   printf("Error type 6 at line %d: left expression illegal for assign\n", p->line);
				   }
				   if(t1 != NULL && t2 != NULL) {
					   if(type_equal(t1, t2)) {
//						   printf("Exp ASSIGNOP Exp\n");
//						   printf("tempNode->firstChild->addr_sp: %d\n", tempNode->firstChild->addr_sp);
						   fprintf(out_fp, "\tlw $t0, %d($sp)\n", temp2Node->firstChild->addr_sp - ADDR);
						   fprintf(out_fp, "\tsw $t0, %d($sp)\n", tempNode->firstChild->addr_sp - ADDR);
						   return t1;//类型匹配
					   }
					   else if(!type_equal(t1, t2)) {
						   printf("Error type 7 at line %d '=' type mismatch\n", p->line);//类型不匹配
						   OUT = false;//表示语义分析错误,删除已生成的目标文件
					   }
				   }
				break;
				   //exp = exp
				   }
			case 2:{TreeNode *temp2Node = tempNode->rightBrother->rightBrother;
				   Type type = (Type)malloc(sizeof(struct Type_));
				   Type t1 = doExp(tempNode);
				   Type t2 = doExp(temp2Node);
				   if(t1 != NULL && t2 != NULL) {
					   if(type_equal(t1, t2)) {
						   type = t1;
						   ADDR -= 4;
						   p->firstChild->addr_sp = ADDR;//将表达式结果存在该地址处
						   fprintf(out_fp, "\taddi $sp, $sp, -4\n");
						   fprintf(out_fp, "\tlw $t0, %d($sp)\n", tempNode->firstChild->addr_sp);
						   fprintf(out_fp, "\tlw $t1, %d($sp)\n", temp2Node->firstChild->addr_sp);
						   fprintf(out_fp, "\tand $t0, $t0, $t1\n");
						   fprintf(out_fp, "\tsw $t0, 0($sp)\n"); 
						   return type;//类型匹配
					   }
					   else if(!type_equal(t1, t2)) {
						   printf("Error type 7 at line %d '&&' type mismatch\n", p->line);//类型不匹配
						   OUT = false;
					   }
				   }
				break;
				//Exp AND Exp
				   }
			case 3:{TreeNode *temp2Node = tempNode->rightBrother->rightBrother;
				   Type type = (Type)malloc(sizeof(struct Type_));
				   Type t1 = doExp(tempNode);
				   Type t2 = doExp(temp2Node);
				   if(t1 != NULL && t2 != NULL) {
					   if(type_equal(t1, t2)) {
						   type = t1;
						   ADDR -= 4;
						   p->firstChild->addr_sp = ADDR;//将表达式结果存在该地址处
						   fprintf(out_fp, "\taddi $sp, $sp, -4\n");
						   fprintf(out_fp, "\tlw $t0, %d($sp)\n", tempNode->firstChild->addr_sp);
						   fprintf(out_fp, "\tlw $t1, %d($sp)\n", temp2Node->firstChild->addr_sp);
						   fprintf(out_fp, "\tor $t0, $t0, $t1\n");
						   fprintf(out_fp, "\tsw $t0, 0($sp)\n"); 
						   return type;//类型匹配
					   }
					   else if(!type_equal(t1, t2)) {
						   printf("Error type 7 at line %d '||' type mismatch\n", p->line);//类型不匹配
						   OUT = false;
					   }
				   }
				break;
				//Exp OR Exp
				   }
			case 4:{TreeNode *temp2Node = tempNode->rightBrother->rightBrother;
				   Type type = (Type)malloc(sizeof(struct Type_));
				   Type t1 = doExp(tempNode);
				   Type t2 = doExp(temp2Node);
				   if(t1 != NULL && t2 != NULL) {
					   if(type_equal(t1, t2)) {
						   type = t1;
						   return type;//类型匹配
					   }
					   else if(!type_equal(t1, t2)) {
						   printf("Error type 7 at line %d 'RELOP' type mismatch\n", p->line);//类型不匹配
					   }
				   }
				break;
				//Exp RELOP Exp
				   }
			case 5:{TreeNode *temp2Node = tempNode->rightBrother->rightBrother;
				   Type type = (Type)malloc(sizeof(struct Type_));
				   Type t1 = doExp(tempNode);
				   Type t2 = doExp(temp2Node);
				   if(t1 != NULL && t2 != NULL) {
					   if(type_equal(t1, t2)) {
						   type = t1;
//						   printf("t1->u.basic: %d\n", t1->u.basic);
						   ADDR -= 4;
						   p->firstChild->addr_sp = ADDR;
						   fprintf(out_fp, "\taddi $sp, $sp, -4\n");
						   fprintf(out_fp, "\tlw $t0, %d($sp)\n", tempNode->firstChild->addr_sp - ADDR);
						   fprintf(out_fp, "\tlw $t1, %d($sp)\n", temp2Node->firstChild->addr_sp - ADDR);
						   fprintf(out_fp, "\tadd $t0, $t0, $t1\n");
						   fprintf(out_fp, "\tsw $t0, 0($sp)\n"); 
						   return type;//类型匹配
					   }
					   else if(!type_equal(t1, t2)) {
						   printf("Error type 7 at line %d '+' type mismatch\n", p->line);//类型不匹配
						   OUT = false;
					   }
				   }
				break;
				//Exp PLUS Exp
				   }
			case 6:{TreeNode *temp2Node = tempNode->rightBrother->rightBrother;
				   Type type = (Type)malloc(sizeof(struct Type_));
				   Type t1 = doExp(tempNode);
				   Type t2 = doExp(temp2Node);
				   if(t1 != NULL && t2 != NULL) {
					   if(type_equal(t1, t2)) {
						   type = t1;

						   ADDR -= 4;
						   p->firstChild->addr_sp = ADDR;
						   fprintf(out_fp, "\taddi $sp, $sp, -4\n");
						   fprintf(out_fp, "\tlw $t0, %d($sp)\n", tempNode->firstChild->addr_sp - ADDR);
						   fprintf(out_fp, "\tlw $t1, %d($sp)\n", temp2Node->firstChild->addr_sp - ADDR);
						   fprintf(out_fp, "\tsub $t0, $t0, $t1\n");
						   fprintf(out_fp, "\tsw $t0, 0($sp)\n"); 
		
						   return type;//类型匹配
					   }
					   else if(!type_equal(t1, t2)) {
						   printf("Error type 7 at line %d '-' type mismatch\n", p->line);//类型不匹配
					   }
				   }
				break;
				//Exp MINUS Exp
				   }
			case 7:{TreeNode *temp2Node = tempNode->rightBrother->rightBrother;
				   Type type = (Type)malloc(sizeof(struct Type_));
				   Type t1 = doExp(tempNode);
				   Type t2 = doExp(temp2Node);
				   if(t1 != NULL && t2 != NULL) {
					   if(type_equal(t1, t2)) {
						   type = t1;

						   ADDR -= 4;
						   p->firstChild->addr_sp = ADDR;
						   fprintf(out_fp, "\taddi $sp, $sp, -4\n");
						   fprintf(out_fp, "\tlw $t0, %d($sp)\n", tempNode->firstChild->addr_sp - ADDR);
						   fprintf(out_fp, "\tlw $t1, %d($sp)\n", temp2Node->firstChild->addr_sp - ADDR);
						   fprintf(out_fp, "\tmul $t0, $t0, $t1\n");
						   fprintf(out_fp, "\tsw $t0, 0($sp)\n"); 
						   return type;//类型匹配
					   }
					   else if(!type_equal(t1, t2)) {
						   printf("Error type 7 at line %d '*' type mismatch\n", p->line);//类型不匹配
					   }
				   }
				break;
				//Exp STAR Exp
				   }
			case 8:{TreeNode *temp2Node = tempNode->rightBrother->rightBrother;
				   Type type = (Type)malloc(sizeof(struct Type_));
				   Type t1 = doExp(tempNode);
				   Type t2 = doExp(temp2Node);
				   if(t1 != NULL && t2 != NULL) {
					   if(type_equal(t1, t2)) {
						   type = t1;
						   ADDR -= 4;
						   p->firstChild->addr_sp = ADDR;
						   fprintf(out_fp, "\taddi $sp, $sp, -4\n");
						   fprintf(out_fp, "\tlw $t0, %d($sp)\n", tempNode->firstChild->addr_sp - ADDR);
						   fprintf(out_fp, "\tlw $t1, %d($sp)\n", temp2Node->firstChild->addr_sp - ADDR);
						   fprintf(out_fp, "\tdiv $t0, $t0, $t1\n");
						   fprintf(out_fp, "\tsw $t0, 0($sp)\n"); 
						   return type;//类型匹配
					   }
					   else if(!type_equal(t1, t2)) {
						   printf("Error type 7 at line %d '/' type mismatch\n", p->line);//类型不匹配
					   }
				   }
				break;
				//Exp DIV Exp
				   }
			case 9:return doExp(tempNode->rightBrother);
				   //LP Exp RP
			case 10:return doExp(tempNode->rightBrother);
					//MINUS Exp
			case 11:return doExp(tempNode->rightBrother);
					//NOT Exp
				
			case 12:{funcTableElement *func = searchFunc(tempNode->value.idValue);
					if(func == NULL) {
						varElement *var = searchAll(tempNode->value.idValue);
						if (var != NULL) {
							printf("Error type 11 at line %d: normal variable %s uses '()'\n", p->line, tempNode->value.idValue);
						} else
							printf("Error type 4 at line %d: undefined function %s\n", p->line, tempNode->value.idValue);
						return NULL;
					}
					TreeNode *argNode = tempNode->rightBrother->rightBrother;
					argElement *args = doArgs(argNode);
					if (compareArgs(func->argListHeader, args) == 0) {	//参数匹配有问题
						printf("Error type 9 at line %d: function var list not matched %s\n", p->line, tempNode->value.idValue);
						return func->type;
					}
					break;
					//ID LP Args RP
				}
			case 13:{funcTableElement *func = searchFunc(tempNode->value.idValue);
					if(func == NULL) {
						varElement *var = searchAll(tempNode->value.idValue);
						if (var != NULL) {
							printf("Error type 11 at line %d: normal variable %s uses '()'\n", p->line, tempNode->value.idValue);
							OUT = false;
						} else {
							printf("Error type 4 at line %d:undefined function %s\n", p->line, tempNode->value.idValue);
							OUT = false;
						}
						return NULL;
					}
					else if (func->argListHeader != NULL) {	//函数定义中有参数而调用没有
						printf("Error type 9 at line %d:function var list not matched %s\n", p->line, tempNode->value.idValue);
						OUT = false;
						return func->type;
					}
					break;
					//ID LP RP
				}
			case 14:{Type type = (Type)malloc(sizeof(struct Type_));
					TreeNode *temp2Node = tempNode->rightBrother->rightBrother;
					Type t1 = doExp(tempNode);
					Type t2 = doExp(temp2Node);
					if(tempNode != NULL && temp2Node != NULL) {
						if(t1->kind != ARRAY) {
							printf("Error type 10 at line %d: normal variable uses '[]'\n", p->line);
							OUT = false;
						}
						else if(t2->u.basic != 0) {
							printf("Error type 12 at line %d:int required\n", p->line);
							OUT = false;
						}
						else {
							type = doExp(tempNode)->u.array.elem;
//							printf("tempNode->firstChild->addr_sp: %d\n", tempNode->firstChild->addr_sp);
							tempNode->addr_sp = tempNode->firstChild->addr_sp - temp2Node->firstChild->value.intValue * 4;
							return type;
						}
					}
					break;
					//Exp LB Exp RB
					}
			case 15:{
					TreeNode *p3 = tempNode->rightBrother->rightBrother;
					Type t = doExp(tempNode);
					if(t != NULL) {
						if(t->kind != STRUCTURE) {
							printf("Error type 13 at line %d: error use of operator '.'\n", p->line);
						}
						else {
							//showStructMember(t);
;							varElement *field = t->u.var;
							while(field != NULL) {
								if(strcmp(field->name, p3->value.idValue) == 0) {
									return field->type;
								}
								field = field->next;
							}
							printf("Error type 14 at line %d:struct member %s undefined\n", p->line, tempNode->rightBrother->rightBrother->value.idValue);
							//结构体成员未定义
						}
					}
					break;
					//Exp DOT ID
					}
			case 16:{Type type = (Type)malloc(sizeof(struct Type_));
					varElement *id = searchAll(tempNode->value.idValue);
					//在符号表中寻找是否定义
					if(id == NULL) {
						printf("Error type 1 at line %d:undefined variable %s\n", p->line, tempNode->value.idValue);
						OUT = false;
					}
					else {
						type = id->type;
						tempNode->addr_sp = id->addr_sp;
						printf("tempNode->addr_sp: %d\n", id->addr_sp);
						return type;
					}
					break;
				//ID
					}
			case 17:{Type type = (Type)malloc(sizeof(struct Type_));
					type->kind = BASIC;
					type->u.basic = 0;
					ADDR -= 4;
					tempNode->addr_sp = ADDR;
					fprintf(out_fp, "\taddi $sp, $sp, -4\n");
					fprintf(out_fp, "\tli $t0, %d\n", tempNode->value.intValue);
					fprintf(out_fp, "\tsw $t0, 0($sp)\n");
					return type;
					//INT
					}
			case 18:{Type type = (Type)malloc(sizeof(struct Type_));
					type->kind = BASIC;
					type->u.basic = 1;
					ADDR -= 4;
					tempNode->addr_sp = ADDR;
					fprintf(out_fp, "\taddi $sp, $sp, -4\n");
					fprintf(out_fp, "\tli $t0, %f\n", tempNode->value.floatValue);
					fprintf(out_fp, "\tsw $t0, 0($sp)\n");
					return type;
					//FLOAT
					}
		}
	}
	return NULL;
}
Exemplo n.º 10
0
// The searchBlockmap function
// arguments: searchBlockmap(searchtype, function, mobj, [x1, x2, y1, y2])
// return value:
//   true = search completely uninteruppted,
//   false = searching of at least one block stopped mid-way (including if the whole search was stopped)
static int lib_searchBlockmap(lua_State *L)
{
	int searchtype = luaL_checkoption(L, 1, "objects", search_opt);
	int n;
	mobj_t *mobj;
	INT32 xl, xh, yl, yh, bx, by;
	fixed_t x1, x2, y1, y2;
	boolean retval = true;
	UINT8 funcret = 0;
	blockmap_func searchFunc;

	lua_remove(L, 1); // remove searchtype, stack is now function, mobj, [x1, x2, y1, y2]
	luaL_checktype(L, 1, LUA_TFUNCTION);

	switch (searchtype)
	{
		case 0: // "objects"
		default:
			searchFunc = lib_searchBlockmap_Objects;
			break;
		case 1: // "lines"
			searchFunc = lib_searchBlockmap_Lines;
			break;
	}

	// the mobj we are searching around, the "calling" mobj we could say
	mobj = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ));
	if (!mobj)
		return LUA_ErrInvalid(L, "mobj_t");

	n = lua_gettop(L);

	if (n > 2) // specific x/y ranges have been supplied
	{
		if (n < 6)
			return luaL_error(L, "arguments 4 to 6 not all given (expected 4 fixed-point integers)");

		x1 = luaL_checkfixed(L, 3);
		x2 = luaL_checkfixed(L, 4);
		y1 = luaL_checkfixed(L, 5);
		y2 = luaL_checkfixed(L, 6);
	}
	else // mobj and function only - search around mobj's radius by default
	{
		fixed_t radius = mobj->radius + MAXRADIUS;
		x1 = mobj->x - radius;
		x2 = mobj->x + radius;
		y1 = mobj->y - radius;
		y2 = mobj->y + radius;
	}
	lua_settop(L, 2); // pop everything except function, mobj

	xl = (unsigned)(x1 - bmaporgx)>>MAPBLOCKSHIFT;
	xh = (unsigned)(x2 - bmaporgx)>>MAPBLOCKSHIFT;
	yl = (unsigned)(y1 - bmaporgy)>>MAPBLOCKSHIFT;
	yh = (unsigned)(y2 - bmaporgy)>>MAPBLOCKSHIFT;

	BMBOUNDFIX(xl, xh, yl, yh);

	blockfuncerror = false; // reset
	validcount++;
	for (bx = xl; bx <= xh; bx++)
		for (by = yl; by <= yh; by++)
		{
			funcret = searchFunc(L, bx, by, mobj);
			// return value of searchFunc determines searchFunc's return value and/or when to stop
			if (funcret == 2){ // stop whole search
				lua_pushboolean(L, false); // return false
				return 1;
			}
			else if (funcret == 1) // search was interrupted for this block
				retval = false; // this changes the return value, but doesn't stop the whole search
			// else don't do anything, continue as normal
			if (P_MobjWasRemoved(mobj)){ // ...unless the original object was removed
				lua_pushboolean(L, false); // in which case we have to stop now regardless
				return 1;
			}
		}
	lua_pushboolean(L, retval);
	return 1;
}
Exemplo n.º 11
0
obj subs0(obj v, obj * vars){
	assert(!! v);
	switch(v->type){
	case tSymbol:
		if(vars){		// macro
			obj vp = search_assoc(*vars, v);
			if(vp) return vp;
		//	vp = searchFunc(v, specials);
		//	if(vp) {release(vp); return retain(v);}
			obj (*func)(obj) = searchFunc(v, specials);
			if(func) return retain(v);
			vp = find_var(v);
			if(vp) {release(vp); return retain(v);}
			assert(0);
		//	return ref2var(add_assoc(*vars, v, Null()));
		} else {		// quasi-quote
			obj vp = find_var(v);
			if(vp) return vp;
			return retain(v);
		}
    case tAssign:{
		obj vp = search_assoc(*vars, car(v));	//macro-locals
		if(vp) goto nex;
	/*	vp = searchFunc(car(v), specials);		// not needed because cant assign to global
		if(vp) {release(vp); vp = retain(v); return vp;}
		vp = find_var(v);
		if(vp) {release(vp); vp = retain(v); return vp;}
	*/	vp = ref2var(nil);
		add_assoc(vars, car(v), vp);
nex:		return operate(tAssign, vp, subs0(cdr(v), vars));
	}
    case tArray:{
		obj r = aArray(uar(v).size);
		for(int i=0; i < uar(v).size; i++) uar(r).v[i] = subs0(uar(v).v[i], vars);
		return r;
	}
    case LIST:		//list
	case POW:
	case MULT:
	case DIVIDE:
	case ARITH:
	case CONDITION:
	case tIf:
	case tExec:
        {
		list l = phi();
		for(list s=ul(v); s; s=rest(s))  l = cons(subs0(first(s), vars), l);
		return render(type(v), reverse(l));
        }
	case tReturn:
		if(!uref(v)) return retain(v);
	case tMinus:
		return encap(v->type, subs0(uref(v), vars));
	case tClosure:
	case tArrow:
		return render(type(v), list3(subs0(em0(v),vars), subs0(em1(v), vars), nil));
	case tDefine:
	case tSyntaxDef:
		assert(0);
	case tInd:
	case tWhile:
		{
		obj st = subs0(cdr(v), vars);
		if(type(st)==LIST) st->type = tExec;
		return operate(v->type, subs0(car(v), vars), st);
		}
	case tOp:
		return operate(v->type, subs0(car(v), vars), subs0(cdr(v), vars));
	case INT:
	case tDouble:
	case TOKEN:
	case tNull:
	case tLAVec:
	case tDblArray:
	case tIntArr:
	case tDblAr2:
	case IMAGE:
	case STRING:
	case tBreak:
		return retain(v);
    default:
        break;
	}
	print(v);
	assert(0);
	return v;
}
Exemplo n.º 12
0
bool postCompile(XOScript* xos)
{
    //обработка указателей на переменные в аргументах

    XOScript* scr=xos;
    for(int i =0;i<scr->Namespaces->count;i++)
    {
        XONamespace* xs=(XONamespace*)_stdLst::get(scr->Namespaces,i);

        for(int j =0;j<xs->Classes->count;j++)
        {
            XOClass* xc=(XOClass*)_stdLst::get(xs->Classes,j);

            for(int k =0;k<=xc->Functions->count;k++)
            {
                bool illum=false;
                XOFunction* xf=0;
                if(k==xc->Functions->count)
                {xf=xc->illuminator;illum=true;}
                else
                    xf=(XOFunction*)_stdLst::get(xc->Functions,k);

                for(int u =0;u<xf->Lines->count;u++)
                {
                    XOLine* xl=(XOLine*)_stdLst::get(xf->Lines,u);
                    for(int h =0;h<xl->Arguments->count;h++)
                    {
                        XOArgument* xv=(XOArgument*)_stdLst::get(xl->Arguments,h);
                        if(xv->needPostCompileGoto)
                            goto GOTODIC;
                        if(!xv->needPostCompile)
                            continue;
                        //-------
                        CPATH[0]=i;CPATH[1]=j;CPATH[2]=illum?-1:k;
                        _stdString* needdel=(_stdString* )xv->ptr;
                        if(searchVar(needdel,scr))return true;
                        _stdStr::DEL(needdel);
                        if(global)
                        {
                            xv->classVar=true;
                            xv->funcVar=false;
                            xv->fly=false;
                            xv->needPostCompile=false;
                            xv->scriptClass=false;
                            xv->stackI=false;
                            xv->stackVar=false;
                            //---------------
                            xv->ptr=_stdMEM::mainAllocate(3*4);
                            memcpy(xv->ptr,&PATH[0],3*4);
                        }
                        else
                        {
                            xv->funcVar=true;
                            xv->classVar=false;
                            xv->fly=false;
                            xv->needPostCompile=false;
                            xv->scriptClass=false;
                            xv->stackI=false;
                            xv->stackVar=false;
                            //---------------
                            xv->ptr=_stdMEM::mainAllocate(1*4);
                            memcpy(xv->ptr,&PATH[0],1*4);
                        }
                        continue;
GOTODIC:
                        _stdString* derb=(_stdString* )xv->ptr;
                        int mo=-1;
                       
                        for(int i=0;i<xf->gotoFlags->keys->count;i++)
                        {
                            _stdString* xp=(_stdString*)_stdLst::get(xf->gotoFlags->keys,i);
                            if(_stdStr::compareWith(xp,derb))
                            {
                                xv->ptr=_stdMEM::mainAllocate(4);
                                unsigned int xto=*(unsigned int*)_stdLst::get(xf->gotoFlags->vals,i);
                                xv->needPostCompileGoto=false;
                                memcpy(xv->ptr,&xto,4);
                                break;
                            }
                        }

                        _stdStr::DEL(derb);
                    }
                }
            }
        }
    }
    //----------------
    ////обработка неопределённых тайпов переменных
    //---------------
    for(int i =0;i<scr->Namespaces->count;i++)
    {
        XONamespace* xs=(XONamespace*)_stdLst::get(scr->Namespaces,i);
        for(int j =0;j<xs->Classes->count;j++)
        {
            XOClass* xc=(XOClass*)_stdLst::get(xs->Classes,j);
            for(int k =0;k<xc->Functions->count;k++)
            {
                XOFunction* xf=(XOFunction*)_stdLst::get(xc->Functions,k);
                for(int u =0;u<xf->Variables->count;u++)
                {
                    XOVariable* xv=(XOVariable*)_stdLst::get(xf->Variables,u);
                    if(xv->needPostCompile)
                    {
                        _stdString* needdel=(_stdString* )xv->ptr;
                        if(searchClass(needdel,scr))return true;
                        if(ndefConstr)continue;//это не класс
                        _stdStr::DEL(needdel);
                        xv->type=XOidentifers::xoScriptClass;
                        xv->mime[0]=NPATH[0];xv->mime[1]=NPATH[1];
                        xv->needPostCompile=false;
                    }
                }
            }
            for(int k =0;k<xc->Variables->count;k++)
            {
                XOVariable* xv=(XOVariable*)_stdLst::get(xc->Variables,k);
                if(xv->needPostCompile)
                {
                    _stdString* needdel=(_stdString* )xv->ptr;
                    if(searchClass(needdel,scr))return true;
                    if(ndefConstr)continue;//это не класс
                    _stdStr::DEL(needdel);
                    xv->type=XOidentifers::xoScriptClass;
                    xv->mime[0]=NPATH[0];xv->mime[1]=NPATH[1];
                    xv->needPostCompile=false;
                }
            }
        }
    }
    ///////////////
    //------Оптимизация invoke(ну если вдруг туда попадут всякие сеты или аддшки)
    ////////////
    for(int i =0;i<scr->Namespaces->count;i++)
    {
        XONamespace* xs=(XONamespace*)_stdLst::get(scr->Namespaces,i);

        for(int j =0;j<xs->Classes->count;j++)
        {
            XOClass* xc=(XOClass*)_stdLst::get(xs->Classes,j);

            for(int k =0;k<=xc->Functions->count;k++)
            {
                //XOFunction* xf=(XOFunction*)_stdLst::get(xc->Functions,k);
                bool illum=false;
                XOFunction* xf=0;
                if(k==xc->Functions->count)
                {xf=xc->illuminator;illum=true;}
                else
                    xf=(XOFunction*)_stdLst::get(xc->Functions,k);

                for(int u =0;u<xf->Lines->count;u++)
                {
                    XOLine* xl=(XOLine*)_stdLst::get(xf->Lines,u);
                    if(u==xf->Lines->count-1)
                    {
                        if(xl->opcode!=XOidentifers::oret)
                        {
                            XOLine* xol=XO_Script::newLine();
                            xol->opcode=XOidentifers::oret;
                            _stdLst::import(xf->Lines,xol);
                        }
                    }
                    if(xl->opcode==XOidentifers::oinvoke)
                    {
                        XOArgument* xa=(XOArgument*)_stdLst::get(xl->Arguments,0);
                        //проверяем первый аргумент(что вызываем?)
                        if(xa->fly)//Только флай потому что других переменных с данными пока нет
                        {
                            XOVariable* xv=(XOVariable*)xa->ptr;
                            if(xv->type==XOidentifers::xostring)
                            {
                                _stdString* str=(_stdString*)xv->ptr;
                                _stdStr::replace(str," ","");
                                int iop=XOidentifers::getOpcode(str);
                                if(iop>=0)//есть что оптимизировать!
                                {
                                    //Удаляем первый аргумент и заменяем опкод линии
                                    xl->opcode=iop;
                                    XO_Script::FreeArg(xa);
                                    _stdLst::removeAt(xl->Arguments,0);
                                }
                                else//замена invoke на call в случае вызова локальной функции
                                {
                                    FPATH[0]=i;FPATH[1]=j;FPATH[2]=illum?-1:k;
                                    if(searchFunc(str,scr))return true;
                                    if(ndefFunc)goto NATIVE_SEARCH;//функция не найдена
                                    //найдена
                                    xl->opcode=XOidentifers::ocall;
                                    XO_Script::DELArg(xa);
                                    //_stdLst::removeAt(xl->Arguments,0);
                                    //
                                    XOArgument* xoa=XO_Script::newArg();
                                    xoa->classVar=true;

                                    //---------------
                                    xoa->ptr=_stdMEM::mainAllocate(3*4);
                                    memcpy(xoa->ptr,&FPATH[0],3*4);
                                    _stdLst::set(xl->Arguments,0,xoa);
                                }
                                continue;
NATIVE_SEARCH:
                                //ПОИСК нативной функции
                                XO_native_func*xnf = xo_natives::getNativeFunc(str->ptr);
                                if(xnf==NULL)continue;//НЕ НАЙДЕНА
                                XO_Script::DELArg(xa);
                                XOArgument* xoa=XO_Script::newArg();
                                xoa->BAR4=true;
                                xoa->ptr=_stdMEM::mainAllocate(4);
                                memcpy(xoa->ptr,&xnf,4);
                                _stdLst::set(xl->Arguments,0,xoa);
                            }
                        }
                    }
                }
            }
        }
    }
    ///////////////
    //------компиляция иллюминаторов
    ////////////
    /*int a=0;
    int b=0;
    int c=0;
    for(int i =0;i<scr->Namespaces->count;i++)
    {
        XONamespace* xs=(XONamespace*)_stdLst::get(scr->Namespaces,i);

        for(int j =0;j<xs->Classes->count;j++)
        {
            XOClass* xc=(XOClass*)_stdLst::get(xs->Classes,j);
            XOFunction* xf=xc->illuminator;
            if(xf->Lines->count>0){
                XOexec* exe=xo_execution::newState();
                exe->xop->xoclass=j;
                exe->xop->xonamespace=i;
                exe->xop->xofunc=-1;
                exe->xop->xoline=0;

                xo_execution::RunLine(exe,scr);
                xo_execution::DELState(exe);
            }
        }
    }*/
    return false;
}