Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
 public static void Create(Forth f)
 {
     string word = f.getWord(' ');
     f.Define(word, MakeLiteralOp((long)f.here));
 }
Ejemplo n.º 3
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));
             }
         )
     );
 }