mirror of
https://github.com/irmen/prog8.git
synced 2025-01-11 13:29:45 +00:00
fix that memory("a b c", ...) produces invalid symbol
This commit is contained in:
parent
a23281afab
commit
7bc75fd220
@ -418,6 +418,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
|||||||
throw AssemblyError("should not discard result of memory allocation at $fcall")
|
throw AssemblyError("should not discard result of memory allocation at $fcall")
|
||||||
val nameRef = fcall.args[0] as IdentifierReference
|
val nameRef = fcall.args[0] as IdentifierReference
|
||||||
val name = (nameRef.targetVarDecl(program)!!.value as StringLiteralValue).value
|
val name = (nameRef.targetVarDecl(program)!!.value as StringLiteralValue).value
|
||||||
|
require(name.all { it.isLetterOrDigit() || it=='_' }) {"memory name should be a valid symbol name"}
|
||||||
val size = (fcall.args[1] as NumericLiteralValue).number.toUInt()
|
val size = (fcall.args[1] as NumericLiteralValue).number.toUInt()
|
||||||
|
|
||||||
val existingSize = asmgen.slabs[name]
|
val existingSize = asmgen.slabs[name]
|
||||||
|
@ -145,6 +145,19 @@ internal class AstIdentifiersChecker(private val errors: IErrorReporter,
|
|||||||
val pos = (if(call.args.any()) call.args[0] else (call as Node)).position
|
val pos = (if(call.args.any()) call.args[0] else (call as Node)).position
|
||||||
errors.err("invalid number of arguments", pos)
|
errors.err("invalid number of arguments", pos)
|
||||||
}
|
}
|
||||||
|
if(func.name=="memory") {
|
||||||
|
val name = call.args[0] as? StringLiteralValue
|
||||||
|
if(name!=null) {
|
||||||
|
val processed = name.value.map {
|
||||||
|
if(it.isLetterOrDigit())
|
||||||
|
it
|
||||||
|
else
|
||||||
|
'_'
|
||||||
|
}.joinToString("")
|
||||||
|
call.args[0] = StringLiteralValue(processed, false, name.position)
|
||||||
|
call.args[0].linkParents(call as Node)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
is Label -> {
|
is Label -> {
|
||||||
if(call.args.isNotEmpty()) {
|
if(call.args.isNotEmpty()) {
|
||||||
|
@ -16,9 +16,11 @@ import prog8.compiler.printProgram
|
|||||||
import prog8.codegen.target.C64Target
|
import prog8.codegen.target.C64Target
|
||||||
import prog8.compilerinterface.isIOAddress
|
import prog8.compilerinterface.isIOAddress
|
||||||
import prog8.parser.SourceCode
|
import prog8.parser.SourceCode
|
||||||
|
import prog8tests.helpers.*
|
||||||
import prog8tests.helpers.DummyFunctions
|
import prog8tests.helpers.DummyFunctions
|
||||||
import prog8tests.helpers.DummyMemsizer
|
import prog8tests.helpers.DummyMemsizer
|
||||||
import prog8tests.helpers.DummyStringEncoder
|
import prog8tests.helpers.DummyStringEncoder
|
||||||
|
import prog8tests.helpers.compileText
|
||||||
|
|
||||||
|
|
||||||
class TestMemory: FunSpec({
|
class TestMemory: FunSpec({
|
||||||
@ -220,4 +222,15 @@ class TestMemory: FunSpec({
|
|||||||
.addModule(module)
|
.addModule(module)
|
||||||
target.isIOAddress(C64Target.machine) shouldBe true
|
target.isIOAddress(C64Target.machine) shouldBe true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
test("memory() with spaces in name works") {
|
||||||
|
val result = compileText(C64Target, false, """
|
||||||
|
main {
|
||||||
|
sub start() {
|
||||||
|
uword @shared mem = memory("a b c", 100)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""", writeAssembly = true).assertSuccess()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
@ -3,6 +3,8 @@ TODO
|
|||||||
|
|
||||||
For next compiler release (7.6)
|
For next compiler release (7.6)
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
- fix that memory("name", ...) allocates a STR variable with contents "name" in the assembly source
|
||||||
|
- make it possible to inline non-asmsub routines that just contain a single statement (return, functioncall, assignment)
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
@ -21,6 +23,7 @@ Blocked by an official Commander-x16 r39 release
|
|||||||
|
|
||||||
Future
|
Future
|
||||||
^^^^^^
|
^^^^^^
|
||||||
|
- add pipe operator ``|>`` ?
|
||||||
- make it possible to use cpu opcodes such as 'nop' as variable names by prefixing all asm vars with something such as ``v_``
|
- make it possible to use cpu opcodes such as 'nop' as variable names by prefixing all asm vars with something such as ``v_``
|
||||||
then we can get rid of the instruction lists in the machinedefinitions as well?
|
then we can get rid of the instruction lists in the machinedefinitions as well?
|
||||||
- fix the asm-labels problem (github issue #62)
|
- fix the asm-labels problem (github issue #62)
|
||||||
|
@ -1,57 +1,13 @@
|
|||||||
%import textio
|
%import textio
|
||||||
%import floats
|
|
||||||
%zeropage basicsafe
|
%zeropage basicsafe
|
||||||
%option no_sysinit
|
|
||||||
|
|
||||||
main {
|
main {
|
||||||
ubyte bb = 1
|
uword buffer = memory("the quick brown fox jumps over the lazy dog", 2000)
|
||||||
uword ww = 1
|
uword buffer2 = memory("the quick brown fox jumps over the lazy dog", 2000)
|
||||||
float ff = 1.111
|
|
||||||
str derp = "zzzz"
|
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
func()
|
txt.print_uwhex(buffer, true)
|
||||||
txt.print(derp)
|
txt.print_uwhex(buffer2, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
sub func() {
|
|
||||||
ubyte fbb = 1
|
|
||||||
uword fww = 1
|
|
||||||
float fff = 1.111
|
|
||||||
|
|
||||||
txt.print_ub(fbb)
|
|
||||||
txt.spc()
|
|
||||||
txt.print_uw(fww)
|
|
||||||
txt.spc()
|
|
||||||
floats.print_f(fff)
|
|
||||||
txt.nl()
|
|
||||||
txt.print_ub(bb)
|
|
||||||
txt.spc()
|
|
||||||
txt.print_uw(ww)
|
|
||||||
txt.spc()
|
|
||||||
floats.print_f(ff)
|
|
||||||
txt.nl()
|
|
||||||
txt.print_ub(block2.bb)
|
|
||||||
txt.spc()
|
|
||||||
txt.print_uw(block2.ww)
|
|
||||||
txt.spc()
|
|
||||||
floats.print_f(block2.ff)
|
|
||||||
txt.nl()
|
|
||||||
|
|
||||||
fbb++
|
|
||||||
fww++
|
|
||||||
fff += 1.1
|
|
||||||
bb++
|
|
||||||
ww++
|
|
||||||
ff += 1.1
|
|
||||||
block2.bb++
|
|
||||||
block2.ww++
|
|
||||||
block2.ff += 1.1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
block2 {
|
|
||||||
ubyte bb = 1
|
|
||||||
uword ww = 1
|
|
||||||
float ff = 1.111
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user