# Path: bincode/encoder.py
# class ConstantTable(object):
#     def __init__(self):
#         self.constants = OrderedDict()
# 
#     def get(self, const):
#         const_table = self.constants
#         if const in const_table:
#             return const_table[const]
#         const_table[const] = len(const_table)
#         return const_table[const]
# 
# def dump_function(pathname, constants, functions):
#     stream = open_file(pathname)
#     stream.write(common.header)
#     stream.write_u16(len(functions))
#     for flags, regc, argc, localc, block in functions:
#         stream.write_u16(flags)
#         stream.write_u16(regc)
#         stream.write_u16(argc)
#         stream.write_u16(localc)
#         stream.write_u16(len(block))
#         for code in block:
#             stream.write_u16(code)
#     stream.write_u16(len(constants))
#     for const in constants:
#         if isinstance(const, (str, unicode)):
#             stream.write_ubyte(0x01)
#             stream.write_string(const)
#         elif isinstance(const, (int, long)):
#             if const >= 0:
#                 stream.write_ubyte(0x02)
#                 stream.write_u64(const)
#             else:
#                 stream.write_ubyte(0x03)
#                 stream.write_u64(const)
#         elif isinstance(const, float):
#             stream.write_ubyte(0x04)
#             stream.write_double(const)
#         else:
#             assert False, "insert encoding for constant"
#     stream.close()
# 
# Path: spacing_functions.py
# class SpacingCheck(object):
# class BinarySpacing(SpacingCheck):
# class PrefixSpacing(SpacingCheck):
# class PostfixSpacing(SpacingCheck):
# class TightSpacing(SpacingCheck):
# class LooseSpacing(SpacingCheck):
#     def __init__(self, symbol):
#     def __eq__(self, other):
#     def __call__(self, token):
#     def __repr__(self):
#     def __call__(self, token):
#     def __repr__(self):
#     def __call__(self, token):
#     def __repr__(self):
#     def __call__(self, token):
#     def __repr__(self):
#     def __call__(self, token):
#     def __repr__(self):
# def spacing_func(cls):
#     def _func_((key, sym)):
# 
# Path: compiler_program.py
# class Function(object):
#     def __init__(self, index, flags, argc, localv, blocks):
#         self.index = index
#         self.blocks = reverse_postorder(blocks[0])
#         #self.is_generator = is_generator
#         self.tmpc = 0
#         allocate_tmp(self)
#         self.argc = argc
#         self.localv = localv
#         self.flags = flags
# 
#     def as_arg(self, consttab, vt):
#         assert vt == 'function'
#         return self.index
# 
#     def dump(self, consttab):
#         block = []
#         for bb in self.blocks:
#             bb.label = len(block)
#             block.extend(bb.dump(consttab))
#         block = []
#         for bb in self.blocks:
#             assert bb.label == len(block)
#             block.extend(bb.dump(consttab))
#         localc = len(self.localv)
#         return self.flags, self.tmpc, self.argc, localc, block
# 
# class Block(object):
#     def __init__(self, index, contents, succ):
#         self.label = 0
#         self.index = index
#         self.contents = contents
#         self.succ = succ
#         self.visited = False
# 
#     def __getitem__(self, index):
#         return self.contents[index]
# 
#     def __len__(self):
#         return len(self.contents)
# 
#     def as_arg(self, consttab, vt):
#         assert vt == 'block'
#         return self.label
# 
#     def append(self, op):
#         self.contents.append(op)
#         self.succ.update(succ for succ in op if isinstance(succ, Block))
# 
#     def dump(self, consttab):
#         result = []
#         for op in self:
#             result.extend(op.dump(consttab))
#         return result
# 
# class Constant(object):
#     def __init__(self, value):
#         self.value = value
# 
#     def as_arg(self, consttab, vt):
#         assert vt == 'constant' or vt == 'string' and isinstance(self.value, (str, unicode))
#         return consttab.get(self.value)
# 
#     def __repr__(self):
#         return "Constant({})".format(self.value)
# 
# class Op(object):
#     index = None
# 
#     def __init__(self, loc, opname, args):
#         self.loc = loc
#         self.args = args
#         self.opname = opname
#         (self.opcode, self.has_result,
#          self.pattern, self.variadic) = optable.enc[opname]
# 
#     def as_arg(self, consttab, vt):
#         assert vt == 'vreg'
#         assert self.has_result
#         return self.index
# 
#     def dump(self, consttab):
#         assert len(self.args) >= len(self.pattern), self.opname
#         assert self.variadic or len(self.args) == len(self.pattern), self.opname
#         oplen = len(self.args) + self.has_result
#         yield self.opcode << 8 | oplen
#         if self.has_result:
#             yield self.index
#         vc = len(self.args) - len(self.pattern)
#         for arg, vt in zip(self.args, self.pattern + [self.variadic]*vc):
#             if isinstance(arg, int):
#                 assert vt == 'index'
#                 yield arg
#             else:
#                 yield arg.as_arg(consttab, vt)
# 
#     def uses(self):
#         return set(arg for arg in self.args if isinstance(arg, Op))
# 
#     def __iter__(self):
#         return iter(self.args)


from bincode.encoder import ConstantTable, dump_function
from spacing_functions import functions
from compiler_program import Function, Block, Constant, Op
            from evaluator import optable
import grammarlang
import os
import sys

def main(debug=False):
    for name in sys.argv[1:]:
        functions = []

# Path: bincode/encoder.py
# class ConstantTable(object):
#     def __init__(self):
#         self.constants = OrderedDict()
# 
#     def get(self, const):
#         const_table = self.constants
#         if const in const_table:
#             return const_table[const]
#         const_table[const] = len(const_table)
#         return const_table[const]
# 
# def dump_function(pathname, constants, functions):
#     stream = open_file(pathname)
#     stream.write(common.header)
#     stream.write_u16(len(functions))
#     for flags, regc, argc, localc, block in functions:
#         stream.write_u16(flags)
#         stream.write_u16(regc)
#         stream.write_u16(argc)
#         stream.write_u16(localc)
#         stream.write_u16(len(block))
#         for code in block:
#             stream.write_u16(code)
#     stream.write_u16(len(constants))
#     for const in constants:
#         if isinstance(const, (str, unicode)):
#             stream.write_ubyte(0x01)
#             stream.write_string(const)
#         elif isinstance(const, (int, long)):
#             if const >= 0:
#                 stream.write_ubyte(0x02)
#                 stream.write_u64(const)
#             else:
#                 stream.write_ubyte(0x03)
#                 stream.write_u64(const)
#         elif isinstance(const, float):
#             stream.write_ubyte(0x04)
#             stream.write_double(const)
#         else:
#             assert False, "insert encoding for constant"
#     stream.close()
# 
# Path: spacing_functions.py
# class SpacingCheck(object):
# class BinarySpacing(SpacingCheck):
# class PrefixSpacing(SpacingCheck):
# class PostfixSpacing(SpacingCheck):
# class TightSpacing(SpacingCheck):
# class LooseSpacing(SpacingCheck):
#     def __init__(self, symbol):
#     def __eq__(self, other):
#     def __call__(self, token):
#     def __repr__(self):
#     def __call__(self, token):
#     def __repr__(self):
#     def __call__(self, token):
#     def __repr__(self):
#     def __call__(self, token):
#     def __repr__(self):
#     def __call__(self, token):
#     def __repr__(self):
# def spacing_func(cls):
#     def _func_((key, sym)):
# 
# Path: compiler_program.py
# class Function(object):
#     def __init__(self, index, flags, argc, localv, blocks):
#         self.index = index
#         self.blocks = reverse_postorder(blocks[0])
#         #self.is_generator = is_generator
#         self.tmpc = 0
#         allocate_tmp(self)
#         self.argc = argc
#         self.localv = localv
#         self.flags = flags
# 
#     def as_arg(self, consttab, vt):
#         assert vt == 'function'
#         return self.index
# 
#     def dump(self, consttab):
#         block = []
#         for bb in self.blocks:
#             bb.label = len(block)
#             block.extend(bb.dump(consttab))
#         block = []
#         for bb in self.blocks:
#             assert bb.label == len(block)
#             block.extend(bb.dump(consttab))
#         localc = len(self.localv)
#         return self.flags, self.tmpc, self.argc, localc, block
# 
# class Block(object):
#     def __init__(self, index, contents, succ):
#         self.label = 0
#         self.index = index
#         self.contents = contents
#         self.succ = succ
#         self.visited = False
# 
#     def __getitem__(self, index):
#         return self.contents[index]
# 
#     def __len__(self):
#         return len(self.contents)
# 
#     def as_arg(self, consttab, vt):
#         assert vt == 'block'
#         return self.label
# 
#     def append(self, op):
#         self.contents.append(op)
#         self.succ.update(succ for succ in op if isinstance(succ, Block))
# 
#     def dump(self, consttab):
#         result = []
#         for op in self:
#             result.extend(op.dump(consttab))
#         return result
# 
# class Constant(object):
#     def __init__(self, value):
#         self.value = value
# 
#     def as_arg(self, consttab, vt):
#         assert vt == 'constant' or vt == 'string' and isinstance(self.value, (str, unicode))
#         return consttab.get(self.value)
# 
#     def __repr__(self):
#         return "Constant({})".format(self.value)
# 
# class Op(object):
#     index = None
# 
#     def __init__(self, loc, opname, args):
#         self.loc = loc
#         self.args = args
#         self.opname = opname
#         (self.opcode, self.has_result,
#          self.pattern, self.variadic) = optable.enc[opname]
# 
#     def as_arg(self, consttab, vt):
#         assert vt == 'vreg'
#         assert self.has_result
#         return self.index
# 
#     def dump(self, consttab):
#         assert len(self.args) >= len(self.pattern), self.opname
#         assert self.variadic or len(self.args) == len(self.pattern), self.opname
#         oplen = len(self.args) + self.has_result
#         yield self.opcode << 8 | oplen
#         if self.has_result:
#             yield self.index
#         vc = len(self.args) - len(self.pattern)
#         for arg, vt in zip(self.args, self.pattern + [self.variadic]*vc):
#             if isinstance(arg, int):
#                 assert vt == 'index'
#                 yield arg
#             else:
#                 yield arg.as_arg(consttab, vt)
# 
#     def uses(self):
#         return set(arg for arg in self.args if isinstance(arg, Op))
# 
#     def __iter__(self):
#         return iter(self.args)


# Path: compile.py
from bincode.encoder import ConstantTable, dump_function
from spacing_functions import functions
from compiler_program import Function, Block, Constant, Op
            from evaluator import optable
import grammarlang
import os
import sys


def main(debug=False):
    for name in sys.argv[1:]:
        functions = []

        env = Scope(None, functions)