diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-03-11 13:18:30 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-03-11 13:18:30 -0400 |
| commit | 294b712e6dabc722772f86aaa9d0faaa08c14717 (patch) | |
| tree | f24ab45434d5bf2d5ebd64b0d533d4d361e9daff | |
| parent | d254b440f8359b42a097edfeb2db1585fd20c695 (diff) | |
Don't use '$' prefix for field names
| -rw-r--r-- | compile.c | 7 | ||||
| -rw-r--r-- | docs/namespacing.md | 2 | ||||
| -rw-r--r-- | examples/game/color.tm | 10 | ||||
| -rw-r--r-- | examples/threads/threads.tm | 16 | ||||
| -rw-r--r-- | structs.c | 3 |
5 files changed, 18 insertions, 20 deletions
@@ -826,7 +826,7 @@ static CORD _compile_statement(env_t *env, ast_t *ast) const char *var_name = Match(arg->value, Var)->name; if (!streq(var_name, "_")) { - code = CORD_all(code, compile_declaration(field->type, compile(env, arg->value)), " = subject.$", clause_tag_name, ".$", field->name, ";\n"); + code = CORD_all(code, compile_declaration(field->type, compile(env, arg->value)), " = subject.$", clause_tag_name, ".", field->name, ";\n"); set_binding(scope, Match(arg->value, Var)->name, field->type, CORD_EMPTY); } field = field->next; @@ -3680,13 +3680,12 @@ CORD compile(env_t *env, ast_t *ast) case StructType: { for (arg_t *field = Match(value_t, StructType)->fields; field; field = field->next) { if (streq(field->name, f->field)) { - const char *prefix = (value_t == MATCH_TYPE) ? "" : "$"; if (fielded_t->tag == PointerType) { CORD fielded = compile_to_pointer_depth(env, f->fielded, 1, false); - return CORD_asprintf("(%r)->%s%s", fielded, prefix, f->field); + return CORD_asprintf("(%r)->%s", fielded, f->field); } else { CORD fielded = compile(env, f->fielded); - return CORD_asprintf("(%r).%s%s", fielded, prefix, f->field); + return CORD_asprintf("(%r).%s", fielded, f->field); } } } diff --git a/docs/namespacing.md b/docs/namespacing.md index 58638411..e8b13305 100644 --- a/docs/namespacing.md +++ b/docs/namespacing.md @@ -54,7 +54,7 @@ static Text_t foo$Baz$as_text(foo$Baz_t *obj, bool use_color) public Int_t foo$Baz$frob(struct foo$Baz_s $b) { - return ($b).$x; + return ($b).x; } ... ``` diff --git a/examples/game/color.tm b/examples/game/color.tm index f8702570..fef12e60 100644 --- a/examples/game/color.tm +++ b/examples/game/color.tm @@ -12,12 +12,12 @@ struct Color(r,g,b:Num,a=1.0): func draw_rectangle(c:Color, pos:Vec2, size:Vec2): inline C { DrawRectangle( - (int)(_$pos.$x), (int)(_$pos.$y), (int)(_$size.$x), (int)(_$size.$y), + (int)(_$pos.x), (int)(_$pos.y), (int)(_$size.x), (int)(_$size.y), ((Color){ - (int8_t)(uint8_t)(255.*_$c.$r), - (int8_t)(uint8_t)(255.*_$c.$g), - (int8_t)(uint8_t)(255.*_$c.$b), - (int8_t)(uint8_t)(255.*_$c.$a), + (int8_t)(uint8_t)(255.*_$c.r), + (int8_t)(uint8_t)(255.*_$c.g), + (int8_t)(uint8_t)(255.*_$c.b), + (int8_t)(uint8_t)(255.*_$c.a), }) ); } diff --git a/examples/threads/threads.tm b/examples/threads/threads.tm index 99bb83b4..5949a5cc 100644 --- a/examples/threads/threads.tm +++ b/examples/threads/threads.tm @@ -13,11 +13,11 @@ struct Mutex(_mutex:@Memory): func do_locked(m:Mutex, fn:func(); inline): inline C { - pthread_mutex_lock((pthread_mutex_t*)_$m.$_mutex); + pthread_mutex_lock((pthread_mutex_t*)_$m._mutex); } fn() inline C { - pthread_mutex_unlock((pthread_mutex_t*)_$m.$_mutex); + pthread_mutex_unlock((pthread_mutex_t*)_$m._mutex); } struct ThreadCondition(_cond:@Memory): @@ -33,17 +33,17 @@ struct ThreadCondition(_cond:@Memory): func wait(c:ThreadCondition, m:Mutex; inline): inline C { - pthread_cond_wait((pthread_cond_t*)_$c.$_cond, (pthread_mutex_t*)_$m.$_mutex); + pthread_cond_wait((pthread_cond_t*)_$c._cond, (pthread_mutex_t*)_$m._mutex); } func signal(c:ThreadCondition; inline): inline C { - pthread_cond_signal((pthread_cond_t*)_$c.$_cond); + pthread_cond_signal((pthread_cond_t*)_$c._cond); } func broadcast(c:ThreadCondition; inline): inline C { - pthread_cond_broadcast((pthread_cond_t*)_$c.$_cond); + pthread_cond_broadcast((pthread_cond_t*)_$c._cond); } struct Guard(mutex=Mutex.new(), cond=ThreadCondition.new()): @@ -66,17 +66,17 @@ struct PThread(_thread:@Memory): func join(t:PThread): inline C { - pthread_join(*(pthread_t*)_$t.$_thread, NULL); + pthread_join(*(pthread_t*)_$t._thread, NULL); } func cancel(t:PThread): inline C { - pthread_cancel(*(pthread_t*)_$t.$_thread); + pthread_cancel(*(pthread_t*)_$t._thread); } func detatch(t:PThread): inline C { - pthread_detach(*(pthread_t*)_$t.$_thread); + pthread_detach(*(pthread_t*)_$t._thread); } func main(): @@ -52,8 +52,7 @@ CORD compile_struct_header(env_t *env, ast_t *ast) CORD fields = CORD_EMPTY; for (arg_ast_t *field = def->fields; field; field = field->next) { type_t *field_t = get_arg_ast_type(env, field); - CORD type_code = compile_type(field_t); - fields = CORD_all(fields, type_code, " $", field->name, field_t->tag == BoolType ? ":1" : CORD_EMPTY, ";\n"); + fields = CORD_all(fields, compile_declaration(field_t, field->name), field_t->tag == BoolType ? ":1" : CORD_EMPTY, ";\n"); } CORD struct_code = CORD_all("struct ", full_name, "$$struct {\n"); struct_code = CORD_all(struct_code, "};\n"); |
