private void CompileGoalRecordVariable(PrologCodeVariable var) { PrologVariableDictionaryEntry entry = _dictionary.GetVariable(var.Name); if (entry.IsReferenced) { /* Compile build value here ... */ if (entry.IsTemporary) { if (entry.IsGlobal) { _generator.Emit(OpCodes.Set_Value, X(entry.TemporaryIndex)); } else { _generator.Emit(OpCodes.Set_Local_Value, X(entry.TemporaryIndex)); entry.IsGlobal = true; } } else { if (entry.IsGlobal) { if (entry.TemporaryIndex != -1) { _generator.Emit(OpCodes.Set_Value, X(entry.TemporaryIndex)); } else { _generator.Emit(OpCodes.Set_Value, Y(entry.PermanentIndex)); } } else { if (entry.TemporaryIndex != -1) { _generator.Emit(OpCodes.Set_Local_Value, X(entry.TemporaryIndex)); } else { _generator.Emit(OpCodes.Set_Local_Value, Y(entry.PermanentIndex)); } } } } else { if (entry.IsTemporary) { if (entry.Occurrences == 1) { _generator.Emit(OpCodes.Set_Void, "1"); } else { _generator.Emit(OpCodes.Set_Variable, X(entry.TemporaryIndex)); } } else { _generator.Emit(OpCodes.Set_Variable, Y(entry.PermanentIndex)); } entry.IsGlobal = true; } }
private void CompileGoalVariable(PrologCodeVariable var, int i) { PrologVariableDictionaryEntry entry = _dictionary.GetVariable(var.Name); if (entry.IsTemporary) { if (entry.TemporaryIndex != i) { ResolveConflicts(var, i); } if (entry.IsReferenced) { if (entry.TemporaryIndex != i) { _generator.Emit(OpCodes.Put_Value, X(entry.TemporaryIndex), X(i)); } } else { if (entry.TemporaryIndex != i) { _generator.Emit(OpCodes.Put_Variable, X(entry.TemporaryIndex), X(i)); } else { _generator.Emit(OpCodes.Put_Variable, X(i), X(i)); } entry.IsGlobal = true; } } else { ResolveConflicts(var, i); if (entry.IsReferenced) { if (entry.IsUnsafe && !entry.IsGlobal && _dictionary.InLastGoal) { _generator.Emit(OpCodes.Put_Unsafe_Value, Y(entry.PermanentIndex), X(i)); entry.IsUnsafe = false; } else { if (entry.TemporaryIndex != -1) { _generator.Emit(OpCodes.Put_Value, X(entry.TemporaryIndex), X(i)); } else { _generator.Emit(OpCodes.Put_Value, Y(entry.PermanentIndex), X(i)); } } } else { _generator.Emit(OpCodes.Put_Variable, Y(entry.PermanentIndex), X(i)); } if (entry.TemporaryIndex == -1) { entry.TemporaryIndex = i; } else { // No } } }
public PrologCodeTerm ConvertBinaryTreeToCodeDOM(BinaryTree tree) { // Clause if (tree.Name == ":-") { PrologCodeClause term = new PrologCodeClause(); if (tree.Left != null) { ArrayList goals = new ArrayList(); tree.Flatten(tree.Right, ref goals); foreach (BinaryTree goal in goals) { term.Goals.Add(ConvertGoalBinaryTreeToCodeDOM(goal)); } term.Head = (PrologCodePredicate)ConvertBinaryTreeToCodeDOM(tree.Left); return term; } // Headless clause else { // process headless clause here PrologCodeHeadlessClause hClause = new PrologCodeHeadlessClause(); ArrayList goals = new ArrayList(); tree.Flatten(tree.Right, ref goals); foreach (BinaryTree goal in goals) { hClause.Goals.Add(ConvertGoalBinaryTreeToCodeDOM(goal)); } return hClause; } } else if (tree.Name == ".") { return ConvertBinaryListToCodeDOM(tree); } // Variable else if (Char.IsUpper(tree.Name[0])) { if (tree.Left != null || tree.Right != null) { ParserError("Something was not parsed right. Variable has arity > 0", 0, 0); } PrologCodeVariable var = new PrologCodeVariable(tree.Name); return var; } else { return ConvertGoalBinaryTreeToCodeDOM(tree); } //return null; }