-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinclude_code_fs
80 lines (63 loc) · 2.46 KB
/
include_code_fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
\ include_code_fs
\ This file is part of Sfera, a library for SuperForth
\ http://programandala.net/en.program.sfera.html
\ Author: Marcos Cruz (programandala.net), 2016.
\
\ Code based on the SuperForth word `load_file`, written by
\ Gerry Jackson, 1985.
\ ==============================================================
\ License
\ You may do whatever you want with this work, so long as you
\ retain the copyright/authorship/acknowledgment/credit
\ notice(s) and this license in all redistributed copies and
\ derived works. There is no warranty.
\ ==============================================================
\ History
\ 2016-01-09: Code copied from SuperForth 2.0. Layout changes.
\ Renamed words. Did some changes after Sfera.
\
\ 2016-01-14: Simplified: no `#bin` to store the channel and
\ close it at the end; `#in` can be used directly.
\
\ 2016-02-08: Removed `end-of-file`.
\
\ 2016-02-10: Improved with `pathed`.
\
\ 2016-02-13: Fixed `include-code`, which was called
\ `require-code`.
\ ==============================================================
2variable #old-in
: read-number ( -- n ) key 256 * key + ;
\ Read a 16-bit number from the current input channel.
: read-code-definitions ( -- )
begin read-number h# 4AFB = while
key tib over expect \ get the name field
span @ #tib !
1 and 0= if key drop then \ lose padding if even
>in off create-code
read-number 0 do key c, loop \ compile the code
repeat ;
\ Read code definitions from the input channel.
: (included-code) ( -- )
\ #in 2@ #old-in 2! \ save the input stream \ XXX OLD
#in 2@ 2>r \ save the input stream
0 filename open_device #in 2!
read-code-definitions
#in 2@ close
\ #old-in 2@ #in 2! ; \ restore the input stream \ XXX OLD
2r> #in 2! ; \ restore the input stream
\ Include the binary file generated by an assembler,
\ whose filename is stored in `filename`.
: included-code ( ca len -- )
pathed ?filename>list (included-code) ;
\ Include a binary file _ca len_ generated by an assembler.
: include-code ( "name" -- ) parse-word included-code ;
\ Include a binary file "name" generated by an assembler.
: required-code ( ca len -- )
pathed 2dup included?
if 2drop
else filename>list (included-code) then ;
\ Require a binary file _ca len_ generated by an assembler.
: require-code ( "name" -- ) parse-word required-code ;
\ Require a binary file "name" generated by an assembler.
\ vim: filetype=superforthsfera