Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
bc1d3692
Commit
bc1d3692
authored
Jan 11, 2014
by
Damien George
Browse files
py: Fix emitcpy and emitnative's binary_op.
parent
8d4ccc49
Changes
3
Hide whitespace changes
Inline
Side-by-side
py/emitcpy.c
View file @
bc1d3692
...
...
@@ -551,7 +551,13 @@ static void emit_cpy_unary_op(emit_t *emit, rt_unary_op_t op) {
}
static
void
emit_cpy_binary_op
(
emit_t
*
emit
,
rt_binary_op_t
op
)
{
emit_pre
(
emit
,
-
1
,
1
);
if
(
op
<=
RT_BINARY_OP_INPLACE_POWER
)
{
// CPython uses a byte code for each binary op
emit_pre
(
emit
,
-
1
,
1
);
}
else
{
// CPython uses a byte code plus an argument for compare ops
emit_pre
(
emit
,
-
1
,
3
);
}
if
(
emit
->
pass
==
PASS_3
)
{
switch
(
op
)
{
case
RT_BINARY_OP_SUBSCR
:
printf
(
"BINARY_SUBSCR
\n
"
);
break
;
...
...
py/emitnative.c
View file @
bc1d3692
...
...
@@ -997,13 +997,29 @@ static void emit_native_binary_op(emit_t *emit, rt_binary_op_t op) {
vtype_kind_t
vtype_lhs
,
vtype_rhs
;
emit_pre_pop_reg_reg
(
emit
,
&
vtype_rhs
,
REG_ARG_3
,
&
vtype_lhs
,
REG_ARG_2
);
if
(
vtype_lhs
==
VTYPE_INT
&&
vtype_rhs
==
VTYPE_INT
)
{
assert
(
op
==
RT_BINARY_OP_ADD
||
op
==
RT_BINARY_OP_INPLACE_ADD
)
;
if
(
op
==
RT_BINARY_OP_ADD
||
op
==
RT_BINARY_OP_INPLACE_ADD
)
{
#if N_X64
asm_x64_add_r64_to_r64
(
emit
->
as
,
REG_ARG_3
,
REG_ARG_2
);
asm_x64_add_r64_to_r64
(
emit
->
as
,
REG_ARG_3
,
REG_ARG_2
);
#elif N_THUMB
asm_thumb_add_reg_reg_reg
(
emit
->
as
,
REG_ARG_2
,
REG_ARG_2
,
REG_ARG_3
);
asm_thumb_add_reg_reg_reg
(
emit
->
as
,
REG_ARG_2
,
REG_ARG_2
,
REG_ARG_3
);
#endif
emit_post_push_reg
(
emit
,
VTYPE_INT
,
REG_ARG_2
);
emit_post_push_reg
(
emit
,
VTYPE_INT
,
REG_ARG_2
);
}
else
if
(
op
==
RT_COMPARE_OP_LESS
)
{
#if N_X64
asm_x64_xor_r64_to_r64
(
emit
->
as
,
REG_RET
,
REG_RET
);
asm_x64_cmp_r64_with_r64
(
emit
->
as
,
REG_ARG_3
,
REG_ARG_2
);
asm_x64_setcc_r8
(
emit
->
as
,
JCC_JL
,
REG_RET
);
#elif N_THUMB
asm_thumb_cmp_reg_reg
(
emit
->
as
,
REG_ARG_2
,
REG_ARG_3
);
asm_thumb_ite_ge
(
emit
->
as
);
asm_thumb_movs_rlo_i8
(
emit
->
as
,
REG_RET
,
0
);
// if r0 >= r1
asm_thumb_movs_rlo_i8
(
emit
->
as
,
REG_RET
,
1
);
// if r0 < r1
#endif
emit_post_push_reg
(
emit
,
VTYPE_BOOL
,
REG_RET
);
}
else
{
// TODO other ops not yet implemented
assert
(
0
);
}
}
else
if
(
vtype_lhs
==
VTYPE_PYOBJ
&&
vtype_rhs
==
VTYPE_PYOBJ
)
{
emit_call_with_imm_arg
(
emit
,
RT_F_BINARY_OP
,
rt_binary_op
,
op
,
REG_ARG_1
);
emit_post_push_reg
(
emit
,
VTYPE_PYOBJ
,
REG_RET
);
...
...
py/runtime0.h
View file @
bc1d3692
...
...
@@ -31,6 +31,7 @@ typedef enum {
RT_BINARY_OP_INPLACE_TRUE_DIVIDE
,
RT_BINARY_OP_INPLACE_MODULO
,
RT_BINARY_OP_INPLACE_POWER
,
// TODO probably should rename these COMPARE->BINARY
RT_COMPARE_OP_LESS
,
RT_COMPARE_OP_MORE
,
RT_COMPARE_OP_EQUAL
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment