]> git.lizzy.rs Git - uwu-lang.git/commitdiff
Argument counting starts at 1 now
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sat, 1 Jan 2022 14:37:07 +0000 (15:37 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sat, 1 Jan 2022 14:37:07 +0000 (15:37 +0100)
api/util.c
api/vm.c
example/fibo.uwu
example/print_args.uwu
std/int.c
std/ref.c

index b6f9b4949906e87f5b86945099cec03a567cb80a..655213a45479dab47d20f507826d13de6d237586 100644 (file)
@@ -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);
        }
index 52a003c49f2dbe56fcde337bd9bff185610aca80..eb384d73be23ce6c5a5c7a7d03d53dd39bcbaffa 100644 (file)
--- 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);
index 48851c54ff05fc04952b6a8f1b4fd7ab31bb2646..c3a4aa50a487f14bee4f866d3cda13f0e53257aa 100644 (file)
@@ -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
        ))
index 2256a881e71d89de1eb0e0724e64a67a33ea783d..593b4beb8422c544b3057575f33062c1e2c715cc 100644 (file)
@@ -1,5 +1,5 @@
 main :str:cat(
-       $0,
        $1,
-       $2
+       $2,
+       $3
 )
index be314dc98cddd69153ecedabc86df3086c596908..615d3a5ed4d354b930ddc1caa6a90d17306bb9e9 100644 (file)
--- 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);
 
index f92e4b0c3933f385ca344ff97e71e9a6728a3cba..ee18bfcabbc67474061504d7dbc1d9cdb1d642c6 100644 (file)
--- 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);
 }