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
9f5f156b
Commit
9f5f156b
authored
Oct 08, 2015
by
Damien George
Browse files
py/emitnative: Raise ViperTypeError for unsupported unary ops.
parent
7e12a601
Changes
3
Hide whitespace changes
Inline
Side-by-side
py/emitnative.c
View file @
9f5f156b
...
...
@@ -1974,14 +1974,19 @@ STATIC void emit_native_pop_except(emit_t *emit) {
STATIC
void
emit_native_unary_op
(
emit_t
*
emit
,
mp_unary_op_t
op
)
{
vtype_kind_t
vtype
;
emit_pre_pop_reg
(
emit
,
&
vtype
,
REG_ARG_2
);
assert
(
vtype
==
VTYPE_PYOBJ
);
if
(
op
==
MP_UNARY_OP_NOT
)
{
// we need to synthesise this operation by converting to bool first
emit_call_with_imm_arg
(
emit
,
MP_F_UNARY_OP
,
MP_UNARY_OP_BOOL
,
REG_ARG_1
);
ASM_MOV_REG_REG
(
emit
->
as
,
REG_ARG_2
,
REG_RET
);
if
(
vtype
==
VTYPE_PYOBJ
)
{
if
(
op
==
MP_UNARY_OP_NOT
)
{
// we need to synthesise this operation by converting to bool first
emit_call_with_imm_arg
(
emit
,
MP_F_UNARY_OP
,
MP_UNARY_OP_BOOL
,
REG_ARG_1
);
ASM_MOV_REG_REG
(
emit
->
as
,
REG_ARG_2
,
REG_RET
);
}
emit_call_with_imm_arg
(
emit
,
MP_F_UNARY_OP
,
op
,
REG_ARG_1
);
emit_post_push_reg
(
emit
,
VTYPE_PYOBJ
,
REG_RET
);
}
else
{
adjust_stack
(
emit
,
1
);
EMIT_NATIVE_VIPER_TYPE_ERROR
(
emit
,
"unary op %q not implemented"
,
mp_unary_op_method_name
[
op
]);
}
emit_call_with_imm_arg
(
emit
,
MP_F_UNARY_OP
,
op
,
REG_ARG_1
);
emit_post_push_reg
(
emit
,
VTYPE_PYOBJ
,
REG_RET
);
}
STATIC
void
emit_native_binary_op
(
emit_t
*
emit
,
mp_binary_op_t
op
)
{
...
...
tests/micropython/viper_error.py
View file @
9f5f156b
...
...
@@ -52,3 +52,8 @@ test("@micropython.viper\ndef f(): 1[x] = 1")
# must raise an object
test
(
"@micropython.viper
\n
def f(): raise 1"
)
# unary ops not implemented
test
(
"@micropython.viper
\n
def f(x:int): +x"
)
test
(
"@micropython.viper
\n
def f(x:int): -x"
)
test
(
"@micropython.viper
\n
def f(x:int): ~x"
)
tests/micropython/viper_error.py.exp
View file @
9f5f156b
...
...
@@ -10,3 +10,6 @@ ViperTypeError("can't load from 'int'",)
ViperTypeError("can't store to 'int'",)
ViperTypeError("can't store to 'int'",)
ViperTypeError('must raise an object',)
ViperTypeError('unary op __pos__ not implemented',)
ViperTypeError('unary op __neg__ not implemented',)
ViperTypeError('unary op __invert__ not implemented',)
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