Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
6f81348f
Commit
6f81348f
authored
Sep 29, 2014
by
Damien George
Browse files
py: Allow viper to use ints as direct conditionals in jumps.
Allows things like: if 1: ...
parent
a7329615
Changes
3
Hide whitespace changes
Inline
Side-by-side
py/emitnative.c
View file @
6f81348f
...
...
@@ -1365,20 +1365,25 @@ STATIC void emit_native_jump(emit_t *emit, mp_uint_t label) {
STATIC
void
emit_native_jump_helper
(
emit_t
*
emit
,
mp_uint_t
label
,
bool
pop
)
{
vtype_kind_t
vtype
=
peek_vtype
(
emit
);
if
(
vtype
==
VTYPE_BOOL
)
{
emit_pre_pop_reg
(
emit
,
&
vtype
,
REG_RET
);
if
(
!
pop
)
{
adjust_stack
(
emit
,
1
);
}
}
else
if
(
vtype
==
VTYPE_PYOBJ
)
{
emit_pre_pop_reg
(
emit
,
&
vtype
,
REG_ARG_1
);
if
(
!
pop
)
{
adjust_stack
(
emit
,
1
);
}
emit_call
(
emit
,
MP_F_OBJ_IS_TRUE
);
}
else
{
printf
(
"ViperTypeError: expecting a bool or pyobj, got %d
\n
"
,
vtype
);
assert
(
0
);
switch
(
vtype
)
{
case
VTYPE_PYOBJ
:
emit_pre_pop_reg
(
emit
,
&
vtype
,
REG_ARG_1
);
if
(
!
pop
)
{
adjust_stack
(
emit
,
1
);
}
emit_call
(
emit
,
MP_F_OBJ_IS_TRUE
);
break
;
case
VTYPE_BOOL
:
case
VTYPE_INT
:
case
VTYPE_UINT
:
emit_pre_pop_reg
(
emit
,
&
vtype
,
REG_RET
);
if
(
!
pop
)
{
adjust_stack
(
emit
,
1
);
}
break
;
default:
printf
(
"ViperTypeError: expecting a bool or pyobj, got %d
\n
"
,
vtype
);
assert
(
0
);
}
// need to commit stack because we may jump elsewhere
need_stack_settled
(
emit
);
...
...
tests/micropython/viper_cond.py
0 → 100644
View file @
6f81348f
# using a bool as a conditional
@
micropython
.
viper
def
f
():
x
=
True
if
x
:
print
(
"x"
,
x
)
f
()
# using an int as a conditional
@
micropython
.
viper
def
g
():
y
=
1
if
y
:
print
(
"y"
,
y
)
g
()
tests/micropython/viper_cond.py.exp
0 → 100644
View file @
6f81348f
x True
y 1
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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