Exemplo n.º 1
0
        public static void InitFusion( )
        {
            MainVM = new ManagedHost( );

            ScriptSource   init_ide_src      = new ScriptSource("data/script/ide/ide_init.vs");
            Compiler       comp              = new Compiler();
            CompiledSource init_ide_compiled = comp.Compile(init_ide_src);

            MainVM.SetEntry(init_ide_compiled.EntryPoint);

            void InitIDE(int w, int h, int fs)
            {
                App       = new FusionIDE(w, h, fs == 1);
                InitState = new States.CodeScreen();

                App.Run();
            }

            CFuncLink initIDE = new CFuncLink
            {
                Link = (t) =>
                {
                    InitIDE(t[0], t[1], t[2]);
                    return(null);
                }
            };

            MainVM.AddCFunc("InitIDE", initIDE);
            CodeScope scope = MainVM.RunEntry( );
        }
Exemplo n.º 2
0
        public GameScript(string path)
        {
            if (Host == null)
            {
                Host = new ManagedHost();
            }

            var src      = new ScriptSource(path);
            var compiler = new Compiler();
            var com_src  = compiler.Compile(src);

            Host.SetEntry(com_src.EntryPoint);
        }
Exemplo n.º 3
0
        private static void Main(string [] args)
        {
            ScriptSource   src  = new ScriptSource("test1.vs");
            Compiler       comp = new Compiler();
            CompiledSource s    = comp.Compile(src);



            ManagedHost test_vme = new ManagedHost();

            test_vme.AddModule(new Module(s.EntryPoint));



            System.Console.WriteLine("R:" + test_vme.ExecuteStaticFunc("test"));



            while (true)
            {
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            ScriptSource   src  = new ScriptSource("Foom/main.fs");
            Compiler       comp = new Compiler();
            CompiledSource s    = comp.Compile(src);



            ManagedHost test_vme = new ManagedHost();

            test_vme.AddModule(new Module(s.EntryPoint));

            InvaderAPP Foom = null;

            dynamic F_InitFoom(dynamic[] pars)
            {
                Console.WriteLine("Foom booting up.");

                Foom = new InvaderAPP();

                return(null);
            }

            var InitFoom = new CFuncLink
            {
                Link = F_InitFoom,
                Name = "InitFoom"
            };

            test_vme.RegFunc("InitFoom", InitFoom);


            System.Console.WriteLine("R:" + test_vme.ExecuteStaticFunc("Entry"));

            while (true)
            {
            }
        }
Exemplo n.º 5
0
        public void ToRPNFloat(List <StructExpr> exp)
        {
            Output.Clear();
            dynamic av = null;

            for (int i = 0; i < exp.Count; i++)
            {
                switch (exp[i].Type)
                {
                case ExprType.ClassVar:

                    dynamic basev = null;
                    foreach (var cve in exp[i].Expr)
                    {
                        if (basev == null)
                        {
                            basev = ManagedHost.CurrentScope.FindVar(cve.VarName, true);
                            if (basev == null)
                            {
                                Console.WriteLine("No var:" + cve.VarName);
                                while (true)
                                {
                                }
                            }
                        }
                        else
                        {
                            basev = basev.Value.FindVar(cve.VarName);
                        }
                    }

                    var cv = new StructExpr();
                    cv.floatV = basev.Value;
                    Output.Add(cv);

                    break;

                case ExprType.VarValue:
                    try
                    {
                        if (av == null)
                        {
                            av = ManagedHost.CurrentScope.FindVar(exp[i].VarName, true);
                            if (av.Value is StructModule || av.Value is Module)
                            {
                            }
                            else
                            {
                                var nnn = new StructExpr();
                                nnn.floatV = av.Value;
                                Output.Add(nnn);
                            }
                        }
                        else
                        {
                            if (av.Value is Module)
                            {
                                if (av.Value.CMod != null)
                                {
                                    if (av.Value.CMod.HasStaticVar(exp[i].VarName))
                                    {
                                        av = av.Value.CMod.GetStaticValue(exp[i].VarName);
                                        var ne = new StructExpr();
                                        ne.floatV = av;
                                        Output.Add(ne);
                                    }
                                }
                            }
                            else if (av.Value is StructModule)
                            {
                                if (av.Value.IsFunc(exp[i].VarName))
                                {
                                    if (exp[i].CallPars != null)
                                    {
                                        dynamic[] pars = new dynamic[exp[i].CallPars.Pars.Count];
                                        for (int cpi = 0; cpi < exp[i].CallPars.Pars.Count; cpi++)
                                        {
                                            pars[cpi] = exp[i].CallPars.Pars[cpi].Exec();
                                        }

                                        av = av.Value.ExecFunc(exp[i].VarName, pars);
                                    }
                                    else
                                    {
                                        av = av.Value.ExecFunc(exp[i].VarName, null);
                                    }
                                    var fr = new StructExpr();
                                    fr.floatV = av;
                                    Output.Add(fr);
                                }
                                else
                                {
                                    av = av.Value.FindVar(exp[i].VarName);
                                    if (av.Value is int)
                                    {
                                        var ni = new StructExpr();
                                        ni.floatV = av.Value;
                                        Output.Add(ni);
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                        Console.WriteLine("Variable retrival error.");
                        ManagedHost.RaiseError("Variable retrival error.");
                    }
                    break;

                case ExprType.SubExpr:
                    var ns = new StructExpr();
                    ns.floatV = exp[i].Exec();
                    Output.Add(ns);
                    break;

                case ExprType.FloatValue:
                    Output.Add(exp[i]);
                    break;

                case ExprType.Operator:
                    while (Stack.Count > 0 && Priority(Stack.Peek()) >= Priority(exp[i]))
                    {
                        Output.Add(Stack.Pop());
                    }
                    Stack.Push(exp[i]);
                    //{
                    //   o
                    //}
                    break;
                }
            }
            while (Stack.Count > 0)
            {
                Output.Add(Stack.Pop());
            }
        }
Exemplo n.º 6
0
        public void ToRPNInt(List <StructExpr> exp)
        {
            Output.Clear();
            dynamic av = null;

            for (int i = 0; i < exp.Count; i++)
            {
                switch (exp[i].Type)
                {
                case ExprType.Call:

                    break;

                case ExprType.ClassVar:

                    dynamic basev = null;
                    foreach (var cve in exp[i].Expr)
                    {
                        if (basev == null)
                        {
                            if (Vivid.SynWave.SynHost.Active.HasSysFunc(cve.VarName))
                            {
                                basev = Vivid.SynWave.SynHost.Active.RunSysFunc(cve.VarName, cve.CallPars == null ? null : cve.CallPars.Exec());
                                Var nv1 = new Var();
                                nv1.Value = basev;
                                if (basev is int)
                                {
                                    nv1.Type = VarType.Int;
                                }
                                else if (basev is object)
                                {
                                    //nv1.Type = VarType.Class;
                                }

                                basev = nv1;
                            }
                            else
                            {
                                basev = Vivid.SynWave.SynHost.Active.FindVar(cve.VarName);
                            }

                            if (basev == null)
                            {
                                Console.WriteLine("No link:");
                            }
                        }
                        else
                        {
                            basev = basev.Value.FindVar(cve.VarName);
                        }
                    }

                    var cv = new StructExpr();
                    if (basev != null)
                    {
                        if (basev.Value is StructModule)
                        {
                            cv.Obj = basev.Value;
                            Output.Add(cv);
                            break;
                        }
                    }
                    cv.Obj  = null;
                    cv.intV = basev.Value;

                    Output.Add(cv);

                    break;

                case ExprType.VarValue:
                    try
                    {
                        if (av == null)
                        {
                            av = Vivid.SynWave.SynHost.Active.FindVar(exp[i].VarName);
                            if (av.Value is StructModule || av.Value is Module)
                            {
                            }
                            else
                            {
                                var nnn = new StructExpr();
                                nnn.intV = (int)av.Value;
                                Output.Add(nnn);
                            }
                        }
                        else
                        {
                            if (av.Value is Module)
                            {
                                if (av.Value.CMod != null)
                                {
                                    if (av.Value.CMod.HasStaticVar(exp[i].VarName))
                                    {
                                        av = av.Value.CMod.GetStaticValue(exp[i].VarName);
                                        var ne = new StructExpr();
                                        ne.intV = av;
                                        Output.Add(ne);
                                    }
                                }
                            }
                            else if (av.Value is StructModule)
                            {
                                if (av.Value.IsFunc(exp[i].VarName))
                                {
                                    if (exp[i].CallPars != null)
                                    {
                                        dynamic[] pars = new dynamic[exp[i].CallPars.Pars.Count];
                                        for (int cpi = 0; cpi < exp[i].CallPars.Pars.Count; cpi++)
                                        {
                                            pars[cpi] = exp[i].CallPars.Pars[cpi].Exec();
                                        }

                                        av = av.Value.ExecFunc(exp[i].VarName, pars);
                                    }
                                    else
                                    {
                                        av = av.Value.ExecFunc(exp[i].VarName, null);
                                    }
                                    var fr = new StructExpr();
                                    fr.intV = av;
                                    Output.Add(fr);
                                }
                                else
                                {
                                    av = av.Value.FindVar(exp[i].VarName);
                                    if (av.Value is int)
                                    {
                                        var ni = new StructExpr();
                                        ni.intV = av.Value;
                                        Output.Add(ni);
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                        Console.WriteLine("Variable retrival error.");
                        ManagedHost.RaiseError("Variable retrival error.");
                    }
                    break;

                case ExprType.SubExpr:
                    var ns = new StructExpr();
                    ns.intV = exp[i].Exec();
                    Output.Add(ns);
                    break;

                case ExprType.IntValue:
                    Output.Add(exp[i]);
                    break;

                case ExprType.Operator:
                    while (Stack.Count > 0 && Priority(Stack.Peek()) >= Priority(exp[i]))
                    {
                        Output.Add(Stack.Pop());
                    }
                    Stack.Push(exp[i]);
                    //{
                    //   o
                    //}
                    break;
                }
            }
            while (Stack.Count > 0)
            {
                Output.Add(Stack.Pop());
            }
        }