3 #include "../src/err.h"
5 #include "../api/bool.h"
7 static inline bool get_bool_arg(UwUVMArgs *args, size_t i)
9 return uwubool_get(uwuvm_get_arg(args, i));
12 UwUVMValue uwu_if(UwUVMArgs *args)
15 error("error: :bool:if requires exactly 3 arguments\n");
17 return uwuvm_copy_value(get_bool_arg(args, 0)
18 ? uwuvm_get_arg(args, 1)
19 : uwuvm_get_arg(args, 2)
23 UwUVMValue uwu_and(UwUVMArgs *args)
26 error("error: :bool:and requires at least one argument\n");
28 for (size_t i = 0; i < args->num; i++)
29 if (! get_bool_arg(args, i))
30 return uwubool_create(false);
32 return uwubool_create(true);
35 UwUVMValue uwu_or(UwUVMArgs *args)
38 error("error: :bool:or requires at least one argument\n");
40 for (size_t i = 0; i < args->num; i++)
41 if (get_bool_arg(args, i))
42 return uwubool_create(true);
44 return uwubool_create(false);
47 UwUVMValue uwu_equal(UwUVMArgs *args)
50 error("error: :bool:equal requires at least 2 arguments\n");
52 bool value = get_bool_arg(args, 0);
54 for (size_t i = 1; i < args->num; i++)
55 if (get_bool_arg(args, i) != value)
56 return uwubool_create(false);
58 return uwubool_create(true);
61 UwUVMValue uwu_not(UwUVMArgs *args)
64 error("error: :bool:not requires exactly 1 argument\n");
66 return uwubool_create(! get_bool_arg(args, 0));
69 UwUVMValue uwu_true(UwUVMArgs *args)
72 error("error: :bool:true does not take any arguments\n");
74 return uwubool_create(true);
77 UwUVMValue uwu_false(UwUVMArgs *args)
80 error("error: :bool:false does not take any arguments\n");
82 return uwubool_create(false);
85 UwUVMValue uwu_is(UwUVMArgs *args)
88 error("error: :bool:is requires at least 1 argument\n");
90 for (size_t i = 0; i < args->num; i++)
91 if (uwuvm_get_arg(args, i).type != &uwubool_type)
92 return uwubool_create(false);
94 return uwubool_create(true);