Beispiel #1
0
        public void run()
        {
            m_globalMemorySpace = new MemorySpace("globals");
            m_currentMemorySpace = m_globalMemorySpace;

            execute(m_ast);
        }
Beispiel #2
0
        public void PushMemorySpace(MemorySpace pMemorySpace)
        {
            if(m_memorySpaces.Count > 0 && m_memorySpaces.Peek() == pMemorySpace) {
                //Console.WriteLine("Pushing duplicate memory space, will ignore");
                return;
            }

            //Console.WriteLine("Push " + pMemorySpace.getName() + " into scope " + this.getName());
            m_memorySpaces.Push(pMemorySpace);
        }
Beispiel #3
0
 public void PushMemorySpace(MemorySpace pMemorySpace)
 {
     //Console.WriteLine("Push " + pMemorySpace.getName() + " into scope " + this.getName());
     m_memorySpaces.Push(pMemorySpace);
 }
Beispiel #4
0
        private ReturnValue function(AST tree, List<ReturnValue> parameterValues)
        {
            // Push scope
            Scope m_previousScope = m_currentScope;
            AST_FunctionDefinitionNode functionDefinitionNode = (AST_FunctionDefinitionNode)(tree);
            Assert.IsNotNull(functionDefinitionNode);
            m_currentScope = (Scope)functionDefinitionNode.getScope();
            Assert.IsNotNull(m_currentScope);

            // Push memory space
            MemorySpace m_previousMemorySpace = m_currentMemorySpace;
            MemorySpace functionMemorySpace =
                new MemorySpace("<FUNCTION_SPACE " + tree.getChild(1).getTokenString() + ">");
            m_memoryStack.Push(functionMemorySpace);
            m_currentMemorySpace = functionMemorySpace;

            // Add parameters to memory space
            List<AST> parameterDeclarations = tree.getChild(2).getChildren();
            if(parameterDeclarations != null) {

                if(parameterDeclarations.Count != parameterValues.Count) {
                    m_errorHandler.errorOccured(
                        "The number of arguments in function " +
                        tree.getChild(1).getTokenString() +
                        " does not match!",
                        Error.ErrorType.SYNTAX);
                }

                foreach(AST parameter in parameterDeclarations) {
                    varDeclaration(parameter);
                }
            }

            // Assign values to parameters
            if(parameterValues != null) {
                int i = 0;
                foreach(ReturnValue parameterValue in parameterValues) {

                    string parameterName = parameterDeclarations[i].getChild(1).getTokenString();
                    assignValue(parameterName, parameterValue);
                    i++;
                }
            }

            // Execute function
            ReturnValue returnValue = null;

            try {
                executeAllChildNodes(tree.getChild(3)); // child 3 is the function body
            }
            catch(ReturnValue functionReturnValue) {
                returnValue = functionReturnValue;
            }

            // Pop memory space
            m_memoryStack.Pop();
            m_currentMemorySpace = m_previousMemorySpace;

            // Pop scope
            m_currentScope = m_previousScope;
            Assert.IsNotNull(m_currentScope);

            return returnValue;
        }
Beispiel #5
0
 public void PushMemorySpace(MemorySpace pMemorySpace)
 {
     //Console.WriteLine("Push " + pMemorySpace.getName() + " into scope " + this.getName());
     m_memorySpaces.Push(pMemorySpace);
 }
Beispiel #6
0
        private ReturnValue function(AST tree, List <ReturnValue> parameterValues)
        {
            // Push scope
            Scope m_previousScope = m_currentScope;
            AST_FunctionDefinitionNode functionDefinitionNode = (AST_FunctionDefinitionNode)(tree);

            Assert.IsNotNull(functionDefinitionNode);
            m_currentScope = (Scope)functionDefinitionNode.getScope();
            Assert.IsNotNull(m_currentScope);

            // Push memory space
            MemorySpace m_previousMemorySpace = m_currentMemorySpace;
            MemorySpace functionMemorySpace   =
                new MemorySpace("<FUNCTION_SPACE " + tree.getChild(1).getTokenString() + ">");

            m_memoryStack.Push(functionMemorySpace);
            m_currentMemorySpace = functionMemorySpace;

            // Add parameters to memory space
            List <AST> parameterDeclarations = tree.getChild(2).getChildren();

            if (parameterDeclarations != null)
            {
                if (parameterDeclarations.Count != parameterValues.Count)
                {
                    m_errorHandler.errorOccured(
                        "The number of arguments in function " +
                        tree.getChild(1).getTokenString() +
                        " does not match!",
                        Error.ErrorType.SYNTAX);
                }

                foreach (AST parameter in parameterDeclarations)
                {
                    varDeclaration(parameter);
                }
            }

            // Assign values to parameters
            if (parameterValues != null)
            {
                int i = 0;
                foreach (ReturnValue parameterValue in parameterValues)
                {
                    string parameterName = parameterDeclarations[i].getChild(1).getTokenString();
                    assignValue(parameterName, parameterValue);
                    i++;
                }
            }

            // Execute function
            ReturnValue returnValue = null;

            try {
                executeAllChildNodes(tree.getChild(3));                 // child 3 is the function body
            }
            catch (ReturnValue functionReturnValue) {
                returnValue = functionReturnValue;
            }

            // Pop memory space
            m_memoryStack.Pop();
            m_currentMemorySpace = m_previousMemorySpace;

            // Pop scope
            m_currentScope = m_previousScope;
            Assert.IsNotNull(m_currentScope);

            return(returnValue);
        }