Change "include" word into ~ rune for includes.

This commit is contained in:
Andrew Alderwick 2021-11-17 22:06:00 +00:00
parent 312429bcd8
commit c3ac41c41d
6 changed files with 27 additions and 42 deletions

View File

@ -82,8 +82,8 @@ expect_failure 'Recursion level too deep:' <<'EOD'
%you { me }
|1000 me
EOD
expect_failure 'Recursion level too deep: include' <<'EOD'
include asma-test/in.tal
expect_failure 'Recursion level too deep: ~asma-test/in.tal' <<'EOD'
~asma-test/in.tal
EOD
expect_failure 'Label not found: ;blah' <<'EOD'
|1000 ;blah

View File

@ -62,7 +62,7 @@
&dest-file
"bin/asma-boot.rom 00
include projects/library/asma.tal
~projects/library/asma.tal
(
Heap, a large temporary area for keeping track of labels. More complex

View File

@ -226,7 +226,7 @@
POP2 POP2 POP2 POP2 POP2
JMP2r
include projects/library/file-read-chunks.tal
~projects/library/file-read-chunks.tal
(
Assemble a chunk of source code, which begins with whitespace or the start
@ -303,7 +303,6 @@ include projects/library/file-read-chunks.tal
asma/state contains several meaningful bits:
0x02 we are in a comment,
0x04 we are in a macro body,
0x08 we are expecting an include filename, and
0x10 we are in a macro body that we are ignoring
(because the macro was already defined in a previous pass).
Since 0x10 never appears without 0x04, the lowest bit set in asma/state is
@ -349,15 +348,11 @@ include projects/library/file-read-chunks.tal
:asma-first-char-normal/_entry
:asma-first-char-comment/_entry
:asma-first-char-macro/_entry
$2 ( invalid position )
$2 ( empty tree for include )
&body-routines
:asma-normal-body
:asma-ignore
:asma-macro-body
$2 ( invalid position )
:asma-include-filename
@asma-parse-hex-digit ( charcode -- 00-0f if valid hex
OR 10-ff otherwise )
@ -410,14 +405,14 @@ include projects/library/file-read-chunks.tal
%asma-RETURN-FLAG { #40 }
%asma-KEEP-FLAG { #80 }
include projects/library/string.tal
~projects/library/string.tal
@asma-traverse-tree ( incoming-ptr* -- binary-ptr* 00 if key found
OR node-incoming-ptr* 01 if key not found )
;asma/token LDA2
( fall through to traverse-tree )
include projects/library/binary-tree.tal
~projects/library/binary-tree.tal
@asma-parse-opcode ( -- byte 00 if valid opcode
OR 01 otherwise )
@ -526,7 +521,7 @@ include projects/library/binary-tree.tal
POP2 POP2
JMP2r
include projects/library/heap.tal
~projects/library/heap.tal
(
First character routines.
@ -793,12 +788,6 @@ include projects/library/heap.tal
&not-macro
POP2
;&include-string ;asma/token LDA2
;strcmp JSR2 NIP2 NIP2 NIP ,&not-include JCN
#08 asma-STATE-SET
JMP2r
&not-include
;asma-msg-token ;asma/error STA2
JMP2r
@ -806,10 +795,8 @@ include projects/library/heap.tal
;asma-msg-too-deep ;asma/error STA2
JMP2r
&include-string "include 00
@asma-include-filename
#08 asma-STATE-CLEAR
@asma-include
.System/rst DEI #e0 GTH ,asma-normal-body/too-deep JCN
;heap LDA2
;asma/token LDA2 ;append-heap-string JSR2
;asma-assemble-file-pass JSR2
@ -864,7 +851,8 @@ include projects/library/heap.tal
&5d :&40 :&7c '] 00 :asma-ignore
&7b $2 $2 '{ 00 :asma-ignore
&7c :&7b :&7d '| 00 :asma-pad-absolute
&7d $2 $2 '} 00 :asma-ignore
&7d $2 :&7e '} 00 :asma-ignore
&7e $2 $2 '~ 00 :asma-include
@asma-opcodes
&_entry :&GTH :&ROT &_disasm "LIT 00

View File

@ -40,7 +40,7 @@
#01 .System/halt DEO
BRK
include projects/library/asma.tal
~projects/library/asma.tal
@asma-heap
|e000 &end

View File

@ -401,11 +401,11 @@ RTN
2729 2b2e 3032 3537 3a3d 3f42 4547 4a4d
5053 5659 5c5f 6265 686b 6e71 7477 7a7d
include projects/library/check-rom.tal
include projects/library/load-rom.tal
~projects/library/check-rom.tal
~projects/library/load-rom.tal
include projects/assets/mascot0cx0c.tal
include projects/assets/msx01x02.tal
~projects/assets/mascot0cx0c.tal
~projects/assets/msx01x02.tal
@dir
&path ". $1

View File

@ -142,7 +142,7 @@ sublabel(char *src, char *scope, char *name)
#pragma mark - Parser
static int
error(char *name, char *msg)
error(const char *name, const char *msg)
{
fprintf(stderr, "%s: %s\n", name, msg);
return 0;
@ -310,17 +310,14 @@ parsetoken(char *w)
}
static int
doinclude(FILE *f, int (*pass)(FILE *))
doinclude(const char *filename, int (*pass)(FILE *))
{
char word[64];
FILE *finc;
FILE *f;
int ret;
if(fscanf(f, "%63s", word) != 1)
return error("End of input", "include");
if(!(finc = fopen(word, "r")))
return error("Include failed to open", word);
ret = pass(finc);
fclose(finc);
if(!(f = fopen(filename, "r")))
return error("Include failed to open", filename);
ret = pass(f);
fclose(f);
return ret;
}
@ -348,8 +345,8 @@ pass1(FILE *f)
} else if(w[0] == '&') {
if(!makelabel(sublabel(subw, scope, w + 1)))
return error("Pass 1 - Invalid sublabel", w);
} else if(scmp(w, "include", 8)) {
if(!doinclude(f, pass1))
} else if(w[0] == '~') {
if(!doinclude(w + 1, pass1))
return 0;
} else if(sihx(w))
addr += slen(w) / 2;
@ -386,8 +383,8 @@ pass2(FILE *f)
} else if(w[0] == '@') {
scpy(w + 1, scope, 64);
continue;
} else if(scmp(w, "include", 8)) {
if(!doinclude(f, pass2))
} else if(w[0] == '~') {
if(!doinclude(w + 1, pass2))
return 0;
continue;
}