<commit_before>from __future__ import absolute_import

import os

from pypy.rlib import jit
from pypy.rlib.objectmodel import specialize
from pypy.tool.cache import Cache

from rply.errors import ParsingError

from rupypy.astcompiler import CompilerContext, SymbolTable
from rupypy.celldict import CellDict
from rupypy.error import RubyError
from rupypy.executioncontext import ExecutionContext
from rupypy.frame import Frame
from rupypy.interpreter import Interpreter
from rupypy.lexer import LexerError, Lexer
from rupypy.lib.dir import W_Dir
from rupypy.lib.random import W_Random
from rupypy.module import ClassCache, ModuleCache
from rupypy.modules.comparable import Comparable
from rupypy.modules.enumerable import Enumerable
from rupypy.modules.math import Math
from rupypy.modules.kernel import Kernel
from rupypy.modules.process import Process
from rupypy.objects.arrayobject import W_ArrayObject
from rupypy.objects.boolobject import W_TrueObject, W_FalseObject
from rupypy.objects.classobject import W_ClassObject
from rupypy.objects.codeobject import W_CodeObject
from rupypy.objects.fileobject import W_FileObject, W_IOObject
from rupypy.objects.floatobject import W_FloatObject
from rupypy.objects.functionobject import W_UserFunction
from rupypy.objects.exceptionobject import (W_ExceptionObject, W_NoMethodError,
    W_ZeroDivisionError, W_SyntaxError, W_LoadError, W_TypeError,
    W_ArgumentError, W_RuntimeError, W_StandardError, W_SystemExit,
    W_SystemCallError)
from rupypy.objects.hashobject import W_HashObject
from rupypy.objects.intobject import W_FixnumObject
from rupypy.objects.integerobject import W_IntegerObject
from rupypy.objects.numericobject import W_NumericObject
from rupypy.objects.moduleobject import W_ModuleObject
from rupypy.objects.nilobject import W_NilObject
from rupypy.objects.objectobject import W_Object, W_BaseObject
from rupypy.objects.procobject import W_ProcObject
from rupypy.objects.rangeobject import W_RangeObject
from rupypy.objects.regexpobject import W_RegexpObject
from rupypy.objects.stringobject import W_StringObject
from rupypy.objects.symbolobject import W_SymbolObject
from rupypy.objects.timeobject import W_TimeObject
from rupypy.parser import Parser


class SpaceCache(Cache):
    def __init__(self, space):
        Cache.__init__(self)
        self.space = space

    def _build(self, obj):
        return obj(self.space)


class ObjectSpace(object):
    def __init__(self):
        self.cache = SpaceCache(self)
        self.symbol_cache = {}
        self._executioncontext = None
        self.globals = CellDict()
        self.bootstrap = True
        self.w_top_self = W_Object(self, self.getclassfor(W_Object))

        self.w_true = W_TrueObject(self)
        self.w_false = W_FalseObject(self)
        self.w_nil = W_NilObject(self)

        # This is bootstrap. We have to delay sending until true, false and nil
        # are defined
        w_mod = self.getmoduleobject(Kernel.moduledef)
        self.send(self.getclassfor(W_Object), self.newsymbol("include"), [w_mod])
        self.bootstrap = False

        for cls in [
            W_NilObject, W_TrueObject, W_FalseObject,
            W_BaseObject, W_Object,
            W_StringObject, W_SymbolObject,
            W_NumericObject, W_IntegerObject, W_FloatObject, W_FixnumObject,
        #     W_ArrayObject, W_HashObject,
            W_IOObject, W_FileObject,
            W_TimeObject,
            W_ExceptionObject, W_NoMethodError, W_LoadError, W_ZeroDivisionError,
            W_SyntaxError, W_TypeError, W_ArgumentError, W_RuntimeError,
            W_StandardError, W_SystemExit, W_SystemCallError,
            # W_Random, W_Dir, W_ProcObject
        ]:
            self.add_class(cls)

        # for module in [Math, Comparable, Enumerable, Kernel, Process]:
        #     self.add_module(module)

        # w_load_path = self.newarray([
        #     self.newstr_fromstr(
        #         os.path.join(os.path.dirname(__file__), os.path.pardir, "lib-ruby")
        #     )
        # ])
        # self.globals.set("$LOAD_PATH", w_load_path)
        # self.globals.set("$:", w_load_path)

        # w_loaded_features = self.newarray([])
        # self.globals.set("$LOADED_FEATURES", w_loaded_features)
        # self.globals.set('$"', w_loaded_features)

    def _freeze_(self):
        return True

    @specialize.memo()
    def fromcache(self, key):
        return self.cache.getorbuild(key)

    # Setup methods

    def add_module(self, module):
        "NOT_RPYTHON"
        w_cls = self.getclassfor(W_Object)
        self.set_const(w_cls,
            module.moduledef.name, self.getmoduleobject(module.moduledef)
        )<commit_msg>reenable initialization fully<commit_after>from __future__ import absolute_import

import os

from pypy.rlib import jit
from pypy.rlib.objectmodel import specialize
from pypy.tool.cache import Cache

from rply.errors import ParsingError

from rupypy.astcompiler import CompilerContext, SymbolTable
from rupypy.celldict import CellDict
from rupypy.error import RubyError
from rupypy.executioncontext import ExecutionContext
from rupypy.frame import Frame
from rupypy.interpreter import Interpreter
from rupypy.lexer import LexerError, Lexer
from rupypy.lib.dir import W_Dir
from rupypy.lib.random import W_Random
from rupypy.module import ClassCache, ModuleCache
from rupypy.modules.comparable import Comparable
from rupypy.modules.enumerable import Enumerable
from rupypy.modules.math import Math
from rupypy.modules.kernel import Kernel
from rupypy.modules.process import Process
from rupypy.objects.arrayobject import W_ArrayObject
from rupypy.objects.boolobject import W_TrueObject, W_FalseObject
from rupypy.objects.classobject import W_ClassObject
from rupypy.objects.codeobject import W_CodeObject
from rupypy.objects.fileobject import W_FileObject, W_IOObject
from rupypy.objects.floatobject import W_FloatObject
from rupypy.objects.functionobject import W_UserFunction
from rupypy.objects.exceptionobject import (W_ExceptionObject, W_NoMethodError,
    W_ZeroDivisionError, W_SyntaxError, W_LoadError, W_TypeError,
    W_ArgumentError, W_RuntimeError, W_StandardError, W_SystemExit,
    W_SystemCallError)
from rupypy.objects.hashobject import W_HashObject
from rupypy.objects.intobject import W_FixnumObject
from rupypy.objects.integerobject import W_IntegerObject
from rupypy.objects.numericobject import W_NumericObject
from rupypy.objects.moduleobject import W_ModuleObject
from rupypy.objects.nilobject import W_NilObject
from rupypy.objects.objectobject import W_Object, W_BaseObject
from rupypy.objects.procobject import W_ProcObject
from rupypy.objects.rangeobject import W_RangeObject
from rupypy.objects.regexpobject import W_RegexpObject
from rupypy.objects.stringobject import W_StringObject
from rupypy.objects.symbolobject import W_SymbolObject
from rupypy.objects.timeobject import W_TimeObject
from rupypy.parser import Parser


class SpaceCache(Cache):
    def __init__(self, space):
        Cache.__init__(self)
        self.space = space

    def _build(self, obj):
        return obj(self.space)


class ObjectSpace(object):
    def __init__(self):
        self.cache = SpaceCache(self)
        self.symbol_cache = {}
        self._executioncontext = None
        self.globals = CellDict()
        self.bootstrap = True
        self.w_top_self = W_Object(self, self.getclassfor(W_Object))

        self.w_true = W_TrueObject(self)
        self.w_false = W_FalseObject(self)
        self.w_nil = W_NilObject(self)

        # This is bootstrap. We have to delay sending until true, false and nil
        # are defined
        w_mod = self.getmoduleobject(Kernel.moduledef)
        self.send(self.getclassfor(W_Object), self.newsymbol("include"), [w_mod])
        self.bootstrap = False

        for cls in [
            W_NilObject, W_TrueObject, W_FalseObject,
            W_BaseObject, W_Object,
            W_StringObject, W_SymbolObject,
            W_NumericObject, W_IntegerObject, W_FloatObject, W_FixnumObject,
            W_ArrayObject, W_HashObject,
            W_IOObject, W_FileObject,
            W_TimeObject,
            W_ExceptionObject, W_NoMethodError, W_LoadError, W_ZeroDivisionError,
            W_SyntaxError, W_TypeError, W_ArgumentError, W_RuntimeError,
            W_StandardError, W_SystemExit, W_SystemCallError,
            W_Random, W_Dir, W_ProcObject
        ]:
            self.add_class(cls)

        for module in [Math, Comparable, Enumerable, Kernel, Process]:
            self.add_module(module)

        w_load_path = self.newarray([
            self.newstr_fromstr(
                os.path.join(os.path.dirname(__file__), os.path.pardir, "lib-ruby")
            )
        ])
        self.globals.set("$LOAD_PATH", w_load_path)
        self.globals.set("$:", w_load_path)

        w_loaded_features = self.newarray([])
        self.globals.set("$LOADED_FEATURES", w_loaded_features)
        self.globals.set('$"', w_loaded_features)

    def _freeze_(self):
        return True

    @specialize.memo()
    def fromcache(self, key):
        return self.cache.getorbuild(key)

    # Setup methods

    def add_module(self, module):
        "NOT_RPYTHON"
        w_cls = self.getclassfor(W_Object)
        self.set_const(w_cls,
            module.moduledef.name, self.getmoduleobject(module.moduledef)
        )
{'fraction_non_alphanumeric': 0.07095533233596922, 'fraction_numerical': 0.0, 'mean_word_length': 3.635463100544824, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5959788', 'n_tokens_mistral': 2975, 'n_tokens_neox': 2928, 'n_words': 648}