Beispiel #1
0
        public LOLMethod(FunctionRef info, LOLProgram prog)
        {
            this.info = info;
            this.args = new ArgumentRef[info.Arity + (info.IsVariadic ? 1 : 0)];
            this.program = prog;
            this.locals = new Scope(prog.globals);

            LocalRef it = new LocalRef("IT");
            locals.AddSymbol(it);
        }
Beispiel #2
0
            void InlineInvocation(CallExpression invocation, JSFunctionMetadata targetFuncMetadata)
            {
                _targetFuncMetadata = targetFuncMetadata;
                _call = invocation;
                Debug.WriteLine("Trying to inline function {0}", _targetFuncMetadata.Declaration);

                _targetFuncMetadata.Analyze(); //Just to make sure it is analyzed

                if (JSRuntime.Instance.Configuration.ProfileStats)
                {
                    JSRuntime.Instance.Counters.GetCounter("Attempted Inline").Count++;
                }

                if (!CanInline(_targetFuncMetadata))
                {
                    return;
                }

                if (JSRuntime.Instance.Configuration.ProfileStats)
                {
                    JSRuntime.Instance.Counters.GetCounter("Succeeded Inline").Count++;
                }

                _functionsBeingInlined.AddLast(_targetFuncMetadata);

                _round++;

                throw new NotImplementedException(); //TODO: we need to update this algorithm based on the recent changes to the scope
                _newScope                     = new Scope(_currentTargetScope);
                _returnValueSymbol            = _newScope.AddSymbol(RenameSymbol("retVal"));
                _returnValueSymbol.SymbolType = JSSymbol.SymbolTypes.HiddenLocal;


                _call.InlinedIR = new InlinedInvocation(
                    _targetFuncMetadata
                    , _newScope
                    , BuildInlinedBody()
                    , new ReadIdentifierExpression(_returnValueSymbol)
                    );
                _call.InlinedIR.AddUser(_call);

                Debug.WriteLine("Inlined function {0}", _targetFuncMetadata.Declaration);

                _functionsBeingInlined.RemoveLast();
            }
        public static common_unit_node make_system_unit(TreeConverterSymbolTable symbol_table,
                                                        initialization_properties initialization_properties)
        {
            //TODO: В качестве location везде в этом методе следует указывать location system_unit-а. Имя файла мы знаем, а место - там где написано, что integer и прочие типы описаны как бы в модуле system.
            location                system_unit_location = null;
            UnitInterfaceScope      main_scope           = symbol_table.CreateUnitInterfaceScope(new Scope[0]);
            UnitImplementationScope impl_scope           = symbol_table.CreateUnitImplementationScope(main_scope,
                                                                                                      new Scope[0]);
            common_unit_node _system_unit = new common_unit_node(main_scope, impl_scope, null, null);

            common_namespace_node cnn = new common_namespace_node(null, _system_unit, compiler_string_consts.system_unit_name,
                                                                  symbol_table.CreateScope(main_scope), system_unit_location);

            main_scope.AddSymbol(compiler_string_consts.system_unit_name, new SymbolInfo(cnn));

            //Scope sc = cnn.scope;
            Scope sc = main_scope;

            //Добавляем типы.
            sc.AddSymbol(compiler_string_consts.byte_type_name, new SymbolInfo(SystemLibrary.byte_type));
            //sc.AddSymbol(compiler_string_consts.decimal_type_name, new SymbolInfo(SystemLibrary.decimal_type));
            sc.AddSymbol(compiler_string_consts.sbyte_type_name, new SymbolInfo(SystemLibrary.sbyte_type));
            sc.AddSymbol(compiler_string_consts.short_type_name, new SymbolInfo(SystemLibrary.short_type));
            sc.AddSymbol(compiler_string_consts.ushort_type_name, new SymbolInfo(SystemLibrary.ushort_type));
            sc.AddSymbol(compiler_string_consts.integer_type_name, new SymbolInfo(SystemLibrary.integer_type));
            sc.AddSymbol(compiler_string_consts.uint_type_name, new SymbolInfo(SystemLibrary.uint_type));
            sc.AddSymbol(compiler_string_consts.long_type_name, new SymbolInfo(SystemLibrary.int64_type));
            sc.AddSymbol(compiler_string_consts.ulong_type_name, new SymbolInfo(SystemLibrary.uint64_type));
            sc.AddSymbol(compiler_string_consts.float_type_name, new SymbolInfo(SystemLibrary.float_type));
            sc.AddSymbol(compiler_string_consts.real_type_name, new SymbolInfo(SystemLibrary.double_type));
            sc.AddSymbol(compiler_string_consts.char_type_name, new SymbolInfo(SystemLibrary.char_type));
            sc.AddSymbol(compiler_string_consts.bool_type_name, new SymbolInfo(SystemLibrary.bool_type));
            sc.AddSymbol(compiler_string_consts.string_type_name, new SymbolInfo(SystemLibrary.string_type));
            //sc.AddSymbol(compiler_string_consts.object_type_name, new SymbolInfo(SystemLibrary.object_type));
            sc.AddSymbol(compiler_string_consts.pointer_type_name, new SymbolInfo(SystemLibrary.pointer_type));
            //sc.AddSymbol(compiler_string_consts.base_exception_class_name, new SymbolInfo(SystemLibrary.exception_base_type));
            sc.AddSymbol(compiler_string_consts.base_array_type_name, new SymbolInfo(SystemLibrary.array_base_type));
            sc.AddSymbol(compiler_string_consts.base_delegate_type_name, new SymbolInfo(SystemLibrary.delegate_base_type));

            //TODO: Переделать. Пусть таблица символов создается одна. Как статическая.
            compiled_type_node comp_byte_type      = ((compiled_type_node)SystemLibrary.byte_type);
            compiled_type_node comp_sbyte_type     = ((compiled_type_node)SystemLibrary.sbyte_type);
            compiled_type_node comp_short_type     = ((compiled_type_node)SystemLibrary.short_type);
            compiled_type_node comp_ushort_type    = ((compiled_type_node)SystemLibrary.ushort_type);
            compiled_type_node comp_integer_type   = ((compiled_type_node)SystemLibrary.integer_type);
            compiled_type_node comp_uint_type      = ((compiled_type_node)SystemLibrary.uint_type);
            compiled_type_node comp_long_type      = ((compiled_type_node)SystemLibrary.int64_type);
            compiled_type_node comp_ulong_type     = ((compiled_type_node)SystemLibrary.uint64_type);
            compiled_type_node comp_float_type     = ((compiled_type_node)SystemLibrary.float_type);
            compiled_type_node comp_real_type      = ((compiled_type_node)SystemLibrary.double_type);
            compiled_type_node comp_char_type      = ((compiled_type_node)SystemLibrary.char_type);
            compiled_type_node comp_bool_type      = ((compiled_type_node)SystemLibrary.bool_type);
            compiled_type_node comp_string_type    = ((compiled_type_node)SystemLibrary.string_type);
            compiled_type_node comp_object_type    = ((compiled_type_node)SystemLibrary.object_type);
            compiled_type_node comp_pointer_type   = ((compiled_type_node)SystemLibrary.pointer_type);
            compiled_type_node comp_exception_type = ((compiled_type_node)SystemLibrary.exception_base_type);
            compiled_type_node comp_array_type     = ((compiled_type_node)SystemLibrary.array_base_type);
            compiled_type_node comp_delegate_type  = ((compiled_type_node)SystemLibrary.delegate_base_type);

            comp_byte_type.scope      = new NetTypeScope(comp_byte_type.compiled_type, symbol_table);
            comp_sbyte_type.scope     = new NetTypeScope(comp_sbyte_type.compiled_type, symbol_table);
            comp_short_type.scope     = new NetTypeScope(comp_short_type.compiled_type, symbol_table);
            comp_ushort_type.scope    = new NetTypeScope(comp_ushort_type.compiled_type, symbol_table);
            comp_integer_type.scope   = new NetTypeScope(comp_integer_type.compiled_type, symbol_table);
            comp_uint_type.scope      = new NetTypeScope(comp_uint_type.compiled_type, symbol_table);
            comp_long_type.scope      = new NetTypeScope(comp_long_type.compiled_type, symbol_table);
            comp_ulong_type.scope     = new NetTypeScope(comp_ulong_type.compiled_type, symbol_table);
            comp_real_type.scope      = new NetTypeScope(comp_real_type.compiled_type, symbol_table);
            comp_char_type.scope      = new NetTypeScope(comp_char_type.compiled_type, symbol_table);
            comp_bool_type.scope      = new NetTypeScope(comp_bool_type.compiled_type, symbol_table);
            comp_string_type.scope    = new NetTypeScope(comp_string_type.compiled_type, symbol_table);
            comp_object_type.scope    = new NetTypeScope(comp_object_type.compiled_type, symbol_table);
            comp_pointer_type.scope   = new NetTypeScope(comp_pointer_type.compiled_type, symbol_table);
            comp_exception_type.scope = new NetTypeScope(comp_exception_type.compiled_type, symbol_table);
            comp_array_type.scope     = new NetTypeScope(comp_array_type.compiled_type, symbol_table);
            comp_delegate_type.scope  = new NetTypeScope(comp_delegate_type.compiled_type, symbol_table);

            init_temp_methods_and_consts(cnn, sc, initialization_properties, system_unit_location);
            return(_system_unit);
        }
Beispiel #4
0
      void InlineInvocation(CallExpression invocation, JSFunctionMetadata targetFuncMetadata)
      {
        _targetFuncMetadata = targetFuncMetadata;
        _call = invocation;
        Debug.WriteLine("Trying to inline function {0}", _targetFuncMetadata.Declaration);

        _targetFuncMetadata.Analyze(); //Just to make sure it is analyzed
        
        if (JSRuntime.Instance.Configuration.ProfileStats)
          JSRuntime.Instance.Counters.GetCounter("Attempted Inline").Count++;

        if (!CanInline(_targetFuncMetadata))
          return;

        if (JSRuntime.Instance.Configuration.ProfileStats)
          JSRuntime.Instance.Counters.GetCounter("Succeeded Inline").Count++;

        _functionsBeingInlined.AddLast(_targetFuncMetadata);

        _round++;

        throw new NotImplementedException(); //TODO: we need to update this algorithm based on the recent changes to the scope
        _newScope = new Scope(_currentTargetScope);
        _returnValueSymbol = _newScope.AddSymbol(RenameSymbol("retVal"));
        _returnValueSymbol.SymbolType = JSSymbol.SymbolTypes.HiddenLocal;


        _call.InlinedIR = new InlinedInvocation(
          _targetFuncMetadata
          , _newScope
          , BuildInlinedBody()
          , new ReadIdentifierExpression(_returnValueSymbol)
        );
        _call.InlinedIR.AddUser(_call);

        Debug.WriteLine("Inlined function {0}", _targetFuncMetadata.Declaration);

        _functionsBeingInlined.RemoveLast();
      }
        private static void init_temp_methods_and_consts(common_namespace_node system_namespace, Scope where_add,
                                                         initialization_properties initialization_properties, location system_unit_location)
        {
            //Scope sc = system_namespace.scope;
            Scope sc = where_add;
            namespace_constant_definition _true_constant_definition = new namespace_constant_definition(
                compiler_string_consts.true_const_name, SystemLibrary.true_constant, system_unit_location, system_namespace);

            system_namespace.constants.AddElement(_true_constant_definition);

            namespace_constant_definition _false_constant_definition = new namespace_constant_definition(
                compiler_string_consts.false_const_name, SystemLibrary.false_constant, system_unit_location, system_namespace);

            system_namespace.constants.AddElement(_false_constant_definition);

            sc.AddSymbol(compiler_string_consts.true_const_name, new SymbolInfo(_true_constant_definition));
            sc.AddSymbol(compiler_string_consts.false_const_name, new SymbolInfo(_false_constant_definition));


            //TODO: Сделано по быстрому. Переделать. Можно просто один раз сериализовать модуль system и не инициализировать его всякий раз подобным образом. Неплохо-бы использовать NetHelper.GetMethod.
            Type tp = typeof(Console);
            compiled_function_node cfn;

            System.Type[] arr = new System.Type[1];
            System.Reflection.MethodInfo mi;

            //TODO: Сделать узел или базовый метод создания и удаления объекта.
            common_namespace_function_node cnfn = new common_namespace_function_node(compiler_string_consts.new_procedure_name, null, null, system_namespace, null);

            cnfn.parameters.AddElement(new common_parameter("ptr", SystemLibrary.pointer_type, parameter_type.value, cnfn,
                                                            concrete_parameter_type.cpt_var, null, null));
            cnfn.SpecialFunctionKind   = SpecialFunctionKind.New;
            _NewProcedure              = new SymbolInfo(cnfn);
            _NewProcedure.symbol_kind  = symbol_kind.sk_overload_function;
            _NewProcedure.access_level = access_level.al_public;
            _NewProcedureDecl          = cnfn;
            sc.AddSymbol(compiler_string_consts.new_procedure_name, _NewProcedure);

            cnfn = new common_namespace_function_node(compiler_string_consts.dispose_procedure_name, null, null, system_namespace, null);
            cnfn.parameters.AddElement(new common_parameter("ptr", SystemLibrary.pointer_type, parameter_type.value,
                                                            cnfn, concrete_parameter_type.cpt_var, null, null));
            _DisposeProcedure              = new SymbolInfo(cnfn);
            _DisposeProcedure.symbol_kind  = symbol_kind.sk_overload_function;
            _DisposeProcedure.access_level = access_level.al_public;
            _DisposeProcedureDecl          = cnfn;
            cnfn.SpecialFunctionKind       = SpecialFunctionKind.Dispose;
            sc.AddSymbol(compiler_string_consts.dispose_procedure_name, _DisposeProcedure);

            cnfn = new common_namespace_function_node(compiler_string_consts.new_array_procedure_name, compiled_type_node.get_type_node(typeof(Array)), null, system_namespace, null);
            cnfn.parameters.AddElement(new common_parameter("t", compiled_type_node.get_type_node(typeof(Type)), parameter_type.value, cnfn,
                                                            concrete_parameter_type.cpt_none, null, null));
            cnfn.parameters.AddElement(new common_parameter("n", SystemLibrary.integer_type, parameter_type.value, cnfn,
                                                            concrete_parameter_type.cpt_none, null, null));
            cnfn.SpecialFunctionKind = SpecialFunctionKind.NewArray;
            _NewArrayProcedure       = new SymbolInfo(cnfn);
            _NewArrayProcedureDecl   = cnfn;
            //sc.AddSymbol(TreeConverter.compiler_string_consts.new_procedure_name, _NewProcedure);

            basic_function_node break_procedure = new basic_function_node(basic_function_type.none,
                                                                          null, true);

            break_procedure.compile_time_executor = initialization_properties.break_executor;
            sc.AddSymbol(compiler_string_consts.break_procedure_name, new SymbolInfo(break_procedure));

            basic_function_node continue_procedure = new basic_function_node(basic_function_type.none,
                                                                             null, true);

            continue_procedure.compile_time_executor = initialization_properties.continue_executor;
            sc.AddSymbol(compiler_string_consts.continue_procedure_name, new SymbolInfo(continue_procedure));

            basic_function_node exit_procedure = new basic_function_node(basic_function_type.none,
                                                                         null, true);

            exit_procedure.compile_time_executor = initialization_properties.exit_executor;
            sc.AddSymbol(compiler_string_consts.exit_procedure_name, new SymbolInfo(exit_procedure));

            sc.AddSymbol(compiler_string_consts.set_length_procedure_name,
                         new SymbolInfo(SystemLibrary.resize_func, access_level.al_public, symbol_kind.sk_overload_function));
        }