public void Intern(string varname, object value) { PlTerm termin = PlTerm.PlVar(); termin.FromObject(value); ModuleCall("Intern", PlNamed(varname), termin); }
public static bool cliToStrRaw(PlTerm obj, PlTerm str) { try { if (!str.IsVar) { var plvar = PlTerm.PlVar(); return(cliToStrRaw(obj, plvar) && SpecialUnify(str, plvar)); } if (obj.IsString) { return(str.Unify(obj)); } if (obj.IsVar) { return(str.Unify((string)obj)); } object o = GetInstance(obj); if (o == null) { return(str.FromObject("" + obj)); } return(str.FromObject(ToString(o))); } catch (Exception e) { Warn("cliToString: {0}", e); object o = GetInstance(obj); if (o == null) { return(str.FromObject("" + obj)); } return(str.FromObject(ToString(o))); } }
static public bool cliJavaToString(PlTerm paramIn, PlTerm valueOut) { if (!valueOut.IsVar) { var plvar = PlTerm.PlVar(); return(cliJavaToString(paramIn, plvar) && SpecialUnify(valueOut, plvar)); } object getInstance = GetInstance(paramIn); if (getInstance == null) { return(valueOut.Unify(PlTerm.PlString("null"))); } #if USE_IKVM object val = getInstance as java.lang.Object; if (val == null) { Class c = ikvm.runtime.Util.getClassFromObject(getInstance); string s = (string)c.getMethod("toString", new Class[0]).invoke(getInstance, ZERO_OBJECTS); return(valueOut.Unify(PlTerm.PlString(s))); } return(valueOut.Unify(PlTerm.PlString(val.toString()))); #else object val = getInstance; return(valueOut.Unify(PlTerm.PlString(val.ToString()))); #endif }
public static PlTerm ToProlog(object value) { PlTerm t = PlTerm.PlVar(); t.FromObject(value); return(t); }
public object GetSymbol(string name) { PlTerm termout = PlTerm.PlVar(); if (!ModuleCall("GetSymbol", PlNamed(name), termout)) { return(null); } return(PrologCLR.CastTerm(termout, typeof(System.Object))); }
public static bool IsDefined(string module, string functor, int arity) { if (!ClientReady) { return(false); } return(InvokeFromC(() => PlQuery.PlCall(null, "predicate_property", new PlTermV( ModuleTerm(module, FunctorTerm(functor, arity)), PlTerm.PlVar())), true)); }
static public bool cliTypeToFullname(PlTerm valueIn, PlTerm valueOut) { if (!valueOut.IsVar) { var plvar = PlTerm.PlVar(); return(cliTypeToFullname(valueIn, plvar) && SpecialUnify(valueOut, plvar)); } Type val = CastTerm(valueIn, typeof(Type)) as Type; if (val == null) { return(false); } return(valueOut.Unify(val.FullName)); }
static public bool cliGetClass(PlTerm valueIn, PlTerm valueOut) { if (!valueOut.IsVar) { var plvar = PlTerm.PlVar(); return(cliGetClass(valueIn, plvar) && SpecialUnify(valueOut, plvar)); } object val = GetInstance(valueIn); // extension method #if USE_IKVM return(valueOut.FromObject((val.getClass()))); #else return(valueOut.FromObject((val.GetType()))); #endif }
static public bool cliGetType(PlTerm valueIn, PlTerm valueOut) { if (!valueOut.IsVar) { var plvar = PlTerm.PlVar(); return(cliGetType(valueIn, plvar) && SpecialUnify(valueOut, plvar)); } object val = GetInstance(valueIn); if (val == null) { Error("Cannot get object for {0}", valueIn); return(true); } return(valueOut.FromObject((val.GetType()))); }
static public bool cliCastImmediate(PlTerm valueIn, PlTerm clazzSpec, PlTerm valueOut) { if (valueIn.IsVar) { return(Warn("Cant find instance {0}", valueIn)); } if (!valueOut.IsVar) { var plvar = PlTerm.PlVar(); return(cliCastImmediate(valueIn, clazzSpec, plvar) && SpecialUnify(valueOut, plvar)); } Type type = GetType(clazzSpec); object retval = CastTerm(valueIn, type); return(valueOut.FromObject(retval)); }
public static bool cliNewArray(PlTerm clazzSpec, PlTerm indexes, PlTerm valueOut) { if (!valueOut.IsVar) { var plvar = PlTerm.PlVar(); return(cliNewArray(clazzSpec, indexes, plvar) && SpecialUnify(valueOut, plvar)); } Type c = GetType(clazzSpec); if (c == null) { Warn("Cant find type {0}", clazzSpec); return(false); } var dims = ToTermArray(indexes); var arrayType = c.MakeArrayType(dims.Length); var value = CreateArrayOfType(dims, c); return(UnifyTagged(value, valueOut)); }
static public bool cliTypeFromClass(PlTerm valueIn, PlTerm valueOut) { if (!valueOut.IsVar) { var plvar = PlTerm.PlVar(); return(cliTypeFromClass(valueIn, plvar) && SpecialUnify(valueOut, plvar)); } Type val = GetType(valueIn); if (val == null) { return(false); } #if USE_IKVM Type c = ikvm.runtime.Util.getInstanceTypeFromClass(val); return(valueOut.FromObject((c))); #else return(valueOut.FromObject(val)); #endif }
static public bool cliGetClassname(PlTerm valueIn, PlTerm valueOut) { if (!valueOut.IsVar) { var plvar = PlTerm.PlVar(); return(cliGetClassname(valueIn, plvar) && SpecialUnify(valueOut, plvar)); } Type val = CastTerm(valueIn, typeof(Type)) as Type; if (val == null) { return(false); } #if USE_IKVM return(valueOut.Unify(val.getName())); #else return(valueOut.Unify(val.GetType().Name)); #endif }
public object Eval(object obj) { PlTerm termin = PlTerm.PlVar(); if (obj is PlTerm) { termin.Unify((PlTerm)obj); } else { termin.FromObject(obj); } PlTerm termout = PlTerm.PlVar(); if (!ModuleCall("Eval", termin, termout)) { return(null); } return(PrologCLR.CastTerm(termout, typeof(System.Object))); }
static public bool cliCast(PlTerm valueIn, PlTerm clazzSpec, PlTerm valueOut) { if (!valueOut.IsVar) { var plvar = PlTerm.PlVar(); return(cliCast(valueIn, clazzSpec, plvar) && SpecialUnify(valueOut, plvar)); } Type type = GetType(clazzSpec); if (type == null) { return(Error("Cant find class {0}", clazzSpec)); } if (valueIn.IsVar) { return(Error("Cant find instance {0}", valueIn)); } object retval = CastTerm(valueIn, type); return(UnifyTagged(retval, valueOut)); }
public static bool cliArrayToTerm(PlTerm arrayValue, PlTerm valueOut) { if (!valueOut.IsVar) { var plvar = PlTerm.PlVar(); return(cliArrayToTerm(arrayValue, plvar) && SpecialUnify(valueOut, plvar)); } object getInstance = GetInstance(arrayValue); if (getInstance == null) { return(valueOut.Unify(PLNULL)); } Array value = GetArrayValue(getInstance); if (value == null) { Error("Cant find array from {0} as {1}", arrayValue, getInstance.GetType()); return(false); } return(unifyArrayToTerm(value, valueOut)); }
public static bool cliTermToArray(PlTerm arrayValue, PlTerm valueOut) { if (!valueOut.IsVar) { var plvar = PlTerm.PlVar(); return(cliTermToArray(arrayValue, plvar) && SpecialUnify(valueOut, plvar)); } if (arrayValue.Name == "array") { return(valueOut.FromObject(GetInstance(arrayValue))); } Type elementType = ResolveType(arrayValue.Name); if (elementType == null) { Error("Cant find vector from {0}", arrayValue); return(false); } var value = CreateArrayOfTypeRankOneFilled(arrayValue, elementType.MakeArrayType()); return(valueOut.FromObject((value))); }
public static bool cliArrayToTermlist(PlTerm arrayValue, PlTerm valueOut) { if (!valueOut.IsVar) { var plvar = PlTerm.PlVar(); return(cliArrayToTermlist(arrayValue, plvar) && SpecialUnify(valueOut, plvar)); } object getInstance = GetInstance(arrayValue); if (getInstance == null) { return(valueOut.Unify(PLNULL)); } Array value = GetArrayValue(getInstance); if (value == null) { Error("Cant find array from {0} as {1}", arrayValue, getInstance.GetType()); return(false); } Type arrayType = value.GetType(); if (arrayType.GetArrayRank() != 1) { Error("Non rank==1 " + arrayType); } int len = value.Length; var termv = ATOM_NIL; for (int i = len - 1; i >= 0; i--) { termv = PlC(".", ToProlog((value.GetValue(i))), termv); } //Type et = value.GetType().GetElementType(); return(valueOut.Unify(termv)); }
static public bool cliGetterm(PlTerm valueCol, PlTerm valueIn, PlTerm valueOut) { List <object> objs; if (valueCol.IsVar) { objs = new List <object>(); valueCol.FromObject(objs); } else { objs = (List <object>)CastTerm(valueCol, typeof(ICollection)); } if (!valueOut.IsVar) { var plvar = PlTerm.PlVar(); return(cliGetterm(valueCol, valueIn, plvar) && SpecialUnify(valueOut, plvar)); } if (IsTaggedObject(valueIn)) { object val = GetInstance(valueIn); int index = objs.IndexOf(val); if (index < 0) { index = objs.Count; objs.Add(val); var type = val.GetType(); if (type.IsArray) { return(valueIn.Unify(valueOut)); } return(ToFieldLayout("object", typeToName(type), val, type, valueOut, false, false) != libpl.PL_fail); } } return(valueIn.Unify(valueOut)); }