]> Nishi Git Mirror - gwion.git/commitdiff
:art: fun $ funptr
authorJérémie Astor <fennecdjay@gmail.com>
Wed, 27 Apr 2022 17:11:34 +0000 (19:11 +0200)
committerJérémie Astor <fennecdjay@gmail.com>
Wed, 27 Apr 2022 17:11:34 +0000 (19:11 +0200)
src/lib/lib_func.c

index a9e6cb51fe30f3d882c760070aa26d458a5b10d5..6550ea98d1e704aa613aa43a15f4bea665b806ef 100644 (file)
@@ -387,6 +387,7 @@ static OP_CHECK(opck_fptr_at) {
   exp_setvar(bin->rhs, 1);
   return bin->rhs->type;
 }
+
 /*
 static OP_CHECK(opck_fptr_cast) {
   Exp_Cast *      cast = (Exp_Cast *)data;
@@ -424,6 +425,15 @@ static OP_CHECK(opck_fptr_impl) {
   return impl->t;
 }
 
+static OP_CHECK(opck_fptr_cast) {
+  Exp_Cast *cast = (Exp_Cast *)data;
+  const Type t = known_type(env, cast->td);
+  struct FptrInfo  info = {cast->exp->type->info->func, t->info->func,
+                          cast->exp, cast->td->pos};
+  CHECK_BN(fptr_do(env, &info));
+  return t;
+}
+
 // smh the VM should be able to do that
 static INSTR(Func2Code) {
   *(VM_Code *)REG(-SZ_INT) = (*(Func *)REG(-SZ_INT))->code;
@@ -724,6 +734,8 @@ GWION_IMPORT(func) {
   GWI_BB(gwi_oper_add(gwi, opck_fptr_impl))
   GWI_BB(gwi_oper_emi(gwi, opem_fptr_impl))
   GWI_BB(gwi_oper_end(gwi, "@implicit", NULL))
+  GWI_BB(gwi_oper_add(gwi, opck_fptr_cast))
+  GWI_BB(gwi_oper_end(gwi, "$", NULL))
   GWI_BB(gwi_oper_ini(gwi, "@op", "@func_ptr", NULL))
   GWI_BB(gwi_oper_add(gwi, opck_op_impl))
   GWI_BB(gwi_oper_emi(gwi, opem_op_impl))