예제 #1
0
파일: Scope.cs 프로젝트: redxdev/shogun-old
        public void PushMemory(Kernel k)
        {
            pushed++;

            if (this.MemorySpace == 0)
                return;

            k.Emit(Opcode.PMMX);
            k.EmitPush(this.MemorySpace.ToString() + "u");
            k.Emit(Opcode.AADD);
            k.Emit(Opcode.SMMX).SetDebug(k.FileStack.Peek(), -1, -1, DebugType.PushMem, this.Name);
        }
예제 #2
0
파일: Scope.cs 프로젝트: redxdev/shogun-old
        public void PopMemory(Kernel k, bool clearPush = true)
        {
            if(clearPush && pushed <= 0)
                throw new InvalidOperationException("Unbalanced memory pop; compiler bug?");

            if (clearPush)
                pushed--;

            if (this.MemorySpace == 0)
                return;

            k.EmitPush(this.MemorySpace.ToString() + "u");
            k.Emit(Opcode.PMMX);
            k.Emit(Opcode.ASUB);
            k.Emit(Opcode.SMMX).SetDebug(k.FileStack.Peek(), -1, -1, DebugType.PopMem, this.Name);
        }
예제 #3
0
        static void Main(string[] args)
        {
            if(args.Length != 2)
            {
                Console.WriteLine("Usage:");
                Console.WriteLine("sholan <input> <output>");
                return;
            }

            Console.WriteLine("Creating kernel...");
            Kernel kernel = new Kernel();

            Console.WriteLine("Parsing input...");
            ICompileNode root = null;

            string file = Path.GetFullPath(args[0]);
            kernel.FileStack.Push(file);

            try
            {
                root = LanguageUtilities.ParseFile(file);
            }
            catch(Exception e)
            {
                Console.WriteLine("Error parsing input:");
                Console.WriteLine(e.ToString());
                return;
            }

            Console.WriteLine("Compiling...");
            kernel.AddImportPath(Path.GetDirectoryName(Path.GetFullPath(args[0])));
            try
            {
                kernel.Compile(root);
            }
            catch(Exception e)
            {
                Console.WriteLine("Error compiling:");
                Console.WriteLine(e.ToString());
                return;
            }

            kernel.EndCompile();

            Console.WriteLine("Kernel operation count: " + kernel.Operations.Count);

            Console.WriteLine("Writing assembly...");

            try
            {
                kernel.Write(args[1]);
            }
            catch(Exception e)
            {
                Console.WriteLine("Error writing assembly:");
                Console.WriteLine(e.ToString());
                return;
            }

            Console.WriteLine("Finished compile");
        }