Esempio n. 1
0
        private void CompileClassStmt(ClassStatement stmt, Scope scope)
        {
            scope = new Scope {
                Out = scope, LocalTable = new LocalTable(), Self = stmt, Line = 0
            };
            var instructionSet = new InstructionSet();

            instructionSet.SetLabel($"{InstructionType.LabelDefClass}:{stmt.Name.Value}");

            CompileBlockStatement(instructionSet, stmt.Body, scope, scope.LocalTable);
            instructionSet.Define(InstructionType.Leave);
            InstructionSets.Add(instructionSet);
        }
Esempio n. 2
0
        private void CompileBlockArgExpression(int index, CallExpression exp, Scope scope, LocalTable table)
        {
            var instructionSet = new InstructionSet();

            instructionSet.SetLabel($"{InstructionType.Block}:{index}");

            for (int i = 0; i < exp.Arguments.Count; i++)
            {
                table.Set(exp.BlockArguments[i].Value);
            }

            CompileBlockStatement(instructionSet, exp.Block, scope, table);
            EndInstructions(instructionSet);
            InstructionSets.Add(instructionSet);
        }
Esempio n. 3
0
        private void CompileDefStmt(DefStatement stmt, Scope scope)
        {
            scope = new Scope {
                Out = scope, LocalTable = new LocalTable(), Self = stmt, Line = 0
            };
            var instructionSet = new InstructionSet();

            instructionSet.SetLabel($"{InstructionType.LabelDef}:{stmt.Name.Value}");

            for (int i = 0; i < stmt.Parameters.Count; i++)
            {
                scope.LocalTable.SetLCL(stmt.Parameters[i].Value, scope.LocalTable.Depth);
            }

            CompileBlockStatement(instructionSet, stmt.BlockStatement, scope, scope.LocalTable);
            EndInstructions(instructionSet);
            InstructionSets.Add(instructionSet);
        }