diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-11-09 16:27:54 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-11-09 16:27:54 -0500 |
| commit | 898bee15817573b5ab865a1dae7e52da310affa8 (patch) | |
| tree | b8531a828190997a63a1e1ef32f4aa568304e61c /compile.c | |
| parent | 7a4f2e73addf6dfcde2a6b17b62b961608e556a0 (diff) | |
Introduce a `Match` struct to represent pattern matching results, which
improves the usability of a lot of the APIs. Also bugfix some issues
with ranges.
Diffstat (limited to 'compile.c')
| -rw-r--r-- | compile.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -217,6 +217,7 @@ CORD compile_type(type_t *t) if (t == THREAD_TYPE) return "Thread_t"; else if (t == RANGE_TYPE) return "Range_t"; else if (t == RNG_TYPE) return "RNG_t"; + else if (t == MATCH_TYPE) return "Match_t"; switch (t->tag) { case ReturnType: errx(1, "Shouldn't be compiling ReturnType to a type"); @@ -3396,12 +3397,13 @@ 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 == RANGE_TYPE || 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", fielded, f->field); + return CORD_asprintf("(%r)->%s%s", fielded, prefix, f->field); } else { CORD fielded = compile(env, f->fielded); - return CORD_asprintf("(%r).$%s", fielded, f->field); + return CORD_asprintf("(%r).%s%s", fielded, prefix, f->field); } } } @@ -3602,6 +3604,7 @@ CORD compile_type_info(env_t *env, type_t *t) { if (t == THREAD_TYPE) return "&Thread$info"; else if (t == RANGE_TYPE) return "&Range$info"; + else if (t == MATCH_TYPE) return "&Match$info"; else if (t == RNG_TYPE) return "&RNG$info"; switch (t->tag) { |
