diff --git a/.travis.sh b/.travis.sh index 9a2a737e1..d7e097a29 100755 --- a/.travis.sh +++ b/.travis.sh @@ -87,8 +87,11 @@ if [ "$QEMU" != "" ]; then export EXIT_STATUS=0; set +e # run test in EusLisp/test + make -C test for test_l in test/*.l; do + [[ "`uname -m`" == "ppc64le"* && $test_l =~ test-foreign.l ]] && continue; + travis_time_start euslisp.${test_l##*/}.test sed -i 's/\(i-max\ [0-9]000\)0*/\1/' $test_l @@ -96,7 +99,15 @@ if [ "$QEMU" != "" ]; then eusgl $test_l; export TMP_EXIT_STATUS=$? - travis_time_end `expr 32 - $TMP_EXIT_STATUS` + export CONTINUE=0 + # test-foreign.l only works for x86 / arm + if [[ $test_l =~ test-foreign.l && ! "$(gcc -dumpmachine)" =~ "aarch".*|"arm".*|"x86_64".*|"i"[0-9]"86".* ]]; then export CONTINUE=1; fi + + if [[ $CONTINUE == 0 ]]; then travis_time_end `expr 32 - $TMP_EXIT_STATUS`; else travis_time_end 33; fi + + if [[ $TMP_EXIT_STATUS != 0 ]]; then echo "Failed running $test_l. Exiting with $TMP_EXIT_STATUS"; fi + + if [[ $CONTINUE != 0 ]]; then export TMP_EXIT_STATUS=0; fi export EXIT_STATUS=`expr $TMP_EXIT_STATUS + $EXIT_STATUS`; @@ -105,7 +116,6 @@ if [ "$QEMU" != "" ]; then eusgl "(let ((o (namestring (merge-pathnames \".o\" \"$test_l\"))) (so (namestring (merge-pathnames \".so\" \"$test_l\")))) (compile-file \"$test_l\" :o o) (if (probe-file so) (load so) (exit 1))))" export TMP_EXIT_STATUS=$? - export CONTINUE=0 # const.l does not compilable https://github.com/euslisp/EusLisp/issues/318 if [[ $test_l =~ const.l ]]; then export CONTINUE=1; fi @@ -235,6 +245,7 @@ if [[ "`uname -m`" == "aarch"* ]]; then fi # run test in EusLisp/test + make -C $CI_SOURCE_PATH/test for test_l in $CI_SOURCE_PATH/test/*.l; do travis_time_start euslisp.${test_l##*/}.test @@ -299,15 +310,6 @@ fi [ $EXIT_STATUS == 0 ] || exit 1 -travis_time_start eus64.test - -if [[ "$TRAVIS_OS_NAME" == "osx" || "`uname -m`" == "arm"* ]]; then - uname -a -else - make -C eus/contrib/eus64-check/ || exit 1 # check eus64-check -fi -travis_time_end - if [ "$TRAVIS_OS_NAME" == "linux" -a "`uname -m`" == "x86_64" ]; then travis_time_start script.doc diff --git a/contrib/eus64-check/Makefile b/contrib/eus64-check/Makefile deleted file mode 100644 index 3ec68ba24..000000000 --- a/contrib/eus64-check/Makefile +++ /dev/null @@ -1,34 +0,0 @@ - -all : test - -MARCH=$(shell uname -m) - -test_foreign.so : test_foreign.c -ifeq ($(ARCHDIR), Linux64) -## - gcc -O2 -g -falign-functions=8 -Dx86_64 -DLinux -fPIC -c $< - gcc -shared -fPIC -falign-functions=8 -o $@ test_foreign.o -else -ifeq ($(ARCHDIR), LinuxARM) -ifeq ($(MARCH), aarch64) -## arm 64bit - gcc -O2 -g -Wimplicit -falign-functions=8 -Daarch64 -Darmv8 -DARM -DLinux -fPIC -c $< - gcc -shared -fPIC -falign-functions=8 -o $@ test_foreign.o -else -## arm 32bit - gcc -O2 -g -falign-functions=4 -DARM -DLinux -fpic -c $< - gcc -shared -fpic -falign-functions=4 -o $@ test_foreign.o -endif -else -## Linux32 bit - gcc -m32 -O2 -g -falign-functions=4 -Di386 -Di486 -DLinux -fpic -c $< - gcc -m32 -shared -fpic -falign-functions=4 -o $@ test_foreign.o -endif -endif - -test: test_foreign.so - irteusgl eus64-test.l - -clean : - \rm -f *.o *.so - diff --git a/contrib/eus64-check/eus64-module.l b/contrib/eus64-check/eus64-module.l deleted file mode 100644 index 922bcbc9e..000000000 --- a/contrib/eus64-check/eus64-module.l +++ /dev/null @@ -1,38 +0,0 @@ -(unless (boundp '*testmod*) - (setq *testmod* (load-foreign "test_foreign.so")) - (defforeign float-test *testmod* "float_test" (:integer :float32 :float32 :float32 :float32) :integer) - (defforeign float2-test *testmod* "float_test" (:integer :double :double :double :double) :integer) - (defforeign float3-test *testmod* "float_test" () :integer) - (defforeign double-test *testmod* "double_test" (:integer :double :double :double :double) :integer) - (defforeign double2-test *testmod* "double_test" (:integer :float32 :float32 :float32 :float32) :integer) - (defforeign double3-test *testmod* "double_test" () :integer) - (defforeign iv-test *testmod* "iv_test" () :integer) - (defforeign lv-test *testmod* "lv_test" () :integer) - (defforeign fv-test *testmod* "fv_test" () :integer) - (defforeign dv-test *testmod* "dv_test" () :integer) - (defforeign str-test *testmod* "str_test" () :integer) - (defforeign int-test *testmod* "int_test" () :integer) - (defforeign ret-float *testmod* "ret_float" () :float32) - (defforeign ret-double *testmod* "ret_double" () :float) - (defforeign ret-long *testmod* "ret_long" () :integer) - - (defforeign set-ifunc *testmod* "set_ifunc" (:integer) :integer) - (defforeign set-ffunc *testmod* "set_ffunc" (:integer) :integer) - - (defforeign test-testd *testmod* "test_testd" (:integer :integer :integer - :integer :integer :integer - :double :double :double :double - :double :double :double :double - :double :double - :integer :integer) :float) - (defforeign call-ifunc *testmod* "call_ifunc" () :integer) - (defforeign call-ffunc *testmod* "call_ffunc" () :float) - - (defforeign get-size-pointer *testmod* "get_size_of_pointer" () :integer) - (defforeign get-size-float32 *testmod* "get_size_of_float32" () :integer) - (defforeign get-size-double *testmod* "get_size_of_double" () :integer) - (defforeign get-size-long *testmod* "get_size_of_long" () :integer) - (defforeign get-size-int *testmod* "get_size_of_int" () :integer) - ) - - diff --git a/contrib/eus64-check/eus64-test.l b/contrib/eus64-check/eus64-test.l deleted file mode 100644 index 9cf1560b1..000000000 --- a/contrib/eus64-check/eus64-test.l +++ /dev/null @@ -1,249 +0,0 @@ -(load "eus64-module.l") -(require :unittest "lib/llib/unittest.l") - -(init-unit-test) - -(deftest test-pointer-size - (format t "~%;;;; pointer size check ;;;;~%") - - (format t "pointer size ~D ~D~%" - lisp::sizeof-* (get-size-pointer)) - (assert (= lisp::sizeof-* (get-size-pointer))) - - (format t "double size ~D ~D~%" - lisp::sizeof-double (get-size-double)) - (assert (= lisp::sizeof-double (get-size-double))) - - (format t "long integer size ~D ~D~%" - (cadr (assoc :long lisp::sizeof-types)) - (get-size-long)) - (assert (= (cadr (assoc :long lisp::sizeof-types)) (get-size-long))) - - (format t "integer size ~D ~D~%" - lisp::sizeof-int (get-size-int)) - (assert (= lisp::sizeof-int (get-size-int))) - - (format t "float size ~D ~D~%" - lisp::sizeof-float (get-size-float32)) - (assert (= lisp::sizeof-float (get-size-float32))) - ) - -(deftest test-multiple-arguments-passing - (format t "~%multiple arguments passing~%") - (format t "expected result~%") - (format t "100 101 102 -103 104 105 -1000.000000 1010.000000 1020.000000 1030.000000 -1040.000000 1050.000000 1060.000000 1070.000000 -2080.000000 2090.000000 -206 207 -test-testd = 1.23456 -~%") - (format t "exec in eus~%") - (format t "test-testd = ~A~%" - (setq ret (test-testd 100 101 102 - 103 104 105 - 1000.0 1010.0 1020.0 1030.0 - 1040.0 1050.0 1060.0 1070.0 - 2080.0 2090.0 - 206 207))) - (assert (eps= 1.23456 ret)) - - ;; - (setq f (piped-fork "irteusgl eus64-module.l '(progn (test-testd 100 101 102 103 104 105 1000.000000 1010.000000 1020.000000 1030.000000 1040.000000 1050.000000 1060.000000 1070.000000 2080.000000 2090.000000 206 207)(exit 0))'")) - (assert (string= (read-line f) "100 101 102")) - (assert (string= (read-line f) "103 104 105")) - (assert (string= (read-line f) "1000.000000 1010.000000 1020.000000 1030.000000")) - (assert (string= (read-line f) "1040.000000 1050.000000 1060.000000 1070.000000")) - (assert (string= (read-line f) "2080.000000 2090.000000")) - (assert (string= (read-line f) "206 207")) - ) - -(deftest test-float-test - (format t "~%~%float-test~%") - (format t "expected result~%") - (format t "0: 1.000000e-01 ..~%") - (format t "0: 2.000000e-01 ..~%") - (format t "0: 3.000000e-01 ..~%") - (format t "0: 4.000000e-01 ..~%") - (format t "~%float-test(success, exec in eus)~%") - (float-test 0 0.1 0.2 0.3 0.4) - (format t "~%float2-test(fail, exec in eus)~%") - (float2-test 0 0.1 0.2 0.3 0.4) - (format t "~%float3-test(depend on architecture, exec in eus)~%") - (float3-test 0 0.1 0.2 0.3 0.4) - - ;; - (setq f (piped-fork "irteusgl eus64-module.l '(progn (float-test 0 0.1 0.2 0.3 0.4)(exit 0))'")) - (assert (eps= (read-from-string (subseq (read-line f) 2)) 0.1)) ;; skip first 2 character - (assert (eps= (read-from-string (subseq (read-line f) 2)) 0.2)) - (assert (eps= (read-from-string (subseq (read-line f) 2)) 0.3)) - (assert (eps= (read-from-string (subseq (read-line f) 2)) 0.4)) - ) - -(deftest test-double-test - (format t "~%~%double-test~%") - (format t "expected result~%") - (format t "1: 1.000000e-01 ..~%") - (format t "1: 2.000000e-01 ..~%") - (format t "1: 3.000000e-01 ..~%") - (format t "1: 4.000000e-01 ..~%") - (format t "~%double-test(success, exec in eus)~%") - (double-test 1 0.1 0.2 0.3 0.4) - (format t "~%double2-test(fail, exec in eus)~%") - (double2-test 1 0.1 0.2 0.3 0.4) - (format t "~%double3-test(depend on architecture, exec in eus)~%") - (double3-test 1 0.1 0.2 0.3 0.4) - - ;; - (setq f (piped-fork "irteusgl eus64-module.l '(progn (double-test 1 0.1 0.2 0.3 0.4)(exit 0))'")) - (assert (eps= (read-from-string (subseq (read-line f) 2)) 0.1)) ;; skip first 2 character - (assert (eps= (read-from-string (subseq (read-line f) 2)) 0.2)) - (assert (eps= (read-from-string (subseq (read-line f) 2)) 0.3)) - (assert (eps= (read-from-string (subseq (read-line f) 2)) 0.4)) - (setq f (piped-fork "irteusgl eus64-module.l '(progn (double3-test 1 0.1 0.2 0.3 0.4)(exit 0))'")) - (assert (eps= (read-from-string (subseq (read-line f) 2)) 0.1)) ;; skip first 2 character - (assert (eps= (read-from-string (subseq (read-line f) 2)) 0.2)) - (assert (eps= (read-from-string (subseq (read-line f) 2)) 0.3)) - (assert (eps= (read-from-string (subseq (read-line f) 2)) 0.4)) - ) - -(deftest test-integer-vector - (setq iv (integer-vector 0 100 10000 1000000 100000000 10000000000)) - #| - (format t "~%iv-test~%") - (format t "expected result~%") - (format t "exec in eus64~%") - (iv-test (length iv) iv) - |# - (format t "~%lv-test~%") - (format t "size = 6 -0: 0 0 -1: 100 64 -2: 10000 2710 -3: 1000000 F4240 -4: 100000000 5F5E100 -5: 10000000000 2540BE400~%") - (format t "~%lv-test(exec in eus)~%") - (lv-test (length iv) iv) - - ;; - (setq f (piped-fork "irteusgl eus64-module.l '(progn (setq iv (integer-vector 0 100 10000 1000000 100000000 10000000000))(lv-test (length iv) iv)(exit 0))'")) - (assert (string= (read-line f) "size = 6")) - (assert (string= (read-line f) "0: 0 0")) - (assert (string= (read-line f) "1: 100 64")) - (assert (string= (read-line f) "2: 10000 2710")) - (assert (string= (read-line f) "3: 1000000 F4240")) - (assert (string= (read-line f) "4: 100000000 5F5E100")) - (assert (string= (read-line f) "5: 10000000000 2540BE400")) - ) - -(deftest test-float-vector - (setq fv (float-vector 0.1 0.2 0.3 0.5 0.7)) - #| - (format t "~%fv-test~%") - (format t "exec in eus64~%") - (fv-test (length fv) fv) - |# - - (format t "~%dv-test~%") - (format t "size = 5 -0: 1.000000e-01 3FB9999999999998 -1: 2.000000e-01 3FC9999999999998 -2: 3.000000e-01 3FD3333333333330 -3: 5.000000e-01 3FE0000000000000 -4: 7.000000e-01 3FE6666666666664~%") - (format t "~%dv-test(exec in eus)~%") - (dv-test (length fv) fv) - - ;; - (setq f (piped-fork "irteusgl eus64-module.l '(progn (setq fv (float-vector 0.1 0.2 0.3 0.5 0.7))(dv-test (length fv) fv)(exit 0))'")) - (assert (string= (read-line f) "size = 5")) - (assert (string= (read-line f) "0: 1.000000e-01 3FB9999999999998")) - (assert (string= (read-line f) "1: 2.000000e-01 3FC9999999999998")) - (assert (string= (read-line f) "2: 3.000000e-01 3FD3333333333330")) - (assert (string= (read-line f) "3: 5.000000e-01 3FE0000000000000")) - (assert (string= (read-line f) "4: 7.000000e-01 3FE6666666666664")) - ) - -(deftest test-string-test - (setq str "input : test64 string") - (format t "~%str-test~%") - ;;(format t "expected result~%") - (format t "input string : ~S~%" str) - (format t "~%str-test(exec in eus)~%") - (str-test (length str) str) - ;; - (setq f (piped-fork "irteusgl eus64-module.l '(progn (setq str \"input : test64 string\")(str-test (length str) str)(exit 0))'")) - (assert (string= (read-line f) (format nil "size = ~d" (length str)))) - (dotimes (i (length str)) - (assert (string= (read-line f) (format nil "~d: ~c ~x" i (elt str i) (elt str i)))) - ) - ) - -(deftest test-return-double - (format t "~%return double test~%") - (format t "expected result~%") - (format t " ret-double ~8,8e~%" (+ 0.55555 133.0)) - (format t "~%ret-double(exec in eus)~%") - (format t " ret-double ~8,8e~%" (ret-double 0.55555 133.0)) - ;; - (assert (eps= (ret-double 0.55555 133.0) (+ 0.55555 133.0))) - ) - -(deftest test-return-long - (format t "~%return long test~%") - (format t "expected result~%") - (format t " ret-long ~D~%" (+ 123 645000)) - (format t "~%ret-long(exec in eus)~%") - (format t " ret-long ~D~%" (ret-long 123 645000)) - - (assert (= (ret-long 123 645000) (+ 123 645000))) - ) -#| -;; ret-int -;; ret-short -;; ret-char - -;; callback function -(defun-c-callable LISP-IFUNC () :integer - (format t "LISP-INTFUNC is called, return ~D~%" 1234) - 1234) -;; -(format t "~%callback function test(integer)~%") -(format t " callback function is set~%") -(set-ifunc (pod-address 'LISP-IFUNC)) -(format t " expected result: LISP-INTFUNC is called, return 1234~%") -(format t " call-ifunc = ~A~%" (call-ifunc)) - -(defun-c-callable LISP-FFUNC ((i0 :integer) (i1 :integer) (i2 :integer) - (i3 :integer) (i4 :integer) (i5 :integer) - (f0 :float) (f1 :float) (f2 :float) (f3 :float) - (f4 :float) (f5 :float) (f6 :float) (f7 :float) - (f8 :float) (f9 :float) - (i6 :integer) (i7 :integer)) :float - (format t "LISP-FFUNC is called~%") - (format t "~A ~A ~A~%" i0 i1 i2) - (format t "~A ~A ~A~%" i3 i4 i5) - (format t "~A ~A ~A ~A~%" f0 f1 f2 f3) - (format t "~A ~A ~A ~A~%" f4 f5 f6 f7) - (format t "~A ~A~%" f8 f9) - (format t "~A ~A~%" i6 i7) - (format t "return ~A~%" 0.12345) - 0.12345) -(format t "~%callback function test(float)~%") -(format t " callback function is set~%") -(set-ffunc (pod-address 'LISP-FFUNC)) -(format t " expected result: LISP-FFUNC is called - 100 101 102 - 103 104 105 - 1000.0 1010.0 1020.0 1030.0 - 1040.0 1050.0 1060.0 1070.0 - 2080.0 2090.0 - 206 207 - return 0.12345~%") -(format t "call-ffunc = ~A~%" (call-ffunc)) -|# - -(run-all-tests) -(exit) diff --git a/contrib/eus64-check/test_foreign.c b/contrib/eus64-check/test_foreign.c deleted file mode 100644 index f0af5255f..000000000 --- a/contrib/eus64-check/test_foreign.c +++ /dev/null @@ -1,216 +0,0 @@ -#include -#include - -int float_test(int n, float f1, float f2, float f3, float f4) { - unsigned int ui; - - //printf("float_test in c\n"); - ui = *((unsigned int *)(&f1)); - printf("%d: %8.8e %X\n", n, f1, ui); - ui = *((unsigned int *)(&f2)); - printf("%d: %8.8e %X\n", n, f2, ui); - ui = *((unsigned int *)(&f3)); - printf("%d: %8.8e %X\n", n, f3, ui); - ui = *((unsigned int *)(&f4)); - printf("%d: %8.8e %X\n", n, f4, ui); - - return -1; -} - -int double_test(long n, double d1, double d2, double d3, double d4) { - unsigned long ul; - - //printf("double_test in c\n"); - ul = *((unsigned long *)(&d1)); - printf("%ld: %16.16e %lX\n", n, d1, ul); - ul = *((unsigned long *)(&d2)); - printf("%ld: %16.16e %lX\n", n, d2, ul); - ul = *((unsigned long *)(&d3)); - printf("%ld: %16.16e %lX\n", n, d3, ul); - ul = *((unsigned long *)(&d4)); - printf("%ld: %16.16e %lX\n", n, d4, ul); - - return -1; -} - -int iv_test(int n, int *src) { - int i; - unsigned int *ui; - printf("size = %d\n", n); - for(i=0;i stack */ \ + "movs r3, #0\n\t" \ + "str r3, [r7, #60]\n\t" \ + "b ."FUNC"_LPCK\n\t" \ + "."FUNC"_LP:\n\t" \ + "ldr r3, [r7, #60]\n\t" /* i */ \ + /* https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/function-parameters-on-32-bit-arm */ \ + "lsl r4, r3, #2\n\t" /* r4 = i * 2 */ \ + "ldr r1, [r7, #80]\n\t" /* vargv[0] */ \ + "add r1, r1, r4\n\t" /* vargv[i] */ \ + "add r2, sp, r4\n\t" /* stack[i] */ \ + "ldr r0, [r1]\n\t" \ + "str r0, [r2]\n\t" /* push stack */ \ + "adds r3, r3, #1\n\t" /* i++ */ \ + "str r3, [r7, #60]\n\t" \ + "."FUNC"_LPCK:\n\t" \ + "ldr r2, [r7, #60]\n\t" \ + "ldr r3, [r7]\n\t" \ + "cmp r2, r3\n\t" \ + "blt ."FUNC"_LP\n\t" \ + /* fargv -> register */ \ + "ldr r0, [r7,#4]\n\t" \ + "vldr.32 s0, [r0]\n\t" \ + "vldr.32 s1, [r0,#4]\n\t" \ + "vldr.32 s2, [r0,#8]\n\t" \ + "vldr.32 s3, [r0,#12]\n\t" \ + "vldr.32 s4, [r0,#16]\n\t" \ + "vldr.32 s5, [r0,#20]\n\t" \ + "vldr.32 s6, [r0,#24]\n\t" \ + "vldr.32 s7, [r0,#28]\n\t" \ + "vldr.32 s8, [r0,#32]\n\t" \ + "vldr.32 s9, [r0,#36]\n\t" \ + "vldr.32 s10, [r0,#40]\n\t" \ + "vldr.32 s11, [r0,#44]\n\t" \ + "vldr.32 s12, [r0,#48]\n\t" \ + "vldr.32 s13, [r0,#52]\n\t" \ + "vldr.32 s14, [r0,#56]\n\t" \ + "vldr.32 s15, [r0,#60]\n\t" \ + /* iargv -> register */ \ + "ldr r0, [r7,#8]\n\t" \ + "ldr r0, [r0]\n\t" \ + "ldr r1, [r7,#8]\n\t" \ + "ldr r1, [r1,#4]\n\t" \ + "ldr r2, [r7,#8]\n\t" \ + "ldr r2, [r2,#8]\n\t" \ + "ldr r3, [r7,#8]\n\t" \ + "ldr r3, [r3,#12]\n\t" \ + /* funcall */ \ + "ldr r6, [r7, #12]\n\t" \ + "blx r6\n\t" + +__asm__ (".align 4\n" + ".global exec_function_i\n\t" + ".type exec_function_i, %function\n" + "exec_function_i:\n\t" + "push {r7, lr}\n\t" + "sub sp, sp, #136\n\t" + "add r7, sp, #64\n\t" + "str r0, [r7, #12]\n\t" // fc + "str r1, [r7, #8]\n\t" // iargv + "str r2, [r7, #4]\n\t" // fargv + "str r3, [r7]\n\t" // vcntr + exec_function_asm("FUNCI") + // retval + "adds r7, r7, #72\n\t" + "mov sp, r7\n\t" + "@ sp needed @\n\t" + "pop {r7, pc}\n\t" + ".size exec_function_i, .-exec_function_i\n\t" + ); + +__asm__ (".align 4\n" + ".global exec_function_f\n\t" + ".type exec_function_f, %function\n" + "exec_function_f:\n\t" + "push {r7, lr}\n\t" + "sub sp, sp, #136\n\t" + "add r7, sp, #64\n\t" + "str r0, [r7, #12]\n\t" // fc + "str r1, [r7, #8]\n\t" // iargv + "str r2, [r7, #4]\n\t" // fargv + "str r3, [r7]\n\t" // vcntr + exec_function_asm("FUNCF") + // retval + "vmov r0, s0 @ \n\t" + "vmov r1, s1 @ \n\t" + "adds r7, r7, #72\n\t" + "mov sp, r7\n\t" + "@ sp needed @\n\t" + "pop {r7, pc}\n\t" + ".size exec_function_f, .-exec_function_f\n\t" + ); + +#define NUM_INT_ARGUMENTS 4 +#define NUM_FLT_ARGUMENTS 16 +#define NUM_EXTRA_ARGUMENTS 16 + pointer call_foreign(ifunc,code,n,args) eusinteger_t (*ifunc)(); /* ???? */ pointer code; int n; pointer args[]; -{ double (*ffunc)(); +{ pointer paramtypes=code->c.fcode.paramtypes; + pointer resulttype=code->c.fcode.resulttype; + pointer p,lisparg; + eusinteger_t iargv[NUM_INT_ARGUMENTS]; + eusinteger_t fargv[NUM_FLT_ARGUMENTS]; + eusinteger_t vargv[NUM_EXTRA_ARGUMENTS]; + int icntr = 0, fcntr_d = 0, fcntr_f = 0, vcntr_8 = 0, vcntr_16 = 0; + + numunion nu; + eusinteger_t j=0; /*lisp argument counter*//* ???? */ + eusinteger_t c=0; + union { + double d; + float f; + long l; + struct { + int i1,i2;} i; + } numbox; + double f; + + if (code->c.fcode.entry2 != NIL) { + ifunc = (eusinteger_t (*)())((((eusinteger_t)ifunc)&0xffffffff00000000) + | (intval(code->c.fcode.entry2)&0x00000000ffffffff)); + /* R.Hanai 090726 */ + } + while (iscons(paramtypes)) { + p=ccar(paramtypes); paramtypes=ccdr(paramtypes); + lisparg=args[j++]; + if (p==K_INTEGER) { + c = isint(lisparg)?intval(lisparg):bigintval(lisparg); + if(icntr < NUM_INT_ARGUMENTS) { + iargv[icntr++] = c; + } else { + vargv[vcntr_8++] = c; + if ( vcntr_8 % 2 == 1 ) vcntr_16 += 2; + if ( vcntr_8 % 2 == 0 ) vcntr_8 = vcntr_16; + } + } else if (p==K_STRING) { + if (elmtypeof(lisparg)==ELM_FOREIGN) c=lisparg->c.ivec.iv[0]; + else c=(eusinteger_t)(lisparg->c.str.chars); + if(icntr < NUM_INT_ARGUMENTS) { + iargv[icntr++] = c; + } else { + vargv[vcntr_8++] = c; + if ( vcntr_8 % 2 == 1 ) vcntr_16 += 2; + if ( vcntr_8 % 2 == 0 ) vcntr_8 = vcntr_16; + } + } else if (p==K_FLOAT32 || p==K_FLOAT) { + numbox.f=(float)ckfltval(lisparg); + c=((eusinteger_t)numbox.i.i1) & 0x00000000FFFFFFFF; + // | s0 | s1 | s2 | s3 | s4 | s5 | + // | d0 | d1 | d2 | + if(fcntr_f < NUM_FLT_ARGUMENTS) { + fargv[fcntr_f++] = c; + if ( fcntr_f % 2 == 1 ) fcntr_d += 2; // if *fcntr_f = s1, use d1 + if ( fcntr_f % 2 == 0 ) fcntr_f = fcntr_d; + } else { + vargv[vcntr_8++] = c; + if ( vcntr_8 % 2 == 1 ) vcntr_16 += 2; + if ( vcntr_8 % 2 == 0 ) vcntr_8 = vcntr_16; + } + } else if (p==K_DOUBLE) { + numbox.d=(double)ckfltval(lisparg); + if(fcntr_d < NUM_FLT_ARGUMENTS-1) { + fargv[fcntr_d++] = numbox.i.i1; fargv[fcntr_d++] = numbox.i.i2; + if ( fcntr_f % 2 == 0 ) fcntr_f = fcntr_d; // if *fcntr_f = s2, use d1 + if(fcntr_d >= NUM_FLT_ARGUMENTS) fcntr_f = fcntr_d; + } else { + vargv[vcntr_16++] = numbox.i.i1; vargv[vcntr_16++] = numbox.i.i2; + if ( vcntr_8 % 2 == 0 ) vcntr_8 = vcntr_16; + } + } else error(E_USER,(pointer)"unknown type specifier"); + if (max(vcntr_8, vcntr_16) >= NUM_EXTRA_ARGUMENTS) { + error(E_USER,(pointer)"too many number of arguments"); + } + } + int vcntr = max(vcntr_8, vcntr_16); + /* &rest arguments? */ + while (jc.ivec.iv[0]; + else c=(eusinteger_t)(lisparg->c.str.chars); + if(icntr < NUM_INT_ARGUMENTS) iargv[icntr++] = c; else vargv[vcntr++] = c; + } else if (isbignum(lisparg)){ + if (bigsize(lisparg)==1){ + eusinteger_t *xv = bigvec(lisparg); + c=(eusinteger_t)xv[0]; + if(icntr < NUM_INT_ARGUMENTS) iargv[icntr++] = c; else vargv[vcntr++] = c; + }else{ + fprintf(stderr, "bignum size!=1\n"); + } + } else { + c=(eusinteger_t)(lisparg->c.obj.iv); + if(icntr < NUM_INT_ARGUMENTS) iargv[icntr++] = c; else vargv[vcntr++] = c; + } + if (vcntr >= NUM_EXTRA_ARGUMENTS) { + error(E_USER,(pointer)"too many number of arguments"); + } + } + /**/ + if (resulttype==K_FLOAT || resulttype==K_FLOAT32) { + numbox.l = exec_function_f((void (*)())ifunc, iargv, fargv, vcntr, vargv); + f = (double)numbox.f; + return(makeflt(f)); + } else { + c = exec_function_i((void (*)())ifunc, iargv, fargv, vcntr, vargv); + if (resulttype==K_INTEGER) { + return(mkbigint(c)); + } else if (resulttype==K_STRING) { + p=makepointer(c-2*sizeof(pointer)); + if (isvector(p)) return(p); + else error(E_USER,(pointer)"illegal foreign string"); + } else if (iscons(resulttype)) { + /* (:string [10]) (:foreign-string [20]) */ + if (ccar(resulttype)==K_STRING) { /* R.Hanai 09/07/25 */ + resulttype=ccdr(resulttype); + if (resulttype!=NIL) j=ckintval(ccar(resulttype)); + else j=strlen((char *)c); + return(makestring((char *)c, j)); + } else if (ccar(resulttype)==K_FOREIGN_STRING) { /* R.Hanai 09/07/25 */ + resulttype=ccdr(resulttype); + if (resulttype!=NIL) j=ckintval(ccar(resulttype)); + else j=strlen((char *)c); + return(make_foreign_string(c, j)); } + error(E_USER,(pointer)"unknown result type"); + } else error(E_USER,(pointer)"result type?"); + } +} + +#else /* not ARM nor (defined(x86_64) || defined(aarch64)) */ + +pointer call_foreign(ifunc,code,n,args) +eusinteger_t (*ifunc)(); /* ???? */ +pointer code; +int n; +pointer args[]; +{ pointer paramtypes=code->c.fcode.paramtypes; pointer resulttype=code->c.fcode.resulttype; pointer p,lisparg; eusinteger_t cargv[100]; @@ -1009,7 +1256,6 @@ pointer args[]; ifunc = (eusinteger_t (*)())((((int)ifunc)&0xffff0000) | (intval(code->c.fcode.entry2)&0x0000ffff)); /* kanehiro's patch 2000.12.13 */ #endif } - ffunc=(double (*)())ifunc; while (iscons(paramtypes)) { p=ccar(paramtypes); paramtypes=ccdr(paramtypes); lisparg=args[j++]; @@ -1018,10 +1264,10 @@ pointer args[]; else if (p==K_STRING) { if (elmtypeof(lisparg)==ELM_FOREIGN) cargv[i++]=lisparg->c.ivec.iv[0]; else cargv[i++]=(eusinteger_t)(lisparg->c.str.chars);} - else if (p==K_FLOAT32) { + else if (p==K_FLOAT32 || (WORD_SIZE==32 && p==K_FLOAT)) { numbox.f=ckfltval(lisparg); cargv[i++]=(int)numbox.i.i1;} - else if (p==K_DOUBLE || p==K_FLOAT) { + else if (p==K_DOUBLE || (WORD_SIZE==64 && p==K_FLOAT)) { numbox.d=ckfltval(lisparg); cargv[i++]=numbox.i.i1; cargv[i++]=numbox.i.i2;} else error(E_USER,(pointer)"unknown type specifier");} @@ -1049,12 +1295,26 @@ pointer args[]; #endif /* end of kanehiro's patch 2000.12.13 */ else cargv[i++]=(eusinteger_t)(lisparg->c.obj.iv);} /**/ - if (resulttype==K_FLOAT) { + if (resulttype==K_FLOAT || resulttype==K_FLOAT32) { + union { + eusfloat_t f; +#if __ARM_ARCH==4 + eusinteger_t i; // ARM 32bit armel +#else + eusfloat_t i; // Intel 32bit x86 +#endif + } n; +#if __ARM_ARCH==4 +#else + eusinteger_t (*tmp_ifunc)() = ifunc; + double (*ifunc)(); + ifunc=(double (*)())tmp_ifunc; +#endif if (i<=8) - f=(*ffunc)(cargv[0],cargv[1],cargv[2],cargv[3], + n.i=(*ifunc)(cargv[0],cargv[1],cargv[2],cargv[3], cargv[4],cargv[5],cargv[6],cargv[7]); else if (i<=32) - f=(*ffunc)(cargv[0],cargv[1],cargv[2],cargv[3], + n.i=(*ifunc)(cargv[0],cargv[1],cargv[2],cargv[3], cargv[4],cargv[5],cargv[6],cargv[7], cargv[8],cargv[9],cargv[10],cargv[11], cargv[12],cargv[13],cargv[14],cargv[15], @@ -1064,7 +1324,7 @@ pointer args[]; cargv[28],cargv[29],cargv[30],cargv[31]); #if (sun3 || sun4 || mips || alpha) else if (i>32) - f=(*ffunc)(cargv[0],cargv[1],cargv[2],cargv[3], + n.i=(*ifunc)(cargv[0],cargv[1],cargv[2],cargv[3], cargv[4],cargv[5],cargv[6],cargv[7], cargv[8],cargv[9],cargv[10],cargv[11], cargv[12],cargv[13],cargv[14],cargv[15], @@ -1085,7 +1345,8 @@ pointer args[]; cargv[72],cargv[73],cargv[74],cargv[75], cargv[76],cargv[77],cargv[78],cargv[79]); #endif - return(makeflt(f));} + fprintf(stderr, "%d %f\n", n.i, n.f); + return(makeflt(n.f));} else { if (i<8) i=(*ifunc)(cargv[0],cargv[1],cargv[2],cargv[3], diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 000000000..1fa5e144d --- /dev/null +++ b/test/Makefile @@ -0,0 +1,42 @@ +GCC_MACHINE=$(shell gcc -dumpmachine) +$(info "-- GCC_MACHINE = ${GCC_MACHINE}") +OS=$(shell uname -s | sed 's/[^A-Za-z1-9].*//') +$(info "-- OS = ${OS}") +ifeq ($(OS),Linux) + export MAKEFILE=Makefile.Linux +endif +ifeq ($(OS),CYGWIN) + export MAKEFILE=Makefile.Cygwin +endif +ifeq ($(OS),Darwin) + export MAKEFILE=Makefile.Darwin +endif + +$(info "-- MAKEFILE = ${MAKEFILE}") + +# set EUSDIR if not defined +export EUSDIR?=$(CURDIR)/.. +$(info "-- EUSDIR = ${EUSDIR}") + +include $(MAKEFILE) + +SRC=test_foreign.c +OBJ=$(basename $(SRC)).o +LIB=$(basename $(SRC)).$(LSFX) + +$(LIB): $(OBJ) + $(LD) $(SOFLAGS) $(OUTOPT)$(LIB) $(OBJ) $(LDFLAGS) + @echo "Try make test" + +$(OBJ): $(SRC) + $(CC) $(CFLAGS) -DCOMPILE_LIB -c $(SRC) $(OBJOPT)$(OBJ) + +clean: + rm -f $(LIB) $(OBJ) + +test: $(LIB) + teusgl eus64-test.l + +clean : + \rm -f *.o *.so + diff --git a/test/Makefile.Cygwin b/test/Makefile.Cygwin new file mode 100644 index 000000000..1f97214c5 --- /dev/null +++ b/test/Makefile.Cygwin @@ -0,0 +1,12 @@ +CC = c++ +CFLAGS = -O2 -falign-functions=4 -DCygwin -I$(EUSDIR)/include +LDFLAGS = +OBJOPT = -o +OUTOPT = -o +LD = c++ -shared -falign-functions=4 +EXELD = c++ -falign-functions=4 +SOFLAGS = +EXESFX = .exe +LSFX = dll +LPFX = lib +LIBS = -L$(ARCHDIR) -lRAPID diff --git a/test/Makefile.Darwin b/test/Makefile.Darwin new file mode 100644 index 000000000..111dcfcfa --- /dev/null +++ b/test/Makefile.Darwin @@ -0,0 +1,12 @@ +CC = c++ +CFLAGS = -O2 -falign-functions=8 -fPIC -DDarwin -DGCC -I$(EUSDIR)/include +LDFLAGS = +OBJOPT = -o +OUTOPT = -o +LD = c++ +SOFLAGS = -dynamiclib -flat_namespace -undefined suppress +EXELD = c++ +EXESFX = +LSFX = so +LPFX = lib +LIBS = -L$(ARCHDIR) -lRAPID diff --git a/test/Makefile.Linux b/test/Makefile.Linux new file mode 100644 index 000000000..fb6f0d689 --- /dev/null +++ b/test/Makefile.Linux @@ -0,0 +1,33 @@ +CC = c++ +CFLAGS = -O2 -DLinux -DGCC -I$(EUSDIR)/include +LDFLAGS = +OBJOPT = -o +OUTOPT = -o +LD = c++ +SOFLAGS = -shared +EXELD = c++ +EXESFX = +LSFX = so +LPFX = lib + +ifneq (,$(findstring 64,$(shell gcc -dumpmachine))) + CFLAGS+=-falign-functions=8 +else + CFLAGS+=-falign-functions=4 +endif + +ifneq ($(shell gcc -dumpmachine | egrep "^(arm|aarch)"),) + LDFLAGS+=-Wl,-z,execstack + CFLAGS+=-DARM -fPIC +endif +ifneq ($(shell gcc -dumpmachine | grep "^x86_64"),) + CFLAGS+=-fPIC +endif + +ifneq ($(shell gcc -dumpmachine | grep "i.*86-linux"),) +CC += -m32 +LD += -m32 +EXELD += -m32 +endif + + diff --git a/test/test-foreign.l b/test/test-foreign.l new file mode 100644 index 000000000..819482b46 --- /dev/null +++ b/test/test-foreign.l @@ -0,0 +1,581 @@ +(eval-when (load eval) (load "test-foreign.module_l")) +(require :unittest "lib/llib/unittest.l") + +(init-unit-test) + +(defun check-func (f) + (warning-message 3 "~A [paramtypes] ~A, [result] ~A~%" + (send f :pname) + (cdr (assoc 'paramtypes (send (send f :func) :slots))) + (cdr (assoc 'resulttype (send (send f :func) :slots))))) + +(defun assert-read-line-eps= (s ret) + (let (l) + (setq l (read-line s)) + (warning-message 2 "check read-line ~A -> ~A = ~A~%" l (subseq l 2) ret) + (assert (eps= (read-from-string (subseq l 2)) ret)))) + +(defun assert-read-line-string= (s ret &optional (f #'identity)) + (let (l) + (setq l (read-line s)) + (warning-message 2 "check read-line ~A -> ~A = ~A~%" l l ret) + (assert (string= l ret)))) + +(defun assert-read-funcall= (f ret) + (let () + (warning-message 2 "check ~A -> ~A = ~A~%" f (eval f) ret) + (assert (eps= (eval f) ret)))) + +(deftest test-pointer-size + (format t "~%;;;; pointer size check ;;;;~%") + + (format t "pointer size ~D ~D~%" + lisp::sizeof-* (get-size-pointer)) + (assert (= lisp::sizeof-* (get-size-pointer))) + + (format t "double size ~D ~D~%" + lisp::sizeof-double (get-size-double)) + (assert (= lisp::sizeof-double (get-size-double))) + + (format t "long integer size ~D ~D~%" + (cadr (assoc :long lisp::sizeof-types)) + (get-size-long)) + (assert (= (cadr (assoc :long lisp::sizeof-types)) (get-size-long))) + + (format t "integer size ~D ~D~%" + lisp::sizeof-int (get-size-int)) + (assert (= lisp::sizeof-int (get-size-int))) + + (format t "float size ~D ~D~%" + lisp::sizeof-float (get-size-float32)) + (assert (= lisp::sizeof-float (get-size-float32))) + + (format t "eusinteger size ~D ~D~%" + lisp::sizeof-* (get-size-eusfloat)) + (assert (= lisp::sizeof-* (get-size-eusfloat))) + + (format t "eusfloat size ~D ~D~%" + lisp::sizeof-* (get-size-eusinteger)) + (assert (= lisp::sizeof-* (get-size-eusinteger))) + ) + +(deftest test-multiple-arguments-passing + (format t "~%multiple arguments passing~%") + (format t "expected result~%") + (format t "100 101 102 +103 104 105 +1000.000000 1010.000000 1020.000000 1030.000000 +1040.000000 1050.000000 1060.000000 1070.000000 +2080.000000 2090.000000 +206 207 +test-testd = 1.23456 +~%") + (format t "exec in eus~%") + (format t "test-testd = ~A~%" + (setq ret (test-testd 100 101 102 + 103 104 105 + 1000.0 1010.0 1020.0 1030.0 + 1040.0 1050.0 1060.0 1070.0 + 2080.0 2090.0 + 206 207))) + (when (not (and (memq :word-size=32 *features*) (memq :arm *features*))) + (assert (eps= 1.23456 ret)) + ) + + ;; + (check-func 'test-testd) + (setq f (piped-fork (format nil "eusg ~A/test/test-foreign.module_l '(progn (test-testd 100 101 102 103 104 105 1000.000000 1010.000000 1020.000000 1030.000000 1040.000000 1050.000000 1060.000000 1070.000000 2080.000000 2090.000000 206 207)(exit 0))'" *eusdir*))) + (assert-read-line-string= f "100 101 102") + (assert-read-line-string= f "103 104 105") + (assert-read-line-string= f "1000.000000 1010.000000 1020.000000 1030.000000") + (assert-read-line-string= f "1040.000000 1050.000000 1060.000000 1070.000000") + (assert-read-line-string= f "2080.000000 2090.000000") + (assert-read-line-string= f "206 207") + + (format t "exec in eus~%") + (format t "test-testf = ~A~%" + (setq ret (test-testf 100 101 102 + 103 104 105 + 1000.0 1010.0 1020.0 1030.0 + 1040.0 1050.0 1060.0 1070.0 + 2080.0 2090.0 + 206 207))) + (assert (eps= 1.23456 ret)) + ;; + (check-func 'test-testf) + (setq f (piped-fork (format nil "eusg ~A/test/test-foreign.module_l '(progn (test-testf 100 101 102 103 104 105 1000.000000 1010.000000 1020.000000 1030.000000 1040.000000 1050.000000 1060.000000 1070.000000 2080.000000 2090.000000 206 207)(exit 0))'" *eusdir*))) + (assert-read-line-string= f "100 101 102") + (assert-read-line-string= f "103 104 105") + (assert-read-line-string= f "1000.000000 1010.000000 1020.000000 1030.000000") + (assert-read-line-string= f "1040.000000 1050.000000 1060.000000 1070.000000") + (assert-read-line-string= f "2080.000000 2090.000000") + (assert-read-line-string= f "206 207") + + (format t "exec in eus~%") + (format t "test-testfd = ~A~%" + (setq ret (test-testfd 100 101 102 + 103 104 105 + 1000.0 1010.0 1020.0 1030.0 + 1040.0 1050.0 1060.0 1070.0 + 2080.0 2090.0 2100.0 2110.0 + 206 207))) + (assert (= 123456 ret)) + ;; + (when (not (eq (read (unix::piped-fork "gcc -dumpmachine") nil 'arm-linux-gnueabi) 'arm-linux-gnueabi)) + (check-func 'test-testfd) + (setq f (piped-fork (format nil "eusg ~A/test/test-foreign.module_l '(progn (test-testfd 100 101 102 103 104 105 1000.000000 1010.000000 1020.000000 1030.000000 1040.000000 1050.000000 1060.000000 1070.000000 2080.000000 2090.000000 2100.000000 2110.000000 206 207)(exit 0))'" *eusdir*))) + (assert-read-line-string= f "100 101 102") + (assert-read-line-string= f "103 104 105") + (assert-read-line-string= f "1000.000000 1010.000000 1020.000000 1030.000000") + (assert-read-line-string= f "1040.000000 1050.000000 1060.000000 1070.000000") + (assert-read-line-string= f "2080.000000 2090.000000 2100.000000 2110.000000") + (assert-read-line-string= f "206 207") + ) + ) + +(deftest test-int-test + (format t "~%~%int-test~%") + (format t "expected result~%") + (format t "0: 1 1~%") + (format t "0: 2 2~%") + (format t "0: 3 3~%") + (format t "0: 4 4~%") + (format t "~%int-test(success, exec in eus)~%") + (check-func 'int-test) + (int-test 0 1 2 3 4) + ;; + (check-func 'int-test) + (setq f (piped-fork (format nil "eusg ~A/test/test-foreign.module_l '(progn (int-test 0 1 2 3 4)(exit 0))'" *eusdir*))) + (assert-read-line-string= f "0: 1 1") + (assert-read-line-string= f "0: 2 2") + (assert-read-line-string= f "0: 3 3") + (assert-read-line-string= f "0: 4 4") + ) + +(deftest test-long-test + (format t "~%~%long-test~%") + (format t "expected result~%") + (format t "0: 1 1~%") + (format t "0: 2 2~%") + (format t "0: 3 3~%") + (format t "0: 4 4~%") + (format t "~%long-test(success, exec in eus)~%") + (check-func 'long-test) + (long-test 0 1 2 3 4) + ;; + (check-func 'long-test) + (setq f (piped-fork (format nil "eusg ~A/test/test-foreign.module_l '(progn (long-test 0 1 2 3 4)(exit 0))'" *eusdir*))) + (assert-read-line-string= f "0: 1 1") + (assert-read-line-string= f "0: 2 2") + (assert-read-line-string= f "0: 3 3") + (assert-read-line-string= f "0: 4 4") + ) + +(deftest test-eusinteger-test + (format t "~%~%eusinteger-test~%") + (format t "expected result~%") + (format t "0: 1 1~%") + (format t "0: 2 2~%") + (format t "0: 3 3~%") + (format t "0: 4 4~%") + (format t "~%eusinteger-test(success, exec in eus)~%") + (check-func 'eusinteger-test) + (eusinteger-test 0 1 2 3 4) + ;; + (check-func 'eusinteger-test) + (setq f (piped-fork (format nil "eusg ~A/test/test-foreign.module_l '(progn (eusinteger-test 0 1 2 3 4)(exit 0))'" *eusdir*))) + (assert-read-line-string= f "0: 1 1") + (assert-read-line-string= f "0: 2 2") + (assert-read-line-string= f "0: 3 3") + (assert-read-line-string= f "0: 4 4") + ) + +(deftest test-float-test + (format t "~%~%float-test~%") + (format t "expected result~%") + (format t "0: 1.000000e-01 ..~%") + (format t "0: 2.000000e-01 ..~%") + (format t "0: 3.000000e-01 ..~%") + (format t "0: 4.000000e-01 ..~%") + (format t "~%float-test(success, exec in eus)~%") + (check-func 'float-test) + (float-test 0 0.1 0.2 0.3 0.4) + (format t "~%float1-test(success, exec in eus)~%") + (check-func 'float1-test) + (float1-test 0 0.1 0.2 0.3 0.4) + (format t "~%float2-test(fail, exec in eus)~%") + (check-func 'float2-test) + (float2-test 0 0.1 0.2 0.3 0.4) + (format t "~%float3-test(depend on architecture, exec in eus)~%") + (check-func 'float3-test) + (float3-test 0 0.1 0.2 0.3 0.4) + + ;; + (check-func 'float-test) + (setq f (piped-fork (format nil "eusg ~A/test/test-foreign.module_l '(progn (float-test 0 0.1 0.2 0.3 0.4)(exit 0))'" *eusdir*))) + (assert-read-line-eps= f 0.1) + (assert-read-line-eps= f 0.2) + (assert-read-line-eps= f 0.3) + (assert-read-line-eps= f 0.4) + + (when (memq :word-size=32 *features*) + (check-func 'float1-test) + (setq f (piped-fork (format nil "eusg ~A/test/test-foreign.module_l '(progn (float1-test 0 0.1 0.2 0.3 0.4)(exit 0))'" *eusdir*))) + (assert-read-line-eps= f 0.1) + (assert-read-line-eps= f 0.2) + (assert-read-line-eps= f 0.3) + (assert-read-line-eps= f 0.4)) + ) + +(deftest test-double-test + (format t "~%~%double-test~%") + (format t "expected result~%") + (format t "1: 1.000000e-01 ..~%") + (format t "1: 2.000000e-01 ..~%") + (format t "1: 3.000000e-01 ..~%") + (format t "1: 4.000000e-01 ..~%") + (format t "~%double-test(success, exec in eus)~%") + (check-func 'double-test) + (double-test 1 0.1 0.2 0.3 0.4) + (format t "~%double1-test(fail, exec in eus)~%") + (check-func 'double1-test) + (double1-test 1 0.1 0.2 0.3 0.4) + (format t "~%double2-test(fail, exec in eus)~%") + (check-func 'double2-test) + (double2-test 1 0.1 0.2 0.3 0.4) + (format t "~%double3-test(depend on architecture, exec in eus)~%") + (check-func 'double3-test) + (double3-test 1 0.1 0.2 0.3 0.4) + + ;; + (when (not (eq (read (unix::piped-fork "gcc -dumpmachine") nil 'arm-linux-gnueabi) 'arm-linux-gnueabi)) + (check-func 'double-test) + (setq f (piped-fork (format nil "eusg ~A/test/test-foreign.module_l '(progn (double-test 1 0.1 0.2 0.3 0.4)(exit 0))'" *eusdir*))) + (assert-read-line-eps= f 0.1) + (assert-read-line-eps= f 0.2) + (assert-read-line-eps= f 0.3) + (assert-read-line-eps= f 0.4) + ) + (when (not (and (memq :word-size=32 *features*) (memq :arm *features*))) + (check-func 'double3-test) + (setq f (piped-fork (format nil "eusg ~A/test/test-foreign.module_l '(progn (double3-test 1 0.1 0.2 0.3 0.4)(exit 0))'" *eusdir*))) + (assert-read-line-eps= f 0.1) + (assert-read-line-eps= f 0.2) + (assert-read-line-eps= f 0.3) + (assert-read-line-eps= f 0.4) + ) + ) + +(deftest test-eusfloat-test + (format t "~%~%eusfloat-test~%") + (format t "expected result~%") + (format t "0: 1.000000e-01 ..~%") + (format t "0: 2.000000e-01 ..~%") + (format t "0: 3.000000e-01 ..~%") + (format t "0: 4.000000e-01 ..~%") + (format t "~%eusfloat-test(fail, exec in eus)~%") + (check-func 'eusfloat-test) + (eusfloat-test 0 0.1 0.2 0.3 0.4) + (format t "~%eusfloat1-test(success, exec in eus)~%") + (check-func 'eusfloat1-test) + (eusfloat1-test 0 0.1 0.2 0.3 0.4) + (format t "~%eusfloat2-test(success, exec in eus)~%") + (check-func 'eusfloat2-test) + (eusfloat2-test 0 0.1 0.2 0.3 0.4) + (format t "~%eusfloat3-test(success, exec in eus)~%") + (check-func 'eusfloat3-test) + (eusfloat3-test 0 0.1 0.2 0.3 0.4) + + ;; + (when (memq :word-size=32 *features*) + (check-func 'eusfloat-test) + (setq f (piped-fork (format nil "eusg ~A/test/test-foreign.module_l '(progn (eusfloat-test 0 0.1 0.2 0.3 0.4)(exit 0))'" *eusdir*))) + (assert-read-line-eps= f 0.1) + (assert-read-line-eps= f 0.2) + (assert-read-line-eps= f 0.3) + (assert-read-line-eps= f 0.4)) + + (check-func 'eusfloat1-test) + (setq f (piped-fork (format nil "eusg ~A/test/test-foreign.module_l '(progn (eusfloat1-test 0 0.1 0.2 0.3 0.4)(exit 0))'" *eusdir*))) + (assert-read-line-eps= f 0.1) + (assert-read-line-eps= f 0.2) + (assert-read-line-eps= f 0.3) + (assert-read-line-eps= f 0.4) + + (when (memq :word-size=64 *features*) + (check-func 'eusfloat2-test) + (setq f (piped-fork (format nil "eusg ~A/test/test-foreign.module_l '(progn (eusfloat2-test 0 0.1 0.2 0.3 0.4)(exit 0))'" *eusdir*))) + (assert-read-line-eps= f 0.1) + (assert-read-line-eps= f 0.2) + (assert-read-line-eps= f 0.3) + (assert-read-line-eps= f 0.4) + + (check-func 'eusfloat3-test) + (setq f (piped-fork (format nil "eusg ~A/test/test-foreign.module_l '(progn (eusfloat3-test 0 0.1 0.2 0.3 0.4)(exit 0))'" *eusdir*))) + (assert-read-line-eps= f 0.1) + (assert-read-line-eps= f 0.2) + (assert-read-line-eps= f 0.3) + (assert-read-line-eps= f 0.4)) + + ) + +(deftest test-integer-vector + (setq iv (integer-vector 0 100 10000 1000000 100000000 10000000000)) + + (format t "~%iv-test~%") + (format t "size = 6 +0: 0 0 +1: 100 64 +2: 10000 2710 +3: 1000000 F4240 +4: 100000000 5F5E100 +5: 10000000000 2540BE400~%") + (format t "~%iv-test(fail, exec in eus)~%") + (check-func 'iv-test) + (iv-test (length iv) iv) + + (format t "~%lv-test~%") + (format t "size = 6 +0: 0 0 +1: 100 64 +2: 10000 2710 +3: 1000000 F4240 +4: 100000000 5F5E100 +5: 10000000000 2540BE400~%") + (format t "~%lv-test(exec in eus)~%") + (check-func 'lv-test) + (lv-test (length iv) iv) + + ;; + (check-func 'lv-test) + (setq f (piped-fork (format nil "eusg ~A/test/test-foreign.module_l '(progn (setq iv (integer-vector 0 100 10000 1000000 100000000 10000000000))(lv-test (length iv) iv)(exit 0))'" *eusdir*))) + (assert-read-line-string= f "size = 6") + (assert-read-line-string= f "0: 0 0") + (assert-read-line-string= f "1: 100 64") + (assert-read-line-string= f "2: 10000 2710") + (assert-read-line-string= f "3: 1000000 F4240") + (assert-read-line-string= f "4: 100000000 5F5E100") + (when (memq :word-size=64 *features*) + (assert-read-line-string= f "5: 10000000000 2540BE400")) + + (format t "~%eiv-test~%") + (format t "size = 6 +0: 0 0 +1: 100 64 +2: 10000 2710 +3: 1000000 F4240 +4: 100000000 5F5E100 +5: 10000000000 2540BE400~%") + (format t "~%lv-test(exec in eus)~%") + (check-func 'eiv-test) + (eiv-test (length iv) iv) + + ;; + (check-func 'eiv-test) + (setq f (piped-fork (format nil "eusg ~A/test/test-foreign.module_l '(progn (setq iv (integer-vector 0 100 10000 1000000 100000000 10000000000))(eiv-test (length iv) iv)(exit 0))'" *eusdir*))) + (assert-read-line-string= f "size = 6") + (assert-read-line-string= f "0: 0 0") + (assert-read-line-string= f "1: 100 64") + (assert-read-line-string= f "2: 10000 2710") + (assert-read-line-string= f "3: 1000000 F4240") + (assert-read-line-string= f "4: 100000000 5F5E100") + (when (memq :word-size=64 *features*) + (assert-read-line-string= f "5: 10000000000 2540BE400")) + ) + +(deftest test-float-vector + (setq fv (float-vector 0.1 0.2 0.3 0.5 0.7)) + + (format t "~%fv-test~%") + (format t "size = 5 +0: 1.000000e-01 3FB9999999999998 +1: 2.000000e-01 3FC9999999999998 +2: 3.000000e-01 3FD3333333333330 +3: 5.000000e-01 3FE0000000000000 +4: 7.000000e-01 3FE6666666666664~%") + (format t "~%fv-test(exec in eus)~%") + (check-func 'fv-test) + (fv-test (length fv) fv) + + (format t "~%dv-test~%") + (format t "size = 5 +0: 1.000000e-01 3FB9999999999998 +1: 2.000000e-01 3FC9999999999998 +2: 3.000000e-01 3FD3333333333330 +3: 5.000000e-01 3FE0000000000000 +4: 7.000000e-01 3FE6666666666664~%") + (format t "~%dv-test(exec in eus)~%") + (check-func 'dv-test) + (dv-test (length fv) fv) + + ;; + (when (memq :word-size=64 *features*) + (check-func 'dv-test) + (setq f (piped-fork (format nil "eusg ~A/test/test-foreign.module_l '(progn (setq fv (float-vector 0.1 0.2 0.3 0.5 0.7))(dv-test (length fv) fv)(exit 0))'" *eusdir*))) + (assert-read-line-string= f "size = 5") + (assert-read-line-string= f "0: 1.000000e-01 3FB9999999999998") + (assert-read-line-string= f "1: 2.000000e-01 3FC9999999999998") + (assert-read-line-string= f "2: 3.000000e-01 3FD3333333333330") + (assert-read-line-string= f "3: 5.000000e-01 3FE0000000000000") + (assert-read-line-string= f "4: 7.000000e-01 3FE6666666666664")) + + ;; + (format t "~%efv-test~%") + (format t "size = 5 +0: 1.000000e-01 3FB9999999999998 +1: 2.000000e-01 3FC9999999999998 +2: 3.000000e-01 3FD3333333333330 +3: 5.000000e-01 3FE0000000000000 +4: 7.000000e-01 3FE6666666666664~%") + (format t "~%efv-test(exec in eus)~%") + (check-func 'efv-test) + (efv-test (length fv) fv) + + ;; + (check-func 'efv-test) + (when (memq :word-size=64 *features*) + (setq f (piped-fork (format nil "eusg ~A/test/test-foreign.module_l '(progn (setq fv (float-vector 0.1 0.2 0.3 0.5 0.7))(efv-test (length fv) fv)(exit 0))'" *eusdir*))) + (assert-read-line-string= f "size = 5") + (assert-read-line-string= f "0: 1.000000e-01 3FB9999999999998") + (assert-read-line-string= f "1: 2.000000e-01 3FC9999999999998") + (assert-read-line-string= f "2: 3.000000e-01 3FD3333333333330") + (assert-read-line-string= f "3: 5.000000e-01 3FE0000000000000") + (assert-read-line-string= f "4: 7.000000e-01 3FE6666666666664")) + ) + +(deftest test-string-test + (setq str "input : test64 string") + (format t "~%str-test~%") + ;;(format t "expected result~%") + (format t "input string : ~S~%" str) + (format t "~%str-test(exec in eus)~%") + (check-func 'str-test) + (str-test (length str) str) + ;; + (check-func 'str-test) + (setq f (piped-fork (format nil "eusg ~A/test/test-foreign.module_l '(progn (setq str \"input : test64 string\")(str-test (length str) str)(exit 0))'" *eusdir*))) + (assert-read-line-string= f (format nil "size = ~d" (length str))) + (dotimes (i (length str)) + (assert-read-line-string= f (format nil "~d: ~c ~x" i (elt str i) (elt str i))) + ) + ) + +(deftest test-return-float + (format t "~%return float test~%") + (format t "expected result~%") + (format t " ret-float ~8,8e~%" (+ 0.55555 133.0)) + (format t "~%ret-float(exec in eus)~%") + (format t " ret-float ~8,8e~%" (ret-float 0.55555 133.0)) + ;; + (check-func 'ret-float) + (assert-read-funcall= '(ret-float 0.55555 133.0) (+ 0.55555 133.0)) + (assert (eps= (ret-float 0.55555 133.0) (+ 0.55555 133.0))) + ) + +(deftest test-return-double + (format t "~%return double test~%") + (format t "expected result~%") + (format t " ret-double ~8,8e~%" (+ 0.55555 133.0)) + (format t "~%ret-double(exec in eus)~%") + (format t " ret-double ~8,8e~%" (ret-double 0.55555 133.0)) + ;; + (when (not (and (memq :word-size=32 *features*) (memq :arm *features*))) + (check-func 'ret-double) + (assert-read-funcall= '(ret-double 0.55555 133.0) (+ 0.55555 133.0)) + (assert (eps= (ret-double 0.55555 133.0) (+ 0.55555 133.0))) + ) + ) + +(deftest test-return-eusfloat + (format t "~%return eusfloat test~%") + (format t "expected result~%") + (format t " ret-eusfloat ~8,8e~%" (+ 0.55555 133.0)) + (format t "~%ret-eusfloat(exec in eus)~%") + (format t " ret-eusfloat ~8,8e~%" (ret-eusfloat 0.55555 133.0)) + ;; + (check-func 'ret-eusfloat) + (assert-read-funcall= '(ret-eusfloat 0.55555 133.0) (+ 0.55555 133.0)) + (assert (eps= (ret-eusfloat 0.55555 133.0) (+ 0.55555 133.0))) + ) + +(deftest test-return-int + (format t "~%return int test~%") + (format t "expected result~%") + (format t " ret-int ~D~%" (+ 123 645000)) + (format t "~%ret-int(exec in eus)~%") + (format t " ret-int ~D~%" (ret-int 123 645000)) + + (check-func 'ret-int) + (assert (= (ret-int 123 645000) (+ 123 645000))) + ) + +(deftest test-return-long + (format t "~%return long test~%") + (format t "expected result~%") + (format t " ret-long ~D~%" (+ 123 645000)) + (format t "~%ret-long(exec in eus)~%") + (format t " ret-long ~D~%" (ret-long 123 645000)) + + (check-func 'ret-long) + (assert (= (ret-long 123 645000) (+ 123 645000))) + ) + +(deftest test-return-eusinteger + (format t "~%return eusinteger test~%") + (format t "expected result~%") + (format t " ret-eusinteger ~D~%" (+ 123 645000)) + (format t "~%ret-eusinteger(exec in eus)~%") + (format t " ret-eusinteger ~D~%" (ret-eusinteger 123 645000)) + + (check-func 'ret-eusinteger) + (assert (= (ret-eusinteger 123 645000) (+ 123 645000))) + ) + +#| +;; ret-int +;; ret-short +;; ret-char + +;; callback function +(defun-c-callable LISP-IFUNC () :integer + (format t "LISP-INTFUNC is called, return ~D~%" 1234) + 1234) +;; +(format t "~%callback function test(integer)~%") +(format t " callback function is set~%") +(set-ifunc (pod-address 'LISP-IFUNC)) +(format t " expected result: LISP-INTFUNC is called, return 1234~%") +(format t " call-ifunc = ~A~%" (call-ifunc)) + +(defun-c-callable LISP-FFUNC ((i0 :integer) (i1 :integer) (i2 :integer) + (i3 :integer) (i4 :integer) (i5 :integer) + (f0 :float) (f1 :float) (f2 :float) (f3 :float) + (f4 :float) (f5 :float) (f6 :float) (f7 :float) + (f8 :float) (f9 :float) + (i6 :integer) (i7 :integer)) :float + (format t "LISP-FFUNC is called~%") + (format t "~A ~A ~A~%" i0 i1 i2) + (format t "~A ~A ~A~%" i3 i4 i5) + (format t "~A ~A ~A ~A~%" f0 f1 f2 f3) + (format t "~A ~A ~A ~A~%" f4 f5 f6 f7) + (format t "~A ~A~%" f8 f9) + (format t "~A ~A~%" i6 i7) + (format t "return ~A~%" 0.12345) + 0.12345) +(format t "~%callback function test(float)~%") +(format t " callback function is set~%") +(set-ffunc (pod-address 'LISP-FFUNC)) +(format t " expected result: LISP-FFUNC is called + 100 101 102 + 103 104 105 + 1000.0 1010.0 1020.0 1030.0 + 1040.0 1050.0 1060.0 1070.0 + 2080.0 2090.0 + 206 207 + return 0.12345~%") +(format t "call-ffunc = ~A~%" (call-ffunc)) +|# + +(eval-when (load eval) + (run-all-tests) + (exit)) diff --git a/test/test-foreign.module_l b/test/test-foreign.module_l new file mode 100644 index 000000000..c4d917d5c --- /dev/null +++ b/test/test-foreign.module_l @@ -0,0 +1,64 @@ +(unless (boundp '*testmod*) + (setq *testmod* (load-foreign "test_foreign.so")) + (defforeign int-test *testmod* "int_test" (:integer :integer :integer :integer :integer) :integer) + (defforeign long-test *testmod* "long_test" (:integer :integer :integer :integer :integer) :integer) + (defforeign eusinteger-test *testmod* "eusinteger_test" (:integer :integer :integer :integer :integer) :integer) + (defforeign float-test *testmod* "float_test" (:integer :float32 :float32 :float32 :float32) :integer) + (defforeign float1-test *testmod* "float_test" (:integer :float :float :float :float) :integer) + (defforeign float2-test *testmod* "float_test" (:integer :double :double :double :double) :integer) + (defforeign float3-test *testmod* "float_test" () :integer) + (defforeign eusfloat-test *testmod* "eusfloat_test" (:integer :float32 :float32 :float32 :float32) :integer) + (defforeign eusfloat1-test *testmod* "eusfloat_test" (:integer :float :float :float :float) :integer) + (defforeign eusfloat2-test *testmod* "eusfloat_test" (:integer :double :double :double :double) :integer) + (defforeign eusfloat3-test *testmod* "eusfloat_test" () :integer) + (defforeign double-test *testmod* "double_test" (:integer :double :double :double :double) :integer) + (defforeign double1-test *testmod* "double_test" (:integer :float :float :float :float) :integer) + (defforeign double2-test *testmod* "double_test" (:integer :float32 :float32 :float32 :float32) :integer) + (defforeign double3-test *testmod* "double_test" () :integer) + (defforeign iv-test *testmod* "iv_test" () :integer) + (defforeign lv-test *testmod* "lv_test" () :integer) + (defforeign eiv-test *testmod* "eiv_test" () :integer) + (defforeign fv-test *testmod* "fv_test" () :integer) + (defforeign dv-test *testmod* "dv_test" () :integer) + (defforeign efv-test *testmod* "efv_test" () :integer) + (defforeign str-test *testmod* "str_test" () :integer) + (defforeign int-test *testmod* "int_test" () :integer) + (defforeign ret-float *testmod* "ret_float" (:float32 :float32) :float32) + (defforeign ret-double *testmod* "ret_double" (:double :double) :float) + (defforeign ret-eusfloat *testmod* "ret_eusfloat" (:float :float) :float) + (defforeign ret-int *testmod* "ret_int" () :integer) + (defforeign ret-long *testmod* "ret_long" () :integer) + (defforeign ret-eusinteger *testmod* "ret_eusinteger" () :integer) + + (defforeign set-ifunc *testmod* "set_ifunc" (:integer) :integer) + (defforeign set-ffunc *testmod* "set_ffunc" (:integer) :integer) + + (defforeign test-testd *testmod* "test_testd" (:integer :integer :integer + :integer :integer :integer + :double :double :double :double + :double :double :double :double + :double :double + :integer :integer) :float) + (defforeign test-testf *testmod* "test_testf" (:integer :integer :integer + :integer :integer :integer + :float :float :float :float + :float :float :float :float + :float :float + :integer :integer) :float) + (defforeign test-testfd *testmod* "test_testfd" (:integer :integer :integer + :integer :integer :integer + :double :float32 :double :float32 + :float32 :double :double :float32 + :float32 :double :double :float32 + :integer :integer) :integer) + (defforeign call-ifunc *testmod* "call_ifunc" () :integer) + (defforeign call-ffunc *testmod* "call_ffunc" () :float) + + (defforeign get-size-pointer *testmod* "get_size_of_pointer" () :integer) + (defforeign get-size-float32 *testmod* "get_size_of_float32" () :integer) + (defforeign get-size-double *testmod* "get_size_of_double" () :integer) + (defforeign get-size-long *testmod* "get_size_of_long" () :integer) + (defforeign get-size-int *testmod* "get_size_of_int" () :integer) + (defforeign get-size-eusinteger *testmod* "get_size_of_eusinteger" () :integer) + (defforeign get-size-eusfloat *testmod* "get_size_of_eusfloat" () :integer) + ) diff --git a/test/test_foreign.c b/test/test_foreign.c new file mode 100644 index 000000000..48f62bd2f --- /dev/null +++ b/test/test_foreign.c @@ -0,0 +1,396 @@ +// for eus.h +#include +#include +#include +#include +#include +#include +#include + +#define class eus_class +#define throw eus_throw +#define export eus_export +#define vector eus_vector +#define string eus_string +#include // include eus.h just for eusfloat_t ... +#undef class +#undef throw +#undef export +#undef vector +#undef string + +extern "C" { +int int_test(int n, int i1, int i2, int i3, int i4) { + unsigned int ui; + + //printf("int_test in c\n"); + ui = *((unsigned int *)(&i1)); + printf("%d: %8d %X\n", n, i1, ui); + ui = *((unsigned int *)(&i2)); + printf("%d: %8d %X\n", n, i2, ui); + ui = *((unsigned int *)(&i3)); + printf("%d: %8d %X\n", n, i3, ui); + ui = *((unsigned int *)(&i4)); + printf("%d: %8d %X\n", n, i4, ui); + + return -1; +} + +int long_test(long n, long d1, long d2, long d3, long d4) { + unsigned long ul; + + //printf("long_test in c\n"); + ul = *((unsigned long *)(&d1)); + printf("%d: %8d %X\n", n, d1, ul); + ul = *((unsigned long *)(&d2)); + printf("%d: %8d %X\n", n, d2, ul); + ul = *((unsigned long *)(&d3)); + printf("%d: %8d %X\n", n, d3, ul); + ul = *((unsigned long *)(&d4)); + printf("%d: %8d %X\n", n, d4, ul); + + return -1; +} + +int eusinteger_test(int n, eusinteger_t i1, eusinteger_t i2, eusinteger_t i3, eusinteger_t i4) { + unsigned long ul; + + //printf("eusinteger_test in c\n"); + ul = *((unsigned int *)(&i1)); + printf("%d: %8d %X\n", n, i1, ul); + ul = *((unsigned int *)(&i2)); + printf("%d: %8d %X\n", n, i2, ul); + ul = *((unsigned int *)(&i3)); + printf("%d: %8d %X\n", n, i3, ul); + ul = *((unsigned int *)(&i4)); + printf("%d: %8d %X\n", n, i4, ul); + + return -1; +} + +int float_test(int n, float f1, float f2, float f3, float f4) { + unsigned int ui; + + //printf("float_test in c\n"); + ui = *((unsigned int *)(&f1)); + printf("%d: %8.8e %X (%4.1f)\n", n, f1, ui, f1); + ui = *((unsigned int *)(&f2)); + printf("%d: %8.8e %X (%4.1f)\n", n, f2, ui, f2); + ui = *((unsigned int *)(&f3)); + printf("%d: %8.8e %X (%4.1f)\n", n, f3, ui, f3); + ui = *((unsigned int *)(&f4)); + printf("%d: %8.8e %X (%4.1f)\n", n, f4, ui, f4); + + return -1; +} + +int double_test(long n, double d1, double d2, double d3, double d4) { + unsigned long ul; + + //printf("double_test in c\n"); + ul = *((unsigned long *)(&d1)); + printf("%ld: %16.16e %lX (%4.1f)\n", n, d1, ul, d1); + ul = *((unsigned long *)(&d2)); + printf("%ld: %16.16e %lX (%4.1f)\n", n, d2, ul, d2); + ul = *((unsigned long *)(&d3)); + printf("%ld: %16.16e %lX (%4.1f)\n", n, d3, ul, d3); + ul = *((unsigned long *)(&d4)); + printf("%ld: %16.16e %lX (%4.1f)\n", n, d4, ul, d4); + + return -1; +} + +int eusfloat_test(int n, eusfloat_t f1, eusfloat_t f2, eusfloat_t f3, eusfloat_t f4) { + unsigned int ui; + + //printf("float_test in c\n"); + ui = *((unsigned int *)(&f1)); + printf("%d: %8.8e %X (%4.1f)\n", n, f1, ui, f1); + ui = *((unsigned int *)(&f2)); + printf("%d: %8.8e %X (%4.1f)\n", n, f2, ui, f2); + ui = *((unsigned int *)(&f3)); + printf("%d: %8.8e %X (%4.1f)\n", n, f3, ui, f3); + ui = *((unsigned int *)(&f4)); + printf("%d: %8.8e %X (%4.1f)\n", n, f4, ui, f4); + + return -1; +} + +int iv_test(int n, int *src) { + int i; + unsigned int *ui; + printf("size = %d\n", n); + for(i=0;i %f\n", a, b, ret); + printf("// return %e, %X\n", ret, *ui); + return ret; +} + +double ret_double(double a, double b) { + double ret = (a + b); + unsigned long long *ul; + ul = (unsigned long long*)&ret; + printf("// %f + %f -> %f\n", a, b, ret); + printf("// return %e, %lX\n", ret, *ul); + return ret; +} + +eusfloat_t ret_eusfloat(eusfloat_t a, eusfloat_t b) { + eusfloat_t ret = (a + b); + unsigned long *ul; + ul = (unsigned long *)&ret; + printf("// %f + %f -> %f\n", a, b, ret); + printf("// return %e, %lX\n", ret, *ul); + return ret; +} + +int ret_int(int a, int b) { + int ret = a + b; + unsigned long *ul; + ul = (unsigned long *)&ret; + printf("// %d + %d -> %d\n", a, b, ret); + printf("// return %ld, %lX\n", ret, *ul); + return ret; +} + +long ret_long(long a, long b) { + long ret = a + b; + unsigned long *ul; + ul = (unsigned long *)&ret; + printf("// %d + %d -> %d\n", a, b, ret); + printf("// return %ld, %lX\n", ret, *ul); + return ret; +} + +eusinteger_t ret_eusinteger(eusinteger_t a, eusinteger_t b) { + eusinteger_t ret = a + b; + unsigned long *ul; + ul = (unsigned long *)&ret; + printf("// %d + %d -> %d\n", a, b, ret); + printf("// return %ld, %lX\n", ret, *ul); + return ret; +} + +double test_testd(long i0, long i1, long i2, + long i3, long i4, long i5, + double d0, double d1, double d2, double d3, + double d4, double d5, double d6, double d7, + double d8, double d9, + long i6, long i7) { + printf("%ld %ld %ld\n", i0, i1, i2); + printf("%ld %ld %ld\n", i3, i4, i5); + //printf("%ld %ld %ld %ld\n", + //(long)d0, (long)d1, (long)d2, (long)d3); + printf("%lf %lf %lf %lf\n", d0, d1, d2, d3); + printf("%lf %lf %lf %lf\n", d4, d5, d6, d7); + printf("%lf %lf\n", d8, d9); + printf("%ld %ld\n", i6, i7); + + //return 0x1234; + return 1.23456; +} +double test_testd2(long i0, long i1, long i2, + long i3, long i4, long i5, + double d0, double d1, double d2, double d3, + double d4, double d5, double d6, double d7, + double d8, double d9, double d10, + long i6, long i7) { + printf("%ld %ld %ld\n", i0, i1, i2); + printf("%ld %ld %ld\n", i3, i4, i5); + //printf("%ld %ld %ld %ld\n", + //(long)d0, (long)d1, (long)d2, (long)d3); + printf("%lf %lf %lf %lf\n", d0, d1, d2, d3); + printf("%lf %lf %lf %lf\n", d4, d5, d6, d7); + printf("%lf %lf %lf\n", d8, d9, d10); + printf("%ld %ld\n", i6, i7); + + //return 0x1234; + return 1.23456; +} +eusfloat_t test_testf(long i0, long i1, long i2, + long i3, long i4, long i5, + eusfloat_t d0, eusfloat_t d1, eusfloat_t d2, eusfloat_t d3, + eusfloat_t d4, eusfloat_t d5, eusfloat_t d6, eusfloat_t d7, + eusfloat_t d8, eusfloat_t d9, + long i6, long i7) { + printf("%ld %ld %ld\n", i0, i1, i2); + printf("%ld %ld %ld\n", i3, i4, i5); + //printf("%ld %ld %ld %ld\n", + //(long)d0, (long)d1, (long)d2, (long)d3); + printf("%lf %lf %lf %lf\n", d0, d1, d2, d3); + printf("%lf %lf %lf %lf\n", d4, d5, d6, d7); + printf("%lf %lf\n", d8, d9); + printf("%ld %ld\n", i6, i7); + + //return 0x1234; + return 1.23456; +} +int test_testfd(long i0, long i1, long i2, + long i3, long i4, long i5, + double d0, float d1, double d2, float d3, + float d4, double d5, double d6, float d7, + float d8, double d9, double d10, float d11, + long i6, long i7) { + printf("%ld %ld %ld\n", i0, i1, i2); + printf("%ld %ld %ld\n", i3, i4, i5); + //printf("%ld %ld %ld %ld\n", + //(long)d0, (long)d1, (long)d2, (long)d3); + printf("%lf %f %lf %f\n", d0, d1, d2, d3); + printf("%f %lf %lf %f\n", d4, d5, d6, d7); + printf("%f %lf %lf %f\n", d8, d9, d10, d11); + printf("%ld %ld\n", i6, i7); + + //return 0x1234; + return 123456; +} +static long (*g)(); +static double (*gf) (long i0, long i1, long i2, + long i3, long i4, long i5, + double d0, double d1, double d2, double d3, + double d4, double d5, double d6, double d7, + double d8, double d9, + long i6, long i7); + +long set_ifunc(long (*f) ()) +{ + g = f; + printf("set_ifunc, g = %lX\n", g); +} + +long set_ffunc(double (*f) ()) +{ + gf = (double (*) (long i0, long i1, long i2, + long i3, long i4, long i5, + double d0, double d1, double d2, double d3, + double d4, double d5, double d6, double d7, + double d8, double d9, + long i6, long i7))f; + printf("set_ffunc, gf = %lX\n", gf); +} + +long call_ifunc() { + printf("call_ifunc, g = %lX\n", g); + return g(); +} + +double call_ffunc() { + printf("call_ffunc, gf = %lX\n", gf); + return gf(100,101,102, + 103,104,105, + 1000.0, 1010.0, 1020.0, 1030.0, + 1040.0, 1050.0, 1060.0, 1070.0, + 2080.0, 2090.0, + 206, 207); +} + +long get_size_of_pointer() { + return (sizeof(void *)); +} + +long get_size_of_float32() { + return (sizeof(float)); +} + +long get_size_of_double() { + return (sizeof(double)); +} + +long get_size_of_long() { + return (sizeof(long)); +} + +long get_size_of_int() { + return (sizeof(int)); +} + +long get_size_of_eusinteger() { + return (sizeof(eusinteger_t)); +} + +long get_size_of_eusfloat() { + return (sizeof(eusfloat_t)); +} + +};