Ejemplo n.º 1
0
 internal static Symbol PrimitiveName(PrimitiveImplementation impl)
 {
     foreach (var pair in Implementations)
         if (pair.Value == impl)
             return pair.Key;
     return Symbol.Intern("unknown_primitive");
 }
Ejemplo n.º 2
0
        private static void DefinePrimitive(Symbol name, PrimitiveImplementation implementationDelegate,
                                            string manualSections, string docstring, params object[] arglist)
        {
            Implementations[name] = implementationDelegate;
            if (arglist.Length > 0 && (arglist[arglist.Length - 1] as string) == "...")
            {
                MinimumArity[name] = arglist.Length - 2;
                MaximumArity[name] = int.MaxValue;
            }
            else
            {
                MinimumArity[name] = MaximumArity[name] = arglist.Length;
                for (var i = arglist.Length - 1; i >= 0; i--)
                {
                    if (!((string)(arglist[i])).StartsWith("["))
                    {
                        // This is a non-optional parameter
                        MinimumArity[name] = i + 1;
                        break;
                    }
                }
            }

            DelegateUtils.NameProcedure(implementationDelegate, name.Name);
            Manual.AddToSections(manualSections, implementationDelegate);

            for (int i = 0; i < arglist.Length; i++)
                if (arglist[i] is string)
                    arglist[i] = Symbol.Intern((string) arglist[i]);

            DelegateUtils.Arglists[implementationDelegate] = arglist;
            DelegateUtils.Docstrings[implementationDelegate] = docstring;
        }
Ejemplo n.º 3
0
 private static void DefinePrimitive(string name, PrimitiveImplementation implementationDelegate,
                                     string manualSections, string docstring, params object[] arglist)
 {
     Symbol s = Symbol.Intern(name);
     DefinePrimitive(s, implementationDelegate, manualSections, docstring, arglist);
 }
Ejemplo n.º 4
0
 internal static IEnumerable<CutState> StackCall(PrimitiveImplementation primitive, int arity, PrologContext context)
 {
     return primitive(context.GetCallArgumentsAsArray(arity), context);
 }