Exemplo n.º 1
0
        private void DeclareSTD()
        {
            //adding standard function print to the enviornment
            var parameterList1 = new ParameterList(new List <Parameter>());

            parameterList1.Parameters.Add(new Parameter(
                                              new VariableType(VariableType.ValueTypeEnum.ANY),
                                              new UserCreatableID(new Token("blah" /* doesn't matter */, Token.TokenType.USER_CREATABLE_ID))));
            var printFunc = new DeclarationFunctionDeclaration(new FunctionDeclaration(
                                                                   new UserCreatableID(new Token("print", Token.TokenType.USER_CREATABLE_ID)),
                                                                   parameterList1,
                                                                   new ReturnTypeNothing(),
                                                                   new Statements(new List <Statement>())
                                                                   ));

            Encoder.printFunction = printFunc;
            idTable.Add(printFunc.FunctionDeclaration.FunctionName, printFunc, IDTable.DeclarationType.FUNCTION);


            //adding standard function tnirp to the enviornment
            var parameterList2 = new ParameterList(new List <Parameter>());
            var tnirpFunc      = new DeclarationFunctionDeclaration(new FunctionDeclaration(
                                                                        new UserCreatableID(new Token("tnirp", Token.TokenType.USER_CREATABLE_ID)),
                                                                        parameterList2,
                                                                        new ReturnTypeVariableType(new VariableType(VariableType.ValueTypeEnum.INTY)),
                                                                        new Statements(new List <Statement>())
                                                                        ));

            Encoder.tnirpFunction = tnirpFunc;
            idTable.Add(tnirpFunc.FunctionDeclaration.FunctionName, tnirpFunc, IDTable.DeclarationType.FUNCTION);
        }
Exemplo n.º 2
0
        public object VisitDeclarationFunctionDeclaration(DeclarationFunctionDeclaration declarationFunctionDeclaration,
                                                          object o)
        {
            idTable.Add(declarationFunctionDeclaration.FunctionDeclaration.FunctionName, declarationFunctionDeclaration, IDTable.DeclarationType.FUNCTION);

            declarationFunctionDeclaration.FunctionDeclaration.Visit(this);
            return(null);
        }
Exemplo n.º 3
0
        public object VisitDeclarationFunctionDeclaration(DeclarationFunctionDeclaration declarationFunctionDeclaration, object o)
        {
            var savedAddr = nextAdr;

            Emit(Machine.JUMPop, 0, Machine.CBr, -1);
            declarationFunctionDeclaration.FunctionDeclaration.Address.Offset = nextAdr;
            _stackManager.IncrementFrameLevel();
            declarationFunctionDeclaration.FunctionDeclaration.Visit(this);
            _stackManager.DecrementFrameLevel();
            Patch(savedAddr, nextAdr);
            return(null);
        }