Exemple #1
0
 private bool BuildAssignment(DAssignment node, Hints hints, CompilerContext ctx)
 {
     Build(node.Value, hints.Append(Push), ctx);
     Build(node.Target, hints.Remove(Push).Append(Pop), ctx);
     PushIf(hints);
     return(true);
 }
Exemple #2
0
    private bool Build(DAssignment node, Hints hints, CompilerContext ctx)
    {
        ValidateAssignment(node);

        if (node.Target.NodeType is NodeType.Access && IsMemberAccess(node.Target) && node.AutoAssign is BinaryOperator.Coalesce)
        {
            return(BuildSetterCoalesce(node, hints, ctx));
        }

        if (node.Target.NodeType is NodeType.Access && IsMemberAccess(node.Target) && node.AutoAssign is not null)
        {
            return(BuildSetterAutoAssign(node, hints, ctx));
        }

        if (node.Target.NodeType is NodeType.Access && IsMemberAccess(node.Target))
        {
            return(BuildSetter(node, hints, ctx));
        }

        if (node.AutoAssign is BinaryOperator.Coalesce)
        {
            return(BuildCoalesce(node, hints, ctx));
        }

        if (node.AutoAssign is not null)
        {
            return(BuildAutoAssign(node, hints, ctx));
        }

        return(BuildAssignment(node, hints, ctx));
    }
Exemple #3
0
    private bool BuildSetter(DAssignment node, Hints hints, CompilerContext ctx)
    {
        var acc = (DAccess)node.Target;

        EmitSetter(acc.Target, node.Value, acc.Name, hints, ctx);
        return(true);
    }
Exemple #4
0
        private void Build(DAssignment node, Hints hints, CompilerContext ctx)
        {
            CheckTarget(node.Target);

            if (node.AutoAssign == BinaryOperator.Coalesce)
            {
                BuildCoalesce(node, hints, ctx);
                return;
            }

            if (node.AutoAssign != null)
            {
                Build(node.Target, hints.Append(Push), ctx);
            }

            Build(node.Value, hints.Append(Push), ctx);

            if (node.AutoAssign != null)
            {
                EmitBinaryOp(node.AutoAssign.Value);
            }

            Build(node.Target, hints.Append(Pop), ctx);

            if (hints.Has(Push))
            {
                cw.PushNil();
            }
        }
        public ActionResult AddAssignment(AttendanceProgress c)
        {
            try
            {
                if (c.file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(c.file.FileName);
                    var path     = Path.Combine(Server.MapPath("~/assignments"), fileName);
                    c.file.SaveAs(path);
                    DAssignment m = new DAssignment()
                    {
                        CourseName   = c.assignment.CourseName,
                        Date         = c.assignment.Date,
                        FilePath     = path,
                        StudentEmail = c.assignment.StudentEmail
                    };
                    // m.FilePath = path;
                    db.assignments.Add(m);
                    db.SaveChanges();
                }

                return(RedirectToAction("Index", "Home"));
            }
            catch
            {
                ViewBag.Message = "Upload failed";
                return(View());
            }
        }
Exemple #6
0
    private bool BuildCoalesce(DAssignment node, Hints hints, CompilerContext ctx)
    {
        var exitLab = cw.DefineLabel();

        Build(node.Target, hints.Remove(Last).Append(Push), ctx);
        cw.Brtrue(exitLab);
        Build(node.Value, hints.Append(Push), ctx);
        Build(node.Target, hints.Append(Pop), ctx);
        cw.MarkLabel(exitLab);
        cw.Nop();
        PushIf(hints);
        return(true);
    }
Exemple #7
0
    private bool BuildSetterCoalesce(DAssignment node, Hints hints, CompilerContext ctx)
    {
        var exitLab = cw.DefineLabel();
        var acc     = (DAccess)node.Target;

        EmitGetter(acc.Target, acc.Name, hints, ctx);
        cw.Brtrue(exitLab);
        EmitSetter(acc.Target, node.Value, acc.Name, hints.Remove(Push), ctx);
        cw.MarkLabel(exitLab);
        cw.Nop();
        PushIf(hints);
        return(true);
    }
Exemple #8
0
    private bool BuildAutoAssign(DAssignment node, Hints hints, CompilerContext ctx)
    {
        Build(node.Target, hints.Append(Push), ctx);
        Build(node.Value, hints.Append(Push), ctx);
        EmitBinaryOp(node.AutoAssign !.Value);

        if (ErrorCount == 0) //To avoid double error reporting
        {
            Build(node.Target, hints.Append(Pop), ctx);
        }

        PushIf(hints);
        return(true);
    }
Exemple #9
0
    private bool BuildSetterAutoAssign(DAssignment node, Hints hints, CompilerContext ctx)
    {
        var acc = (DAccess)node.Target;

        Build(acc.Target, hints.Remove(Last).Append(Push), ctx);
        cw.GetMember(Builtins.Setter(acc.Name));
        cw.FunPrep(1);
        EmitGetter(acc.Target, acc.Name, hints, ctx);
        Build(node.Value, hints.Append(Push), ctx);
        EmitBinaryOp(node.AutoAssign !.Value);
        cw.FunArgIx(0);
        cw.FunCall(1);
        PopIf(hints);
        return(true);
    }
Exemple #10
0
        private void BuildCoalesce(DAssignment node, Hints hints, CompilerContext ctx)
        {
            CheckTarget(node.Target);

            var exitLab = cw.DefineLabel();

            Build(node.Target, hints.Remove(Last).Append(Push), ctx);
            cw.Brtrue(exitLab);
            Build(node.Value, hints.Append(Push), ctx);
            Build(node.Target, hints.Append(Pop), ctx);
            cw.MarkLabel(exitLab);
            cw.Nop();

            if (hints.Has(Push))
            {
                cw.Dup();
            }
        }
Exemple #11
0
    private void ValidateAssignment(DAssignment node)
    {
        if (node.Target.NodeType != NodeType.Name &&
            node.Target.NodeType != NodeType.Index &&
            node.Target.NodeType != NodeType.Access)
        {
            AddError(CompilerError.UnableAssignExpression, node.Target.Location, node.Target);
        }

        if (node.Target.NodeType == node.Value.NodeType &&
            node.Target.NodeType == NodeType.Name &&
            node.Target is INamedNode nn1 &&
            node.Value is INamedNode nn2 &&
            nn1.NodeName == nn2.NodeName &&
            node.AutoAssign is null)
        {
            AddWarning(CompilerWarning.AssignmentSameVariable, node.Location);
        }
    }