agar

Check-in [e08bcf4470]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Indirect variable support
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:e08bcf447052a7c3134ff74deeefcad615cfecbd
User & Date: murphy 2016-09-25 10:50:24
Context
2016-09-25
12:05
Access to child objects check-in: b31d8954f0 user: murphy tags: trunk
10:50
Indirect variable support check-in: e08bcf4470 user: murphy tags: trunk
10:18
Checkboxes, radio buttons and small tweaks check-in: 39b15b34a1 user: murphy tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to agar.scm.

171
172
173
174
175
176
177


178
179
180
181
182
183
184
185




186
187
188
189




190
191
192
193




194
195
196
197




198
199
200
201




202
203
204
205




206
207
208
209




210
211
212
213




214
215
216
217




218
219
220
221




222
223
224
225




226
227
228
229




230
231
232




233
234
235
236




237
238
239
240
241
242
243




244
245
246
247




248
249
250
251




252
253
254
255




256
257
258
259




260
261
262
263




264
265
266
267




268
269
270
271




272
273
274
275




276
277
278
279




280
281
282
283




284
285
286
287




288
289
290
291
292
293






294
295
296
297




298
299
300
301
302
303
304
    "av[3] = C_fix(cls->ver.minor);\n"
    "C_values(4, av);\n"))

(define var-type
  (foreign-lambda* int ([(nonnull-c-pointer "AG_Variable") var])
    "C_return(var->type);"))



(define (var-ref var)
  (select (var-type var)
    [((foreign-value "AG_VARIABLE_NULL" int))
     #f]
    [((foreign-value "AG_VARIABLE_UINT" int))
     ((foreign-lambda* unsigned-int ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.u);")
      var)]




    [((foreign-value "AG_VARIABLE_INT" int))
     ((foreign-lambda* int ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.i);")
      var)]




    [((foreign-value "AG_VARIABLE_UINT8" int))
     ((foreign-lambda* unsigned-byte ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.u8);")
      var)]




    [((foreign-value "AG_VARIABLE_SINT8" int))
     ((foreign-lambda* byte ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.s8);")
      var)]




    [((foreign-value "AG_VARIABLE_UINT16" int))
     ((foreign-lambda* unsigned-short ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.u16);")
      var)]




    [((foreign-value "AG_VARIABLE_SINT16" int))
     ((foreign-lambda* short ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.s16);")
      var)]




    [((foreign-value "AG_VARIABLE_UINT32" int))
     ((foreign-lambda* unsigned-integer32 ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.u32);")
      var)]




    [((foreign-value "AG_VARIABLE_SINT32" int))
     ((foreign-lambda* integer32 ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.s32);")
      var)]




    [((foreign-value "AG_VARIABLE_UINT64" int))
     ((foreign-lambda* unsigned-integer64 ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.u64);")
      var)]




    [((foreign-value "AG_VARIABLE_SINT64" int))
     ((foreign-lambda* integer64 ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.s64);")
      var)]




    [((foreign-value "AG_VARIABLE_FLOAT" int))
     ((foreign-lambda* float ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.flt);")
      var)]




    [((foreign-value "AG_VARIABLE_DOUBLE" int))
     ((foreign-lambda* double ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.dbl);")
      var)]




    [((foreign-value "AG_VARIABLE_STRING" int) (foreign-value "AG_VARIABLE_CONST_STRING" int))
     ((foreign-lambda* c-string ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.Cs);")




      var)]
    [((foreign-value "AG_VARIABLE_POINTER" int) (foreign-value "AG_VARIABLE_CONST_POINTER" int))
     ((foreign-lambda* c-pointer ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.Cp);")




      var)]))

(define (var-set! var v)
  (select (var-type var)
    [((foreign-value "AG_VARIABLE_UINT" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [unsigned-int v])
        "var->data.u = v;")




      var v)]
    [((foreign-value "AG_VARIABLE_INT" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [int v])
        "var->data.i = v;")




      var v)]
    [((foreign-value "AG_VARIABLE_UINT8" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [unsigned-byte v])
        "var->data.u8 = v;")




      var v)]
    [((foreign-value "AG_VARIABLE_SINT8" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [byte v])
        "var->data.s8 = v;")




      var v)]
    [((foreign-value "AG_VARIABLE_UINT16" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [unsigned-short v])
        "var->data.u16 = v;")




      var v)]
    [((foreign-value "AG_VARIABLE_SINT16" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [short v])
        "var->data.s16 = v;")




      var v)]
    [((foreign-value "AG_VARIABLE_UINT32" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [unsigned-integer32 v])
        "var->data.u32 = v;")




      var v)]
    [((foreign-value "AG_VARIABLE_SINT32" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [integer32 v])
        "var->data.s32 = v;")




      var v)]
    [((foreign-value "AG_VARIABLE_UINT64" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [unsigned-integer64 v])
        "var->data.u64 = v;")




      var v)]
    [((foreign-value "AG_VARIABLE_SINT64" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [integer64 v])
        "var->data.s64 = v;")




      var v)]
    [((foreign-value "AG_VARIABLE_FLOAT" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [float v])
        "var->data.flt = v;")




      var v)]
    [((foreign-value "AG_VARIABLE_DOUBLE" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [double v])
        "var->data.dbl = v;")




      var v)]
    [((foreign-value "AG_VARIABLE_STRING" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [c-string v])
        "char *old = var->data.s;\n"
        "var->data.s = AG_Strdup(v);\n"
        "if (old) AG_Free(old);\n")






      var v)]
    [((foreign-value "AG_VARIABLE_POINTER" int) (foreign-value "AG_VARIABLE_CONST_POINTER" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [c-pointer v])
        "var->data.p = v;")




      var v)]))

(define object-var
  (foreign-safe-lambda (c-pointer "AG_Variable") "AG_GetVariable" nonnull-object nonnull-c-string c-pointer))

(define-values (object-ref object-set!)
  (let ([object-ref







>
>








>
>
>
>




>
>
>
>




>
>
>
>




>
>
>
>




>
>
>
>




>
>
>
>




>
>
>
>




>
>
>
>




>
>
>
>




>
>
>
>




>
>
>
>




>
>
>
>



>
>
>
>




>
>
>
>







>
>
>
>




>
>
>
>




>
>
>
>




>
>
>
>




>
>
>
>




>
>
>
>




>
>
>
>




>
>
>
>




>
>
>
>




>
>
>
>




>
>
>
>




>
>
>
>






>
>
>
>
>
>




>
>
>
>







171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
    "av[3] = C_fix(cls->ver.minor);\n"
    "C_values(4, av);\n"))

(define var-type
  (foreign-lambda* int ([(nonnull-c-pointer "AG_Variable") var])
    "C_return(var->type);"))

(foreign-declare "#include <agar/core/types.h>")

(define (var-ref var)
  (select (var-type var)
    [((foreign-value "AG_VARIABLE_NULL" int))
     #f]
    [((foreign-value "AG_VARIABLE_UINT" int))
     ((foreign-lambda* unsigned-int ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.u);")
      var)]
    [((foreign-value "AG_VARIABLE_P_UINT" int))
     ((foreign-lambda* unsigned-int ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(*(const Uint *)var->data.Cp);")
      var)]
    [((foreign-value "AG_VARIABLE_INT" int))
     ((foreign-lambda* int ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.i);")
      var)]
    [((foreign-value "AG_VARIABLE_P_INT" int))
     ((foreign-lambda* int ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(*(const int *)var->data.Cp);")
      var)]
    [((foreign-value "AG_VARIABLE_UINT8" int))
     ((foreign-lambda* unsigned-byte ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.u8);")
      var)]
    [((foreign-value "AG_VARIABLE_P_UINT8" int))
     ((foreign-lambda* unsigned-byte ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(*(const Uint8 *)var->data.Cp);")
      var)]
    [((foreign-value "AG_VARIABLE_SINT8" int))
     ((foreign-lambda* byte ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.s8);")
      var)]
    [((foreign-value "AG_VARIABLE_P_SINT8" int))
     ((foreign-lambda* byte ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(*(const Sint8 *)var->data.Cp);")
      var)]
    [((foreign-value "AG_VARIABLE_UINT16" int))
     ((foreign-lambda* unsigned-short ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.u16);")
      var)]
    [((foreign-value "AG_VARIABLE_P_UINT16" int))
     ((foreign-lambda* unsigned-short ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(*(const Uint16 *)var->data.Cp);")
      var)]
    [((foreign-value "AG_VARIABLE_SINT16" int))
     ((foreign-lambda* short ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.s16);")
      var)]
    [((foreign-value "AG_VARIABLE_P_SINT16" int))
     ((foreign-lambda* short ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(*(const Sint16 *)var->data.Cp);")
      var)]
    [((foreign-value "AG_VARIABLE_UINT32" int))
     ((foreign-lambda* unsigned-integer32 ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.u32);")
      var)]
    [((foreign-value "AG_VARIABLE_P_UINT32" int))
     ((foreign-lambda* unsigned-integer32 ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(*(const Uint32 *)var->data.Cp);")
      var)]
    [((foreign-value "AG_VARIABLE_SINT32" int))
     ((foreign-lambda* integer32 ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.s32);")
      var)]
    [((foreign-value "AG_VARIABLE_P_SINT32" int))
     ((foreign-lambda* integer32 ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(*(const Sint32 *)var->data.Cp);")
      var)]
    [((foreign-value "AG_VARIABLE_UINT64" int))
     ((foreign-lambda* unsigned-integer64 ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.u64);")
      var)]
    [((foreign-value "AG_VARIABLE_P_UINT64" int))
     ((foreign-lambda* unsigned-integer64 ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(*(const Uint64 *)var->data.Cp);")
      var)]
    [((foreign-value "AG_VARIABLE_SINT64" int))
     ((foreign-lambda* integer64 ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.s64);")
      var)]
    [((foreign-value "AG_VARIABLE_P_SINT64" int))
     ((foreign-lambda* integer64 ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(*(const Sint64 *)var->data.Cp);")
      var)]
    [((foreign-value "AG_VARIABLE_FLOAT" int))
     ((foreign-lambda* float ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.flt);")
      var)]
    [((foreign-value "AG_VARIABLE_P_FLOAT" int))
     ((foreign-lambda* float ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(*(const float *)var->data.Cp);")
      var)]
    [((foreign-value "AG_VARIABLE_DOUBLE" int))
     ((foreign-lambda* double ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.dbl);")
      var)]
    [((foreign-value "AG_VARIABLE_P_DOUBLE" int))
     ((foreign-lambda* double ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(*(const double *)var->data.Cp);")
      var)]
    [((foreign-value "AG_VARIABLE_STRING" int) (foreign-value "AG_VARIABLE_CONST_STRING" int))
     ((foreign-lambda* c-string ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.Cs);")
      var)]
    [((foreign-value "AG_VARIABLE_P_STRING" int) (foreign-value "AG_VARIABLE_P_CONST_STRING" int))
     ((foreign-lambda* c-string ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(*(const char *const *)var->data.Cp);")
      var)]
    [((foreign-value "AG_VARIABLE_POINTER" int) (foreign-value "AG_VARIABLE_CONST_POINTER" int))
     ((foreign-lambda* c-pointer ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(var->data.Cp);")
      var)]
    [((foreign-value "AG_VARIABLE_P_POINTER" int) (foreign-value "AG_VARIABLE_P_CONST_POINTER" int))
     ((foreign-lambda* c-pointer ([(nonnull-c-pointer "AG_Variable") var])
        "C_return(*(const void *const *)var->data.Cp);")
      var)]))

(define (var-set! var v)
  (select (var-type var)
    [((foreign-value "AG_VARIABLE_UINT" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [unsigned-int v])
        "var->data.u = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_P_UINT" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [unsigned-int v])
        "*(Uint *)var->data.p = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_INT" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [int v])
        "var->data.i = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_P_INT" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [int v])
        "*(int *)var->data.p = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_UINT8" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [unsigned-byte v])
        "var->data.u8 = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_P_UINT8" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [unsigned-byte v])
        "*(Uint8 *)var->data.p = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_SINT8" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [byte v])
        "var->data.s8 = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_P_SINT8" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [byte v])
        "*(Sint8 *)var->data.p = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_UINT16" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [unsigned-short v])
        "var->data.u16 = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_P_UINT16" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [unsigned-short v])
        "*(Uint16 *)var->data.p = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_SINT16" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [short v])
        "var->data.s16 = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_P_SINT16" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [short v])
        "*(Sint16 *)var->data.p = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_UINT32" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [unsigned-integer32 v])
        "var->data.u32 = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_P_UINT32" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [unsigned-integer32 v])
        "*(Uint32 *)var->data.p = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_SINT32" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [integer32 v])
        "var->data.s32 = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_P_SINT32" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [integer32 v])
        "*(Sint32 *)var->data.p = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_UINT64" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [unsigned-integer64 v])
        "var->data.u64 = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_P_UINT64" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [unsigned-integer64 v])
        "*(Uint64 *)var->data.p = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_SINT64" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [integer64 v])
        "var->data.s64 = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_P_SINT64" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [integer64 v])
        "*(Sint64 *)var->data.p = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_FLOAT" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [float v])
        "var->data.flt = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_P_FLOAT" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [float v])
        "*(float *)var->data.p = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_DOUBLE" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [double v])
        "var->data.dbl = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_P_DOUBLE" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [double v])
        "*(double *)var->data.p = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_STRING" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [c-string v])
        "char *old = var->data.s;\n"
        "var->data.s = AG_Strdup(v);\n"
        "if (old) AG_Free(old);\n")
      var v)]
    [((foreign-value "AG_VARIABLE_P_STRING" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [c-string v])
        "char *old = *(char **)var->data.p;\n"
        "*(char **)var->data.p = AG_Strdup(v);\n"
        "if (old) AG_Free(old);\n")
      var v)]
    [((foreign-value "AG_VARIABLE_POINTER" int) (foreign-value "AG_VARIABLE_CONST_POINTER" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [c-pointer v])
        "var->data.p = v;")
      var v)]
    [((foreign-value "AG_VARIABLE_P_POINTER" int) (foreign-value "AG_VARIABLE_P_CONST_POINTER" int))
     ((foreign-lambda* void ([(nonnull-c-pointer "AG_Variable") var] [c-pointer v])
        "*(void **)var->data.p = v;")
      var v)]))

(define object-var
  (foreign-safe-lambda (c-pointer "AG_Variable") "AG_GetVariable" nonnull-object nonnull-c-string c-pointer))

(define-values (object-ref object-set!)
  (let ([object-ref