Beispiel #1
0
 public void Insert(BuiltinFunctionSymbol n)
 {
     n.StackLocation = GetStackSize() + 1;
     List<ASTType> param2 = new List<ASTType>();
     foreach (ParameterDeclaration decl in n.Parameters)
         param2.Add(decl.Type);
     dictionary.Add(Tuple.Create(n.Name, param2), n);
 }
 public void TestLookup()
 {
     Table swiftTable = new Table(null, 0, null);
     BuiltinFunctionSymbol printSymbol = new BuiltinFunctionSymbol("print");
     List<ParameterDeclaration> lst = new List<ParameterDeclaration>();
     ParameterDeclaration par = new ParameterDeclaration(null, new Int64Type(), null);
     lst.Add(par);
     printSymbol.Parameters = lst;
     printSymbol.ReturnValue = new TupleType();
     swiftTable.Insert(printSymbol);
     Assert.IsNotNull(swiftTable.Lookup("print", new List<ASTType>() { new Int64Type() }));
 }
 public void visit(BuiltinFunctionSymbol n)
 {
     throw new NotImplementedException();
 }
        public static Table CreateBuiltinSymbols()
        {
            Table swiftTable = new Table(null, Global.Scope.BuiltinScope, "Builtin");
            // print(string)
            BuiltinFunctionSymbol printSymbol = new BuiltinFunctionSymbol("print");
            List<ParameterDeclaration> lst = new List<ParameterDeclaration>();
            ParameterDeclaration par = new ParameterDeclaration(null, new StringType(), null);
            lst.Add(par);
            printSymbol.Parameters = lst;
            printSymbol.ReturnValue = new TupleType();
            printSymbol.OccupiedParamRegisters = 1;
            swiftTable.Insert(printSymbol);

            // print(int8)
            printSymbol = new BuiltinFunctionSymbol("print");
            lst = new List<ParameterDeclaration>();
            par = new ParameterDeclaration(null, new Int8Type(), null);
            lst.Add(par);
            printSymbol.Parameters = lst;
            printSymbol.ReturnValue = new TupleType();
            printSymbol.OccupiedParamRegisters = 1;
            swiftTable.Insert(printSymbol);

            // print(int16)
            printSymbol = new BuiltinFunctionSymbol("print");
            lst = new List<ParameterDeclaration>();
            par = new ParameterDeclaration(null, new Int16Type(), null);
            lst.Add(par);
            printSymbol.Parameters = lst;
            printSymbol.ReturnValue = new TupleType();
            printSymbol.OccupiedParamRegisters = 1;
            swiftTable.Insert(printSymbol);

            // print(int32)
            printSymbol = new BuiltinFunctionSymbol("print");
            lst = new List<ParameterDeclaration>();
            par = new ParameterDeclaration(null, new Int32Type(), null);
            lst.Add(par);
            printSymbol.Parameters = lst;
            printSymbol.ReturnValue = new TupleType();
            printSymbol.OccupiedParamRegisters = 1;
            swiftTable.Insert(printSymbol);

            // print(int64)
            printSymbol = new BuiltinFunctionSymbol("print");
            lst = new List<ParameterDeclaration>();
            par = new ParameterDeclaration(null, new Int64Type(), null);
            lst.Add(par);
            printSymbol.Parameters = lst;
            printSymbol.ReturnValue = new TupleType();
            printSymbol.OccupiedParamRegisters = 1;
            swiftTable.Insert(printSymbol);

            // print(uint8)
            printSymbol = new BuiltinFunctionSymbol("print");
            lst = new List<ParameterDeclaration>();
            par = new ParameterDeclaration(null, new UInt8Type(), null);
            lst.Add(par);
            printSymbol.Parameters = lst;
            printSymbol.ReturnValue = new TupleType();
            printSymbol.OccupiedParamRegisters = 1;
            swiftTable.Insert(printSymbol);

            // print(uint16)
            printSymbol = new BuiltinFunctionSymbol("print");
            lst = new List<ParameterDeclaration>();
            par = new ParameterDeclaration(null, new UInt16Type(), null);
            lst.Add(par);
            printSymbol.Parameters = lst;
            printSymbol.ReturnValue = new TupleType();
            printSymbol.OccupiedParamRegisters = 1;
            swiftTable.Insert(printSymbol);

            // print(uint32)
            printSymbol = new BuiltinFunctionSymbol("print");
            lst = new List<ParameterDeclaration>();
            par = new ParameterDeclaration(null, new UInt32Type(), null);
            lst.Add(par);
            printSymbol.Parameters = lst;
            printSymbol.ReturnValue = new TupleType();
            printSymbol.OccupiedParamRegisters = 1;
            swiftTable.Insert(printSymbol);

            // print(uint64)
            printSymbol = new BuiltinFunctionSymbol("print");
            lst = new List<ParameterDeclaration>();
            par = new ParameterDeclaration(null, new UInt64Type(), null);
            lst.Add(par);
            printSymbol.Parameters = lst;
            printSymbol.ReturnValue = new TupleType();
            printSymbol.OccupiedParamRegisters = 1;
            swiftTable.Insert(printSymbol);

            return swiftTable;
        }
 public ASTType visit(BuiltinFunctionSymbol n)
 {
     return n.ReturnValue;
 }