26.10.2013 Views

2 - Forth Interest Group

2 - Forth Interest Group

2 - Forth Interest Group

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

( 0 ENDCASE ) THEN THEN THEN<br />

; IMMEDIATE<br />

The arithmetic operators should all receive optimization.<br />

(Optimize: x n + x + n + 0 + n + )<br />

: +<br />

( CASE )<br />

STATE @ 0=<br />

IF<br />

do-PLUS EXECUTE<br />

ELSE<br />

last @ do-LITERAL =<br />

IF<br />

( CASE )<br />

penult @ do-LITERAL =<br />

ORIF penult k do-LITERAL-PLUS = THEN<br />

IF \ x n t or x + n t<br />

0 last !<br />

next 1 codes - @ next 3 codes - @ +<br />

-4 codes gap<br />

DUE' 9RIF penult @ do-LITERAL = THEN<br />

IF<br />

penult COMPILE,<br />

ELSE<br />

r<br />

ELSE DROP THEN<br />

next 1 codes - @o=<br />

IF \ a +<br />

penult @ last !<br />

0 penult !<br />

-2 codes gap<br />

ELSE \ n t<br />

penult @ last !<br />

next 1 codes - @<br />

-2 codeg gap<br />

do-LITERAL-PLUS COMPILE,<br />

I<br />

( 0 ENDCASE ) THEN THEN<br />

ELSE \ +<br />

do-PLUS COMPILE,<br />

( 0 ENDCASE ) THEN THEN<br />

; IMMEDIATE<br />

Pinhole optimization, like any form of peephole optimization, should work across uses of POSTPONE.<br />

Given the definition,<br />

: UNLESS 0 POSTPONE LITERAL POSTPONE = POSTPONE IF ; IMMEDIATE<br />

when UNLESS is used, POSTPONE = should combine with the result of the preceding 0 POSTPONE LITERAL<br />

to yield 0=, and then POSTPONE IF should yield the BRANCH-UNLESS-ZERO optimization.<br />

<strong>Forth</strong> Dimensions 35 July 1995 August

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!