public override Runlet ExecuteRunlet(RuntimeEngine runtimeEngine) { FunctionRunlet f = (FunctionRunlet)runtimeEngine.Pop(); runtimeEngine.PushReturnAddress(this._next); return(f.Call(runtimeEngine)); }
public override Runlet ExecuteRunlet(RuntimeEngine runtimeEngine) { //runtimeEngine.ShowFrames(); //Console.WriteLine( $"Slot number {this._slot}" ); runtimeEngine.PushSlot(this._slot); //Console.WriteLine( $"PUSHED <<{runtimeEngine.PeekOrElse()}>>" ); return(this._next); }
public override Runlet ExecuteRunlet(RuntimeEngine runtimeEngine) { long y = (long)runtimeEngine.Pop(); long x = (long)runtimeEngine.Pop(); runtimeEngine.Push(x <= y); runtimeEngine.UnlockValueStack(); return(this.Next); }
public override Runlet ExecuteRunlet(RuntimeEngine runtimeEngine) { long n = 0; while (runtimeEngine.TryPop(out var d)) { n += (long)d; } runtimeEngine.Push(n); runtimeEngine.UnlockValueStack(); return(this.Next); }
public Runlet Call(RuntimeEngine runtimeEngine) { var nargs = runtimeEngine.CreateFrameAndCopyValueStack(this.Nlocals); if (nargs != this.Nargs) { throw new NutmegException("Mismatch in the number of arguments to the number of parameters") .Culprit("Expected", $"{this.Nargs}") .Culprit("Found", $"{nargs}"); } else { return(this._startCodelet); } }
public override Runlet ExecuteRunlet(RuntimeEngine runtimeEngine) { Console.WriteLine($"{runtimeEngine.Pop()}"); return(this.Next); }
private void Run() { TextWriter stdErr = Console.Error; if (this._debug) { stdErr.WriteLine("Nutmeg kicks the ball ..."); } if (this._debug) { stdErr.WriteLine($"Bundle file: {this._bundleFile}"); } if (this._debug) { stdErr.WriteLine($"Entry point: {this._entryPoint}"); } try { RuntimeEngine runtimeEngine = new RuntimeEngine(this._debug); using (SQLiteConnection connection = new SQLiteConnection($"Data Source={this._bundleFile}")) { connection.Open(); var cmd = new SQLiteCommand("SELECT B.[IdName], B.[Value] FROM [Bindings] B JOIN [EntryPoints] E ON E.[Needs] = B.[IdName] WHERE E.[EntryPoint]=@EntryPoint", connection); cmd.Parameters.AddWithValue("@EntryPoint", this._entryPoint); cmd.Prepare(); var reader = cmd.ExecuteReader(); var bindings = new Dictionary <string, Codelet>(); var initialisations = new List <KeyValuePair <string, Codelet> >(); while (reader.Read()) { string idName = reader.GetString(0); string jsonValue = reader.GetString(1); if (this._debug) { stdErr.WriteLine($"Loading definition: {idName}"); } try { Codelet codelet = Codelet.DeserialiseCodelet(jsonValue); runtimeEngine.PreBind(idName); if (codelet is FunctionCodelet fc) { bindings.Add(idName, codelet); } else { initialisations.Add(new KeyValuePair <string, Codelet>(idName, codelet)); } } catch (Newtonsoft.Json.JsonSerializationException e) { Exception inner = e.InnerException; throw (inner is NutmegException nme) ? (Exception)nme : (Exception)e; } } foreach (var k in bindings) { runtimeEngine.Bind(k.Key, k.Value); } foreach (var kvp in initialisations) { if (this._debug) { Console.WriteLine($"Binding {kvp.Key}"); } try { runtimeEngine.Initialise(kvp.Key, kvp.Value); } catch (NormalExitNutmegException) { // This is how initialisation is halted. } } } runtimeEngine.Start(this._entryPoint, useEvaluate: false); } catch (NutmegException nme) { Console.Error.WriteLine($"MISHAP: {nme.Message}"); foreach (var culprit in nme.Culprits) { Console.Error.WriteLine($" {culprit.Key}: {culprit.Value}"); } throw nme; // rethrow } //var jobj = JToken.ReadFrom(new JsonTextReader(new StreamReader(Console.OpenStandardInput()))); //Console.WriteLine($"Output = {jobj.ToString()}"); }
public override Runlet ExecuteRunlet(RuntimeEngine runtimeEngine) { runtimeEngine.Push(this._ident.Value); return(this._next); }
public override Runlet ExecuteRunlet(RuntimeEngine runtimeEngine) { throw new NormalExitNutmegException(); }
public override Runlet ExecuteRunlet(RuntimeEngine runtimeEngine) { return(this._next); }
public abstract Runlet ExecuteRunlet(RuntimeEngine runtimeEngine);
public override Runlet ExecuteRunlet(RuntimeEngine runtimeEngine) { return(runtimeEngine.PopBool() ? ThenPart : ElsePart); }
public override Runlet ExecuteRunlet(RuntimeEngine runtimeEngine) { this._ident.Value = runtimeEngine.Pop1(); return(_next); }
public override Runlet ExecuteRunlet(RuntimeEngine runtimeEngine) { runtimeEngine.UnlockValueStack(); return(_next); }
public override Runlet ExecuteRunlet(RuntimeEngine runtimeEngine) { return(runtimeEngine.Return()); }
public override Runlet ExecuteRunlet(RuntimeEngine runtimeEngine) { runtimeEngine.PushReturnAddress(this._next); return(this._functionRunlet.Call(runtimeEngine)); }