1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; UrForth level
1: self
-hosting
32-bit Forth compiler
3 ;; Copyright
(C
) 2020 Ketmar Dark
// Invisible Vector
5 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7 vocabulary
(concomp
-flow
) (hidden
)
8 voc
-set
-active
(concomp
-flow
)
10 : [IF] ( level
-- newlevel
) 1+ ;
15 : [ELSE] ( level
-- newlevel
) 1- dup
if 1+ endif ;
17 : [ENDIF] ( level
-- newlevel
) 1- ;
26 parse
-skip
-comments parse
-name dup
27 ifnot refill not ERR
-UNBALANCED
-IFDEF ?error
endif
29 vocid
: (concomp
-flow
) voc
-search
-noimm
if execute
else 2drop
endif
34 : [ENDIF] ( -- ) ; immediate
39 ifnot
[compile
] [ELSE] endif
43 if [compile
] [ELSE] endif
46 : [IFDEF
] ( -- ) \ word
47 parse
-name has
-word? ifnot
[compile
] [ELSE] endif
50 : [IFNDEF
] ( -- ) \ word
51 parse
-name has
-word?
if [compile
] [ELSE] endif
54 : [DEFINED
] ( -- flag
) \ word
58 : [UNDEFINED
] ( -- flag
) \ word
59 parse
-name has
-word? not
63 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
64 ;; sorry
, i should find a better place
for this
65 $value
"(.lib-info)" 0
68 $value
"(.lib-sttime)" 0
71 $value
"(.lib-used)" 0
74 ;;$value
"(.lib-tmp-mark)" 0
75 ;; 1024 brk
-alloc constant
(.lib
-info
)
77 : (lib
-current
.) ( -- )
80 dup
0> over
1020 <= and
if
90 : (.lib
-put
-cell
) ( addr value
-- addr
+4 )
94 : .LIB
-START
" ( -- sttime stunused ) ;;"
95 ;; (.lib
-info
) ifnot
1024 brk
-alloc
to (.lib
-info
) endif
96 34 parse
1020 umin
;; (.lib
-info
) c4s
:COPY
-counted
97 dup
5 +cells simple
-malloc throw dup
>r
98 r
> over
>r
;; save buffer start
99 (.lib
-put
-cell
) ;; mark
100 (.lib
-info
) (.lib
-put
-cell
) ;; prev info pointer
101 ;; update info pointer
103 (.lib
-sttime
) (.lib
-put
-cell
) ;; old sttime
104 (.lib
-used
) (.lib
-put
-cell
) ;; old used
105 ;; ( addr count cbufptr
)
106 over
(.lib
-put
-cell
) ;; counter
107 swap cmove
;; libname string
108 TLOAD
-VERBOSE
-LIBS
1 > if
109 ." *** compiling library \`" (lib
-current
.) ." \`\n"
111 unused
to (.lib
-used
)
112 os
:gettickcount
to (.lib
-sttime
)
116 : .LIB
-END ( -- ) ;;"
117 TLOAD-VERBOSE-LIBS if
119 ." *** compiled library \`
" (lib-current.) ." \`
, size is
"
120 (.lib-used) unused - . ." bytes
, "
121 (.lib-sttime) - . ." msecs
\n"
124 (.lib-info) 2 +cells @ to (.lib-sttime)
125 (.lib-info) 3 +cells @ to (.lib-used)
126 (.lib-info) cell+ @ ;; old pointer
127 (.lib-info) @ simple-free throw