本文整理汇总了Python中Target类的典型用法代码示例。如果您正苦于以下问题:Python Target类的具体用法?Python Target怎么用?Python Target使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Target类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _instr_cmp
def _instr_cmp(self, instr, cf):
rhs = cf.stack_pop()
lhs = cf.stack_pop()
it = Target.get_instr(instr)
if it == Target.CON_INSTR_EQ:
r = lhs.eq(self, rhs)
elif it == Target.CON_INSTR_LE:
r = lhs.le(self, rhs)
elif it == Target.CON_INSTR_NEQ:
r = lhs.neq(self, rhs)
elif it == Target.CON_INSTR_LE_EQ:
r = lhs.le_eq(self, rhs)
elif it == Target.CON_INSTR_GR_EQ:
r = lhs.gr_eq(self, rhs)
elif it == Target.CON_INSTR_GT:
r = lhs.gt(self, rhs)
else:
raise Exception("XXX")
if r:
cf.stack_push(rhs)
cf.bc_off += Target.INTSIZE
else:
self._fail_now(cf)
示例2: _instr_assign_slot
def _instr_assign_slot(self, instr, cf):
o = cf.stack_pop()
v = cf.stack_get(cf.stackpe - 1)
nm_start, nm_size = Target.unpack_assign_slot(instr)
nm = Target.extract_str(cf.pc.mod.bc, nm_start + cf.bc_off, nm_size)
o.set_slot(self, nm, v)
cf.bc_off += Target.align(nm_start + nm_size)
示例3: _instr_exbi
def _instr_exbi(self, instr, cf):
class_ = Builtins.type_check_class(self, cf.stack_pop())
bind_o = cf.stack_pop()
nm_start, nm_size = Target.unpack_exbi(instr)
nm = Target.extract_str(cf.pc.mod.bc, nm_start + cf.bc_off, nm_size)
pa = Builtins.Con_Partial_Application(self, class_.get_field(self, nm), [bind_o])
cf.stack_push(pa)
cf.bc_off += Target.align(nm_start + nm_size)
示例4: _instr_module_lookup
def _instr_module_lookup(self, instr, cf):
o = cf.stack_pop()
nm_start, nm_size = Target.unpack_mod_lookup(instr)
nm = Target.extract_str(cf.pc.mod.bc, cf.bc_off + nm_start, nm_size)
if isinstance(o, Builtins.Con_Module):
v = o.get_defn(self, nm)
else:
v = self.get_slot_apply(o, "get_defn", [Builtins.Con_String(self, nm)])
cf.stack_push(v)
cf.bc_off += Target.align(nm_start + nm_size)
示例5: _instr_unpack_assign
def _instr_unpack_assign(self, instr, cf):
o = cf.stack_get(cf.stackpe - 1)
o = Builtins.type_check_list(self, o)
ne = len(o.l)
if ne != Target.unpack_unpack_assign(instr):
self.raise_helper("Unpack_Exception", \
[Builtins.Con_Int(self, Target.unpack_unpack_assign(instr)), \
Builtins.Con_Int(self, ne)])
for i in range(ne - 1, -1, -1):
cf.stack_push(o.l[i])
cf.bc_off += Target.INTSIZE
示例6: _instr_is_assigned
def _instr_is_assigned(self, instr, cf):
closure_off, var_num = Target.unpack_var_lookup(instr)
closure = cf.closure
while closure_off > 0:
closure = closure.parent
closure_off -= 1
v = closure.vars[var_num]
if closure.vars[var_num] is not None:
pc = cf.pc
assert isinstance(pc, BC_PC)
mod_bc = pc.mod.bc
instr2 = Target.read_word(mod_bc, cf.bc_off + Target.INTSIZE)
cf.bc_off += Target.unpack_is_assigned(instr2)
else:
cf.bc_off += Target.INTSIZE + Target.INTSIZE
示例7: _instr_var_assign
def _instr_var_assign(self, instr, cf):
closure_off, var_num = Target.unpack_var_assign(instr)
closure = cf.closure
while closure_off > 0:
closure = closure.parent
closure_off -= 1
closure.vars[var_num] = cf.stack_get(cf.stackpe - 1)
cf.bc_off += Target.INTSIZE
示例8: _instr_var_lookup
def _instr_var_lookup(self, instr, cf):
closure_off, var_num = Target.unpack_var_lookup(instr)
closure = cf.closure
while closure_off > 0:
closure = closure.parent
closure_off -= 1
v = closure.vars[var_num]
if not v:
self.raise_helper("Unassigned_Var_Exception")
cf.stack_push(v)
cf.bc_off += Target.INTSIZE
示例9: _instr_calc
def _instr_calc(self, instr, cf):
rhs = cf.stack_pop()
lhs = cf.stack_pop()
it = Target.get_instr(instr)
if it == Target.CON_INSTR_ADD:
r = lhs.add(self, rhs)
else:
assert it == Target.CON_INSTR_SUBTRACT
r = lhs.subtract(self, rhs)
cf.stack_push(r)
cf.bc_off += Target.INTSIZE
示例10: _instr_func_defn
def _instr_func_defn(self, instr, cf):
is_bound, max_stack_size, has_loop = Target.unpack_func_defn(instr)
np_o = cf.stack_pop()
assert isinstance(np_o, Builtins.Con_Int)
nv_o = cf.stack_pop()
assert isinstance(nv_o, Builtins.Con_Int)
name = cf.stack_pop()
new_pc = BC_PC(cf.pc.mod, cf.bc_off + 2 * Target.INTSIZE)
container = cf.func.get_slot(self, "container")
f = Builtins.Con_Func(self, name, is_bound, new_pc, max_stack_size, np_o.v, nv_o.v, \
container, cf.closure, has_loop=has_loop)
cf.stack_push(f)
cf.bc_off += Target.INTSIZE
示例11: set_target
def set_target(self, crop_x, crop_y):
self.target = Target(self)
# need these for rendering the target
self.target.x_coord = crop_x
self.target.y_coord = crop_y
# need this stuff for calculating latitude and longitude
# * needs pitch, yaw, roll, pan, tilt from picture, etc.
gps_x = float(self.picture.gps_x)
gps_y = float(self.picture.gps_y)
pan = self.picture.pan
tilt = self.picture.tilt
yaw = self.picture.yaw
pitch = self.picture.pitch
roll = self.picture.roll
plane_orientation = self.picture.plane_orientation
altitude = self.picture.altitude
# * needs intrinsic camera matrix (should be in picture)
# -> in picture constructor put a bloggie = Camera() part
# -> right now all pictures should use the default image size of
# fully zoomed out, and the corresponding intrinsic params.
# If this were to change the image station would have to get
# the zoom level and use it to calculate new intrinsic params
M_int = self.picture.bloggie.get_intrinsic_matrix()
# * needs to determine real coordinates from crop coordinates
# -> for this define a seperate function.
# -> e.g. (real_x, real_y) = self.calculate_real_coordinates(
# crop_x + self.x_offset,
# crop_y + self.y_offset)
#
# *** to get x_offset and y_offset
# --> look at '_execute_generate_crop' and make it so xa and ya are stored
(real_x, real_y) = self.calculate_real_coordinates(crop_x, crop_y)
print "lat is: %f and long is %f" % (gps_x, gps_y,)
print "crop_coords are x: %d, y: %d" % (crop_x, crop_y,)
print "real coords are x: %d, y: %d" % (real_x, real_y,)
# FINALLY: pass all this info to the calculate_gps function, which
# will do matrix mults and math described in the blue notebook
#
self.target.calculate_gps(M_int, real_x, real_y, gps_x, gps_y, \
pan, tilt, yaw, pitch, roll, plane_orientation, altitude)
示例12: _instr_apply
def _instr_apply(self, instr, cf):
ff = cf.stack_get(cf.ffp)
assert isinstance(ff, Stack_Failure_Frame)
num_args = Target.unpack_apply(instr)
fp = cf.stackpe - num_args - 1
func = cf.stack_get(fp)
if isinstance(func, Builtins.Con_Partial_Application):
new_cf = self._add_continuation_frame(func.f, num_args + 1)
new_cf.stack_extend(func.args)
i = 1
else:
new_cf = self._add_continuation_frame(func, num_args)
i = 0
for j in range(0, num_args):
k = i + num_args - j - 1
assert k >= 0
jit.promote(k)
new_cf.stack[k] = cf.stack_pop()
new_cf.stackpe = i + num_args
if ff.is_fail_up:
gf = Stack_Generator_Frame(cf.gfp, cf.bc_off + Target.INTSIZE)
cf.stack_set(fp, gf)
cf.gfp = fp
o = self.apply_pump()
else:
cf.stack_pop() # Function pointer
o = self.execute_proc(new_cf)
self._remove_continuation_frame()
if o is self.get_builtin(Builtins.BUILTIN_FAIL_OBJ):
o = None
if o is None:
self._fail_now(cf)
return
cf.stack_push(o)
cf.bc_off += Target.INTSIZE
示例13: _instr_unpack_args
def _instr_unpack_args(self, instr, cf):
num_fargs, has_vargs = Target.unpack_unpack_args(instr)
num_fargs = jit.promote(num_fargs)
has_vargs = jit.promote(has_vargs)
if not has_vargs:
nargs = jit.promote(cf.nargs)
else:
nargs = cf.nargs
if nargs > num_fargs and not has_vargs:
msg = "Too many parameters (%d passed, but a maximum of %d allowed)." % \
(nargs, num_fargs)
self.raise_helper("Parameters_Exception", [Builtins.Con_String(self, msg)])
if num_fargs > 0:
arg_offset = cf.bc_off + Target.INTSIZE + num_fargs * Target.INTSIZE
for i in range(num_fargs - 1, -1, -1):
arg_offset -= Target.INTSIZE
arg_info = Target.read_word(cf.pc.mod.bc, arg_offset)
if i >= nargs:
if not Target.unpack_unpack_args_is_mandatory(arg_info):
msg = "No value passed for parameter %d." % (i + 1)
self.raise_helper("Parameters_Exception", [Builtins.Con_String(self, msg)])
else:
if nargs > num_fargs:
o = cf.stack_pop_n(nargs - num_fargs)
else:
o = cf.stack_pop()
assert isinstance(o, Builtins.Con_Object)
cf.closure.vars[Target.unpack_unpack_args_arg_num(arg_info)] = o
if has_vargs:
arg_offset = cf.bc_off + Target.INTSIZE + num_fargs * Target.INTSIZE
arg_info = Target.read_word(cf.pc.mod.bc, arg_offset)
if nargs <= num_fargs:
l = []
else:
j = cf.stackpe
i = j - (nargs - num_fargs)
assert i >= 0 and j >= 0
l = cf.stack_get_slice(i, j)
cf.stackpe = i + 1
cf.closure.vars[Target.unpack_unpack_args_arg_num(arg_info)] = Builtins.Con_List(self, l)
cf.bc_off += Target.INTSIZE + (num_fargs + 1) * Target.INTSIZE
else:
cf.bc_off += Target.INTSIZE + num_fargs * Target.INTSIZE
示例14: TestTargetFunctions
class TestTargetFunctions (unittest.TestCase):
def setUp (self):
""" Initializes a green and red target
"""
self.redTarget = Target ()
self.greenTarget = Target (isRed = False)
def tearDown (self):
""" Nothing to tear down
"""
pass
def test_update (self):
""" Tests that update increments the counter.
Then tests when counter resets, image is changed
"""
# Test that update increments the counter
self.redTarget.update()
self.assertEqual(self.redTarget._counter, 1)
# Test that when counter resets, currentImage increments
while self.redTarget._counter > 0:
self.redTarget.update()
self.assertEqual (self.redTarget._currentImage, 3)
def test_timedOut (self):
""" Tests that a target successfully times out
"""
for x in range (0, COUNTDOWN_FRAME * 5):
self.greenTarget.update ()
self.assertTrue (self.greenTarget.timedOut)
def test_isRed (self):
""" Tests isRed
"""
self.assertTrue (self.redTarget.isRed ())
示例15: _instr_set
def _instr_set(self, instr, cf):
ne = Target.unpack_set(instr)
l = cf.stack_get_slice_del(cf.stackpe - ne)
cf.stack_push(Builtins.Con_Set(self, l))
cf.bc_off += Target.INTSIZE