Beispiel #1
0
 public static Value GetDatum(Syntax syn)
 {
     return(syn.GetDatum());
 }
Beispiel #2
0
 public AstSequence(Syntax syntax, Syntax keyword, LinkedList <Value> expression) : base(syntax)
 {
     Keyword        = keyword;
     BodyExpression = expression;
 }
Beispiel #3
0
 public AST(Syntax syntax)
 {
     Expression = syntax;
 }
Beispiel #4
0
 public AstPrimitive(Syntax syntax, Syntax identifier, LinkedList <Value> arguments) : base(syntax)
 {
     Identifier = identifier;
     Arguments  = arguments;
 }
Beispiel #5
0
 public AstApplication(Syntax syntax, LinkedList <Value> expression) : base(syntax)
 {
     list = expression;
 }
Beispiel #6
0
        public LinkedList <Value> ElseCase;       //< else condition

        public AstCondition(Syntax syntax, Syntax keyword, LinkedList <Value> conditions, LinkedList <Value> elseCase) : base(syntax)
        {
            Keyword    = keyword;
            Conditions = conditions;
            ElseCase   = elseCase;
        }
Beispiel #7
0
 /// <summary>
 /// Create new reference
 /// </summary>
 /// <param name="syntax">reference's syntax</param>
 /// <param name="argIdx">index in local scope</param>
 /// <param name="upEnvIdx">index (relative offset) of environment</param>
 /// <param name="upVarIdx">index of variable inside referenced environment</param>
 public AstReference(Syntax syntax, AstReferenceType type, int argIdx) : base(syntax)
 {
     ReferenceType = type;
     VarIdx        = (byte)argIdx;
 }
Beispiel #8
0
 public AstLiteral(Syntax stx, bool isSyntaxLiteral = false) : base(stx)
 {
     this.isSyntaxLiteral = isSyntaxLiteral;
 }
Beispiel #9
0
        // aka: x
        public static AST ExpandIdentifier(Syntax syntax, Environment env)
        {
            if (!syntax.IsIdentifier)
            {
                throw SchemeError.SyntaxError("ast-builder-expand-identifier", "expected identifier", syntax);
            }

            var varname = syntax.GetDatum().AsSymbol();

            // Check and expand some of literals
            if (varname == Symbol.NULL)
            {
                return(new AstLiteral(syntax));
            }

            // Find the variable in ast environment
            int envIdx  = 0;
            var binding = env.LookupAstRecursively(varname, ref envIdx);

            if (binding == null)
            {
                // If variable is not found designate it as global variable
                var localIdx = env.Define(varname, new GlobalBinding(syntax));
                return(new AstReference(syntax, AstReferenceType.Global, localIdx));
            }
            else
            {
                if (envIdx == 0)
                {
                    // local variable reference
                    return(new AstReference(syntax, AstReferenceType.Local, binding.VarIdx, 0, 0));
                }
                else
                {
                    // up-value reference
                    if (binding is GlobalBinding || !binding.environment.IsLexical)
                    {
                        // global variable
                        var localIdx = env.Define(varname, new GlobalBinding(syntax));
                        return(new AstReference(syntax, AstReferenceType.Global, localIdx));
                    }
                    else if (binding is LocalBinding || binding is ArgumentBinding)
                    {
                        // up value to local variable
                        var localIdx = env.Define(varname, new UpBinding(syntax, envIdx, binding.VarIdx));
                        return(new AstReference(syntax, AstReferenceType.UpValue, localIdx, envIdx, binding.VarIdx));
                    }
                    else if (binding is UpBinding)
                    {
                        // upValue to other upValue
                        var upBinding = binding as UpBinding;
                        var nEnvIdx   = upBinding.UpEnvIdx + envIdx;
                        var nVarIdx   = upBinding.UpVarIdx;
                        var localIdx  = env.Define(varname, new UpBinding(syntax, nEnvIdx, nVarIdx));
                        return(new AstReference(syntax, AstReferenceType.UpValue, localIdx, nEnvIdx, nVarIdx));
                    }
                    else
                    {
                        throw new SystemException();
                    }
                }
            }
        }
Beispiel #10
0
 // aka: 99
 public static AST ExpandLiteral(Syntax syntax, Environment env)
 {
     // n.b. value '() is null it will be as literal
     return(new AstLiteral(syntax));
 }