]> Nishi Git Mirror - gwion.git/commitdiff
:art: array and range/slice access
authorfennecdjay <fennecdjay@gmail.com>
Mon, 24 Oct 2022 17:58:13 +0000 (19:58 +0200)
committerfennecdjay <fennecdjay@gmail.com>
Mon, 24 Oct 2022 17:58:13 +0000 (19:58 +0200)
plug
src/emit/emit.c
src/import/import_prim.c
src/lib/array.c
src/lib/dict.c
src/lib/prim.c
src/lib/string.c
src/parse/check.c

diff --git a/plug b/plug
index f69bdbeee0f878c46de0a1e44c2236cacc332fe3..a9eaca11c2bf2408316968cad2619a9161f204b5 160000 (submodule)
--- a/plug
+++ b/plug
@@ -1 +1 @@
-Subproject commit f69bdbeee0f878c46de0a1e44c2236cacc332fe3
+Subproject commit a9eaca11c2bf2408316968cad2619a9161f204b5
index bbce4f15ee92be26e7f7aed384d588c9611404cd..dc978ff2552b874477f76c3bd983181eb481c0c1 100644 (file)
@@ -657,10 +657,10 @@ ANN static m_bool emit_prim_range(const Emitter emit, Range **data) {
   Range *range = *data;
   CHECK_BB(emit_range(emit, range));
   const Exp    e   = range->start ?: range->end;
-  const Symbol sym = insert_symbol("@range");
+  const Symbol sym = insert_symbol("[:]");
   assert(e);
   struct Op_Import opi = {.op   = sym,
-                          .rhs  = e->type,
+                          .lhs  = e->type,
                           .pos  = e->pos,
                           .data = (uintptr_t)prim_exp(data)};
   CHECK_BB(op_emit(emit, &opi));
@@ -724,7 +724,7 @@ ANN m_bool emit_array_access(const Emitter                 emit,
   if (tflag(info->array.type, tflag_typedef))
     info->array.type = typedef_base(info->array.type);
   // look mum no pos
-  struct Op_Import opi = {.op   = insert_symbol("@array"),
+  struct Op_Import opi = {.op   = insert_symbol("[]"),
                           .lhs  = info->array.exp->type,
                           .rhs  = info->array.type,
                           .data = (uintptr_t)info};
@@ -748,7 +748,7 @@ ANN static m_bool emit_exp_array(const Emitter emit, const Exp_Array *array) {
 ANN static m_bool emit_exp_slice(const Emitter emit, const Exp_Slice *range) {
   CHECK_BB(emit_exp(emit, range->base));
   CHECK_BB(emit_range(emit, range->range));
-  const Symbol sym = insert_symbol("@slice");
+  const Symbol sym = insert_symbol("[:]");
   const Exp    e   = range->range->start ?: range->range->end;
   assert(e);
   struct Op_Import opi = {.op   = sym,
index 4afdbd231a2c2df8b678f7c63ee232bc5ee0c0ee..7a99ff821903ffc51070c55ec6b01f19d168b56f 100644 (file)
@@ -119,7 +119,7 @@ static OP_CHECK(opck_bit_access) {
 ANN static void scan_prim_op(const Env env, const Type t){
   struct Op_Func   opfunc = { .ck = opck_bit_access, .em = opem_bit_access };
   struct Op_Import opi    = {
-      .op = insert_symbol(env->gwion->st, "@array"),
+      .op = insert_symbol(env->gwion->st, "[]"),
       .lhs = env->gwion->type[et_int],
       .rhs = t,
       .func = &opfunc
index bb4ea30c313314df1bebaa13bcd6060f393be5b6..7276fa77e9ca84c9c435885545a55e006ed34e67 100644 (file)
@@ -972,11 +972,11 @@ GWION_IMPORT(array) {
   GWI_BB(gwi_oper_ini(gwi, "int", "Array", "int"))
   GWI_BB(gwi_oper_add(gwi, opck_array_slice))
   GWI_BB(gwi_oper_emi(gwi, opem_array_slice))
-  GWI_BB(gwi_oper_end(gwi, "@slice", NULL))
+  GWI_BB(gwi_oper_end(gwi, "[:]", NULL))
   GWI_BB(gwi_oper_ini(gwi, "int", "Array", NULL))
   GWI_BB(gwi_oper_add(gwi, opck_array))
   GWI_BB(gwi_oper_emi(gwi, opem_array_access))
-  GWI_BB(gwi_oper_end(gwi, "@array", NULL))
+  GWI_BB(gwi_oper_end(gwi, "[]", NULL))
   GWI_BB(gwi_oper_ini(gwi, "Array", NULL, "void"))
   GWI_BB(gwi_oper_emi(gwi, opem_array_each_init))
   GWI_BB(gwi_oper_end(gwi, "@each_init", NULL))
index c055dfe0ae98f191b621d2d1bb90a2d94f2867f2..b242a1d380257cfc46345e98f03785ec4d3ea4b5 100644 (file)
@@ -650,7 +650,7 @@ static OP_CHECK(opck_dict_scan) {
     set_tflag(t, tflag_dtor);
   }
   struct Op_Func opfunc = { .ck = opck_dict_access, .em = opem_dict_access };
-  struct Op_Import opi = { .lhs = key, .rhs = t, .ret = val, .op = insert_symbol("@array"), .func = &opfunc };
+  struct Op_Import opi = { .lhs = key, .rhs = t, .ret = val, .op = insert_symbol("[]"), .func = &opfunc };
   add_op(env->gwion, &opi);
   opi.op = insert_symbol("~~");
   opfunc.em = opem_dict_remove;
index c1cf7acd1c3011c9d4a88118d6ab28d21bdbc364..ae2be81c3e35054ad1a97cc921e666893cf528c6 100644 (file)
@@ -230,10 +230,10 @@ static GWION_IMPORT(int_unary) {
   GWI_BB(gwi_oper_end(gwi, "--", int_pre_dec))
   GWI_BB(gwi_oper_add(gwi, opck_int_cmp))
   GWI_BB(gwi_oper_end(gwi, "~", int_cmp))
-  GWI_BB(gwi_oper_ini(gwi, NULL, "int", NULL))
+  GWI_BB(gwi_oper_ini(gwi, "int", NULL, NULL))
   GWI_BB(gwi_oper_add(gwi, opck_int_range))
   GWI_BB(gwi_oper_emi(gwi, opem_int_range))
-  GWI_BB(gwi_oper_end(gwi, "@range", NULL))
+  GWI_BB(gwi_oper_end(gwi, "[:]", NULL))
   GWI_BB(gwi_oper_ini(gwi, "int", NULL, "int"))
   GWI_BB(gwi_oper_add(gwi, opck_post))
   GWI_BB(gwi_oper_end(gwi, "++", int_post_inc))
index ae32cd96aeb32b08614cf8ea610629035cc6d220..b61f5b11a190d45ec2b3a07daa4d0a2763f075fc 100644 (file)
@@ -573,7 +573,7 @@ GWION_IMPORT(string) {
   GWI_BB(gwi_oper_ini(gwi, "int", "string", NULL))
   GWI_BB(gwi_oper_add(gwi, opck_string_access))
   GWI_BB(gwi_oper_emi(gwi, opem_string_access))
-  GWI_BB(gwi_oper_end(gwi, "@array", NULL))
+  GWI_BB(gwi_oper_end(gwi, "[]", NULL))
 
   GWI_BB(gwi_oper_ini(gwi, "string", "string", "bool"))
   GWI_BB(gwi_oper_add(gwi, opck_string_eq))
@@ -582,7 +582,7 @@ GWION_IMPORT(string) {
   GWI_BB(gwi_oper_end(gwi, "!=", String_neq))
 
   GWI_BB(gwi_oper_ini(gwi, "int", "string", "string"))
-  GWI_BB(gwi_oper_end(gwi, "@slice", StringSlice))
+  GWI_BB(gwi_oper_end(gwi, "[:]", StringSlice))
 
   struct SpecialId_ file_spid = {
       .ck = check_filepp, .is_const = 1};
index 7561c9903d4486c4bca9d0e37cf75ad8974f9f0c..2117b11377af487a1972695f1d7cad338c49e421 100644 (file)
@@ -233,9 +233,9 @@ ANN static Type check_prim_range(const Env env, Range **data) {
   env_weight(env, 1);
   const Exp e = range->start ?: range->end;
   assert(e);
-  const Symbol     sym = insert_symbol("@range");
+  const Symbol     sym = insert_symbol("[:]");
   struct Op_Import opi = {.op   = sym,
-                          .rhs  = e->type,
+                          .lhs  = e->type,
                           .pos  = e->pos,
                           .data = (uintptr_t)prim_exp(data)};
   return op_check(env, &opi);
@@ -449,7 +449,7 @@ ANN static Type check_prim(const Env env, Exp_Primary *prim) {
 }
 
 ANN Type check_array_access(const Env env, const Array_Sub array) {
-  const Symbol     sym = insert_symbol("@array");
+  const Symbol     sym = insert_symbol("[]");
   struct Op_Import opi = {.op   = sym,
                           .lhs  = array->exp->type,
                           .rhs  = array->type,
@@ -468,7 +468,7 @@ static ANN Type check_exp_slice(const Env env, const Exp_Slice *range) {
   CHECK_OO(check_exp(env, range->base));
   CHECK_BO(check_range(env, range->range));
   env_weight(env, 1);
-  const Symbol sym = insert_symbol("@slice");
+  const Symbol sym = insert_symbol("[:]");
   const Exp    e   = range->range->start ?: range->range->end;
   assert(e);
   struct Op_Import opi = {.op   = sym,