コード例 #1
0
ファイル: CallInfo.cs プロジェクト: awesomedotnetcore/Andl
 // load up all the methods and index by name
 static void Init(BuiltinInfo[] builtins)
 {
     foreach (var builtin in builtins)
     {
         _callables[builtin.Name] = CallInfo.Create(builtin.Name, builtin.ReturnType, builtin.Arguments);
     }
 }
コード例 #2
0
ファイル: SymbolTable.cs プロジェクト: awesomedotnetcore/Andl
        ///-------------------------------------------------------------------

        // Make symbols that can be user-defined
        internal static Symbol MakeUserType(string name, DataTypeUser datatype)
        {
            var callinfo = CallInfo.Create(name, datatype, datatype.Heading.Columns.ToArray());

            return(new Symbol {
                Name = name,
                Kind = SymKinds.SELECTOR,
                CallKind = CallKinds.SFUNC,
                NumArgs = callinfo.NumArgs,
                DataType = datatype,
                CallInfo = callinfo,
            });
        }
コード例 #3
0
ファイル: SymbolTable.cs プロジェクト: awesomedotnetcore/Andl
        // Create a symbol for a defined function
        public static Symbol MakeDeffun(string name, DataType datatype, DataColumn[] args, int accums, bool mutable = false)
        {
            Symbol sym = new Symbol {
                Name     = name,
                Kind     = SymKinds.CATVAR,
                DataType = datatype,
                CallKind = CallKinds.EFUNC,
                CallInfo = CallInfo.Create(name, datatype, args, accums),
                NumArgs  = args?.Length ?? 0,
                Mutable  = mutable,
            };

            return(sym);
        }
コード例 #4
0
ファイル: SymbolTable.cs プロジェクト: awesomedotnetcore/Andl
        // Add an overload. Give it a unique name
        // return false if duplicate list of types, cannot add
        public bool AddOverload(Symbol sym, DataType rettype, DataColumn[] argtypes)
        {
            Logger.Assert(!sym.IsArgLess, sym);
            var nover = 0;

            for (var ci = sym.CallInfo; ci != null; ci = ci.OverLoad, nover++)
            {
                if (argtypes.Length == ci.NumArgs &&
                    Enumerable.Range(0, argtypes.Length)
                    .Select(x => argtypes[x].DataType == ci.Arguments[x].DataType)
                    .All(b => b))
                {
                    return(false);
                }
            }
            var callinfo = CallInfo.Create($"{sym.Name}{_overload_delimiter}{nover}", rettype, argtypes, 0, sym.CallInfo);

            sym.CallInfo = callinfo;
            if (sym.NumArgs < callinfo.NumArgs)
            {
                sym.NumArgs = callinfo.NumArgs;
            }
            return(true);
        }