예제 #1
0
        public Type Compile(Ast.Program program)
        {
            if (functions != null)
            {
                throw new InvalidOperationException("Compiler must finish compilation of first source before compiling other");
            }
            functions = new Dictionary <String, MethodBuilder>();


            var           aName       = new AssemblyName("DynamicAssemblyCompiler");
            var           ab          = AppDomain.CurrentDomain.DefineDynamicAssembly(aName, AssemblyBuilderAccess.RunAndSave);
            ModuleBuilder mb          = ab.DefineDynamicModule(aName.Name, aName.Name + ".dll");
            var           typeBuilder = mb.DefineType("ProgramBody", TypeAttributes.Public);

            var verifier = new FunctionsVerificationListener(typeBuilder, functions);

            verifier.Accept(program, 0);

            var listener = new CompilerListener(this);

            listener.Accept(program, 0);

            functions = null;
            return(typeBuilder.CreateType());
        }
예제 #2
0
 public override bool Accept(Ast.Program element, int data)
 {
     foreach (var i in element.functions)
     {
         i.Value.Accept(this, 0);
     }
     return(false);
 }
예제 #3
0
 private static Object.Object EvalProgram(Ast.Program program, Object.Environment env)
 {
     Object.Object result = null;
     foreach (var statement in program.Statements)
     {
         result = Eval(statement, env);
         if (result is Object.ReturnValue)
         {
             return((result as Object.ReturnValue).Value);
         }
         if (result is Object.Error)
         {
             return(result as Object.Error);
         }
     }
     return(result);
 }