示例#1
0
        public DiagnosticBag Emit(BoundGlobalScope scope, string outputPath)
        {
            if (scope.Diagnostics.Any())
            {
                return(scope.Diagnostics);
            }

            var module = _assembly.MainModule;

            var programType = new TypeDefinition(
                _defaultNamespace,
                ProgramClassName,
                TypeAttributes.Class | TypeAttributes.Public,
                module.TypeSystem.Object
                );

            module.Types.Add(programType);

            var mainMethod = EmitMethod("Main", scope.Statements, scope.Variables);

            programType.Methods.Add(mainMethod);

            _assembly.EntryPoint = mainMethod;

            _assembly.Write(outputPath);

            // TODO Cleanup
            _variables.Clear();
            _methods.Clear();

            return(scope.Diagnostics);
        }
示例#2
0
文件: Evaluator.cs 项目: p1x/QSPNet
        public Evaluator(BoundGlobalScope scope, TextReader reader, TextWriter writer)
        {
            _scope     = scope;
            _variables = scope.Variables.ToDictionary(x => x, x => (object?)null);

            _reader = reader;
            _writer = writer;
        }