예제 #1
0
파일: Debugger.cs 프로젝트: jdruin/F5Eagle
        ///////////////////////////////////////////////////////////////////////

        #region Public Constructors
        public Debugger(
            bool isolated,
            string culture,
            CreateFlags createFlags,
            InitializeFlags initializeFlags,
            ScriptFlags scriptFlags,
            InterpreterFlags interpreterFlags,
            AppDomain appDomain,
            IHost host,
            string libraryPath,
            StringList autoPathList
            )
        {
            interpreter = isolated ? DebuggerOps.CreateInterpreter(
                culture, createFlags, initializeFlags, scriptFlags,
                interpreterFlags, appDomain, host, libraryPath,
                autoPathList) : null;

            ReturnCode code;
            Result     error = null;

            code = Initialize(ref error);

            if (code != ReturnCode.Ok)
            {
                DebugOps.Complain(interpreter, code, error);
            }
        }
예제 #2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="staticMemoryAddr">Base of static memory.</param>
 /// <param name="highMemoryAddr">Base of high memory.</param>
 /// <param name="initProgramCounterAddr">Initial address of the program counter.</param>
 /// <param name="dictionaryAddr">Address of the dictionary table.</param>
 /// <param name="objectTableAddr">Address of the object table.</param>
 /// <param name="globalVariablesTableAddr">Address of the global variables table.</param>
 /// <param name="headerExtensionTableAddr">Address of the header extension table.</param>
 /// <param name="releaseNumber">Release number given to this story file.</param>
 public ZHeader(ushort staticMemoryAddr, ushort highMemoryAddr, ushort initProgramCounterAddr, ushort dictionaryAddr, ushort objectTableAddr, ushort globalVariablesTableAddr, ushort headerExtensionTableAddr, ushort releaseNumber)
 {
     _versionNumber = 0x08;                                  // CodeGen supports version 8 only.
     _interpreterFlags = InterpreterFlags.None;              // Flags set by the interpreter. Let it be zero for a new story file.
     _releaseNumber = releaseNumber;                         // Release Number of this story file.
     _highMemoryAddr = highMemoryAddr;                       // Base of high memory. 0xFFFF
     _initProgramCounterAddr = initProgramCounterAddr;       // Initial value of program counter. 0x2000
     _dictionaryAddr = dictionaryAddr;                       // Points to the Dictionary Table. 0x4000
     _objectTableAddr = objectTableAddr;                     // Points to the Object Table. 0x0048
     _globalVariablesTableAddr = globalVariablesTableAddr;   // Points to the Global Variables Table. 0x0048
     _staticMemoryAddr = staticMemoryAddr;                   // Base of static memory. 0x4000
     _gameFlags = GameFlags.None;                            // Flags set by the game. Zero at start.
     _serialNumber = new byte[6];                            // Let's ignore the serial number for now.
     _abbreviationsTableAddr = 0x0000;                       // Not supported yet.
     _lengthOfStoryFile = 0x0000;                            // Not supported yet.
     _checksumOfStoryFile = 0x0000;                          // Not supported yet.
     _interpreterNumber = 0x00;                              // Set by interpreter.
     _interpreterVersion = 0x00;                             // Set by interpreter.
     _screenHeightInLines = 0x00;                            // Set by interpreter.
     _screenWidthInChars = 0x00;                             // Set by interpreter.
     _screenWidthInUnits = 0x0000;                           // Set by interpreter.
     _screenHeightInUnits = 0x0000;                          // Set by interpreter.
     _fontHeightInUnits = 0x00;                              // Set by interpreter.
     _fontWidthInUnits = 0x00;                               // Set by interpreter.
     _routinesOffset = 0x0000;                               // Is this version 6 only?
     _staticStringsOffset = 0x0000;                          // Is this version 6 only?
     _defaultBackgroundColor = 0x00;                         // Set by interpreter.
     _defaultForegroundColor = 0x00;                         // Set by interpreter.
     _terminatingCharsTableAddr = 0x0000;                    // Not supported yet.
     _textWidthForOutputStream3 = 0x0000;                    // Is this version 6 only?
     _standardRevisionNumber = 0x0000;                       // Set by interpreter.
     _alphabetTableAddr = 0x0000;                            // Not supported yet.
     _headerExtensionTableAddr = headerExtensionTableAddr;   // Points to Header Extension Table. 0x0040
 }
예제 #3
0
        ///////////////////////////////////////////////////////////////////////

        public static Interpreter CreateInterpreter(
            string culture,
            CreateFlags createFlags,
            InitializeFlags initializeFlags,
            ScriptFlags scriptFlags,
            InterpreterFlags interpreterFlags,
            AppDomain appDomain,
            IHost host,
            string libraryPath,
            StringList autoPathList,
            ref Result result
            )
        {
            //
            // NOTE: First, mask off flags that we know to be invalid for all
            //       debugger interpreters.  Next, add flags to force a cloned
            //       interpreter host to be created and used.  Finally, create
            //       an isolated debugging interpreter with the right set of
            //       options.
            //
            createFlags &= ~CreateFlags.NonDebuggerUse;
            createFlags |= CreateFlags.CloneHost;

            return(Interpreter.Create(
                       culture, createFlags, initializeFlags, scriptFlags,
                       interpreterFlags, appDomain, host, libraryPath,
                       autoPathList, ref result));
        }
예제 #4
0
        ///////////////////////////////////////////////////////////////////////

        #region Debugger Interpreter Support Methods
#if DEBUGGER
        public static Interpreter CreateInterpreter(
            string culture,
            CreateFlags createFlags,
            InitializeFlags initializeFlags,
            ScriptFlags scriptFlags,
            InterpreterFlags interpreterFlags,
            AppDomain appDomain,
            IHost host,
            string libraryPath,
            StringList autoPathList
            )
        {
            Result result = null;

            Interpreter interpreter = CreateInterpreter(
                culture, createFlags, initializeFlags, scriptFlags,
                interpreterFlags, appDomain, host, libraryPath,
                autoPathList, ref result);

            if (interpreter == null)
            {
                DebugOps.Complain(interpreter, ReturnCode.Error, result);
            }

            return(interpreter);
        }
예제 #5
0
        ///////////////////////////////////////////////////////////////////////

        /* NOTE: For use by [test2] and CreateSlaveInterpreter ONLY. */
        internal static InterpreterHelper Create(
            AppDomain appDomain,
            IEnumerable <string> args,
            CreateFlags createFlags,
            InitializeFlags initializeFlags,
            ScriptFlags scriptFlags,
            InterpreterFlags interpreterFlags,
            string text,
            string libraryPath,
            StringList autoPathList,
            ref Result result
            )
        {
            if (appDomain == null)
            {
                result = "invalid application domain";
                return(null);
            }

            if (assemblyName == null)
            {
                result = "invalid assembly name";
                return(null);
            }

            if (typeName == null)
            {
                result = "invalid type name";
                return(null);
            }

            try
            {
                object[] ctorArgs =
                {
                    args,             createFlags, initializeFlags, scriptFlags,
                    interpreterFlags, text,        libraryPath,     autoPathList,
                    result
                };

                InterpreterHelper interpreterHelper =
                    (InterpreterHelper)appDomain.CreateInstanceAndUnwrap(
                        assemblyName.ToString(), typeName, false,
                        MarshalOps.PrivateCreateInstanceBindingFlags,
                        null, ctorArgs, null, null, null);

                //
                // NOTE: Grab the result as it may have been modified.
                //
                result = ctorArgs[ctorArgs.Length - 1] as Result;

                return(interpreterHelper);
            }
            catch (Exception e)
            {
                result = e;
            }

            return(null);
        }
예제 #6
0
        ///////////////////////////////////////////////////////////////////////

        public static bool HasFlags(
            InterpreterFlags flags,
            InterpreterFlags hasFlags,
            bool all
            )
        {
            if (all)
            {
                return((flags & hasFlags) == hasFlags);
            }
            else
            {
                return((flags & hasFlags) != InterpreterFlags.None);
            }
        }
예제 #7
0
        ///////////////////////////////////////////////////////////////////////

        public static IDebugger Create(
            bool isolated,
            string culture,
            CreateFlags createFlags,
            InitializeFlags initializeFlags,
            ScriptFlags scriptFlags,
            InterpreterFlags interpreterFlags,
            AppDomain appDomain,
            IHost host,
            string libraryPath,
            StringList autoPathList
            )
        {
            return(new Debugger(
                       isolated, culture, createFlags, initializeFlags, scriptFlags,
                       interpreterFlags, appDomain, host, libraryPath, autoPathList));
        }
예제 #8
0
        ///////////////////////////////////////////////////////////////////////

        //
        // NOTE: For use by the associated InterpreterHelper.Create method
        //       overload ONLY.
        //
        private InterpreterHelper(
            IEnumerable <string> args,
            CreateFlags createFlags,
            InitializeFlags initializeFlags,
            ScriptFlags scriptFlags,
            InterpreterFlags interpreterFlags,
            string text,
            string libraryPath,
            StringList autoPathList,
            ref Result result
            )
        {
            interpreter = Interpreter.Create(
                args, createFlags, initializeFlags, scriptFlags,
                interpreterFlags, text, libraryPath, autoPathList,
                ref result);
        }
예제 #9
0
        ///////////////////////////////////////////////////////////////////////

        #region IExecute Members
        public override ReturnCode Execute(
            Interpreter interpreter,
            IClientData clientData,
            ArgumentList arguments,
            ref Result result
            )
        {
            if (interpreter == null)
            {
                result = "invalid interpreter";
                return(ReturnCode.Error);
            }

            if (arguments == null)
            {
                result = "invalid argument list";
                return(ReturnCode.Error);
            }

            if (arguments.Count < 2)
            {
                result = "wrong # args: should be \"source ?options? fileName\"";
                return(ReturnCode.Error);
            }

            ReturnCode code = ReturnCode.Ok;

            OptionDictionary options = new OptionDictionary(
                new IOption[] {
                new Option(null, OptionFlags.MustHaveEncodingValue,
                           Index.Invalid, Index.Invalid, "-encoding", null),
                new Option(null, OptionFlags.MustHaveBooleanValue,
                           Index.Invalid, Index.Invalid, "-withinfo", null),
                new Option(null, OptionFlags.None, Index.Invalid,
                           Index.Invalid, Option.EndOfOptions, null)
            });

            int argumentIndex = Index.Invalid;

            if (arguments.Count > 2)
            {
                if (interpreter.GetOptions(
                        options, arguments, 0, 1, Index.Invalid, false,
                        ref argumentIndex, ref result) != ReturnCode.Ok)
                {
                    return(ReturnCode.Error);
                }
            }
            else
            {
                argumentIndex = 1;
            }

            if ((argumentIndex == Index.Invalid) ||
                ((argumentIndex + 1) != arguments.Count))
            {
                if ((argumentIndex != Index.Invalid) &&
                    Option.LooksLikeOption(arguments[argumentIndex]))
                {
                    result = OptionDictionary.BadOption(
                        options, arguments[argumentIndex]);
                }
                else
                {
                    result = "wrong # args: should be \"source ?options? fileName\"";
                }

                return(ReturnCode.Error);
            }

            Variant  value    = null;
            Encoding encoding = null;

            if (options.IsPresent("-encoding", ref value))
            {
                encoding = (Encoding)value.Value;
            }

            bool withInfo = false;

            if (options.IsPresent("-withinfo", ref value))
            {
                withInfo = (bool)value.Value;
            }

            if (code == ReturnCode.Ok)
            {
                string name = StringList.MakeList(
                    "source", arguments[argumentIndex]);

                ICallFrame frame = interpreter.NewTrackingCallFrame(
                    name, CallFrameFlags.Source);

                interpreter.PushAutomaticCallFrame(frame);

                try
                {
#if ARGUMENT_CACHE
                    CacheFlags savedCacheFlags = CacheFlags.None;

                    if (withInfo)
                    {
                        interpreter.BeginNoArgumentCache(
                            ref savedCacheFlags);
                    }

                    try
                    {
#endif
#if DEBUGGER && BREAKPOINTS
                    InterpreterFlags savedInterpreterFlags =
                        InterpreterFlags.None;

                    if (withInfo)
                    {
                        interpreter.BeginArgumentLocation(
                            ref savedInterpreterFlags);
                    }

                    try
                    {
#endif

                    code = interpreter.EvaluateFile(
                        encoding, arguments[argumentIndex],
                        ref result);
#if DEBUGGER && BREAKPOINTS
                }
                finally
                {
                    if (withInfo)
                    {
                        interpreter.EndArgumentLocation(
                            ref savedInterpreterFlags);
                    }
                }
#endif
#if ARGUMENT_CACHE
                }
                finally
                {
                    if (withInfo)
                    {
                        interpreter.EndNoArgumentCache(
                            ref savedCacheFlags);
                    }
                }
#endif
                }
                finally
                {
                    //
                    // NOTE: Pop the original call frame that we pushed above
                    //       and any intervening scope call frames that may be
                    //       leftover (i.e. they were not explicitly closed).
                    //
                    /* IGNORED */
                    interpreter.PopScopeCallFramesAndOneMore();
                }
            }

            return(code);
        }