diff options
| author | 2023-05-31 08:57:22 +0200 | |
|---|---|---|
| committer | 2023-05-31 09:16:18 +0200 | |
| commit | 5e46b36476c57418c0bd3cfced2d4c63eb7d1048 (patch) | |
| tree | 3d19fdcfa04362f12848e0c9a5a105d9c984fd0e | |
| parent | 05c305bee19221e3b5b9557267c5cfa7525f752f (diff) | |
'!' optimizations
| -rw-r--r-- | lex.c | 11 | ||||
| -rw-r--r-- | parse.c | 22 | ||||
| -rw-r--r-- | test.c | 12 |
3 files changed, 39 insertions, 6 deletions
@@ -376,10 +376,13 @@ Begin: case ' ': case '\r': case '\t': goto Begin; break; - case '!': case '(': case ')': case ',': - case ':': case ';': case '?': case '[': - case ']': case '{': case '}': case '~': - case '$': case '@': case '`': case '\\': case TKEOF: case '\n': + case '(': case ')': case ',': case ':': + case ';': case '?': case '[': case ']': + case '{': case '}': case '~': case '$': + case '@': case '`': case '\\': case TKEOF: case '\n': + RET(c); + case '!': + if (match(pr, '=')) RET(TKNEQ); RET(c); case '#': if (match(pr, '#')) RET(TKPPCAT); @@ -1149,6 +1149,19 @@ Loop: condjump(fn, &ex->sub[1], tr, fl); useblk(fn, next2); condjump(fn, &ex->sub[2], tr, fl); + } else if (ex->t == ELOGNOT) { + Negate: + /* swap tr,fl */ + next = tr; + tr = fl; + fl = next; + ex = &ex->sub[0]; + goto Loop; + } else if (ex->t == EEQU && isnullpo(&ex->sub[1])) { /* == 0 */ + goto Negate; + } else if (ex->t == ENEQ && isnullpo(&ex->sub[1])) { /* != 0 */ + ex = &ex->sub[0]; + goto Loop; } else { putjump(fn, Jbcnd, exprvalue(fn, ex), tr, fl); } @@ -1204,7 +1217,10 @@ condexprrec(struct function *fn, const struct expr *ex, bool tobool, static union ref condexprvalue(struct function *fn, const struct expr *ex) { - struct condphis phis = {0}; + struct block *blkbuf[8]; + union ref refbuf[8]; + struct condphis phis = { VINIT(blkbuf, arraylength(blkbuf)), + VINIT(refbuf, arraylength(refbuf))}; struct block *dst = newblk(fn); union ref r; condexprrec(fn, ex, 0, &phis, dst, NULL); @@ -1258,7 +1274,9 @@ exprvalue(struct function *fn, const struct expr *ex) ins.cls = cls; return addinstr(fn, ins); case ELOGNOT: - ins.op = Oequ; + for (; sub->t == ELOGNOT; ex = sub, sub = sub->sub) + swp ^= 1; + ins.op = Oequ + swp; ins.l = exprvalue(fn, sub); ins.l = cvt(fn, ex->ty.t, sub->ty.t, ins.l); ins.r = mkintcon(fn, cls, 0); @@ -7,6 +7,8 @@ wawa #else boop #endif + +#define NULL ((void *)0) int glob [ wow+wow]; struct foo { @@ -32,4 +34,14 @@ int test4(int c) { : 0; } +int test5(int *p) +{ + return p ? *p : 0; +} + +int test6(int x) +{ + return !!!!x; +} + // |