private void CompileHeadArguments(ArrayList arguments)
{
for (int i = 0; i < arguments.Count; i++)
{
_currArgN = i;
PrologCodeTerm arg = (PrologCodeTerm)arguments[i];
if (arg is PrologCodeNilAtom || arg is PrologCodeEmptyList)
{
_generator.Emit(OpCodes.Get_Constant, "[]", X(i));
}
else if (arg is PrologCodeAtom)
{
if (arg is PrologCodeConstantAtom)
{
_generator.Emit(OpCodes.Get_Constant, ((PrologCodeConstantAtom)arg).Value, X(i));
}
else if (arg is PrologCodeIntegerAtom)
{
_generator.Emit(OpCodes.Get_Constant, ((PrologCodeIntegerAtom)arg).Value.ToString(), X(i));
}
else if (arg is PrologCodeFloatAtom)
{
_generator.Emit(OpCodes.Get_Constant, ((PrologCodeFloatAtom)arg).Value.ToString(), X(i));
}
else if (arg is PrologCodeStringAtom)
{
_generator.Emit(OpCodes.Get_Constant, ((PrologCodeStringAtom)arg).Value, X(i));
}
}
else if (arg is PrologCodeVariable)
{
if (_dictionary.GoalCount == 0)
{
// warning: singleton variable
}
PrologVariableDictionaryEntry entry = _dictionary.GetVariable(((PrologCodeVariable)arg).Name);
if (entry.IsTemporary)
{
if (entry.IsReferenced && entry.TemporaryIndex != i)
{
_generator.Emit(OpCodes.Get_Value, X(entry.TemporaryIndex), X(i));
}
}
else
{
if (entry.IsReferenced)
{
_generator.Emit(OpCodes.Get_Value, Y(entry.PermanentIndex), X(i));
}
else
{
_generator.Emit(OpCodes.Get_Variable, Y(entry.PermanentIndex), X(i));
}
}
}
else if (arg is PrologCodeNonEmptyList)
{
_generator.Emit(OpCodes.Get_List, X(i));
ArrayList listArguments = new ArrayList();
PrologCodeNonEmptyList NEList = (PrologCodeNonEmptyList)arg;
listArguments.Add(NEList.Head);
listArguments.Add(NEList.Tail);
CompileStructArguments(listArguments);
}
else if (arg is PrologCodePredicate)
{
PrologCodePredicate structure = (PrologCodePredicate)arg;
_generator.Emit(OpCodes.Get_Structure, structure.Name + "/" + structure.Arity, X(i));
CompileStructArguments(structure.Arguments);
}
else
{
throw new PrologCompilerException("Unknown argument type (" + arg.GetType().ToString() + ") in head arguments");
}
}
}