• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Implementing figFORTH on SH3 assembler


Commit MetaInfo

Revisión338d0dd50a7709c65aa80f78651c5a33bfee2c4c (tree)
Tiempo2014-03-14 21:06:47
AutorJoel Matthew Rees <reiisi@user...>
CommiterJoel Matthew Rees

Log Message

Up to HEX and DECIMAL, #116

Cambiar Resumen

Diferencia incremental

--- a/compiler.inc
+++ b/compiler.inc
@@ -221,4 +221,115 @@ _fDOUSER:
221221 .data.l HERE,CSTORE,ONE,ALLOT
222222 .data.l SEMIS
223223
224+
225+; !CSP ( --- )
226+; Save the parameter stack pointer in CSP for compiler checks.
227+ HIHEADER "!CSP", SCSP, DOCOL
228+ .data.l SPAT,CSP,STORE
229+ .data.l SEMIS
230+
231+
232+; ?COMP ( --- ) ( *** )
233+; ( --- IN BLK ) ( anything *** nothing )
234+; ERROR if not compiling.
235+;
236+ HIHEADER "?COMP", QCOMP, DOCOL
237+ .data.l STATE,AT,ZEQU,LIT
238+ .data.l errCOMPILE_ONLY
239+ .data.l QERR
240+ .data.l SEMIS
241+
242+
243+; ?PAIRS ( n1 n2 --- ) ( *** )
244+; ( n1 n2 --- IN BLK ) ( anything *** nothing )
245+; ERROR if n1 and n2 are unequal.
246+;
247+; MESSAGE says compiled conditionals do not match.
248+;
249+ HIHEADER "?PAIRS", QPAIRS, DOCOL
250+ .data.l SUB,LIT
251+ .data.l errUNBALANCED_CONDITIONALS
252+ .data.l QERR
253+ .data.l SEMIS
254+
255+
256+; ?CSP ( --- ) ( *** )
257+; ( --- IN BLK ) ( anything *** nothing )
258+; ERROR if parameter stack is not at same level as last !CSP.
259+;
260+; MESSAGE says a definition has been left incomplete.
261+;
262+ HIHEADER "?CSP", QCSP, DOCOL
263+ .data.l SPAT,CSP,AT,SUB,LIT
264+ .data.l errDEFINITION_INCOMPLETE
265+ .data.l QERR
266+ .data.l SEMIS
267+
268+
269+; COMPILE ( --- )
270+; Compile an in-line literal value from the instruction stream.
271+;
272+ HIHEADER COMPILE, COMPIL, DOCOL
273+ .data.l QCOMP,FROMR,NATPLUS,DUP,TOR,AT,COMMA
274+ .data.l SEMIS
275+
276+
277+COMPILE_MODE: .equ h'C0
278+
279+
280+; [ ( --- ) P
281+; Clear the compile state bits (shift to interpret).
282+; { : symbol compiled-stuff [ compile-time-stuff ] more-compiled-stuff ; } typical use
283+;
284+; Sometimes you need to do something run-time at compile-time.
285+; For example, you may not know a constant's actual value
286+; until the source is compiled. But it will be a real constant,
287+; so you don't want to compile in the calculation.
288+;
289+; (This is one of the killer features of FORTH.
290+; It seriously reduces the burden on the optimizer, when there is one.)
291+;
292+ HIHEADER "[", LBRAK, DOCOL, MIMM
293+ .data.l ZERO,STATE,STORE
294+ .data.l SEMIS
295+
296+
297+; ] ( --- )
298+; Set the compile state bits. (Shift back to compiling.)
299+; See [.
300+;
301+ HIHEADER "[", RBRAK, DOCOL
302+ .data.l LIT
303+ .data.l COMPILE_MODE
304+ .data.l STATE,STORE
305+ .data.l SEMIS
306+
307+
308+; SMUDGE ( --- )
309+; Toggle HIDDEN bit of LATEST definition header,
310+; to hide it until defined, or reveal it after definition.
311+;
312+; It helps keep symbol table lookup simple in the compiler.
313+;
314+ HIHEADER SMUDGE, SMUDGE, DOCOL
315+ .data.l LATEST,LIT
316+ .data.l MHID
317+ .data.l TOGGLE
318+ .data.l SEMIS
319+
320+
321+
322+; [COMPILE] ( --- ) P
323+; { [COMPILE] name } typical use
324+; -DFIND next WORD and COMPILE it, literally; used to compile
325+; immediate definitions.
326+;[COMPILE] p,C
327+; Used in a colon-definition in form:
328+; : xxx [COMPILE] FORTH ;
329+; [COMPILE] will force the compilation of an immediate definitions,
330+; that would otherwise execute during compilation. The above example
331+; will select the FORTH vocabulary then xxx executes, rather than at
332+; compile time.
333+;
334+;
224335
--- a/context.inc
+++ b/context.inc
@@ -389,6 +389,7 @@ _s\characteristic: .sdata .substr("\name", 0, .len("\name")-1)
389389 ; Symbol names float a little, yes this is a little awkward.
390390 .align NATURAL_SIZE
391391 ; (Allocation) link to previously defined symbol's header.
392+_l\characteristic
392393 .data.l _PREVNAME
393394 ; Use the SH-3 assembler to track the last symbol.
394395 ; (This is not always a good idea.)
--- /dev/null
+++ b/error.inc
@@ -0,0 +1,125 @@
1+ .list ON, EXP
2+
3+; Error handling and other message definitions for fig-FORTH for SH-3
4+; Joel Matthew Rees, Hyougo Polytec Center
5+; 2014.03.15
6+
7+; Licensed extended under GPL v. 2 or 3, or per the following:
8+; ------------------------------------LICENSE-------------------------------------
9+;
10+; Copyright (c) 2009, 2010, 2011 Joel Matthew Rees
11+;
12+; Permission is hereby granted, free of charge, to any person obtaining a copy
13+; of this software and associated documentation files (the "Software"), to deal
14+; in the Software without restriction, including without limitation the rights
15+; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16+; copies of the Software, and to permit persons to whom the Software is
17+; furnished to do so, subject to the following conditions:
18+;
19+; The above copyright notice and this permission notice shall be included in
20+; all copies or substantial portions of the Software.
21+;
22+; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23+; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24+; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25+; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26+; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27+; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28+; THE SOFTWARE.
29+;
30+; --------------------------------END-OF-LICENSE----------------------------------
31+
32+; Monolithic, not separate assembly:
33+; context.inc must be included before this file.
34+; .include "context.inc"
35+;
36+; .section error, code
37+
38+
39+; This list was originall borrowed from BIF,
40+; *** so it has some that aren't relevant! ***
41+;
42+errNONE: .equ 0
43+; FCC "DATA STACK UNDERFLOW " 1
44+errSTACK_UNDERFLOW: .equ 1
45+; FCC "DICTIONARY FULL " 2
46+; FCC "ADDRESS RESOLUTION ERROR " 3
47+; FCC "HIDES DEFINITION IN " 4
48+; FCC "NULL VECTOR WRITTEN " 5
49+; FCC "DISC RANGE? " 6
50+; FCC "DATA STACK OVERFLOW " 7
51+; FCC "DISC ERROR! " 8
52+; FCC "CAN'T EXECUTE A NULL! " 9
53+; FCC "CONTROL STACK UNDERFLOW " 10
54+; FCC "CONTROL STACK OVERFLOW " 11
55+; FCC "ARRAY REFERENCE OUT OF BOUNDS " 12
56+; FCC "ARRAY DIMENSION NOT VALID " 13
57+; FCC "NO PROCEDURE TO ENTER " 14
58+; FCC " ( WAS REGISTER ) " 15
59+;* SCREEN 5
60+; FCC " " 0
61+; FCC "COMPILATION ONLY, USE IN DEF " 1
62+errCOMPILE_ONLY: .equ h'11
63+; FCC "EXECUTION ONLY " 2
64+errEXECUTE_ONLY: .equ h'12
65+; FCC "CONDITIONALS NOT PAIRED " 3
66+errUNBALANCED_CONDITIONALS: .equ h'13
67+; FCC "DEFINITION INCOMPLETE " 4
68+errDEFINITION_INCOMPLETE: .equ h'14
69+; FCC "IN PROTECTED DICTIONARY " 5
70+; FCC "USE ONLY WHEN LOADING " 6
71+errLOADING_ONLY: .equ h'16
72+; FCC "OFF CURRENT EDITING SCREEN " 7
73+; FCC "DECLARE VOCABULARY " 8
74+; FCC "DEFINITION NOT IN VOCABULARY " 9
75+; FCC "IN FORWARD BLOCK " 10
76+; FCC "ALLOCATION LIST CORRUPTED: LOST " 11
77+; FCC "CAN'T REDEFINE nul! " 12
78+; FCC "NOT FORWARD REFERENCE " 13
79+; FCC " ( WAS IMMEDIATE ) " 14
80+; FCC " " 15
81+;* SCREEN 6
82+; FCC "( MORE ERROR MESSAGES asm6809 ) " 0
83+; FCC "HAS INCORRECT ADDRESS MODE " 1
84+; FCC "HAS INCORRECT INDEX MODE " 2
85+; FCC "OPERAND NOT REGISTER " 3
86+; FCC "HAS ILLEGAL IMMEDIATE " 4
87+; FCC "PC OFFSET MUST BE ABSOLUTE " 5
88+; FCC "ACCUMULATOR OFFSET REQUIRED " 6
89+; FCC "ILLEGAL MEMORY INDIRECTION (6809) " 7
90+; FCC "ILLEGAL INDEX BASE (6809) " 8
91+; FCC "ILLEGAL TARGET SPECIFIED " 9
92+; FCC "CAN'T STACK ON SELF (6809) " 10
93+; FCC "DUPLICATE IN LIST " 11
94+; FCC "REGISTER NOT STACK (6809) " 12
95+; FCC "EMPTY REGISTER LIST (6809) " 13
96+; FCC "IMMEDIATE OPERAND REQUIRED " 14
97+; FCC "REQUIRES CONDITION " 15
98+;*
99+;* SCREEN 7
100+; FCC " " 0
101+; FCC "COMPILE-TIME STACK UNDERFLOW " 1
102+; FCC "COMPILE-TIME STACK OVERFLOW " 2
103+
104+
105+; ?ERROR ( 0 n --- ) ( *** )
106+; ( true n --- IN BLK ) ( anything *** nothing )
107+; If flag is false, do nothing.
108+; If flag is true, issue error MESSAGE and QUIT or ABORT, via ERROR.
109+; Leaves cursor position (IN) and currently loading block number (BLK) on stack,
110+; for later analysis.
111+;
112+ HIHEADER "?ERROR", QERR, DOCOL
113+ .data.l SWAP,ZBRAN
114+ mTARGET QERRnone
115+ .data.l ERROR,BRAN
116+ mTARGET QERRleave
117+QERRnone:
118+ .data.l DROP
119+QERRleave:
120+ .data.l SEMIS
121+
122+
123+
124+
125+
--- a/evaluator.inc
+++ b/evaluator.inc
@@ -43,7 +43,7 @@
4343 ; In other words, if ptr1 is aligned at a NATURAL_SIZE boundary, do nothing.
4444 ; Otherwise, adjust it up until it is aligned.
4545 ;
46- HEADER ALIGN, xPALIGN
46+ HEADER ALIGN, ALIGN
4747 mov.l @fSP, r0
4848 mALIGNr0
4949 rts
@@ -692,12 +692,78 @@ GREATgreat:
692692 mov.l r2, @fSP
693693
694694
695+; MIN ( n0 n1 --- min(n0,n1) )
696+; Leave the minimum of the top two natural integers.
695697 ;
696-;* ======>> 93 <<
697-; FCB $83
698-; FCC 2,ROT
699-; FCB $D4
700-; FDB GREAT-4
698+ HIHEADER MIN, MIN, DOCOL
699+ .data.l OVER,OVER,GREAT,ZBRAN
700+ mTARGET MINdrop
701+ .data.l SWAP
702+MINdrop:
703+ .data.l DROP
704+ .data.l SEMIS
705+
706+
707+; MAX ( n0 n1 --- max(n0,n1) )
708+; Leave the maximum of the top two natural integers.
709+;
710+ HIHEADER MAX, MAX, DOCOL
711+ .data.l OVER,OVER,LESS,ZBRAN
712+ mTARGET MAXdrop
713+ .data.l SWAP
714+MAXdrop:
715+ .data.l DROP
716+ .data.l SEMIS
717+
718+
719+; -DUP ( 0 --- 0 )
720+; ( n --- n n )
721+; DUP iff non-zero.
722+;
723+; Convenience definition for IF tests.
724+; (Otherwise, many ELSE clauses would contain only a DROP.)
725+;
726+ HIHEADER "-DUP", DDUP, DOCOL
727+ .data.l DUP,ZBRAN
728+ mTARGET DDUPzero
729+ .data.l DUP
730+DDUPzero:
731+ .data.l SEMIS
732+
733+
734+; ?EXEC ( --- ) ( *** )
735+; ( --- IN BLK ) ( anything *** nothing )
736+; ERROR if not executing.
737+;
738+ HIHEADER "?EXEC", QEXEC, DOCOL
739+ .data.l STATE,AT,LIT
740+ .data.l errEXECUTE_ONLY
741+ .data.l QERR
742+ .data.l SEMIS
743+
744+
745+; HEX ( --- )
746+; Set the conversion base to sixteen (hexadecimal).
747+;
748+ HIHEADER HEX, HEX, DOCOL
749+ .data.l LIT
750+ .data.l 16
751+ .data.l BASE,STORE
752+ .data.l SEMIS
753+
754+
755+; DECIMAL ( --- )
756+; Set the conversion base to ten.
757+;
758+; (Note that "DEC" is a valid hexadecimal number. So is A.)
759+;
760+ HIHEADER DECIMAL, DEC, DOCOL
761+ .data.l LIT
762+ .data.l 10
763+ .data.l BASE,STORE
764+ .data.l SEMIS
765+
766+
701767
702768
703769 ; D- ( d1 d2 --- d1+d2 )
--- a/inout.inc
+++ b/inout.inc
@@ -215,3 +215,21 @@
215215 HIHEADER COLUMNS, COLUMS, DOUSER
216216 .data.l XCOLUM
217217
218+; SPACE ( --- )
219+; EMIT a SPACE.
220+;
221+ HIHEADER SPACE, SPACE, DOCOL
222+ .data.l BL,EMIT
223+ .data.l SEMIS
224+
225+
226+; ?LOADING ( --- ) ( *** )
227+; ( --- IN BLK ) ( anything *** nothing )
228+; ERROR if not loading, i. e., if BLK is zero.
229+;
230+ HIHEADER "?LOADING", QLOAD, DOCOL
231+ .data.l BLK,AT,ZEQU,LIT
232+ .data.l errLOADING_ONLY
233+ .data.l QERR
234+ .data.l SEMIS
235+
--- a/main.src
+++ b/main.src
@@ -117,6 +117,7 @@ _iWENT:
117117 .include "symbol.inc"
118118 .include "compiler.inc"
119119 .include "inout.inc"
120+ .include "error.inc"
120121
121122 .include "driver.inc"
122123
--- a/symbol.inc
+++ b/symbol.inc
@@ -196,7 +196,110 @@ PFINDret:
196196 .data.l XVOCL
197197
198198
199+; TRAVERSE ( addr1 dir --- addr2 )
200+; Traverse the name of a symbol.
201+; The sign of dir is the direction to traverse,
202+; if 1 traverse to the end (high memory),
203+; if -1 traverse to the beginning (low memory).
204+; Leave the address at the other end.
205+; (Don't pass anything but -1 or 1, not firewalled!)
206+;
207+ HIHEADER TRAVERSE, TRAV, DOCOL
208+ .data.l SWAP
209+TRAVloop:
210+ .data.l OVER,PLUS,LIT
211+ .data.l h'7f
212+ .data.l OVER,CAT,LESS,ZBRAN
213+ mTARGET TRAVloop
214+ .data.l SWAP,DROP
215+ .data.l SEMIS
216+
217+
218+; LATEST ( --- symptr )
219+; Fetch CURRENT as a per-USER constant.
220+; Returns the NFA of the most recently defined symbol
221+; in the CURRENT vocabulary.
222+;
223+ HIHEADER LATEST, LATEST, DOCOL
224+ .data.l CURENT,AT,AT
225+ .data.l SEMIS
226+
227+
228+; LFA ( pfa --- lfa )
229+; Convert PFA to LFA.
230+;
231+; LFA is the Link Field Address,
232+; the address of a definition's allocation link:
233+;
234+ HIHEADER LFA, LFA, DOCOL
235+ .data.l LIT
236+ .data.l _fLFA-_lLFA ; Use the offsets in its own header.
237+ .data.l SUB
238+ .data.l SEMIS
239+
199240
241+; CFA ( pfa --- cfa )
242+; Convert PFA to CFA.
243+;
244+; CFA is the Characteristic (or Code) Field Address,
245+; the address of the pointer to the that interprets the definition.
246+;
247+ HIHEADER CFA, CFA, DOCOL
248+ .data.l LIT
249+ .data.l _fCFA-CFA ; Use the offsets in its own header.
250+ .data.l SUB
251+ .data.l SEMIS
252+
200253
254+; NFA ( pfa --- nfa )
255+; Convert PFA to NFA.
256+;
257+; NFA is the Name Field Address,
258+; the address of the symbol name length byte in the header.
259+;
260+; Because of SH-3 alignment issues, we have to be a little tricky.
261+; **** And CREATE has to clear alignment bytes! ****
262+; This is part of the reason BIF actually points to the name string.
263+;
264+ HIHEADER NFA, NFA, DOCOL
265+ .data.l LFA ; Not to one before the link, but the link itself.
266+ .data.l ONE,MINUS,TRAV ; We know TRAVERSE bumps without looking.
267+; And we know CREATE clears the alignment bytes.
268+ .data.l ONE,MINUS,TRAV ; This is the real TRAVERSE.
269+ .data.l SEMIS
270+
271+
272+; PFA ( nfa --- pfa )
273+; Convert NFA to PFA.
274+;
275+; PFA is the Parameter Field Address,
276+; the address of the parameters which define a symbol.
277+; For a low-level definition, this is machine code.
278+; For a high-level definition, this is the definition parameters.
279+;
280+; For a CONSTANT, the parameter is a constant, or several constants.
281+; For a global VARIABLE, the parameter is a variable data value.
282+; (This makes true multi-tasking problematic, yes.)
283+; For a USER variable, it is a (constant) offset into the per-USER table.
284+;
285+; For a COLON definition, the parameter field is a list of virtual icodes,
286+; considering the address of the characteristic field
287+; as a sort of virtual (non-portable) FORTH intermediate code.
288+;
289+; And so forth (ahem).
290+;
291+; There are many ways to use the parameter field.
292+; It is the magic, the LISPishness, of FORTH!
293+;
294+ HIHEADER PFA, PFA, DOCOL
295+ .data.l ONE,TRAV,ONEP,ALIGN ; Bumped to the LFA
296+ .data.l LIT
297+ .data.l _fPFA-_lPFA ; Use the offsets in its own header.
298+ .data.l PLUS
299+ .data.l SEMIS
201300
202301
302+; HEADER ,
303+; HIHEADER , ,
304+; .data.l
305+; .data.l SEMIS
--- a/teststuff.inc
+++ b/teststuff.inc
@@ -44,20 +44,21 @@
4444 ;
4545 ; These aren't magic, just shims for the assembler.
4646 ;
47-QEXEC: .define "NOOP" ; used in COLON
48-SCSP: .define "NOOP" ; used in COLON
47+; QEXEC: .define "NOOP" ; used in COLON
48+; SCSP: .define "NOOP" ; used in COLON
4949 ; CURENT: .define "NOOP" ; used in COLON
5050 ; CONTXT: .define "NOOP" ; used in COLON
5151 CREATE: .define "NOOP" ; used in COLON
52-RBRAK: .define "NOOP" ; used in COLON
52+; RBRAK: .define "NOOP" ; used in COLON
5353 PSCODE: .define "NOOP" ; used in COLON
54-QCSP: .define "NOOP" ; used in SEMI
55-COMPIL: .define "NOOP" ; used in SEMI
56-SMUDGE: .define "NOOP" ; used in SEMI
57-LBRAK: .define "NOOP" ; used in SEMI
54+; QCSP: .define "NOOP" ; used in SEMI
55+; COMPIL: .define "NOOP" ; used in SEMI
56+; SMUDGE: .define "NOOP" ; used in SEMI
57+; LBRAK: .define "NOOP" ; used in SEMI
5858 ; COMMA: .define "NOOP" ; used in CONSTANT
5959 DODOES: .define "NOOP" ; used in ROMFORTH
6060 DOVOC: .define "NOOP" ; used in ROMFORTH
61+ERROR: .define "NOOP" ; used in QERROR
6162 ; : .define "NOOP"
6263
6364