Skip to content

Commit e80ec57

Browse files
author
theBF
committed
Fixing DEMO for compiler changes
1 parent 82a8ae3 commit e80ec57

23 files changed

+1870
-68
lines changed

COMPILER/src/MFORTH-oct-2023.FTH

Lines changed: 591 additions & 0 deletions
Large diffs are not rendered by default.

COMPILER/src/old/MFORTH-OCT-2023.FTH

Lines changed: 600 additions & 0 deletions
Large diffs are not rendered by default.

DEMOS.SRC/BYTEMAGSIEVE.FTH

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
\ BYTE MAGAZINE SIEVE
2+
\ 10 ITERATION TIMINGS
3+
\ Normal 1FILL OPT
4+
\ Camel99 DTC 104 67.3
5+
\ TurboForth 107
6+
\ Camel99 ITC 120 117 75.6
7+
\ FbForth 2.0:13 174
8+
NEEDS ELAPSE FROM DSK1.ELAPSE
9+
10+
DECIMAL
11+
8190 CONSTANT SIZE
12+
0 VARIABLE FLAGS SIZE ALLOT 0 FLAGS !
13+
14+
: DO-PRIME
15+
FLAGS SIZE 1 FILL ( set array )
16+
0 ( counter )
17+
SIZE 0
18+
DO FLAGS I + C@
19+
IF I DUP + 3 + DUP I +
20+
BEGIN
21+
DUP SIZE <
22+
WHILE
23+
0 OVER FLAGS + C!
24+
OVER +
25+
REPEAT
26+
DROP DROP
27+
1+
28+
THEN
29+
LOOP
30+
;
31+
32+
: PRIMES ( -- )
33+
PAGE ." 10 Iterations"
34+
10 0 DO DO-PRIME CR SPACE . ." Primes" LOOP
35+
CR ." Done!"
36+
;
37+
38+
39+
INCLUDE DSK1.FILLW
40+
\ WITH fast fill
41+
HEX 0101 CONSTANT $0101
42+
DECIMAL
43+
: DO-PRIME3
44+
FLAGS SIZE $0101 FILLW ( set array )
45+
0 ( counter )
46+
SIZE 0
47+
DO FLAGS I + C@
48+
IF I DUP + 3 + DUP I +
49+
BEGIN
50+
DUP SIZE <
51+
WHILE
52+
0 OVER FLAGS + C!
53+
OVER +
54+
REPEAT
55+
DROP DROP
56+
1+
57+
THEN
58+
LOOP
59+
;
60+
61+
: PRIMES3 ( -- )
62+
PAGE ." 10 Iterations"
63+
10 0 DO DO-PRIME3 CR SPACE . ." Primes" LOOP
64+
CR ." Done!"
65+
;
66+
67+
NEEDS INLINE[ FROM DSK1.INLINE
68+
69+
\ optimized Version
70+
DECIMAL
71+
: DO-PRIME2
72+
INLINE[ FLAGS SIZE 01 FILL 0 SIZE 0 ]
73+
DO
74+
INLINE[ FLAGS I + C@ ]
75+
IF INLINE[ I 2* 3 + DUP I + ]
76+
BEGIN INLINE[ DUP SIZE < ]
77+
WHILE INLINE[ 0 OVER FLAGS + C! OVER + ]
78+
REPEAT
79+
INLINE[ 2DROP 1+ ]
80+
THEN
81+
LOOP
82+
CR SPACE . ." Primes" ;
83+
84+
\ Camel99
85+
: PRIMES-OPT ( -- )
86+
PAGE ." 10 Iterations"
87+
10 0 DO DO-PRIME2 LOOP
88+
CR
89+
CR ." Done!"
90+
;

DEMOS.SRC/DEMO-DOLOOP.FTH

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
\ MACHFORTH DEMO DO/LOOP libary
2+
3+
COMPILER \ names space that has compiler directives
4+
5+
NEW. \ init heap memory, clear TARGET vocabulary
6+
HEX 2000 ORIGIN.
7+
8+
INCLUDE DSK2.DOLOOP
9+
10+
TARGET
11+
VARIABLE X
12+
VARIABLE Y
13+
14+
PROG: TESTDOLOOP
15+
\ [
16+
\ HEX
17+
\ 8300 WORKSPACE
18+
\ 8400 DSTACK
19+
\ 83E0 RSTACK
20+
\ ]
21+
22+
100 0
23+
DO
24+
100 0
25+
DO
26+
I X !
27+
J Y !
28+
LOOP
29+
LOOP
30+
NEXT, \ goto ti99 ROM monitor
31+
END.
32+
33+
\ SAVE DSK2.TESTDOLOOP

DEMOS.SRC/DEMO1.FTH

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ PROG: DEMO1
1717
DROP \ remove number from data stack.
1818
( *machine Forth does not clean the stack like standard Forth)
1919

20-
NEXT, \ HOST Forth's NEXT routine gets us back to Forth
20+
>HOST \ back to Forth
2121
END.
2222

2323
\ Usage from Forth command line.

DEMOS.SRC/DEMO11.FTH

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,23 @@ COMPILER \ preamble to set up target image
66

77
INCLUDE DSK2.STDLIB
88

9-
COMPILER
9+
TARGET
1010
CREATE TITLE$ S" Signed Un-signed" S,
1111

12-
DECIMAL \ compiler interprets numbers as BASE 10
12+
DECIMAL \ compiler interprets numbers as BASE 10
1313

14-
TARGET
1514
PROG: DEMO11
16-
PAGE
15+
TEXT
1716
16 BASE ! \ **set the base for TARGET code number conversion to HEX
1817

1918
8 9 AT-XY TITLE$ COUNT TYPE
20-
32000 \ first number in count (the compiler is still in DECIMAL )
21-
OPT-OFF \ for loops don't like optimizer (bug)
22-
2000
23-
FOR
24-
9 10 AT-XY DUP . DUP U.
25-
1+
26-
NEXT
19+
8 10 AT-XY 1234 . 1234 U.
20+
\ 32000 \ first number in count (the compiler is still in DECIMAL )
21+
\ 2000
22+
\ FOR
23+
\ 9 10 AT-XY DUP . DUP U.
24+
\ 1+
25+
\ NEXT
2726

2827
NEXT,
2928
END.

DEMOS.SRC/DEMO13.FTH

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ PROG: DEMO13
3434
NEXT, \ return to Camel99 Forth
3535
END.
3636

37-
\ patch TARGET variable MDP, that holds end of memory
38-
COMPILER THERE 4 + TARGET T' MEM T!
37+
\ patch TARGET variable DP, that holds end of memory
38+
CONCUR

DEMOS.SRC/DEMO14.FTH

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
\ Machine Forth DEMO with OPTIMIZE
2+
COMPILER
3+
NEW.
4+
HEX 2000 ORIGIN.
5+
6+
TARGET
7+
VARIABLE X
8+
VARIABLE Y
9+
10+
\ using Camel99 workspace for simplicity
11+
PROG: DEMO14
12+
FFFF \ 0 -> top of stack
13+
BEGIN
14+
?TERMINAL \ loops until FNCT 4 is pressed
15+
NOT WHILE
16+
DUP X ! \ store copy in X
17+
DUP Y !
18+
19+
1- \ dec TOS
20+
REPEAT
21+
DROP \ clean the stack
22+
NEXT,
23+
END.

DEMOS.SRC/DEMO1C.FTH

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ COMPILER \ names space that has compiler directives
2828
PROG: DEMO1C
2929
DEMOWHILE
3030

31-
NEXT, \ Return to Forth console
31+
>HOST \ Return to Forth console
3232
END.
3333

3434
\ Usage from Forth command line:

DEMOS.SRC/DEMO5ANS.FTH

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
\ ANS Forth verion of DEMO5 for speed comparison
2-
2+
HERE
3+
HEX
34
VARIABLE X
45
VARIABLE Y
56
VARIABLE Z
67

7-
\ create 1 as a constant. It puts itself on the stack
8-
01 CONSTANT 1
98
FFFF CONSTANT LOOPS
109

1110
: DEMO5
@@ -19,3 +18,4 @@ FFFF CONSTANT LOOPS
1918
REPEAT
2019
DROP
2120
;
21+
HERE SWAP - DECIMAL .

DEMOS.SRC/DEMO5MF.FTH

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
\ MachFORTH DEMO #5: Using variables and constants
2+
3+
\ Compiler Time Bytes
4+
\ ------------ --------- -----
5+
\ Camel99 Forth 47.70 100 (including headers)
6+
\ MachForth 15.56 94
7+
8+
\ Compiler Preamble
9+
COMPILER
10+
NEW.
11+
HEX 2000 ORIGIN.
12+
13+
TARGET
14+
15+
VARIABLE X
16+
VARIABLE Y
17+
VARIABLE Z
18+
19+
FFFF CONSTANT LOOPS
20+
21+
PROG: DEMO5
22+
LOOPS
23+
BEGIN
24+
1-
25+
<> WHILE \ no need to DUP TOS in machine Forth.
26+
\ MUST use comparator
27+
-3 X +!
28+
Y 1+!
29+
X @ Y @ + Z !
30+
REPEAT
31+
DROP
32+
33+
NEXT, \ return to Camel99 Forth
34+
END.
35+
36+
\ ELAPSE DEMO5 RUN

DEMOS.SRC/DEMO8.FTH

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
\ Machine Forth DEMO 6A: Use ?TERMINAL to escape while loop
2+
COMPILER
3+
NEW.
4+
HEX 2000 ORIGIN.
5+
6+
TARGET
7+
VARIABLE X
8+
9+
\ using Camel99 workspace for simplicity
10+
PROG: DEMO8
11+
FFFF \ 0 -> top of stack
12+
BEGIN
13+
?TERMINAL \ loops until FNCT 4 is pressed
14+
NOT WHILE
15+
DUP X ! \ store copy in X
16+
1- \ dec TOS
17+
REPEAT
18+
DROP \ clean the stack
19+
NEXT,
20+
END.

DEMOS.SRC/DEMO9.FTH

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ VARIABLE Z
2323
: WORD7 WORD6 -;
2424
: WORD8 WORD7 -;
2525
: WORD9 WORD8 -;
26-
: WORD10 WORD9 -;
26+
: TAILCALL WORD9 -;
2727

2828
\ using Camel99 workspace for easy testing
29-
[CC] HEX
30-
TARGET
29+
HEX
3130
PROG: DEMO9
32-
400 FOR
33-
I@ WORD10 \ return stack holds the loop index
31+
FFFF FOR
32+
i TAILCALL \ return stack holds the loop index
3433
NEXT
3534

3635
NEXT, \ go back to Forth interpreter

DEMOS.SRC/HELLO3.FTH

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ CREATE MSG2 S" Put text anywhere." S,
2626

2727
\ MACRO: write CHAR, auto-incr. VDP address, drop char
2828
: EMIT+ ( char -- ) VDPWD C! ;
29-
3029
: TYPE ( addr len -- ) 1- FOR COUNT EMIT+ NEXT DROP ;
3130

3231
CODE BYE 0000 @@ BLWP, ENDCODE

DEMOS.SRC/OPT-TESTER.FTH

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
\ TEST drop/dup removal from a compiled program
2+
3+
COMPILER
4+
NEW.
5+
HEX 2000 ORIGIN.
6+
7+
TARGET
8+
PROG: DROPDUPER
9+
DEAD
10+
BEEF
11+
DROP DUP DROP DUP DROP DUP
12+
DROP DUP DROP DUP DROP DUP
13+
END.
14+
15+

DEMOS.SRC/SIEVE-MF-TEST.FTH

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
\ BYTE MAGAZINE SIEVE in MACHFORTH
2+
3+
COMPILER
4+
NEW.
5+
6+
HEX A000 ORIGIN.
7+
8+
INCLUDE DSK2.BYE
9+
10+
TARGET
11+
DECIMAL
12+
8192 CONSTANT SIZE
13+
14+
HEX 2000 CONSTANT FLAGS \ using Low RAM for array
15+
0101 CONSTANT FILLER
16+
17+
: FILLFLAGS
18+
FLAGS
19+
SIZE
20+
FOR
21+
1 OVER C!
22+
1+
23+
NEXT
24+
DROP
25+
;
26+
27+
CODE I DUP W TOS MOV, ENDCODE
28+
CODE I++ W INC, ENDCODE
29+
30+
: DO-PRIME
31+
FILLFLAGS
32+
FLAGS OFF \ reset 1st two bytes
33+
0 A! \ use "A" register as loop index
34+
0 ( counter )
35+
SIZE FOR
36+
FLAGS I + C@
37+
<> IF
38+
I 2* 3 + DUP I +
39+
BEGIN
40+
DUP SIZE CMP <
41+
WHILE
42+
0 OVER FLAGS + C!
43+
OVER +
44+
REPEAT
45+
DROP DROP
46+
1+
47+
THEN
48+
I++
49+
NEXT
50+
;
51+
52+
53+
54+
PROG: SIEVE
55+
[
56+
8300 WORKSPACE
57+
FFF0 DSTACK
58+
FD00 RSTACK
59+
]
60+
61+
DO-PRIME
62+
BEGIN ?TERMINAL UNTIL
63+
64+
BYE
65+
END.
66+
67+
SAVE DSK2.SIEVETEST
68+

0 commit comments

Comments
 (0)