]> Nishi Git Mirror - gwion.git/commitdiff
:art: Add Object conditionnal
authorJérémie Astor <fennecdjay@gmail.com>
Sun, 5 Sep 2021 21:21:45 +0000 (23:21 +0200)
committerJérémie Astor <fennecdjay@gmail.com>
Sun, 5 Sep 2021 21:21:45 +0000 (23:21 +0200)
src/lib/object_op.c

index 04f92bded7b6176a87a8fff8484fd418d8789a52..d06c65e6532baeef16b7782383ec6fb528802701 100644 (file)
@@ -348,9 +348,6 @@ static OP_EMIT(opem_not_object) {
   const Instr  back = (Instr)vector_back(v);
   if (back->opcode == eGWOP_EXCEPT) {
     back->opcode = eIntNot;
-//    vector_pop(v);
-//    mp_free(emit->gwion->mp, Instr, back);
-//    emit_add_instr(emit, IntNot);
     return GW_OK;
   }
   const Instr instr = emit_add_instr(emit, RegSetImm);
@@ -358,6 +355,28 @@ static OP_EMIT(opem_not_object) {
   return GW_OK;
 }
 
+static OP_EMIT(opem_uncond_object) {
+  const Vector v    = &emit->code->instr;
+  const Instr  back = (Instr)vector_at(v, vector_size(v) -2);
+  if (back->opcode == eGWOP_EXCEPT) {
+    free_instr(emit->gwion, back);
+    vector_rem(v, vector_size(v) - 2);
+  }
+  emit_add_instr(emit, BranchNeqInt);
+  return GW_OK;
+}
+
+static OP_EMIT(opem_cond_object) {
+  const Vector v    = &emit->code->instr;
+  const Instr  back = (Instr)vector_at(v, vector_size(v) -2);
+  if (back->opcode == eGWOP_EXCEPT) {
+    free_instr(emit->gwion, back);
+    vector_rem(v, vector_size(v) - 2);
+  }
+  emit_add_instr(emit, BranchEqInt);
+  return GW_OK;
+}
+
 GWION_IMPORT(object_op) {
   const Type t_error         = gwi_mk_type(gwi, "@error", 0, NULL);
   gwi->gwion->type[et_error] = t_error;
@@ -371,12 +390,13 @@ GWION_IMPORT(object_op) {
   GWI_BB(gwi_oper_end(gwi, "!=", NeqObject))
   GWI_BB(gwi_oper_add(gwi, opck_object_cast))
   GWI_BB(gwi_oper_end(gwi, "$", NULL))
-  //.  GWI_BB(gwi_oper_add(gwi, opck_implicit_null2obj))
-  //  GWI_BB(gwi_oper_emi(gwi, opem_implicit_null2obj))
-  //  GWI_BB(gwi_oper_end(gwi, "@implicit", NULL))
   GWI_BB(gwi_oper_ini(gwi, NULL, "Object", "bool"))
+  GWI_BB(gwi_oper_emi(gwi, opem_uncond_object))
+  GWI_BB(gwi_oper_end(gwi, "@unconditionnal", NULL))
+  GWI_BB(gwi_oper_emi(gwi, opem_cond_object))
+  GWI_BB(gwi_oper_end(gwi, "@conditional", NULL))
   GWI_BB(gwi_oper_emi(gwi, opem_not_object))
-  GWI_BB(gwi_oper_end(gwi, "!", IntNot))
+  GWI_BB(gwi_oper_end(gwi, "!", NULL))
   GWI_BB(gwi_oper_ini(gwi, "@Compound", NULL, NULL))
   GWI_BB(gwi_oper_add(gwi, opck_struct_scan))
   GWI_BB(gwi_oper_end(gwi, "@scan", NULL))