• 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

Revisiondeab3b82bdeda15f36b40adf7a9e29e5471a6203 (tree)
Time2014-03-17 21:13:31
AuthorJoel Matthew Rees <reiisi@user...>
CommiterJoel Matthew Rees

Log Message

Through ?STACK.
May be my last edits for a while -- I've run out of time.

Change Summary

Incremental Difference

--- a/compiler.inc
+++ b/compiler.inc
@@ -203,6 +203,26 @@ _fDOUSER:
203203 .data.l SEMIS
204204
205205
206+; 0, ( n --- )
207+; Add NULs to the dictionary, to the alignment boundary.
208+;
209+ HIHEADER "0,", NULCOMMA, DOCOL
210+ mov.l @(XDP,fUP), r0 ; XDP is within range.
211+ mov.l r0, r1
212+ mALIGNr0
213+ mov #0, r2
214+NULCOMMAloop:
215+ cmp/hi r1, r0 ; aligned in r0 higher than r1?
216+ bf NULCOMMAend
217+ mov.b r2, @r1
218+ bra NULCOMMAloop
219+ add #1, r1
220+;
221+NULCOMMAend:
222+ mov.l r0, @(XDP,fUP)
223+ rts
224+
225+
206226 ; , ( n --- )
207227 ; Store natural word n at DP+.
208228 ; (Store and allocate, which is the wrong order for things.)
@@ -318,6 +338,173 @@ COMPILE_MODE: .equ h'C0
318338 .data.l SEMIS
319339
320340
341+
342+; (;CODE) ( --- ) ( IP *** ) C
343+; Compile the latest symbol as a reference to a ;CODE definition.
344+; Overwrite the code field of the symbol referenced by LATEST
345+; with a jump to the low-level characteristic code provided
346+; in the defining definition.
347+; The machine-level code which follows (;CODE) in the
348+; instruction stream is not executed by the defining symbol,
349+; but becomes the characteristic of the defined symbol. See ;CODE.
350+;
351+; Note that IP is popped in the process,
352+; so the assembler level code (or machine code)
353+; which follows ;CODE is assembled in interpretive mode.
354+;
355+ HIHEADER "(;CODE)", PSCODE, DOCOL
356+ .data.l FROMR,NATPLUS,LATEST,PFA,CFA,STORE
357+ .data.l SEMIS
358+
359+
360+; ;CODE ( --- ) P,C
361+; { : name preparatory-stuff ;CODE defining-machine-level-code C, .... } or
362+; { : name preparatory-stuff ;CODE defining-assembler-code .... } typical use
363+; ?CSP to see if there are loose ends in the defining definition
364+; before shifting to the assembler, compile (;CODE)
365+; in the defining definition's instruction stream,
366+; shift to interpreting.
367+;
368+; When the assembler has been implemented, this should
369+; set the ASSEMBLER vocabulary CURRENT.
370+;
371+; Note that ;CODE, unlike DOES>, is IMMEDIATE, and compiles
372+; (;CODE), which will do the actual work of changing the LATEST
373+; definition's characteristic when the defining word runs.
374+; Assembly is then done by the interpreter rather than the compiler.
375+;
376+; Note also that I would be inclined to check the stack here (QSTACK)
377+; and mark it again, to be checked at the end of the assembly
378+; language code by a word called ";ASM" or some such.
379+; The 6800 model, on the other hand, suggests just replacing the
380+;
381+ HIHEADER ";CODE", SEMIC, DOCOL, MIMM
382+ .data.l QCSP,COMPIL,PSCODE,SMUDGE,LBRAK,QSTACK
383+ .data.l NOOP, NOOP
384+ .data.l SEMIS
385+; note: "QSTACK" can be replaced by "ASSEMBLER" later,
386+; or stack-checking performed here and at the end of assembly, too.
387+; For the present, we can still hand-assemble code and use , and C,
388+; to "poke" it in after the ;CODE .
389+
390+
391+; <BUILDS ( --- )
392+; { : name <BUILDS preparatory-stuff
393+; DOES> defining-stuff ; } typical use
394+; Build a header for DOES> definitions.
395+; The defining code is high-level.
396+;
397+; Actually <BUILDS just compiles a CONSTANT zero
398+; which can be overwritten later by DOES>.
399+;
400+; Note that <BUILDS is not IMMEDIATE,
401+; and therefore executes during a definition's run-time,
402+; rather than its compile-time.
403+; It is not intended to be used directly,
404+; but rather so that one definition can build another.
405+; Also, note that nothing particularly special
406+; happens in the defining definition until DOES> executes.
407+; The name <BUILDS seems intended to be a reminder
408+; of what is about to occur.
409+;
410+ HIHEADER "<BUILDS", BUILDS, DOCOL
411+ .data.l ZERO,CON
412+ .data.l SEMIS
413+
414+
415+; DOES> ( --- ) ( IP *** ) C
416+; Define run-time behavior of definitions at the high level
417+; -- could be called the FORTH equivalent of a compiler-compiler,
418+; but not-quite-the-same.
419+; DOES> assumes that the LATEST symbol table entry has
420+; at least one word of parameter field, which <BUILDS provides.
421+;
422+; Note that DOES> is also not IMMEDIATE.
423+; When the defining word containing DOES> executes the DOES> icode,
424+; it overwrites the LATEST symbol's CFA with the DOES>
425+; (hidden) characteristic (DODOES),
426+; overwrites the first word of that symbol's parameter field
427+; with its own IP, and pops the previous IP from the return stack.
428+; The icodes which follow DOES> in the stream do not execute
429+; at the defining word's run-time,
430+; but at the run-time of the word which is being CREATEd.
431+;
432+; This is similar to ;CODE, but at the high-level.
433+;
434+; The advantage of this kind of behaviour is that the defined word
435+; can contain both operations and data to be operated on.
436+; This is how FORTH data objects define their own behavior.
437+;
438+; Finally, note that the effective code field for DOES> definitions
439+; is two natural words, rather than the usual on. This means that
440+; the effective parameter field is one word farther from the header
441+; than with ;CODE.
442+;
443+ HIHEADER "DOES>", DOES, DOCOL
444+ .data.l FROMR,NATPLUS,LATEST,PFA,STORE
445+ .data.l PSCODE
446+DODOES:
447+_fDODOES:
448+ mov.l fIP, @-fRP ; ready to resume caller
449+ add #NATURAL_SIZE, fW ; point to characteristic being invoked
450+ mov.l @fW, fIP ; Ready to start high-level characteristic.
451+ add #NATURAL_SIZE, fW ; high-level parameter field
452+ rts ; Back to the inner interpreter
453+ mov.l fW, @-fSP ; push the address as we go
454+
455+
456+; ." ( --- ) P
457+; { ." something-to-be-printed " } typical input
458+; Use WORD to parse to trailing quote.
459+; If compiling, compile XDOTQ and string parsed,
460+; otherwise, TYPE string.
461+;
462+; Maximum length is installation dependent and not well-defined.
463+; Note that WORD uses unallocated space in the dictionary as a
464+; convenient parsing buffer,
465+; so all that is needed after the scan is an allot
466+; to finish compiling the string into the instruction stream.
467+; But on the SH-3, we must then ALIGN the dictionary with NULs.
468+; (I suppose ASCII SPACE might do as well, relative to the high bit.)
469+;
470+ HIHEADER ".""", DOTQ, DOCOL, MIMM
471+ .data.l LIT
472+ .data.l """"
473+ .data.l STATE,AT,ZBRAN
474+ mTARGET DOTQinterp
475+ .data.l COMPIL,PDOTQ,WORD
476+ .data.l HERE,CAT,ONEP,ALLOT,NULCOMMA
477+ .data.l BRAN
478+ mTARGET DOTQleave
479+DOTQinterp:
480+ .data.l WORD,HERE,COUNT,TYPE
481+DOTQleave:
482+ .data.l SEMIS
483+
484+
485+; ?STACK ( --- )
486+; Check paramater stack and ERROR if out of bounds.
487+;
488+; Checks that the stack hasn't entered the buffer region.
489+;
490+ HIHEADER "?STACK", QSTACK, DOCOL
491+ .data.l LIT
492+ .data.l SINIT-ORIG ; Why not the USER S0?
493+ .data.l PORIG,AT,PTRWIDTH,SUB,SPAT,LESS,LIT
494+ .data.l errSTACK_UNDERFLOW
495+ .data.l QERR ; stack underflow?
496+;
497+ .data.l SPAT
498+ .data.l HERE,LIT
499+ .data.l h'80 ; hard-wired buffer zone of 128
500+ .data.l PLUS,LESS,ZBRAN
501+ .data.l QSTACleave
502+ .data.l LIT
503+ .data.l errDICTIONARY_FULL ; at least 128 higher than dictionary pointer?
504+ .data.l QERR ; stack overflow?
505+QSTACleave:
506+ .data.l SEMIS
507+
321508
322509 ; [COMPILE] ( --- ) P
323510 ; { [COMPILE] name } typical use
--- a/error.inc
+++ b/error.inc
@@ -42,7 +42,8 @@
4242 errNONE: .equ 0
4343 ; FCC "DATA STACK UNDERFLOW " 1
4444 errSTACK_UNDERFLOW: .equ 1
45-; FCC "DICTIONARY FULL " 2
45+; FCC "DICTIONARY FULL " 2
46+errDICTIONARY_FULL: .equ 2
4647 ; FCC "ADDRESS RESOLUTION ERROR " 3
4748 ; FCC "HIDES DEFINITION IN " 4
4849 ; FCC "NULL VECTOR WRITTEN " 5
--- a/evaluator.inc
+++ b/evaluator.inc
@@ -764,6 +764,35 @@ DDUPzero:
764764 .data.l SEMIS
765765
766766
767+; COUNT ( strptr --- strptr+1 count )
768+; Convert counted string to string and count. (Fetch the byte at
769+; strptr, post-increment and leave the pointer under the count.)
770+; COUNT is typically used to set up the arguments for TYPE.
771+;
772+ HIHEADER COUNT, COUNT, DOCOL
773+ .data.l DUP,ONEP,SWAP,CAT
774+ .data.l SEMIS
775+
776+
777+; -TRAILING ( strptr count1 --- strptr count2 )
778+; Supress trailing blanks.
779+; (Subtract count of trailing blanks from count1.)
780+;
781+ HIHEADER "-TRAILING", DTRAIL, DOCOL
782+ .data.l DUP,ZERO,XDO
783+DTRALloop:
784+ .data.l OVER,OVER,PLUS,ONE,SUB,CAT,BL
785+ .data.l SUB,ZBRAN
786+ mTARGET DTRALbackup
787+ .data.l LEAVE,BRAN
788+ mTARGET DTRALend
789+DTRALbackup:
790+ .data.l ONE,SUB
791+DTRALend:
792+ .data.l XLOOP
793+ mTARGET DTRALloop
794+ .data.l SEMIS
795+
767796
768797
769798 ; D- ( d1 d2 --- d1+d2 )
--- a/inout.inc
+++ b/inout.inc
@@ -233,3 +233,32 @@
233233 .data.l QERR
234234 .data.l SEMIS
235235
236+
237+; TYPE ( strptr count --- )
238+; EMIT count characters at strptr.
239+;
240+ HIHEADER TYPE, TYPE, DOCOL
241+ .data.l DDUP,ZBRAN
242+ mTARGET TYPEdrop
243+ .data.l OVER,PLUS,SWAP,XDO
244+TYPEloop:
245+ .data.l I,CAT,EMIT,XLOOP
246+ mTARGET TYPEloop
247+ .data.l BRAN
248+ mTARGET TYPEleave
249+TYPEdrop:
250+ .data.l DROP
251+TYPEleave:
252+ .data.l SEMIS
253+
254+
255+; (.") ( --- )
256+; TYPE counted string out of instruction stream (updating IP).
257+;
258+ HIHEADER "(."")", PDOTQ, DOCOL
259+ .data.l R,COUNT,DUP,ONEP
260+ .data.l FROMR,PLUS,ALIGN,TOR,TYPE
261+ .data.l SEMIS
262+
263+
264+
--- a/symbol.inc
+++ b/symbol.inc
@@ -297,7 +297,7 @@ TRAVloop:
297297 .data.l _fPFA-_lPFA ; Use the offsets in its own header.
298298 .data.l PLUS
299299 .data.l SEMIS
300-
300+
301301
302302 ; HEADER ,
303303 ; HIHEADER , ,
--- a/teststuff.inc
+++ b/teststuff.inc
@@ -50,15 +50,18 @@
5050 ; CONTXT: .define "NOOP" ; used in COLON
5151 CREATE: .define "NOOP" ; used in COLON
5252 ; RBRAK: .define "NOOP" ; used in COLON
53-PSCODE: .define "NOOP" ; used in COLON
53+; PSCODE: .define "NOOP" ; used in COLON
5454 ; QCSP: .define "NOOP" ; used in SEMI
5555 ; COMPIL: .define "NOOP" ; used in SEMI
5656 ; SMUDGE: .define "NOOP" ; used in SEMI
5757 ; LBRAK: .define "NOOP" ; used in SEMI
5858 ; COMMA: .define "NOOP" ; used in CONSTANT
59-DODOES: .define "NOOP" ; used in ROMFORTH
59+; DODOES: .define "NOOP" ; used in ROMFORTH
6060 DOVOC: .define "NOOP" ; used in ROMFORTH
6161 ERROR: .define "NOOP" ; used in QERROR
62+; QSTACK: .define "NOOP" ; used in ;CODE
63+WORD: .define "NOOP" ; used in DOTQ
64+
6265 ; : .define "NOOP"
6366
6467