Order SwiftForth™ for Windows, Mac OS X and Linux programming. Examples, source, documentation, more.
Mac and the Mac logo are trademarks of Apple Inc., registered in the U.S. and other countries.
SwiftForth includes a powerful rule-based optimizing compiler.
As noted previously, SwiftForth uses inlined code and tail recursion to increase efficiency. More extensive optimization is provided by a powerful rule-based optimizer that can optimize hundreds of common high-level phrases. This optimizer is normally enabled, but can be disabled for debugging or comparison purposes.
For example, consider the definition of DIGIT, which converts a small binary number to a printable character:
: DIGIT ( u -- char) DUP 9 > IF 7 + THEN [CHAR] 0 + ;
With the optimizer disabled, the following code is generated (displayed here using the SwiftForth disassembler):
SEE DIGIT 47170F 4 # EBP SUB 83ED04 471712 EBX 0 [EBP] MOV 895D00 471715 4 # EBP SUB 83ED04 471718 EBX 0 [EBP] MOV 895D00 47171B 9 # EBX MOV BB09000000 471720 403A8F ( > ) CALL E86A23F9FF 471725 EBX EBX OR 09DB 471727 0 [EBP] EBX MOV 8B5D00 47172A 4 [EBP] EBP LEA 8D6D04 47172D 471744 JZ 0F8411000000 471733 4 # EBP SUB 83ED04 471736 EBX 0 [EBP] MOV 895D00 471739 7 # EBX MOV BB07000000 47173E 0 [EBP] EBX ADD 035D00 471741 4 # EBP ADD 83C504 471744 4 # EBP SUB 83ED04 471747 EBX 0 [EBP] MOV 895D00 47174A 30 # EBX MOV BB30000000 47174F 0 [EBP] EBX ADD 035D00 471752 4 # EBP ADD 83C504 471755 RET C3
With the optimizer enabled, the benefits are obvious:
SEE DIGIT 47170F 9 # EBX CMP 83FB09 471712 47171B JLE 0F8E03000000 471718 7 # EBX ADD 83C307 47171B 30 # EBX ADD 83C330 47171E RET C3