示例#1
0
C4ValueArray * C4PropList::GetProperties() const
{
	C4ValueArray * a;
	int i;
	if (GetPrototype())
	{
		a = GetPrototype()->GetProperties();
		i = a->GetSize();
		a->SetSize(i + Properties.GetSize());
	}
	else
	{
		a = new C4ValueArray(Properties.GetSize());
		i = 0;
	}
	const C4Property * p = Properties.First();
	while (p)
	{
		assert(p->Key != nullptr && "Proplist key is nullpointer");
		(*a)[i++] = C4VString(p->Key);
		assert(((*a)[i - 1].GetType() == C4V_String) && "Proplist key is non-string");
		p = Properties.Next(p);
	}
	return a;
}
示例#2
0
bool C4PropList::GetPropertyBoolByS(C4String * k, bool default_val) const
{
	if (Properties.Has(k))
	{
		return Properties.Get(k).Value.getBool();
	}
	if (GetPrototype())
	{
		return GetPrototype()->GetPropertyBoolByS(k, default_val);
	}
	return default_val;
}
示例#3
0
C4ValueArray * C4PropList::GetPropertyArray(C4PropertyName n) const
{
	C4String * k = &Strings.P[n];
	if (Properties.Has(k))
	{
		return Properties.Get(k).Value.getArray();
	}
	if (GetPrototype())
	{
		return GetPrototype()->GetPropertyArray(n);
	}
	return 0;
}
示例#4
0
C4AulFunc * C4PropList::GetFunc(C4String * k) const
{
	assert(k);
	if (Properties.Has(k))
	{
		return Properties.Get(k).Value.getFunction();
	}
	if (GetPrototype())
	{
		return GetPrototype()->GetFunc(k);
	}
	return 0;
}
示例#5
0
int32_t C4PropList::GetPropertyInt(C4PropertyName n, int32_t default_val) const
{
	C4String * k = &Strings.P[n];
	if (Properties.Has(k))
	{
		return Properties.Get(k).Value.getInt();
	}
	if (GetPrototype())
	{
		return GetPrototype()->GetPropertyInt(n, default_val);
	}
	return default_val;
}
示例#6
0
C4PropList *C4PropList::GetPropertyPropList(C4PropertyName n) const
{
	C4String * k = &Strings.P[n];
	if (Properties.Has(k))
	{
		return Properties.Get(k).Value.getPropList();
	}
	if (GetPrototype())
	{
		return GetPrototype()->GetPropertyPropList(n);
	}
	return NULL;
}
示例#7
0
C4PropertyName C4PropList::GetPropertyP(C4PropertyName n) const
{
	C4String * k = &Strings.P[n];
	if (Properties.Has(k))
	{
		C4String * v = Properties.Get(k).Value.getStr();
		if (v >= &Strings.P[0] && v < &Strings.P[P_LAST])
			return C4PropertyName(v - &Strings.P[0]);
		return P_LAST;
	}
	if (GetPrototype())
	{
		return GetPrototype()->GetPropertyP(n);
	}
	return P_LAST;
}
示例#8
0
bool C4PropList::GetPropertyByS(C4String * k, C4Value *pResult) const
{
	if (Properties.Has(k))
	{
		*pResult = Properties.Get(k).Value;
		return true;
	}
	else if (k == &Strings.P[P_Prototype])
	{
		*pResult = prototype;
		return true;
	}
	else if(GetPrototype())
		return GetPrototype()->GetPropertyByS(k, pResult);
	else
		return false;
}
示例#9
0
C4PropList::Iterator C4PropList::begin()
{
	C4PropList::Iterator iter;

	if (GetPrototype())
	{
		iter = GetPrototype()->begin();
	}
	else
	{
		iter.properties = std::make_shared<std::vector<const C4Property*> >();
	}
	iter.Reserve(Properties.GetSize());

	const C4Property * p = Properties.First();
	while (p)
	{
		iter.AddProperty(p);
		p = Properties.Next(p);
	}

	iter.Init();
	return iter;
}
示例#10
0
class C4MapScriptMap * C4PropList::GetMapScriptMap()
{
	if (GetPrototype()) return GetPrototype()->GetMapScriptMap();
	return NULL;
}
示例#11
0
Tool* IBGraphicCompTool::Copy () {
    return new IBGraphicCompTool(CopyControlInfo(), GetPrototype());
}
示例#12
0
文件: funcmap.c 项目: LuccoJ/z80sim
int main(int argc, char* argv[]) {
	FILE* MapFile=0;
	FILE* CallsFile=0;
	FILE* ObjFile=0;
	FILE* CodeFile=0;
	FILE* ProtoFile=0;
	char Line[MAX_STRING];
	char Name[MAX_NAME];
	char Command[MAX_NAME];
	char File[MAX_STRING];
	char AddressString[MAX_STRING];
	word Address;
	bool PrependJPs=FALSE;
	int i;

	if(argc>1) if(!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")) {
		Syntax(argv[0]);
		exit(0);
	}
	for(i=1; i<argc; i++) {
		if(!strcmp(argv[i], "--jp")) {
			PrependJPs=TRUE;
		} else if(!strcmp(argv[i], "--code") && i+1<argc) {
			CodeFile=fopen(argv[++i], "w");
		} else if((!strcmp(argv[i], "--input") || !strcmp(argv[i], "-i")) && i+1<argc) {
			if(!strcmp(argv[++i], "-")) {
				CallsFile=stdin;
			} else {
				CallsFile=fopen(argv[i], "r");
			}
		} else if(!strcmp(argv[i], "--sym")  && i+1<argc) {
			MapFile=fopen(argv[++i], "r");
		} else if((!strcmp(argv[i], "--obj") || !strcmp(argv[i], "-o")) && i+1<argc) {
			ObjFile=fopen(argv[++i], "w");
		}
	}
	if(!CallsFile || !MapFile || !ObjFile) {
		fprintf(stderr, "You must specify at least a valid input file, symbols file and object file\n");
		Syntax(argv[0]);
		exit(-1);
	}

	if(CodeFile) fprintf(stderr, "Will generate a C source with function wrappers.\n");

	fprintf(stderr, "Creating list of functions to be mapped...\n");

	FunctionsCount=0; while(!feof(CallsFile)) {
		fgets(Line, MAX_STRING, CallsFile);
		sscanf(Line, "%s", Command);
		if(!strcmp(Command, "prototypes")) {
			sscanf(Line, "%s %s", Command, File);
			if(ProtoFile) fclose(ProtoFile);
			if(!(ProtoFile=fopen(File, "r"))) {
				fprintf(stderr, "No such prototypes file '%s'.\n", File);
				exit(-1);
			}
		} else {
			sscanf(Line, "%x %s", &Functions[FunctionsCount].ID, Functions[FunctionsCount].Name);
			Functions[FunctionsCount].Address=0xFFFF;
			if(ProtoFile) GetPrototype(ProtoFile, &Functions[FunctionsCount]);
			if(!feof(CallsFile)) FunctionsCount++;
		}
	}

	fprintf(stderr, "Mapping functions...\n");

	while(!feof(MapFile)) {
		fgets(Line, MAX_STRING, MapFile);
		if(Line[0]!=';') {
			sscanf(Line, "%s %s", AddressString, Name);
                        sscanf(&AddressString[3], "%x", &Address);
			if(Name[0]=='_' && AddressString[2]==':') Map(&Name[1], Address);
		}
	}

	fprintf(stderr, "Sorting list...\n");

	SortFunctions();

	fprintf(stderr, "Generating output...\n\n");

	if(CodeFile) {
		fprintf(CodeFile, "/* Library source generated by funcmap\n   (Copyright (c) 2003 Lorenzo J. Lucchini, <*****@*****.**>)\n\n   Every library function saves the address to resume userland execution from\n   into HL, then loads the system call number into A, and then makes the call\n   by means of a RST08 instruction. */\n\n\n");
		fprintf(CodeFile, "/* Declarations */\n\n");
		for(i=0; i<FunctionsCount; i++) {
			fprintf(CodeFile, "%s;\n", Functions[i].Prototype);
		}
		fprintf(CodeFile, "\n/* Definitions */ \n");
	}

	for(i=0; i<FunctionsCount; i++) {
		if(Functions[i].Address==0xFFFF) {
			fprintf(stderr, "Warning: Unmapped call %03d ('%s')\n", Functions[i].ID, Functions[i].Name);
		} else {
			if(CodeFile) {
				fprintf(CodeFile, "\n%s {\n", Functions[i].Prototype);
				fprintf(CodeFile, "    _asm\n    pop hl\n    ld a,#0x%02x\n    rst 0x08\n    _endasm;\n", Functions[i].ID);
				fprintf(CodeFile, "}\n");
			}
			fprintf(stdout, "Call %03d: '%s' at %04x\n", Functions[i].ID, Functions[i].Name, Functions[i].Address);
			if(PrependJPs) fprintf(ObjFile, "%c", OP_JP);
			fprintf(ObjFile, "%c%c", Functions[i].Address&0xff, (Functions[i].Address>>8)&0xff);
		}
	}
	fprintf(stdout, "\n");
	return 0;
}
示例#13
0
C4Object * C4PropList::GetObject()
{
	if (GetPrototype()) return GetPrototype()->GetObject();
	return 0;
}
示例#14
0
C4Def * C4PropList::GetDef()
{
	if (GetPrototype()) return GetPrototype()->GetDef();
	return 0;
}
示例#15
0
C4Def const * C4PropList::GetDef() const
{
	if (GetPrototype()) return GetPrototype()->GetDef();
	return 0;
}
示例#16
0
C4Effect * C4PropList::GetEffect()
{
	if (GetPrototype()) return GetPrototype()->GetEffect();
	return 0;
}
示例#17
0
double Attribute::EvalCompiledNLGExpression (double const x, double const y ,double const z, double const g ) {

//cout << GetPrototype()->GetName() << " ??  at pointer num " << m_cur_fp << " -> compiled = " << m_compiled.at(m_cur_fp) << endl;
 	if (m_nlgfp == NULL && m_ginac_excomp) {
 		//substitute all attributes with numbers in GiNaC expression, except the attribute
 		//which serves as the free parameter for runtime compilation
 		GiNaC::lst symlist;
 		GiNaC::lst numlist;
 		for (unsigned int i=0; i<m_subjects.size() ; i++) {
 			Attribute* a = m_subjects.at(i);
 			if (a->GetName() == "NLG_posX") continue;
 			if (a->GetName() == "NLG_posY") continue;
 			if (a->GetName() == "NLG_posZ") continue;
 			if (a->GetName() == "NLG_value") continue;
 	        symlist.append( get_symbol(a->GetSymbol()) );
 			if (a->GetTypeID()==typeid(  double*).name()) { numlist.append(a->GetMember  <double>() ); continue; }
 			if (a->GetTypeID()==typeid(     int*).name()) { numlist.append(a->GetMember     <int>() ); continue; }
 			if (a->GetTypeID()==typeid(    long*).name()) { numlist.append(a->GetMember    <long>() ); continue; }
 			if (a->GetTypeID()==typeid(unsigned*).name()) { numlist.append(a->GetMember<unsigned>() ); continue; }
 			if (a->GetTypeID()==typeid(    bool*).name()) { numlist.append(a->GetMember    <bool>() ); continue; }
 		}

		GiNaC::ex e = GiNaC::evalf((symlist.nops()==0)?m_expression:m_expression.subs(symlist,numlist));

		try {
			compile_ex (e,
						get_symbol(GetPrototype()->GetAttribute("NLG_posX")->GetSymbol()),
						get_symbol(GetPrototype()->GetAttribute("NLG_posY")->GetSymbol()),
						get_symbol(GetPrototype()->GetAttribute("NLG_posZ")->GetSymbol()),
						get_symbol(GetPrototype()->GetAttribute("NLG_value")->GetSymbol()),
						m_nlgfp);
 			//cout << " compiling attribute " << GetName() << " of module " << GetPrototype()->GetName() << endl;
		}
	 	catch (exception &p) {
 			cout << " Warning: attribute " << GetName() << " of module " << GetPrototype()->GetName() << endl << endl
 				 << " function Attribute::EvalCompiledNLGExpression" << endl
 				 << " No external runtime compiler available: " << p.what() << endl
				 << " Falling back to (slow) analytic evaluation!" << endl << endl
				 << " Hint: if you have a shell and gcc on your system, create the one-liner " << endl << endl
				 << "    #!/bin/sh" << endl
				 << "    gcc -x c -fPIC -shared -o $1.so $1" << endl << endl
 		         << " name it \"ginac-excompiler\", and put it somewhere in your search path." << endl << endl;
	 		m_ginac_excomp = false;
	 	}
 	}

	//if compilation failed, invoke slow analytic evaluation
	if (!m_ginac_excomp ) {
		*((double*) GetPrototype()->GetAttribute("NLG_posX")-> GetAddress()) = x;
		*((double*) GetPrototype()->GetAttribute("NLG_posY")-> GetAddress()) = y;
		*((double*) GetPrototype()->GetAttribute("NLG_posZ")-> GetAddress()) = z;
		*((double*) GetPrototype()->GetAttribute("NLG_value")-> GetAddress()) = g;
 		EvalExpression();
 		return *((double*) GetAddress());
 	}

	//invoke fast runtime compiled routines
	if ( m_nlgfp != NULL ) return m_nlgfp(x,y,z,g);

	return 0.0;

}
示例#18
0
C4PropListNumbered * C4PropList::GetPropListNumbered()
{
	if (GetPrototype()) return GetPrototype()->GetPropListNumbered();
	return 0;
}
示例#19
0
double Attribute::EvalCompiledExpression (double const val, std::string const attrib ) {

//cout << GetPrototype()->GetName() << " ??  at pointer num " << m_cur_fp << " -> compiled = " << m_compiled.at(m_cur_fp) << endl;
 	if (!m_compiled.at(m_cur_fp)) {
 		//substitute all attributes with numbers in GiNaC expression, except the attribute
 		//which serves as the free parameter for runtime compilation
 		GiNaC::lst symlist;
 		GiNaC::lst numlist;
 		for (unsigned int i=0; i<m_subjects.size() ; i++) {
 			Attribute* a = m_subjects.at(i);
 			if (a->GetName() == attrib) continue;
 	        symlist.append( get_symbol(a->GetSymbol()) );
 			if (a->GetTypeID()==typeid(  double*).name()) { numlist.append(a->GetMember  <double>() ); continue; }
 			if (a->GetTypeID()==typeid(     int*).name()) { numlist.append(a->GetMember     <int>() ); continue; }
 			if (a->GetTypeID()==typeid(    long*).name()) { numlist.append(a->GetMember    <long>() ); continue; }
 			if (a->GetTypeID()==typeid(unsigned*).name()) { numlist.append(a->GetMember<unsigned>() ); continue; }
 			if (a->GetTypeID()==typeid(    bool*).name()) { numlist.append(a->GetMember    <bool>() ); continue; }
 		}

		GiNaC::ex e = GiNaC::evalf((symlist.nops()==0)?m_expression:m_expression.subs(symlist,numlist));

		//add function pointers
		m_fp.push_back(NULL);
		m_fpi.push_back(NULL);
		//compile the GiNaC expression
		try {
			//fairly easy for real valued expressions
			if (!m_complex) {
				compile_ex(e, get_symbol(GetPrototype()->GetAttribute(attrib)->GetSymbol()), m_fp.at(m_num_fp));
			}
			//more work to do, since GiNaC::realsymbol does not behave as expected (and it is therefore not used at all)
			else {
				stringstream se; se << e; std::string formula = se.str();
				std::string sym  = GetPrototype()->GetAttribute(attrib)->GetSymbol();
				std::string asym = "abs(VarForEvalCompiledExpression)";
				Prototype::ReplaceString(formula,sym,asym);
				GiNaC::lst symlist;
				symlist.append( get_symbol("VarForEvalCompiledExpression") );
				GiNaC::ex ea = GiNaC::ex(formula,symlist);
				symlist.remove_all();
				symlist.append( get_symbol(sym) );

				GiNaC::ex ear = ea.real_part();
				stringstream ser;  ser << ear; formula = ser.str();
				if ( Prototype::ReplaceString(formula,asym,sym) ) {
					ear  = GiNaC::ex(formula,symlist);
					compile_ex(ear, get_symbol(GetPrototype()->GetAttribute(attrib)->GetSymbol()), m_fp.at(m_num_fp));
				}

				GiNaC::ex eai = ea.imag_part();
				stringstream sei;  sei << eai; formula = sei.str();
				if ( Prototype::ReplaceString(formula,asym,sym) ) {
					eai  = GiNaC::ex(formula,symlist);
					compile_ex(eai, get_symbol(GetPrototype()->GetAttribute(attrib)->GetSymbol()), m_fpi.at(m_num_fp));
				}
			}
 			//cout << " compiling expression " << e << " of attribute " << GetName() << " in module " << GetPrototype()->GetName() << endl;
 		 	m_num_fp++;
		}
	 	catch (exception &p) {
 			cout << " Warning: attribute " << GetName() << " of module " << GetPrototype()->GetName() << endl << endl
 				 << " function Attribute::EvalCompiledExpression" << endl
 				 << " No external runtime compiler available: " << p.what() << endl
				 << " Falling back to (slow) analytic evaluation!" << endl << endl
				 << " Hint: if you have a shell and gcc on your system, create the one-liner " << endl << endl
				 << "    #!/bin/sh" << endl
				 << "    gcc -x c -fPIC -shared -o $1.so $1" << endl << endl
 		         << " name it \"ginac-excompiler\", and put it somewhere in your search path." << endl << endl;
	 		m_ginac_excomp = false;
	 	}
		m_compiled.at(m_cur_fp) = true; //even if compilation failed, as we don't have to try a second time!
 	}

	//if compilation failed, invoke slow analytic evaluation
	if (!m_ginac_excomp ) {
		*((double*) GetPrototype()->GetAttribute(attrib)-> GetAddress()) = val;
 		EvalExpression();
 		return *((double*) GetAddress());
 	}

	//invoke fast runtime compiled routines
 	if (m_fpi.at(m_cur_fp) != NULL ) m_imaginary = m_fpi.at(m_cur_fp)(val);
	if ( m_fp.at(m_cur_fp) != NULL ) return m_fp.at(m_cur_fp)(val);

	return 0.0;

}