Assembler improvement: Calculating labels
Currently, in the Python-based Boneless assembler, when specifying the name of a label in an instruction, e.g. MOVR(R3, "label"), the instruction operand is substituted by the PC-relative address of the label. This is the only way to use a label.
I propose a way to apply arbitrary calculations to labels before their values get substituted. Instead of specifying "label", the user could specify LabelCalc(lambda pc, lbl: label, "label") to the same effect.
By allowing an arbitrary lambda expression for the label, many other possibilities could be expressed. For example, LabelCalc(lambda pc, lbl: label-pc, "label") specifies the absolute location of "label". If there was an array with labels at the start and end, one could specify CMPI(R3, LabelCalc(lambda pc, s, e: e-s, "data_start", "data_end")) to test if R3 has reached the number of items in the array.
Based on my understanding of the assembler, this lambda expression would allow arbitrary calculations without changing its framework. However, there may be problems converging if the user specified a nonlinear calculation. In that case, there may need to be a check to fail assembly if there is no convergence after a reasonable number of iterations.
By allowing an arbitrary lambda expression for the label
But that adds a disparity with the text assembler, which doesn't let you do that. And as you correctly note, makes convergence not always possible.
I think there should just be a way to compute using labels, like L("foo") - 1 or L("bar") - L("foo").