private bool StartCompile() { Compile compile = new Compile() { Minimize = true, LazyClassLoading = false, LazyTableLoading = false, UpdateCrossReference = UpdateXRef, Development = true, NoModalBoxes = true }; if (!string.IsNullOrEmpty(ConfigurationFile)) { compile.ConfigurationFile = ConfigurationFile; } if (Layercodes != null) { if (!string.IsNullOrEmpty(ModelManifest)) { string model; string publisher; string layer; string layerCode; Helper.ExtractClientLayerModelInfo(ConfigurationFile, Layercodes, ModelManifest, out model, out publisher, out layer, out layerCode); compile.Model = model; compile.ModelPublisher = publisher; compile.Layer = layer; compile.LayerCode = layerCode; } } var clientConfig = Helper.GetClientConfig(ConfigurationFile); logFile = string.Format(@"{0}\{1}", Environment.ExpandEnvironmentVariables(clientConfig.LogDirectory), "AxCompileAll.html"); Process task = null; if (string.IsNullOrEmpty(ClientExecutablePath)) { task = Client.StartCommand(compile); } else { task = Client.StartCommand(ClientExecutablePath, compile); } task.WaitForExit(); return(true); }
static void Main() { var imports = new ImportDictionary { { "env", "greet", new FunctionImport(new Action(greet)) }, { "env", "printf", new FunctionImport(new Func <int, int, int>(printf)) }, }; var compiled = Compile.FromBinary <dynamic>(new FileStream("test.wasm", FileMode.Open, FileAccess.Read))(imports); memory = compiled.Exports.memory; compiled.Exports._start(); }
public void Compiler_ReadGlobalSectionWhenGlobalImport() { // Set up a module with a global import and a global var module = new Module(); module.Imports.Add(new WebAssembly.Import.Global("mod", "field")); module.Globals.Add(new Global { ContentType = WebAssemblyValueType.Int32, IsMutable = false, InitializerExpression = new Instruction[] { new Int32Constant(1), new End() }.ToList() }); module.Types.Add(new WebAssemblyType { Returns = new[] { WebAssemblyValueType.Int32, }, }); module.Functions.Add(new Function { Type = 0 }); module.Codes.Add(new FunctionBody { Code = new Instruction[] { new GlobalGet(0), new GlobalGet(1), new Int32Add(), new End(), }, }); module.Exports.Add(new Export { Kind = ExternalKind.Function, Index = 0, Name = "fn", }); using var memoryStream = new MemoryStream(); module.WriteToBinary(memoryStream); memoryStream.Seek(0L, SeekOrigin.Begin); var compilationResult = Compile.FromBinary <dynamic>(memoryStream); var result = compilationResult.Invoke(new Dictionary <string, IDictionary <string, RuntimeImport> > { { "mod", new Dictionary <string, RuntimeImport> { { "field", new GlobalImport(() => 2) } } }, }).Exports.fn(); Assert.AreEqual(3, result); }
void Start() { _level = GameObject.Find("BackTiles"); _levelLayout = _level.GetComponent <LevelLayout>(); _compileObject = GameObject.Find("Compile"); _compile = _compileObject.GetComponent <Compile>(); _repeatObject = GameObject.Find("Repeat"); _repeat = _repeatObject.GetComponent <RepeatCommand>(); moveSpeed = _StandardSpeed; }
private void Run_Click(object sender, EventArgs e) { if (!TestContent()) { return; } Compile.PerformClick(); if (!isLexError && !isGrmErr) { run.StartRun(); } }
public void FunctionReturnTypeReferenceIntrinsic() { const string code = "fn: (): Str" + Tokens.NewLine + Tokens.Indent1 + "return \"Hello Z#\"" + Tokens.NewLine ; var file = Compile.File(code); var fn = file.CodeBlock.LineAt <AstFunctionDefinitionImpl>(0); fn.FunctionType.TypeReference.TypeDefinition.Should().NotBeNull(); }
public void FunctionReturnIntrinsic() { const string code = "fn: (): Str" + Tokens.NewLine + Tokens.Indent1 + "return \"Hello Z#\"" + Tokens.NewLine ; var file = Compile.File(code); var strSymbol = file.CodeBlock.SymbolTable.FindSymbol("Str", Zsharp.AST.AstSymbolKind.Type); strSymbol.Definition.Should().NotBeNull(); }
internal static Instance <JitEntryPoint> CompileWasm(UInt160 contract, byte[] buffer, ImportDictionary imports, bool ignoreEndingCode) { if (ByteCodeCache.TryGetValue(contract, out var instance)) { return(instance()); } var config = new CompilerConfiguration() { IgnoreEndingCode = ignoreEndingCode }; using var stream = new MemoryStream(buffer, 0, buffer.Length, false); return(Compile.FromBinary <JitEntryPoint>(stream, config)(imports)); }
public static void Create() { var testproject = ProjectExtensions.CreateDefaultConsole("netcoreapp3.1"); var itemGroup1 = new ItemGroup(); var newFile1 = new Compile("testfile.cs"); itemGroup1.Add(newFile1); testproject.Add(itemGroup1); testproject.SaveAs("testconsole.csproj"); }
void Start() { _playerObject = GameObject.Find("Player"); _player = _playerObject.GetComponent <Player>(); _levelLayoutObject = GameObject.Find("BackTiles"); _levelLayout = _levelLayoutObject.GetComponent <LevelLayout>(); _compileObject = GameObject.Find("Compile"); _compile = _compileObject.GetComponent <Compile>(); _repeatObject = GameObject.Find("Repeat"); _repeat = _repeatObject.GetComponent <RepeatCommand>(); }
protected void RblFormulaType_SelectedIndexChanged(object sender, EventArgs e) { dgSample.DataSource = null; dgSample.DataBind(); // create instance of compile class Compile mCompile = new Compile(); // show allowable parameters int selType = Convert.ToInt32(rblFormulaType.SelectedValue); StringBuilder sbInfo = new StringBuilder(); sbInfo.Append("The last line of the function must be of the form - CalcCost = ..."); sbInfo.Append("<br />"); sbInfo.Append("Parameters available for store cost calculations:"); sbInfo.Append("<br />"); for (int i = 0; i < mCompile.aryVars[selType].Length; i++) { sbInfo.Append(mCompile.aryVars[selType][i]); sbInfo.Append(" - "); sbInfo.Append(mCompile.aryNotes[selType][i]); sbInfo.Append("<br />"); } lblInfo.Text = sbInfo.ToString(); lblInfo.Visible = true; btnValidate.Enabled = true; DataRow[] fdr = dsFormula.Tables["Formula"].Select(string.Format("FormulaType = '{0}'", rblFormulaType.SelectedItem.Text), "EffDate DESC"); if (fdr.Length > 0) { txtFormula.Text = fdr[fdr.Length - 1]["Formula"].ToString(); } else { txtFormula.Text = "CalcCost = "; } txtFormula.Visible = true; if (fdr.Length == 2) { btnRevert.Enabled = true; } else { btnRevert.Enabled = false; } }
public void ConstructorCapacity() { const string code = "arr = Array<U8>(10)" + Tokens.NewLine ; var moduleLoader = new AssemblyManagerBuilder() .AddZsharpRuntime() .ToModuleLoader(); var file = Compile.File(code, moduleLoader); var assign = file.CodeBlock.LineAt <AstAssignment>(0); assign.Expression.RHS.FunctionReference.Should().NotBeNull(); }
public void FunctionReferenceByParameterType_Forward() { const string code = "fn(42)" + Tokens.NewLine + "fn: (p: I32)" + Tokens.NewLine + Tokens.Indent1 + "return" + Tokens.NewLine ; var file = Compile.File(code); var fnRef = file.CodeBlock.LineAt <AstFunctionReference>(0); fnRef.Should().NotBeNull(); fnRef.Symbol.Definition.Should().NotBeNull(); }
public override object[] GetResult(KeyValuePair <string, string> keyValue) { var name = keyValue.Key; var content = keyValue.Value; var code = GetFunc(name); if (string.IsNullOrEmpty(code)) { return new string[] { content } } ; code = string.Format(code, content); return(Compile.GetResult(code).ToArray()); }
public void FunctionCallParameterReference() { const string code = "fn: (p: U8)" + Tokens.NewLine + Tokens.Indent1 + "fn(42)" + Tokens.NewLine ; var file = Compile.File(code); var fn = file.CodeBlock.LineAt <AstFunctionDefinitionImpl>(0); var call = fn.CodeBlock.LineAt <AstFunctionReference>(0); var arg = call.FunctionType.Arguments.First(); arg.TypeReference.Should().NotBeNull(); }
public void LoadNamespaceExternal_System() { var symbolTable = new AstSymbolTable(); var loader = Compile.CreateModuleLoader(); loader.Initialize(symbolTable); var sysMods = loader.LoadNamespace("System"); sysMods.Should().NotBeEmpty(); sysMods.All(m => m.SymbolTable.Namespace.StartsWith("System.")) .Should().BeTrue(); sysMods.All(m => m.SymbolTable.FindSymbols(AstSymbolKind.Function) .All(e => e.SymbolLocality == AstSymbolLocality.Imported)) .Should().BeTrue(); }
public void FunctionReferenceInferredTypeRef() { const string code = "fn: (): Str" + Tokens.NewLine + Tokens.Indent1 + "return \"Hello Z#\"" + Tokens.NewLine + "s = fn()" + Tokens.NewLine ; var file = Compile.File(code); var assign = file.CodeBlock.LineAt <AstAssignment>(1); assign.Expression.RHS.FunctionReference.FunctionType.TypeReference.Should().NotBeNull(); assign.Variable.TypeReference.TypeDefinition .Should().BeEquivalentTo(assign.Expression.TypeReference.TypeDefinition); }
/// <summary> /// Wait for the compiler to respond to a specified compile request /// </summary> /// <param name="projectId">Id of the project</param> /// <param name="compileId">Id of the compilation of the project</param> /// <returns></returns> private Compile WaitForCompilerResponse(int projectId, string compileId) { var compile = new Compile(); var finish = DateTime.Now.AddSeconds(60); while (DateTime.Now < finish) { compile = _api.ReadCompile(projectId, compileId); if (compile.State == CompileState.BuildSuccess) { break; } Thread.Sleep(1000); } return(compile); }
public void ResolveConversionFunction_TopVariableAssign() { const string code = "x = U16(42)" + Tokens.NewLine ; var moduleLoader = new AssemblyManagerBuilder() .AddZsharpRuntime() .ToModuleLoader(); var file = Compile.File(code, moduleLoader); var assign = file.CodeBlock.LineAt <AstAssignment>(0); assign.Expression.TypeReference.Should().NotBeNull(); }
public static void AddBeforeLastImport() { var project = Project.Load("testproj.csproj"); var lastImport = project.Imports.Last(); var itemGroup = new ItemGroup(); var newFile = new Compile("testfile.cs"); itemGroup.Add(newFile); lastImport.AddBeforeSelf(itemGroup); project.Save(); }
/// <summary> /// Wait for the compiler to respond to a specified compile request /// </summary> /// <param name="api">API Method</param> /// <param name="projectId"></param> /// <param name="compileId"></param> /// <returns></returns> private Compile WaitForCompilerResponse(IApi api, int projectId, string compileId) { var compile = new Compile(); var finish = DateTime.Now.AddSeconds(30); while (DateTime.Now < finish) { compile = api.ReadCompile(projectId, compileId); if (compile.State != CompileState.InQueue) { break; } Thread.Sleep(500); } return(compile); }
public void IntrinsicConversion() { const string code = "fn: (p: U8): U16" + Tokens.NewLine + Tokens.Indent1 + "return U16(p)" + Tokens.NewLine ; var moduleLoader = new AssemblyManagerBuilder() .AddZsharpRuntime() .ToModuleLoader(); var file = Compile.File(code, moduleLoader); var fn = file.CodeBlock.LineAt <AstFunctionDefinitionImpl>(0); var intrinsic = fn.SymbolTable.FindDefinition <AstFunctionDefinition>("U16", AstSymbolKind.Function); intrinsic.FunctionType.Parameters.First().IsSelf.Should().BeTrue(); }
public void TemplateIntrinsicTypeUsage() { const string code = "s: Array<U8>" + Tokens.NewLine ; var file = Compile.File(code); var v = file.CodeBlock.LineAt <AstVariableDefinition>(0); var typeRef = v.TypeReference as AstTypeReferenceType; typeRef.IsTemplateOrGeneric.Should().BeTrue(); var typeDef = typeRef.TypeDefinition as AstTemplateInstanceType; typeDef.Should().NotBeNull(); typeDef.TemplateParameterArguments.Count.Should().Be(1); }
public void StructTemplate_ReuseInstantiationType() { const string code = "Struct<#T>" + Tokens.NewLine + Tokens.Indent1 + "Id: T" + Tokens.NewLine + "s = Struct<U8>" + Tokens.NewLine + Tokens.Indent1 + "Id = 42" + Tokens.NewLine + "t = Struct<U8>" + Tokens.NewLine + Tokens.Indent1 + "Id = 101" + Tokens.NewLine ; var file = Compile.File(code); var v1 = file.CodeBlock.LineAt <AstAssignment>(1).Variable as AstVariableDefinition; var v2 = file.CodeBlock.LineAt <AstAssignment>(2).Variable as AstVariableDefinition; v1.TypeReference.TypeDefinition.Should().Be(v2.TypeReference.TypeDefinition); }
public void ExternalZsharpConversion() { const string code = "v = U16(42)" + Tokens.NewLine ; var moduleLoader = new AssemblyManagerBuilder() .AddZsharpRuntime() .ToModuleLoader(); var file = Compile.File(code, moduleLoader); var assign = file.CodeBlock.LineAt <AstAssignment>(0); assign.Expression.RHS.FunctionReference.FunctionDefinition.Should().NotBeNull(); assign.Expression.RHS.FunctionReference.FunctionDefinition.IsExternal.Should().BeTrue(); }
public void FunctionParameterReference() { const string code = "fn: (p: U8)" + Tokens.NewLine + Tokens.Indent1 + "x = p" + Tokens.NewLine ; var file = Compile.File(code); var fn = file.CodeBlock.LineAt <AstFunctionDefinitionImpl>(0); var a = fn.CodeBlock.LineAt <AstAssignment>(0); var v = a.Variable as AstVariableDefinition; var p = a.Expression.RHS.VariableReference.ParameterDefinition; p.Should().NotBeNull(); v.TypeReference.Identifier.NativeFullName.Should().Be(p.TypeReference.Identifier.NativeFullName); }
public void CustomConversion() { const string code = "MyStruct" + Tokens.NewLine + Tokens.Indent1 + "Fld: U16" + Tokens.NewLine + "U16: (self: MyStruct): U16" + Tokens.NewLine + Tokens.Indent1 + "return self.Fld" + Tokens.NewLine + "fn: (p: MyStruct): U16" + Tokens.NewLine + Tokens.Indent1 + "return U16(p)" + Tokens.NewLine ; var file = Compile.File(code); var fn = file.CodeBlock.LineAt <AstFunctionDefinitionImpl>(2); var intrinsic = fn.SymbolTable.FindDefinition <AstFunctionDefinition>("U16", AstSymbolKind.Function); intrinsic.FunctionType.Parameters.First().IsSelf.Should().BeTrue(); }
public void CurrentMemory_Compiled() { var module = new Module(); module.Types.Add(new Type { Returns = new[] { ValueType.Int32, }, }); module.Functions.Add(new Function { }); module.Exports.Add(new Export { Name = "Test", }); module.Codes.Add(new FunctionBody { Code = new Instruction[] { new CurrentMemory(), new End(), } }); module.Memories.Add(new Memory(1, 1)); Instance <dynamic> compiled; using (var memory = new MemoryStream()) { module.WriteToBinary(memory); Assert.AreNotEqual(0, memory.Length); memory.Position = 0; var maker = Compile.FromBinary <dynamic>(memory); Assert.IsNotNull(maker); compiled = maker(); } var exports = compiled.Exports; Assert.AreEqual <int>(1, exports.Test()); }
static Instance <SelectTester <T> > CreateTester <T>(ValueType type) where T : struct { var module = new Module(); module.Types.Add(new Type { Parameters = new ValueType[] { type, type, ValueType.Int32, }, Returns = new[] { type, }, }); module.Functions.Add(new Function { }); module.Exports.Add(new Export { Name = nameof(SelectTester <T> .Test), }); module.Codes.Add(new FunctionBody { Code = new Instruction[] { new GetLocal(0), new GetLocal(1), new GetLocal(2), new Select(), new End(), }, }); using (var memory = new MemoryStream()) { module.WriteToBinary(memory); memory.Position = 0; return(Compile.FromBinary <SelectTester <T> >(memory)()); } }
/// <summary> /// Runs the algorithm with the given settings and file /// </summary> /// <param name="settings">Settings for Lean</param> /// <param name="file">File to run</param> private void RunLiveAlgorithm(BaseLiveAlgorithmSettings settings, ProjectFile file) { // Create a new project var project = _api.CreateProject($"Test project - {DateTime.Now.ToStringInvariant()}", Language.CSharp); // Add Project Files var addProjectFile = _api.AddProjectFile(project.Projects.First().ProjectId, file.Name, file.Code); Assert.IsTrue(addProjectFile.Success); // Create compile var compile = _api.CreateCompile(project.Projects.First().ProjectId); Assert.IsTrue(compile.Success); // Wait at max 30 seconds for project to compile Compile compileCheck = WaitForCompilerResponse(project.Projects.First().ProjectId, compile.CompileId, 30); Assert.IsTrue(compileCheck.Success); Assert.IsTrue(compileCheck.State == CompileState.BuildSuccess); // Get a live node to launch the algorithm on var nodes = _api.ReadNodes(_testOrganization); Assert.IsTrue(nodes.Success); var freeNode = nodes.LiveNodes.Where(x => x.Busy == false); Assert.IsNotEmpty(freeNode, "No free Live Nodes found"); // Create live default algorithm var createLiveAlgorithm = _api.CreateLiveAlgorithm(project.Projects.First().ProjectId, compile.CompileId, freeNode.FirstOrDefault().Id, settings); Assert.IsTrue(createLiveAlgorithm.Success); if (stopLiveAlgos) { // Liquidate live algorithm; will also stop algorithm var liquidateLive = _api.LiquidateLiveAlgorithm(project.Projects.First().ProjectId); Assert.IsTrue(liquidateLive.Success); // Delete the project var deleteProject = _api.DeleteProject(project.Projects.First().ProjectId); Assert.IsTrue(deleteProject.Success); } }
// TODO: define operators for DateTime public override void EmitLiteral(Compile.MethodContext method, object value) { method.IL.Emit(OpCodes.Ldc_I8, ((DateTime)value).Ticks); method.IL.Emit(OpCodes.Newobj, ReflectionUtility.DateTimeTicksConstructor); }
// TODO: define operators for Double public override void EmitLiteral(Compile.MethodContext method, object value) { method.IL.Emit(OpCodes.Ldc_R8, (double)value); }
public override System.Type GetNative(Compile.Emitter emitter) { return typeof(Runtime.Void); }
// TODO: define operators for Version public override void EmitLiteral(Compile.MethodContext method, object value) { method.EmitVersion((Version)value); }
public override System.Type GetNative(Compile.Emitter emitter) { return Native; }
public Target(Target origin) { word = origin.word; pos = origin.pos; text = origin.text; compile = origin.compile; }
public Target(int count, Text text) { this.text = text; word = text.start; pos = count + 1; this.count = count; move(true); compile = html_compile; }