github.com/gotranspile/cxgo@v0.3.7/libs/setjmp.go (about)

     1  package libs
     2  
     3  import "github.com/gotranspile/cxgo/types"
     4  
     5  const (
     6  	setjmpH = "setjmp.h"
     7  )
     8  
     9  func init() {
    10  	RegisterLibrary(setjmpH, func(c *Env) *Library {
    11  		gint := c.Go().Int()
    12  		bufT := types.NamedTGo("jmp_buf", "libc.JumpBuf", c.MethStructT(map[string]*types.FuncType{
    13  			"SetJump":  c.FuncTT(gint),
    14  			"LongJump": c.FuncTT(nil, gint),
    15  		}))
    16  		return &Library{
    17  			Types: map[string]types.Type{
    18  				"jmp_buf": bufT,
    19  			},
    20  			Imports: map[string]string{
    21  				"libc": RuntimeLibc,
    22  			},
    23  			Header: `
    24  #include <` + BuiltinH + `>
    25  
    26  typedef struct jmp_buf {
    27  	_cxgo_go_int (*SetJump) ();
    28  	void (*LongJump) (_cxgo_go_int);
    29  } jmp_buf;
    30  
    31  #define setjmp(b) ((jmp_buf)b).SetJump()
    32  #define longjmp(b, v) ((jmp_buf)b).LongJump(v)
    33  `,
    34  		}
    35  	})
    36  }