示例#1
0
        public static GlulxFunction Read(Memory memory, int address, int ramStart)
        {
            var scanner           = memory.CreateScanner(address);
            var type              = ReadType(scanner);
            var bodyBuilder       = new AstBodyBuilder();
            var addressToLocalMap = ReadLocals(scanner, bodyBuilder);
            var binder            = new InstructionBinder(bodyBuilder, addressToLocalMap, ramStart);

            ReadBody(scanner, binder);
            var body = bodyBuilder.ToBody();

            return(new GlulxFunction(type, address, body));
        }
示例#2
0
        private static void ReadBody(MemoryScanner scanner, InstructionBinder binder)
        {
            while (true)
            {
                // Note: We read instructions until we find an opcode number that we don't know about.

                var address      = scanner.Address;
                var opcodeNumber = ReadOpcodeNumber(scanner);

                if (!Opcodes.TryGetOpcode(opcodeNumber, out var opcode))
                {
                    break;
                }

                var(loadOps, storeOps) = ReadOperands(scanner, opcode);

                var length = scanner.Address - address;

                binder.BindInstruction(opcode, loadOps, storeOps, address, length);
            }
        }