txlyre 23 hours ago
parent
commit
92a7ebaf08
2 changed files with 20 additions and 0 deletions
  1. 19 0
      qirt.c
  2. 1 0
      qirt.h

+ 19 - 0
qirt.c

@@ -2828,6 +2828,25 @@ leave:
   return NULL;
 }
 
+qi_value_t *qi_unary_plus(qi_state_t *state, qi_value_t *a) {
+  qi_value_t *meta;
+  bool fail = false;
+  if ((meta = qi_call_meta(state, &fail, a, "__unary_plus", 1, a)))
+    return meta;
+
+  if (fail)
+    goto leave;
+
+  if (a->type == QI_NUMBER)
+    return a;
+
+leave:
+  qi_throw_format(state, "unsupported operand type for unary +: %s",
+                  _qi_type(state, a));
+
+  return NULL;
+}
+
 qi_value_t *qi_bnot(qi_state_t *state, qi_value_t *a) {
   qi_value_t *meta;
   bool fail = false;

+ 1 - 0
qirt.h

@@ -429,6 +429,7 @@ qi_value_t *qi_shr(qi_state_t *state, qi_value_t *a, qi_value_t *b);
 bool _qi_lt(qi_state_t *state, qi_value_t *a, qi_value_t *b);
 bool _qi_gt(qi_state_t *state, qi_value_t *a, qi_value_t *b);
 qi_value_t *qi_negate(qi_state_t *state, qi_value_t *a);
+qi_value_t *qi_unary_plus(qi_state_t *state, qi_value_t *a);
 qi_value_t *qi_bnot(qi_state_t *state, qi_value_t *a);
 void qi_exit(qi_state_t *state, int code);
 void *qi_thread_create(qi_state_t *state, qi_value_t *fn, qi_list_t *args);