diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-04-07 15:35:13 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-04-07 15:35:13 -0400 |
| commit | 0d2060717a21653deb3db03ba5b3fe62aa4c098e (patch) | |
| tree | 9c0636930d5a358d8e654690cec69d7d3d7c19a4 | |
| parent | d2bee9ce7401672cae5cf02cf15dfa0ee48c2352 (diff) | |
Remove table.bump()
| -rw-r--r-- | docs/tables.md | 25 | ||||
| -rw-r--r-- | src/compile.c | 11 | ||||
| -rw-r--r-- | src/stdlib/tables.h | 7 | ||||
| -rw-r--r-- | src/typecheck.c | 3 |
4 files changed, 1 insertions, 45 deletions
diff --git a/docs/tables.md b/docs/tables.md index c0376f38..ee2603f5 100644 --- a/docs/tables.md +++ b/docs/tables.md @@ -152,37 +152,12 @@ iterating over any of the new values. ## Table Methods -- [`func bump(t:&{K=V}, key: K, amount: Int = 1 -> Void)`](#bump) - [`func clear(t:&{K=V})`](#clear) - [`func get(t:{K=V}, key: K -> V?)`](#get) - [`func has(t:{K=V}, key: K -> Bool)`](#has) - [`func remove(t:{K=V}, key: K -> Void)`](#remove) - [`func set(t:{K=V}, key: K, value: V -> Void)`](#set) -### `bump` -Increments the value associated with a key by a specified amount. If the key is -not already in the table, its value will be assumed to be zero. - -```tomo -func bump(t:&{K=V}, key: K, amount: Int = 1 -> Void) -``` - -- `t`: The reference to the table. -- `key`: The key whose value is to be incremented. -- `amount`: The amount to increment the value by (default: 1). - -**Returns:** -Nothing. - -**Example:** -```tomo ->> t := {"A"=1} -t.bump("A") -t.bump("B", 10) ->> t -= {"A"=2, "B"=10} -``` - --- ### `clear` diff --git a/src/compile.c b/src/compile.c index 3ebe08a9..59c25f6a 100644 --- a/src/compile.c +++ b/src/compile.c @@ -3323,17 +3323,6 @@ CORD compile(env_t *env, ast_t *ast) .next=new(arg_t, .name="value", .type=table->value_type)); return CORD_all("Table$set_value(", self, ", ", compile_arguments(env, ast, arg_spec, call->args), ", ", compile_type_info(self_value_t), ")"); - } else if (streq(call->name, "bump")) { - EXPECT_POINTER("a", "table"); - if (!(table->value_type->tag == IntType || table->value_type->tag == NumType)) - code_err(ast, "bump() is only supported for tables with numeric value types, not ", type_to_str(self_value_t)); - ast_t *one = table->value_type->tag == IntType - ? FakeAST(Int, .str="1") - : FakeAST(Num, .n=1); - arg_t *arg_spec = new(arg_t, .name="key", .type=table->key_type, - .next=new(arg_t, .name="amount", .type=table->value_type, .default_val=one)); - return CORD_all("Table$bump(", self, ", ", compile_arguments(env, ast, arg_spec, call->args), ", ", - compile_type_info(self_value_t), ")"); } else if (streq(call->name, "remove")) { EXPECT_POINTER("a", "table"); arg_t *arg_spec = new(arg_t, .name="key", .type=table->key_type); diff --git a/src/stdlib/tables.h b/src/stdlib/tables.h index 1557e429..ad6127c7 100644 --- a/src/stdlib/tables.h +++ b/src/stdlib/tables.h @@ -53,13 +53,6 @@ void *Table$reserve(Table_t *t, const void *key, const void *value, const TypeIn void Table$set(Table_t *t, const void *key, const void *value, const TypeInfo_t *type); #define Table$set_value(t, key_expr, value_expr, type) ({ __typeof(key_expr) k = key_expr; __typeof(value_expr) v = value_expr; \ Table$set(t, &k, &v, type); }) -#define Table$reserve_value(t, key_expr, type) ({ __typeof(key_expr) k = key_expr; Table$reserve(t, &k, NULL, type); }) -#define Table$bump(t_expr, key_expr, amount_expr, type) ({ __typeof(key_expr) key = key_expr; \ - Table_t *t = t_expr; \ - __typeof(amount_expr) *val = Table$get_raw(*t, &key, type); \ - if (val) *val += amount_expr; \ - else { __typeof(amount_expr) init = amount_expr; Table$set(t, &key, &init, type); } (void)0; }) - void Table$remove(Table_t *t, const void *key, const TypeInfo_t *type); #define Table$remove_value(t, key_expr, type) ({ __typeof(key_expr) k = key_expr; Table$remove(t, &k, type); }) diff --git a/src/typecheck.c b/src/typecheck.c index f5acad31..e42f6ca8 100644 --- a/src/typecheck.c +++ b/src/typecheck.c @@ -936,8 +936,7 @@ type_t *get_type(env_t *env, ast_t *ast) } case TableType: { auto table = Match(self_value_t, TableType); - if (streq(call->name, "bump")) return Type(VoidType); - else if (streq(call->name, "clear")) return Type(VoidType); + if (streq(call->name, "clear")) return Type(VoidType); else if (streq(call->name, "get")) return Type(OptionalType, .type=table->value_type); else if (streq(call->name, "has")) return Type(BoolType); else if (streq(call->name, "remove")) return Type(VoidType); |
