/// <summary> /// Compile a routine /// </summary> /// <param name="routine"></param> /// <param name="bIsMain">The main function doesn't need a RETURN commands</param> private void compileRoutine(XElement routine, bool bIsMain, Stack stack) { DataTable localDataTable = new DataTable(); // push all parameters(attributes) int index = 2 + routine.Attributes().Count(); // 0 points to next free,-1 is eip, -2 is ebp, -3 is first param foreach (XAttribute attr in routine.Attributes()) { //if (bIsMain) //{ //m_currentProgramCode.Writer.Write((int)XmlScriptExecutor.OpCode.ALLOC_STRING_ON_HEAP); //stack.push(); //} localDataTable.add(attr.Name.LocalName, -1 * index * sizeof(int)); --index; } foreach (XElement instruction in routine.Elements()) { // push parameters foreach (XAttribute attr in instruction.Attributes()) { pushParameter(localDataTable, attr.Value); } compile(instruction, localDataTable, instruction.Attributes().Count()); } if (!bIsMain) { m_currentProgramCode.Writer.Write((int)XmlScriptExecutor.OpCode.RETURN); } }