diff --git a/stix/kernel/Stix.st b/stix/kernel/Stix.st index ce917ef..6c6a852 100644 --- a/stix/kernel/Stix.st +++ b/stix/kernel/Stix.st @@ -272,6 +272,7 @@ { self.funcs := Dictionary new. self.name := aString. + self.handle := self privateOpen: self.name. "[ self.handle := self privateOpen: self.name ] diff --git a/stix/kernel/test-005.st b/stix/kernel/test-005.st index c5c2843..7b791f2 100644 --- a/stix/kernel/test-005.st +++ b/stix/kernel/test-005.st @@ -226,27 +226,31 @@ #method(#class) abc { - + } #method(#class) main { - "| ffi | +" + | ffi | ffi := FFI new: 'libc.so.6'. + ## ffi call: #printf with: #((str '%d') (int 10) (long 20)). ffi call: #printf withSig: 'i|sii' withArgs: #(S'hello world %d %d\n' 11123 9876543). ## ffi call: #puts withSig: 'i|s' withArgs: #('hello world'). - ffi close." + ffi close. +" self abc. self abc. self abc. - +" FFI isNil dump. FFI notNil dump. nil isNil dump. nil notNil dump. nil class dump. nil class class class dump. +" } } diff --git a/stix/lib/Makefile.am b/stix/lib/Makefile.am index 97898c9..ceb7826 100644 --- a/stix/lib/Makefile.am +++ b/stix/lib/Makefile.am @@ -1,18 +1,18 @@ AUTOMAKE_OPTIONS = nostdinc CPPFLAGS_ALL_COMMON = \ - -I$(top_builddir)/include \ - -I$(top_srcdir)/include \ + -I$(abs_builddir) \ + -I$(abs_srcdir) \ -I$(includedir) -LDFLAGS_ALL_COMMON = -L. -L$(libdir) -version-info 1:0:0 -no-undefined +LDFLAGS_ALL_COMMON = -L$(abs_builddir) -L$(libdir) ################################################## # MAIN LIBRARY ################################################## CPPFLAGS_LIB_COMMON = $(CPPFLAGS_ALL_COMMON) $(LTDLINCL) -LDFLAGS_LIB_COMMON = $(LDFLAGS_ALL_COMMON) +LDFLAGS_LIB_COMMON = $(LDFLAGS_ALL_COMMON) -version-info 1:0:0 -no-undefined LIBADD_LIB_COMMON = $(LIBM) $(LIBLTDL) if WIN32 @@ -31,12 +31,14 @@ pkginclude_HEADERS = \ stix-cfg.h \ stix-cmn.h \ stix-rbt.h \ + stix-utl.h \ stix.h pkglib_LTLIBRARIES = libstix.la libstix_la_SOURCES = \ stix-prv.h \ stix-rbt.c \ + stix-utl.c \ stix.c \ heap.c \ gc.c \ @@ -72,17 +74,17 @@ else # DYNAMIC MODULES ################################################## -#CPPFLAGS_MOD_COMMON = $(CPPFLAGS_ALL_COMMON) -#LDFLAGS_MOD_COMMON = $(LDFLAGS_ALL_COMMON) -#LIBADD_MOD_COMMON = -lstix +CPPFLAGS_MOD_COMMON = $(CPPFLAGS_LIB_COMMON) +LDFLAGS_MOD_COMMON = $(LDFLAGS_LIB_COMMON) +LIBADD_MOD_COMMON = -lstix -#modexecdir = $(libdir) +pkgmodexecdir = $(libdir) -#modexec_LTLIBRARIES = libstix-dir.la -#ibstix_dir_la_SOURCES = mod-dir.c mod-dir.h -#ibstix_dir_la_CPPFLAGS = $(CPPFLAGS_MOD_COMMON) -#ibstix_dir_la_LDFLAGS = $(LDFLAGS_MOD_COMMON) -#ibstix_dir_la_LIBADD = $(LIBADD_MOD_COMMON) +pkgmodexec_LTLIBRARIES = libstix-snd.la +libstix_snd_la_SOURCES = mod-snd.c mod-snd.h +libstix_snd_la_CPPFLAGS = $(CPPFLAGS_MOD_COMMON) +libstix_snd_la_LDFLAGS = $(LDFLAGS_MOD_COMMON) +libstix_snd_la_LIBADD = $(LIBADD_MOD_COMMON) endif diff --git a/stix/lib/Makefile.in b/stix/lib/Makefile.in index bb221f2..6f85bfa 100644 --- a/stix/lib/Makefile.in +++ b/stix/lib/Makefile.in @@ -101,21 +101,34 @@ am__uninstall_files_from_dir = { \ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ $(am__cd) "$$dir" && rm -f $$files; }; \ } -am__installdirs = "$(DESTDIR)$(pkglibdir)" "$(DESTDIR)$(pkgbindir)" \ +am__installdirs = "$(DESTDIR)$(pkglibdir)" \ + "$(DESTDIR)$(pkgmodexecdir)" "$(DESTDIR)$(pkgbindir)" \ "$(DESTDIR)$(pkgincludedir)" -LTLIBRARIES = $(pkglib_LTLIBRARIES) +LTLIBRARIES = $(pkglib_LTLIBRARIES) $(pkgmodexec_LTLIBRARIES) am__DEPENDENCIES_1 = -am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) -libstix_la_DEPENDENCIES = $(am__DEPENDENCIES_2) -am_libstix_la_OBJECTS = libstix_la-stix-rbt.lo libstix_la-stix.lo \ - libstix_la-heap.lo libstix_la-gc.lo libstix_la-obj.lo \ - libstix_la-sym.lo libstix_la-dic.lo libstix_la-ignite.lo \ - libstix_la-utf8.lo libstix_la-comp.lo libstix_la-exec.lo \ - libstix_la-debug.lo -libstix_la_OBJECTS = $(am_libstix_la_OBJECTS) +@ENABLE_STATIC_MODULE_FALSE@libstix_snd_la_DEPENDENCIES = \ +@ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_1) +am__libstix_snd_la_SOURCES_DIST = mod-snd.c mod-snd.h +@ENABLE_STATIC_MODULE_FALSE@am_libstix_snd_la_OBJECTS = \ +@ENABLE_STATIC_MODULE_FALSE@ libstix_snd_la-mod-snd.lo +libstix_snd_la_OBJECTS = $(am_libstix_snd_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent +libstix_snd_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ + $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ + $(AM_CFLAGS) $(CFLAGS) $(libstix_snd_la_LDFLAGS) $(LDFLAGS) -o \ + $@ +@ENABLE_STATIC_MODULE_FALSE@am_libstix_snd_la_rpath = -rpath \ +@ENABLE_STATIC_MODULE_FALSE@ $(pkgmodexecdir) +am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +libstix_la_DEPENDENCIES = $(am__DEPENDENCIES_2) +am_libstix_la_OBJECTS = libstix_la-stix-rbt.lo libstix_la-stix-utl.lo \ + libstix_la-stix.lo libstix_la-heap.lo libstix_la-gc.lo \ + libstix_la-obj.lo libstix_la-sym.lo libstix_la-dic.lo \ + libstix_la-ignite.lo libstix_la-utf8.lo libstix_la-comp.lo \ + libstix_la-exec.lo libstix_la-debug.lo +libstix_la_OBJECTS = $(am_libstix_la_OBJECTS) libstix_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(libstix_la_LDFLAGS) $(LDFLAGS) -o $@ @@ -152,8 +165,10 @@ am__v_CCLD_0 = @echo " CCLD " $@; AM_V_GEN = $(am__v_GEN_@AM_V@) am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) am__v_GEN_0 = @echo " GEN " $@; -SOURCES = $(libstix_la_SOURCES) $(stix_SOURCES) -DIST_SOURCES = $(libstix_la_SOURCES) $(stix_SOURCES) +SOURCES = $(libstix_snd_la_SOURCES) $(libstix_la_SOURCES) \ + $(stix_SOURCES) +DIST_SOURCES = $(am__libstix_snd_la_SOURCES_DIST) \ + $(libstix_la_SOURCES) $(stix_SOURCES) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -333,30 +348,32 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = nostdinc CPPFLAGS_ALL_COMMON = \ - -I$(top_builddir)/include \ - -I$(top_srcdir)/include \ + -I$(abs_builddir) \ + -I$(abs_srcdir) \ -I$(includedir) -LDFLAGS_ALL_COMMON = -L. -L$(libdir) -version-info 1:0:0 -no-undefined +LDFLAGS_ALL_COMMON = -L$(abs_builddir) -L$(libdir) ################################################## # MAIN LIBRARY ################################################## CPPFLAGS_LIB_COMMON = $(CPPFLAGS_ALL_COMMON) $(LTDLINCL) \ $(am__append_1) $(am__append_2) -LDFLAGS_LIB_COMMON = $(LDFLAGS_ALL_COMMON) +LDFLAGS_LIB_COMMON = $(LDFLAGS_ALL_COMMON) -version-info 1:0:0 -no-undefined LIBADD_LIB_COMMON = $(LIBM) $(LIBLTDL) pkgbindir = $(bindir) pkginclude_HEADERS = \ stix-cfg.h \ stix-cmn.h \ stix-rbt.h \ + stix-utl.h \ stix.h pkglib_LTLIBRARIES = libstix.la libstix_la_SOURCES = \ stix-prv.h \ stix-rbt.c \ + stix-utl.c \ stix.c \ heap.c \ gc.c \ @@ -376,6 +393,26 @@ stix_SOURCES = main.c stix_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) stix_LDFLAGS = $(LDFLAGS_LIB_COMMON) stix_LDADD = $(LIBADD_LIB_COMMON) -lstix -ldyncall_s + +################################################## +# STATIC MODULES BUILT INTO MAIN LIBRARY +################################################## +#libstix_la_SOURCES += \ +# mod-dir.c mod-dir.h \ +#libstix_la_LIBADD += + +################################################## +# DYNAMIC MODULES +################################################## +@ENABLE_STATIC_MODULE_FALSE@CPPFLAGS_MOD_COMMON = $(CPPFLAGS_LIB_COMMON) +@ENABLE_STATIC_MODULE_FALSE@LDFLAGS_MOD_COMMON = $(LDFLAGS_LIB_COMMON) +@ENABLE_STATIC_MODULE_FALSE@LIBADD_MOD_COMMON = -lstix +@ENABLE_STATIC_MODULE_FALSE@pkgmodexecdir = $(libdir) +@ENABLE_STATIC_MODULE_FALSE@pkgmodexec_LTLIBRARIES = libstix-snd.la +@ENABLE_STATIC_MODULE_FALSE@libstix_snd_la_SOURCES = mod-snd.c mod-snd.h +@ENABLE_STATIC_MODULE_FALSE@libstix_snd_la_CPPFLAGS = $(CPPFLAGS_MOD_COMMON) +@ENABLE_STATIC_MODULE_FALSE@libstix_snd_la_LDFLAGS = $(LDFLAGS_MOD_COMMON) +@ENABLE_STATIC_MODULE_FALSE@libstix_snd_la_LIBADD = $(LIBADD_MOD_COMMON) all: stix-cfg.h $(MAKE) $(AM_MAKEFLAGS) all-am @@ -458,6 +495,40 @@ clean-pkglibLTLIBRARIES: echo "rm -f \"$${dir}/so_locations\""; \ rm -f "$${dir}/so_locations"; \ done +install-pkgmodexecLTLIBRARIES: $(pkgmodexec_LTLIBRARIES) + @$(NORMAL_INSTALL) + @list='$(pkgmodexec_LTLIBRARIES)'; test -n "$(pkgmodexecdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(MKDIR_P) '$(DESTDIR)$(pkgmodexecdir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(pkgmodexecdir)" || exit 1; \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(pkgmodexecdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(pkgmodexecdir)"; \ + } + +uninstall-pkgmodexecLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(pkgmodexec_LTLIBRARIES)'; test -n "$(pkgmodexecdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(pkgmodexecdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(pkgmodexecdir)/$$f"; \ + done + +clean-pkgmodexecLTLIBRARIES: + -test -z "$(pkgmodexec_LTLIBRARIES)" || rm -f $(pkgmodexec_LTLIBRARIES) + @list='$(pkgmodexec_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libstix-snd.la: $(libstix_snd_la_OBJECTS) $(libstix_snd_la_DEPENDENCIES) $(EXTRA_libstix_snd_la_DEPENDENCIES) + $(AM_V_CCLD)$(libstix_snd_la_LINK) $(am_libstix_snd_la_rpath) $(libstix_snd_la_OBJECTS) $(libstix_snd_la_LIBADD) $(LIBS) libstix.la: $(libstix_la_OBJECTS) $(libstix_la_DEPENDENCIES) $(EXTRA_libstix_la_DEPENDENCIES) $(AM_V_CCLD)$(libstix_la_LINK) -rpath $(pkglibdir) $(libstix_la_OBJECTS) $(libstix_la_LIBADD) $(LIBS) install-pkgbinPROGRAMS: $(pkgbin_PROGRAMS) @@ -525,9 +596,11 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-ignite.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-obj.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-stix-rbt.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-stix-utl.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-stix.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-sym.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-utf8.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_snd_la-mod-snd.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stix-main.Po@am__quote@ .c.o: @@ -551,6 +624,13 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< +libstix_snd_la-mod-snd.lo: mod-snd.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstix_snd_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libstix_snd_la-mod-snd.lo -MD -MP -MF $(DEPDIR)/libstix_snd_la-mod-snd.Tpo -c -o libstix_snd_la-mod-snd.lo `test -f 'mod-snd.c' || echo '$(srcdir)/'`mod-snd.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_snd_la-mod-snd.Tpo $(DEPDIR)/libstix_snd_la-mod-snd.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mod-snd.c' object='libstix_snd_la-mod-snd.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstix_snd_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libstix_snd_la-mod-snd.lo `test -f 'mod-snd.c' || echo '$(srcdir)/'`mod-snd.c + libstix_la-stix-rbt.lo: stix-rbt.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstix_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libstix_la-stix-rbt.lo -MD -MP -MF $(DEPDIR)/libstix_la-stix-rbt.Tpo -c -o libstix_la-stix-rbt.lo `test -f 'stix-rbt.c' || echo '$(srcdir)/'`stix-rbt.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_la-stix-rbt.Tpo $(DEPDIR)/libstix_la-stix-rbt.Plo @@ -558,6 +638,13 @@ libstix_la-stix-rbt.lo: stix-rbt.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstix_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libstix_la-stix-rbt.lo `test -f 'stix-rbt.c' || echo '$(srcdir)/'`stix-rbt.c +libstix_la-stix-utl.lo: stix-utl.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstix_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libstix_la-stix-utl.lo -MD -MP -MF $(DEPDIR)/libstix_la-stix-utl.Tpo -c -o libstix_la-stix-utl.lo `test -f 'stix-utl.c' || echo '$(srcdir)/'`stix-utl.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_la-stix-utl.Tpo $(DEPDIR)/libstix_la-stix-utl.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='stix-utl.c' object='libstix_la-stix-utl.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstix_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libstix_la-stix-utl.lo `test -f 'stix-utl.c' || echo '$(srcdir)/'`stix-utl.c + libstix_la-stix.lo: stix.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstix_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libstix_la-stix.lo -MD -MP -MF $(DEPDIR)/libstix_la-stix.Tpo -c -o libstix_la-stix.lo `test -f 'stix.c' || echo '$(srcdir)/'`stix.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_la-stix.Tpo $(DEPDIR)/libstix_la-stix.Plo @@ -762,7 +849,7 @@ check-am: all-am check: check-am all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(HEADERS) stix-cfg.h installdirs: - for dir in "$(DESTDIR)$(pkglibdir)" "$(DESTDIR)$(pkgbindir)" "$(DESTDIR)$(pkgincludedir)"; do \ + for dir in "$(DESTDIR)$(pkglibdir)" "$(DESTDIR)$(pkgmodexecdir)" "$(DESTDIR)$(pkgbindir)" "$(DESTDIR)$(pkgincludedir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-am @@ -798,7 +885,8 @@ maintainer-clean-generic: clean: clean-am clean-am: clean-generic clean-libtool clean-pkgbinPROGRAMS \ - clean-pkglibLTLIBRARIES mostlyclean-am + clean-pkglibLTLIBRARIES clean-pkgmodexecLTLIBRARIES \ + mostlyclean-am distclean: distclean-am -rm -rf ./$(DEPDIR) @@ -825,7 +913,8 @@ install-dvi: install-dvi-am install-dvi-am: -install-exec-am: install-pkglibLTLIBRARIES +install-exec-am: install-pkglibLTLIBRARIES \ + install-pkgmodexecLTLIBRARIES install-html: install-html-am @@ -866,52 +955,31 @@ ps: ps-am ps-am: uninstall-am: uninstall-pkgbinPROGRAMS uninstall-pkgincludeHEADERS \ - uninstall-pkglibLTLIBRARIES + uninstall-pkglibLTLIBRARIES uninstall-pkgmodexecLTLIBRARIES @$(NORMAL_INSTALL) $(MAKE) $(AM_MAKEFLAGS) uninstall-hook .MAKE: all install-am install-data-am install-strip uninstall-am .PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ clean-libtool clean-pkgbinPROGRAMS clean-pkglibLTLIBRARIES \ - ctags distclean distclean-compile distclean-generic \ - distclean-hdr distclean-libtool distclean-tags distdir dvi \ - dvi-am html html-am info info-am install install-am \ - install-data install-data-am install-data-hook install-dvi \ - install-dvi-am install-exec install-exec-am install-html \ - install-html-am install-info install-info-am install-man \ - install-pdf install-pdf-am install-pkgbinPROGRAMS \ - install-pkgincludeHEADERS install-pkglibLTLIBRARIES install-ps \ - install-ps-am install-strip installcheck installcheck-am \ - installdirs maintainer-clean maintainer-clean-generic \ - mostlyclean mostlyclean-compile mostlyclean-generic \ - mostlyclean-libtool pdf pdf-am ps ps-am tags uninstall \ - uninstall-am uninstall-hook uninstall-pkgbinPROGRAMS \ - uninstall-pkgincludeHEADERS uninstall-pkglibLTLIBRARIES + clean-pkgmodexecLTLIBRARIES ctags distclean distclean-compile \ + distclean-generic distclean-hdr distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am \ + install-data-hook install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-man install-pdf install-pdf-am \ + install-pkgbinPROGRAMS install-pkgincludeHEADERS \ + install-pkglibLTLIBRARIES install-pkgmodexecLTLIBRARIES \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-hook \ + uninstall-pkgbinPROGRAMS uninstall-pkgincludeHEADERS \ + uninstall-pkglibLTLIBRARIES uninstall-pkgmodexecLTLIBRARIES -################################################## -# STATIC MODULES BUILT INTO MAIN LIBRARY -################################################## -#libstix_la_SOURCES += \ -# mod-dir.c mod-dir.h \ -#libstix_la_LIBADD += - -################################################## -# DYNAMIC MODULES -################################################## - -#CPPFLAGS_MOD_COMMON = $(CPPFLAGS_ALL_COMMON) -#LDFLAGS_MOD_COMMON = $(LDFLAGS_ALL_COMMON) -#LIBADD_MOD_COMMON = -lstix - -#modexecdir = $(libdir) - -#modexec_LTLIBRARIES = libstix-dir.la -#ibstix_dir_la_SOURCES = mod-dir.c mod-dir.h -#ibstix_dir_la_CPPFLAGS = $(CPPFLAGS_MOD_COMMON) -#ibstix_dir_la_LDFLAGS = $(LDFLAGS_MOD_COMMON) -#ibstix_dir_la_LIBADD = $(LIBADD_MOD_COMMON) - install-data-hook: @echo "#ifndef _STIX_CFG_H_" > "$(DESTDIR)$(pkgincludedir)/stix-cfg.h" @echo "#define _STIX_CFG_H_" >> "$(DESTDIR)$(pkgincludedir)/stix-cfg.h" diff --git a/stix/lib/comp.c b/stix/lib/comp.c index 1272300..46e7177 100644 --- a/stix/lib/comp.c +++ b/stix/lib/comp.c @@ -4224,6 +4224,8 @@ static int add_compiled_method (stix_t* stix) mth->owner = stix->c->cls.self_oop; mth->preamble = STIX_OOP_FROM_SMINT(STIX_METHOD_MAKE_PREAMBLE(preamble_code, preamble_index)); + mth->preamble_data[0] = STIX_OOP_FROM_SMINT(0); + mth->preamble_data[1] = STIX_OOP_FROM_SMINT(0); mth->tmpr_count = STIX_OOP_FROM_SMINT(stix->c->mth.tmpr_count); mth->tmpr_nargs = STIX_OOP_FROM_SMINT(stix->c->mth.tmpr_nargs); diff --git a/stix/lib/exec.c b/stix/lib/exec.c index c6c558d..7f0c60a 100644 --- a/stix/lib/exec.c +++ b/stix/lib/exec.c @@ -1033,6 +1033,7 @@ static int primitive_ffi_open (stix_t* stix, stix_ooi_t nargs) return 0; } + /* TODO: check null-termination... */ handle = stix->vmprim.mod_open (stix, ((stix_oop_char_t)arg)->slot); if (!handle) @@ -1283,12 +1284,12 @@ printf ("wrong function name...\n"); return 1; } -typedef int (*primitive_handler_t) (stix_t* stix, stix_ooi_t nargs); + struct primitive_t { stix_ooi_t nargs; /* expected number of arguments */ - primitive_handler_t handler; + stix_prim_impl_t handler; const char* name; /* the name is supposed to be 7-bit ascii only */ }; typedef struct primitive_t primitive_t; @@ -1341,31 +1342,6 @@ int stix_getprimno (stix_t* stix, const stix_ucs_t* name) return -1; } -typedef struct stix_prim_mod_t stix_prim_mod_t; - -typedef int (*stix_prim_mod_load_t) ( - stix_t* stix, - stix_prim_mod_t* mod -); - -typedef void* (*stix_prim_mod_query_t) ( - stix_t* stix, - stix_prim_mod_t* mod, - const stix_uch_t* name -); - -typedef void (*stix_prim_mod_unload_t) ( - stix_t* stix, - stix_prim_mod_t* mod -); - -struct stix_prim_mod_t -{ - stix_prim_mod_load_t load; - stix_prim_mod_unload_t unload; - stix_prim_mod_query_t query; -}; - struct stix_prim_mod_data_t { void* handle; @@ -1373,12 +1349,13 @@ struct stix_prim_mod_data_t }; typedef struct stix_prim_mod_data_t stix_prim_mod_data_t; -static stix_prim_mod_t* query_primitive_module (stix_t* stix, const stix_uch_t* name, stix_oow_t len) +static stix_prim_impl_t query_primitive_module (stix_t* stix, const stix_uch_t* name, stix_oow_t len) { stix_rbt_pair_t* pair; stix_prim_mod_data_t* mdp; const stix_uch_t* sep; stix_oow_t mod_name_len; + stix_prim_impl_t handler; int n; sep = stix_findchar (name, len, '_'); @@ -1396,25 +1373,25 @@ static stix_prim_mod_t* query_primitive_module (stix_t* stix, const stix_uch_t* stix_prim_mod_load_t load = STIX_NULL; /* maximum module name length is STIX_MOD_NAME_LEN_MAX. - * 17 is decomposed to 15 + 1 + 1. - * 15 for _stix_prim_mod_. + * 16 is decomposed to 14 + 1 + 1. + * 14 for stix_prim_mod_. * 1 for _ at the end when stix_prim_mod_xxx_ is attempted. * 1 for the terminating '\0'. */ - stix_uch_t buf[STIX_MOD_NAME_LEN_MAX + 17]; + stix_uch_t buf[STIX_MOD_NAME_LEN_MAX + 16]; /* the terminating null isn't needed in buf here */ - stix_copybchtouchars (buf, "_stix_prim_mod_", 15); + stix_copybchtouchars (buf, "stix_prim_mod_", 14); - if (mod_name_len > STIX_COUNTOF(buf) - 17) + if (mod_name_len > STIX_COUNTOF(buf) - 16) { /* module name too long */ stix->errnum = STIX_EINVAL; /* TODO: change the error number to something more specific */ return STIX_NULL; } - stix_copyuchars (&buf[15], name, mod_name_len); - buf[15 + mod_name_len] = '\0'; + stix_copyuchars (&buf[14], name, mod_name_len); + buf[14 + mod_name_len] = '\0'; #if defined(STIX_ENABLE_STATIC_MODULE) /* attempt to find a statically linked module */ @@ -1466,7 +1443,7 @@ static stix_prim_mod_t* query_primitive_module (stix_t* stix, const stix_uch_t* STIX_MEMSET (&md, 0, STIX_SIZEOF(md)); if (stix->vmprim.mod_open && stix->vmprim.mod_getsym && stix->vmprim.mod_close) { - md.handle = stix->vmprim.mod_open (stix, &buf[15]); + md.handle = stix->vmprim.mod_open (stix, &buf[14]); } if (md.handle == STIX_NULL) @@ -1497,15 +1474,27 @@ static stix_prim_mod_t* query_primitive_module (stix_t* stix, const stix_uch_t* mdp = (stix_prim_mod_data_t*)STIX_RBT_VPTR(pair); if (load (stix, &mdp->mod) <= -1) { + /* stix->errnum = STIX_ENOENT; TODO: proper error code and handling */ stix_rbt_delete (&stix->pmtable, name, mod_name_len); stix->vmprim.mod_close (stix, mdp->handle); return STIX_NULL; } + + if (!mdp->mod.query) + { + /* the module must be at fault */ + stix->errnum = STIX_EINVAL; /* TODO: proper error code and handling */ + return STIX_NULL; + } } done: - if (mdp->mod.query (stix, &mdp->mod, sep + 1) == STIX_NULL) return STIX_NULL; - return &mdp->mod; + if ((handler = mdp->mod.query (stix, &mdp->mod, sep + 1)) == STIX_NULL) + { + stix->errnum = STIX_ENOENT; /* TODO: proper error code and handling */ + return STIX_NULL; + } + return handler; } /* ------------------------------------------------------------------------- */ @@ -2121,7 +2110,7 @@ printf ("]\n"); if (n >= 1) break; } - /* primitive failed */ + /* primitive handler failed */ if (activate_new_method (stix, newmth) <= -1) goto oops; break; } @@ -2130,7 +2119,7 @@ printf ("]\n"); { stix_ooi_t prim_name_index; stix_oop_t name; - primitive_handler_t handler; + stix_prim_impl_t handler; prim_name_index = STIX_METHOD_GET_PREAMBLE_INDEX(preamble); DBGOUT_EXEC_1 ("METHOD_PREAMBLE_NAMED_PRIMITIVE %d", (int)prim_name_index); @@ -2141,28 +2130,36 @@ printf ("]\n"); STIX_ASSERT (STIX_OBJ_GET_FLAGS_EXTRA(name)); STIX_ASSERT (STIX_CLASSOF(stix,name) == stix->_symbol); - handler = query_primitive_module (stix, ((stix_oop_char_t)name)->slot, STIX_OBJ_GET_SIZE(name)); + /* merge two SmallIntegers to get a full pointer */ + handler = (stix_oow_t)STIX_OOP_TO_SMINT(newmth->preamble_data[0]) << (STIX_OOW_BITS / 2) | + (stix_oow_t)STIX_OOP_TO_SMINT(newmth->preamble_data[1]); + if (!handler) handler = query_primitive_module (stix, ((stix_oop_char_t)name)->slot, STIX_OBJ_GET_SIZE(name)); + if (handler) { int n; + /* split a pointer to two OOP fields as SmallIntegers for storing. */ + newmth->preamble_data[0] = STIX_OOP_FROM_SMINT((stix_oow_t)handler >> (STIX_OOW_BITS / 2)); + newmth->preamble_data[1] = STIX_OOP_FROM_SMINT((stix_oow_t)handler & STIX_LBMASK(stix_oow_t, STIX_OOW_BITS / 2)); + stix_pushtmp (stix, (stix_oop_t*)&newmth); n = handler (stix, b1); stix_poptmp (stix); if (n <= -1) goto oops; if (n >= 1) break; } + - /* primitive failed */ + /* primitive handler failed or not found*/ if (activate_new_method (stix, newmth) <= -1) goto oops; break; } default: - /* this must not happen */ - - stix->errnum = STIX_EINTERN; - return -1; + STIX_ASSERT (preamble_code == STIX_METHOD_PREAMBLE_NONE); + if (activate_new_method (stix, newmth) <= -1) goto oops; + break; } break; /* CMD_SEND_MESSAGE */ diff --git a/stix/lib/main.c b/stix/lib/main.c index e3c1f7c..e8463d1 100644 --- a/stix/lib/main.c +++ b/stix/lib/main.c @@ -29,9 +29,28 @@ #include #include #include -#include - #include + + +#if defined(_WIN32) +# include +# include +# if defined(STIX_HAVE_CFG_H) +# include +# define USE_LTDL +# endif +#elif defined(__OS2__) +# define INCL_DOSMODULEMGR +# define INCL_DOSPROCESS +# define INCL_DOSERRORS +# include +#elif defined(__DOS__) + /* nothing to include */ +#else +# include +# include +# define USE_LTDL +#endif #include #if !defined(STIX_DEFAULT_MODPREFIX) @@ -196,10 +215,22 @@ static stix_ssize_t input_handler (stix_t* stix, stix_io_cmd_t cmd, stix_io_arg_ static void* mod_open (stix_t* stix, const stix_uch_t* name) { +#if defined(USE_LTDL) /* TODO: support various platforms */ stix_bch_t buf[1024]; /* TODO: use a proper path buffer */ stix_size_t ucslen, bcslen; stix_size_t len; + void* handle; + +/* TODO: using MODPREFIX isn't a good idean for all kind of modules. + * OK to use it for a primitive module. + * NOT OK to use it for a FFI target. + * Attempting /home/hyung-hwan/xxx/lib/libstix-libc.so.6 followed by libc.so.6 is bad. + * Need to accept the type or flags? + * + * mod_open (stix, "xxxx", STIX_MOD_EXTERNAL); + * if external, don't use DEFAULT_MODPERFIX and MODPOSTFIX??? + */ len = stix_copybcstr (buf, STIX_COUNTOF(buf), STIX_DEFAULT_MODPREFIX); @@ -208,17 +239,44 @@ static void* mod_open (stix_t* stix, const stix_uch_t* name) bcslen = STIX_COUNTOF(buf) - len; stix_ucstoutf8 (name, &ucslen, &buf[len], &bcslen); + stix_copybcstr (&buf[bcslen + len], STIX_COUNTOF(buf) - bcslen - len, STIX_DEFAULT_MODPOSTFIX); + printf ("MOD_OPEN %s\n", buf); - return dlopen (buf, RTLD_NOW); + handle = lt_dlopenext (buf); + if (!handle) + { + buf[bcslen + len] = '\0'; +printf ("MOD_OPEN %s\n", &buf[len]); + handle = lt_dlopenext (&buf[len]); + } + +printf ("MOD_OPEN RET=>%p\n", handle); + return handle; + +#else + /* TODO: implemenent this */ + return STIX_NULL; +#endif } static void mod_close (stix_t* stix, void* handle) { - dlclose (handle); +#if defined(USE_LTDL) + lt_dlclose (handle); +#elif defined(_WIN32) + FreeLibrary ((HMODULE)handle); +#elif defined(__OS2__) + DosFreeModule ((HMODULE)handle); +#elif defined(__DOS__) && defined(QSE_ENABLE_DOS_DYNAMIC_MODULE) + FreeModule (handle); +#else + /* nothing to do */ +#endif } static void* mod_getsym (stix_t* stix, void* handle, const stix_uch_t* name) { +#if defined(USE_LTDL) stix_bch_t buf[1024]; /* TODO: use a proper buffer. dynamically allocated if conversion result in too a large value */ stix_size_t ucslen, bcslen; void* sym; @@ -229,17 +287,17 @@ static void* mod_getsym (stix_t* stix, void* handle, const stix_uch_t* name) bcslen = STIX_COUNTOF(buf) - 2; stix_ucstoutf8 (name, &ucslen, &buf[1], &bcslen); printf ("MOD_GETSYM [%s]\n", &buf[1]); - sym = dlsym (handle, &buf[1]); + sym = lt_dlsym (handle, &buf[1]); if (!sym) { printf ("MOD_GETSYM [%s]\n", &buf[0]); - sym = dlsym (handle, &buf[0]); + sym = lt_dlsym (handle, &buf[0]); if (!sym) { buf[bcslen + 1] = '_'; buf[bcslen + 2] = '\0'; printf ("MOD_GETSYM [%s]\n", &buf[1]); - sym = dlsym (handle, &buf[1]); + sym = lt_dlsym (handle, &buf[1]); if (!sym) { printf ("MOD_GETSYM [%s]\n", &buf[0]); @@ -249,6 +307,10 @@ printf ("MOD_GETSYM [%s]\n", &buf[0]); } return sym; +#else + /* TODO: IMPLEMENT THIS */ + return STIX_NULL; +#endif } static char* syntax_error_msg[] = @@ -360,6 +422,10 @@ int main (int argc, char* argv[]) vmprim.mod_close = mod_close; vmprim.mod_getsym = mod_getsym; +#if defined(USE_LTDL) + lt_dlinit (); +#endif + stix = stix_open (&sys_mmgr, STIX_SIZEOF(xtn_t), 512000lu, &vmprim, STIX_NULL); if (!stix) { @@ -502,6 +568,8 @@ printf ("%p\n", a); dump_dictionary (stix, stix->sysdic, "System dictionary"); stix_close (stix); - +#if defined(USE_LTDL) + lt_dlexit (); +#endif return 0; } diff --git a/stix/lib/stix-cmn.h b/stix/lib/stix-cmn.h index f8f922c..c210ddd 100644 --- a/stix/lib/stix-cmn.h +++ b/stix/lib/stix-cmn.h @@ -1,4 +1,3 @@ - /* * $Id$ * diff --git a/stix/lib/stix-prv.h b/stix/lib/stix-prv.h index d987cca..133cde2 100644 --- a/stix/lib/stix-prv.h +++ b/stix/lib/stix-prv.h @@ -28,6 +28,7 @@ #define _STIX_PRV_H_ #include "stix.h" +#include "stix-utl.h" /* you can define this to either 1 or 2 */ #define STIX_BCODE_LONG_PARAM_SIZE 2 @@ -857,62 +858,6 @@ stix_size_t stix_hashuchars ( #define stix_hashbchars(ptr,len) stix_hashbytes(ptr,len) -int stix_equalchars ( - const stix_uch_t* str1, - const stix_uch_t* str2, - stix_size_t len -); - -int stix_compucstr ( - const stix_uch_t* str1, - const stix_uch_t* str2 -); - -int stix_compbcstr ( - const stix_bch_t* str1, - const stix_bch_t* str2 -); - -int stix_compucbcstr ( - const stix_uch_t* str1, - const stix_bch_t* str2 -); - -int stix_compucxbcstr ( - const stix_uch_t* str1, - stix_size_t len, - const stix_bch_t* str2 -); - -void stix_copyuchars ( - stix_uch_t* dst, - const stix_uch_t* src, - stix_size_t len -); - -void stix_copybchtouchars ( - stix_uch_t* dst, - const stix_bch_t* src, - stix_size_t len -); - -stix_uch_t* stix_findchar ( - const stix_uch_t* ptr, - stix_size_t len, - stix_uch_t c -); - -stix_size_t stix_copyucstr ( - stix_uch_t* dst, - stix_size_t len, - const stix_uch_t* src -); - -stix_size_t stix_copybcstr ( - stix_bch_t* dst, - stix_size_t len, - const stix_bch_t* src -); /* ========================================================================= */ /* gc.c */ diff --git a/stix/lib/stix-utl.c b/stix/lib/stix-utl.c new file mode 100644 index 0000000..6d67e81 --- /dev/null +++ b/stix/lib/stix-utl.c @@ -0,0 +1,141 @@ + +/* + * $Id$ + * + Copyright (c) 2014-2015 Chung, Hyung-Hwan. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "stix-utl.h" + +int stix_equalchars (const stix_uch_t* str1, const stix_uch_t* str2, stix_size_t len) +{ + stix_size_t i; + + for (i = 0; i < len; i++) + { + if (str1[i] != str2[i]) return 0; + } + + return 1; +} + +int stix_compucstr (const stix_uch_t* str1, const stix_uch_t* str2) +{ + while (*str1 == *str2) + { + if (*str1 == '\0') return 0; + str1++, str2++; + } + + return (*str1 > *str2)? 1: -1; +} + +int stix_compbcstr (const stix_bch_t* str1, const stix_bch_t* str2) +{ + while (*str1 == *str2) + { + if (*str1 == '\0') return 0; + str1++, str2++; + } + + return (*str1 > *str2)? 1: -1; +} + +int stix_compucbcstr (const stix_uch_t* str1, const stix_bch_t* str2) +{ + while (*str1 == *str2) + { + if (*str1 == '\0') return 0; + str1++, str2++; + } + + return (*str1 > *str2)? 1: -1; +} + +int stix_compucxbcstr (const stix_uch_t* str1, stix_size_t len, const stix_bch_t* str2) +{ + const stix_uch_t* end = str1 + len; + while (str1 < end && *str2 != '\0' && *str1 == *str2) str1++, str2++; + if (str1 == end && *str2 == '\0') return 0; + if (*str1 == *str2) return (str1 < end)? 1: -1; + return (*str1 > *str2)? 1: -1; +} + +void stix_copyuchars (stix_uch_t* dst, const stix_uch_t* src, stix_size_t len) +{ + stix_size_t i; + for (i = 0; i < len; i++) dst[i] = src[i]; +} + +void stix_copybchtouchars (stix_uch_t* dst, const stix_bch_t* src, stix_size_t len) +{ + stix_size_t i; + for (i = 0; i < len; i++) dst[i] = src[i]; +} + +stix_size_t stix_copyucstr (stix_uch_t* dst, stix_size_t len, const stix_uch_t* src) +{ + stix_uch_t* p, * p2; + + p = dst; p2 = dst + len - 1; + + while (p < p2) + { + if (*src == '\0') break; + *p++ = *src++; + } + + if (len > 0) *p = '\0'; + return p - dst; +} + +stix_size_t stix_copybcstr (stix_bch_t* dst, stix_size_t len, const stix_bch_t* src) +{ + stix_bch_t* p, * p2; + + p = dst; p2 = dst + len - 1; + + while (p < p2) + { + if (*src == '\0') break; + *p++ = *src++; + } + + if (len > 0) *p = '\0'; + return p - dst; +} + +stix_uch_t* stix_findchar (const stix_uch_t* ptr, stix_size_t len, stix_uch_t c) +{ + const stix_uch_t* end; + + end = ptr + len; + while (ptr < end) + { + if (*ptr == c) return (stix_uch_t*)ptr; + ptr++; + } + + return STIX_NULL; +} + diff --git a/stix/lib/stix-utl.h b/stix/lib/stix-utl.h new file mode 100644 index 0000000..42e3fcf --- /dev/null +++ b/stix/lib/stix-utl.h @@ -0,0 +1,103 @@ +/* + * $Id$ + * + Copyright (c) 2014-2015 Chung, Hyung-Hwan. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STIX_UTL_H_ +#define _STIX_UTL_H_ + +#include "stix-cmn.h" + +#if defined(__cplusplus) +extern "C" { +#endif + + +/* ========================================================================= */ +/* stix-utl.c */ +/* ========================================================================= */ +int stix_equalchars ( + const stix_uch_t* str1, + const stix_uch_t* str2, + stix_size_t len +); + +int stix_compucstr ( + const stix_uch_t* str1, + const stix_uch_t* str2 +); + +int stix_compbcstr ( + const stix_bch_t* str1, + const stix_bch_t* str2 +); + +int stix_compucbcstr ( + const stix_uch_t* str1, + const stix_bch_t* str2 +); + +int stix_compucxbcstr ( + const stix_uch_t* str1, + stix_size_t len, + const stix_bch_t* str2 +); + +void stix_copyuchars ( + stix_uch_t* dst, + const stix_uch_t* src, + stix_size_t len +); + +void stix_copybchtouchars ( + stix_uch_t* dst, + const stix_bch_t* src, + stix_size_t len +); + +stix_uch_t* stix_findchar ( + const stix_uch_t* ptr, + stix_size_t len, + stix_uch_t c +); + +stix_size_t stix_copyucstr ( + stix_uch_t* dst, + stix_size_t len, + const stix_uch_t* src +); + +stix_size_t stix_copybcstr ( + stix_bch_t* dst, + stix_size_t len, + const stix_bch_t* src +); + + +#if defined(__cplusplus) +} +#endif + + +#endif diff --git a/stix/lib/stix.c b/stix/lib/stix.c index f5721eb..c6ce4e2 100644 --- a/stix/lib/stix.c +++ b/stix/lib/stix.c @@ -208,117 +208,6 @@ stix_size_t stix_hashuchars (const stix_uch_t* ptr, stix_size_t len) return stix_hashbytes ((const stix_byte_t *)ptr, len * STIX_SIZEOF(*ptr)); } -int stix_equalchars (const stix_uch_t* str1, const stix_uch_t* str2, stix_size_t len) -{ - stix_size_t i; - - for (i = 0; i < len; i++) - { - if (str1[i] != str2[i]) return 0; - } - - return 1; -} - -int stix_compucstr (const stix_uch_t* str1, const stix_uch_t* str2) -{ - while (*str1 == *str2) - { - if (*str1 == '\0') return 0; - str1++, str2++; - } - - return (*str1 > *str2)? 1: -1; -} - -int stix_compbcstr (const stix_bch_t* str1, const stix_bch_t* str2) -{ - while (*str1 == *str2) - { - if (*str1 == '\0') return 0; - str1++, str2++; - } - - return (*str1 > *str2)? 1: -1; -} - -int stix_compucbcstr (const stix_uch_t* str1, const stix_bch_t* str2) -{ - while (*str1 == *str2) - { - if (*str1 == '\0') return 0; - str1++, str2++; - } - - return (*str1 > *str2)? 1: -1; -} - -int stix_compucxbcstr (const stix_uch_t* str1, stix_size_t len, const stix_bch_t* str2) -{ - const stix_uch_t* end = str1 + len; - while (str1 < end && *str2 != '\0' && *str1 == *str2) str1++, str2++; - if (str1 == end && *str2 == '\0') return 0; - if (*str1 == *str2) return (str1 < end)? 1: -1; - return (*str1 > *str2)? 1: -1; -} - -void stix_copyuchars (stix_uch_t* dst, const stix_uch_t* src, stix_size_t len) -{ - stix_size_t i; - for (i = 0; i < len; i++) dst[i] = src[i]; -} - -void stix_copybchtouchars (stix_uch_t* dst, const stix_bch_t* src, stix_size_t len) -{ - stix_size_t i; - for (i = 0; i < len; i++) dst[i] = src[i]; -} - -stix_size_t stix_copyucstr (stix_uch_t* dst, stix_size_t len, const stix_uch_t* src) -{ - stix_uch_t* p, * p2; - - p = dst; p2 = dst + len - 1; - - while (p < p2) - { - if (*src == '\0') break; - *p++ = *src++; - } - - if (len > 0) *p = '\0'; - return p - dst; -} - -stix_size_t stix_copybcstr (stix_bch_t* dst, stix_size_t len, const stix_bch_t* src) -{ - stix_bch_t* p, * p2; - - p = dst; p2 = dst + len - 1; - - while (p < p2) - { - if (*src == '\0') break; - *p++ = *src++; - } - - if (len > 0) *p = '\0'; - return p - dst; -} - -stix_uch_t* stix_findchar (const stix_uch_t* ptr, stix_size_t len, stix_uch_t c) -{ - const stix_uch_t* end; - - end = ptr + len; - while (ptr < end) - { - if (*ptr == c) return (stix_uch_t*)ptr; - ptr++; - } - - return STIX_NULL; -} void* stix_allocmem (stix_t* stix, stix_size_t size) { diff --git a/stix/lib/stix.h b/stix/lib/stix.h index 541a2b5..985b723 100644 --- a/stix/lib/stix.h +++ b/stix/lib/stix.h @@ -503,7 +503,7 @@ typedef struct stix_t stix_t; /* ========================================================================= * VIRTUAL MACHINE PRIMITIVES * ========================================================================= */ -#define STIX_MOD_NAME_LEN_MAX 60 +#define STIX_MOD_NAME_LEN_MAX 120 typedef void* (*stix_mod_open_t) (stix_t* stix, const stix_uch_t* name); typedef void (*stix_mod_close_t) (stix_t* stix, void* handle); @@ -541,6 +541,39 @@ struct stix_cb_t }; +/* ========================================================================= + * PRIMITIVE MODULE MANIPULATION + * ========================================================================= */ +typedef int (*stix_prim_impl_t) (stix_t* stix, stix_ooi_t nargs); + +typedef struct stix_prim_mod_t stix_prim_mod_t; + +typedef int (*stix_prim_mod_load_t) ( + stix_t* stix, + stix_prim_mod_t* mod +); + +typedef stix_prim_impl_t (*stix_prim_mod_query_t) ( + stix_t* stix, + stix_prim_mod_t* mod, + const stix_uch_t* name +); + +typedef void (*stix_prim_mod_unload_t) ( + stix_t* stix, + stix_prim_mod_t* mod +); + +struct stix_prim_mod_t +{ + stix_prim_mod_unload_t unload; + stix_prim_mod_query_t query; + void* ctx; +}; + +/* ========================================================================= + * STIX VM + * ========================================================================= */ #if defined(STIX_INCLUDE_COMPILER) typedef struct stix_compiler_t stix_compiler_t; #endif