當前位置: 首頁>>代碼示例>>C#>>正文


C# VM.WrenVM類代碼示例

本文整理匯總了C#中Wren.Core.VM.WrenVM的典型用法代碼示例。如果您正苦於以下問題:C# WrenVM類的具體用法?C# WrenVM怎麽用?C# WrenVM使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


WrenVM類屬於Wren.Core.VM命名空間,在下文中一共展示了WrenVM類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Eval

        static bool Eval(WrenVM vm, Obj[] args, int stackStart)
        {
            if (args[stackStart + 1] is ObjString)
            {

                // Eval the code in the module where the calling function was defined.
                Obj callingFn = vm.Fiber.GetFrame().Fn;
                ObjModule module = (callingFn is ObjFn)
                    ? ((ObjFn)callingFn).Module
                    : ((ObjClosure)callingFn).Function.Module;

                // Compile it.
                ObjFn fn = Compiler.Compile(vm, module, "", args[stackStart + 1].ToString(), false);

                if (fn == null)
                {
                    vm.Fiber.Error = Obj.MakeString("Could not compile source code.");
                    return false;
                }

                // TODO: Include the compile errors in the runtime error message.

                // Create a fiber to run the code in.
                ObjFiber evalFiber = new ObjFiber(fn) { Caller = vm.Fiber };

                // Switch to the fiber.
                args[stackStart] = evalFiber;

                return false;
            }

            vm.Fiber.Error = Obj.MakeString("Source code must be a string.");
            return false;
        }
開發者ID:robotii,項目名稱:Wren.NET,代碼行數:34,代碼來源:Meta.cs

示例2: LoadLibrary

        public static void LoadLibrary(WrenVM vm, string libraryName, string typeName)
        {
            Type wrenLibrary = Type.GetType("Wren.Core.Library.LoadLibrary");

            var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            var di = new DirectoryInfo(path);
            foreach (var file in di.GetFiles(libraryName))
            {
                try
                {
                    var nextAssembly = Assembly.LoadFrom(file.FullName);

                    foreach (var type in nextAssembly.GetTypes())
                    {
                        if (type.GetCustomAttributes(wrenLibrary, false).Length > 0)
                        {
                            // This class implements the interface
                            var m = type.GetMethod("LoadLibrary");
                            m.Invoke(null, new object[] {vm});
                        }
                    }
                }
                catch (BadImageFormatException)
                {
                    // Not a .net assembly  - ignore
                }
            }
        }
開發者ID:robotii,項目名稱:Wren.NET,代碼行數:29,代碼來源:LoadLibrary.cs

示例3: LoadLibrary

        public static void LoadLibrary(WrenVM vm)
        {
            vm.Interpret("", "", MetaLibSource);

            ObjClass meta = (ObjClass)vm.FindVariable("Meta");
            vm.Primitive(meta.ClassObj, "eval(_)", Eval);
        }
開發者ID:robotii,項目名稱:Wren.NET,代碼行數:7,代碼來源:Meta.cs

示例4: LoadLibrary

 public static void LoadLibrary(WrenVM vm)
 {
     vm.Interpret("scheduler", "scheduler", _schedulerSource);
     ObjClass scheduler = (ObjClass)vm.FindVariable("scheduler", "Scheduler");
     vm.Primitive(scheduler.ClassObj, "captureMethods_()", CaptureMethods);
     vm.Interpret("scheduler", "scheduler", "Scheduler.captureMethods_()");
 }
開發者ID:robotii,項目名稱:Wren.NET,代碼行數:7,代碼來源:Scheduler.cs

示例5: RunFile

        static int RunFile(string path)
        {
            if (!File.Exists(path)) 
                return 66; // File Not Found

            _loadedFile = path;
            string source = File.ReadAllText(path);
            WrenVM vm = new WrenVM { LoadModuleFn = LoadModule };
            LibraryLoader.LoadLibraries(vm);
            return (int)vm.Interpret("main", path, source);
        }
開發者ID:robotii,項目名稱:Wren.NET,代碼行數:11,代碼來源:Program.cs

示例6: RunFile

 static int RunFile(string path)
 {
     if (File.Exists(path))
     {
         loadedFile = path;
         string source = File.ReadAllText(path);
         WrenVM vm = new WrenVM { LoadModuleFn = LoadModule };
         return (int)vm.Interpret(path, source);
     }
     return 66; // File Not Found
 }
開發者ID:minirop,項目名稱:Wren.NET,代碼行數:11,代碼來源:Program.cs

示例7: LoadLibrary

        public static void LoadLibrary(WrenVM vm)
        {
            vm.Interpret("io", "io", IoSource);
            ObjClass file = (ObjClass)vm.FindVariable("io", "File");
            vm.Primitive(file.ClassObj, "open_(_,_)", Open);
            vm.Primitive(file.ClassObj, "sizePath_(_,_)", SizePath);

            vm.Primitive(file, "close_(_)", Close);
            vm.Primitive(file, "descriptor", Descriptor);
            vm.Primitive(file, "readBytes_(_,_)", ReadBytes);
            vm.Primitive(file, "size_(_)", Size);
        }
開發者ID:robotii,項目名稱:Wren.NET,代碼行數:12,代碼來源:io.cs

示例8: RunRepl

        static void RunRepl()
        {
            WrenVM vm = new WrenVM();

            Console.WriteLine("-- wren v0.0.0");

            string line = "";

            for (; line != "/exit"; )
            {
                Console.Write("> ");
                line = Console.ReadLine();

                // TODO: Handle failure.
                vm.Interpret("Prompt", line);
            }
        }
開發者ID:minirop,項目名稱:Wren.NET,代碼行數:17,代碼來源:Program.cs

示例9: RunRepl

        static void RunRepl()
        {
            WrenVM vm = new WrenVM();
            LibraryLoader.LoadLibraries(vm);

            Console.WriteLine("-- wren v0.0.0");

            string line = "";

            for (; ; )
            {
                Console.Write("> ");
                line += Console.ReadLine() + "\n";

                if(OpenBrackets(line) > 0)
                    continue;

                // TODO: Handle failure.
                vm.Interpret("Prompt","Prompt", line);
                line = "";
            }
        }
開發者ID:robotii,項目名稱:Wren.NET,代碼行數:22,代碼來源:Program.cs

示例10: prim_map_clear

 static bool prim_map_clear(WrenVM vm, Obj[] args, int stackStart)
 {
     ObjMap m = args[stackStart] as ObjMap;
     if (m != null)
         m.Clear();
     args[stackStart] = Obj.Null;
     return true;
 }
開發者ID:robotii,項目名稱:Wren.NET,代碼行數:8,代碼來源:CoreLibrary.cs

示例11: prim_map_subscriptSetter

        static bool prim_map_subscriptSetter(WrenVM vm, Obj[] args, int stackStart)
        {
            if (ValidateKey(args[stackStart + 1]))
            {
                ObjMap map = args[stackStart] as ObjMap;

                if (map != null)
                {
                    map.Set(args[stackStart + 1], args[stackStart + 2]);
                }
                args[stackStart] = args[stackStart + 2];
                return true;
            }

            vm.Fiber.Error = Obj.MakeString("Key must be a value type or fiber.");
            return false;
        }
開發者ID:robotii,項目名稱:Wren.NET,代碼行數:17,代碼來源:CoreLibrary.cs

示例12: prim_map_subscript

        static bool prim_map_subscript(WrenVM vm, Obj[] args, int stackStart)
        {
            Obj a = args[stackStart + 1];
            if (ValidateKey(a))
            {
                ObjMap map = args[stackStart] as ObjMap;
                if (map != null)
                {
                    args[stackStart] = map.Get(a);
                    if (args[stackStart] == Obj.Undefined)
                    {
                        args[stackStart] = Obj.Null;
                    }
                }
                else
                {
                    args[stackStart] = Obj.Null;
                }
                return true;
            }

            vm.Fiber.Error = Obj.MakeString("Key must be a value type or fiber.");
            return false;
        }
開發者ID:robotii,項目名稱:Wren.NET,代碼行數:24,代碼來源:CoreLibrary.cs

示例13: prim_map_instantiate

 static bool prim_map_instantiate(WrenVM vm, Obj[] args, int stackStart)
 {
     args[stackStart] = new ObjMap();
     return true;
 }
開發者ID:robotii,項目名稱:Wren.NET,代碼行數:5,代碼來源:CoreLibrary.cs

示例14: prim_list_subscriptSetter

        static bool prim_list_subscriptSetter(WrenVM vm, Obj[] args, int stackStart)
        {
            ObjList list = (ObjList)args[stackStart];
            if (args[stackStart + 1].Type == ObjType.Num)
            {
                int index = (int)args[stackStart + 1].Num;

                if (index == args[stackStart + 1].Num)
                {
                    if (index < 0)
                    {
                        index += list.Count();
                    }

                    if (list != null && index >= 0 && index < list.Count())
                    {
                        list.Set(args[stackStart + 2], index);
                        args[stackStart] = args[stackStart + 2];
                        return true;
                    }

                    vm.Fiber.Error = Obj.MakeString("Subscript out of bounds.");
                    return false;
                }

                vm.Fiber.Error = Obj.MakeString("Subscript must be an integer.");
                return false;
            }
            vm.Fiber.Error = Obj.MakeString("Subscript must be a number.");
            return false;
        }
開發者ID:robotii,項目名稱:Wren.NET,代碼行數:31,代碼來源:CoreLibrary.cs

示例15: prim_fn_arity

 static bool prim_fn_arity(WrenVM vm, Obj[] args, int stackStart)
 {
     ObjFn fn = args[stackStart] as ObjFn;
     args[stackStart] = fn != null ? new Obj(fn.Arity) : new Obj(0.0);
     return true;
 }
開發者ID:robotii,項目名稱:Wren.NET,代碼行數:6,代碼來源:CoreLibrary.cs


注:本文中的Wren.Core.VM.WrenVM類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。