<commit_before>from pycket        import values
from pycket        import vector
from pycket.prims  import prim_env
from pycket.error  import SchemeException
from pycket.cont   import Cont
from rpython.rlib  import jit, debug
from small_list    import inline_small_list


class ModuleEnv(object):
    def __init__(self):
        self.modules = {}
    
    def require(module_name):
        assert 0
        # load the file, evaluate it, register it in the table

    def add_module(name, module):
        # note that `name` and `module.name` are different!
        assert isinstance(module, Module)
        self.modules[name] = module

    def lookup(modvar):
        assert isinstance(modvar, ModuleVar)
        return self.modules[modvar]

class Env(object):
    _immutable_fields_ = ["toplevel_env"]
    pass

class Version(object):
    pass

class ToplevelEnv(Env):
    _immutable_fields_ = ["version?"]
    def __init__(self):
        self.bindings = {}
        self.version = Version()
        self.toplevel_env = self # bit silly
        self.commandline_arguments = []

    def lookup(self, sym, env_structure):
        raise SchemeException("variable %s is unbound"%sym.value)

    def toplevel_lookup(self, sym):
        jit.promote(self)
        w_res = self._lookup(sym, jit.promote(self.version))
        if isinstance(w_res, values.W_Cell):
            w_res = w_res.value
        return w_res

    @jit.elidable
    def _lookup(self, sym, version):
        try:
            return self.bindings[sym]
        except KeyError:
            raise SchemeException("toplevel variable %s not found" % sym.value)

    def toplevel_set(self, sym, w_val):
        if sym in self.bindings:
            self.bindings[sym].set_val(w_val)
        else:
            self.bindings[sym] = values.W_Cell(w_val)
            self.version = Version()<commit_msg>more progress<commit_after>from pycket        import values
from pycket        import vector
from pycket.prims  import prim_env
from pycket.error  import SchemeException
from pycket.cont   import Cont
from rpython.rlib  import jit, debug
from small_list    import inline_small_list


class ModuleEnv(object):
    def __init__(self):
        self.modules = {}
    
    def require(module_name):
        assert 0
        # load the file, evaluate it, register it in the table

    def add_module(name, module):
        # note that `name` and `module.name` are different!
        assert isinstance(module, Module)
        self.modules[name] = module

    def lookup(modvar):
        assert isinstance(modvar, ModuleVar)
        return self.modules[modvar]

class Env(object):
    _immutable_fields_ = ["toplevel_env", "module_env"]
    pass

class Version(object):
    pass

class ToplevelEnv(Env):
    _immutable_fields_ = ["version?"]
    def __init__(self):
        self.bindings = {}
        self.version = Version()
        self.toplevel_env = self # bit silly
        self.module_env = None # could put something else here?
        self.commandline_arguments = []

    def lookup(self, sym, env_structure):
        raise SchemeException("variable %s is unbound"%sym.value)

    def toplevel_lookup(self, sym):
        jit.promote(self)
        w_res = self._lookup(sym, jit.promote(self.version))
        if isinstance(w_res, values.W_Cell):
            w_res = w_res.value
        return w_res

    @jit.elidable
    def _lookup(self, sym, version):
        try:
            return self.bindings[sym]
        except KeyError:
            raise SchemeException("toplevel variable %s not found" % sym.value)

    def toplevel_set(self, sym, w_val):
        if sym in self.bindings:
            self.bindings[sym].set_val(w_val)
        else:
            self.bindings[sym] = values.W_Cell(w_val)
            self.version = Version()
{'fraction_non_alphanumeric': 0.09050131926121371, 'fraction_numerical': 0.0005277044854881266, 'mean_word_length': 2.533084808946878, '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': '730915', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1140, 'n_words': 300}