diff --git a/libs/arpa_inet.go b/libs/arpa_inet.go index da9ed6e..a7155f8 100644 --- a/libs/arpa_inet.go +++ b/libs/arpa_inet.go @@ -1,8 +1,6 @@ package libs import ( - _ "embed" - "github.com/gotranspile/cxgo/runtime/cnet" "github.com/gotranspile/cxgo/types" ) @@ -13,9 +11,6 @@ const ( arpaInetH = "arpa/inet.h" ) -//go:embed includes/arpa_inet.h -var harpaInet string - func init() { RegisterLibrary(arpaInetH, func(c *Env) *Library { inAddrT := types.NamedTGo("in_addr_t", "cnet.Addr", types.UintT(8)) @@ -45,7 +40,6 @@ func init() { "inet_ntop": c.NewIdent("inet_ntop", "cnet.Ntop", cnet.Ntop, c.FuncTT(strT, types.IntT(4), c.PtrT(nil), strT, sockLenT)), "inet_pton": c.NewIdent("inet_pton", "cnet.Pton", cnet.Pton, c.FuncTT(strT, types.IntT(4), strT, c.PtrT(nil))), }, - Header: harpaInet, } }) } diff --git a/libs/ctype.go b/libs/ctype.go index 8187f52..71f7f79 100644 --- a/libs/ctype.go +++ b/libs/ctype.go @@ -39,24 +39,6 @@ func init() { "tolower": c.NewIdent("tolower", "unicode.ToLower", unicode.ToLower, toT), "toupper": c.NewIdent("toupper", "unicode.ToUpper", unicode.ToUpper, toT), }, - // TODO - Header: ` -_cxgo_go_bool isalnum(_cxgo_go_rune); -_cxgo_go_bool isalpha(_cxgo_go_rune); -_cxgo_go_bool isascii(_cxgo_go_rune); -_cxgo_go_bool iscntrl(_cxgo_go_rune); -_cxgo_go_bool isdigit(_cxgo_go_rune); -_cxgo_go_bool isgraph(_cxgo_go_rune); -_cxgo_go_bool islower(_cxgo_go_rune); -_cxgo_go_bool isprint(_cxgo_go_rune); -_cxgo_go_bool ispunct(_cxgo_go_rune); -_cxgo_go_bool isspace(_cxgo_go_rune); -_cxgo_go_bool isupper(_cxgo_go_rune); -_cxgo_go_bool isxdigit(_cxgo_go_rune); -_cxgo_go_rune toascii(_cxgo_go_rune); -_cxgo_go_rune tolower(_cxgo_go_rune); -_cxgo_go_rune toupper(_cxgo_go_rune); -`, } }) } diff --git a/libs/dlfcn.go b/libs/dlfcn.go index 94b45f5..8681456 100644 --- a/libs/dlfcn.go +++ b/libs/dlfcn.go @@ -31,8 +31,6 @@ func init() { "dlopen": RuntimePrefix + "dlopen", }, Header: ` -#include <` + BuiltinH + `> - const int RTLD_LAZY = 1; const int RTLD_NOW = 2; const int RTLD_GLOBAL = 4; diff --git a/libs/errno.go b/libs/errno.go index a2aadf5..0707749 100644 --- a/libs/errno.go +++ b/libs/errno.go @@ -22,11 +22,8 @@ func init() { }) } - func errnoHeader() string { - lines := []string{ - "#include <" + BuiltinH + ">", "_cxgo_go_int errno = 0;", "char* strerror (_cxgo_go_int errnum);", } diff --git a/libs/fenv.go b/libs/fenv.go index bf4cb2e..0e2847d 100644 --- a/libs/fenv.go +++ b/libs/fenv.go @@ -21,12 +21,6 @@ func init() { "FE_TOWARDZERO": c.NewIdent("FE_TOWARDZERO", "cmath.TowardZero", cmath.TowardZero, gint), "fesetround": c.NewIdent("fesetround", "cmath.FSetRound", cmath.FSetRound, c.FuncTT(intT, intT)), }, - // TODO - Header: ` -#include <` + BuiltinH + `> -const _cxgo_go_int FE_TOWARDZERO = 1; -_cxgo_sint32 fesetround(_cxgo_sint32 round); -`, } }) } diff --git a/libs/glob.go b/libs/glob.go index c9c8118..f8aba78 100644 --- a/libs/glob.go +++ b/libs/glob.go @@ -1,8 +1,6 @@ package libs import ( - _ "embed" - "github.com/gotranspile/cxgo/runtime/stdio" "github.com/gotranspile/cxgo/types" ) @@ -11,9 +9,6 @@ const ( globH = "glob.h" ) -//go:embed includes/glob.h -var hglob string - func init() { RegisterLibrary(globH, func(c *Env) *Library { gint := c.Go().Int() @@ -38,8 +33,6 @@ func init() { Idents: map[string]*types.Ident{ "GLOB_NOESCAPE": c.NewIdent("GLOB_NOESCAPE", "stdio.GlobNoEscape", stdio.GlobNoEscape, gint), }, - // TODO - Header: hglob, } }) } diff --git a/libs/includes/embed/AL/al.h b/libs/includes/AL/al.h similarity index 100% rename from libs/includes/embed/AL/al.h rename to libs/includes/AL/al.h diff --git a/libs/includes/embed/AL/alc.h b/libs/includes/AL/alc.h similarity index 100% rename from libs/includes/embed/AL/alc.h rename to libs/includes/AL/alc.h diff --git a/libs/includes/embed/GL/gl.h b/libs/includes/GL/gl.h similarity index 100% rename from libs/includes/embed/GL/gl.h rename to libs/includes/GL/gl.h diff --git a/libs/includes/SDL2/SDL.h b/libs/includes/SDL2/SDL.h new file mode 100644 index 0000000..68029b9 --- /dev/null +++ b/libs/includes/SDL2/SDL.h @@ -0,0 +1,230 @@ +#define Uint32 _cxgo_uint32 +#define Uint16 _cxgo_uint16 +#define Uint8 _cxgo_uint8 +#define Sint32 _cxgo_sint32 +#define Sint16 _cxgo_sint16 +#define Sint8 _cxgo_sint8 +#define SDL_bool _cxgo_go_bool +typedef Sint32 SDL_FingerID; +typedef Sint32 SDL_Scancode; +typedef Sint32 SDL_Keymod; +typedef Sint32 SDL_BlendMode; +typedef Sint32 SDL_TimerID; + + +#define SDL_TRUE 1 +#define SDL_FALSE 0 +const Sint32 SDL_PIXELFORMAT_RGBA5551 = 1; +const Sint32 SDL_PIXELFORMAT_RGB565 = 2; +const Sint32 SDL_PIXELFORMAT_RGB555 = 3; + +const Sint32 SDL_RENDERER_ACCELERATED = 1; +const Sint32 SDL_RENDERER_PRESENTVSYNC = 2; + +#define SDL_NUM_SCANCODES 512 + +typedef struct{ + Sint16 x, y; + Uint16 w, h; +} SDL_Rect; + +#define SDL_TEXTEDITING 770 +#define SDL_TEXTINPUT 771 +#define SDL_KEYDOWN 768 +#define SDL_KEYUP 769 +#define SDL_MOUSEBUTTONDOWN 1025 +#define SDL_MOUSEBUTTONUP 1026 +#define SDL_MOUSEMOTION 1024 +#define SDL_MOUSEWHEEL 1027 +#define SDL_WINDOWEVENT 512 + +#define SDL_WINDOWEVENT_FOCUS_LOST 13 +#define SDL_WINDOWEVENT_FOCUS_GAINED 12 + +#define SDL_BUTTON_LEFT 1 +#define SDL_BUTTON_RIGHT 3 +#define SDL_BUTTON_MIDDLE 2 + +const Sint32 SDL_PRESSED = 1; + +const Sint32 SDL_SCANCODE_SPACE = 1; +const Sint32 KMOD_LSHIFT = 1; +const Sint32 KMOD_RSHIFT = 2; +const Sint32 KMOD_RALT = 3; + +const Uint32 SDL_INIT_VIDEO = 1; +const Uint32 SDL_INIT_TIMER = 2; +const Sint32 SDL_WINDOWPOS_UNDEFINED = -1; +const Sint32 SDL_WINDOWPOS_CENTERED = -2; +const Uint32 SDL_WINDOW_RESIZABLE = 1; +const Uint32 SDL_WINDOW_OPENGL = 2; +const SDL_BlendMode SDL_BLENDMODE_NONE = 1; + +typedef struct{ + SDL_Scancode scancode; +} SDL_Keysym; + +typedef struct{ + SDL_Keysym keysym; + Uint8 state; +} SDL_KeyboardEvent; + +typedef struct{ + Uint8 button; + Uint8 state; + Sint32 x,y; +} SDL_MouseButtonEvent; + +typedef struct{ + Sint32 x, y; + Sint32 xrel, yrel; +} SDL_MouseMotionEvent; + +typedef struct{ + Sint32 x, y; +} SDL_MouseWheelEvent; + +typedef struct{} SDL_TouchFingerEvent; + +typedef struct{ + char text[32]; +} SDL_TextEditingEvent; + +typedef struct{ + char text[32]; +} SDL_TextInputEvent; + +typedef struct{ + Uint8 event; +} SDL_WindowEvent; + +typedef struct{ + int type; + SDL_TextEditingEvent edit; + SDL_TextInputEvent text; + SDL_KeyboardEvent key; + SDL_MouseButtonEvent button; + SDL_MouseMotionEvent motion; + SDL_MouseWheelEvent wheel; + SDL_WindowEvent window; +} SDL_Event; + +const Uint32 SDL_WINDOW_FULLSCREEN_DESKTOP = 0; + +typedef struct SDL_GLContext {} SDL_GLContext; + +typedef struct SDL_Window { + Sint32 (*SetFullscreen)(Uint32 flags); + void (*GetSize)(Sint32 *w, Sint32 *h); + void (*GetPosition)(Sint32 *x, Sint32 *y); + void (*SetSize)(Sint32 w, Sint32 h); + void (*SetPosition)(Sint32 x, Sint32 y); + void (*Minimize)(void); + void (*Restore)(void); + void (*SetGrab)(SDL_bool); + void (*SetResizable)(SDL_bool); + void (*SetBordered)(SDL_bool); + void (*SetTitle)(const char*); + Sint32 (*GetDisplayIndex)(void); + void (*GLGetDrawableSize)(Sint32* w, Sint32* h); + void (*GLSwapWindow)(void); + SDL_GLContext (*GLCreateContext)(void); +} SDL_Window; + +const char* SDL_GetError(void); + +Uint32 SDL_GetTicks(void); +SDL_Window* SDL_CreateWindow(const char* title, Sint32 x, Sint32 y, Sint32 w, Sint32 h, Uint32 flags); +#define SDL_SetWindowFullscreen(win, flags) ((SDL_Window*)win)->SetFullscreen(flags) +#define SDL_SetWindowSize(win, w, h) ((SDL_Window*)win)->SetSize(w, h) +#define SDL_SetWindowPosition(win, x, y) ((SDL_Window*)win)->SetPosition(x, y) +#define SDL_SetWindowGrab(win, v) ((SDL_Window*)win)->SetGrab(v) +#define SDL_SetWindowTitle(win, v) ((SDL_Window*)win)->SetTitle(v) +#define SDL_MinimizeWindow(win) ((SDL_Window*)win)->Minimize() +#define SDL_RestoreWindow(win) ((SDL_Window*)win)->Restore() +#define SDL_GetWindowDisplayIndex(win) ((SDL_Window*)win)->GetDisplayIndex() +#define SDL_SetWindowResizable(win, v) ((SDL_Window*)win)->SetResizable(v) +#define SDL_SetWindowBordered(win, v) ((SDL_Window*)win)->SetBordered(v) +#define SDL_GetWindowPosition(win, x, y) ((SDL_Window*)win)->GetPosition(x, y) +#define SDL_GetWindowSize(win, w, h) ((SDL_Window*)win)->GetSize(w, h) + +#define SDL_GL_GetDrawableSize(win, w, h) ((SDL_Window*)win)->GLGetDrawableSize(w, h) +#define SDL_GL_SwapWindow(win) ((SDL_Window*)win)->GLSwap() +#define SDL_GL_CreateContext(win) ((SDL_Window*)win)->GLCreateContext() + +typedef struct SDL_Renderer { + void (*Destroy)(void); + void (*Present)(void); +} SDL_Renderer; + +SDL_Renderer* SDL_CreateRenderer(SDL_Window* window, Sint32 index, Uint32 flags); + +#define SDL_RenderPresent(r) ((SDL_Renderer*)r)->Present() +#define SDL_DestroyRenderer(r) ((SDL_Renderer*)r)->Destroy() + +char *SDL_itoa(Sint32 value, char *str, Sint32 radix); +char *SDL_uitoa(Uint32 value, char *str, Sint32 radix); +void SDL_Delay(Uint32 ms); + +typedef struct SDL_mutex { + void (*Lock)(void); + void (*Unlock)(void); + void (*Destroy)(void); +} SDL_mutex; + +SDL_mutex* SDL_CreateMutex(void); + +#define SDL_DestroyMutex(m) ((SDL_mutex*)m)->Destroy() +#define SDL_LockMutex(m) ((SDL_mutex*)m)->Lock() +#define SDL_UnlockMutex(m) ((SDL_mutex*)m)->Unlock() + + +typedef struct SDL_Surface { + Sint32 w, h; + Sint32 pitch; + void* pixels; + SDL_Rect clip_rect; + + Sint32 (*Lock)(void); + void (*Unlock)(void); + void (*Free)(void); + Sint32 (*SetColorKey)(Sint32 flag, Uint32 key); + void (*GetClipRect)(SDL_Rect* rect); + Sint32 (*SetBlendMode)(SDL_BlendMode blendMode); +} SDL_Surface; + +SDL_Surface* SDL_CreateRGBSurfaceWithFormat(Uint32 flags, Sint32 width, Sint32 height, Sint32 depth, Uint32 format); + +#define SDL_LockSurface(s) ((SDL_Surface*)s)->Lock() +#define SDL_UnlockSurface(s) ((SDL_Surface*)s)->Unlock() +#define SDL_FreeSurface(s) ((SDL_Surface*)s)->Free() +#define SDL_SetColorKey(s, f, k) ((SDL_Surface*)s)->SetColorKey(f, k) +#define SDL_GetClipRect(s, r) ((SDL_Surface*)s)->GetClipRect(r) +#define SDL_SetSurfaceBlendMode(s, m) ((SDL_Surface*)s)->SetBlendMode(m) +Sint32 SDL_BlitSurface(SDL_Surface* src, const SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect); +Sint32 SDL_BlitScaled(SDL_Surface* src, const SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect); + +typedef struct SDL_Texture { + void (*Destroy)(void); +} SDL_Texture; +SDL_Texture* SDL_CreateTextureFromSurface(SDL_Renderer* renderer, SDL_Surface* surface); +#define SDL_DestroyTexture(t) ((SDL_Texture*)t)->Destroy() + +Sint32 SDL_RenderCopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srcrect, const SDL_Rect* dstrect); + + +Sint32 SDL_GL_SetSwapInterval(Sint32 interval); +void SDL_GL_DeleteContext(SDL_GLContext context); +Sint32 SDL_Init(Uint32 flags); +Sint32 SDL_PollEvent(SDL_Event* event); +void SDL_StartTextInput(void); +void SDL_StopTextInput(void); +SDL_Keymod SDL_GetModState(void); +Sint32 SDL_SetRelativeMouseMode(SDL_bool enabled); +Uint8 SDL_GetEventState(Uint32 type); +Uint32 SDL_GetGlobalMouseState(int* x, int* y); +Sint32 SDL_GetDisplayBounds(Sint32 displayIndex, SDL_Rect* rect); + +typedef Uint32 (*SDL_TimerCallback)(Uint32 interval, void* param); +SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void* param); +SDL_bool SDL_RemoveTimer(SDL_TimerID id); \ No newline at end of file diff --git a/libs/includes/SDL2/SDL_opengl.h b/libs/includes/SDL2/SDL_opengl.h new file mode 100644 index 0000000..e69de29 diff --git a/libs/includes/SDL2/SDL_opengl_glext.h b/libs/includes/SDL2/SDL_opengl_glext.h new file mode 100644 index 0000000..e69de29 diff --git a/libs/includes/SDL2/SDL_stdinc.h b/libs/includes/SDL2/SDL_stdinc.h new file mode 100644 index 0000000..e69de29 diff --git a/libs/includes/arpa_inet.h b/libs/includes/arpa/inet.h similarity index 100% rename from libs/includes/arpa_inet.h rename to libs/includes/arpa/inet.h diff --git a/libs/includes/ctype.h b/libs/includes/ctype.h new file mode 100644 index 0000000..83e1371 --- /dev/null +++ b/libs/includes/ctype.h @@ -0,0 +1,15 @@ +_cxgo_go_bool isalnum(_cxgo_go_rune); +_cxgo_go_bool isalpha(_cxgo_go_rune); +_cxgo_go_bool isascii(_cxgo_go_rune); +_cxgo_go_bool iscntrl(_cxgo_go_rune); +_cxgo_go_bool isdigit(_cxgo_go_rune); +_cxgo_go_bool isgraph(_cxgo_go_rune); +_cxgo_go_bool islower(_cxgo_go_rune); +_cxgo_go_bool isprint(_cxgo_go_rune); +_cxgo_go_bool ispunct(_cxgo_go_rune); +_cxgo_go_bool isspace(_cxgo_go_rune); +_cxgo_go_bool isupper(_cxgo_go_rune); +_cxgo_go_bool isxdigit(_cxgo_go_rune); +_cxgo_go_rune toascii(_cxgo_go_rune); +_cxgo_go_rune tolower(_cxgo_go_rune); +_cxgo_go_rune toupper(_cxgo_go_rune); \ No newline at end of file diff --git a/libs/includes/embed/dirent.h b/libs/includes/dirent.h similarity index 100% rename from libs/includes/embed/dirent.h rename to libs/includes/dirent.h diff --git a/libs/includes/embed/fcntl.h b/libs/includes/fcntl.h similarity index 100% rename from libs/includes/embed/fcntl.h rename to libs/includes/fcntl.h diff --git a/libs/includes/fenv.h b/libs/includes/fenv.h new file mode 100644 index 0000000..4014f3e --- /dev/null +++ b/libs/includes/fenv.h @@ -0,0 +1,2 @@ +const _cxgo_go_int FE_TOWARDZERO = 1; +_cxgo_sint32 fesetround(_cxgo_sint32 round); \ No newline at end of file diff --git a/libs/includes/embed/float.h b/libs/includes/float.h similarity index 100% rename from libs/includes/embed/float.h rename to libs/includes/float.h diff --git a/libs/includes/embed/getopt.h b/libs/includes/getopt.h similarity index 100% rename from libs/includes/embed/getopt.h rename to libs/includes/getopt.h diff --git a/libs/includes/embed/inttypes.h b/libs/includes/inttypes.h similarity index 100% rename from libs/includes/embed/inttypes.h rename to libs/includes/inttypes.h diff --git a/libs/includes/embed/libgen.h b/libs/includes/libgen.h similarity index 100% rename from libs/includes/embed/libgen.h rename to libs/includes/libgen.h diff --git a/libs/includes/pthread.h b/libs/includes/pthread.h index 6da4259..9e1e009 100644 --- a/libs/includes/pthread.h +++ b/libs/includes/pthread.h @@ -1,4 +1,3 @@ -#include #include const _cxgo_go_int PTHREAD_MUTEX_RECURSIVE = 1; diff --git a/libs/includes/embed/sched.h b/libs/includes/sched.h similarity index 100% rename from libs/includes/embed/sched.h rename to libs/includes/sched.h diff --git a/libs/includes/embed/semaphore.h b/libs/includes/semaphore.h similarity index 100% rename from libs/includes/embed/semaphore.h rename to libs/includes/semaphore.h diff --git a/libs/includes/setjmp.h b/libs/includes/setjmp.h index 0cc4220..8904ace 100644 --- a/libs/includes/setjmp.h +++ b/libs/includes/setjmp.h @@ -1,5 +1,3 @@ -#include - typedef struct jmp_buf { _cxgo_go_int (*SetJump) (); void (*LongJump) (_cxgo_go_int); diff --git a/libs/includes/embed/signal.h b/libs/includes/signal.h similarity index 100% rename from libs/includes/embed/signal.h rename to libs/includes/signal.h diff --git a/libs/includes/stdarg.h b/libs/includes/stdarg.h index ad67a19..95d92be 100644 --- a/libs/includes/stdarg.h +++ b/libs/includes/stdarg.h @@ -1,5 +1,3 @@ -#include - #define va_list __builtin_va_list #define va_start(va, t) va.Start(t, _rest) #define va_arg(va, typ) (typ)(va.Arg()) diff --git a/libs/includes/stdlib.h b/libs/includes/stdlib.h index b5ba35f..6355e46 100644 --- a/libs/includes/stdlib.h +++ b/libs/includes/stdlib.h @@ -1,4 +1,3 @@ -#include #include #define EXIT_FAILURE 1 diff --git a/libs/includes/string.h b/libs/includes/string.h index 188f819..5dc0ee6 100644 --- a/libs/includes/string.h +++ b/libs/includes/string.h @@ -1,4 +1,3 @@ -#include #include #include diff --git a/libs/includes/embed/strings.h b/libs/includes/strings.h similarity index 100% rename from libs/includes/embed/strings.h rename to libs/includes/strings.h diff --git a/libs/includes/embed/sys/mkdev.h b/libs/includes/sys/mkdev.h similarity index 100% rename from libs/includes/embed/sys/mkdev.h rename to libs/includes/sys/mkdev.h diff --git a/libs/includes/sys_socket.h b/libs/includes/sys/socket.h similarity index 100% rename from libs/includes/sys_socket.h rename to libs/includes/sys/socket.h diff --git a/libs/includes/sys_stat.h b/libs/includes/sys/stat.h similarity index 100% rename from libs/includes/sys_stat.h rename to libs/includes/sys/stat.h diff --git a/libs/includes/sys_time.h b/libs/includes/sys/time.h similarity index 100% rename from libs/includes/sys_time.h rename to libs/includes/sys/time.h diff --git a/libs/includes/sys_types.h b/libs/includes/sys/types.h similarity index 95% rename from libs/includes/sys_types.h rename to libs/includes/sys/types.h index 8fec000..3a21dd9 100644 --- a/libs/includes/sys_types.h +++ b/libs/includes/sys/types.h @@ -1,4 +1,3 @@ -#include #include #include diff --git a/libs/includes/time.h b/libs/includes/time.h index 458c9b9..0bbb12b 100644 --- a/libs/includes/time.h +++ b/libs/includes/time.h @@ -1,4 +1,3 @@ -#include #include const _cxgo_go_int CLOCK_REALTIME = 0; diff --git a/libs/includes/unistd.h b/libs/includes/unistd.h index 5628cbe..9813e29 100644 --- a/libs/includes/unistd.h +++ b/libs/includes/unistd.h @@ -1,4 +1,3 @@ -#include #include #include #include diff --git a/libs/includes/wctype.h b/libs/includes/wctype.h index 2b182e8..2669dee 100644 --- a/libs/includes/wctype.h +++ b/libs/includes/wctype.h @@ -1,5 +1,3 @@ -//#include - #include #include #include diff --git a/libs/includes/embed/windows.h b/libs/includes/windows.h similarity index 100% rename from libs/includes/embed/windows.h rename to libs/includes/windows.h diff --git a/libs/math.go b/libs/math.go index 6f30f2a..74ef97c 100644 --- a/libs/math.go +++ b/libs/math.go @@ -18,7 +18,6 @@ func init() { doubleT := types.FloatT(8) floatT := types.FloatT(4) var buf bytes.Buffer - buf.WriteString("#include <" + BuiltinH + ">\n") buf.WriteString("const double M_PI = 3.1415;\n") lib := &Library{ Imports: map[string]string{ diff --git a/libs/netdb.go b/libs/netdb.go index a1c9074..4b8ae82 100644 --- a/libs/netdb.go +++ b/libs/netdb.go @@ -1,8 +1,6 @@ package libs import ( - _ "embed" - "github.com/gotranspile/cxgo/runtime/cnet" "github.com/gotranspile/cxgo/types" ) @@ -11,9 +9,6 @@ const ( netdbH = "netdb.h" ) -//go:embed includes/netdb.h -var hnetdb string - func init() { RegisterLibrary(netdbH, func(c *Env) *Library { strT := c.C().String() @@ -35,8 +30,6 @@ func init() { Idents: map[string]*types.Ident{ "gethostbyname": c.NewIdent("gethostbyname", "cnet.GetHostByName", cnet.GetHostByName, c.FuncTT(c.PtrT(hostentT), strT)), }, - // TODO - Header: hnetdb, } }) } diff --git a/libs/pthread.go b/libs/pthread.go index 18d9f38..fbd38f9 100644 --- a/libs/pthread.go +++ b/libs/pthread.go @@ -1,8 +1,6 @@ package libs import ( - _ "embed" - "github.com/gotranspile/cxgo/runtime/pthread" "github.com/gotranspile/cxgo/types" ) @@ -11,9 +9,6 @@ const ( pthreadH = "pthread.h" ) -//go:embed includes/pthread.h -var hpthread string - func init() { RegisterLibrary(pthreadH, func(c *Env) *Library { gintT := c.Go().Int() @@ -70,8 +65,6 @@ func init() { "pthread_cond_init": c.NewIdent("pthread_cond_init", "pthread.CondInit", pthread.CondInit, c.FuncTT(intT, c.PtrT(condT), c.PtrT(condAttrT))), "pthread_cond_destroy": c.NewIdent("pthread_cond_destroy", "pthread.CondFree", pthread.CondFree, c.FuncTT(intT, c.PtrT(condT))), }, - // TODO - Header: hpthread, } }) } diff --git a/libs/registry.go b/libs/registry.go index 8fabb28..b883057 100644 --- a/libs/registry.go +++ b/libs/registry.go @@ -107,11 +107,16 @@ func cTypeStr(t types.Type) string { } } -var libs = make(map[string]LibraryFunc) +var ( + libs = make(map[string]LibraryFunc) + libsrc = make(map[string]string) +) type LibraryFunc func(c *Env) *Library // RegisterLibrary registers an override for a C library. +// +// If the library provides no custom cxgo identifiers or types, RegisterLibrarySrc can be used instead. func RegisterLibrary(name string, fnc LibraryFunc) { if name == "" { panic("empty name") @@ -125,6 +130,19 @@ func RegisterLibrary(name string, fnc LibraryFunc) { libs[name] = fnc } +// RegisterLibrarySrc registers an override for a C library source. +// +// For registering custom cxgo identifiers or types see RegisterLibrary. +func RegisterLibrarySrc(name string, hdr string) { + if name == "" { + panic("empty name") + } + if _, ok := libsrc[name]; ok { + panic("already registered") + } + libsrc[name] = hdr +} + const IncludePath = "/_cxgo_overrides" var defPathReplacer = strings.NewReplacer( @@ -134,14 +152,19 @@ var defPathReplacer = strings.NewReplacer( // GetLibrary finds or initializes the library, given a C include filename. func (c *Env) GetLibrary(name string) (*Library, bool) { - if l, ok := c.libs[name]; ok { + l, ok := c.libs[name] + if ok { return l, true } - fnc, ok := libs[name] - if !ok { + // First consult a general library registry. + // If not found, but we have a library source - register library anyway. + if fnc, ok := libs[name]; ok { + l = fnc(c) + } else if _, ok := libsrc[name]; ok { + l = new(Library) + } else { return nil, false } - l := fnc(c) l.created = true l.Name = name //for name, typ := range l.Types { @@ -163,21 +186,24 @@ func (c *Env) GetLibrary(name string) (*Library, bool) { for k, v := range l.ForceMacros { c.macros[k] = v } - ifdef := "_cxgo_" + strings.ToUpper(defPathReplacer.Replace(name)) - l.Header = fmt.Sprintf(` -#ifndef %s -#define %s - -%s - -#endif // %s -`, - ifdef, - ifdef, - l.Header, - ifdef, - ) + var hdr strings.Builder + hdr.WriteString("#ifndef " + ifdef + "\n") + hdr.WriteString("#define " + ifdef + "\n") + if name != BuiltinH { + hdr.WriteString("#include <" + BuiltinH + ">\n") + } + hdr.WriteString("\n") + if src := libsrc[name]; src != "" { + hdr.WriteString(src) + hdr.WriteString("\n") + } + if l.Header != "" { + hdr.WriteString(l.Header) + hdr.WriteString("\n") + } + hdr.WriteString("\n#endif // " + ifdef + "\n") + l.Header = hdr.String() return l, true } diff --git a/libs/reglibs.go b/libs/reglibs.go index 80faacb..012a6bf 100644 --- a/libs/reglibs.go +++ b/libs/reglibs.go @@ -2,16 +2,15 @@ package libs import ( "embed" - "fmt" "io/fs" "strings" ) -//go:embed includes/embed +//go:embed includes var efs embed.FS func init() { - const root = "includes/embed" + const root = "includes" err := fs.WalkDir(efs, root, func(path string, d fs.DirEntry, err error) error { if err != nil { return err @@ -23,11 +22,7 @@ func init() { return err } fname := strings.TrimPrefix(path, root+"/") - RegisterLibrary(fname, func(env *Env) *Library { - return &Library{ - Header: fmt.Sprintf("#include <%s>\n%s", BuiltinH, string(data)), - } - }) + RegisterLibrarySrc(fname, string(data)) return nil }) if err != nil { diff --git a/libs/sdl2.go b/libs/sdl2.go index f885f96..53d2511 100644 --- a/libs/sdl2.go +++ b/libs/sdl2.go @@ -5,10 +5,7 @@ import ( ) const ( - sdl2H = "SDL2/SDL.h" - sdl2OpenGLH = "SDL2/SDL_opengl.h" - sdl2OpenGLExtH = "SDL2/SDL_opengl_glext.h" - sdl2StdIncH = "SDL2/SDL_stdinc.h" + sdl2H = "SDL2/SDL.h" ) func init() { @@ -195,265 +192,6 @@ func init() { "SDL_WINDOW_OPENGL": types.NewIdent("sdl.WINDOW_OPENGL", uintT), "SDL_WINDOW_FULLSCREEN_DESKTOP": types.NewIdent("sdl.WINDOW_FULLSCREEN_DESKTOP", uintT), }, - // TODO - Header: ` -#include <` + BuiltinH + `> - -#define Uint32 _cxgo_uint32 -#define Uint16 _cxgo_uint16 -#define Uint8 _cxgo_uint8 -#define Sint32 _cxgo_sint32 -#define Sint16 _cxgo_sint16 -#define Sint8 _cxgo_sint8 -#define SDL_bool _cxgo_go_bool -typedef Sint32 SDL_FingerID; -typedef Sint32 SDL_Scancode; -typedef Sint32 SDL_Keymod; -typedef Sint32 SDL_BlendMode; -typedef Sint32 SDL_TimerID; - - -#define SDL_TRUE 1 -#define SDL_FALSE 0 -const Sint32 SDL_PIXELFORMAT_RGBA5551 = 1; -const Sint32 SDL_PIXELFORMAT_RGB565 = 2; -const Sint32 SDL_PIXELFORMAT_RGB555 = 3; - -const Sint32 SDL_RENDERER_ACCELERATED = 1; -const Sint32 SDL_RENDERER_PRESENTVSYNC = 2; - -#define SDL_NUM_SCANCODES 512 - -typedef struct{ - Sint16 x, y; - Uint16 w, h; -} SDL_Rect; - -#define SDL_TEXTEDITING 770 -#define SDL_TEXTINPUT 771 -#define SDL_KEYDOWN 768 -#define SDL_KEYUP 769 -#define SDL_MOUSEBUTTONDOWN 1025 -#define SDL_MOUSEBUTTONUP 1026 -#define SDL_MOUSEMOTION 1024 -#define SDL_MOUSEWHEEL 1027 -#define SDL_WINDOWEVENT 512 - -#define SDL_WINDOWEVENT_FOCUS_LOST 13 -#define SDL_WINDOWEVENT_FOCUS_GAINED 12 - -#define SDL_BUTTON_LEFT 1 -#define SDL_BUTTON_RIGHT 3 -#define SDL_BUTTON_MIDDLE 2 - -const Sint32 SDL_PRESSED = 1; - -const Sint32 SDL_SCANCODE_SPACE = 1; -const Sint32 KMOD_LSHIFT = 1; -const Sint32 KMOD_RSHIFT = 2; -const Sint32 KMOD_RALT = 3; - -const Uint32 SDL_INIT_VIDEO = 1; -const Uint32 SDL_INIT_TIMER = 2; -const Sint32 SDL_WINDOWPOS_UNDEFINED = -1; -const Sint32 SDL_WINDOWPOS_CENTERED = -2; -const Uint32 SDL_WINDOW_RESIZABLE = 1; -const Uint32 SDL_WINDOW_OPENGL = 2; -const SDL_BlendMode SDL_BLENDMODE_NONE = 1; - -typedef struct{ - SDL_Scancode scancode; -} SDL_Keysym; - -typedef struct{ - SDL_Keysym keysym; - Uint8 state; -} SDL_KeyboardEvent; - -typedef struct{ - Uint8 button; - Uint8 state; - Sint32 x,y; -} SDL_MouseButtonEvent; - -typedef struct{ - Sint32 x, y; - Sint32 xrel, yrel; -} SDL_MouseMotionEvent; - -typedef struct{ - Sint32 x, y; -} SDL_MouseWheelEvent; - -typedef struct{} SDL_TouchFingerEvent; - -typedef struct{ - char text[32]; -} SDL_TextEditingEvent; - -typedef struct{ - char text[32]; -} SDL_TextInputEvent; - -typedef struct{ - Uint8 event; -} SDL_WindowEvent; - -typedef struct{ - int type; - SDL_TextEditingEvent edit; - SDL_TextInputEvent text; - SDL_KeyboardEvent key; - SDL_MouseButtonEvent button; - SDL_MouseMotionEvent motion; - SDL_MouseWheelEvent wheel; - SDL_WindowEvent window; -} SDL_Event; - -const Uint32 SDL_WINDOW_FULLSCREEN_DESKTOP = 0; - -typedef struct SDL_GLContext {} SDL_GLContext; - -typedef struct SDL_Window { - Sint32 (*SetFullscreen)(Uint32 flags); - void (*GetSize)(Sint32 *w, Sint32 *h); - void (*GetPosition)(Sint32 *x, Sint32 *y); - void (*SetSize)(Sint32 w, Sint32 h); - void (*SetPosition)(Sint32 x, Sint32 y); - void (*Minimize)(void); - void (*Restore)(void); - void (*SetGrab)(SDL_bool); - void (*SetResizable)(SDL_bool); - void (*SetBordered)(SDL_bool); - void (*SetTitle)(const char*); - Sint32 (*GetDisplayIndex)(void); - void (*GLGetDrawableSize)(Sint32* w, Sint32* h); - void (*GLSwapWindow)(void); - SDL_GLContext (*GLCreateContext)(void); -} SDL_Window; - -const char* SDL_GetError(void); - -Uint32 SDL_GetTicks(void); -SDL_Window* SDL_CreateWindow(const char* title, Sint32 x, Sint32 y, Sint32 w, Sint32 h, Uint32 flags); -#define SDL_SetWindowFullscreen(win, flags) ((SDL_Window*)win)->SetFullscreen(flags) -#define SDL_SetWindowSize(win, w, h) ((SDL_Window*)win)->SetSize(w, h) -#define SDL_SetWindowPosition(win, x, y) ((SDL_Window*)win)->SetPosition(x, y) -#define SDL_SetWindowGrab(win, v) ((SDL_Window*)win)->SetGrab(v) -#define SDL_SetWindowTitle(win, v) ((SDL_Window*)win)->SetTitle(v) -#define SDL_MinimizeWindow(win) ((SDL_Window*)win)->Minimize() -#define SDL_RestoreWindow(win) ((SDL_Window*)win)->Restore() -#define SDL_GetWindowDisplayIndex(win) ((SDL_Window*)win)->GetDisplayIndex() -#define SDL_SetWindowResizable(win, v) ((SDL_Window*)win)->SetResizable(v) -#define SDL_SetWindowBordered(win, v) ((SDL_Window*)win)->SetBordered(v) -#define SDL_GetWindowPosition(win, x, y) ((SDL_Window*)win)->GetPosition(x, y) -#define SDL_GetWindowSize(win, w, h) ((SDL_Window*)win)->GetSize(w, h) - -#define SDL_GL_GetDrawableSize(win, w, h) ((SDL_Window*)win)->GLGetDrawableSize(w, h) -#define SDL_GL_SwapWindow(win) ((SDL_Window*)win)->GLSwap() -#define SDL_GL_CreateContext(win) ((SDL_Window*)win)->GLCreateContext() - -typedef struct SDL_Renderer { - void (*Destroy)(void); - void (*Present)(void); -} SDL_Renderer; - -SDL_Renderer* SDL_CreateRenderer(SDL_Window* window, Sint32 index, Uint32 flags); - -#define SDL_RenderPresent(r) ((SDL_Renderer*)r)->Present() -#define SDL_DestroyRenderer(r) ((SDL_Renderer*)r)->Destroy() - -char *SDL_itoa(Sint32 value, char *str, Sint32 radix); -char *SDL_uitoa(Uint32 value, char *str, Sint32 radix); -void SDL_Delay(Uint32 ms); - -typedef struct SDL_mutex { - void (*Lock)(void); - void (*Unlock)(void); - void (*Destroy)(void); -} SDL_mutex; - -SDL_mutex* SDL_CreateMutex(void); - -#define SDL_DestroyMutex(m) ((SDL_mutex*)m)->Destroy() -#define SDL_LockMutex(m) ((SDL_mutex*)m)->Lock() -#define SDL_UnlockMutex(m) ((SDL_mutex*)m)->Unlock() - - -typedef struct SDL_Surface { - Sint32 w, h; - Sint32 pitch; - void* pixels; - SDL_Rect clip_rect; - - Sint32 (*Lock)(void); - void (*Unlock)(void); - void (*Free)(void); - Sint32 (*SetColorKey)(Sint32 flag, Uint32 key); - void (*GetClipRect)(SDL_Rect* rect); - Sint32 (*SetBlendMode)(SDL_BlendMode blendMode); -} SDL_Surface; - -SDL_Surface* SDL_CreateRGBSurfaceWithFormat(Uint32 flags, Sint32 width, Sint32 height, Sint32 depth, Uint32 format); - -#define SDL_LockSurface(s) ((SDL_Surface*)s)->Lock() -#define SDL_UnlockSurface(s) ((SDL_Surface*)s)->Unlock() -#define SDL_FreeSurface(s) ((SDL_Surface*)s)->Free() -#define SDL_SetColorKey(s, f, k) ((SDL_Surface*)s)->SetColorKey(f, k) -#define SDL_GetClipRect(s, r) ((SDL_Surface*)s)->GetClipRect(r) -#define SDL_SetSurfaceBlendMode(s, m) ((SDL_Surface*)s)->SetBlendMode(m) -Sint32 SDL_BlitSurface(SDL_Surface* src, const SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect); -Sint32 SDL_BlitScaled(SDL_Surface* src, const SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect); - -typedef struct SDL_Texture { - void (*Destroy)(void); -} SDL_Texture; -SDL_Texture* SDL_CreateTextureFromSurface(SDL_Renderer* renderer, SDL_Surface* surface); -#define SDL_DestroyTexture(t) ((SDL_Texture*)t)->Destroy() - -Sint32 SDL_RenderCopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srcrect, const SDL_Rect* dstrect); - - -Sint32 SDL_GL_SetSwapInterval(Sint32 interval); -void SDL_GL_DeleteContext(SDL_GLContext context); -Sint32 SDL_Init(Uint32 flags); -Sint32 SDL_PollEvent(SDL_Event* event); -void SDL_StartTextInput(void); -void SDL_StopTextInput(void); -SDL_Keymod SDL_GetModState(void); -Sint32 SDL_SetRelativeMouseMode(SDL_bool enabled); -Uint8 SDL_GetEventState(Uint32 type); -Uint32 SDL_GetGlobalMouseState(int* x, int* y); -Sint32 SDL_GetDisplayBounds(Sint32 displayIndex, SDL_Rect* rect); - -typedef Uint32 (*SDL_TimerCallback)(Uint32 interval, void* param); -SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void* param); -SDL_bool SDL_RemoveTimer(SDL_TimerID id); -`, - } - }) - RegisterLibrary(sdl2OpenGLH, func(c *Env) *Library { - return &Library{ - // TODO - Header: ` -#include <` + BuiltinH + `> -`, - } - }) - RegisterLibrary(sdl2OpenGLExtH, func(c *Env) *Library { - return &Library{ - // TODO - Header: ` -#include <` + BuiltinH + `> -`, - } - }) - RegisterLibrary(sdl2StdIncH, func(c *Env) *Library { - return &Library{ - // TODO - Header: ` -#include <` + BuiltinH + `> -`, } }) } diff --git a/libs/setjmp.go b/libs/setjmp.go index 3119ac2..8d135b9 100644 --- a/libs/setjmp.go +++ b/libs/setjmp.go @@ -1,8 +1,6 @@ package libs import ( - _ "embed" - "github.com/gotranspile/cxgo/types" ) @@ -10,9 +8,6 @@ const ( setjmpH = "setjmp.h" ) -//go:embed includes/setjmp.h -var hsetjmp string - func init() { RegisterLibrary(setjmpH, func(c *Env) *Library { gint := c.Go().Int() @@ -27,7 +22,6 @@ func init() { Imports: map[string]string{ "libc": RuntimeLibc, }, - Header: hsetjmp, } }) } diff --git a/libs/stdarg.go b/libs/stdarg.go index a2ddfbe..44e6bbd 100644 --- a/libs/stdarg.go +++ b/libs/stdarg.go @@ -1,19 +1,13 @@ package libs -import _ "embed" - const ( StdargH = "stdarg.h" ) -//go:embed includes/stdarg.h -var hstdarg string - func init() { RegisterLibrary(StdargH, func(c *Env) *Library { // all types and method are define as builtins, so only macros here l := &Library{ - Header: hstdarg, Imports: map[string]string{ "libc": RuntimeLibc, }, diff --git a/libs/stdarg_test.go b/libs/stdarg_test.go index 14817b5..a6ae8a8 100644 --- a/libs/stdarg_test.go +++ b/libs/stdarg_test.go @@ -3,14 +3,13 @@ package libs import ( "testing" - "github.com/gotranspile/cxgo/types" "github.com/stretchr/testify/require" + + "github.com/gotranspile/cxgo/types" ) -var expStdArgsH = ` -#ifndef _cxgo_STDARG_H +var expStdArgsH = `#ifndef _cxgo_STDARG_H #define _cxgo_STDARG_H - #include #define va_list __builtin_va_list diff --git a/libs/stdint.go b/libs/stdint.go index 6c87d56..63118ba 100644 --- a/libs/stdint.go +++ b/libs/stdint.go @@ -156,7 +156,6 @@ var ( func incStdInt(e *types.Env, m map[string]*types.Ident) string { var buf strings.Builder - buf.WriteString("#include <" + BuiltinH + ">\n") buf.WriteString(fixedIntTypes()) buf.WriteString(maxIntTypes(e)) buf.WriteString(intLimits(m)) diff --git a/libs/stdint_test.go b/libs/stdint_test.go index 4ceef46..1ab7527 100644 --- a/libs/stdint_test.go +++ b/libs/stdint_test.go @@ -4,17 +4,19 @@ import ( "strings" "testing" - "github.com/gotranspile/cxgo/types" "github.com/stretchr/testify/require" + + "github.com/gotranspile/cxgo/types" ) func TestStdInt(t *testing.T) { - c := types.NewEnv(types.Config32()) - s := incStdInt(c, nil) - s = strings.TrimSpace(s) - s = strings.TrimSpace(s) - require.Equal(t, strings.TrimSpace(` + c := NewEnv(types.Config32()) + l, ok := c.GetLibrary(stdintH) + require.True(t, ok) + require.Equal(t, strings.TrimSpace(`#ifndef _cxgo_STDINT_H +#define _cxgo_STDINT_H #include + #define int8_t _cxgo_sint8 #define int16_t _cxgo_sint16 #define int32_t _cxgo_sint32 @@ -108,5 +110,9 @@ typedef _cxgo_uint64 uintmax_t; #define WINT_MIN 0 #define WINT_MAX 4294967295u -`), strings.TrimSpace(s)) + + + +#endif // _cxgo_STDINT_H +`), strings.TrimSpace(l.Header)) } diff --git a/libs/stdio.go b/libs/stdio.go index a8c3936..3983d6f 100644 --- a/libs/stdio.go +++ b/libs/stdio.go @@ -58,7 +58,6 @@ func init() { "_cxgo_EOF": c.NewIdent("_cxgo_EOF", "stdio.EOF", stdio.EOF, types.UntypedIntT(1)), }, Header: ` -#include <` + BuiltinH + `> #include <` + stddefH + `> #include <` + StdargH + `> #include <` + StdlibH + `> diff --git a/libs/stdlib.go b/libs/stdlib.go index 4fbb54a..370cb0a 100644 --- a/libs/stdlib.go +++ b/libs/stdlib.go @@ -1,7 +1,6 @@ package libs import ( - _ "embed" "fmt" "os" @@ -12,9 +11,6 @@ import ( const StdlibH = "stdlib.h" -//go:embed includes/stdlib.h -var hstdlib string - // https://pubs.opengroup.org/onlinepubs/9699919799/ func init() { @@ -48,7 +44,7 @@ func init() { "bsearch": c.NewIdent("bsearch", "libc.Search", libc.Search, c.FuncTT(voidPtr, voidPtr, voidPtr, uintT, uintT, c.FuncTT(intT, voidPtr, voidPtr))), "mbstowcs": c.NewIdent("mbstowcs", "libc.Mbstowcs", libc.Mbstowcs, c.FuncTT(uintT, wstrT, cstrT, uintT)), }, - Header: hstdlib + fmt.Sprintf("#define RAND_MAX %d\n", libc.RandMax), + Header: fmt.Sprintf("#define RAND_MAX %d\n", libc.RandMax), } l.Declare( diff --git a/libs/string.go b/libs/string.go index 6f8f5d1..dc6d637 100644 --- a/libs/string.go +++ b/libs/string.go @@ -1,8 +1,6 @@ package libs import ( - _ "embed" - "github.com/gotranspile/cxgo/runtime/libc" "github.com/gotranspile/cxgo/types" ) @@ -13,9 +11,6 @@ const ( stringH = "string.h" ) -//go:embed includes/string.h -var hstring string - func init() { // TODO: should include RegisterLibrary(stringH, func(c *Env) *Library { @@ -45,7 +40,6 @@ func init() { "strspn": c.NewIdent("strspn", "libc.StrSpn", libc.StrSpn, c.FuncTT(gintT, cstrT, cstrT)), "strcspn": c.NewIdent("strcspn", "libc.StrCSpn", libc.StrCSpn, c.FuncTT(gintT, cstrT, cstrT)), }, - Header: hstring, } }) } diff --git a/libs/sys_socket.go b/libs/sys_socket.go index 1f83bd5..7be34d0 100644 --- a/libs/sys_socket.go +++ b/libs/sys_socket.go @@ -1,8 +1,6 @@ package libs import ( - _ "embed" - "github.com/gotranspile/cxgo/runtime/cnet" "github.com/gotranspile/cxgo/types" ) @@ -11,9 +9,6 @@ const ( sysSocketH = "sys/socket.h" ) -//go:embed includes/sys_socket.h -var hsys_socket string - func init() { RegisterLibrary(sysSocketH, func(c *Env) *Library { intT := types.IntT(4) @@ -59,8 +54,6 @@ func init() { "socket": c.NewIdent("socket", "cnet.Socket", cnet.Socket, c.FuncTT(gintT, gintT, gintT, gintT)), "setsockopt": c.NewIdent("setsockopt", "cnet.SetSockOpt", cnet.SetSockOpt, c.FuncTT(gintT, gintT, gintT, gintT, bytesT, gintT)), }, - // TODO - Header: hsys_socket, } }) } diff --git a/libs/sys_stat.go b/libs/sys_stat.go index 0f65eb8..63cbdbf 100644 --- a/libs/sys_stat.go +++ b/libs/sys_stat.go @@ -1,8 +1,6 @@ package libs import ( - _ "embed" - "github.com/gotranspile/cxgo/runtime/csys" "github.com/gotranspile/cxgo/types" ) @@ -11,9 +9,6 @@ const ( sysStatH = "sys/stat.h" ) -//go:embed includes/sys_stat.h -var hsys_stat string - func init() { RegisterLibrary(sysStatH, func(c *Env) *Library { intT := types.IntT(4) @@ -49,8 +44,6 @@ func init() { "mkdir": c.NewIdent("mkdir", "csys.Mkdir", csys.Mkdir, c.FuncTT(intT, strT, modeT)), "S_ISDIR": c.NewIdent("S_ISDIR", "csys.IsDir", csys.IsDir, c.FuncTT(intT, modeT)), }, - // TODO - Header: hsys_stat, } }) } diff --git a/libs/sys_time.go b/libs/sys_time.go index 2305884..fbac461 100644 --- a/libs/sys_time.go +++ b/libs/sys_time.go @@ -1,8 +1,6 @@ package libs import ( - _ "embed" - "github.com/gotranspile/cxgo/runtime/csys" "github.com/gotranspile/cxgo/types" ) @@ -11,9 +9,6 @@ const ( sysTimeH = "sys/time.h" ) -//go:embed includes/sys_time.h -var hsys_time string - func init() { RegisterLibrary(sysTimeH, func(c *Env) *Library { intT := types.IntT(4) @@ -29,8 +24,6 @@ func init() { Idents: map[string]*types.Ident{ "gettimeofday": c.NewIdent("gettimeofday", "csys.GetTimeOfDay", csys.GetTimeOfDay, c.FuncTT(intT, c.PtrT(timevalT), c.PtrT(nil))), }, - // TODO - Header: hsys_time, } }) } diff --git a/libs/sys_types.go b/libs/sys_types.go index 4680a7e..f3440a5 100644 --- a/libs/sys_types.go +++ b/libs/sys_types.go @@ -1,8 +1,6 @@ package libs import ( - _ "embed" - "github.com/gotranspile/cxgo/runtime/csys" "github.com/gotranspile/cxgo/types" ) @@ -11,9 +9,6 @@ const ( sysTypesH = "sys/types.h" ) -//go:embed includes/sys_types.h -var hsysTypes string - func init() { RegisterLibrary(sysTypesH, func(c *Env) *Library { intT := types.IntT(4) @@ -26,8 +21,6 @@ func init() { "O_EXCL": c.NewIdent("O_EXCL", "csys.O_EXCL", csys.O_EXCL, intT), "O_TRUNC": c.NewIdent("O_TRUNC", "csys.O_TRUNC", csys.O_TRUNC, intT), }, - // TODO - Header: hsysTypes, } }) } diff --git a/libs/time.go b/libs/time.go index 30ea762..5f42eb5 100644 --- a/libs/time.go +++ b/libs/time.go @@ -1,8 +1,6 @@ package libs import ( - _ "embed" - "github.com/gotranspile/cxgo/runtime/libc" "github.com/gotranspile/cxgo/types" ) @@ -11,9 +9,6 @@ const ( timeH = "time.h" ) -//go:embed includes/time.h -var htime string - func init() { RegisterLibrary(timeH, func(c *Env) *Library { gintT := c.Go().Int() @@ -71,8 +66,6 @@ func init() { "CLOCK_MONOTONIC": c.NewIdent("CLOCK_MONOTONIC", "libc.CLOCK_MONOTONIC", libc.CLOCK_MONOTONIC, gintT), "CLOCKS_PER_SEC": c.NewIdent("CLOCKS_PER_SEC", "libc.CLOCKS_PER_SEC", libc.CLOCKS_PER_SEC, gintT), }, - // TODO - Header: htime, } }) } diff --git a/libs/unistd.go b/libs/unistd.go index a66e155..d2fd34f 100644 --- a/libs/unistd.go +++ b/libs/unistd.go @@ -1,8 +1,6 @@ package libs import ( - _ "embed" - "github.com/gotranspile/cxgo/runtime/cnet" "github.com/gotranspile/cxgo/runtime/stdio" "github.com/gotranspile/cxgo/types" @@ -12,9 +10,6 @@ const ( unistdH = "unistd.h" ) -//go:embed includes/unistd.h -var hunistd string - func init() { RegisterLibrary(unistdH, func(c *Env) *Library { modeT := c.GetLibraryType(sysStatH, "mode_t") @@ -42,7 +37,6 @@ func init() { "getcwd": c.NewIdent("getcwd", "stdio.GetCwd", stdio.GetCwd, c.FuncTT(strT, strT, gintT)), "gethostname": c.NewIdent("gethostname", "cnet.GetHostname", cnet.GetHostname, c.FuncTT(gintT, strT, gintT)), }, - Header: hunistd, } }) } diff --git a/libs/wctype.go b/libs/wctype.go index e4f1d3f..cd8a22d 100644 --- a/libs/wctype.go +++ b/libs/wctype.go @@ -1,7 +1,6 @@ package libs import ( - _ "embed" "unicode" "github.com/gotranspile/cxgo/runtime/libc" @@ -14,9 +13,6 @@ const ( wctypeH = "wctype.h" ) -//go:embed includes/wctype.h -var hwctype string - func init() { RegisterLibrary(wctypeH, func(c *Env) *Library { runeT := c.Go().Rune() @@ -42,7 +38,6 @@ func init() { "towlower": c.NewIdent("towlower", "unicode.ToLower", unicode.ToLower, toT), "towupper": c.NewIdent("towupper", "unicode.ToUpper", unicode.ToUpper, toT), }, - Header: hwctype, } }) }