Exemple #1
0
    public bool visitAssignmentStmt(Statement.Assignment stmt)
    {
        var identifier = stmt.Identifier;

        if (!environment.Contains(identifier.Name))
        {
            ErrorWriter.Write(identifier, "Cannot assign to uninitialized variable '{0}'", identifier.Name);
            return(false);
        }

        var variableType = environment.GetType(identifier.Name);

        var initializerType = stmt.Value.Accept(expressionAnalyzer);

        if (initializerType == null)
        {
            return(false);
        }
        if (initializerType != variableType)
        {
            ErrorWriter.Write(stmt.Value, "Cannot assign value of type {2} to variable {0} of type {1}", identifier.Name, variableType, initializerType);
            return(false);
        }
        if (environment.isLocked(identifier.Name))
        {
            ErrorWriter.Write(stmt.Value, "Cannot reassign loop variable {0} during loop", identifier.Name);
            return(false);
        }

        return(true);
    }
Exemple #2
0
        public ByteCodeChunk VisitAssignment(Statement.Assignment statement)
        {
            var chunk = new ByteCodeChunk();

            if (statement.Target is Expression.AtomReference atom)
            {
                var localIndex = _locals[0].IndexOf(atom.Identifier.Lexeme);
                if (localIndex >= 0)
                {
                    chunk.AddRange(VisitExpression(statement.Value));
                    chunk.AddInstruction(Instruction.Store, (ulong)localIndex);
                }
                else
                {
                    IvyInterpreter.ReportError(statement.Target.Span,
                                               "The assignment target wasn't declared in this scope.");
                }
            }
            else
            {
                IvyInterpreter.ReportError(statement.Target.Span,
                                           "The expression isn't a valid assignment target.");
            }
            return(chunk);
        }
Exemple #3
0
        public override Statement VisitSTMR_Increment([NotNull] S_ScriptParser.STMR_IncrementContext context)
        {
            Statement.AssignmentType v = Statement.AssignmentType.PlusPlus;
            string LibName             = context.name().unit_name().Length == 1 ? SystemNameSpaces.GLOBAL : context.name().unit_name()[0].GetText();
            string VarName             = context.name().unit_name().Length == 1 ? context.name().unit_name()[0].GetText() : context.name().unit_name()[1].GetText();

            if (context.increment().PLUS() != null)
            {
                v = Statement.AssignmentType.PlusPlus;
            }
            else if (context.increment().MINUS() != null)
            {
                v = Statement.AssignmentType.MinusMinus;
            }

            Statement x = new Statement.Assignment(this._Host, this._Master, LibName, VarName, v);

            foreach (S_ScriptParser.ExpressionContext e in context.expression())
            {
                Expression n = this._expr.Visit(e);
                x.Parameters.Add("F" + x.Parameters.Count.ToString(), n);
            }

            return(x);
        }
 public object visitAssignmentStmt(Statement.Assignment stmt)
 {
     if (!environment.Assign(stmt.Identifier.Name, stmt.Value.Accept(this)))
     {
         // TODO is this even possible?
         runtimeError(stmt.Identifier, "Cannot assign to uninitialized variable {0}", stmt.Identifier.Name);
     }
     return(null);
 }
Exemple #5
0
    public object VisitAssignmentStatement(Statement.Assignment stmt)
    {
        var exprType = stmt.Expr.Accept(this);
        var varType  = stmt.Variable.Accept(this);

        if (exprType.ToString() != varType.ToString())
        {
            throw new Exception(string.Format("cannot assign {0} to {1}", exprType, varType));
        }
        return(null);
    }
Exemple #6
0
    public object VisitAssignmentStatement(Statement.Assignment stmt)
    {
        var index = Util.LEB128encode(environment.FindIndex(stmt.Variable.Identifier));

        addInstruction(LOCAL_GET);
        addInstruction(index);
        if (stmt.Variable.Indexer != null)
        {
            stmt.Variable.Indexer.Accept(this);
            addInstruction(I32_CONST);
            addInstruction(4);
            addInstruction(0x6c);
            addInstruction(0x6a); // add index
        }

        stmt.Expr.Accept(this);

        addInstruction(0x36, 0x02, 0x00);

        return(null);
    }
Exemple #7
0
        public override Statement VisitSTMR_Assign([NotNull] S_ScriptParser.STMR_AssignContext context)
        {
            Statement.AssignmentType v = Statement.AssignmentType.Equals;
            bool   assign  = context.assignment().ASSIGN() != null;
            string LibName = context.name().unit_name().Length == 1 ? SystemNameSpaces.GLOBAL : context.name().unit_name()[0].GetText();
            string VarName = context.name().unit_name().Length == 1 ? context.name().unit_name()[0].GetText() : context.name().unit_name()[1].GetText();

            if (this._Context.SpoolExists(LibName) && !this._Context[LibName].Exists(VarName))
            {
                this._Context[LibName].Add(VarName);
            }

            if (assign && context.assignment().PLUS() != null)
            {
                v = Statement.AssignmentType.PlusEquals;
            }
            else if (assign && context.assignment().MINUS() != null)
            {
                v = Statement.AssignmentType.MinusEquals;
            }
            else if (assign && context.assignment().MUL() != null)
            {
                v = Statement.AssignmentType.MultEquals;
            }
            else if (assign && context.assignment().DIV() != null)
            {
                v = Statement.AssignmentType.DivEquals;
            }
            else if (assign && context.assignment().DIV2() != null)
            {
                v = Statement.AssignmentType.Div2Equals;
            }
            else if (assign && context.assignment().MOD() != null)
            {
                v = Statement.AssignmentType.ModEquals;
            }
            else if (assign && context.assignment().MOD2() != null)
            {
                v = Statement.AssignmentType.Mod2Equals;
            }

            // Check if we have a table //
            //if (v == Statement.AssignmentType.PlusEquals && this._Host.Spools.Exists(LibName) && this._Host.Spools[LibName].Exists(VarName) && this._Host.Spools[LibName][VarName].Affinity == CellAffinity.TREF)
            //{
            //    string tref = this._Host.Spools[LibName][VarName].valueTREF;
            //    Table t = this._Host.OpenTable(tref);
            //    Expression a = this._expr.Visit(context.expression()[0]);
            //    bool ContainsAggregate = (a is Expression.ArrayLiteral && a.ContainsAggregate);

            //    Statement s = null;
            //    if (!ContainsAggregate)
            //    {
            //        s = new TableInsert.GenericTableInsert(this._Host, this._Master, t);
            //        s.Parameters.Add(a);
            //    }
            //    else
            //    {
            //        s = new TableInsert.DictionGroupBy(this._Host, this._Master, t);
            //        foreach(Expression exp in a.Children)
            //        {
            //            s.Parameters.Add(exp);
            //        }
            //    }

            //    this._Master = s;
            //    return s;
            //}

            Statement x = new Statement.Assignment(this._Host, this._Master, LibName, VarName, v);

            foreach (S_ScriptParser.ExpressionContext e in context.expression())
            {
                Expression n = this._expr.Visit(e);
                x.Parameters.Add("F" + x.Parameters.Count.ToString(), n);
            }

            return(x);
        }