Skip to content

Commit c7e2713

Browse files
committed
Unify header registry with custom types and identifiers.
1 parent 4a0d2b1 commit c7e2713

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+313
-441
lines changed

libs/arpa_inet.go

-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package libs
22

33
import (
4-
_ "embed"
5-
64
"github.com/gotranspile/cxgo/runtime/cnet"
75
"github.com/gotranspile/cxgo/types"
86
)
@@ -13,9 +11,6 @@ const (
1311
arpaInetH = "arpa/inet.h"
1412
)
1513

16-
//go:embed includes/arpa_inet.h
17-
var harpaInet string
18-
1914
func init() {
2015
RegisterLibrary(arpaInetH, func(c *Env) *Library {
2116
inAddrT := types.NamedTGo("in_addr_t", "cnet.Addr", types.UintT(8))
@@ -45,7 +40,6 @@ func init() {
4540
"inet_ntop": c.NewIdent("inet_ntop", "cnet.Ntop", cnet.Ntop, c.FuncTT(strT, types.IntT(4), c.PtrT(nil), strT, sockLenT)),
4641
"inet_pton": c.NewIdent("inet_pton", "cnet.Pton", cnet.Pton, c.FuncTT(strT, types.IntT(4), strT, c.PtrT(nil))),
4742
},
48-
Header: harpaInet,
4943
}
5044
})
5145
}

libs/ctype.go

-18
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,6 @@ func init() {
3939
"tolower": c.NewIdent("tolower", "unicode.ToLower", unicode.ToLower, toT),
4040
"toupper": c.NewIdent("toupper", "unicode.ToUpper", unicode.ToUpper, toT),
4141
},
42-
// TODO
43-
Header: `
44-
_cxgo_go_bool isalnum(_cxgo_go_rune);
45-
_cxgo_go_bool isalpha(_cxgo_go_rune);
46-
_cxgo_go_bool isascii(_cxgo_go_rune);
47-
_cxgo_go_bool iscntrl(_cxgo_go_rune);
48-
_cxgo_go_bool isdigit(_cxgo_go_rune);
49-
_cxgo_go_bool isgraph(_cxgo_go_rune);
50-
_cxgo_go_bool islower(_cxgo_go_rune);
51-
_cxgo_go_bool isprint(_cxgo_go_rune);
52-
_cxgo_go_bool ispunct(_cxgo_go_rune);
53-
_cxgo_go_bool isspace(_cxgo_go_rune);
54-
_cxgo_go_bool isupper(_cxgo_go_rune);
55-
_cxgo_go_bool isxdigit(_cxgo_go_rune);
56-
_cxgo_go_rune toascii(_cxgo_go_rune);
57-
_cxgo_go_rune tolower(_cxgo_go_rune);
58-
_cxgo_go_rune toupper(_cxgo_go_rune);
59-
`,
6042
}
6143
})
6244
}

libs/dlfcn.go

-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ func init() {
3131
"dlopen": RuntimePrefix + "dlopen",
3232
},
3333
Header: `
34-
#include <` + BuiltinH + `>
35-
3634
const int RTLD_LAZY = 1;
3735
const int RTLD_NOW = 2;
3836
const int RTLD_GLOBAL = 4;

libs/errno.go

-3
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ func init() {
2222
})
2323
}
2424

25-
2625
func errnoHeader() string {
27-
2826
lines := []string{
29-
"#include <" + BuiltinH + ">",
3027
"_cxgo_go_int errno = 0;",
3128
"char* strerror (_cxgo_go_int errnum);",
3229
}

libs/fenv.go

-6
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ func init() {
2121
"FE_TOWARDZERO": c.NewIdent("FE_TOWARDZERO", "cmath.TowardZero", cmath.TowardZero, gint),
2222
"fesetround": c.NewIdent("fesetround", "cmath.FSetRound", cmath.FSetRound, c.FuncTT(intT, intT)),
2323
},
24-
// TODO
25-
Header: `
26-
#include <` + BuiltinH + `>
27-
const _cxgo_go_int FE_TOWARDZERO = 1;
28-
_cxgo_sint32 fesetround(_cxgo_sint32 round);
29-
`,
3024
}
3125
})
3226
}

libs/glob.go

-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package libs
22

33
import (
4-
_ "embed"
5-
64
"github.com/gotranspile/cxgo/runtime/stdio"
75
"github.com/gotranspile/cxgo/types"
86
)
@@ -11,9 +9,6 @@ const (
119
globH = "glob.h"
1210
)
1311

14-
//go:embed includes/glob.h
15-
var hglob string
16-
1712
func init() {
1813
RegisterLibrary(globH, func(c *Env) *Library {
1914
gint := c.Go().Int()
@@ -38,8 +33,6 @@ func init() {
3833
Idents: map[string]*types.Ident{
3934
"GLOB_NOESCAPE": c.NewIdent("GLOB_NOESCAPE", "stdio.GlobNoEscape", stdio.GlobNoEscape, gint),
4035
},
41-
// TODO
42-
Header: hglob,
4336
}
4437
})
4538
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

libs/includes/SDL2/SDL.h

+230
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
#define Uint32 _cxgo_uint32
2+
#define Uint16 _cxgo_uint16
3+
#define Uint8 _cxgo_uint8
4+
#define Sint32 _cxgo_sint32
5+
#define Sint16 _cxgo_sint16
6+
#define Sint8 _cxgo_sint8
7+
#define SDL_bool _cxgo_go_bool
8+
typedef Sint32 SDL_FingerID;
9+
typedef Sint32 SDL_Scancode;
10+
typedef Sint32 SDL_Keymod;
11+
typedef Sint32 SDL_BlendMode;
12+
typedef Sint32 SDL_TimerID;
13+
14+
15+
#define SDL_TRUE 1
16+
#define SDL_FALSE 0
17+
const Sint32 SDL_PIXELFORMAT_RGBA5551 = 1;
18+
const Sint32 SDL_PIXELFORMAT_RGB565 = 2;
19+
const Sint32 SDL_PIXELFORMAT_RGB555 = 3;
20+
21+
const Sint32 SDL_RENDERER_ACCELERATED = 1;
22+
const Sint32 SDL_RENDERER_PRESENTVSYNC = 2;
23+
24+
#define SDL_NUM_SCANCODES 512
25+
26+
typedef struct{
27+
Sint16 x, y;
28+
Uint16 w, h;
29+
} SDL_Rect;
30+
31+
#define SDL_TEXTEDITING 770
32+
#define SDL_TEXTINPUT 771
33+
#define SDL_KEYDOWN 768
34+
#define SDL_KEYUP 769
35+
#define SDL_MOUSEBUTTONDOWN 1025
36+
#define SDL_MOUSEBUTTONUP 1026
37+
#define SDL_MOUSEMOTION 1024
38+
#define SDL_MOUSEWHEEL 1027
39+
#define SDL_WINDOWEVENT 512
40+
41+
#define SDL_WINDOWEVENT_FOCUS_LOST 13
42+
#define SDL_WINDOWEVENT_FOCUS_GAINED 12
43+
44+
#define SDL_BUTTON_LEFT 1
45+
#define SDL_BUTTON_RIGHT 3
46+
#define SDL_BUTTON_MIDDLE 2
47+
48+
const Sint32 SDL_PRESSED = 1;
49+
50+
const Sint32 SDL_SCANCODE_SPACE = 1;
51+
const Sint32 KMOD_LSHIFT = 1;
52+
const Sint32 KMOD_RSHIFT = 2;
53+
const Sint32 KMOD_RALT = 3;
54+
55+
const Uint32 SDL_INIT_VIDEO = 1;
56+
const Uint32 SDL_INIT_TIMER = 2;
57+
const Sint32 SDL_WINDOWPOS_UNDEFINED = -1;
58+
const Sint32 SDL_WINDOWPOS_CENTERED = -2;
59+
const Uint32 SDL_WINDOW_RESIZABLE = 1;
60+
const Uint32 SDL_WINDOW_OPENGL = 2;
61+
const SDL_BlendMode SDL_BLENDMODE_NONE = 1;
62+
63+
typedef struct{
64+
SDL_Scancode scancode;
65+
} SDL_Keysym;
66+
67+
typedef struct{
68+
SDL_Keysym keysym;
69+
Uint8 state;
70+
} SDL_KeyboardEvent;
71+
72+
typedef struct{
73+
Uint8 button;
74+
Uint8 state;
75+
Sint32 x,y;
76+
} SDL_MouseButtonEvent;
77+
78+
typedef struct{
79+
Sint32 x, y;
80+
Sint32 xrel, yrel;
81+
} SDL_MouseMotionEvent;
82+
83+
typedef struct{
84+
Sint32 x, y;
85+
} SDL_MouseWheelEvent;
86+
87+
typedef struct{} SDL_TouchFingerEvent;
88+
89+
typedef struct{
90+
char text[32];
91+
} SDL_TextEditingEvent;
92+
93+
typedef struct{
94+
char text[32];
95+
} SDL_TextInputEvent;
96+
97+
typedef struct{
98+
Uint8 event;
99+
} SDL_WindowEvent;
100+
101+
typedef struct{
102+
int type;
103+
SDL_TextEditingEvent edit;
104+
SDL_TextInputEvent text;
105+
SDL_KeyboardEvent key;
106+
SDL_MouseButtonEvent button;
107+
SDL_MouseMotionEvent motion;
108+
SDL_MouseWheelEvent wheel;
109+
SDL_WindowEvent window;
110+
} SDL_Event;
111+
112+
const Uint32 SDL_WINDOW_FULLSCREEN_DESKTOP = 0;
113+
114+
typedef struct SDL_GLContext {} SDL_GLContext;
115+
116+
typedef struct SDL_Window {
117+
Sint32 (*SetFullscreen)(Uint32 flags);
118+
void (*GetSize)(Sint32 *w, Sint32 *h);
119+
void (*GetPosition)(Sint32 *x, Sint32 *y);
120+
void (*SetSize)(Sint32 w, Sint32 h);
121+
void (*SetPosition)(Sint32 x, Sint32 y);
122+
void (*Minimize)(void);
123+
void (*Restore)(void);
124+
void (*SetGrab)(SDL_bool);
125+
void (*SetResizable)(SDL_bool);
126+
void (*SetBordered)(SDL_bool);
127+
void (*SetTitle)(const char*);
128+
Sint32 (*GetDisplayIndex)(void);
129+
void (*GLGetDrawableSize)(Sint32* w, Sint32* h);
130+
void (*GLSwapWindow)(void);
131+
SDL_GLContext (*GLCreateContext)(void);
132+
} SDL_Window;
133+
134+
const char* SDL_GetError(void);
135+
136+
Uint32 SDL_GetTicks(void);
137+
SDL_Window* SDL_CreateWindow(const char* title, Sint32 x, Sint32 y, Sint32 w, Sint32 h, Uint32 flags);
138+
#define SDL_SetWindowFullscreen(win, flags) ((SDL_Window*)win)->SetFullscreen(flags)
139+
#define SDL_SetWindowSize(win, w, h) ((SDL_Window*)win)->SetSize(w, h)
140+
#define SDL_SetWindowPosition(win, x, y) ((SDL_Window*)win)->SetPosition(x, y)
141+
#define SDL_SetWindowGrab(win, v) ((SDL_Window*)win)->SetGrab(v)
142+
#define SDL_SetWindowTitle(win, v) ((SDL_Window*)win)->SetTitle(v)
143+
#define SDL_MinimizeWindow(win) ((SDL_Window*)win)->Minimize()
144+
#define SDL_RestoreWindow(win) ((SDL_Window*)win)->Restore()
145+
#define SDL_GetWindowDisplayIndex(win) ((SDL_Window*)win)->GetDisplayIndex()
146+
#define SDL_SetWindowResizable(win, v) ((SDL_Window*)win)->SetResizable(v)
147+
#define SDL_SetWindowBordered(win, v) ((SDL_Window*)win)->SetBordered(v)
148+
#define SDL_GetWindowPosition(win, x, y) ((SDL_Window*)win)->GetPosition(x, y)
149+
#define SDL_GetWindowSize(win, w, h) ((SDL_Window*)win)->GetSize(w, h)
150+
151+
#define SDL_GL_GetDrawableSize(win, w, h) ((SDL_Window*)win)->GLGetDrawableSize(w, h)
152+
#define SDL_GL_SwapWindow(win) ((SDL_Window*)win)->GLSwap()
153+
#define SDL_GL_CreateContext(win) ((SDL_Window*)win)->GLCreateContext()
154+
155+
typedef struct SDL_Renderer {
156+
void (*Destroy)(void);
157+
void (*Present)(void);
158+
} SDL_Renderer;
159+
160+
SDL_Renderer* SDL_CreateRenderer(SDL_Window* window, Sint32 index, Uint32 flags);
161+
162+
#define SDL_RenderPresent(r) ((SDL_Renderer*)r)->Present()
163+
#define SDL_DestroyRenderer(r) ((SDL_Renderer*)r)->Destroy()
164+
165+
char *SDL_itoa(Sint32 value, char *str, Sint32 radix);
166+
char *SDL_uitoa(Uint32 value, char *str, Sint32 radix);
167+
void SDL_Delay(Uint32 ms);
168+
169+
typedef struct SDL_mutex {
170+
void (*Lock)(void);
171+
void (*Unlock)(void);
172+
void (*Destroy)(void);
173+
} SDL_mutex;
174+
175+
SDL_mutex* SDL_CreateMutex(void);
176+
177+
#define SDL_DestroyMutex(m) ((SDL_mutex*)m)->Destroy()
178+
#define SDL_LockMutex(m) ((SDL_mutex*)m)->Lock()
179+
#define SDL_UnlockMutex(m) ((SDL_mutex*)m)->Unlock()
180+
181+
182+
typedef struct SDL_Surface {
183+
Sint32 w, h;
184+
Sint32 pitch;
185+
void* pixels;
186+
SDL_Rect clip_rect;
187+
188+
Sint32 (*Lock)(void);
189+
void (*Unlock)(void);
190+
void (*Free)(void);
191+
Sint32 (*SetColorKey)(Sint32 flag, Uint32 key);
192+
void (*GetClipRect)(SDL_Rect* rect);
193+
Sint32 (*SetBlendMode)(SDL_BlendMode blendMode);
194+
} SDL_Surface;
195+
196+
SDL_Surface* SDL_CreateRGBSurfaceWithFormat(Uint32 flags, Sint32 width, Sint32 height, Sint32 depth, Uint32 format);
197+
198+
#define SDL_LockSurface(s) ((SDL_Surface*)s)->Lock()
199+
#define SDL_UnlockSurface(s) ((SDL_Surface*)s)->Unlock()
200+
#define SDL_FreeSurface(s) ((SDL_Surface*)s)->Free()
201+
#define SDL_SetColorKey(s, f, k) ((SDL_Surface*)s)->SetColorKey(f, k)
202+
#define SDL_GetClipRect(s, r) ((SDL_Surface*)s)->GetClipRect(r)
203+
#define SDL_SetSurfaceBlendMode(s, m) ((SDL_Surface*)s)->SetBlendMode(m)
204+
Sint32 SDL_BlitSurface(SDL_Surface* src, const SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect);
205+
Sint32 SDL_BlitScaled(SDL_Surface* src, const SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect);
206+
207+
typedef struct SDL_Texture {
208+
void (*Destroy)(void);
209+
} SDL_Texture;
210+
SDL_Texture* SDL_CreateTextureFromSurface(SDL_Renderer* renderer, SDL_Surface* surface);
211+
#define SDL_DestroyTexture(t) ((SDL_Texture*)t)->Destroy()
212+
213+
Sint32 SDL_RenderCopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srcrect, const SDL_Rect* dstrect);
214+
215+
216+
Sint32 SDL_GL_SetSwapInterval(Sint32 interval);
217+
void SDL_GL_DeleteContext(SDL_GLContext context);
218+
Sint32 SDL_Init(Uint32 flags);
219+
Sint32 SDL_PollEvent(SDL_Event* event);
220+
void SDL_StartTextInput(void);
221+
void SDL_StopTextInput(void);
222+
SDL_Keymod SDL_GetModState(void);
223+
Sint32 SDL_SetRelativeMouseMode(SDL_bool enabled);
224+
Uint8 SDL_GetEventState(Uint32 type);
225+
Uint32 SDL_GetGlobalMouseState(int* x, int* y);
226+
Sint32 SDL_GetDisplayBounds(Sint32 displayIndex, SDL_Rect* rect);
227+
228+
typedef Uint32 (*SDL_TimerCallback)(Uint32 interval, void* param);
229+
SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void* param);
230+
SDL_bool SDL_RemoveTimer(SDL_TimerID id);

libs/includes/SDL2/SDL_opengl.h

Whitespace-only changes.

libs/includes/SDL2/SDL_opengl_glext.h

Whitespace-only changes.

libs/includes/SDL2/SDL_stdinc.h

Whitespace-only changes.
File renamed without changes.

libs/includes/ctype.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
_cxgo_go_bool isalnum(_cxgo_go_rune);
2+
_cxgo_go_bool isalpha(_cxgo_go_rune);
3+
_cxgo_go_bool isascii(_cxgo_go_rune);
4+
_cxgo_go_bool iscntrl(_cxgo_go_rune);
5+
_cxgo_go_bool isdigit(_cxgo_go_rune);
6+
_cxgo_go_bool isgraph(_cxgo_go_rune);
7+
_cxgo_go_bool islower(_cxgo_go_rune);
8+
_cxgo_go_bool isprint(_cxgo_go_rune);
9+
_cxgo_go_bool ispunct(_cxgo_go_rune);
10+
_cxgo_go_bool isspace(_cxgo_go_rune);
11+
_cxgo_go_bool isupper(_cxgo_go_rune);
12+
_cxgo_go_bool isxdigit(_cxgo_go_rune);
13+
_cxgo_go_rune toascii(_cxgo_go_rune);
14+
_cxgo_go_rune tolower(_cxgo_go_rune);
15+
_cxgo_go_rune toupper(_cxgo_go_rune);
File renamed without changes.
File renamed without changes.

libs/includes/fenv.h

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const _cxgo_go_int FE_TOWARDZERO = 1;
2+
_cxgo_sint32 fesetround(_cxgo_sint32 round);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

libs/includes/pthread.h

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <cxgo_builtin.h>
21
#include <time.h>
32

43
const _cxgo_go_int PTHREAD_MUTEX_RECURSIVE = 1;
File renamed without changes.
File renamed without changes.

libs/includes/setjmp.h

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#include <cxgo_builtin.h>
2-
31
typedef struct jmp_buf {
42
_cxgo_go_int (*SetJump) ();
53
void (*LongJump) (_cxgo_go_int);
File renamed without changes.

libs/includes/stdarg.h

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#include <cxgo_builtin.h>
2-
31
#define va_list __builtin_va_list
42
#define va_start(va, t) va.Start(t, _rest)
53
#define va_arg(va, typ) (typ)(va.Arg())

libs/includes/stdlib.h

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <cxgo_builtin.h>
21
#include <stddef.h>
32

43
#define EXIT_FAILURE 1

libs/includes/string.h

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <cxgo_builtin.h>
21
#include <stddef.h>
32
#include <stdlib.h>
43

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

libs/includes/sys_types.h libs/includes/sys/types.h

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <cxgo_builtin.h>
21
#include <stddef.h>
32
#include <time.h>
43

0 commit comments

Comments
 (0)