You cannot inspect the `type` signature of an `untyped` node. And yes 
concretely that is because the ident is not bound.

Fix:
    
    
    import macros
    
    macro getTheType*(stmts: typed) =
      echo stmts.treerepr
      echo stmts[0][0].getType().repr
    
    proc f(x: string): int = 2
    
    getTheType:
      proc myProc(s: string): int =
        discard
    
    
    Run

will return proc[int, string] (the first type is the one of the return value or 
an empty node).

* * *

If you need to work with proc types in a typed context, you will have to deal 
with symbol overloads (nnkClosedSymChoice). In that case this might help: 
[https://github.com/numforge/laser/blob/d1e6ae61/laser/lux_compiler/frontend/lux_sigmatch.nim](https://github.com/numforge/laser/blob/d1e6ae61/laser/lux_compiler/frontend/lux_sigmatch.nim)

This allows matching type-erased types with a concrete one in my 
linear-algebra-compiler-as-macro project, for instance: 
[https://github.com/numforge/laser/blob/d1e6ae61/laser/lux_compiler/lux_dsl.nim#L43-L58](https://github.com/numforge/laser/blob/d1e6ae61/laser/lux_compiler/lux_dsl.nim#L43-L58)
    
    
    proc foobar(a, b, c: Fn): Fn =
        
        # Iteration Domain
        var i, j: Iter
        
        # Avoid in-place update of implicit result ref address
        # https://github.com/nim-lang/Nim/issues/11637
        var bar: Fn
        
        bar[i, j] = a[i, j] + b[i, j] + c[i, j]
        
        # Update result
        result = bar
    
    
    Run

with `Fn` being concretized into `Tensor[float32]`
    
    
    generate foobar:
        proc foobar(a: Tensor[float32], b, c: Tensor[float32]): Tensor[float32]
    
    
    
    Run

Reply via email to