1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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;"))
|