> Compiler extensions / module-range macros

I think Nim is almost there. One thing left is to implement pragma push for 
templates/macros. 
    
    
    import myModuleThatChangesEverything
    {.push myPragmaThatChangesEverything.}
    # rest of the code
    {.pop.} # is it needed?
    

> Type invariant inheritance

I would be really glad for type ct callbacks, that evaluate upon type use. 
    
    
    type MyMagicType = ref object of RootObj
    
    macro `=onInherit`(t: typedesc[MyMagicType], n: untyped): untyped 
{.compileTime.} =
      # do smth with n
      result = n
    
    macro `=onUsedAsArgument`(t: typedesc[MyMagicType], n: untyped): untyped 
{.compileTime.} =
      # do smth with n
      result = n
    
    # Further usage
    type MyInheritedType = ref object of MyMagicType
      a: int
    # This actually gets rewritten to:
    # `=onInherit`(MyMagicType):
    #   type MyInheritedType = ref object of MyMagicType
    #      a: int
    
    # Some routine:
    proc someProcThatUsesMyType(a: int, v: MyMagicType) =
      discard
    
    # This actually gets rewritten to:
    # `= onUsedAsArgument `(MyMagicType):
    #   proc someProcThatUsesMyType(a: int, v: MyMagicType) =
    #     discard
    

Further on the `onUsedAsArgument` can insert invariant calls to the proc. The 
`onInherit` can implement some code for the inherited type, or register it in a 
factory or whatever.

Reply via email to