wasm shell + destructuring
This commit is contained in:
@@ -296,6 +296,13 @@ Builder :: struct {
|
||||
}
|
||||
}
|
||||
|
||||
// Global variable for address-of test
|
||||
g_smoke_val : s32 = 42;
|
||||
|
||||
write_to_ptr :: (p: *s32) {
|
||||
p.* = 99;
|
||||
}
|
||||
|
||||
main :: () {
|
||||
|
||||
// ========================================================
|
||||
@@ -724,6 +731,10 @@ END;
|
||||
print("str-suffix: {}\n", msg[6..]);
|
||||
|
||||
// --- Pointers ---
|
||||
// Address-of global variable
|
||||
write_to_ptr(@g_smoke_val);
|
||||
print("global-addr-of: {}\n", g_smoke_val);
|
||||
|
||||
pv := Point.{ 10, 20 };
|
||||
ptr := @pv;
|
||||
print("deref: {}\n", ptr.*);
|
||||
@@ -750,6 +761,13 @@ END;
|
||||
print("ptr2==null: {}\n", np2 == null);
|
||||
print("ptr2!=null: {}\n", np2 != null);
|
||||
|
||||
// Pointer to nested struct field
|
||||
Inner3 :: struct { a: f32; b: f32; c: f32; }
|
||||
Outer3 :: struct { key: s32; inner: Inner3; }
|
||||
out3 := Outer3.{ key = 42, inner = Inner3.{ a = 1.0, b = 2.0, c = 3.0 } };
|
||||
ip3 := @out3.inner;
|
||||
print("ptr-nested-field: {} {} {}\n", ip3.a, ip3.b, ip3.c);
|
||||
|
||||
// --- Vectors ---
|
||||
vc := vec3(1, 3, 2);
|
||||
print("vec-construct: {}\n", vc);
|
||||
@@ -1291,6 +1309,34 @@ END;
|
||||
print("3-way: {} {} {}\n", ra, rb, rc);
|
||||
}
|
||||
|
||||
// --- Tuple destructuring ---
|
||||
print("--- destructure ---\n");
|
||||
|
||||
// Basic tuple destructuring
|
||||
{
|
||||
da, db := (10, 20);
|
||||
print("basic: {} {}\n", da, db);
|
||||
}
|
||||
|
||||
// Destructure from function return
|
||||
{
|
||||
dswap :: (a: s64, b: s64) -> (s64, s64) { (b, a); }
|
||||
dx, dy := dswap(1, 2);
|
||||
print("fn: {} {}\n", dx, dy);
|
||||
}
|
||||
|
||||
// Discard with _
|
||||
{
|
||||
_, dsecond := (100, 200);
|
||||
print("discard: {}\n", dsecond);
|
||||
}
|
||||
|
||||
// Three elements
|
||||
{
|
||||
da3, db3, dc3 := (1, 2, 3);
|
||||
print("triple: {} {} {}\n", da3, db3, dc3);
|
||||
}
|
||||
|
||||
// ========================================================
|
||||
// 15. FOREIGN FUNCTION BINDING
|
||||
// ========================================================
|
||||
|
||||
@@ -8,6 +8,7 @@ POINTER_SIZE : s64 = 8;
|
||||
BuildOptions :: struct {
|
||||
add_link_flag :: (self: BuildOptions, flag: [:0]u8) #compiler;
|
||||
set_output_path :: (self: BuildOptions, path: [:0]u8) #compiler;
|
||||
set_wasm_shell :: (self: BuildOptions, path: [:0]u8) #compiler;
|
||||
}
|
||||
|
||||
build_options :: () -> BuildOptions #compiler;
|
||||
|
||||
@@ -86,6 +86,12 @@ glReadPixels : (s32, s32, s32, s32, u32, u32, *void) -> void = ---;
|
||||
glActiveTexture : (u32) -> void = ---;
|
||||
glUniform1i : (s32, s32) -> void = ---;
|
||||
glPixelStorei : (u32, s32) -> void = ---;
|
||||
glTexSubImage2D : (u32, s32, s32, s32, s32, s32, u32, u32, *void) -> void = ---;
|
||||
glDeleteTextures : (s32, *u32) -> void = ---;
|
||||
|
||||
GL_TEXTURE_WRAP_S :u32: 0x2802;
|
||||
GL_TEXTURE_WRAP_T :u32: 0x2803;
|
||||
GL_CLAMP_TO_EDGE :u32: 0x812F;
|
||||
|
||||
// Loader: call once after creating GL context
|
||||
// Pass in a proc loader (e.g. SDL_GL_GetProcAddress)
|
||||
@@ -133,6 +139,8 @@ load_gl :: (get_proc: ([*]u8) -> *void) {
|
||||
glActiveTexture = xx get_proc("glActiveTexture");
|
||||
glUniform1i = xx get_proc("glUniform1i");
|
||||
glPixelStorei = xx get_proc("glPixelStorei");
|
||||
glTexSubImage2D = xx get_proc("glTexSubImage2D");
|
||||
glDeleteTextures = xx get_proc("glDeleteTextures");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,9 @@ sdl3 :: #library "SDL3";
|
||||
SDL_INIT_VIDEO :u32: 0x20;
|
||||
|
||||
// SDL_WindowFlags
|
||||
SDL_WINDOW_OPENGL :u64: 0x2;
|
||||
SDL_WINDOW_OPENGL :u64: 0x2;
|
||||
SDL_WINDOW_RESIZABLE :u64: 0x20;
|
||||
SDL_WINDOW_HIGH_PIXEL_DENSITY :u64: 0x2000;
|
||||
|
||||
// SDL_GLAttr (enum starting at 0)
|
||||
SDL_GL_DOUBLEBUFFER :s32: 5;
|
||||
@@ -332,3 +334,16 @@ SDL_GL_GetProcAddress :: (proc: [:0]u8) -> *void #foreign sdl3;
|
||||
SDL_PollEvent :: (event: *SDL_Event) -> bool #foreign sdl3;
|
||||
SDL_GetTicks :: () -> u64 #foreign sdl3;
|
||||
SDL_Delay :: (ms: u32) -> void #foreign sdl3;
|
||||
SDL_GetWindowDisplayScale :: (window: *void) -> f32 #foreign sdl3;
|
||||
SDL_GetWindowSize :: (window: *void, w: *s32, h: *s32) -> bool #foreign sdl3;
|
||||
SDL_GetWindowSizeInPixels :: (window: *void, w: *s32, h: *s32) -> bool #foreign sdl3;
|
||||
|
||||
SDL_Rect :: struct {
|
||||
x: s32;
|
||||
y: s32;
|
||||
w: s32;
|
||||
h: s32;
|
||||
}
|
||||
|
||||
SDL_GetPrimaryDisplay :: () -> u32 #foreign sdl3;
|
||||
SDL_GetDisplayUsableBounds :: (display_id: u32, rect: *SDL_Rect) -> bool #foreign sdl3;
|
||||
|
||||
@@ -4,4 +4,7 @@
|
||||
|
||||
#include "vendors/file_utils/file_utils.h";
|
||||
#source "vendors/file_utils/file_utils.c";
|
||||
|
||||
#include "vendors/kb_text_shape/kbts_api.h";
|
||||
#source "vendors/kb_text_shape/kb_text_shape_impl.c";
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user