public ABI() { var f = new AVMFunction(); f.name = "Main"; f.inputs.Add(new AVMInput() { name = "operation", type = Emulator.Type.String }); f.inputs.Add(new AVMInput() { name = "args", type = Emulator.Type.Array }); this.functions[f.name] = f; this.entryPoint = functions.Values.FirstOrDefault(); }
public ABI(string fileName) { this.fileName = fileName; var json = File.ReadAllText(fileName); var root = JSONReader.ReadFromString(json); var fn = root.GetNode("functions"); foreach (var child in fn.Children) { var f = new AVMFunction(); f.name = child.GetString("name"); if (!Enum.TryParse(child.GetString("returnType"), true, out f.returnType)) { f.returnType = Emulator.Type.Unknown; } var p = child.GetNode("parameters"); if (p != null && p.ChildCount > 0) { for (int i = 0; i < p.ChildCount; i++) { var input = new AVMInput(); input.name = p[i].GetString("name"); var temp = p[i].GetString("type"); if (!Enum.TryParse <Emulator.Type>(temp, true, out input.type)) { input.type = Emulator.Type.Unknown; } f.inputs.Add(input); } } functions[f.name] = f; } entryPoint = functions[root.GetString("entrypoint")]; }
public byte[] GenerateLoaderScriptFromInputs(DataNode inputs, ABI abi) { var methodName = abi != null && abi.entryPoint != null ? abi.entryPoint.name : null; using (ScriptBuilder sb = new ScriptBuilder()) { var items = new Stack <object>(); if (inputs != null) { AVMFunction method = methodName != null && abi.functions.ContainsKey(methodName) ? abi.functions[methodName] : null; int index = 0; foreach (var item in inputs.Children) { Emulator.Type hint = method != null ? method.inputs[index].type : Emulator.Type.Unknown; var obj = Emulator.ConvertArgument(item, hint); items.Push(obj); index++; } } while (items.Count > 0) { var item = items.Pop(); NeoAPI.EmitObject(sb, item); } var loaderScript = sb.ToArray(); //System.IO.File.WriteAllBytes("loader.avm", loaderScript); return(loaderScript); } }