示例#1
0
def intrinsic(fn):
    intrinsic_name = as_dashed(fn.__name__)

    def wrapper(frame, args):
        debug(0, [':', '@!' + intrinsic.name] + [a.s() for a in args])
        return fn(frame, args)

    # make sure the name is stored as a symbol
    sym(intrinsic_name)

    intrinsic = Intrinsic(intrinsic_name, wrapper)
    intrinsics.register(intrinsic)
    return intrinsic
示例#2
0
def sym_arg_aux(flag, output=6, prefix='segnet_new', epoch=2):
    if flag == 'restart':
        sym = symbol.sym(output=output)
        return sym, {}, {}
    if flag == 'fineturn':
        import load_model
        sym = symbol.sym(output=output)
        arg = load_model.mxnet_test('VGG_FC_ILSVRC_16_layers', 74).arg_aux()
        arg_ = load_model.mxnet_test('VGG_FC_ILSVRC_16_layers', 74).arg_aux_1()
        arg.update(arg_)
        return sym, arg, {}
    if flag == 'continue':
        return mx.model.load_checkpoint(prefix, epoch)
    sym = symbol.sym(output=output)
    return sym, {}, {}
示例#3
0
        def invoke(self, frame, args):
            invokee = None
            symbol = sym(self.value)
            try:
                invokee = frame.env.get(symbol)
            except KeyError:
                raise frame.fail(tagged('no-such-function', self))

            if invokee.invokable:
                invokee.invokable.invoke(frame, args)
            else:
                frame.fail(tagged('not-invokable', invokee))
示例#4
0
def load_fd(fd):
    offsets = {
        'const': len(const_table),
        'label': len(label_table),
        'inst': len(inst_table),
    }

    # constants block
    num_constants = read_int(fd)
    for _ in range(0, num_constants):
        const = read_constant(fd)
        const_table.register(const)

    # symbols block
    num_symbols = read_int(fd)
    symbol_translation = [0] * num_symbols
    for i in range(0, num_symbols):
        val = read_str(fd)
        symbol_translation[i] = sym(val)

    num_labels = read_int(fd)
    for _ in range(0, num_labels):
        name = read_str(fd)
        addr = read_int(fd) + offsets['inst']
        trace = None
        has_trace = read_int(fd)
        trace = None
        if has_trace == 1: trace = read_str(fd)
        label = Label(name, addr, trace)
        register_label(label)

    num_insts = read_int(fd)
    for i in range(0, num_insts):
        command = read_str(fd)
        num_args = read_int(fd)
        raw_args = [999] * num_args
        for i in range(0, num_args):
            raw_args[i] = read_int(fd)
        inst_type = inst_type_table.get(command)
        args = inst_type.reindex(raw_args, offsets, symbol_translation)
        inst_table.register(Inst(inst_type.id, args))
示例#5
0
def has(frame, args):
    key = args[0].s()
    env = args[1]
    assert isinstance(env, Env)
    boolify(env.has(sym(key)), frame, 'no-key-' + key)
示例#6
0
    mag_binary = prefixed('/bin/magc')

    debug(0, ['magc out of date, recompiling', mag_binary, fname])
    spawn(mag_binary, [fname])


@intrinsic
def load(frame, args):
    fname = _get_fname(args)

    if not os.path.exists(fname): fname = prefixed(fname)

    if not os.path.exists(fname):
        frame.fail(tagged('no-such-file', String(fname)))

    label = precompile_and_load_file(fname)

    frame.proc.frame(base_env, label.addr, tail_elim=False)


base_env.let(sym('load'), load)


@intrinsic
def decomp(frame, args):
    if len(args) == 0:
        decomp_fd(1)  # stdout
    else:
        fname = _get_fname(args)
        decomp_to_file(fname)