コード例 #1
0
ファイル: Program.cs プロジェクト: Sunlighter/SimpleForth
        static void Main(string[] args)
        {
            try
            {
#if false
                using (MemoryBlock mb = new MemoryBlock((UIntPtr)0x20000))
                {
                    Console.WriteLine("Is64Bit = " + MemoryBlock.Is64Bit);
                    Console.WriteLine("mb.Location = " + mb.Location);
                    Console.WriteLine("mb.Size = " + mb.Size);

                    Marshal.WriteByte(mb.Location, (byte)32);
                    byte b = Marshal.ReadByte(mb.Location);
                    System.Diagnostics.Debug.Assert(b == (byte)32);

                    mb.Security = MemoryBlockSecurity.ReadOnly;

                    byte b2 = Marshal.ReadByte(mb.Location);
                    Marshal.WriteByte(mb.Location, (byte)64);
                }
#endif
                Console.SetBufferSize(120, 60);
                Console.SetWindowSize(120, 60);
                Console.WriteLine("Sunlit World Forth in C#");
                Console.WriteLine("Copyright (c) 2007 by Edward Kiser");
                Console.WriteLine("All Rights Reserved");
                if (MemoryBlock.Is64Bit) Console.WriteLine("[Running in 64-bit Mode]");
                using (MemoryBlock mb = new MemoryBlock((UIntPtr)0x20000))
                {
                    mb.Security = MemoryBlockSecurity.ExecuteReadWrite;
                    Forth f = new Forth();
                    f.ByteMemory = new MemoryAccessor(mb.Location, mb.Size);
                    f.LoadX86Asm();
                    bool done = false;
                    f.Execute("also forth definitions previous");
                    f.Define("bye", delegate(Forth g) { done = true; });
                    f.Execute("vocabulary user  also user definitions");
                    while (!done)
                    {
                        if (f.IsCompiling) Console.WriteLine("ok (compiling)"); else Console.WriteLine("ok");
                        string x = Console.ReadLine();
                        f.Execute(x);
                    }
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine();
                Console.WriteLine("***** Exception! *****");
                Console.WriteLine();
                Console.WriteLine(exc);
            }
            Console.WriteLine("Press a key...");
            Console.ReadKey();
        }
コード例 #2
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void Hex(Forth f)
 {
     f.numericBase = 16;
 }
コード例 #3
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public void Run(Forth f)
 {
     f.rStack.Push(0);
     while(true)
     {
         int pos = f.rStack.Pop();
         if (pos < 0 || pos >= components.Count) break;
         int posNext = pos + 1;
         f.rStack.Push(posNext);
         components[pos](f);
     }
 }
コード例 #4
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void Allot(Forth f)
 {
     long amt = f.PopInt64();
     if (amt > (long)(f.memory.Length - f.here)) throw new ArgumentOutOfRangeException("Attempt to allot more memory than is available");
     f.here += (int)amt;
 }
コード例 #5
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void Comma(Forth f)
 {
     object v = f.dStack.Pop();
     f.memory[f.here] = v;
     f.here++;
 }
コード例 #6
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void Bang(Forth f)
 {
     long index = f.PopInt64();
     object v = f.dStack.Pop();
     f.memory[(int)index] = v;
 }
コード例 #7
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void Unused(Forth f)
 {
     f.PushInt64((long)(f.memory.Length - f.here));
 }
コード例 #8
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void IsExecutionToken(Forth f)
 {
     bool b = (f.dStack.Top is ExecutionToken);
     f.dStack.Pop();
     f.PushBool(b);
 }
コード例 #9
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void Not(Forth f)
 {
     bool b = f.PopBool();
     f.PushBool(!b);
 }
コード例 #10
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void IsNotLessThanUnsigned(Forth f)
 {
     ulong b = f.PopUInt64();
     ulong a = f.PopUInt64();
     f.PushBool(a >= b);
 }
コード例 #11
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void IsNotGreaterThanUnsigned(Forth f)
 {
     ulong b = f.PopUInt64();
     ulong a = f.PopUInt64();
     f.PushBool(a <= b);
 }
コード例 #12
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void IsNotLessThan(Forth f)
 {
     long b = f.PopInt64();
     long a = f.PopInt64();
     f.PushBool(a >= b);
 }
コード例 #13
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void IsNotGreaterThan(Forth f)
 {
     long b = f.PopInt64();
     long a = f.PopInt64();
     f.PushBool(a <= b);
 }
コード例 #14
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void DoesNotEqual(Forth f)
 {
     ulong b = f.PopUInt64();
     ulong a = f.PopUInt64();
     f.PushBool(a != b);
 }
コード例 #15
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void Equals(Forth f)
 {
     ulong b = f.PopUInt64();
     ulong a = f.PopUInt64();
     f.PushBool(a == b);
 }
コード例 #16
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void IsNull(Forth f)
 {
     bool b = (f.dStack.Top == null);
     f.dStack.Pop();
     f.dStack.Push(b);
 }
コード例 #17
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void IsLong(Forth f)
 {
     bool b = (f.dStack.Top is long);
     f.dStack.Pop();
     f.PushBool(b);
 }
コード例 #18
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void Dot(Forth f)
 {
     object obj = f.dStack.Pop();
     Console.Write(Convert.ToString(obj));
     Console.Write(" ");
 }
コード例 #19
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void Here(Forth f)
 {
     f.PushInt64((long)(f.here));
 }
コード例 #20
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void UnsignedDot(Forth f)
 {
     object obj = f.dStack.Pop();
     if (obj is long)
     {
         long l = (long)obj;
         ulong u = unchecked((ulong)l);
         obj = u;
     }
     Console.Write(Convert.ToString(obj));
     Console.Write(" ");
 }
コード例 #21
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void At(Forth f)
 {
     long index = f.PopInt64();
     f.dStack.Push(f.memory[(int)index]);
 }
コード例 #22
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);
     }
 }
コード例 #23
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void Off(Forth f)
 {
     long index = f.PopInt64();
     f.memory[(int)index] = 0L;
 }
コード例 #24
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void Backslash(Forth f)
 {
     f.getWord('\n');
 }
コード例 #25
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void Create(Forth f)
 {
     string word = f.getWord(' ');
     f.Define(word, MakeLiteralOp((long)f.here));
 }
コード例 #26
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void LParen(Forth f)
 {
     f.getWord(')');
 }
コード例 #27
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void Variable(Forth f)
 {
     Create(f);
     f.memory[f.here] = null;
     f.here++;
 }
コード例 #28
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void Space(Forth f)
 {
     Console.Write(" ");
 }
コード例 #29
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void Cr(Forth f)
 {
     Console.WriteLine();
 }
コード例 #30
0
ファイル: Forth.cs プロジェクト: Sunlighter/SimpleForth
 public static void Decimal(Forth f)
 {
     f.numericBase = 10;
 }