Esempio n. 1
0
        private void Generate(FunctionNode node, List <Instruction> instructions)
        {
            string name = node.functionName.identifier;
            List <ParameterInstruction> parameters = new List <ParameterInstruction>();

            foreach (ParameterNode param in node.parameters)
            {
                parameters.Add(new ParameterInstruction(param.identifier));
            }
            List <Instruction> funcInstructions = new List <Instruction>();

            foreach (StatementNode statement in node.body)
            {
                Generate(statement, funcInstructions);
            }
            ReturnInstruction returnInstruction = null;

            if (node.returnNode != null)
            {
                List <Instruction> returnInstructions = new List <Instruction>();
                returnInstruction = GenerateReturn(node.returnNode);
            }
            instructions.Add(new FunctionInstruction(name, parameters, funcInstructions, returnInstruction));
        }
 public FunctionInstruction(string name, List <ParameterInstruction> parameters, List <Instruction> instructions, ReturnInstruction returnExpression) : base(InstructionType.FUNCTION)
 {
     this.name              = name;
     this.parameters        = parameters;
     this.body              = instructions;
     this.returnInstruction = returnExpression;
 }