py/emitnative: Support arbitrary number of arguments to viper functions.

This commit is contained in:
Damien George 2018-09-15 16:06:58 +10:00
parent 43f1848bfa
commit a676b5acf6
5 changed files with 11 additions and 12 deletions

View File

@ -295,13 +295,6 @@ STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop
// generate code for entry to function
if (emit->do_viper_types) {
// right now we have a restriction of maximum of 4 arguments
if (scope->num_pos_args > REG_ARG_NUM) {
EMIT_NATIVE_VIPER_TYPE_ERROR(emit, "Viper functions don't currently support more than 4 arguments");
return;
}
// Work out size of state (locals plus stack)
// n_state counts all stack and locals, even those in registers
emit->n_state = scope->num_locals + scope->stack_size;

View File

@ -25,7 +25,15 @@ def f4(x1:int, x2:int, x3:int, x4:int):
print(x1, x2, x3, x4)
f4(1, 2, 3, 4)
# only up to 4 arguments currently supported
@micropython.viper
def f5(x1:int, x2:int, x3:int, x4:int, x5:int):
print(x1, x2, x3, x4, x5)
f5(1, 2, 3, 4, 5)
@micropython.viper
def f6(x1:int, x2:int, x3:int, x4:int, x5:int, x6:int):
print(x1, x2, x3, x4, x5, x6)
f6(1, 2, 3, 4, 5, 6)
# test compiling *x, **x, * args (currently unsupported at runtime)
@micropython.viper

View File

@ -3,3 +3,5 @@
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6

View File

@ -13,9 +13,6 @@ test("@micropython.viper\ndef f() -> 1: pass")
# unknown type
test("@micropython.viper\ndef f(x:unknown_type): pass")
# too many arguments
test("@micropython.viper\ndef f(a, b, c, d, e): pass")
# local used before type known
test("""
@micropython.viper

View File

@ -1,7 +1,6 @@
SyntaxError('annotation must be an identifier',)
SyntaxError('annotation must be an identifier',)
ViperTypeError("unknown type 'unknown_type'",)
ViperTypeError("Viper functions don't currently support more than 4 arguments",)
ViperTypeError("local 'x' used before type known",)
ViperTypeError("local 'x' has type 'int' but source is 'object'",)
ViperTypeError("can't implicitly convert 'ptr' to 'bool'",)