From 7300b9430b3e3185eccc87da43e7e1e26763d33e Mon Sep 17 00:00:00 2001 From: Masaki Murooka Date: Fri, 13 Sep 2019 22:12:44 +0900 Subject: [PATCH 1/2] add defforeign test. --- .travis.sh | 2 ++ test/Makefile | 34 ++++++++++++++++++++++++++++++++++ test/Makefile.Cygwin | 12 ++++++++++++ test/Makefile.Darwin | 12 ++++++++++++ test/Makefile.Linux | 33 +++++++++++++++++++++++++++++++++ test/test-defforeign.l | 35 +++++++++++++++++++++++++++++++++++ test/testdefforeign.c | 34 ++++++++++++++++++++++++++++++++++ 7 files changed, 162 insertions(+) create mode 100644 test/Makefile create mode 100644 test/Makefile.Cygwin create mode 100644 test/Makefile.Darwin create mode 100644 test/Makefile.Linux create mode 100644 test/test-defforeign.l create mode 100644 test/testdefforeign.c diff --git a/.travis.sh b/.travis.sh index 9a2a737e1..5a5f94ff4 100755 --- a/.travis.sh +++ b/.travis.sh @@ -87,6 +87,7 @@ if [ "$QEMU" != "" ]; then export EXIT_STATUS=0; set +e # run test in EusLisp/test + make -C test for test_l in test/*.l; do travis_time_start euslisp.${test_l##*/}.test @@ -235,6 +236,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 diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 000000000..132d75210 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,34 @@ +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=testdefforeign.c +OBJ=$(basename $(SRC)).o +LIB=$(LPFX)$(basename $(SRC)).$(LSFX) + +$(LIB): $(OBJ) + $(LD) $(SOFLAGS) $(OUTOPT)$(LIB) $(OBJ) $(LDFLAGS) + +$(OBJ): $(SRC) + $(CC) $(CFLAGS) -DCOMPILE_LIB -c $(SRC) $(OBJOPT)$(OBJ) + +clean: + rm -f $(LIB) $(OBJ) 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-defforeign.l b/test/test-defforeign.l new file mode 100644 index 000000000..fa1b8efe2 --- /dev/null +++ b/test/test-defforeign.l @@ -0,0 +1,35 @@ +(require :unittest "lib/llib/unittest.l") + +(init-unit-test) + +(deftest test-defforeign + (defvar *testforeign-lib* + (load-foreign (format nil "~a/test/libtestdefforeign.so" (unix:getenv "EUSDIR")))) + + (defforeign test1 + *testforeign-lib* + "test1" + (:integer :float) + :float + ) + + (defforeign test2 + *testforeign-lib* + "test2" + (:string) + :float + ) + + (setq test1-result (test1 1 2.5)) + (format t "test1: ~a~%" test1-result) + (assert (= test1-result 3.5)) + + (setq test2-result (test2 (float-vector 1.0 2.5))) + (format t "test2: ~a~%" test2-result) + (assert (= test2-result 3.5)) + ) + +(eval-when + (load eval) + (run-all-tests) + (exit)) diff --git a/test/testdefforeign.c b/test/testdefforeign.c new file mode 100644 index 000000000..aaf71f920 --- /dev/null +++ b/test/testdefforeign.c @@ -0,0 +1,34 @@ +// 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" { + eusfloat_t test1(eusinteger_t v1, eusfloat_t v2) { + printf("// v1: %d\n", (int)v1); + printf("// v2: %f\n", v2); + return v1 + v2; + } + + eusfloat_t test2(eusfloat_t *v) { + printf("// v[0]: %f\n", v[0]); + printf("// v[1]: %f\n", v[1]); + return v[0] + v[1]; + } +} From 1b249d60681e344d3b768dfc08417bea58cac80f Mon Sep 17 00:00:00 2001 From: Kei Okada Date: Sun, 31 May 2020 15:03:50 +0900 Subject: [PATCH 2/2] fix K_FLOAT for 32bit environment --- lisp/c/eval.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/c/eval.c b/lisp/c/eval.c index 1602e5940..a0faad621 100644 --- a/lisp/c/eval.c +++ b/lisp/c/eval.c @@ -1018,10 +1018,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");}