Improvement for Chibi

This commit is contained in:
retropikzel 2025-01-24 21:17:18 +02:00
parent 9578cc9ee3
commit cf0f269110
3 changed files with 53 additions and 38 deletions

View File

@ -152,23 +152,37 @@ EXPORT struct test* init_struct(struct test* test) {
EXPORT int test_check(struct test* test) { EXPORT int test_check(struct test* test) {
print_offsets(); print_offsets();
printf("C: Value of a is %c\n", test->a);
assert(test->a == 1); assert(test->a == 1);
printf("C: Value of b is %c\n", test->b);
assert(test->b == 'b'); assert(test->b == 'b');
printf("C: Value of c is %lf\n", test->c);
assert(test->c == 3.0); assert(test->c == 3.0);
printf("C: Value of d is %c\n", test->d);
assert(test->d == 'd'); assert(test->d == 'd');
printf("C: Value of e is %s\n", test->e);
assert(test->e == NULL); assert(test->e == NULL);
printf("C: Value of f is %f\n", test->f);
assert(test->f == 6.0); assert(test->f == 6.0);
printf("C: Value of g is %f\n", test->g);
assert(strcmp(test->g, "foo") == 0); assert(strcmp(test->g, "foo") == 0);
printf("C: Value of g is %i\n", test->h);
assert(test->h == 8); assert(test->h == 8);
printf("C: Value of i is %s\n", test->i);
assert(test->i == NULL); assert(test->i == NULL);
printf("C: Value of j is %i\n", test->j);
assert(test->j == 10); assert(test->j == 10);
printf("C: Value of k is %i\n", test->k);
assert(test->k == 11); assert(test->k == 11);
printf("C: Value of l is %i\n", test->l);
assert(test->l == 12); assert(test->l == 12);
printf("C: Value of m is %i\n", test->m);
assert(test->m == 13); assert(test->m == 13);
printf("C: Value of n is %i\n", test->n);
assert(test->n == 14); assert(test->n == 14);
} }
EXPORT struct test* test_new(struct test* test) { EXPORT struct test* test_n1ew(struct test* test) {
print_offsets(); print_offsets();
struct test* t = malloc(sizeof(struct test)); struct test* t = malloc(sizeof(struct test));
t->a = 1; t->a = 1;

View File

@ -65,47 +65,47 @@
(define-c void (pointer-free pointer_free) ((maybe-null void*))) (define-c void (pointer-free pointer_free) ((maybe-null void*)))
;; pffi-pointer-set! ;; pffi-pointer-set!
(c-declare "void pointer_set_c_int8_t(void* pointer, int offset, int8_t value) { int8_t* p = (int8_t*)pointer; p[offset] = value; }") (c-declare "void pointer_set_c_int8_t(void* pointer, int offset, int8_t value) { *(int8_t*)((char*)pointer + offset) = value; }")
(define-c void (pointer-set-c-int8_t! pointer_set_c_int8_t) ((pointer void*) int int8_t)) (define-c void (pointer-set-c-int8_t! pointer_set_c_int8_t) ((pointer void*) int int8_t))
(c-declare "void pointer_set_c_uint8_t(void* pointer, int offset, uint8_t value) { uint8_t* p = (uint8_t*)pointer; p[offset] = value; }") (c-declare "void pointer_set_c_uint8_t(void* pointer, int offset, uint8_t value) { *(uint8_t*)((char*)pointer + offset) = value; }")
(define-c void (pointer-set-c-uint8_t! pointer_set_c_uint8_t) ((pointer void*) int uint8_t)) (define-c void (pointer-set-c-uint8_t! pointer_set_c_uint8_t) ((pointer void*) int uint8_t))
(c-declare "void pointer_set_c_int16_t(void* pointer, int offset, int16_t value) { int16_t* p = (int16_t*)pointer; p[offset] = value; }") (c-declare "void pointer_set_c_int16_t(void* pointer, int offset, int16_t value) { *(int16_t*)((char*)pointer + offset) = value; }")
(define-c void (pointer-set-c-int16_t! pointer_set_c_int16_t) ((pointer void*) int int16_t)) (define-c void (pointer-set-c-int16_t! pointer_set_c_int16_t) ((pointer void*) int int16_t))
(c-declare "void pointer_set_c_uint16_t(void* pointer, int offset, uint16_t value) { uint16_t* p = (uint16_t*)pointer; p[offset] = value; }") (c-declare "void pointer_set_c_uint16_t(void* pointer, int offset, uint16_t value) { *(uint16_t*)((char*)pointer + offset) = value; }")
(define-c void (pointer-set-c-uint16_t! pointer_set_c_uint16_t) ((pointer void*) int uint16_t)) (define-c void (pointer-set-c-uint16_t! pointer_set_c_uint16_t) ((pointer void*) int uint16_t))
(c-declare "void pointer_set_c_int32_t(void* pointer, int offset, int32_t value) { int32_t* p = (int32_t*)pointer; p[offset] = value; }") (c-declare "void pointer_set_c_int32_t(void* pointer, int offset, int32_t value) { *(int32_t*)((char*)pointer + offset) = value; }")
(define-c void (pointer-set-c-int32_t! pointer_set_c_int32_t) ((pointer void*) int int32_t)) (define-c void (pointer-set-c-int32_t! pointer_set_c_int32_t) ((pointer void*) int int32_t))
(c-declare "void pointer_set_c_uint32_t(void* pointer, int offset, uint32_t value) { uint32_t* p = (uint32_t*)pointer; p[offset] = value; }") (c-declare "void pointer_set_c_uint32_t(void* pointer, int offset, uint32_t value) { *(uint32_t*)((char*)pointer + offset) = value; }")
(define-c void (pointer-set-c-uint32_t! pointer_set_c_uint32_t) ((pointer void*) int uint32_t)) (define-c void (pointer-set-c-uint32_t! pointer_set_c_uint32_t) ((pointer void*) int uint32_t))
(c-declare "void pointer_set_c_int64_t(void* pointer, int offset, int64_t value) { int64_t* p = (int64_t*)pointer; p[offset] = value; }") (c-declare "void pointer_set_c_int64_t(void* pointer, int offset, int64_t value) { *(int64_t*)((char*)pointer + offset) = value; }")
(define-c void (pointer-set-c-int64_t! pointer_set_c_int64_t) ((pointer void*) int int64_t)) (define-c void (pointer-set-c-int64_t! pointer_set_c_int64_t) ((pointer void*) int int64_t))
(c-declare "void pointer_set_c_uint64_t(void* pointer, int offset, uint64_t value) { uint64_t* p = (uint64_t*)pointer; p[offset] = value; }") (c-declare "void pointer_set_c_uint64_t(void* pointer, int offset, uint64_t value) { *(uint64_t*)((char*)pointer + offset) = value; }")
(define-c void (pointer-set-c-uint64_t! pointer_set_c_uint64_t) ((pointer void*) int uint64_t)) (define-c void (pointer-set-c-uint64_t! pointer_set_c_uint64_t) ((pointer void*) int uint64_t))
(c-declare "void pointer_set_c_char(void* pointer, int offset, char value) { char* p = (char*)pointer; p[offset] = value; }") (c-declare "void pointer_set_c_char(void* pointer, int offset, char value) { *((char*)pointer + offset) = value; }")
(define-c void (pointer-set-c-char! pointer_set_c_char) ((pointer void*) int char)) (define-c void (pointer-set-c-char! pointer_set_c_char) ((pointer void*) int char))
(c-declare "void pointer_set_c_unsigned_char(void* pointer, int offset, unsigned char value) { unsigned char* p = (unsigned char*)pointer; p[offset] = value; }") (c-declare "void pointer_set_c_unsigned_char(void* pointer, int offset, unsigned char value) { *(unsigned char*)((char*)pointer + offset) = value; }")
(define-c void (pointer-set-c-unsigned-char! pointer_set_c_unsigned_char) ((pointer void*) int unsigned-char)) (define-c void (pointer-set-c-unsigned-char! pointer_set_c_unsigned_char) ((pointer void*) int unsigned-char))
(c-declare "void pointer_set_c_short(void* pointer, int offset, short value) { short* p = (short*)pointer; p[offset] = value; }") (c-declare "void pointer_set_c_short(void* pointer, int offset, short value) { *(short*)((char*)pointer + offset) = value; }")
(define-c void (pointer-set-c-short! pointer_set_c_short) ((pointer void*) int short)) (define-c void (pointer-set-c-short! pointer_set_c_short) ((pointer void*) int short))
(c-declare "void pointer_set_c_unsigned_short(void* pointer, int offset, unsigned short value) { short* p = (unsigned short*)pointer; p[offset] = value; }") (c-declare "void pointer_set_c_unsigned_short(void* pointer, int offset, unsigned short value) { *(unsigned short*)((char*)pointer + offset) = value; }")
(define-c void (pointer-set-c-unsigned-short! pointer_set_c_unsigned_short) ((pointer void*) int unsigned-short)) (define-c void (pointer-set-c-unsigned-short! pointer_set_c_unsigned_short) ((pointer void*) int unsigned-short))
(c-declare "void pointer_set_c_int(void* pointer, int offset, int value) { int* p = (int*)pointer; p[offset] = value; }") (c-declare "void pointer_set_c_int(void* pointer, int offset, int value) { *(int*)((char*)pointer + offset) = value; }")
(define-c void (pointer-set-c-int! pointer_set_c_int) ((pointer void*) int int)) (define-c void (pointer-set-c-int! pointer_set_c_int) ((pointer void*) int int))
(c-declare "void pointer_set_c_unsigned_int(void* pointer, int offset, unsigned int value) { int* p = (unsigned int*)pointer; p[offset] = value; }") (c-declare "void pointer_set_c_unsigned_int(void* pointer, int offset, unsigned int value) { *(unsigned int*)((char*)pointer + offset) = value; }")
(define-c void (pointer-set-c-unsigned-int! pointer_set_c_unsigned_int) ((pointer void*) int unsigned-int)) (define-c void (pointer-set-c-unsigned-int! pointer_set_c_unsigned_int) ((pointer void*) int unsigned-int))
(c-declare "void pointer_set_c_long(void* pointer, int offset, long value) { long* p = (long*)pointer; p[offset] = value; }") (c-declare "void pointer_set_c_long(void* pointer, int offset, long value) { *(long*)((char*)pointer + offset) = value; }")
(define-c void (pointer-set-c-long! pointer_set_c_long) ((pointer void*) int long)) (define-c void (pointer-set-c-long! pointer_set_c_long) ((pointer void*) int long))
(c-declare "void pointer_set_c_unsigned_long(void* pointer, int offset, unsigned long value) { long* p = (unsigned long*)pointer; p[offset] = value; }") (c-declare "void pointer_set_c_unsigned_long(void* pointer, int offset, unsigned long value) { *(unsigned long*)((char*)pointer + offset) = value; }")
(define-c void (pointer-set-c-unsigned-long! pointer_set_c_unsigned_long) ((pointer void*) int unsigned-long)) (define-c void (pointer-set-c-unsigned-long! pointer_set_c_unsigned_long) ((pointer void*) int unsigned-long))
(c-declare "void pointer_set_c_float(void* pointer, int offset, float value) { float* p = (float*)pointer; p[offset] = value; }") (c-declare "void pointer_set_c_float(void* pointer, int offset, float value) { *(float*)((char*)pointer + offset) = value; }")
(define-c void (pointer-set-c-float! pointer_set_c_float) ((pointer void*) int float)) (define-c void (pointer-set-c-float! pointer_set_c_float) ((pointer void*) int float))
(c-declare "void pointer_set_c_double(void* pointer, int offset, double value) { *(double*)((char*)pointer + offset) = value; }") (c-declare "void pointer_set_c_double(void* pointer, int offset, double value) { *(double*)((char*)pointer + offset) = value; }")

View File

@ -646,9 +646,9 @@
(debug (pffi-struct-get struct-test 'l)) (debug (pffi-struct-get struct-test 'l))
(assert = (pffi-struct-get struct-test 'l) 12) (assert = (pffi-struct-get struct-test 'l) 12)
(debug (pffi-struct-get struct-test 'm)) (debug (pffi-struct-get struct-test 'm))
(assert = (pffi-struct-get struct-test 'm) 13) (assert = (pffi-struct-get struct-test 'm) 13.0)
(debug (pffi-struct-get struct-test 'n)) (debug (pffi-struct-get struct-test 'n))
(assert = (pffi-struct-get struct-test 'n) 14) (assert = (pffi-struct-get struct-test 'n) 14.0)
;; pffi-struct-set! ;; pffi-struct-set!
@ -672,7 +672,7 @@
(float . n)))) (float . n))))
(pffi-struct-set! struct-test1 'a 1) (pffi-struct-set! struct-test1 'a 1)
(pffi-struct-set! struct-test1 'b #\b) (pffi-struct-set! struct-test1 'b #\b)
;(pffi-struct-set! struct-test1 'c 3) ;FIXME (pffi-struct-set! struct-test1 'c 3.0)
(pffi-struct-set! struct-test1 'd #\d) (pffi-struct-set! struct-test1 'd #\d)
(pffi-struct-set! struct-test1 'e (pffi-pointer-null)) (pffi-struct-set! struct-test1 'e (pffi-pointer-null))
(pffi-struct-set! struct-test1 'f 6.0) (pffi-struct-set! struct-test1 'f 6.0)
@ -682,13 +682,13 @@
(pffi-struct-set! struct-test1 'j 10) (pffi-struct-set! struct-test1 'j 10)
(pffi-struct-set! struct-test1 'k 11) (pffi-struct-set! struct-test1 'k 11)
(pffi-struct-set! struct-test1 'l 12) (pffi-struct-set! struct-test1 'l 12)
;(pffi-struct-set! struct-test1 'm 13) ;FIXME (pffi-struct-set! struct-test1 'm 13.0)
;(pffi-struct-set! struct-test1 'n 14) ;FIXME (pffi-struct-set! struct-test1 'n 14.0)
(c-test-check (pffi-struct-pointer struct-test1)) (c-test-check (pffi-struct-pointer struct-test1))
;; pffi-struct-make with pointer ;; pffi-struct-make with pointer
(print-header 'pffi-struct-pointer-set!) (print-header "pffi-struct-make with pointer")
(pffi-define c-test-new c-testlib 'test_new 'pointer (list)) (pffi-define c-test-new c-testlib 'test_new 'pointer (list))
(define struct-test2 (pffi-struct-make 'test (define struct-test2 (pffi-struct-make 'test
@ -713,32 +713,33 @@
(assert = (pffi-struct-get struct-test2 'a) 1) (assert = (pffi-struct-get struct-test2 'a) 1)
(debug (pffi-struct-get struct-test2 'b)) (debug (pffi-struct-get struct-test2 'b))
(assert char=? (pffi-struct-get struct-test2 'b) #\b) (assert char=? (pffi-struct-get struct-test2 'b) #\b)
;(debug (pffi-struct-get struct-test2 'c)) ; FIXME (debug (pffi-struct-get struct-test2 'c))
;(assert = (pffi-struct-get struct-test2 'c) 3) ; FIXME (assert = (pffi-struct-get struct-test2 'c) 3)
(debug (pffi-struct-get struct-test2 'd)) (debug (pffi-struct-get struct-test2 'd))
(assert char=? (pffi-struct-get struct-test2 'd) #\d) (assert char=? (pffi-struct-get struct-test2 'd) #\d)
;(debug (pffi-struct-get struct-test2 'e)) ; FIXME (debug (pffi-struct-get struct-test2 'e))
;(debug (pffi-pointer-null? (pffi-struct-get struct-test2 'e))) ; FIXME (debug (pffi-pointer-null? (pffi-struct-get struct-test2 'e)))
; (assert (lambda (p t) (pffi-pointer-null? p)) (pffi-struct-get struct-test2 'e) #t) ; FIXME (assert equal? (pffi-pointer-null? (pffi-struct-get struct-test2 'e)) #t)
(debug (pffi-struct-get struct-test2 'f)) (debug (pffi-struct-get struct-test2 'f))
(assert = (pffi-struct-get struct-test2 'f) 6.0) (assert = (pffi-struct-get struct-test2 'f) 6.0)
;(debug (pffi-struct-get struct-test2 'g)) ; FIXME (debug (pffi-pointer->string (pffi-struct-get struct-test2 'g)))
;(assert (lambda (p t) (string=? (pffi-pointer->string p) "foo")) (pffi-struct-get struct-test2 'g) #t) ; FIXME (assert equal? (string=? (pffi-pointer->string (pffi-struct-get struct-test2 'g)) "FOOBAR") #t)
(debug (pffi-struct-get struct-test2 'h)) (debug (pffi-struct-get struct-test2 'h))
(assert = (pffi-struct-get struct-test2 'h) 8) (assert = (pffi-struct-get struct-test2 'h) 8)
;(debug (pffi-struct-get struct-test2 'i)) ; FIXME (debug (pffi-struct-get struct-test2 'i))
;(debug (pffi-pointer-null? (pffi-struct-get struct-test2 'i))) ; FIXME (debug (pffi-pointer-null? (pffi-struct-get struct-test2 'i)))
; (assert (lambda (p t) (pffi-pointer-null? p)) (pffi-struct-get struct-test2 'i) #t) ; FIXME (assert (lambda (p t) (pffi-pointer-null? p)) (pffi-struct-get struct-test2 'i) #t)
(debug (pffi-struct-get struct-test2 'j)) (debug (pffi-struct-get struct-test2 'j))
(assert = (pffi-struct-get struct-test2 'j) 10) (assert = (pffi-struct-get struct-test2 'j) 10)
(debug (pffi-struct-get struct-test2 'k)) (debug (pffi-struct-get struct-test2 'k))
(assert = (pffi-struct-get struct-test2 'k) 11) (assert = (pffi-struct-get struct-test2 'k) 11)
(debug (pffi-struct-get struct-test2 'l)) (debug (pffi-struct-get struct-test2 'l))
(assert = (pffi-struct-get struct-test2 'l) 12) (assert = (pffi-struct-get struct-test2 'l) 12)
;(debug (pffi-struct-get struct-test2 'm)) ; FIXME (debug (pffi-struct-get struct-test2 'm))
;(assert = (pffi-struct-get struct-test2 'm) 13) ; FIXME (assert = (pffi-struct-get struct-test2 'm) 13.0)
(debug (pffi-struct-get struct-test2 'n)) (debug (pffi-struct-get struct-test2 'n))
(assert = (pffi-struct-get struct-test2 'n) 14) (assert = (pffi-struct-get struct-test2 'n) 14.0)
;; pffi-define-callback ;; pffi-define-callback
(print-header 'pffi-define-callback) (print-header 'pffi-define-callback)