Exemplo n.º 1
0
        public void Visit(ReturnStmnt returnStmnt)
        {
            if (hierarchy.Count == 0)
            {
                throw new CompilationError(ReturnOutsideFunction);
            }
            var func = hierarchy.Peek();

            if (returnStmnt.Values.Count == 0)
            {
                if (func.RetType != null)
                {
                    throw new CompilationError(ObjectRequired);
                }
            }
            else if (returnStmnt.Values.Count == 1)
            {
                returnStmnt.Values[0].Accept(this);
                var type = result.Pop();
                if (func.RetType != null && func.RetType != type)
                {
                    throw new Exception("Not implemented");     // type generaization or type conversion
                }
                else
                {
                    func.RetType = type;
                }
            }
            else
            {
                throw new Exception("Not implemented");         // tuple
            }
        }
Exemplo n.º 2
0
        public void Visit(ReturnStmnt returnStmnt)
        {
            var vals = returnStmnt.Values;

            for (var i = 0; i < vals.Count; i += 1)
            {
                var val = vals[i];
                Replace(ref val);
                vals[i] = val;
            }
        }
Exemplo n.º 3
0
        public void Visit(ReturnStmnt returnStmnt)
        {
            var clone = new ReturnStmnt();

            foreach (var val in returnStmnt.Values)
            {
                val.Accept(this);
                clone.Values.Add(result.Pop());
            }

            result.Push(clone);
        }