diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-03-09 02:48:09 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-03-09 02:48:09 -0500 |
| commit | 18ef4c5b3ffe1fe85dd521fff98636e6c676c2ad (patch) | |
| tree | 80e9cee85080405b35df8d9676f907f32f637e5a /compile.c | |
| parent | 41d28764eebd53bec1edd2fdc3f0f004dd3e3824 (diff) | |
Table methods
Diffstat (limited to 'compile.c')
| -rw-r--r-- | compile.c | 32 |
1 files changed, 23 insertions, 9 deletions
@@ -748,15 +748,29 @@ CORD compile(env_t *env, ast_t *ast) compile_type_info(env, self_value_t), ")"); } else code_err(ast, "There is no '%s' method for arrays", call->name); } - // case TableType: { - // if (streq(call->name, "get")) { - // type_t *item_t = Match(self_value_t, ArrayType)->item_type; - // CORD self = compile_to_pointer_depth(env, call->self, 1, false); - // arg_t *arg_spec = new(arg_t, .name="item", .type=Type(PointerType, .pointed=item_t, .is_stack=true, .is_readonly=true), - // .next=new(arg_t, .name="at", .type=Type(IntType, .bits=64), .default_val=FakeAST(Int, .i=0, .bits=64))); - // return CORD_all("Table_get(", self, ", ", compile_arguments(env, ast, arg_spec, call->args), ", ", - // compile_type_info(env, self_value_t), ")"); - // } + case TableType: { + auto table = Match(self_value_t, TableType); + if (streq(call->name, "get")) { + CORD self = compile_to_pointer_depth(env, call->self, 0, false); + arg_t *arg_spec = new(arg_t, .name="key", .type=Type(PointerType, .pointed=table->key_type, .is_stack=true, .is_readonly=true)); + return CORD_all("Table_get(", self, ", ", compile_arguments(env, ast, arg_spec, call->args), ", ", + compile_type_info(env, self_value_t), ")"); + } else if (streq(call->name, "set")) { + CORD self = compile_to_pointer_depth(env, call->self, 1, false); + arg_t *arg_spec = new(arg_t, .name="key", .type=Type(PointerType, .pointed=table->key_type, .is_stack=true, .is_readonly=true), + .next=new(arg_t, .name="value", .type=Type(PointerType, .pointed=table->value_type, .is_stack=true, .is_readonly=true))); + return CORD_all("Table_set(", self, ", ", compile_arguments(env, ast, arg_spec, call->args), ", ", + compile_type_info(env, self_value_t), ")"); + } else if (streq(call->name, "remove")) { + CORD self = compile_to_pointer_depth(env, call->self, 1, false); + arg_t *arg_spec = new(arg_t, .name="key", .type=Type(PointerType, .pointed=table->key_type, .is_stack=true, .is_readonly=true)); + return CORD_all("Table_remove(", self, ", ", compile_arguments(env, ast, arg_spec, call->args), ", ", + compile_type_info(env, self_value_t), ")"); + } else if (streq(call->name, "clear")) { + CORD self = compile_to_pointer_depth(env, call->self, 1, false); + return CORD_all("Table_clear(", self, ")"); + } else code_err(ast, "There is no '%s' method for tables", call->name); + } default: goto fncall; } } |
