示例#1
0
        object Expr.Visitor <object> .VisitAssignExpr(Expr.Assign expr)
        {
            Object value = Evaluate(expr.value);

            environment.Assign(expr.name, value);
            return(value);
        }
示例#2
0
        public Unit VisitAssignExpr(Expr.Assign expr)
        {
            Resolve(expr.Value);
            ResolveLocal(expr, expr.Name);

            return(new Unit());
        }
示例#3
0
        public object VisitAssignExpr(Expr.Assign expr)
        {
            object value = Evaluate(expr.Value);

            environment.Assign(expr.Name, value);
            return(value);
        }
示例#4
0
        public object visitAssign(Expr.Assign assign)
        {
            object value = evaluate(assign.Value);

            environment.assign(assign.Name, value);
            return(value);
        }
示例#5
0
        public VoidObject VisitAssignExpr(Expr.Assign expr)
        {
            Resolve(expr.Value);
            ResolveLocalOrGlobal(expr, expr.Name);

            return(VoidObject.Void);
        }
        public object VisitAssignExpr(Expr.Assign expr)
        {
            Resolve(expr.value);
            ResolveLocal(expr, expr.name, false);

            return(null);
        }
        public override VoidObject VisitAssignExpr(Expr.Assign expr)
        {
            base.VisitAssignExpr(expr);

            Binding variableBinding = GetVariableOrFunctionCallback(expr);

            if (variableBinding == null)
            {
                // An attempt is made to assign a value to an undefined variable. This is an error, but it's handled
                // elsewhere so we can silently ignore it at this point.
                return(VoidObject.Void);
            }

            if (variableBinding is FunctionBinding)
            {
                // Functions are immutable, handled by a class in the Perlang.Interpreter.Immutability namespace. We can
                // ignore it at this point; the attempt to reassign it will be detected elsewhere.
                return(VoidObject.Void);
            }

            var  targetTypeReference     = variableBinding.TypeReference;
            var  sourceTypeReference     = expr.Value.TypeReference;
            long?sourceConstantValueSize = null;

            if (expr.Value is Expr.Literal {
                Value : INumericLiteral parsedNumber
            })
示例#8
0
        public override VoidObject VisitAssignExpr(Expr.Assign expr)
        {
            base.VisitAssignExpr(expr);

            // Letting the type be inferred in an assignment expression is important to make constructs like
            // "var i = 100; var j = i+= 2;" work correctly. This is indeed an odd way of writing code, but as long
            // as += is an expression and not a statement, we need to have predictable semantics for cases like
            // this.
            if (!expr.TypeReference.IsResolved && expr.Value.TypeReference.IsResolved)
            {
                expr.TypeReference.ClrType = expr.Value.TypeReference.ClrType;
            }

            return(VoidObject.Void);
        }
示例#9
0
    public object VisitAssignExpr(Expr.Assign expr)
    {
        object value = Evaluate(expr.Value);
        int    distance;

        if (Locals.TryGetValue(expr, out distance))
        {
            Environment.AssignAt(distance, expr.Name, value);
        }
        else
        {
            Globals.Assign(expr.Name, value);
        }

        return(value);
    }
        public object VisitAssignExpr(Expr.Assign expr)
        {
            var value = Evaluate(expr.value);

            var valuePresent = _locals.TryGetValue(expr, out var distance);

            if (valuePresent)
            {
                _environment.AssignAt(distance, expr.name, value);
            }
            else
            {
                Globals.Assign(expr.name, value);
            }

            return(value);
        }
示例#11
0
        public object visitAssignExpr(Expr.Assign expr)
        {
            object value = evaluate(expr.value);

            int distance;

            if (locals.ContainsKey(expr))
            {
                distance = locals[expr];
                environment.assignAt(distance, expr.name, value);
            }
            else
            {
                globals.assign(expr.name, value);
            }
            return(value);
        }
示例#12
0
        public object Visit(Expr.Assign expr)
        {
            object value = Evaluate(expr.value);

            int?distance = _locals.Get(expr);

            if (distance != null)
            {
                _environment.AssignAt(distance.Value, expr.Name, value);
            }
            else
            {
                _globals.Assign(expr.Name, value);
            }


            return(value);
        }
示例#13
0
        public override VoidObject VisitAssignExpr(Expr.Assign expr)
        {
            base.VisitAssignExpr(expr);

            Binding?binding = getVariableOrFunctionBinding(expr);

            // 'null' here can either be because of an internal error (failure to locate a binding that _should_ exist),
            // or a completely valid case when trying to reassign an undefined variable. Regretfully, we cannot
            // distinguish between these two scenarios at the moment.
            if (binding?.IsImmutable == true)
            {
                immutabilityValidationErrorCallback(new ImmutabilityValidationError(
                                                        expr.Name,
                                                        $"{binding.ObjectTypeTitleized} '{expr.Name.Lexeme}' is immutable and cannot be modified."
                                                        ));
            }

            return(VoidObject.Void);
        }
示例#14
0
 public string VisitAssignExpr(Expr.Assign expr)
 {
     return($"{expr.Name.Lexeme} = {PrintExpr(expr.Value)}");
 }
示例#15
0
 public string VisitAssignExpr(Expr.Assign expr)
 {
     return(Parenthesize(expr.Name.Lexeme, expr.Value));
 }
示例#16
0
        public TypeSpecifier VisitAssignmentExpression(Expr.Assign exp)
        {
            if (exp.Var is Expr.Variable exprname)
            {
                var name     = exprname.Name.Source;
                var variable = _namedValues[name];

                var type  = Visit(exp.Value);
                var value = _valueStack.Pop();

                var casted = CheckedCast(value, type, variable.KtsType);

                var store = LLVM.BuildStore(_builder, casted, variable.Value);
                _valueStack.Push(store);

                if (variable.Binding != null)
                {
                    HandleBinding(variable, false);
                }

                return(variable.KtsType);
            }
            else if (exp.Var is Expr.IndexAccess exprindex)
            {
                var name     = exprindex.Identifier.Source;
                var variable = _namedValues[name];
                var vartype  = new TypeSpecifier {
                    Dimensions = 0, Type = variable.KtsType.Type
                };

                if (variable.IsDecayed)
                {
                    LLVMValueRef[] indices = new LLVMValueRef[exprindex.Expressions.Count];

                    for (int i = 0; i < indices.Length; i++)
                    {
                        var indexType = Visit(exprindex.Expressions[i]);
                        var indexVal  = _valueStack.Pop();

                        var integerIndex = CheckedCast(indexVal, indexType, new TypeSpecifier {
                            Dimensions = 0, Type = TypeEnum.I64
                        });
                        indices[i] = integerIndex;
                    }

                    var load    = LLVM.BuildLoad(_builder, variable.Value, "");
                    var address = LLVM.BuildInBoundsGEP(_builder, load, indices, "");

                    var exprType = Visit(exp.Value);
                    var exprVal  = _valueStack.Pop();

                    var casted = CheckedCast(exprVal, exprType, vartype);

                    LLVMValueRef store = LLVM.BuildStore(_builder, casted, address);
                    _valueStack.Push(store);

                    return(vartype);
                }
                else
                {
                    LLVMValueRef[] indices = new LLVMValueRef[exprindex.Expressions.Count + 1];

                    indices[0] = LLVM.ConstInt(LLVM.Int64Type(), 0, _lFalse);

                    for (int i = 1; i < indices.Length; i++)
                    {
                        var indexType = Visit(exprindex.Expressions[i - 1]);
                        var indexVal  = _valueStack.Pop();

                        var integerIndex = CheckedCast(indexVal, indexType, new TypeSpecifier {
                            Dimensions = 0, Type = TypeEnum.I64
                        });
                        indices[i] = integerIndex;
                    }

                    var address = LLVM.BuildInBoundsGEP(_builder, variable.Value, indices, "");

                    var exprType = Visit(exp.Value);
                    var exprVal  = _valueStack.Pop();

                    var casted = CheckedCast(exprVal, exprType, vartype);

                    LLVMValueRef store = LLVM.BuildStore(_builder, casted, address);
                    _valueStack.Push(store);

                    if (variable.Binding != null)
                    {
                        HandleBinding(variable, false);
                    }

                    return(vartype);
                }
            }
            else
            {
                throw new Exception("Should be either index access or primitive assignment");
            }
        }
示例#17
0
 public string VisitAssignExpr(Expr.Assign expr)
 {
     return(Printer(expr.Name.Lexeme, expr.Value));
 }
示例#18
0
 public string visitAssignExpr(Expr.Assign expr)
 {
     throw new NotImplementedException();
 }
示例#19
0
 public object VisitAssignExpr(Expr.Assign expr, object options = null)
 {
     return(null);
 }
示例#20
0
 public T VisitAssignmentExpression(Expr.Assign exp);
示例#21
0
 public string VisitAssignExpr(Expr.Assign expr)
 {
     throw new System.NotImplementedException();
 }
示例#22
0
 public object VisitAssignExpr(Expr.Assign expr, object options)
 {
     return(Parenthesize2("=", expr.token.lexeme, expr.value));
 }
示例#23
0
 public object visitAssignExpr(Expr.Assign expr)
 {
     captureToken(expr.name);
     setNamedVariable(expr.name, expr.value);
     return(null);
 }
示例#24
0
 public object visitAssignExpr(Expr.Assign expr)
 {
     resolve(expr.value);
     resolveLocal(expr, expr.name);
     return(null);
 }
示例#25
0
 public string visitAssign(Expr.Assign assign)
 {
     throw new System.NotImplementedException();
 }
示例#26
0
 public string VisitAssignExpr(Expr.Assign expr)
 {
     return(Parenthesize("=", expr.value));
 }
示例#27
0
文件: Resolver.cs 项目: sisakat/cslox
 public object VisitAssignExpr(Expr.Assign expr)
 {
     Resolve(expr.Value);
     ResolveLocal(expr, expr.Name);
     return(null);
 }