fix %asminclude by removing scopelabel argument and improving docs to remove false promise about labels

This commit is contained in:
Irmen de Jong 2021-05-16 00:14:57 +02:00
parent bc731e6f8e
commit 0416aacbbd
9 changed files with 41 additions and 40 deletions

View File

@ -195,7 +195,7 @@ sub print_f (float value) {
}} }}
} }
%asminclude "library:c64/floats.asm", "" %asminclude "library:c64/floats.asm"
%asminclude "library:c64/floats_funcs.asm", "" %asminclude "library:c64/floats_funcs.asm"
} }

View File

@ -158,7 +158,7 @@ sub print_f (float value) {
}} }}
} }
%asminclude "library:c64/floats.asm", "" %asminclude "library:c64/floats.asm"
%asminclude "library:c64/floats_funcs.asm", "" %asminclude "library:c64/floats_funcs.asm"
} }

View File

@ -3,5 +3,5 @@
; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0 ; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
math { math {
%asminclude "library:math.asm", "" %asminclude "library:math.asm"
} }

View File

@ -3,8 +3,8 @@
; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0 ; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
prog8_lib { prog8_lib {
%asminclude "library:prog8_lib.asm", "" %asminclude "library:prog8_lib.asm"
%asminclude "library:prog8_funcs.asm", "" %asminclude "library:prog8_funcs.asm"
uword @zp retval_interm_uw ; to store intermediary expression results for return values (hopefully allocated on ZP to reduce code size) uword @zp retval_interm_uw ; to store intermediary expression results for return values (hopefully allocated on ZP to reduce code size)
word @zp retval_interm_w ; to store intermediary expression results for return values (hopefully allocated on ZP to reduce code size) word @zp retval_interm_w ; to store intermediary expression results for return values (hopefully allocated on ZP to reduce code size)

View File

@ -691,8 +691,8 @@ internal class AstChecker(private val program: Program,
"%asminclude" -> { "%asminclude" -> {
if(directive.parent !is INameScope || directive.parent is Module) if(directive.parent !is INameScope || directive.parent is Module)
err("this directive may only occur in a block") err("this directive may only occur in a block")
if(directive.args.size!=2 || directive.args[0].str==null || directive.args[1].str==null) if(directive.args.size!=1 || directive.args[0].str==null)
err("invalid asminclude directive, expected arguments: \"filename\", \"scopelabel\"") err("invalid asminclude directive, expected argument: \"filename\"")
checkFileExists(directive, directive.args[0].str!!) checkFileExists(directive, directive.args[0].str!!)
} }
"%asmbinary" -> { "%asmbinary" -> {

View File

@ -1236,12 +1236,7 @@ $repeatLabel lda $counterVar
when(stmt.directive) { when(stmt.directive) {
"%asminclude" -> { "%asminclude" -> {
val sourcecode = loadAsmIncludeFile(stmt.args[0].str!!, stmt.definingModule().source) val sourcecode = loadAsmIncludeFile(stmt.args[0].str!!, stmt.definingModule().source)
val scopeprefix = stmt.args[1].str ?: ""
if(scopeprefix.isNotBlank())
out("$scopeprefix\t.proc")
assemblyLines.add(sourcecode.trimEnd().trimStart('\n')) assemblyLines.add(sourcecode.trimEnd().trimStart('\n'))
if(scopeprefix.isNotBlank())
out(" .pend\n")
} }
"%asmbinary" -> { "%asmbinary" -> {
val offset = if(stmt.args.size>1) ", ${stmt.args[1].int}" else "" val offset = if(stmt.args.size>1) ", ${stmt.args[1].int}" else ""

View File

@ -142,15 +142,15 @@ Directives
The optional offset and length can be used to select a particular piece of the file. The optional offset and length can be used to select a particular piece of the file.
The file is located relative to the current working directory! The file is located relative to the current working directory!
.. data:: %asminclude "<filename>", "scopelabel" .. data:: %asminclude "<filename>"
Level: block. Level: block.
This directive can only be used inside a block. This directive can only be used inside a block.
The assembler will include the file as raw assembly source text at this point, The assembler will include the file as raw assembly source text at this point,
prog8 will not process this at all, with one exception: the labels. prog8 will not process this at all. Symbols defined in the included assembly can not be referenced
The scopelabel argument will be used as a prefix to access the labels from the included source code, from prog8 code. However they can be referenced from other assembly code if properly prefixed.
otherwise you would risk symbol redefinitions or duplications. Be careful: you risk symbol redefinitions or duplications if you include a piece of
If you know what you are doing you can leave it as an empty string to not have a scope prefix. assembly into a prog8 block that already defines symbols itself.
The compiler first looks for the file relative to the same directory as the module containing this statement is in, The compiler first looks for the file relative to the same directory as the module containing this statement is in,
if the file can't be found there it is searched relative to the current directory. if the file can't be found there it is searched relative to the current directory.

View File

@ -8,7 +8,7 @@ TODO
StatementOptimizer line 60: only optimize when it's a known constant literal StatementOptimizer line 60: only optimize when it's a known constant literal
IMPROVE DOCUMENTATION ABOUT STRINGS AND DEDUP and (NON)IMMUTABILITY. IMPROVE DOCUMENTATION ABOUT STRINGS AND DEDUP and (NON)IMMUTABILITY.
- test all examples before release of the new version - test all examples (including imgviewer, assembler and petaxian) before release of the new version
- simplify cx16.joystick_get2() once this cx16 rom issue is resolved: https://github.com/commanderx16/x16-rom/issues/203 - simplify cx16.joystick_get2() once this cx16 rom issue is resolved: https://github.com/commanderx16/x16-rom/issues/203
- c64: make the graphics.BITMAP_ADDRESS configurable (VIC banking) - c64: make the graphics.BITMAP_ADDRESS configurable (VIC banking)

View File

@ -1,24 +1,30 @@
%import textio ; txt.* %import textio ; txt.*
%zeropage basicsafe %zeropage basicsafe
main { main {
sub start() { sub start() {
txt.print("a")
txt.print("a") str string1 = "stringvalue"
txt.print("bb") str string2 = "stringvalue"
txt.print("bb") str string3 = "stringvalue"
txt.print("\n")
txt.print("\n\n") txt.print("a")
; txt.print("hello\n") txt.print("a")
; txt.print("hello\n") txt.print("bb")
; txt.print("hello\n") txt.print("bb")
; txt.print("hello\n") txt.print("\n")
; txt.print("hello22\n") txt.print("\n\n")
; txt.print("hello22\n") txt.print(string1)
; txt.print("hello22\n") txt.nl()
; txt.print("hello22\n") txt.print(string2)
; txt.print("hello666\n") txt.nl()
; txt.print("hello666\n") txt.print(string3)
; txt.print("hello666\n") txt.nl()
; txt.print("hello666\n") txt.print("hello\n")
} txt.print("hello\n")
txt.print("hello\n")
txt.print("bye\n")
txt.print("bye\n")
txt.print("bye\n")
}
} }