From 7b6481cd83ef1869345566e2583559d53476883c Mon Sep 17 00:00:00 2001 From: ketmar Date: Sat, 28 Oct 2023 21:18:15 +0000 Subject: [PATCH] urasm: moved DUP and INCLUDE into separate source file FossilOrigin-Name: 884221a0f0b0fcf19317da1e6a324cf147224f8385c4f727276f7fce085269c9 --- urflibs/urasm/ext/00-main-loader.f | 2 + urflibs/urasm/ext/dup-include.f | 91 ++++++++++++++++++++++++++++++++++++++ urflibs/urasm/main.f | 69 ++--------------------------- 3 files changed, 96 insertions(+), 66 deletions(-) create mode 100644 urflibs/urasm/ext/dup-include.f diff --git a/urflibs/urasm/ext/00-main-loader.f b/urflibs/urasm/ext/00-main-loader.f index b652076..b786e1d 100644 --- a/urflibs/urasm/ext/00-main-loader.f +++ b/urflibs/urasm/ext/00-main-loader.f @@ -17,6 +17,8 @@ $include-once $include-once $include-once +$include-once + $include-once prev-defs diff --git a/urflibs/urasm/ext/dup-include.f b/urflibs/urasm/ext/dup-include.f new file mode 100644 index 0000000..5aaede6 --- /dev/null +++ b/urflibs/urasm/ext/dup-include.f @@ -0,0 +1,91 @@ +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; and now for something completely different... +;; UrAsm Forth Engine! +;; GPLv3 ONLY +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Z80 Assembler: DUP and INCLUDE instructions +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + +also-defs: asm-helpers + +: .curr-file ( -- ) + 0 (include-file-name) xtype +; + + +0 value dup-curr + +: dup->prev ( addr -- addr ) ; immediate +: dup->count ( addr -- addr ) cell+ ; +: dup->line ( addr -- addr ) 2 +cells ; +: dup->fofs ( addr -- addr ) 3 +cells ; +4 cells constant dup-size + + +0 value inc-curr + +: inc->prev ( addr -- addr ) ; immediate +: inc->dupr ( addr -- addr ) cell+ ; +2 cells constant inc-size + +: (end-include) ( -- eof-flag ) + inc-curr if + dup-curr " unfinished DUP" ?error + inc-curr inc->dupr @ to dup-curr + inc-curr inc->prev @ to inc-curr + next-token expect-eol + refill drop next-token + false + ." continue >: " .curr-file cr + else true endif +; + +: do-include ( -- ) + next-token tok-type tk-str <> " quoted file name expected" ?error + token string:>pad next-token expect-eol + inc-size n-allot + inc-curr over inc->prev ! to inc-curr + dup-curr inc-curr inc->dupr ! + 0 to dup-curr + string:pad-cc@ 0 0 (include-no-refill) + ." included <: " .curr-file cr + next-token expect-eol +; + + +: do-edup ( -- ) + next-token expect-eol + dup-curr " EDUP without DUP" ?not-error + dup-curr dup->count @ 1- dup +if + dup-curr dup->count ! + dup-curr dup->line @ 1- dup-curr dup->fofs @ (INCLUDE-LINE-SEEK) + refill-nocross " wuta?" ?not-error parse-skip-line ;; skip EDUP + next-token expect-eol + else drop dup-curr dup->prev @ to dup-curr endif +; + +: do-dup ( -- ) + next-token asm-expr:expression-const expect-eol + dup 1 65536 within " invalid DUP counter" ?not-error + dup-size n-allot + dup-curr over dup->prev ! to dup-curr + dup-curr dup->count ! + 0 (INCLUDE-FILE-LINE) dup-curr dup->line ! + (INCLUDE-LINE-FOFS) dup-curr dup->fofs ! +; + +prev-defs + + +also-defs: asm-instr + +: INCLUDE ( -- ) asm-helpers:do-include ; +ALIAS INCLUDE $INCLUDE + +: EDUP ( -- ) asm-helpers:do-edup ; + +;;WARNING! THIS MUST BE THE LAST ONE! +: $DUP ( -- ) asm-helpers:do-dup ; + +prev-defs diff --git a/urflibs/urasm/main.f b/urflibs/urasm/main.f index 1b3c401..26c7a16 100644 --- a/urflibs/urasm/main.f +++ b/urflibs/urasm/main.f @@ -23,10 +23,6 @@ false value out-locked false value do-org-100 -: .curr-file ( -- ) - 0 (include-file-name) xtype -; - also asm-lexer also-defs: asm-instr @@ -78,67 +74,8 @@ also-defs: asm-instr ALIAS DEFFMT $DEFFMT -0 value dup-curr (hidden) - -: dup->prev ( addr -- addr ) ; immediate (hidden) -: dup->count ( addr -- addr ) cell+ ; (hidden) -: dup->line ( addr -- addr ) 2 +cells ; (hidden) -: dup->fofs ( addr -- addr ) 3 +cells ; (hidden) -4 cells constant dup-size (hidden) - - -0 value inc-curr (hidden) - -: inc->prev ( addr -- addr ) ; immediate (hidden) -: inc->dupr ( addr -- addr ) cell+ ; (hidden) -2 cells constant inc-size (hidden) - -: (end-include) ( -- eof-flag ) - inc-curr if - dup-curr " unfinished DUP" ?error - inc-curr inc->dupr @ to dup-curr - inc-curr inc->prev @ to inc-curr - next-token expect-eol - refill drop next-token - false - ." continue >: " .curr-file cr - else true endif -; (hidden) - -: INCLUDE ( -- ) - next-token tok-type tk-str <> " quoted file name expected" ?error - token string:>pad next-token expect-eol - inc-size n-allot - inc-curr over inc->prev ! to inc-curr - dup-curr inc-curr inc->dupr ! - 0 to dup-curr - string:pad-cc@ 0 0 (include-no-refill) - ." included <: " .curr-file cr - next-token expect-eol -; -ALIAS INCLUDE $INCLUDE - -: EDUP ( -- ) - next-token expect-eol - dup-curr " EDUP without DUP" ?not-error - dup-curr dup->count @ 1- dup +if - dup-curr dup->count ! - dup-curr dup->line @ 1- dup-curr dup->fofs @ (INCLUDE-LINE-SEEK) - refill-nocross " wuta?" ?not-error parse-skip-line ;; skip EDUP - next-token expect-eol - else drop dup-curr dup->prev @ to dup-curr endif -; - ;;WARNING! THIS MUST BE THE LAST ONE! -: DUP ( -- ) - next-token asm-expr:expression-const expect-eol - dup 1 65536 within " invalid DUP counter" ?not-error - dup-size n-allot - dup-curr over dup->prev ! to dup-curr - dup-curr dup->count ! - 0 (INCLUDE-FILE-LINE) dup-curr dup->line ! - (INCLUDE-LINE-FOFS) dup-curr dup->fofs ! -; +ALIAS $DUP DUP ;;WARNING! THOSE MUST BE THE LATEST ONES! : else " please, use $ELSE" asm-lexer:warning $ELSE ; @@ -202,7 +139,7 @@ also asm-lexer : assemble-file ( addr count -- ) dup +if false false (include) else 2drop endif true to line-start next-token - ." assembling: " .curr-file cr + ." assembling: " asm-helpers:.curr-file cr get-msecs >r begin begin @@ -223,7 +160,7 @@ also asm-lexer tok-type case tk-eos of asm-labels:clear-last-defined-label - asm-instr:(end-include) + asm-helpers:(end-include) if break endif endof tk-punct of assemble-token-punct endof -- 2.11.4.GIT