# Path: native.py
# DIGEST_INDEX = {}
# HEADERS = {'form': '\xe5\xa4\xa9\x00', 'normal': '\xe7\xa5\x9e\x00'}
# def _write(b):
# def _write_ref(node, t):
# def _encode_int(n):
# def _encode_float(f):
# def _encode_str(s):
# def _serialize_node(node, t):
# def _inspect_node(node, t):
# def inspect(module):
# def serialize(module):
#     def write_header():
# 
# Path: types_builtin.py
# def app_map(data, appTs):
#     apps = {}
#     for tv, at in ezip(data.tvars, appTs):
#         if isinstance(at, TVar) and at.typeVar is tv:
#             continue
#         apps[tv] = at
#     return apps
# 
# def subst(mapping, t):
#     return map_type_vars(lambda st: mapping.get(st.typeVar, st), t)


from base import *
from bedrock import *
from globs import *
from hashlib import sha256
from native import ModuleMeta, HEADERS, DIGEST_INDEX
from types_builtin import app_map, subst
import os

DeserialState = DT('DeserialState',
        ('file', file),
        ('module', Module),
        ('deps', {int: Module}),
        ('index', int),
        ('depsSeen', int),
        ('ownMap', {int: object}),
        ('forwardRefs', {int: [object]}))

Deserialize = new_env('Deserialize', DeserialState)

def _read_int(f):
    a = ord(f.read(1))
    if a <= 0b01111111:
        return a
    elif a <= 0b10111111:
        b = ord(f.read(1))
        a = ((a & 0b00111111)<<8) | b
        return a + 0x80
    elif a <= 0b11011111:
        b, c = map(ord, f.read(2))
        a = ((a & 0b00011111)<<16) | (b<<8) | c
        return a + 0x4080
    elif a <= 0b11101111:
        b, c, d = map(ord, f.read(3))
        a = ((a & 0b00001111)<<24) | (b<<16) | (c<<8) | d
        return a + 0x204080
    elif a == 0b11110000:
        b, c, d, e = map(ord, f.read(4))

# Path: native.py
# DIGEST_INDEX = {}
# HEADERS = {'form': '\xe5\xa4\xa9\x00', 'normal': '\xe7\xa5\x9e\x00'}
# def _write(b):
# def _write_ref(node, t):
# def _encode_int(n):
# def _encode_float(f):
# def _encode_str(s):
# def _serialize_node(node, t):
# def _inspect_node(node, t):
# def inspect(module):
# def serialize(module):
#     def write_header():
# 
# Path: types_builtin.py
# def app_map(data, appTs):
#     apps = {}
#     for tv, at in ezip(data.tvars, appTs):
#         if isinstance(at, TVar) and at.typeVar is tv:
#             continue
#         apps[tv] = at
#     return apps
# 
# def subst(mapping, t):
#     return map_type_vars(lambda st: mapping.get(st.typeVar, st), t)


# Path: deserialize.py
from base import *
from bedrock import *
from globs import *
from hashlib import sha256
from native import ModuleMeta, HEADERS, DIGEST_INDEX
from types_builtin import app_map, subst
import os


DeserialState = DT('DeserialState',
        ('file', file),
        ('module', Module),
        ('deps', {int: Module}),
        ('index', int),
        ('depsSeen', int),
        ('ownMap', {int: object}),
        ('forwardRefs', {int: [object]}))

Deserialize = new_env('Deserialize', DeserialState)

def _read_int(f):
    a = ord(f.read(1))
    if a <= 0b01111111:
        return a
    elif a <= 0b10111111:
        b = ord(f.read(1))
        a = ((a & 0b00111111)<<8) | b
        return a + 0x80
    elif a <= 0b11011111:
        b, c = map(ord, f.read(2))
        a = ((a & 0b00011111)<<16) | (b<<8) | c
        return a + 0x4080
    elif a <= 0b11101111:
        b, c, d = map(ord, f.read(3))
        a = ((a & 0b00001111)<<24) | (b<<16) | (c<<8) | d
        return a + 0x204080
    elif a == 0b11110000:
        b, c, d, e = map(ord, f.read(4))

        a = (b<<24) | (c<<16) | (d<<8) | e