My next experiment is to use tables with procs, which gives useful compiler 
warnings when our procs are not GC-safe.
    
    
    import tables
    
    # These three lines give GC-safe warnings when "gprocs[1] = ptest" runs.
    # var gprocs*: Table[int, proc (test: Test): bool]
    # gprocs = initTable[int, proc (test: Test): bool](initialSize = 16)
    # gprocs[1] = ptest
    
    # If we use "gcsafe" and "locks" pragmas, and remove the testSeq line
    # from ptest(), there aren't any GC-safe warnings.
    var gprocs: Table[int, proc (test: Test): bool{.gcsafe, locks: 0.}]
    gprocs = initTable[int, proc (test: Test): bool{.gcsafe, locks: 
0.}](initialSize = 16)
    gprocs[1] = ptest
    echo "CALLING PTEST (GCSAFE): "; discard gprocs[1](testing123)
    

I get good compiler warnings when using tables, but as I'm doing this all 
within AST meta-programming, I'd like to keep things as simple as possible and 
keep using seq of tuples-of-procs. I am hoping the compiler warnings improve 
when using tuples-of-procs.

Is there really no way to use meta-programming proc calls with non-GC-safe 
procs? I just need a way to make procs first-class citizens and pass them 
around easily, without the requirement that they're GC-safe. 

Reply via email to