コード例 #1
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void Create(Forth f)
 {
     string word = f.getWord(' ');
     f.Define(word, MakeLiteralOp((long)f.here));
 }
コード例 #2
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void Backslash(Forth f)
 {
     f.getWord('\n');
 }
コード例 #3
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void LParen(Forth f)
 {
     f.getWord(')');
 }
コード例 #4
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 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));
     }
 }
コード例 #5
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 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);
     }
 }
コード例 #6
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 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)));
 }
コード例 #7
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 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));
 }
コード例 #8
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 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);
 }
コード例 #9
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 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));
     }
 }
コード例 #10
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 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));
             }
         )
     );
 }