Ejemplo n.º 1
0
        public object VisitStatementGiveBack(StatementGiveBack statementGiveBack, object o)
        {
            var functionDeclaration = o as FunctionDeclaration;
            var parametersSize      = functionDeclaration.ParameterList.Parameters.Count; // TODO Parameter size won't work for structs.

            if (statementGiveBack.Expression == null)
            {
                Emit(Machine.RETURNop, 0, 0, parametersSize);
            }
            else
            {
                statementGiveBack.Expression.Visit(this);
                Emit(Machine.RETURNop, 1, 0, parametersSize);
                _stackManager.DecrementOffset();
            }


            return(null);
        }
Ejemplo n.º 2
0
        public object VisitStatementGiveBack(StatementGiveBack statementGiveBack, object o)
        {
            if (idTable.ExpectedReturnType == VariableType.ValueTypeEnum.NOTHING)
            {
                return(null);
            }

            if (statementGiveBack.Expression == null)
            {
                throw new Exception("Giveback statement must return value of type: " + idTable.ExpectedReturnType);
            }

            var expressionVariableType = (VariableType.ValueTypeEnum)statementGiveBack.Expression.Visit(this);

            if (expressionVariableType != idTable.ExpectedReturnType)
            {
                throw new Exception("Give back must return value of expected type");
            }

            return(null);
        }