Exemple #1
0
        //Compile all declarations including function bindings, name bindings and bindings
        //defined by pattern matching.
        private void CompileDeclaration(ElaEquation s, LabelMap map, Hints hints)
        {
            //Check for some errors
            ValidateBinding(s);
            var partial = (s.VariableFlags & ElaVariableFlags.PartiallyApplied) == ElaVariableFlags.PartiallyApplied;
            var fun     = partial || s.IsFunction();

            if ((s.Left.Type != ElaNodeType.NameReference || ((ElaNameReference)s.Left).Uppercase) && !fun)
            {
                if ((hints & Hints.Lazy) == Hints.Lazy)
                {
                    CompileLazyBindingPattern(s, map);
                }
                else
                {
                    CompileBindingPattern(s, map);
                }
            }
            else
            {
                var nm   = default(String);
                var sv   = GetNoInitVariable(s, out nm);
                var addr = sv.Address;

                if (sv.IsEmpty())
                {
                    addr = AddVariable(s.Left.GetName(), s, s.VariableFlags, -1);
                }
                else
                {
                    CurrentScope.AddFlags(nm, ElaVariableFlags.Self);
                }

                //Compile expression and write it to a variable
                if (fun)
                {
                    //*****CURRENTLY NOT USED!
                    //Here we automatically eta expand functions defined through partial application
                    if (partial)
                    {
                        EtaExpand(s.Left.GetName(), s.Right, map, s.Arguments);
                    }
                    else if (CompileFunction(s, map))
                    {
                        CurrentScope.AddFlags(nm, ElaVariableFlags.Clean); //A function is clean
                    }
                }
                else
                {
                    map.BindingName = s.Left.GetName();

                    if ((hints & Hints.Lazy) == Hints.Lazy)
                    {
                        CompileLazyExpression(s.Right, map, Hints.None);
                    }
                    else
                    {
                        var ed = CompileExpression(s.Right, map, Hints.None, s);

                        if (ed.Type == DataKind.Builtin)
                        {
                            CurrentScope.AddFlagsAndData(nm, ElaVariableFlags.Builtin, ed.Data);
                        }
                    }
                }

                //Now, when done initialization, when can remove NoInit flags.
                if (!sv.IsEmpty())
                {
                    CurrentScope.RemoveFlags(nm, ElaVariableFlags.NoInit | ElaVariableFlags.Self);
                }

                AddLinePragma(s);
                PopVar(addr);
            }
        }