Beispiel #1
0
 public override Runlet Weave(Runlet continuation, GlobalDictionary g)
 {
     if (this.Scope == "global")
     {
         Ident ident = g.Get(Name);
         if (this.Reftype == "get")
         {
             return(new PushIdentRunlet(ident, continuation));
         }
         else
         {
             throw new UnimplementedNutmegException();
         }
     }
     else if (this.Scope == "local" && this.Slot >= 0)
     {
         if (this.Reftype == "get")
         {
             return(new PushSlotRunlet(this.Slot, continuation));
         }
         else
         {
             throw new UnimplementedNutmegException();
         }
     }
     else
     {
         throw new UnimplementedNutmegException();
     }
 }
Beispiel #2
0
 public override void UpdateLinkNotification()
 {
     while (this._next is JumpRunlet j && j.Next != null)
     {
         this._next = j.Next;
     }
 }
Beispiel #3
0
 public RunletWithNext(Runlet next)
 {
     while (next is JumpRunlet j && j.Next != null)
     {
         next = j.Next;
     }
     this._next = next?.Track(this);
 }
Beispiel #4
0
 public void UpdateLink(Runlet runlet)
 {
     this._next = runlet;
     foreach (var r in this._tracked)
     {
         r.UpdateLinkNotification();
     }
 }
Beispiel #5
0
 public override Runlet Weave(Runlet continuation, GlobalDictionary g)
 {
     for (int i = Body.Length - 1; i >= 0; i -= 1)
     {
         Codelet codelet = Body[i];
         continuation = codelet.Weave(continuation, g);
     }
     return(continuation);
 }
Beispiel #6
0
 public override Runlet Weave(Runlet continuation, GlobalDictionary g)
 {
     if (long.TryParse(this.Value, out var n))
     {
         return(new PushQRunlet(n, continuation));
     }
     else
     {
         throw new Exception($"Invalid int value: {Value}");
     }
 }
Beispiel #7
0
 public override void UpdateLinkNotification()
 {
     while (this.ThenPart is JumpRunlet thenj && thenj.Next != null)
     {
         this.ThenPart = thenj.Next;
     }
     while (this.ElsePart is JumpRunlet elsej && elsej.Next != null)
     {
         this.ElsePart = elsej.Next;
     }
 }
Beispiel #8
0
        public void StartFromCodelet(Runlet codelet, bool useEvaluate)
        {
            TextWriter stdErr = Console.Error;

            if (codelet is FunctionRunlet fwc)
            {
                if (Debug)
                {
                    stdErr.WriteLine($"Running codelet ...");
                }
                try {
                    Runlet currentInstruction = new LockRunlet(new CallQRunlet(fwc, new HaltRunlet()));
                    if (Debug)
                    {
                        while (true)
                        {
                            Console.WriteLine($"Instruction: {currentInstruction}");
                            currentInstruction = currentInstruction.ExecuteRunlet(this);
                        }
                    }
                    else
                    {
                        while (true)
                        {
                            currentInstruction = currentInstruction.ExecuteRunlet(this);
                        }
                    }
                } catch (NormalExitNutmegException) {
                    //  Normal exit.
                } finally {
                    if (Debug)
                    {
                        stdErr.WriteLine($"Bye, bye ...");
                    }
                }
            }
            else
            {
                stdErr.WriteLine("Entry point {id} is not a function");
            }
        }
Beispiel #9
0
 public LTESystemFunction(Runlet next) : base(next)
 {
 }
Beispiel #10
0
 public SubtractSystemFunction(Runlet next) : base(next)
 {
 }
Beispiel #11
0
 public CallSRunlet(Runlet next) : base(next)
 {
 }
Beispiel #12
0
 public abstract Runlet Weave(Runlet continuation, GlobalDictionary g);
Beispiel #13
0
 public override Runlet Weave(Runlet continuation, GlobalDictionary g)
 {
     return(TestPart.Weave(new ForkRunlet(ThenPart.Weave(continuation, g), ElsePart.Weave(continuation, g)), g));
 }
Beispiel #14
0
 public override Runlet Weave(Runlet continuation, GlobalDictionary g)
 {
     return(new LockRunlet(Arguments.Weave(Funarg.Weave(new CallSRunlet(continuation), g), g)));
 }
Beispiel #15
0
 public ForkRunlet(Runlet thenPart, Runlet elsePart)
 {
     this.ThenPart = thenPart.Track(this);
     this.ElsePart = elsePart.Track(this);
 }
Beispiel #16
0
 public override Runlet Track(Runlet runlet)
 {
     this._tracked.Add(runlet);
     return(this);
 }
Beispiel #17
0
 public JumpRunlet(Runlet next) : base(next)
 {
 }
Beispiel #18
0
 public PushQRunlet(object value, Runlet next) : base(next)
 {
     this._value = value;
 }
Beispiel #19
0
 public override Runlet Weave(Runlet continuation, GlobalDictionary g)
 {
     return(new FunctionRunlet(Nargs, Nlocals, this.Body.Weave(new ReturnRunlet(), g), continuation));
 }
Beispiel #20
0
 public virtual Runlet Track(Runlet runlet)
 {
     return(this);
 }
Beispiel #21
0
 public PushIdentRunlet(Ident ident, Runlet next) : base(next)
 {
     this._ident = ident;
 }
Beispiel #22
0
 public PrintlnSystemFunction(Runlet next) : base(next)
 {
 }
Beispiel #23
0
 public override Runlet Weave(Runlet continuation, GlobalDictionary g)
 {
     return(new LockRunlet(Arguments.Weave(_systemFunction(continuation), g)));
 }
Beispiel #24
0
 public AddSystemFunction(Runlet next) : base(next)
 {
 }
Beispiel #25
0
 public override Runlet Weave(Runlet continuation, GlobalDictionary g)
 {
     return(new PushQRunlet(this.Value, continuation));
 }
Beispiel #26
0
 public SumSystemFunction(Runlet next) : base(next)
 {
 }
Beispiel #27
0
        public void Start(string idName, bool useEvaluate)
        {
            Runlet codelet = (Runlet)(this._dictionary.Get(idName).Value);

            StartFromCodelet(codelet, useEvaluate);
        }
Beispiel #28
0
 public SystemFunction(Runlet next)
 {
     this.Next = next;
 }
Beispiel #29
0
 public void PushReturnAddress(Runlet next)
 {
     this._callStack.Push(next);
 }
Beispiel #30
0
 public FunctionRunlet(int nargs, int nlocals, Runlet startCodelet, Runlet next) : base(next)
 {
     this.Nargs         = nargs;
     this.Nlocals       = nlocals;
     this._startCodelet = startCodelet;
 }