示例#1
0
        private CVar Create_caller(CVar c, VariabelDatabase db, CVar[] stack, EnegyData data, Posision pos)
        {
            if(((StaticMethodVariabel)TypeHandler.ToObjectVariabel(c).get("exists")).call(data, db, stack[0].toString(pos, data, db)).toBoolean(pos, data, db))
            {
                data.setError(new ScriptError("'" + stack[0].toString(pos, data, db) + "' exists and there for can not be createt", pos), db);
                return null;
            }

            FileStream fs;
            StreamWriter f = new StreamWriter((fs = System.IO.File.Create(stack[0].toString(pos, data, db))));

            if(!(stack[1] is NullVariabel))
            {
                try {
                    f.Write(stack[1].toString(pos, data, db));
                }catch(IOException e)
                {
                    fs.Close();
                    f.Close();
                    data.setError(new ScriptError("Write to the new file '" + stack[0].toString(pos, data, db) + "' failed: " + e.Message, pos), db);
                    return null;
                }
            }

            fs.Close();
            f.Close();

            return null;
        }
示例#2
0
        public CVar call(ObjectVariabel obj, VariabelDatabase db, CVar[] stack, EnegyData data, Posision pos)
        {
            //interprenter.setObject(obj);
            Interprenter.parse(new TokenCache(Body, data, db), data, db);

            return data.getReturn();
        }
示例#3
0
        public CVar call(CVar obj, VariabelDatabase db, CVar[] stack, EnegyData data, Posision pos)
        {
            if (obj is ObjectVariabel)
                return call((ObjectVariabel)obj, db, stack, data, pos);

            return call((ClassVariabel)obj, db, stack, data, pos);
        }
示例#4
0
        private void UnsetNext(Token token, EnegyData data, VariabelDatabase db)
        {
            if(token.next().type() != TokenType.Variabel)
            {
                data.setError(new ScriptError("Missing variabel in 'unset' statmenet", token.getCache().posision()), db);
                return;
            }

            //control wee has the variabel in the variabel database.
            if (!db.isExists(token.getCache().ToString()))
            {
                data.setError(new ScriptError("Unknown variabel: " + token.getCache().ToString(), token.getCache().posision()), db);
                return;
            }

            //is this variabel a global.
            if (!db.allowedOveride(token.getCache().ToString()))
            {
                data.setError(new ScriptError("You can not unset the variabel: " + token.getCache().ToString(), token.getCache().posision()), db);
                return;
            }

            //unset the variabel.
            db.removeVariabel(token.getCache().ToString());
        }
示例#5
0
        public CVar parse(EnegyData ed, VariabelDatabase db, Token token)
        {
            if (token.next().type() != TokenType.LeftBue)
                ed.setError(new ScriptError("Missing ( after while", token.getCache().posision()), db);

            TokenCache scope = ScopeParser.getScope(token, ed, db);
            ArrayList body = BodyParser.parse(token, ed, db);
            token.next();

            //run the code until a boolean false i hit :)
            while (ed.State == RunningState.Normal && new VariabelParser().parseNoEnd(ed, db, scope).toBoolean(new Posision(0, 0), ed, db))
            {
                Interprenter.parse(new TokenCache(body, ed, db), ed, db);
                if(ed.State == RunningState.Continue)
                {
                    ed.setNormal();
                }else if(ed.State == RunningState.Break)
                {
                    ed.setNormal();
                    break;
                }
            }

            return new NullVariabel();
        }
示例#6
0
        public override CVar call(EnegyData data, VariabelDatabase db, params object[] parameters)
        {
            CVar[] stack = new CVar[method.Agument.size()];
            VariabelDatabase vd = getShadowVariabelDatabase(db);

            for (int i = 0; i < parameters.Length && i <= method.Agument.size(); i++)
            {
                CVar context = ScriptConverter.convert(parameters[i], data, db);
                if (method.Agument.get(i).hasType() && !TypeHandler.controlType(context, method.Agument.get(i).Type))
                {
                    data.setError(new ScriptError("Cant convert " + context.type() + " to " + method.Agument.get(i).Type.ToString(), new Posision(0, 0)), db);
                }

                //okay let cache the parameters :)
                stack[0] = context;
                if(SetVariabel)
                    vd.push(method.Agument.get(i).Name, stack[0], data);
            }

            //wee take a new for loop to get other parameters there is not has been set :)
            for (int i = stack.Length; i < method.Agument.size(); i++)
            {
                if (!method.Agument.get(i).hasValue())
                {
                    data.setError(new ScriptError("Missing agument to " + method.Name, new Posision(0, 0)), db);
                    return new NullVariabel();
                }

                stack[i] = method.Agument.get(i).Value;
                if(SetVariabel)
                    vd.push(method.Agument.get(i).Name, method.Agument.get(i).Value, data);
            }

            return call(stack, db, data, new Posision(0,0));
        }
示例#7
0
        public ArrayVariabel(EnegyData data, VariabelDatabase db, Posision pos)
            : base(new ClassVariabel(new Class()), new Dictionary<string, PointerContainer>(), new Dictionary<string, MethodContainer>(), null, new System.Collections.ArrayList())
        {
            Class c = new Class("array");

            Method length = new Method("length");
            length.SetBody(Length_caller);
            c.SetMethod(length, data, db, pos);

            Method hasValue = new Method("hasValue");
            hasValue.GetAgumentStack().push("context");
            hasValue.SetBody(HasValue_caller);
            c.SetMethod(hasValue, data, db, pos);

            Method hasKey = new Method("hasKey");
            hasKey.GetAgumentStack().push("string", "context");
            hasKey.SetBody(HasKey_caller);
            c.SetMethod(hasKey, data, db, pos);

            Method removeKey = new Method("removeKey");
            removeKey.GetAgumentStack().push("string", "key");
            removeKey.SetBody(RemoveKey_caller);
            c.SetMethod(removeKey, data, db, pos);

            Method removeValue = new Method("removeValue");
            removeValue.GetAgumentStack().push("value");
            removeValue.SetBody(RemoveValue_caller);
            c.SetMethod(removeValue, data, db, pos);

            ClassVariabel i = new ClassVariabel(c);
            ObjectVariabel o = i.createNew(db, data, new CVar[0], pos);
            Items = o.Items;
        }
示例#8
0
        public override CVar call(CVar[] call, VariabelDatabase db, EnegyData data, Posision pos)
        {
            if(extraVariabelDatabase != null)
            {
                db = getShadowVariabelDatabase(extraVariabelDatabase);
                if (SetVariabel)
                {
                    for (int i = 0; i < method.Agument.size(); i++)
                        db.push(method.Agument.get(i).Name, call[i], data);
                }
            }

            CVar cache = method.Body(obj, db, call, data, pos);
            db.garbageCollector();
            if(method.ReturnType != null)
            {
                if(!TypeHandler.controlType(cache, method.ReturnType))
                {
                    data.setError(new ScriptError("a method '" + obj.Name + "->"+method.Name+"' returns can not be convertet to '" + method.ReturnType + "'", pos), db);
                    return new NullVariabel();
                }
            }

            return cache;
        }
示例#9
0
 public MethodVariabel(MethodContainer method, ObjectVariabel obj, VariabelDatabase extra)
     : base(null)
 {
     this.method = method;
     this.obj = obj;
     extraVariabelDatabase = extra;
 }
示例#10
0
        private CVar Type_call(CVar[] stack, VariabelDatabase db, EnegyData data, Posision pos)
        {
            if (stack[0] is ObjectVariabel && stack[1].toString(pos, data, db) == ((ObjectVariabel)stack[0]).Name)
                return new BooleanVariabel(true);

            return new BooleanVariabel(stack[0].type() == stack[1].toString(pos, data, db));
        }
示例#11
0
        public void open(VariabelDatabase database, EnegyData data, Posision pos)
        {
            Class config = new Class("Config");

            Method get = new Method("get");
            get.GetAgumentStack().push("string", "name");
            get.SetBody(Get_caller);
            get.SetStatic();
            config.SetMethod(get, data, database, pos);

            Method isScriptLock = new Method("isScriptLock");
            isScriptLock.SetBody(IsScriptLock_caller);
            isScriptLock.SetStatic();
            config.SetMethod(isScriptLock, data, database, pos);

            Method set = new Method("set");
            set.GetAgumentStack().push("string", "name");
            set.GetAgumentStack().push("string", "value");
            set.SetBody(Set_caller);
            set.SetStatic();
            config.SetMethod(set, data, database, pos);

            Method isLocked = new Method("isLocked");
            isLocked.SetStatic();
            isLocked.GetAgumentStack().push("string", "name");
            isLocked.SetBody(IsLocked_caller);
            config.SetMethod(isLocked, data, database, pos);

            database.pushClass(config, data);
        }
示例#12
0
        public virtual CVar call(CVar[] call, VariabelDatabase db, EnegyData data, Posision pos)
        {
            if(func.extraVariabelDatabase != null)
            {
                db = func.extraVariabelDatabase.createShadow();
                if (SetVariabel)
                {
                    for (int i = 0; i < func.agument.size(); i++)
                        db.push(func.agument.get(i).Name, call[i], data);
                }
            }

            CVar r = func.callFunction(call, db, data, pos);
            db.garbageCollector();
            if(func.ReturnType != null)
            {
                //this function is lock to a type :)
                if (r == null)
                    r = new NullVariabel();

                if(!TypeHandler.controlType(r, func.ReturnType))
                {
                    data.setError(new ScriptError("a function '"+func.Name+"' returns can not be convertet to '" + func.ReturnType + "'", pos), db);
                    return new NullVariabel();
                }
            }

            if (r == null)
                return new NullVariabel();

            return r;
        }
示例#13
0
 public StaticMethodVariabel(MethodContainer m, ClassVariabel c, VariabelDatabase extra)
     : base(null, null, extra)
 {
     method = m;
     this.c = c;
     this.extra = extra;
 }
示例#14
0
        public override VariabelDatabase getShadowVariabelDatabase(VariabelDatabase db)
        {
            if (extra != null)
                return extra.createShadow(c);

            return db.createShadow(c);
        }
示例#15
0
        public static TokenCache getScope(Token token, EnegyData data, VariabelDatabase db)
        {
            ArrayList cache = new ArrayList();
            TokenBuffer buffer;

            int happens = 1;

            while((buffer = token.next()).type() != TokenType.EOF)
            {
                if (buffer.type() == TokenType.RightBue)
                {
                    happens--;
                    if (happens == 0)
                        return new TokenCache(cache, data, db);

                    cache.Add(buffer);
                    continue;
                }
                else if (buffer.type() == TokenType.LeftBue)
                    happens++;

                cache.Add(buffer);
            }

            data.setError(new ScriptError("Missing ) ", token.getCache().posision()), db);
            return new TokenCache(new ArrayList(), data, db);
        }
示例#16
0
 public void open(VariabelDatabase database, EnegyData data, Posision pos)
 {
     Function version = new Function();
     version.Name = "version";
     version.call += Version_call;
     database.pushFunction(version, data);
 }
示例#17
0
        public static AgumentStack parseAguments(Token token, VariabelDatabase database, EnegyData data)
        {
            hasDefault = false;//be sure :)
            AgumentStack agument = new AgumentStack();
            if(token.getCache().type() != TokenType.LeftBue)
            {
                data.setError(new ScriptError("Excpect ( got: " + token.getCache().ToString(), token.getCache().posision()), database);
                return null;
            }

            //control if wee need to look and parse aguments :)
            if(token.next().type() != TokenType.RightBue)
            {
                //wee need :)
                if (!getSingleAguments(token, agument, database, data))
                    return new AgumentStack();
                while(token.getCache().type() == TokenType.Comma)
                {
                    token.next();
                    if (!getSingleAguments(token, agument, database, data))
                        return new AgumentStack();
                }
            }

            //control wee got to )
            if(token.getCache().type() != TokenType.RightBue)
            {
                data.setError(new ScriptError("Missing ) after function aguments got: " + token.getCache().ToString(), token.getCache().posision()), database);
                return new AgumentStack();
            }

            return agument;
        }
示例#18
0
        public ObjectVariabel(ClassVariabel c, Dictionary<string, PointerContainer> pointer, Dictionary<string, MethodContainer> Method, VariabelDatabase extra, ArrayList Extends)
        {
            owner = c;
            Items = new ClassItemContainer[pointer.Count + Method.Count];
            int i = 0;

            foreach(PointerContainer p in pointer.Values)
            {
                Items[i] = new ClassItemContainer()
                {
                    Name = p.Name,
                    Context = p.DefaultValue,
                    IsPointer = true,
                    Level = p.Level,
                };
                i++;
            }

            foreach(MethodContainer m in Method.Values)
            {
                Items[i] = new ClassItemContainer()
                {
                    Name = m.Name,
                    Context = new MethodVariabel(m, this, extra),
                    IsPointer = false,
                    Level = m.Level,
                };
                i++;
            }

            AppendExtends(extra);
        }
示例#19
0
        private static void createIntClass(EnegyData data, VariabelDatabase db, Posision pos)
        {
            Class i = new Class("int");

            Method constructor = new Method(null);
            constructor.GetAgumentStack().push("int", "double", new NullVariabel());
            constructor.SetBody(Constructor_caller1);
            i.SetConstructor(constructor, data, db, pos);

            Method toInt = new Method("toInt");
            toInt.SetBody(ToInt_caller);
            i.SetMethod(toInt, data, db, pos);

            Method toString = new Method("toString");
            toString.SetBody(ToString_caller1);
            i.SetMethod(toString, data, db, pos);

            Method convert = new Method("convert");
            convert.SetStatic();
            convert.GetAgumentStack().push("string", "int");
            convert.SetBody(Convert_caller);
            i.SetMethod(convert, data, db, pos);

            db.pushClass(i, data);
        }
示例#20
0
 public CVar parse(EnegyData ed, VariabelDatabase db, Token token)
 {
     this.token = token;
     this.ed = ed;
     this.db = db;
     begin(false);
     return null;
 }
示例#21
0
        public CVar callFunction(CVar[] stack, VariabelDatabase db, EnegyData data, Posision pos)
        {
            if (call == null)
            {
                return new NullVariabel();
            }

            return call(stack, db, data, pos);
        }
示例#22
0
        private void parseFile(EnegyData ed, VariabelDatabase db, Posision pos, string plugin)
        {
            if (!File.Exists(plugin))
            {
                ed.setError(new ScriptError("Unknown file: " + plugin, pos), db);
                return;
            }

            FileEnergy.parse(ed, new FileVariabelDatabase(db), plugin);
        }
示例#23
0
        public void SetConstructor(Method method, EnegyData data, VariabelDatabase db, Posision pos)
        {
            if(container.Constructor != null)
            {
                data.setError(new ScriptError("A class can only have one constructor", pos), db);
                return;
            }

            container.Constructor = method.GetMethodContainer();
        }
示例#24
0
        public CVar get(CVar key, Posision pos, EnegyData data, VariabelDatabase db)
        {
            if (!keyExists(key, pos, data, db))
            {
                data.setError(new ScriptError("Unknown key in array: " + key.toString(pos, data, db), pos), db);
                return new NullVariabel();
            }

            return container[key.toString(pos, data, db)];
        }
示例#25
0
        public void SetPointer(Pointer pointer, EnegyData data, VariabelDatabase db, Posision pos)
        {
            PointerContainer pc = pointer.GetPointerContainer();

            Control(pc.Name, data, db, pos);//control if the class contains the name already

            if (pc.IsStatic)
                container.StaticPointer.Add(pc.Name, pc);
            else
                container.Pointer.Add(pc.Name, pc);
        }
示例#26
0
        private CVar ToInt_call(CVar[] stack, VariabelDatabase db, EnegyData data, Posision pos)
        {
            double result;
            if (!double.TryParse(stack[0].toString(pos, data, db), out result))
            {
                data.setError(new ScriptError(stack[0].toString(pos, data, db) + " could not be convertet to int", new Posision(0, 0)), db);
                return new NullVariabel();
            }

            return Types.toInt(result, data, db, pos);
        }
示例#27
0
        private static CVar Convert_caller(CVar c, VariabelDatabase db, CVar[] stack, EnegyData data, Posision pos)
        {
            double number;

            if (double.TryParse(stack[0].toString(pos, data, db), out number))
            {
                return Types.toInt(number, data, db, pos);
            }

            return Types.toInt(0, data, db, pos);
        }
示例#28
0
        private CVar Get_caller(CVar c, VariabelDatabase db, CVar[] stack, EnegyData data, Posision pos)
        {
            string name = stack[0].toString(pos, data, db);

            if (!data.Config.exists(name))
            {
                data.setError(new ScriptError("Unknown config name: " + name, pos), db);
                return new NullVariabel();
            }

            return Types.toString(data.Config.get(name, ""), data, db, pos);
        }
示例#29
0
        private CVar IsLocked_caller(CVar c, VariabelDatabase db, CVar[] stack, EnegyData data, Posision pos)
        {
            string name = stack[0].toString(pos, data, db);

            if (!data.Config.exists(name))
            {
                data.setError(new ScriptError("Unknown config: " + name, pos), db);
                return new BooleanVariabel(false);
            }

            return new BooleanVariabel(data.Config.isAllowedOverride(name));
        }
示例#30
0
        private CVar HasValue_call(CVar[] stack, VariabelDatabase db, EnegyData data, Posision pos)
        {
            ArrayVariabel array = (ArrayVariabel)stack[0];

            foreach (string key in array.Keys())
            {
                if (array.get(key, pos, data, db).compare(stack[1], pos, data, db))
                    return new BooleanVariabel(true);
            }

            return new BooleanVariabel(false);
        }
示例#31
0
        private static CVar Useage_call(CVar[] stack, VariabelDatabase db, EnegyData data, Posision pos)
        {
            Console.WriteLine("----container----");
            foreach (string co in db.ContainerKeys())
            {
                Console.WriteLine("-" + co);
            }

            Console.WriteLine("------Global-----");
            foreach (string go in db.GlobalsKey())
            {
                Console.WriteLine("-" + go);
            }

            return(new NullVariabel());
        }
示例#32
0
 private static CVar Print_call(CVar[] stack, VariabelDatabase db, EnegyData data, Posision pos)
 {
     Console.WriteLine(stack[0].toString(pos, data, db));
     return(null);
 }