Exemplo n.º 1
0
        private async Task <Dictionary <string, object> > RunInlineVm(string[] runtimeArgs, string extensionArgsJson, CbxBundle cbxBundle, bool showLibStack, bool showOutputPrefixes, Interpreter.ResourceReader resourceReader)
        {
            string byteCode         = cbxBundle.ByteCode;
            string resourceManifest = cbxBundle.ResourceDB.ResourceManifestFile.TextContent;
            string imageManifest    = cbxBundle.ResourceDB.ImageResourceManifestFile.TextContent;

            Interpreter.Structs.VmContext vm = Interpreter.Vm.CrayonWrapper.createVm(byteCode, resourceManifest, imageManifest);
            resourceReader.Vm = vm;

            Interpreter.Vm.CrayonWrapper.vmEnvSetCommandLineArgs(vm, runtimeArgs);
            Interpreter.Vm.CrayonWrapper.vmSetResourceReaderObj(vm, resourceReader);
            Interpreter.Vm.CrayonWrapper.vmSetWaxHub(vm, this.Hub);
            Interpreter.Vm.CrayonWrapper.vmSetWaxPayload(vm, extensionArgsJson);

            vm.environment.stdoutPrefix     = showOutputPrefixes ? "STDOUT" : null;
            vm.environment.stacktracePrefix = showOutputPrefixes ? "STACKTRACE" : null;

            if (showLibStack)
            {
                Interpreter.Vm.CrayonWrapper.vmEnableLibStackTrace(vm);
            }
            Interpreter.Vm.EventLoop eventLoop = new Interpreter.Vm.EventLoop(vm);

            int vmId = vmIdAlloc++;

            Interpreter.Vm.CrayonWrapper.setVmId(vm, vmId);
            vmContexts[vmId] = vm;

            await eventLoop.StartInterpreter();

            string response = Interpreter.Vm.CrayonWrapper.vmGetWaxResponse(vm) ?? "{}";

            return(new Dictionary <string, object>(new Wax.Util.JsonParser(response).ParseAsDictionary()));
        }
Exemplo n.º 2
0
        public void ReadBinaryResourceWithCallback(string path, bool isText, bool useBase64, List <Interpreter.Structs.Value> bytesOut, Interpreter.Structs.Value[] integers, Interpreter.Structs.Value callback)
        {
            string output = ReadBinaryResource(path, isText, useBase64, bytesOut, integers);

            Interpreter.Vm.EventLoop evLoop = (Interpreter.Vm.EventLoop) this.Vm.environment.platformEventLoop;
            if (output == null)
            {
                evLoop.ExecuteFunctionPointerNativeArgs(callback, new object[] { null });
            }
            else
            {
                evLoop.ExecuteFunctionPointerNativeArgs(callback, new object[] { output });
            }
        }