diff options
Diffstat (limited to 'src/analyzer.c')
-rw-r--r-- | src/analyzer.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/analyzer.c b/src/analyzer.c index 6e6df9d..c74e89f 100644 --- a/src/analyzer.c +++ b/src/analyzer.c @@ -309,6 +309,16 @@ analyzeexpr(struct azctx ctx, scope_t *scps, type_t *types, ast_t ast, err("analyzer: Unknown symbol ā%.*sā", SV_PRI_ARGS(sv)); } + case ASTUNNEG: { + idx_t ni, rhs; + rhs = ast.kids[i].rhs; + ni = analyzeexpr(ctx, scps, types, ast, aux, toks, rhs); + type_t t = types[rhs]; + if (t.kind != TYPE_NUM || !t.issigned) + err("analyzer: Unary negation is reserved for signed numeric types"); + types[i] = t; + return ni; + } case ASTFN: return analyzefn(ctx, scps, types, ast, aux, toks, i); default: @@ -476,6 +486,16 @@ constfoldexpr(struct cfctx ctx, mpq_t *folds, scope_t *scps, type_t *types, } } } + case ASTUNNEG: { + idx_t rhs = ast.kids[i].rhs; + idx_t ni = constfoldexpr(ctx, folds, scps, types, ast, toks, rhs); + mpq_t *x = folds + rhs; + if (MPQ_IS_INIT(*x)) { + MPQCPY(folds[i], *x); + mpq_neg(folds[i], folds[i]); + } + return ni; + } case ASTFN: return constfoldblk(ctx, folds, scps, types, ast, toks, ast.kids[i].rhs); |