示例#1
0
        /// <summary>
        /// Loads a compiled Rant program from the specified stream.
        /// </summary>
        /// <param name="programName">The name to give to the program.</param>
        /// <param name="stream">The stream to load the program from.</param>
        /// <returns></returns>
        public static RantProgram LoadStream(string programName, Stream stream)
        {
            if (programName == null)
            {
                throw new ArgumentNullException(nameof(programName));
            }
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            using (var input = new EasyReader(stream))
            {
                if (Encoding.ASCII.GetString(input.ReadBytes(4)) != Magic)
                {
                    throw new InvalidDataException(GetString("err-pgmload-bad-magic"));
                }

                var rst = RST.DeserializeRST(input);

                // TODO: Use string table

                return(new RantProgram(programName, RantProgramOrigin.File, rst));
            }
        }
示例#2
0
 internal override void DeserializeData(EasyReader reader)
 {
     Name       = reader.ReadString();
     SyntaxTree = RST.DeserializeRST(reader);
 }