From 0416aacbbdbe89b0361130a8ef6fe017fdd197c3 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 16 May 2021 00:14:57 +0200 Subject: [PATCH] fix %asminclude by removing scopelabel argument and improving docs to remove false promise about labels --- compiler/res/prog8lib/c64/floats.p8 | 4 +- compiler/res/prog8lib/cx16/floats.p8 | 4 +- compiler/res/prog8lib/math.p8 | 2 +- compiler/res/prog8lib/prog8_lib.p8 | 4 +- .../compiler/astprocessing/AstChecker.kt | 4 +- .../compiler/target/cpu6502/codegen/AsmGen.kt | 5 -- docs/source/syntaxreference.rst | 10 ++-- docs/source/todo.rst | 2 +- examples/test.p8 | 46 +++++++++++-------- 9 files changed, 41 insertions(+), 40 deletions(-) diff --git a/compiler/res/prog8lib/c64/floats.p8 b/compiler/res/prog8lib/c64/floats.p8 index 10a730353..7d8ee5d29 100644 --- a/compiler/res/prog8lib/c64/floats.p8 +++ b/compiler/res/prog8lib/c64/floats.p8 @@ -195,7 +195,7 @@ sub print_f (float value) { }} } -%asminclude "library:c64/floats.asm", "" -%asminclude "library:c64/floats_funcs.asm", "" +%asminclude "library:c64/floats.asm" +%asminclude "library:c64/floats_funcs.asm" } diff --git a/compiler/res/prog8lib/cx16/floats.p8 b/compiler/res/prog8lib/cx16/floats.p8 index 437cee85b..9400a2af2 100644 --- a/compiler/res/prog8lib/cx16/floats.p8 +++ b/compiler/res/prog8lib/cx16/floats.p8 @@ -158,7 +158,7 @@ sub print_f (float value) { }} } -%asminclude "library:c64/floats.asm", "" -%asminclude "library:c64/floats_funcs.asm", "" +%asminclude "library:c64/floats.asm" +%asminclude "library:c64/floats_funcs.asm" } diff --git a/compiler/res/prog8lib/math.p8 b/compiler/res/prog8lib/math.p8 index ceff18d48..234079159 100644 --- a/compiler/res/prog8lib/math.p8 +++ b/compiler/res/prog8lib/math.p8 @@ -3,5 +3,5 @@ ; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0 math { - %asminclude "library:math.asm", "" + %asminclude "library:math.asm" } diff --git a/compiler/res/prog8lib/prog8_lib.p8 b/compiler/res/prog8lib/prog8_lib.p8 index dc2791485..5804022a6 100644 --- a/compiler/res/prog8lib/prog8_lib.p8 +++ b/compiler/res/prog8lib/prog8_lib.p8 @@ -3,8 +3,8 @@ ; Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0 prog8_lib { - %asminclude "library:prog8_lib.asm", "" - %asminclude "library:prog8_funcs.asm", "" + %asminclude "library:prog8_lib.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) word @zp retval_interm_w ; to store intermediary expression results for return values (hopefully allocated on ZP to reduce code size) diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index 0b56b7e52..2353a19fb 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -691,8 +691,8 @@ internal class AstChecker(private val program: Program, "%asminclude" -> { if(directive.parent !is INameScope || directive.parent is Module) err("this directive may only occur in a block") - if(directive.args.size!=2 || directive.args[0].str==null || directive.args[1].str==null) - err("invalid asminclude directive, expected arguments: \"filename\", \"scopelabel\"") + if(directive.args.size!=1 || directive.args[0].str==null) + err("invalid asminclude directive, expected argument: \"filename\"") checkFileExists(directive, directive.args[0].str!!) } "%asmbinary" -> { diff --git a/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt b/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt index 465b06403..6ef00bdba 100644 --- a/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt +++ b/compiler/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt @@ -1236,12 +1236,7 @@ $repeatLabel lda $counterVar when(stmt.directive) { "%asminclude" -> { 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')) - if(scopeprefix.isNotBlank()) - out(" .pend\n") } "%asmbinary" -> { val offset = if(stmt.args.size>1) ", ${stmt.args[1].int}" else "" diff --git a/docs/source/syntaxreference.rst b/docs/source/syntaxreference.rst index d43e8a463..930e8a998 100644 --- a/docs/source/syntaxreference.rst +++ b/docs/source/syntaxreference.rst @@ -142,15 +142,15 @@ Directives 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! -.. data:: %asminclude "", "scopelabel" +.. data:: %asminclude "" Level: block. This directive can only be used inside a block. 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. - The scopelabel argument will be used as a prefix to access the labels from the included source code, - otherwise you would risk symbol redefinitions or duplications. - If you know what you are doing you can leave it as an empty string to not have a scope prefix. + prog8 will not process this at all. Symbols defined in the included assembly can not be referenced + from prog8 code. However they can be referenced from other assembly code if properly prefixed. + Be careful: you risk symbol redefinitions or duplications if you include a piece of + 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, if the file can't be found there it is searched relative to the current directory. diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 12084c221..b613d14f0 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -8,7 +8,7 @@ TODO StatementOptimizer line 60: only optimize when it's a known constant literal 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 - c64: make the graphics.BITMAP_ADDRESS configurable (VIC banking) diff --git a/examples/test.p8 b/examples/test.p8 index 5380dba20..179697814 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,24 +1,30 @@ %import textio ; txt.* %zeropage basicsafe main { - sub start() { - txt.print("a") - txt.print("a") - txt.print("bb") - txt.print("bb") - txt.print("\n") - txt.print("\n\n") -; txt.print("hello\n") -; txt.print("hello\n") -; txt.print("hello\n") -; txt.print("hello\n") -; txt.print("hello22\n") -; txt.print("hello22\n") -; txt.print("hello22\n") -; txt.print("hello22\n") -; txt.print("hello666\n") -; txt.print("hello666\n") -; txt.print("hello666\n") -; txt.print("hello666\n") - } + sub start() { + + str string1 = "stringvalue" + str string2 = "stringvalue" + str string3 = "stringvalue" + + txt.print("a") + txt.print("a") + txt.print("bb") + txt.print("bb") + txt.print("\n") + txt.print("\n\n") + txt.print(string1) + txt.nl() + txt.print(string2) + txt.nl() + txt.print(string3) + txt.nl() + txt.print("hello\n") + txt.print("hello\n") + txt.print("hello\n") + txt.print("bye\n") + txt.print("bye\n") + txt.print("bye\n") + + } }