ExpandSSyntax() 공개 정적인 메소드

public static ExpandSSyntax ( Object x ) : Object
x Object
리턴 Object
예제 #1
0
파일: Compiler.cs 프로젝트: wisemoth/LSharp
        public static Expression Compile1(Object s, Environment environment)
        {
            // Literals are constants
            if (Runtime.IsLiteral(s))
            {
                return(Expression.Constant(s));
            }

            // Special Syntax gets expanded and compiled
            if (Runtime.IsSsyntax(s))
            {
                return(Compile1(Runtime.ExpandSSyntax(s), environment));
            }

            // Symbols are variable references
            if (s is Symbol)
            {
                return(CompileVarRef((Symbol)s));
            }

            // Special Syntax gets expanded and compiled
            if (Runtime.IsSsyntax(Runtime.Car(s)))
            {
                object expansion = Runtime.ExpandSSyntax(((Pair)s).First());
                return(Compile1(new Pair(expansion, (Pair)s), environment));
            }

            if (s is Pair)
            {
                object f = ((Pair)s).First();

                // Special Forms

                if (f == Symbol.FromName("if"))
                {
                    return(Compiler.CompileIf(((Pair)s).Rest(), environment));
                }

                if (f == Symbol.FromName("quote"))
                {
                    return(Compiler.CompileQuote(((Pair)s).Rest(), environment));
                }

                if (f == Symbol.FromName("call-clr"))
                {
                    return(Compiler.CompileCall((Pair)((Pair)s).Rest(), environment));
                }

                if (f == Symbol.FromName("call-instance"))
                {
                    return(Compiler.CompileInstanceCall((Pair)((Pair)s).Rest(), environment));
                }

                if (f == Symbol.FromName("fn"))
                {
                    return(Compiler.CompileFn((Pair)((Pair)s).Rest(), environment));
                }

                if (f == Symbol.FromName("macro"))
                {
                    return(Compiler.CompileMac((Pair)((Pair)s).Rest(), environment));
                }

                if (f == Symbol.FromName("quasiquote"))
                {
                    return(Compiler.CompileQuasiQuote((Pair)((Pair)s).Rest(), environment));
                }



                if ((f is Symbol) && (environment.Contains((Symbol)f)))
                {
                    object value = environment.GetValue((Symbol)f);


                    // Macros get invoked at compile time, then their results are themeselves compiled
                    if (value is Macro)
                    {
                        object expansion = ((Macro)value).Call(Runtime.AsArray(((Pair)s).Rest()));
                        return(Compile1(expansion, environment));
                    }
                }

                // It must be a function call
                return(CompileFunctionCall(f, ((Pair)s).Rest(), environment));
            }

            throw new LSharpException(string.Format("Bad object in expression: ", s), environment);
        }