示例#1
0
        public override Value Execute(VirtualMachine vm, IEnumerable <Value> args)
        {
            var fileName = GetFileName(vm, args);
            // TODO: Skip if already imported?
            // This could be part of the system so it could just return the proper scope to wrap
            // Or the intrinsic itself could cache already loaded in values
            // Load in file
            // TODO: syntax status?
            var ast = System.LoadAst(fileName);

            // We need to create a struct type that contains the constants in the file
            // First we define the new scope
            System.SymbolTable.PushScope(Semantic.ScopeKind.Struct);
            var structScope = System.SymbolTable.CurrentScope;

            // Define things
            // TODO: compile status?
            SymbolResolution.Resolve(System.SymbolTable, ast);
            // Pop scope
            System.SymbolTable.PopScope();
            // Create the new type
            var moduleType = new Type.Struct(
                structScope,
                new Syntax.Token(new Text.Span(), Syntax.TokenType.KwStruct, "struct"),
                new Dictionary <string, Type.Struct.Field>());

            // Wrap it, return it
            return(new Value.User(moduleType));
        }
示例#2
0
            public override Value Execute(VirtualMachine vm, IEnumerable <Value> args)
            {
                // TODO: Check args
                var typeParam = System.TypeTranslator.ToSemanticType(args.First());

                // We need to create a struct type that contains the constants in the file
                // First we define the new scope
                System.SymbolTable.PushScope(Semantic.ScopeKind.Struct);
                var structScope = System.SymbolTable.CurrentScope;
                // Define things
                var impl = new Impl(System, typeParam);

                structScope.Define(new Symbol.Const("f", impl.Type, new Value.User(impl)));
                // Pop scope
                System.SymbolTable.PopScope();
                // Create the new type
                var moduleType = new Type.Struct(
                    structScope,
                    new Syntax.Token(new Text.Span(), Syntax.TokenType.KwStruct, "struct"),
                    new Dictionary <string, Type.Struct.Field>());

                // Wrap it, return it
                return(new Value.User(moduleType));
            }