mirror of
https://github.com/irmen/prog8.git
synced 2024-12-23 09:32:43 +00:00
taking the address of a romsub is now the constant value of said romsub's declared address
This commit is contained in:
parent
a064ade1e0
commit
a6107fcfdf
@ -419,25 +419,31 @@ data class AddressOf(var identifier: IdentifierReference, var arrayIndex: ArrayI
|
||||
|
||||
override fun copy() = AddressOf(identifier.copy(), arrayIndex?.copy(), position)
|
||||
override fun constValue(program: Program): NumericLiteral? {
|
||||
val target = this.identifier.targetStatement(program) as? VarDecl
|
||||
if(target?.type==VarDeclType.MEMORY || target?.type==VarDeclType.CONST) {
|
||||
var address = target.value?.constValue(program)?.number
|
||||
if(address!=null) {
|
||||
if(arrayIndex!=null) {
|
||||
val index = arrayIndex?.constIndex()
|
||||
if (index != null) {
|
||||
address += when (target.datatype) {
|
||||
DataType.UWORD -> index
|
||||
in ArrayDatatypes -> program.memsizer.memorySize(target.datatype, index)
|
||||
else -> throw FatalAstException("need array or uword ptr")
|
||||
}
|
||||
val target = this.identifier.targetStatement(program)
|
||||
val targetVar = target as? VarDecl
|
||||
if(targetVar!=null) {
|
||||
if (targetVar.type == VarDeclType.MEMORY || targetVar.type == VarDeclType.CONST) {
|
||||
var address = targetVar.value?.constValue(program)?.number
|
||||
if (address != null) {
|
||||
if (arrayIndex != null) {
|
||||
val index = arrayIndex?.constIndex()
|
||||
if (index != null) {
|
||||
address += when (targetVar.datatype) {
|
||||
DataType.UWORD -> index
|
||||
in ArrayDatatypes -> program.memsizer.memorySize(targetVar.datatype, index)
|
||||
else -> throw FatalAstException("need array or uword ptr")
|
||||
}
|
||||
} else
|
||||
return null
|
||||
}
|
||||
else
|
||||
return null
|
||||
return NumericLiteral(DataType.UWORD, address, position)
|
||||
}
|
||||
return NumericLiteral(DataType.UWORD, address, position)
|
||||
}
|
||||
}
|
||||
val targetSub = target as? Subroutine
|
||||
if(targetSub?.asmAddress!=null) {
|
||||
return NumericLiteral(DataType.UWORD, targetSub.asmAddress.toDouble(), position)
|
||||
}
|
||||
return null
|
||||
}
|
||||
override fun referencesIdentifier(nameInSource: List<String>) = identifier.nameInSource==nameInSource || arrayIndex?.referencesIdentifier(nameInSource)==true
|
||||
|
@ -5,8 +5,7 @@ Regenerate skeleton doc files.
|
||||
|
||||
"invalid number of arguments" -> print the list of missing arguments
|
||||
|
||||
callfar() should allow setting an argument in the X register as well? + similar optimizations that call() got.
|
||||
|
||||
callfar() should allow setting an argument in the X register as well?
|
||||
|
||||
Add a new SublimeText syntax file for prog8, and also install this for bat: https://github.com/sharkdp/bat?tab=readme-ov-file#adding-new-syntaxes--language-definitions
|
||||
|
||||
|
@ -8,35 +8,41 @@
|
||||
main {
|
||||
sub start() {
|
||||
test_stack.test()
|
||||
example(function1, 42)
|
||||
example(function1, 99)
|
||||
example(function2, 42)
|
||||
example(function2, 99)
|
||||
|
||||
txt.print_uwhex(cbm.CHROUT, true)
|
||||
txt.print_uwhex(&cbm.CHROUT, true)
|
||||
txt.nl()
|
||||
|
||||
cx16.r0 = &function1
|
||||
callfar(0, $ffd2, $0031)
|
||||
callfar(0, cbm.CHROUT, $000d)
|
||||
callfar(0, function1, $6660)
|
||||
callfar(0, cx16.r0, $ffff)
|
||||
cx16.r0 -=10
|
||||
callfar(0, cx16.r0+10, $eeee)
|
||||
|
||||
cx16.r0 = &function2
|
||||
callfar(0, $ffd2, $0032)
|
||||
callfar(0, cbm.CHROUT, $000d)
|
||||
callfar(0, function2, $6660)
|
||||
callfar(0, cx16.r0, $ffff)
|
||||
cx16.r0 -=10
|
||||
callfar(0, cx16.r0+10, $eeee)
|
||||
|
||||
test_stack.test()
|
||||
cx16.r0++
|
||||
|
||||
sub function1(ubyte arg) {
|
||||
sub function1(uword arg) {
|
||||
txt.print("function 1 arg=")
|
||||
txt.print_ub(arg)
|
||||
txt.print_uwhex(arg, false)
|
||||
txt.nl()
|
||||
}
|
||||
|
||||
sub function2(ubyte arg) {
|
||||
sub function2(uword arg) {
|
||||
txt.print("function 2 arg=")
|
||||
txt.print_ub(arg)
|
||||
txt.print_uwhex(arg, false)
|
||||
txt.nl()
|
||||
}
|
||||
|
||||
sub example(uword function, ubyte value) {
|
||||
|
||||
%asm {{
|
||||
lda p8v_value
|
||||
}}
|
||||
|
||||
call(function)
|
||||
cx16.r1 = function+10
|
||||
call(cx16.r1-10)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user