Beispiel #1
0
 public static void Create(Forth f)
 {
     string word = f.getWord(' ');
     f.Define(word, MakeLiteralOp((long)f.here));
 }
Beispiel #2
0
 public static void Backslash(Forth f)
 {
     f.getWord('\n');
 }
Beispiel #3
0
 public static void LParen(Forth f)
 {
     f.getWord(')');
 }
Beispiel #4
0
 public static void PfBytes(Forth f)
 {
     if (f.isCompiling)
     {
         string hex = f.getWord(' ');
         f.AppendCode(MakeLiteralOp(HexToBytes(hex)));
     }
     else
     {
         string hex = f.getWord(' ');
         f.dStack.Push(HexToBytes(hex));
     }
 }
Beispiel #5
0
 public static void DotQuote(Forth f)
 {
     if (f.isCompiling)
     {
         string str = f.getWord('"');
         f.AppendCode
         (
             delegate(Forth g)
             {
                 Console.Write(str);
             }
         );
     }
     else
     {
         string str = f.getWord('"');
         Console.Write(str);
     }
 }
Beispiel #6
0
 public static void CreateVocabulary(Forth f)
 {
     string name = f.getWord(' ');
     Dictionary<string, ForthDictionaryEntry> dict = f.definitions.Dict;
     if (dict.ContainsKey(name)) dict.Remove(name);
     dict.Add(name, new ForthDictionaryEntry(new Vocabulary(name)));
 }
Beispiel #7
0
 public static void BracketTick(Forth f)
 {
     if (!f.isCompiling) throw new InvalidOperationException("bracket-tick is only valid when compiling");
     string word = f.getWord(' ');
     ForthDictionaryEntry fde = f.SearchVocabularies(word);
     if (fde == null) throw new InvalidOperationException("attempt to bracket-tick undefined word " + word);
     f.AppendCode(MakeLiteralOp(fde.Proc));
 }
Beispiel #8
0
 public static void Tick(Forth f)
 {
     string word = f.getWord(' ');
     ForthDictionaryEntry fde = f.SearchVocabularies(word);
     if (fde == null) throw new InvalidOperationException("attempt to tick undefined word " + word);
     f.dStack.Push(fde.Proc);
 }
Beispiel #9
0
 public static void Postpone(Forth f)
 {
     if (!f.isCompiling) throw new InvalidOperationException("postpone is only valid when compiling");
     string word = f.getWord(' ');
     ForthDictionaryEntry fde = f.SearchVocabularies(word);
     if (fde == null) throw new InvalidOperationException("attempt to postpone undefined word " + word);
     if (fde.IsImmediate)
     {
         f.AppendCode(fde.Proc);
     }
     else
     {
         f.AppendCode(MakeLiteralOp(fde.Proc));
         f.AppendCode(new ExecutionToken(PopAndAppendCode));
     }
 }
Beispiel #10
0
 public static void Define(Forth f)
 {
     if (!f.compileStack.IsEmpty) throw new InvalidOperationException("Nested definitions are not permitted");
     f.isCompiling = true;
     string localWordBeingCompiled = f.getWord(' ');
     f.compileStack.Push
     (
         new CompileState
         (
             new CompositeWord(),
             delegate(CompositeWord finishedWord)
             {
                 f.Define(localWordBeingCompiled, new ExecutionToken(finishedWord.Run));
             }
         )
     );
 }