dNewtonLuaCompiler::dUserVariable dNewtonLuaCompiler::EmitLoadConstant(const dUserVariable& constName) { dString localVariableAliasName(m_currentClosure->NewTemp()); dCILInstr::dIntrisicType constType = dCILInstr::m_luaType; dCILInstr::dIntrisicType variableType = dCILInstr::m_luaType; int token = constName.GetToken(); switch (token) { case _INTEGER: variableType = dCILInstr::m_int; constType = dCILInstr::m_constInt; break; default: dAssert(0); } dCILInstrMove* const move = new dCILInstrMove(*m_currentClosure, localVariableAliasName, dCILInstr::dArgType(variableType), constName.GetString(), dCILInstr::dArgType (constType)); TRACE_INSTRUCTION(move); return dUserVariable(move); }
void dDAGFunctionNode::CompileCIL(dCIL& cil) { dAssert (m_body); dDAGClassNode* const myClass = GetClass(); cil.ResetTemporaries(); dString returnVariable (cil.NewTemp()); dString functionName (myClass->GetFunctionName (m_name, m_parameters)); dCILInstrFunction* const function = new dCILInstrFunction (cil, functionName, m_returnType->GetArgType()); m_functionStart = function->GetNode(); if (!m_isStatic) { dAssert (0); // dList<dDAGParameterNode*>::dListNode* const argNode = m_parameters.GetFirst(); // dDAGParameterNode* const arg = argNode->GetInfo(); // m_opertatorThis = arg->m_result.m_label; } // emit the function arguments for (dList<dDAGParameterNode*>::dListNode* argNode = m_parameters.GetFirst(); argNode; argNode = argNode->GetNext()) { dDAGParameterNode* const arg = argNode->GetInfo(); arg->m_result = function->AddParameter (arg->m_name, arg->m_type->GetArgType())->GetInfo(); } function->Trace(); dCILInstrLabel* const entryPoint = new dCILInstrLabel(cil, cil.NewLabel()); entryPoint->Trace(); for (dList<dDAGParameterNode*>::dListNode* argNode = m_parameters.GetFirst(); argNode; argNode = argNode->GetNext()) { dDAGParameterNode* const arg = argNode->GetInfo(); dTree<dCILInstr::dArg, dString>::dTreeNode* const varNameNode = m_body->FindVariable(arg->m_name); dAssert (varNameNode); dCILInstrArgument* const localVariable = new dCILInstrArgument(cil, varNameNode->GetInfo().m_label, varNameNode->GetInfo().GetType()); localVariable->Trace(); } for (dList<dDAGParameterNode*>::dListNode* argNode = m_parameters.GetFirst(); argNode; argNode = argNode->GetNext()) { dDAGParameterNode* const arg = argNode->GetInfo(); dTree<dCILInstr::dArg, dString>::dTreeNode* const varNameNode = m_body->FindVariable(arg->m_name); dAssert (varNameNode); //dCILInstrStore* const store = new dCILInstrStore(cil, varNameNode->GetInfo().m_label, varNameNode->GetInfo().GetType(), arg->m_name, arg->GetType()->GetArgType()); dString localVariableAliasName(cil.NewTemp()); dCILInstrMove* const store = new dCILInstrMove(cil, localVariableAliasName, arg->GetType()->GetArgType(), varNameNode->GetInfo().m_label, varNameNode->GetInfo().GetType()); //arg->m_result = store->GetArg0(); varNameNode->GetInfo().m_label = localVariableAliasName; store->Trace(); } m_body->CompileCIL(cil); if (!m_returnType->GetArgType().m_isPointer && (m_returnType->GetArgType().m_intrinsicType == dCILInstr::m_void)) { if (!cil.GetLast()->GetInfo()->GetAsReturn()) { dCILInstrReturn* const ret = new dCILInstrReturn(cil, "", dCILInstr::dArgType (dCILInstr::m_void)); ret->Trace(); } } new dCILInstrFunctionEnd(function); // cil.Trace(); }