diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-08-16 02:29:07 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-08-16 02:29:07 -0400 |
| commit | 2d3c114435e6b6ade1151edf22592ca7d298e17a (patch) | |
| tree | 927bd84a2a813caebd958c30de1bf77a419c73b6 | |
| parent | a6be5c90ca99a4bfceb59c3a720c606b2f05fc8f (diff) | |
Check for compile-time constant integers that require heap allocations.
| -rw-r--r-- | typecheck.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/typecheck.c b/typecheck.c index ec42a83d..be21948c 100644 --- a/typecheck.c +++ b/typecheck.c @@ -1341,7 +1341,17 @@ type_t *parse_type_string(env_t *env, const char *str) bool is_constant(env_t *env, ast_t *ast) { switch (ast->tag) { - case Bool: case Int: case Num: case Nil: case TextLiteral: return true; + case Bool: case Num: case Nil: case TextLiteral: return true; + case Int: { + auto info = Match(ast, Int); + if (info->bits == 0) { + Int_t int_val = Int$from_text(info->str); + mpz_t i; + mpz_init_set_int(i, int_val); + return (mpz_cmpabs_ui(i, BIGGEST_SMALL_INT) <= 0); + } + return true; + } case TextJoin: { auto text = Match(ast, TextJoin); return !text->children || !text->children->next; |
