Hello again,
I'm trying to create a template that substitutes a proc in a loop, so I can
create the same proc with minor variations.
This is the relevant snippet:
const erroringVectors = [8, 10, 11, 12, 13, 14, 17, 21, 29, 30]
var interruptProcedures: array[32, uint64]
template interproc(interruptVector, wrapper) =
proc vectorPusher() {.exportc, gensym, asmNoStackFrame.} =
asm """
pushq `interruptVector`
jmp `wrapper`
"""
interruptProcedures[`interruptVector`] = cast[uint64](vectorPusher)
for iv in 0..<32:
var wrapperProcName: string = if iv in erroringVectors:
"errorInterruptWrapper" else: "genericInterruptWrapper"
interproc(iv, wrapperProcName)
Run
I have two issues:
1. I can't figure out how to give the vectorPusher proc a different name each
iteration.
2. I can't figure out how to include the value of `interruptVector` and
`wrapper` in the asm.
With regards to 1), if I use gensym on the proc my compiler screams, and if I
try to define it as a var like so:
template interproc(interruptVector, name, wrapper) =
proc `name`() {.exportc, asmNoStackFrame.} =
....
for iv in 0..<32:
var wrapperProcName: string = if iv in erroringVectors:
"errorInterruptWrapper" else: "genericInterruptWrapper"
var procname: string = "vectorPusher" & $iv
interproc(iv, procname, wrapperProcName)
Run
I get an error at this line `proc `name`() {.exportc, asmNoStackFrame.} =`
telling me `procname` was already defined at this line: `var procname: string =
"vectorPusher" & $iv` which is very odd.
I would be grateful for any help.