Skip to content

Commit 3961973

Browse files
authored
Merge pull request #26 from timmoorhouse/dev
Dev
2 parents c7d2ddb + eabe371 commit 3961973

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+921
-1079
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11

2-
v0.2 alpha TBD
2+
v0.2 alpha 2023-03-20
33
- Add `COMPILE-ONLY`.
44
- Catch exceptions in `AUTOBOOT`.
55
- Embed the bootstrap Forth code in forth-skeletal and parse out of memory instead of reading from a file. This will allow `INCLUDE` and others to be implemented in Forth.
66
- Turn `AUTOBOOT` into a deferred, so what happens automatically at startup can be customized (by default this is a no-op - should it be something like `:NONAME INCLUDE AUTOBOOT.F ;` ?)
7+
- Add support for double literals (such as 123.) to the interpreter.
78
- Improve error reporting. The source line number, line contents and parse position are displayed along with (if available) a message for the exception number.
8-
- CORE: add `ENVIRONMENT?`.
9+
- Added value `UNIT` used by `OPEN-FILE` as the unit number. Defaults to 8.
10+
- CORE: add `ENVIRONMENT?` and `MARKER`. CORE is now feature complete (with the exception of the obsolescent `[COMPILE]`).
11+
- DOUBLE: add `2CONSTANT`, `2LITERAL`, `D>S`.
912
- SEARCH: add `ALSO`, `DEFINITIONS`, `FORTH`, `GET-CURRENT`, `GET-ORDER`, `ONLY`, `ORDER`, `PREVIOUS`, `SET-CURRENT` and `SET-ORDER`. SEARCH is now feature complete.
1013
- STRING: add `UNESCAPE`.
14+
- TOOLS: add `SEE` (incomplete).
1115

1216
v0.1 pre-alpha 2023-03-04
1317
- Initial version

README.md

Lines changed: 10 additions & 34 deletions
Large diffs are not rendered by default.

src/assembler.f

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
3+

src/basepage.asm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ DO_JUMP_W
1616
; W address of the code field pointer in zero-page.
1717
W !word 0
1818

19+
!byte 0 ; alignment
20+
1921
; floating point stack?
2022

2123
; TODO use a word for this? (turn it into S)
@@ -25,8 +27,6 @@ XSAVE !byte 0 ; temporary to save S when we need to reuse X
2527
; TODO separate XSAVE for kernel calls
2628
KERNEL_XSAVE !byte 0 ; just for use in kernel calls
2729

28-
NEXT_SBUF !byte 0 ; TODO move out of base page?
29-
3030
; TODO move these out of basepage? make them values ...
3131
INPUT_BUFFER !word 0 ; Address and length of input buffer
3232
INPUT_LEN !word 0

src/benchmark.f

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
marker pre-bm
3+
24
\ see also https://theultimatebenchmark.org/
35

46
\

src/bootstrap.asm

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
; TODO can we move put_string here?
1212

13+
+NONAME
1314
W_SIMPLE_DOT
1415
!word *+2
1516
lda #'$'
@@ -61,6 +62,39 @@ SIMPLE_DOTS
6162
+
6263
rts
6364

65+
+NONAME
66+
W_SIMPLE_FIND_NAME ; ( c-addr u -- 0 | nt )
67+
!word DO_COLON
68+
69+
!word W_2DUP
70+
!word W_INTERNALS_WORDLIST
71+
!word W_FIND_NAME_IN
72+
!word W_DUP
73+
!word W_ZEQUAL
74+
+ZBRANCH +
75+
!word W_DROP
76+
77+
; ( c-addr u )
78+
79+
!word W_2DUP
80+
!word W_FORTH_WORDLIST
81+
!word W_FIND_NAME_IN
82+
!word W_DUP
83+
!word W_ZEQUAL
84+
+ZBRANCH +
85+
!word W_DROP
86+
87+
; ( c-addr u )
88+
89+
!word W_2DUP
90+
!word W_ENVIRONMENT_WORDLIST
91+
!word W_FIND_NAME_IN
92+
93+
+
94+
; ( c-addr u 0|nt )
95+
!word W_NIP
96+
!word W_NIP
97+
!word W_PSEMI
6498

6599
+NONAME
66100
W_AUTOBOOT_BOOTSTRAP
@@ -71,9 +105,6 @@ W_AUTOBOOT_BOOTSTRAP
71105

72106
!word W_BOOTSTRAP_MIN
73107

74-
!word W_CR
75-
+DOTQ "Starting bootstrap stage 2..."
76-
!word W_CR
77108
+CSLITERAL "bootstrap2.f"
78109
!word W_COUNT
79110
+CSLITERAL "included"
@@ -123,32 +154,19 @@ _bootstrap_min_extend_line
123154

124155
_bootstrap_min_found_linefeed
125156

126-
!if 0 {
127-
!word W_DOTS
128-
!word W_2DUP
129-
!word W_TYPE
130-
!word W_CR
131-
}
132-
133157
!word W_DUP
134158
!word W_TOR
135159

136160
; (c-addr u) (R: c-addr u)
137161
!word W_EVALUATE
138162

139-
!if 0 {
140-
+DOTQ "evaluate done"
141-
!word W_CR
142-
}
163+
; TODO check for dictionary colliding with bootstrap
143164

144165
!word W_2RFROM
145166
!word W_PLUS
146167
!word W_1PLUS ; eat the linefeed
147168

148169
!word W_TOR
149-
!if 0 {
150-
!word W_DOTS,W_CR
151-
}
152170

153171
+BRANCH _bootstrap_min_loop
154172

@@ -161,11 +179,7 @@ _bootstrap_min_done
161179
!word W_PSEMI
162180

163181
BOOTSTRAP_MIN_START
164-
; TODO make a bootstrap.f of just what we need to get off the ground
165182
!binary "bootstrap1.f"
166-
; !binary "core.f"
167-
; !binary "core-ext.f"
168-
; !binary "file.f"
169-
!byte $0a
183+
!byte $0a ; an extra linefeed since we don't handle the last line yet TODO remove
170184
BOOTSTRAP_MIN_LEN = *-BOOTSTRAP_MIN_START
171185
BOOTSTRAP_MIN_END

src/bootstrap1.f

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
( 2 if... )
2121
( 3 do... [loop|+loop] )
2222

23+
internals-wordlist current !
24+
2325
( Resolve backward branch )
2426
: back here - , ; compile-only ( TODO REMOVE? )
2527

28+
forth-wordlist current !
29+
2630
( Marks the origin of an unconditional forward branch )
2731
: ahead postpone branch here 0 , ( 2 ) ; immediate compile-only
2832

@@ -57,11 +61,15 @@
5761

5862
: c, ( char -- ) here c! 1 allot ;
5963

64+
internals-wordlist current !
65+
6066
( counted string literal )
6167
: csliteral ( c-addr u -- ) ( -- c-addr )
6268
postpone (csliteral) dup c, swap over here swap cmove allot
6369
; immediate compile-only
6470

71+
forth-wordlist current !
72+
6573
( TODO this only works for len <= 255 )
6674
: sliteral ( c-addr u -- ) ( -- c-addr u )
6775
postpone csliteral postpone count
@@ -75,17 +83,17 @@
7583
sbuf swap 2dup 2>r cmove 2r> ( TODO klunky )
7684
then ; immediate
7785

78-
: ' parse-name find-name dup 0= -13 and throw name>interpret ;
86+
: ' parse-name find-name name>interpret dup 0= -14 and throw ;
7987

8088
( : postpone )
8189
( parse-name find-name dup 0= -13 and throw )
8290
( name>compile swap postpone literal compile, ; immediate )
8391

8492
: ['] ' postpone literal ; immediate compile-only
8593

86-
: >body 2+ ;
94+
: >body ( xt -- a-addr ) 2+ ;
8795

88-
: to state @ if
96+
: to ( i*x "<spaces>name" -- ) state @ if
8997
postpone ['] postpone >body postpone !
9098
else
9199
' >body !
@@ -96,7 +104,18 @@
96104

97105
1 constant r/o
98106

99-
: included r/o open-file if -38 throw then
107+
: close-file ( fileid -- ior ) k-close k-readss ;
108+
109+
: open-file ( c-addr u fam -- fileid ior )
110+
drop ( TODO use fam )
111+
0 0 k-setbank k-setnam unused-logical dup unit unused-secondary k-setlfs k-open k-readss ;
112+
113+
: include-file ( i*x fileid -- j*x ) save-input n>r to source-id 0 source-line !
114+
0 begin drop
115+
refill if ['] (evaluate) catch dup else 0 true then ( exception exit-flag )
116+
until nr> restore-input drop throw ; ( TODO check status from restore-input )
117+
118+
: included r/o open-file 0<> -38 and throw
100119
>r r@ include-file r> close-file drop ;
101120

102121
.( ... BOOTSTRAP STAGE 1 COMPLETE ) cr

src/bootstrap2.f

Lines changed: 78 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11

2+
cr .( Starting bootstrap stage 2... ) cr
3+
24
s" d-core.f" included
35
s" d-core-ext.f" included
46
s" d-file.f" included
7+
s" d-search.f" included
58

6-
:noname ; is autoboot \ TODO could use decimal to save a few bytes
9+
' decimal is autoboot
710

811
: savesystem ( "<spaces>name" -- ) parse-name w/o open-file drop \ TODO check status from open-file
912
>r ( R: fid )
@@ -21,11 +24,20 @@
2124
then
2225
again ; is (quit)
2326

27+
:noname ( -- )
28+
'<' emit depth 0 u.r '>' emit space depth
29+
if 0 depth 2- do i pick . -1 +loop then ; is .s
30+
2431
\ Before saving a system, the following deferred words MUST be defined:
25-
\ . .S AUTOBOOT (QUIT)
32+
\ . .S AUTOBOOT (QUIT) FIND-NAME
33+
34+
forth-wordlist 1 set-order
2635

27-
.( ... saving forth-minimal ) cr
36+
.( ... saving forth-minimal )
2837
savesystem forth-minimal,p,w
38+
unused . s" bytes free" type cr \ 28194
39+
40+
environment-wordlist forth-wordlist internals-wordlist 3 set-order
2941

3042
s" d-block.f" included
3143
s" d-block-ext.f" included
@@ -42,7 +54,6 @@
4254
s" d-locals-ext.f" included
4355
s" d-memory.f" included
4456
\ s" d-memory-ext.f" included \ TODO no need for one yet
45-
s" d-search.f" included
4657
s" d-search-ext.f" included
4758
s" d-string.f" included
4859
s" d-string-ext.f" included
@@ -51,25 +62,81 @@
5162
s" d-xchar.f" included
5263
s" d-xchar-ext.f" included
5364

65+
\ TODO should prompt text be separate from prompt colour?
5466
:noname
5567
case
56-
3 of 4 foreground endof \ error - purple
57-
2 of 14 foreground ." ok" cr endof \ prompt - lt blue
58-
1 of 7 foreground endof \ input - yellow
68+
3 of 4 foreground endof \ error - purple
69+
2 of 14 foreground space ." ok" cr endof \ prompt - lt blue
70+
1 of 7 foreground endof \ input - yellow
5971
( 0 ) 1 foreground \ output - white
6072
endcase ; is theme
6173

62-
.( ... saving forth-complete ) cr
74+
: marker ( "<spaces>name" -- ) ( -- )
75+
here
76+
create
77+
, \ save here
78+
get-current , \ save current
79+
get-order dup , 0 ?do , loop \ save order
80+
\ save fixup to account for head of current wordlist changing when
81+
\ we did the create
82+
get-current @ @ get-current forth-wordlist - here +
83+
forth-wordlist here 20 dup allot cmove \ save wordlist table
84+
! \ do the fixup
85+
does>
86+
dup @ to here cell+ \ restore here
87+
dup @ set-current cell+ \ restore current
88+
dup dup @ 0 ?do dup dup @ i - cells + @ swap loop @ set-order dup @ 1+ cells + \ restore order
89+
forth-wordlist 20 cmove \ restore wordlist table
90+
;
91+
92+
: type-file ( fileid -- )
93+
cr >r r@ fileid>buffer
94+
begin
95+
( c-addr u ) ( R: fileid )
96+
2dup r@ read-line throw ( c-addr u u2 flag ior ) ( R: fileid )
97+
while
98+
( c-addr u u2 )
99+
2 pick swap type cr
100+
repeat 2drop r> drop ;
101+
102+
: cat ( "<spaces>name" ) parse-name r/o open-file 0<> -38 and throw
103+
dup type-file close-file drop ;
104+
105+
only forth definitions
106+
107+
.( ... saving forth-complete )
63108
savesystem forth-complete,p,w
109+
unused . s" bytes free" type cr \ 24754
64110

65111
.( ... bootstrap stage 2 complete ) cr cr
66112

67-
unused . s" bytes free" type cr \ 26693
68-
69113
: test s" test.f" included ;
70114

71115
: bm s" benchmark.f" included ;
72116

73-
1 2 3 asdjfklj 4 5 6
117+
\ see marker
118+
119+
\ 1 2 3 asdjfklj 4 5 6
120+
121+
\ .( pre marker ) cr
122+
\ .( here= ) here . cr
123+
\
124+
\ marker foo
125+
\
126+
\ 100 allot
127+
\
128+
\ cr
129+
\ .( after creating marker ) cr
130+
\ .s cr
131+
\ .( here= ) here . cr
132+
\ .( foo= ) s" foo" find-name . cr
133+
\
134+
\ foo
135+
\
136+
\ cr
137+
\ .( after running marker ) cr
138+
\ .s cr
139+
\ .( here= ) here . cr
140+
\ .( foo= ) s" foo" find-name . cr
74141

75142
.( end of bootstrap2.f ) cr

src/d-block-ext.asm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
; This is also an initialisation procedure before first use
1717
; of the disc.
1818

19-
+WORD "empty-buffers"
19+
+CREATE "empty-buffers"
2020
W_EMPTY_BUFFERS
2121
!word DO_COLON
2222
; !word FIRST
@@ -37,7 +37,7 @@ W_EMPTY_BUFFERS
3737
; device. SCR contains the screen number during and after
3838
; this process.
3939

40-
+WORD "list"
40+
+CREATE "list"
4141
W_LIST
4242
!word DO_COLON
4343
; !word DECIM
@@ -81,7 +81,7 @@ W_LIST
8181
;; SCR
8282
;; SCREEN 36 LINE 13
8383
;;
84-
+WORD "scr"
84+
+CREATE "scr"
8585
W_SCR
8686
; !word DOUSE
8787
; !byte $1C

0 commit comments

Comments
 (0)