vm assembler now understands simple indexed addresses (symbol+number)

This commit is contained in:
Irmen de Jong 2022-09-18 02:07:39 +02:00
parent 3091e3a1c8
commit c8f3bfa726
2 changed files with 10 additions and 2 deletions

View File

@ -3,9 +3,9 @@ TODO
For next release
^^^^^^^^^^^^^^^^
- IR/VM: add address calculation for simple addition: conv.string_out+42
- IR/VM: add proper memory mapped variables support - replace the symbol by the memory address in the IR code.
- IR/VM: check that the above works ok now with the cx16 virtual registers.
- IR/VM: actually support the physical cpu registers and status flags in the STORECPU and LOADCPU opcodes.
- IR/VM: add proper memory slabs support
- IR/VM: improve unit tests

View File

@ -247,7 +247,15 @@ class Assembler {
for((line, label) in placeholders) {
val replacement = labels[label]
if(replacement==null) {
println("TODO: find address of symbol $label") // TODO
// it could be an address + index: symbol+42
if('+' in label) {
val (symbol, indexStr) = label.split('+')
val index = indexStr.toInt()
val address = labels.getValue(symbol) + index
program[line] = program[line].copy(value = address)
} else {
throw IllegalArgumentException("placeholder not found in labels: $label")
}
} else {
program[line] = program[line].copy(value = replacement)
}