0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-15 18:55:06 +00:00

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 } %you { me }
|1000 me |1000 me
EOD EOD
expect_failure 'Recursion level too deep: include' <<'EOD' expect_failure 'Recursion level too deep: ~asma-test/in.tal' <<'EOD'
include asma-test/in.tal ~asma-test/in.tal
EOD EOD
expect_failure 'Label not found: ;blah' <<'EOD' expect_failure 'Label not found: ;blah' <<'EOD'
|1000 ;blah |1000 ;blah

View file

@ -62,7 +62,7 @@
&dest-file &dest-file
"bin/asma-boot.rom 00 "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 Heap, a large temporary area for keeping track of labels. More complex

View file

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

View file

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

View file

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

View file

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