From: Elias Fleckenstein Date: Sat, 1 Jan 2022 14:37:07 +0000 (+0100) Subject: Argument counting starts at 1 now X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=8e3ed7630c7383869b6e16b494d4288c4e094dd3;p=uwu-lang.git Argument counting starts at 1 now --- diff --git a/api/util.c b/api/util.c index b6f9b49..655213a 100644 --- a/api/util.c +++ b/api/util.c @@ -17,7 +17,7 @@ void uwuutil_require_min(const char *fnname, UwUVMArgs *args, size_t n) { if (args->num < n) { if (n == 1) - error("type error: %s requires at least one optional argument, but none were given\n", fnname); + error("type error: %s requires at least one argument, but none were given\n", fnname); else error("type error: %s requires at least %d arguments, but only %d were given\n", fnname, n, args->num); } diff --git a/api/vm.c b/api/vm.c index 52a003c..eb384d7 100644 --- a/api/vm.c +++ b/api/vm.c @@ -44,10 +44,12 @@ UwUVMValue uwuvm_evaluate_expression(UwUVMExpression *expression, UwUVMArgs *arg return uwustr_create(expression->value.str_value); case EX_ARGNUM: - if ((size_t) expression->value.int_value >= args->num) - error("type error: not enough arguments (accessed argument $%d, but only %lu arguments were passed)\n", expression->value.int_value, args->num); + if (expression->value.int_value == 0) + error("type error: trying to access argument $0\n"); + if ((size_t) expression->value.int_value > args->num) + error("type error: trying to access argument $%d, but only %lu arguments were passed)\n", expression->value.int_value, args->num); - return uwuvm_clone_value(uwuvm_get_arg(args, expression->value.int_value)); + return uwuvm_clone_value(uwuvm_get_arg(args, expression->value.int_value - 1)); case EX_FNNAME: return uwuref_create(expression->value.ref_value); diff --git a/example/fibo.uwu b/example/fibo.uwu index 48851c5..c3a4aa5 100644 --- a/example/fibo.uwu +++ b/example/fibo.uwu @@ -1,24 +1,24 @@ -if :bool:if($0, $1, $2) -smaller :int:smaller($0, $1) -equal :int:equal($0, $1) -add :int:add($0, $1) -sub :int:sub($0, $1) +if :bool:if($1, $2, $3) +smaller :int:smaller($1, $2) +equal :int:equal($1, $2) +add :int:add($1, $2) +sub :int:sub($1, $2) newline " " fibo - if(smaller($0, 0), 0, - if(equal($0, 0), 1, + if(smaller($1, 0), 0, + if(equal($1, 0), 1, add( - fibo(sub($0, 1)), - fibo(sub($0, 2)) + fibo(sub($1, 1)), + fibo(sub($1, 2)) ))) print - if(smaller($0, 0), "", + if(smaller($1, 0), "", :str:cat( - print(sub($0, 1)), - fibo($0), + print(sub($1, 1)), + fibo($1), newline )) diff --git a/example/print_args.uwu b/example/print_args.uwu index 2256a88..593b4be 100644 --- a/example/print_args.uwu +++ b/example/print_args.uwu @@ -1,5 +1,5 @@ main :str:cat( - $0, $1, - $2 + $2, + $3 ) diff --git a/std/int.c b/std/int.c index be314dc..615d3a5 100644 --- a/std/int.c +++ b/std/int.c @@ -23,12 +23,12 @@ static long binary(const char *fnname, UwUVMArgs *args, BinaryOP op) UwUVMValue value0 = uwuvm_get_arg(args, 0); if (value0.type != &uwuint_type) - error("type error: %s requires an integer as $0\n", fnname); + error("type error: %s requires an integer as $1\n", fnname); UwUVMValue value1 = uwuvm_get_arg(args, 1); if (value1.type != &uwuint_type) - error("type error: %s requires an integer as $1\n", fnname); + error("type error: %s requires an integer as $2\n", fnname); long a = uwuint_get(value0); long b = uwuint_get(value1); @@ -60,7 +60,7 @@ static long reduce(const char *fnname, UwUVMArgs *args, ReduceOP op, long result UwUVMValue value = uwuvm_get_arg(args, i); if (value.type != &uwuint_type) - error("type error: %s only accepts integers as arguments (invalid argument: $%lu)\n", fnname, i); + error("type error: %s only accepts integers as arguments (invalid argument: $%lu)\n", fnname, i + 1); long this = uwuint_get(value); diff --git a/std/ref.c b/std/ref.c index f92e4b0..ee18bfc 100644 --- a/std/ref.c +++ b/std/ref.c @@ -9,7 +9,7 @@ UwUVMValue uwu_call(UwUVMArgs *args) UwUVMValue value = uwuvm_get_arg(args, 0); if (value.type != &uwuref_type) - error(":ref:call requires a function reference as $0\n"); + error(":ref:call requires a function reference as $1\n"); return uwuvm_call_function(value.data, args->num - 1, &args->unevaluated[1], args->super); }