From 111086ccb0967a756ebe6747851821da54a6928e Mon Sep 17 00:00:00 2001
From: fennecdjay <fennecdjay@gmail.com>
Date: Fri, 16 Feb 2024 16:51:57 +0100
Subject: [PATCH] :art: more bool

---
 ast             |  2 +-
 include/array.h |  2 +-
 plug            |  2 +-
 src/emit/emit.c |  6 +++---
 src/lib/array.c | 20 +++++++++++---------
 src/lib/dict.c  |  4 ++--
 src/lib/ugen.c  |  6 +++---
 7 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/ast b/ast
index ff6cac51..f8ed98c9 160000
--- a/ast
+++ b/ast
@@ -1 +1 @@
-Subproject commit ff6cac512fe72a7fd108def245b8744708584571
+Subproject commit f8ed98c97d7b938bb3d116e9428e9b52a3e76450
diff --git a/include/array.h b/include/array.h
index 4ae02081..22143610 100644
--- a/include/array.h
+++ b/include/array.h
@@ -20,7 +20,7 @@ typedef struct ArrayInfo_ {
 } ArrayInfo;
 
 ANN Type   check_array_access(const Env env, const Array_Sub array);
-ANN m_bool emit_array_access(const Emitter                 emit,
+ANN bool emit_array_access(const Emitter                 emit,
                              struct ArrayAccessInfo *const info);
 ANN2(1,2) bool check_array_instance(const Env env, Type_Decl *td, Exp* args);
 #endif
diff --git a/plug b/plug
index 1ce5b946..1d1f9c36 160000
--- a/plug
+++ b/plug
@@ -1 +1 @@
-Subproject commit 1ce5b946d432ed53fbcdf5d85781f627036049b8
+Subproject commit 1d1f9c36fa7129e4095f86c7ef89f48112672454
diff --git a/src/emit/emit.c b/src/emit/emit.c
index 3b0cec62..4a788ed6 100644
--- a/src/emit/emit.c
+++ b/src/emit/emit.c
@@ -674,7 +674,7 @@ ANN static m_bool emit_prim_dict(const Emitter emit, Exp* *data) {
   return GW_OK;
 }
 
-ANN m_bool emit_array_access(const Emitter                 emit,
+ANN bool emit_array_access(const Emitter                 emit,
                              struct ArrayAccessInfo *const info) {
   if (tflag(info->array.type, tflag_typedef))
     info->array.type = typedef_base(info->array.type);
@@ -683,7 +683,7 @@ ANN m_bool emit_array_access(const Emitter                 emit,
                           .lhs  = info->array.exp->type,
                           .rhs  = info->array.type,
                           .data = (uintptr_t)info};
-  return op_emit(emit, &opi);
+  return op_emit(emit, &opi) > 0;
 }
 
 ANN static m_bool emit_exp_array(const Emitter emit, const Exp_Array *array) {
@@ -694,7 +694,7 @@ ANN static m_bool emit_exp_array(const Emitter emit, const Exp_Array *array) {
     .array = *array->array,
     .type = e->type,
     .is_var = exp_getvar(e)};
-  return emit_array_access(emit, &info);
+  return emit_array_access(emit, &info) ? GW_OK : GW_ERROR;
 }
 
 ANN static m_bool emit_exp_slice(const Emitter emit, const Exp_Slice *range) {
diff --git a/src/lib/array.c b/src/lib/array.c
index 291468a9..5aadae63 100644
--- a/src/lib/array.c
+++ b/src/lib/array.c
@@ -182,11 +182,11 @@ static OP_CHECK(opck_array_sr) {
   return check_array_shift(env, bin->rhs, bin->lhs, ">>", exp_self(bin)->loc);
 }
 
-ANN static inline m_bool emit_array_shift(const Emitter emit,
+ANN static inline bool emit_array_shift(const Emitter emit,
                                           const f_instr exec) {
   emit_regmove(emit, -SZ_INT);
   (void)emit_add_instr(emit, exec);
-  return GW_OK;
+  return true;
 }
 
 static INSTR(ArrayAppendFront) {
@@ -233,7 +233,7 @@ static INSTR(ArrayConcatRight) {
 static OP_EMIT(opem_array_sr) {
   const Exp_Binary *bin = (Exp_Binary *)data;
   if (shift_match(bin->lhs->type, bin->rhs->type))
-    return emit_array_shift(emit, ArrayConcatRight);
+    return emit_array_shift(emit, ArrayConcatRight) ? GW_OK : GW_ERROR;
   emit_regmove(emit, -SZ_INT);
   if (tflag(bin->lhs->type, tflag_compound))
     emit_compound_addref(emit, bin->lhs->type, -SZ_INT - bin->lhs->type->size, false);
@@ -244,7 +244,7 @@ static OP_EMIT(opem_array_sr) {
 static OP_EMIT(opem_array_sl) {
   const Exp_Binary *bin = (Exp_Binary *)data;
   if (shift_match(bin->rhs->type,  bin->lhs->type))
-    return emit_array_shift(emit, ArrayConcatLeft);
+    return emit_array_shift(emit, ArrayConcatLeft) ? GW_OK : GW_ERROR;
   if (tflag(bin->rhs->type, tflag_compound))
     emit_compound_addref(emit, bin->rhs->type, -bin->rhs->type->size, false);
   emit_regmove(emit, -bin->rhs->type->size);
@@ -329,9 +329,9 @@ static OP_CHECK(opck_array_slice) {
   return e->d.exp_slice.base->type;
 }
 
-static inline m_bool bounds(const M_Vector v, const m_int i) {
-  CHECK_BB(i);
-  return (m_uint)i < ARRAY_LEN(v) ? GW_OK : GW_ERROR;
+static inline bool bounds(const M_Vector v, const m_int i) {
+  CHECK_B(i);
+  return (m_uint)i < ARRAY_LEN(v);
 }
 
 static INSTR(ArraySlice) {
@@ -343,7 +343,7 @@ static INSTR(ArraySlice) {
   if (end < 0) end = ARRAY_LEN(in) + end;
   const m_int  op = start < end ? 1 : -1;
   const m_uint sz = op > 0 ? end - start : start - end;
-  if (bounds(in, start) < 0 || bounds(in, end) < 0) {
+  if (!bounds(in, start) || !bounds(in, end)) {
     handle(shred, "OutOfBoundsArraySliceException");
     return;
   }
@@ -462,7 +462,9 @@ static OP_EMIT(opem_array_access) {
   Exp* exp             = emit_n_exp(emit, info);
   next.exp                  = exp;
   info->array               = next;
-  return exp ? emit_array_access(emit, info) : GW_ERROR;
+  if(exp)
+    return emit_array_access(emit, info) ? GW_OK : GW_ERROR;
+  return GW_ERROR;
 }
 
 static m_bit                 map_byte[BYTECODE_SZ * 5];
diff --git a/src/lib/dict.c b/src/lib/dict.c
index ceeb72a2..1e83c35a 100644
--- a/src/lib/dict.c
+++ b/src/lib/dict.c
@@ -431,7 +431,7 @@ static OP_EMIT(opem_dict_remove) {
   return GW_OK;
 }
 
-ANN static m_bool emit_next_access(const Emitter emit, struct ArrayAccessInfo *const info) {
+ANN static bool emit_next_access(const Emitter emit, struct ArrayAccessInfo *const info) {
   const struct Array_Sub_ array = info->array;
   HMapInfo *const hinfo = (HMapInfo*)info->array.type->nspc->class_data;
   info->array = (struct Array_Sub_){
@@ -450,7 +450,7 @@ static OP_EMIT(opem_dict_access) {
   const m_bool ret = _opem_dict_access(emit, data);
   array->exp->next = enext;
   CHECK_BB(ret);
-  return !enext ? GW_OK : emit_next_access(emit, info);
+  return !enext ? GW_OK : (emit_next_access(emit, info) ? GW_OK : GW_ERROR);
 }
 
 static OP_CHECK(opck_dict_access) {
diff --git a/src/lib/ugen.c b/src/lib/ugen.c
index eb5e7d78..7162f8af 100644
--- a/src/lib/ugen.c
+++ b/src/lib/ugen.c
@@ -168,9 +168,9 @@ ANN static void release_connect(const VM_Shred shred) {
 }
 
 typedef ANN void (*f_connect)(const UGen lhs, const UGen rhs);
-ANN /* static */ void _do_(const f_connect f, const UGen lhs, const UGen rhs) {
-  const m_bool l_multi = lhs->multi;
-  const m_bool r_multi = rhs->multi;
+ANN static void _do_(const f_connect f, const UGen lhs, const UGen rhs) {
+  const bool l_multi = lhs->multi;
+  const bool r_multi = rhs->multi;
   const uint   l_max   = l_multi ? lhs->connect.multi->n_out : 1;
   const uint   r_max   = r_multi ? rhs->connect.multi->n_in : 1;
   const uint   max     = l_max > r_max ? l_max : r_max;
-- 
2.43.0