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);
        }