示例#1
0
 public COOPFunction(string name, COOPClass returnType, Dictionary <string, COOPClass> varNames)
 {
     this.name       = name;
     this.inputTypes = new List <COOPClass>(varNames.Values);
     this.varNames   = varNames;
     this.ReturnType = returnType;
     hasReturnType   = true;
 }
示例#2
0
 public COOPArray(COOPClass baseClass, uint length) : base(baseClass.Name + "_array", Base, new Collection <COOPFunction> {
     bracketOperator(baseClass), getFunction(baseClass)
 }, new Dictionary <string, COOPClass>())
 {
     this.baseClass = baseClass;
     this.length    = length;
     Functions["operator []"].AccessLevel = AccessLevel.Public;
     Functions["get"].AccessLevel         = AccessLevel.Public;
 }
示例#3
0
 public COOPClass(string name, COOPClass parent, Dictionary <string, COOPFunction> functions, Dictionary <string, COOPClass> varNames)
 {
     this.name      = name;
     this.parent    = parent;
     this.functions = functions;
     this.varNames  = varNames;
     foreach (COOPFunction functionsValue in functions.Values)
     {
         functionsValue.owner = this;
     }
 }
示例#4
0
 public COOPClass(string name, COOPClass parent, Collection <COOPFunction> functions, Dictionary <string, COOPClass> varNames)
 {
     this.name      = name;
     this.parent    = parent;
     this.functions = new Dictionary <string, COOPFunction>();
     foreach (COOPFunction coopFunction in functions)
     {
         coopFunction.owner = this;
         this.functions.Add(coopFunction.Name, coopFunction);
     }
     this.varNames = varNames;
 }
示例#5
0
        static COOPClass()
        {
            COOPFunction init = new COOPFunction("__init__", Base);

            Void = new PrimitiveCOOPClass("void");
            Base = new COOPClass("Object", null,
                                 new Collection <COOPFunction>
            {
                init,
                new COOPFunction("ToString", String),
                new COOPFunction("Print", Void),
                new COOPFunction("PrintLn", Void)
            },
                                 new Dictionary <string, COOPClass>()
                                 );
            Base.functions["ToString"].AccessLevel = AccessLevel.Public;
            Base.functions["ToString"].Body        = "return &{.ptr=char[2]{&this, 0}};";
            Base.functions["ToString"].bodyInC     = true;
            Base.functions["Print"].AccessLevel    = AccessLevel.Public;
            Base.functions["Print"].Body           = "ToString().Print()";
            Base.functions["PrintLn"].AccessLevel  = AccessLevel.Public;
            Base.functions["PrintLn"].Body         = "ToString().PrintLn()";
            Base.functions["__init__"].Body        = "";
            Base.functions["__init__"].AccessLevel = AccessLevel.Public;
            Base.functions["__init__"].ReturnType  = Base;

            CharPtr = new PrimitiveCOOPClass("char*");
            String  = new COOPClass("String", Base,
                                    new Collection <COOPFunction> (),
                                    new Dictionary <string, COOPClass> {
                { "ptr", CharPtr }
            }
                                    );
            String.functions.Add("Print", new COOPFunction("Print", Void));
            String.functions.Add("PrintLn", new COOPFunction("PrintLn", Void));
            String.functions.Add("ToString", new COOPFunction("ToString", String));

            String.addNonDefualtAccessLevel("ptr", AccessLevel.Protected);
            String.functions["ToString"].AccessLevel = AccessLevel.Public;
            String.functions["ToString"].owner       = String;
            String.functions["ToString"].Body        = "return this;";
            String.functions["Print"].AccessLevel    = AccessLevel.Public;
            String.functions["Print"].owner          = String;
            String.functions["Print"].bodyInC        = true;
            String.functions["Print"].Body           = "\tprintf(\"%s\", __this->ptr);";
            String.functions["PrintLn"].AccessLevel  = AccessLevel.Public;
            String.functions["PrintLn"].owner        = String;
            String.functions["PrintLn"].bodyInC      = true;
            String.functions["PrintLn"].Body         = "\tprintf(\"%s\\n\", __this->ptr);";

            Base.functions["ToString"].ReturnType = String;
        }
示例#6
0
 public COOPFunction(string name, COOPClass returnType, List <KeyValuePair <string, COOPClass> > vars = null)
 {
     this.name       = name;
     this.ReturnType = returnType;
     hasReturnType   = true;
     inputTypes      = new List <COOPClass>();
     varNames        = new Dictionary <string, COOPClass>();
     if (vars != null)
     {
         foreach (var keyValuePair in vars)
         {
             inputTypes.Add(keyValuePair.Value);
             varNames.Add(keyValuePair.Key, keyValuePair.Value);
         }
     }
 }
示例#7
0
 protected bool Equals(COOPClass other)
 {
     return(string.Equals(name, other.name));
 }
示例#8
0
 public void addImports(COOPClass coopClass)
 {
     imports.Add(coopClass);
 }
示例#9
0
 private static COOPFunction getFunction(COOPClass baseClass)
 {
     return(new COOPFunction("get", baseClass, new Dictionary <string, COOPClass> {
         { "index", COOPPrimitives.integer }
     }));
 }
示例#10
0
 private static COOPFunction bracketOperator(COOPClass baseClass)
 {
     return(new COOPFunction("operator []", baseClass, new List <COOPClass> {
         COOPPrimitives.uinteger
     }, new Dictionary <string, COOPClass>()));
 }