If you do `echo val.treeRepr` instead of `repr`, you get the output
    
    
    ProcDef
      Ident "f"
      Empty
      Empty
      FormalParams
        Empty
        IdentDefs
          Ident "x"
          Ident "int"
          Empty
      Pragma
        Pragma
          ExprColonExpr
            Ident "exportc"
            Ident "\"oops\""
      Empty
      StmtList
        Command
          Ident "echo"
          StrLit "hello"
    
    
    Run

Notice how there is a double `Pragma`. By calling `addPragma`, you are adding a 
node of kind `Pragma` to the pragmas.

Also, you are creating an identifier node for the value of exportc. You should 
be creating a string literal, with `newLit`.

Fixing these, you get:
    
    
    import macros, options, strformat
    
    macro exportc_pragma(prefix: string, val: untyped): untyped =
      let export_name = "oops"
      let export_pragma = newColonExpr(ident"exportc", newLit(export_name))
      val.addPragma(export_pragma)
      
      echo val.repr
      return val
    
    proc f(x: int){.exportc_pragma: "my_export_name".} =
      echo "hello"
    
    
    Run

Reply via email to