コード例 #1
0
ファイル: CSharpCodegen.cpp プロジェクト: bobzhen/tinymoe
string FunctionToValue(CSharpNameResolver& resolver, AstFunctionDeclaration* decl, AstDeclaration* scope)
{
	stringstream ss;
	string argumentName = resolver.Resolve("__args__", scope);
	ss << "new TinymoeFunction(" << argumentName << " => " << FunctionToTypedName(resolver, decl) << "(";
	for (auto it = decl->arguments.begin(); it != decl->arguments.end(); it++)
	{
		ss << argumentName << "[" << it - decl->arguments.begin() << "]";
		if (it + 1 == decl->arguments.end())
		{
			ss << "))";
		}
		else
		{
			ss << ", ";
		}
	}
	return ss.str();
}
コード例 #2
0
ファイル: CSharpCodegen.cpp プロジェクト: 542447275/tinymoe
string_t FunctionToValue(CSharpNameResolver& resolver, AstFunctionDeclaration* decl, AstDeclaration* scope)
{
	stringstream_t ss;
	string_t argumentName = resolver.Resolve(T("__args__"), scope);
	ss << T("new TinymoeFunction(") << argumentName << T(" => ") << FunctionToTypedName(resolver, decl) << T("(");
	for (auto it = decl->arguments.begin(); it != decl->arguments.end(); it++)
	{
		ss << argumentName << T("[") << it - decl->arguments.begin() << T("]");
		if (it + 1 == decl->arguments.end())
		{
			ss << T("))");
		}
		else
		{
			ss << T(", ");
		}
	}
	return ss.str();
}
コード例 #3
0
ファイル: CSharpCodegen.cpp プロジェクト: bobzhen/tinymoe
void GenerateCSharpCode(AstAssembly::Ptr assembly, ostream& o)
{
	CSharpNameResolver resolver;
	o << "using System;" << endl;
	o << "using System.Collections.Generic;" << endl;
	o << "using TinymoeDotNet;" << endl;
	o << "" << endl;
	o << "namespace TinymoeProgramNamespace" << endl;
	o << "{" << endl;
	o << "\tpublic class TinymoeProgram : TinymoeOperations" << endl;
	o << "\t{" << endl;
	{
		for (auto decl : assembly->declarations)
		{
			resolver.Scope(decl.get(), nullptr);
		}
		CSharpDeclarationCodegen codegen(resolver, o, "\t\t");
		for (auto decl : assembly->declarations)
		{
			decl->Accept(&codegen);
		}
	}
	o << "\t\tpublic TinymoeProgram()" << endl;
	o << "\t\t{" << endl;
	{
		CSharpExtensionDeclarationCodegen codegen(resolver, o, "\t\t\t");
		for (auto decl : assembly->declarations)
		{
			decl->Accept(&codegen);
		}
	}
	o << "\t\t}" << endl;
	o << endl;
	{
		string mainName;
		for (auto decl : assembly->declarations)
		{
			if (decl->composedName.size() >= 6)
			{
				if (decl->composedName.substr(decl->composedName.size() - 6, 6) == "::main")
				{
					mainName = resolver.Resolve(decl.get());
					break;
				}
			}
		}
		o << "\t\tstatic void Main(string[] args)" << endl;
		o << "\t\t{" << endl;
		o << "\t\t\tvar program = new TinymoeProgram();" << endl;
		o << "\t\t\tvar continuation = new TinymoeFunction((TinymoeObject[] arguments) =>" << endl;
		o << "\t\t\t{" << endl;
		o << "\t\t\t});" << endl;
		o << "\t\t\tvar trap = new TinymoeProgram.standard_library__continuation_trap();" << endl;
		o << "\t\t\ttrap.SetField(\"continuation\", continuation);" << endl;
		o << "\t\t\tvar state = new TinymoeProgram.standard_library__continuation_state();" << endl;
		o << "\t\t\tstate.SetField(\"trap\", trap);" << endl;
		o << "\t\t\tprogram." << mainName << "(state, continuation);" << endl;
		o << "\t\t}" << endl;
	}
	o << "\t}" << endl;
	o << "}" << endl;
}
コード例 #4
0
ファイル: CSharpCodegen.cpp プロジェクト: bobzhen/tinymoe
string FunctionToName(CSharpNameResolver& resolver, AstFunctionDeclaration* decl)
{
	return resolver.Resolve(decl);
}