You can check out answers for these questions yourself if you compile with 
something like `nim c -d:danger --nimcache:ccode file.nim` and then check the C 
files in the ccode folder.

For example, for:
    
    
    proc main =
      var external: string
      proc my(x: int) =
        echo x
        echo external
      
      my(5)
    
    main()
    
    
    Run

Relevant parts in the C code:
    
    
    # The environment of the closure
    struct tyObject_Env_testdotnim_main___s9aFarTYu8wC9aBkHyu9aWVqQ {
      RootObj Sup;
      NI colonstate_;
      NimStringDesc* external1;
    };
    
    # The closure struct itself that has two fields: the pointer to the closure 
itself and pointer to the environment
    # Also, the function signature is all the normal arguments of the closure, 
and then the closure environment
    typedef struct {
      N_NIMCALL_PTR(void, ClP_0) (NI x, void* ClE_0);
      void* ClE_0;
    } tyProc__SqRJqa5aOiKB4EuKlKh9asA;
    
    
    
    Run

Reply via email to