Exemple #1
0
        private void ChunkDeclaration()
        {
            Expect(TokenType.Identifier);
            string chunkIdentifier = scanner.CurrValue;

            if (chunks.ContainsKey(chunkIdentifier))
            {
                Error("Chunk '{0}' already declared.", chunkIdentifier);
            }
            scanner.Scan();

            // Reset variables:
            variables.Clear();
            currVarIndex = 0;
            DeclareVariable("chunksize", InternalType.Integer);

            // Clear code:
            Array.Clear(code, 0, code.Length);
            codePosition = 0;

            Statement();

            EmitOpcode(Opcodes.END);
            byte[] chunkCode = new byte[codePosition];
            Array.Copy(code, chunkCode, codePosition);
            chunks.Add(chunkIdentifier, chunkCode);
        }
Exemple #2
0
        public List <ChunkSpecValue> Interpret(Chunk chunk)
        {
            string id = rxReplaceSpecialChars.Replace(chunk.ChunkTypeId, "_");

            specValues.Clear();

            if (!specs.ContainsKey(id))
            {
                return(specValues);
            }

            variables.Clear();

            AddVariable(0, InternalType.Integer, (long)(chunk.Size));

            stack.Clear();

            code    = specs[id];
            codePos = 0;

            using (ChunkStream chunkStream = chunk.GetStream())
            {
                using (reader = new BinReader(chunkStream))
                {
                    byte opcode;
                    do
                    {
                        opcode = code[codePos++];

                        Debug.Assert(opcodes.ContainsKey(opcode));

                        opcodes[opcode]();
                        //Trace.TraceInformation("Opcode {0}", opcodes[opcode].Method.Name);
                    } while (opcode != Opcodes.END);
                }
            }
            return(specValues);
        }