From 5e764e9edd3c5e33fa9a384b49b74e5c4eb370a3 Mon Sep 17 00:00:00 2001 From: gonzo Date: Fri, 25 Oct 2024 19:20:18 +0200 Subject: first commit --- structs.scm | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 structs.scm (limited to 'structs.scm') diff --git a/structs.scm b/structs.scm new file mode 100644 index 0000000..44ed30b --- /dev/null +++ b/structs.scm @@ -0,0 +1,125 @@ +;;; ------- +;;; structs +;;; ------- + +;; Color, 4 components, R8G8B8A8 (32bit) +(c-define-type color (struct "Color")) + +;; color constructor +(define make-color + (c-lambda (unsigned-int8 unsigned-int8 unsigned-int8 unsigned-int8) color + #<< c-lambda + Color col = (Color){___arg1, ___arg2, ___arg3, ___arg4 }; + ___return(col); + c-lambda + )) + +;; color getters +(define color-red + (c-lambda (color) unsigned-int8 + #<< c-lambda + ___return(___arg1.r); + c-lambda + )) +(define color-blue + (c-lambda (color) unsigned-int8 + #<< c-lambda + ___return(___arg1.b); + c-lambda + )) +(define color-green + (c-lambda (color) unsigned-int8 + #<< c-lambda + ___return(___arg1.g); + c-lambda + )) +(define color-alpha + (c-lambda (color) unsigned-int8 + #<< c-lambda + ___return(___arg1.a); + c-lambda + )) + +;; color setters +(define color-red-set! + (c-lambda (color unsigned-int8) void + #<< c-lambda + ___arg1.r = ___arg2; + c-lambda + )) +(define color-blue-set! + (c-lambda (color unsigned-int8) void + #<< c-lambda + ___arg1.b = ___arg2; + c-lambda + )) +(define color-green-set! + (c-lambda (color unsigned-int8) void + #<< c-lambda + ___arg1.g = ___arg2; + c-lambda + )) +(define color-alpha-set! + (c-lambda (color unsigned-int8) void + #<< c-lambda + ___arg1.a = ___arg2; + c-lambda + )) + + +;; vector2, 2 float components, x32y32 (64 bits) +(c-define-type vec2 (struct "Vector2")) + +;; vec2 constructor +(define make-vec2 + (c-lambda (float float) vec2 + #<< c-lambda + Vector2 v = (Vector2){___arg1, ___arg2}; + ___return(v); + c-lambda + )) + +;; vec2 getters +(define vec2-x + (c-lambda (vec2) float "___return(___arg1.x);")) +(define vec2-y + (c-lambda (vec2) float "___return(___arg1.y);")) + +;; vec2 setters +(define vec2-x-set! + (c-lambda (vec2 float) void "___arg1.x = ___arg2;")) +(define vec2-y-set! + (c-lambda (vec2 float) void "___arg1.y = ___arg2;")) + + +;; Rectangle, 4 float components, x32y32w32h32 (128 bits) +(c-define-type rec (struct "Rectangle")) + +;; vec2 constructor +(define make-rec + (c-lambda (float float float float) rec + #<< c-lambda + Rectangle r = (Rectangle){___arg1, ___arg2, ___arg3, ___arg4}; + ___return(r); + c-lambda + )) + +;; vec2 getters +(define rec-x + (c-lambda (rec) float "___return(___arg1.x);")) +(define rec-y + (c-lambda (rec) float "___return(___arg1.y);")) +(define rec-width + (c-lambda (rec) float "___return(___arg1.width);")) +(define rec-height + (c-lambda (rec) float "___return(___arg1.height);")) + +;; vec2 setters +(define rec-x-set! + (c-lambda (rec float) void "___arg1.x = ___arg2;")) +(define rec-y-set! + (c-lambda (rec float) void "___arg1.y = ___arg2;")) +(define rec-width-set! + (c-lambda (rec float) void "___arg1.width = ___arg2;")) +(define rec-height-set! + (c-lambda (rec float) void "___arg1.height = ___arg2;")) -- cgit v1.2.3