private string GetInstructionStatement(AbstractInstruction inst) { string statement = "program.Add(iset.CreateInstruction("; if (inst.Name() == "procedure") { ProcedureInstruction pi = (ProcedureInstruction)inst; statement += "\"procedure\", \"" + pi.ProcedureName + "\", \"" + pi.Arity + "\""; } else { if (inst._arguments == null || inst._arguments.Length == 0) { statement += "\"" + inst.Name() + "\""; } else { statement += "\"" + inst.Name() + "\", "; for (int i = 0; i < inst._arguments.Length; i++) { statement += "\"" + inst._arguments[i] + "\""; if (i != (inst._arguments.Length - 1)) { statement += ", "; } } } } statement += "));"; return(statement); }
private void GenerateMethod(CodeTypeDeclaration classType, ProcedureInstruction pi) { CodeMemberMethod method = new CodeMemberMethod(); method.Name = pi.ProcedureName; method.ReturnType = new CodeTypeReference("System.Boolean"); method.Attributes = MemberAttributes.Public; string objectStatement = "new object [] { "; for (int i = 0; i < pi.Arity; i++) { method.Parameters.Add(new CodeParameterDeclarationExpression("System.Object", "arg" + (i + 1))); objectStatement += "arg" + (i + 1); if (i == pi.Arity - 1) { objectStatement += " }"; } else { objectStatement += ", "; } } method.Statements.Add(new CodeSnippetStatement("return machine.Call(\"" + pi.ProcedureName + "\", " + pi.Arity + ", " + objectStatement + ", _more);")); classType.Members.Add(method); }
public override void Initialize(ArrayList program) { foreach (AbstractInstruction i in program) { if (i.Name() == "procedure") { ProcedureInstruction p = (ProcedureInstruction)i; ProgramClause pClause = new ProgramClause(p.ProcedureName, p.Arity); AddLabel(pClause.Name + "/" + pClause.Arity, pClause); } else { AddInstruction(i); } } _p = _program; }
public AMInstructionSet() { _instructions["allocate"] = new AllocateInstruction(); _instructions["bcall"] = new BCallInstruction(); _instructions["call"] = new CallInstruction(); _instructions["cut"] = new CutInstruction(); _instructions["deallocate"] = new DeallocateInstruction(); _instructions["execute"] = new ExecuteInstruction(); _instructions["fcall"] = new FCallInstruction(); _instructions["fail"] = new FailInstruction(); _instructions["get_constant"] = new GetConstantInstruction(); _instructions["get_list"] = new GetListInstruction(); _instructions["get_structure"] = new GetStructureInstruction(); _instructions["get_value"] = new GetValueInstruction(); _instructions["get_variable"] = new GetVariableInstruction(); _instructions["halt"] = new HaltInstruction(); _instructions["nop"] = new NopInstruction(); _instructions["proceed"] = new ProceedInstruction(); _instructions["put_constant"] = new PutConstantInstruction(); _instructions["put_list"] = new PutListInstruction(); _instructions["put_structure"] = new PutStructureInstruction(); _instructions["put_unsafe_value"] = new PutUnsafeValueInstruction(); _instructions["put_variable"] = new PutVariableInstruction(); _instructions["put_value"] = new PutValueInstruction(); _instructions["retry_me_else"] = new RetryMeElseInstruction(); _instructions["set_constant"] = new SetConstantInstruction(); _instructions["set_local_value"] = new SetLocalValueInstruction(); _instructions["set_value"] = new SetValueInstruction(); _instructions["set_variable"] = new SetVariableInstruction(); _instructions["set_void"] = new SetVoidInstruction(); _instructions["trust_me"] = new TrustMeInstruction(); _instructions["try_me_else"] = new TryMeElseInstruction(); _instructions["unify_constant"] = new UnifyConstantInstruction(); _instructions["unify_local_value"] = new UnifyLocalValueInstruction(); _instructions["unify_variable"] = new UnifyVariableInstruction(); _instructions["unify_value"] = new UnifyValueInstruction(); _instructions["unify_void"] = new UnifyVoidInstruction(); _instructions["procedure"] = new ProcedureInstruction(); }
private void GenerateMethodSignatures(CodeTypeDeclaration classType, ArrayList instructions) { Hashtable procedures = new Hashtable(); // Get all predicate names foreach (AbstractInstruction i in instructions) { if (i.Name() == "procedure") { ProcedureInstruction pi = (ProcedureInstruction)i; if (!procedures.ContainsKey(pi.ProcedureName)) { procedures.Add(pi.ProcedureName, pi); } } } foreach (DictionaryEntry entry in procedures) { ProcedureInstruction pi = (ProcedureInstruction)entry.Value; GenerateMethod(classType, pi); } }
private static void GenerateXmlFile(string xmlFilename, ArrayList assemblyFiles, ArrayList arrayList) { XmlTextWriter xmltw = new XmlTextWriter(xmlFilename, null); xmltw.Formatting = Formatting.Indented; xmltw.WriteStartDocument(); xmltw.WriteComment(" This file was automatically generated by axiomc "); xmltw.WriteComment(" Source: " + xmlFilename.Replace(".xml", ".pro") + ", Date: " + DateTime.Now + " "); xmltw.WriteStartElement("AMProgram"); /* write namespaces and assembly files here */ if (assemblyFiles.Count > 0) { xmltw.WriteStartElement("AssemblyFiles"); foreach (string asmFile in assemblyFiles) { xmltw.WriteStartElement("LoadAssembly"); xmltw.WriteString(asmFile); xmltw.WriteEndElement(); } xmltw.WriteEndElement(); } for (int i = 0; i < arrayList.Count; i++) { AbstractInstruction inst = (AbstractInstruction)arrayList[i]; if (inst.Name() == "procedure") { ProcedureInstruction p = (ProcedureInstruction)inst; xmltw.WriteStartElement("Predicate"); xmltw.WriteAttributeString("name", p.ProcedureName + "/" + p.Arity); for (int j = i + 1; j < arrayList.Count; j++) { AbstractInstruction cinst = (AbstractInstruction)arrayList[j]; WriteXmlInstruction(xmltw, cinst); if (cinst.Name() == "proceed" || cinst.Name() == "execute") { i = j; break; } } xmltw.WriteEndElement(); } else { WriteXmlInstruction(xmltw, inst); } } xmltw.WriteEndElement(); xmltw.WriteEndDocument(); xmltw.Flush(); xmltw.Close(); }