diff --git a/stix/Makefile.in b/stix/Makefile.in index f0ab6e3..818b03e 100644 --- a/stix/Makefile.in +++ b/stix/Makefile.in @@ -97,7 +97,7 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ configure.lineno config.status.lineno mkinstalldirs = $(install_sh) -d -CONFIG_HEADER = $(top_builddir)/lib/stix-cfg.h +CONFIG_HEADER = $(top_builddir)/lib/moo-cfg.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = AM_V_P = $(am__v_P_@AM_V@) @@ -260,6 +260,20 @@ LT_DLPREOPEN = @LT_DLPREOPEN@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ +MOO_PROJECT_AUTHOR = @MOO_PROJECT_AUTHOR@ +MOO_PROJECT_URL = @MOO_PROJECT_URL@ +MOO_SIZEOF_CHAR = @MOO_SIZEOF_CHAR@ +MOO_SIZEOF_DOUBLE = @MOO_SIZEOF_DOUBLE@ +MOO_SIZEOF_FLOAT = @MOO_SIZEOF_FLOAT@ +MOO_SIZEOF_INT = @MOO_SIZEOF_INT@ +MOO_SIZEOF_LONG = @MOO_SIZEOF_LONG@ +MOO_SIZEOF_LONG_DOUBLE = @MOO_SIZEOF_LONG_DOUBLE@ +MOO_SIZEOF_LONG_LONG = @MOO_SIZEOF_LONG_LONG@ +MOO_SIZEOF_OFF64_T = @MOO_SIZEOF_OFF64_T@ +MOO_SIZEOF_OFF_T = @MOO_SIZEOF_OFF_T@ +MOO_SIZEOF_SHORT = @MOO_SIZEOF_SHORT@ +MOO_SIZEOF_VOID_P = @MOO_SIZEOF_VOID_P@ +MOO_SIZEOF_WCHAR_T = @MOO_SIZEOF_WCHAR_T@ NM = @NM@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ @@ -282,20 +296,6 @@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ -STIX_PROJECT_AUTHOR = @STIX_PROJECT_AUTHOR@ -STIX_PROJECT_URL = @STIX_PROJECT_URL@ -STIX_SIZEOF_CHAR = @STIX_SIZEOF_CHAR@ -STIX_SIZEOF_DOUBLE = @STIX_SIZEOF_DOUBLE@ -STIX_SIZEOF_FLOAT = @STIX_SIZEOF_FLOAT@ -STIX_SIZEOF_INT = @STIX_SIZEOF_INT@ -STIX_SIZEOF_LONG = @STIX_SIZEOF_LONG@ -STIX_SIZEOF_LONG_DOUBLE = @STIX_SIZEOF_LONG_DOUBLE@ -STIX_SIZEOF_LONG_LONG = @STIX_SIZEOF_LONG_LONG@ -STIX_SIZEOF_OFF64_T = @STIX_SIZEOF_OFF64_T@ -STIX_SIZEOF_OFF_T = @STIX_SIZEOF_OFF_T@ -STIX_SIZEOF_SHORT = @STIX_SIZEOF_SHORT@ -STIX_SIZEOF_VOID_P = @STIX_SIZEOF_VOID_P@ -STIX_SIZEOF_WCHAR_T = @STIX_SIZEOF_WCHAR_T@ STRIP = @STRIP@ UNICOWS_LIBS = @UNICOWS_LIBS@ VERSION = @VERSION@ diff --git a/stix/configure b/stix/configure index 36f9fb3..218dd9b 100755 --- a/stix/configure +++ b/stix/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for stix 0.6.0. +# Generated by GNU Autoconf 2.69 for moo 0.1.0. # # Report bugs to . # @@ -592,12 +592,12 @@ MFLAGS= MAKEFLAGS= # Identity of this package. -PACKAGE_NAME='stix' -PACKAGE_TARNAME='stix' -PACKAGE_VERSION='0.6.0' -PACKAGE_STRING='stix 0.6.0' +PACKAGE_NAME='moo' +PACKAGE_TARNAME='moo' +PACKAGE_VERSION='0.1.0' +PACKAGE_STRING='moo 0.1.0' PACKAGE_BUGREPORT='Chung, Hyung-Hwan (hyunghwan.chung@gmail.com)' -PACKAGE_URL='http://code.abiyo.net/@stix' +PACKAGE_URL='http://code.abiyo.net/@moo' # Factoring default headers for most tests. ac_includes_default="\ @@ -642,20 +642,20 @@ am__EXEEXT_FALSE am__EXEEXT_TRUE LTLIBOBJS LIBOBJS -STIX_PROJECT_URL -STIX_PROJECT_AUTHOR -STIX_SIZEOF_OFF64_T -STIX_SIZEOF_OFF_T -STIX_SIZEOF_LONG_DOUBLE -STIX_SIZEOF_DOUBLE -STIX_SIZEOF_FLOAT -STIX_SIZEOF_VOID_P -STIX_SIZEOF_CHAR -STIX_SIZEOF_SHORT -STIX_SIZEOF_INT -STIX_SIZEOF_LONG -STIX_SIZEOF_LONG_LONG -STIX_SIZEOF_WCHAR_T +MOO_PROJECT_URL +MOO_PROJECT_AUTHOR +MOO_SIZEOF_OFF64_T +MOO_SIZEOF_OFF_T +MOO_SIZEOF_LONG_DOUBLE +MOO_SIZEOF_DOUBLE +MOO_SIZEOF_FLOAT +MOO_SIZEOF_VOID_P +MOO_SIZEOF_CHAR +MOO_SIZEOF_SHORT +MOO_SIZEOF_INT +MOO_SIZEOF_LONG +MOO_SIZEOF_LONG_LONG +MOO_SIZEOF_WCHAR_T ENABLE_STATIC_MODULE_FALSE ENABLE_STATIC_MODULE_TRUE ENABLE_CXX_FALSE @@ -1382,7 +1382,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures stix 0.6.0 to adapt to many kinds of systems. +\`configure' configures moo 0.1.0 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1430,7 +1430,7 @@ Fine tuning of the installation directories: --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] - --docdir=DIR documentation root [DATAROOTDIR/doc/stix] + --docdir=DIR documentation root [DATAROOTDIR/doc/moo] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] @@ -1452,7 +1452,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of stix 0.6.0:";; + short | recursive ) echo "Configuration of moo 0.1.0:";; esac cat <<\_ACEOF @@ -1507,7 +1507,7 @@ Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. Report bugs to . -stix home page: . +moo home page: . _ACEOF ac_status=$? fi @@ -1570,7 +1570,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -stix configure 0.6.0 +moo configure 0.1.0 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2343,7 +2343,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by stix $as_me 0.6.0, which was +It was created by moo $as_me 0.1.0, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2692,7 +2692,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu -ac_config_headers="$ac_config_headers lib/stix-cfg.h" +ac_config_headers="$ac_config_headers lib/moo-cfg.h" ac_aux_dir= for ac_dir in ac "$srcdir"/ac; do @@ -3217,8 +3217,8 @@ fi # Define the identity of the package. - PACKAGE='stix' - VERSION='0.6.0' + PACKAGE='moo' + VERSION='0.1.0' cat >>confdefs.h <<_ACEOF @@ -17793,8 +17793,8 @@ then fi fi -CFLAGS="$CFLAGS -DSTIX_HAVE_CFG_H" -CXXFLAGS="$CXXFLAGS -DSTIX_HAVE_CFG_H" +CFLAGS="$CFLAGS -DMOO_HAVE_CFG_H" +CXXFLAGS="$CXXFLAGS -DMOO_HAVE_CFG_H" CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE" CXXFLAGS="$CXXFLAGS -D_LARGEFILE64_SOURCE" @@ -19460,161 +19460,161 @@ fi cat >>confdefs.h <<_ACEOF -#define STIX_SIZEOF_CHAR ${ac_cv_sizeof_char} +#define MOO_SIZEOF_CHAR ${ac_cv_sizeof_char} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_SIZEOF_SHORT ${ac_cv_sizeof_short} +#define MOO_SIZEOF_SHORT ${ac_cv_sizeof_short} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_SIZEOF_INT ${ac_cv_sizeof_int} +#define MOO_SIZEOF_INT ${ac_cv_sizeof_int} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_SIZEOF_LONG ${ac_cv_sizeof_long} +#define MOO_SIZEOF_LONG ${ac_cv_sizeof_long} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_SIZEOF_LONG_LONG ${ac_cv_sizeof_long_long} +#define MOO_SIZEOF_LONG_LONG ${ac_cv_sizeof_long_long} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_SIZEOF___INT8 ${ac_cv_sizeof___int8} +#define MOO_SIZEOF___INT8 ${ac_cv_sizeof___int8} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_SIZEOF___INT16 ${ac_cv_sizeof___int16} +#define MOO_SIZEOF___INT16 ${ac_cv_sizeof___int16} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_SIZEOF___INT32 ${ac_cv_sizeof___int32} +#define MOO_SIZEOF___INT32 ${ac_cv_sizeof___int32} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_SIZEOF___INT64 ${ac_cv_sizeof___int64} +#define MOO_SIZEOF___INT64 ${ac_cv_sizeof___int64} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_SIZEOF___INT128 ${ac_cv_sizeof___int128} +#define MOO_SIZEOF___INT128 ${ac_cv_sizeof___int128} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_SIZEOF___INT128_T ${ac_cv_sizeof___int128_t} +#define MOO_SIZEOF___INT128_T ${ac_cv_sizeof___int128_t} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_SIZEOF___UINT128_T ${ac_cv_sizeof___uint128_t} +#define MOO_SIZEOF___UINT128_T ${ac_cv_sizeof___uint128_t} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_SIZEOF_VOID_P ${ac_cv_sizeof_void_p} +#define MOO_SIZEOF_VOID_P ${ac_cv_sizeof_void_p} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_SIZEOF_FLOAT ${ac_cv_sizeof_float} +#define MOO_SIZEOF_FLOAT ${ac_cv_sizeof_float} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_SIZEOF_DOUBLE ${ac_cv_sizeof_double} +#define MOO_SIZEOF_DOUBLE ${ac_cv_sizeof_double} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_SIZEOF_LONG_DOUBLE ${ac_cv_sizeof_long_double} +#define MOO_SIZEOF_LONG_DOUBLE ${ac_cv_sizeof_long_double} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_SIZEOF___FLOAT128 ${ac_cv_sizeof___float128} +#define MOO_SIZEOF___FLOAT128 ${ac_cv_sizeof___float128} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_SIZEOF_WCHAR_T ${ac_cv_sizeof_wchar_t} +#define MOO_SIZEOF_WCHAR_T ${ac_cv_sizeof_wchar_t} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_SIZEOF_OFF_T ${ac_cv_sizeof_off_t} +#define MOO_SIZEOF_OFF_T ${ac_cv_sizeof_off_t} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_SIZEOF_OFF64_T ${ac_cv_sizeof_off64_t} +#define MOO_SIZEOF_OFF64_T ${ac_cv_sizeof_off64_t} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_SIZEOF_MBSTATE_T ${ac_cv_sizeof_mbstate_t} +#define MOO_SIZEOF_MBSTATE_T ${ac_cv_sizeof_mbstate_t} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_MBLEN_MAX ${ax_cv_numvalof_MB_LEN_MAX} +#define MOO_MBLEN_MAX ${ax_cv_numvalof_MB_LEN_MAX} _ACEOF -stix_package_version_major="`echo ${PACKAGE_VERSION} | cut -d. -f1`" -stix_package_version_minor="`echo ${PACKAGE_VERSION} | cut -d. -f2`" -stix_package_version_patch="`echo ${PACKAGE_VERSION} | cut -d. -f3`" -PACKAGE_VERSION_MAJOR=${stix_package_version_major} +moo_package_version_major="`echo ${PACKAGE_VERSION} | cut -d. -f1`" +moo_package_version_minor="`echo ${PACKAGE_VERSION} | cut -d. -f2`" +moo_package_version_patch="`echo ${PACKAGE_VERSION} | cut -d. -f3`" +PACKAGE_VERSION_MAJOR=${moo_package_version_major} -PACKAGE_VERSION_MINOR=${stix_package_version_minor} +PACKAGE_VERSION_MINOR=${moo_package_version_minor} -PACKAGE_VERSION_PATCH=${stix_package_version_patch} +PACKAGE_VERSION_PATCH=${moo_package_version_patch} cat >>confdefs.h <<_ACEOF -#define STIX_PACKAGE_VERSION "${PACKAGE_VERSION}" +#define MOO_PACKAGE_VERSION "${PACKAGE_VERSION}" _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_PACKAGE_VERSION_MAJOR ${stix_package_version_major} +#define MOO_PACKAGE_VERSION_MAJOR ${moo_package_version_major} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_PACKAGE_VERSION_MINOR ${stix_package_version_minor} +#define MOO_PACKAGE_VERSION_MINOR ${moo_package_version_minor} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_PACKAGE_VERSION_PATCH ${stix_package_version_patch} +#define MOO_PACKAGE_VERSION_PATCH ${moo_package_version_patch} _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_PACKAGE_AUTHOR "${PACKAGE_BUGREPORT}" +#define MOO_PACKAGE_AUTHOR "${PACKAGE_BUGREPORT}" _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_PACKAGE_NAME "${PACKAGE_NAME}" +#define MOO_PACKAGE_NAME "${PACKAGE_NAME}" _ACEOF cat >>confdefs.h <<_ACEOF -#define STIX_PACKAGE_URL "${PACKAGE_URL}" +#define MOO_PACKAGE_URL "${PACKAGE_URL}" _ACEOF @@ -19829,11 +19829,11 @@ $as_echo "$ac_cv_c_bigendian" >&6; } case $ac_cv_c_bigendian in #( yes) -$as_echo "#define STIX_ENDIAN_BIG /**/" >>confdefs.h +$as_echo "#define MOO_ENDIAN_BIG /**/" >>confdefs.h ;; #( no) -$as_echo "#define STIX_ENDIAN_LITTLE /**/" >>confdefs.h +$as_echo "#define MOO_ENDIAN_LITTLE /**/" >>confdefs.h ;; #( universal) @@ -19842,7 +19842,7 @@ $as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h ;; #( *) -$as_echo "#define STIX_ENDIAN_UNKNOWN /**/" >>confdefs.h +$as_echo "#define MOO_ENDIAN_UNKNOWN /**/" >>confdefs.h ;; esac @@ -19856,13 +19856,13 @@ fi if test "$enable_debug_is" = "yes" then - CFLAGS="$CFLAGS -g -D_DEBUG -UNDEBUG -DSTIX_BUILD_DEBUG -U_FORTIFY_SOURCE" - CXXFLAGS="$CXXFLAGS -g -D_DEBUG -UNDEBUG -DSTIX_BUILD_DEBUG -U_FORTIFY_SOURCE" + CFLAGS="$CFLAGS -g -D_DEBUG -UNDEBUG -DMOO_BUILD_DEBUG -U_FORTIFY_SOURCE" + CXXFLAGS="$CXXFLAGS -g -D_DEBUG -UNDEBUG -DMOO_BUILD_DEBUG -U_FORTIFY_SOURCE" BUILD_MODE="debug" else - CFLAGS="$CFLAGS -DNDEBUG -U_DEBUG -DSTIX_BUILD_RELEASE -U_FORTIFY_SOURCE" - CXXFLAGS="$CXXFLAGS -DNDEBUG -U_DEBUG -DSTIX_BUILD_RELEASE -U_FORTIFY_SOURCE" + CFLAGS="$CFLAGS -DNDEBUG -U_DEBUG -DMOO_BUILD_RELEASE -U_FORTIFY_SOURCE" + CXXFLAGS="$CXXFLAGS -DNDEBUG -U_DEBUG -DMOO_BUILD_RELEASE -U_FORTIFY_SOURCE" BUILD_MODE="release" fi @@ -19902,7 +19902,7 @@ test "${enable_shared}" = "no" -a "${enable_static}" = "yes" && enable_static_mo if test "${enable_static_module}" = "yes" then -$as_echo "#define STIX_ENABLE_STATIC_MODULE /**/" >>confdefs.h +$as_echo "#define MOO_ENABLE_STATIC_MODULE /**/" >>confdefs.h fi if test "${enable_static_module}" = "yes"; then @@ -19914,34 +19914,34 @@ else fi -STIX_SIZEOF_WCHAR_T=$ac_cv_sizeof_wchar_t +MOO_SIZEOF_WCHAR_T=$ac_cv_sizeof_wchar_t -STIX_SIZEOF_LONG_LONG=$ac_cv_sizeof_long_long +MOO_SIZEOF_LONG_LONG=$ac_cv_sizeof_long_long -STIX_SIZEOF_LONG=$ac_cv_sizeof_long +MOO_SIZEOF_LONG=$ac_cv_sizeof_long -STIX_SIZEOF_INT=$ac_cv_sizeof_int +MOO_SIZEOF_INT=$ac_cv_sizeof_int -STIX_SIZEOF_SHORT=$ac_cv_sizeof_short +MOO_SIZEOF_SHORT=$ac_cv_sizeof_short -STIX_SIZEOF_CHAR=$ac_cv_sizeof_char +MOO_SIZEOF_CHAR=$ac_cv_sizeof_char -STIX_SIZEOF_VOID_P=$ac_cv_sizeof_void_p +MOO_SIZEOF_VOID_P=$ac_cv_sizeof_void_p -STIX_SIZEOF_FLOAT=$ac_cv_sizeof_float +MOO_SIZEOF_FLOAT=$ac_cv_sizeof_float -STIX_SIZEOF_DOUBLE=$ac_cv_sizeof_double +MOO_SIZEOF_DOUBLE=$ac_cv_sizeof_double -STIX_SIZEOF_LONG_DOUBLE=$ac_cv_sizeof_long_double +MOO_SIZEOF_LONG_DOUBLE=$ac_cv_sizeof_long_double -STIX_SIZEOF_OFF_T=$ac_cv_sizeof_off_t +MOO_SIZEOF_OFF_T=$ac_cv_sizeof_off_t -STIX_SIZEOF_OFF64_T=$ac_cv_sizeof_off64_t +MOO_SIZEOF_OFF64_T=$ac_cv_sizeof_off64_t -STIX_PROJECT_AUTHOR="${PACKAGE_BUGREPORT}" +MOO_PROJECT_AUTHOR="${PACKAGE_BUGREPORT}" -STIX_PROJECT_URL="${PACKAGE_URL}" +MOO_PROJECT_URL="${PACKAGE_URL}" ac_config_files="$ac_config_files Makefile lib/Makefile mod/Makefile" @@ -20095,7 +20095,7 @@ if test -z "${CONVENIENCE_LTDL_TRUE}" && test -z "${CONVENIENCE_LTDL_FALSE}"; th as_fn_error $? "conditional \"CONVENIENCE_LTDL\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi -LT_CONFIG_H=lib/stix-cfg.h +LT_CONFIG_H=lib/moo-cfg.h _ltdl_libobjs= _ltdl_ltlibobjs= @@ -20522,7 +20522,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by stix $as_me 0.6.0, which was +This file was extended by moo $as_me 0.1.0, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -20583,13 +20583,13 @@ Configuration commands: $config_commands Report bugs to . -stix home page: ." +moo home page: ." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -stix config.status 0.6.0 +moo config.status 0.1.0 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" @@ -21093,7 +21093,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 for ac_config_target in $ac_config_targets do case $ac_config_target in - "lib/stix-cfg.h") CONFIG_HEADERS="$CONFIG_HEADERS lib/stix-cfg.h" ;; + "lib/moo-cfg.h") CONFIG_HEADERS="$CONFIG_HEADERS lib/moo-cfg.h" ;; "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;; "libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;; "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; diff --git a/stix/configure.ac b/stix/configure.ac index d727667..844c4f0 100644 --- a/stix/configure.ac +++ b/stix/configure.ac @@ -1,8 +1,8 @@ dnl AC_PREREQ([2.67]) -AC_INIT([stix],[0.6.0],[Chung, Hyung-Hwan (hyunghwan.chung@gmail.com)],[],[http://code.abiyo.net/@stix]) +AC_INIT([moo],[0.1.0],[Chung, Hyung-Hwan (hyunghwan.chung@gmail.com)],[],[http://code.abiyo.net/@moo]) -AC_CONFIG_HEADER([lib/stix-cfg.h]) +AC_CONFIG_HEADER([lib/moo-cfg.h]) AC_CONFIG_AUX_DIR([ac]) AC_CONFIG_MACRO_DIR([m4]) @@ -83,8 +83,8 @@ then fi dnl indicate the existence of config.h -CFLAGS="$CFLAGS -DSTIX_HAVE_CFG_H" -CXXFLAGS="$CXXFLAGS -DSTIX_HAVE_CFG_H" +CFLAGS="$CFLAGS -DMOO_HAVE_CFG_H" +CXXFLAGS="$CXXFLAGS -DMOO_HAVE_CFG_H" dnl make visible the 64-bit interface to the file system CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE" @@ -234,7 +234,7 @@ dnl so i've added this check to determine if the compiler has dnl proper support for __int128_t. dnl dnl Changing ac_cv_sizeof___int128_t here doesn't corret SIZEOF___INT128_T -dnl since it's already generated. It only affects STIX_SIZEOF___INT128_T below. +dnl since it's already generated. It only affects MOO_SIZEOF___INT128_T below. if test ${ac_cv_sizeof___int128_t} -gt 0 then AC_MSG_CHECKING([__int128_t with %]) @@ -327,65 +327,65 @@ fi AC_SUBST(QUADMATH_LIBS) -AC_DEFINE_UNQUOTED(STIX_SIZEOF_CHAR, ${ac_cv_sizeof_char}, [sizeof(char)]) -AC_DEFINE_UNQUOTED(STIX_SIZEOF_SHORT, ${ac_cv_sizeof_short}, [sizeof(short)]) -AC_DEFINE_UNQUOTED(STIX_SIZEOF_INT, ${ac_cv_sizeof_int}, [sizeof(int)]) -AC_DEFINE_UNQUOTED(STIX_SIZEOF_LONG, ${ac_cv_sizeof_long}, [sizeof(long)]) -AC_DEFINE_UNQUOTED(STIX_SIZEOF_LONG_LONG, ${ac_cv_sizeof_long_long}, [sizeof(long long)]) -AC_DEFINE_UNQUOTED(STIX_SIZEOF___INT8, ${ac_cv_sizeof___int8}, [sizeof(__int8)]) -AC_DEFINE_UNQUOTED(STIX_SIZEOF___INT16, ${ac_cv_sizeof___int16}, [sizeof(__int16)]) -AC_DEFINE_UNQUOTED(STIX_SIZEOF___INT32, ${ac_cv_sizeof___int32}, [sizeof(__int32)]) -AC_DEFINE_UNQUOTED(STIX_SIZEOF___INT64, ${ac_cv_sizeof___int64}, [sizeof(__int64)]) -AC_DEFINE_UNQUOTED(STIX_SIZEOF___INT128, ${ac_cv_sizeof___int128}, [sizeof(__int128)]) -AC_DEFINE_UNQUOTED(STIX_SIZEOF___INT128_T, ${ac_cv_sizeof___int128_t}, [sizeof(__int128_t)]) -AC_DEFINE_UNQUOTED(STIX_SIZEOF___UINT128_T, ${ac_cv_sizeof___uint128_t}, [sizeof(__uint128_t)]) -AC_DEFINE_UNQUOTED(STIX_SIZEOF_VOID_P, ${ac_cv_sizeof_void_p}, [sizeof(void*)]) -AC_DEFINE_UNQUOTED(STIX_SIZEOF_FLOAT, ${ac_cv_sizeof_float}, [sizeof(float)]) -AC_DEFINE_UNQUOTED(STIX_SIZEOF_DOUBLE, ${ac_cv_sizeof_double}, [sizeof(double)]) -AC_DEFINE_UNQUOTED(STIX_SIZEOF_LONG_DOUBLE, ${ac_cv_sizeof_long_double}, [sizeof(long double)]) -AC_DEFINE_UNQUOTED(STIX_SIZEOF___FLOAT128, ${ac_cv_sizeof___float128}, [sizeof(__float128)]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF_CHAR, ${ac_cv_sizeof_char}, [sizeof(char)]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF_SHORT, ${ac_cv_sizeof_short}, [sizeof(short)]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF_INT, ${ac_cv_sizeof_int}, [sizeof(int)]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF_LONG, ${ac_cv_sizeof_long}, [sizeof(long)]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF_LONG_LONG, ${ac_cv_sizeof_long_long}, [sizeof(long long)]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF___INT8, ${ac_cv_sizeof___int8}, [sizeof(__int8)]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF___INT16, ${ac_cv_sizeof___int16}, [sizeof(__int16)]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF___INT32, ${ac_cv_sizeof___int32}, [sizeof(__int32)]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF___INT64, ${ac_cv_sizeof___int64}, [sizeof(__int64)]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF___INT128, ${ac_cv_sizeof___int128}, [sizeof(__int128)]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF___INT128_T, ${ac_cv_sizeof___int128_t}, [sizeof(__int128_t)]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF___UINT128_T, ${ac_cv_sizeof___uint128_t}, [sizeof(__uint128_t)]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF_VOID_P, ${ac_cv_sizeof_void_p}, [sizeof(void*)]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF_FLOAT, ${ac_cv_sizeof_float}, [sizeof(float)]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF_DOUBLE, ${ac_cv_sizeof_double}, [sizeof(double)]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF_LONG_DOUBLE, ${ac_cv_sizeof_long_double}, [sizeof(long double)]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF___FLOAT128, ${ac_cv_sizeof___float128}, [sizeof(__float128)]) -AC_DEFINE_UNQUOTED(STIX_SIZEOF_WCHAR_T, ${ac_cv_sizeof_wchar_t}, [sizeof(wchar_t)]) -AC_DEFINE_UNQUOTED(STIX_SIZEOF_OFF_T, ${ac_cv_sizeof_off_t}, [sizeof(off_t)]) -AC_DEFINE_UNQUOTED(STIX_SIZEOF_OFF64_T, ${ac_cv_sizeof_off64_t}, [sizeof(off64_t)]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF_WCHAR_T, ${ac_cv_sizeof_wchar_t}, [sizeof(wchar_t)]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF_OFF_T, ${ac_cv_sizeof_off_t}, [sizeof(off_t)]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF_OFF64_T, ${ac_cv_sizeof_off64_t}, [sizeof(off64_t)]) -AC_DEFINE_UNQUOTED(STIX_SIZEOF_MBSTATE_T, ${ac_cv_sizeof_mbstate_t}, [sizeof(mbstate_t)]) -AC_DEFINE_UNQUOTED(STIX_MBLEN_MAX, ${ax_cv_numvalof_MB_LEN_MAX}, [MB_LEN_MAX]) +AC_DEFINE_UNQUOTED(MOO_SIZEOF_MBSTATE_T, ${ac_cv_sizeof_mbstate_t}, [sizeof(mbstate_t)]) +AC_DEFINE_UNQUOTED(MOO_MBLEN_MAX, ${ax_cv_numvalof_MB_LEN_MAX}, [MB_LEN_MAX]) -stix_package_version_major="`echo ${PACKAGE_VERSION} | cut -d. -f1`" -stix_package_version_minor="`echo ${PACKAGE_VERSION} | cut -d. -f2`" -stix_package_version_patch="`echo ${PACKAGE_VERSION} | cut -d. -f3`" -AC_SUBST(PACKAGE_VERSION_MAJOR, ${stix_package_version_major}) -AC_SUBST(PACKAGE_VERSION_MINOR, ${stix_package_version_minor}) -AC_SUBST(PACKAGE_VERSION_PATCH, ${stix_package_version_patch}) +moo_package_version_major="`echo ${PACKAGE_VERSION} | cut -d. -f1`" +moo_package_version_minor="`echo ${PACKAGE_VERSION} | cut -d. -f2`" +moo_package_version_patch="`echo ${PACKAGE_VERSION} | cut -d. -f3`" +AC_SUBST(PACKAGE_VERSION_MAJOR, ${moo_package_version_major}) +AC_SUBST(PACKAGE_VERSION_MINOR, ${moo_package_version_minor}) +AC_SUBST(PACKAGE_VERSION_PATCH, ${moo_package_version_patch}) -AC_DEFINE_UNQUOTED(STIX_PACKAGE_VERSION, "${PACKAGE_VERSION}", [Package version]) -dnl AC_DEFINE_UNQUOTED(STIX_PACKAGE_VERSION_MAJOR, $(echo ${VERSION} | cut -d. -f1), [Major version number]) -dnl AC_DEFINE_UNQUOTED(STIX_PACKAGE_VERSION_MINOR, $(echo ${VERSION} | cut -d. -f2), [Minor version number]) -dnl AC_DEFINE_UNQUOTED(STIX_PACKAGE_VERSION_PATCH, $(echo ${VERSION} | cut -d. -f3), [Patch level]) -AC_DEFINE_UNQUOTED(STIX_PACKAGE_VERSION_MAJOR, ${stix_package_version_major}, [Major version number]) -AC_DEFINE_UNQUOTED(STIX_PACKAGE_VERSION_MINOR, ${stix_package_version_minor}, [Minor version number]) -AC_DEFINE_UNQUOTED(STIX_PACKAGE_VERSION_PATCH, ${stix_package_version_patch}, [Patch level]) +AC_DEFINE_UNQUOTED(MOO_PACKAGE_VERSION, "${PACKAGE_VERSION}", [Package version]) +dnl AC_DEFINE_UNQUOTED(MOO_PACKAGE_VERSION_MAJOR, $(echo ${VERSION} | cut -d. -f1), [Major version number]) +dnl AC_DEFINE_UNQUOTED(MOO_PACKAGE_VERSION_MINOR, $(echo ${VERSION} | cut -d. -f2), [Minor version number]) +dnl AC_DEFINE_UNQUOTED(MOO_PACKAGE_VERSION_PATCH, $(echo ${VERSION} | cut -d. -f3), [Patch level]) +AC_DEFINE_UNQUOTED(MOO_PACKAGE_VERSION_MAJOR, ${moo_package_version_major}, [Major version number]) +AC_DEFINE_UNQUOTED(MOO_PACKAGE_VERSION_MINOR, ${moo_package_version_minor}, [Minor version number]) +AC_DEFINE_UNQUOTED(MOO_PACKAGE_VERSION_PATCH, ${moo_package_version_patch}, [Patch level]) -AC_DEFINE_UNQUOTED(STIX_PACKAGE_AUTHOR,"${PACKAGE_BUGREPORT}", [Author]) -AC_DEFINE_UNQUOTED(STIX_PACKAGE_NAME,"${PACKAGE_NAME}", [package name]) -AC_DEFINE_UNQUOTED(STIX_PACKAGE_URL, "${PACKAGE_URL}", [Project URL]) +AC_DEFINE_UNQUOTED(MOO_PACKAGE_AUTHOR,"${PACKAGE_BUGREPORT}", [Author]) +AC_DEFINE_UNQUOTED(MOO_PACKAGE_NAME,"${PACKAGE_NAME}", [package name]) +AC_DEFINE_UNQUOTED(MOO_PACKAGE_URL, "${PACKAGE_URL}", [Project URL]) AC_C_BIGENDIAN( - [AC_DEFINE([STIX_ENDIAN_BIG],[],[Big Endian])], - [AC_DEFINE([STIX_ENDIAN_LITTLE],[],[Little Endian])], - [AC_DEFINE([STIX_ENDIAN_UNKNOWN],[],[Unknown Endian])]) + [AC_DEFINE([MOO_ENDIAN_BIG],[],[Big Endian])], + [AC_DEFINE([MOO_ENDIAN_LITTLE],[],[Little Endian])], + [AC_DEFINE([MOO_ENDIAN_UNKNOWN],[],[Unknown Endian])]) AC_ARG_ENABLE([debug], [AS_HELP_STRING([--enable-debug],[build the library in the debug mode (default. no)])], enable_debug_is=$enableval,enable_debug_is=no) if test "$enable_debug_is" = "yes" then - [CFLAGS="$CFLAGS -g -D_DEBUG -UNDEBUG -DSTIX_BUILD_DEBUG -U_FORTIFY_SOURCE"] - [CXXFLAGS="$CXXFLAGS -g -D_DEBUG -UNDEBUG -DSTIX_BUILD_DEBUG -U_FORTIFY_SOURCE"] + [CFLAGS="$CFLAGS -g -D_DEBUG -UNDEBUG -DMOO_BUILD_DEBUG -U_FORTIFY_SOURCE"] + [CXXFLAGS="$CXXFLAGS -g -D_DEBUG -UNDEBUG -DMOO_BUILD_DEBUG -U_FORTIFY_SOURCE"] AC_SUBST(BUILD_MODE, "debug") else - [CFLAGS="$CFLAGS -DNDEBUG -U_DEBUG -DSTIX_BUILD_RELEASE -U_FORTIFY_SOURCE"] - [CXXFLAGS="$CXXFLAGS -DNDEBUG -U_DEBUG -DSTIX_BUILD_RELEASE -U_FORTIFY_SOURCE"] + [CFLAGS="$CFLAGS -DNDEBUG -U_DEBUG -DMOO_BUILD_RELEASE -U_FORTIFY_SOURCE"] + [CXXFLAGS="$CXXFLAGS -DNDEBUG -U_DEBUG -DMOO_BUILD_RELEASE -U_FORTIFY_SOURCE"] AC_SUBST(BUILD_MODE, "release") fi @@ -412,25 +412,25 @@ test "${enable_shared}" = "no" -a "${enable_static}" = "yes" && enable_static_mo if test "${enable_static_module}" = "yes" then - AC_DEFINE([STIX_ENABLE_STATIC_MODULE],[],[link modules statically into the main library]) + AC_DEFINE([MOO_ENABLE_STATIC_MODULE],[],[link modules statically into the main library]) fi AM_CONDITIONAL(ENABLE_STATIC_MODULE, test "${enable_static_module}" = "yes") -AC_SUBST(STIX_SIZEOF_WCHAR_T, $ac_cv_sizeof_wchar_t) -AC_SUBST(STIX_SIZEOF_LONG_LONG, $ac_cv_sizeof_long_long) -AC_SUBST(STIX_SIZEOF_LONG, $ac_cv_sizeof_long) -AC_SUBST(STIX_SIZEOF_INT, $ac_cv_sizeof_int) -AC_SUBST(STIX_SIZEOF_SHORT, $ac_cv_sizeof_short) -AC_SUBST(STIX_SIZEOF_CHAR, $ac_cv_sizeof_char) -AC_SUBST(STIX_SIZEOF_VOID_P, $ac_cv_sizeof_void_p) -AC_SUBST(STIX_SIZEOF_FLOAT, $ac_cv_sizeof_float) -AC_SUBST(STIX_SIZEOF_DOUBLE, $ac_cv_sizeof_double) -AC_SUBST(STIX_SIZEOF_LONG_DOUBLE, $ac_cv_sizeof_long_double) -AC_SUBST(STIX_SIZEOF_OFF_T, $ac_cv_sizeof_off_t) -AC_SUBST(STIX_SIZEOF_OFF64_T, $ac_cv_sizeof_off64_t) +AC_SUBST(MOO_SIZEOF_WCHAR_T, $ac_cv_sizeof_wchar_t) +AC_SUBST(MOO_SIZEOF_LONG_LONG, $ac_cv_sizeof_long_long) +AC_SUBST(MOO_SIZEOF_LONG, $ac_cv_sizeof_long) +AC_SUBST(MOO_SIZEOF_INT, $ac_cv_sizeof_int) +AC_SUBST(MOO_SIZEOF_SHORT, $ac_cv_sizeof_short) +AC_SUBST(MOO_SIZEOF_CHAR, $ac_cv_sizeof_char) +AC_SUBST(MOO_SIZEOF_VOID_P, $ac_cv_sizeof_void_p) +AC_SUBST(MOO_SIZEOF_FLOAT, $ac_cv_sizeof_float) +AC_SUBST(MOO_SIZEOF_DOUBLE, $ac_cv_sizeof_double) +AC_SUBST(MOO_SIZEOF_LONG_DOUBLE, $ac_cv_sizeof_long_double) +AC_SUBST(MOO_SIZEOF_OFF_T, $ac_cv_sizeof_off_t) +AC_SUBST(MOO_SIZEOF_OFF64_T, $ac_cv_sizeof_off64_t) -AC_SUBST(STIX_PROJECT_AUTHOR, "${PACKAGE_BUGREPORT}") -AC_SUBST(STIX_PROJECT_URL, "${PACKAGE_URL}") +AC_SUBST(MOO_PROJECT_AUTHOR, "${PACKAGE_BUGREPORT}") +AC_SUBST(MOO_PROJECT_URL, "${PACKAGE_URL}") AC_CONFIG_FILES([ Makefile diff --git a/stix/kernel/Apex.st b/stix/kernel/Apex.st index 43a5dcd..2b9d744 100644 --- a/stix/kernel/Apex.st +++ b/stix/kernel/Apex.st @@ -365,8 +365,8 @@ class Apex(nil) method(#class) error: msgText { - ## TODO: implement this - ## Error signal: msgText. + (* TODO: implement this + Error signal: msgText. *) msgText dump. } diff --git a/stix/kernel/Class.st b/stix/kernel/Class.st index 2c0ff45..6ca7426 100644 --- a/stix/kernel/Class.st +++ b/stix/kernel/Class.st @@ -33,7 +33,7 @@ class(#pointer) Class(Apex) method specNumInstVars { ## shift right by 7 bits. - ## see stix-prv.h for details. + ## see moo-prv.h for details. ^self.spec bitShift: -7 } diff --git a/stix/kernel/Collect.st b/stix/kernel/Collect.st index 70f5cb8..1623d85 100644 --- a/stix/kernel/Collect.st +++ b/stix/kernel/Collect.st @@ -385,7 +385,7 @@ pooldic Log { ## ----------------------------------------------------------- ## defines log levels - ## these items must follow defintions in stix.h + ## these items must follow defintions in moo.h ## ----------------------------------------------------------- #DEBUG := 1. @@ -399,7 +399,7 @@ class SystemDictionary(Dictionary) { ## the following methods may not look suitable to be placed ## inside a system dictionary. but they are here for quick and dirty - ## output production from the stix code. + ## output production from the moo code. ## System logNl: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'. ## diff --git a/stix/kernel/Console.st b/stix/kernel/Console.st index 88ff978..4941367 100644 --- a/stix/kernel/Console.st +++ b/stix/kernel/Console.st @@ -187,7 +187,7 @@ class Console(Object) } " -Stix define: 'console_write' +Moo define: 'console_write' forClass: Console method: 'write: aString upto: length' returns: 'size_t' diff --git a/stix/kernel/Except.st b/stix/kernel/Except.st index 2a7e3b7..271ee87 100644 --- a/stix/kernel/Except.st +++ b/stix/kernel/Except.st @@ -187,19 +187,19 @@ extend MethodContext { method isExceptionContext { - ## 10 - STIX_METHOD_PREAMBLE_EXCEPTION in VM. + ## 10 - MOO_METHOD_PREAMBLE_EXCEPTION in VM. ^self.method preambleCode == 10. } method isEnsureContext { - ## 10 - STIX_METHOD_PREAMBLE_ENSURE in VM. + ## 10 - MOO_METHOD_PREAMBLE_ENSURE in VM. ^self.method preambleCode == 11 } method ensureBlock { -## TODO: change 8 to a constant when stix is enhanced to support constant definition +## TODO: change 8 to a constant when moo is enhanced to support constant definition (* [ value-block ] ensure: [ ensure-block ] * assuming ensure block is a parameter the ensure: method to a @@ -223,7 +223,7 @@ extend MethodContext * basicAt: 8 must be the on: argument. * basicAt: 9 must be the do: argument *) -## TODO: change 8 to a constant when stix is enhanced to support constant definition +## TODO: change 8 to a constant when moo is enhanced to support constant definition ## or calcuate the minimum size using the class information. (self isExceptionContext) ifTrue: [ diff --git a/stix/kernel/Stix.st b/stix/kernel/Moo.st similarity index 100% rename from stix/kernel/Stix.st rename to stix/kernel/Moo.st diff --git a/stix/kernel/generr.st b/stix/kernel/generr.st index e6f098c..45242bd 100644 --- a/stix/kernel/generr.st +++ b/stix/kernel/generr.st @@ -1,4 +1,4 @@ -#include 'Stix.st'. +#include 'Moo.st'. class MyObject(Object) { @@ -121,7 +121,7 @@ class MyObject(Object) ]. - f puts: S'static stix_ooch_t* '. + f puts: S'static moo_ooch_t* '. f puts: name. f puts: S'[] =\n{\n'. 0 to: c do: [:i | @@ -140,7 +140,7 @@ class MyObject(Object) | c | c := s size - 1. - f puts: 'static stix_ooch_t '. + f puts: 'static moo_ooch_t '. f puts: prefix. f puts: index asString. f puts: '[] = {'. diff --git a/stix/kernel/test-001.st b/stix/kernel/test-001.st index 64d9bc3..cfef992 100644 --- a/stix/kernel/test-001.st +++ b/stix/kernel/test-001.st @@ -1,5 +1,5 @@ -#include 'Stix.st'. +#include 'Moo.st'. ################################################################# ## MAIN diff --git a/stix/kernel/test-002.st b/stix/kernel/test-002.st index 4011f7a..f50c340 100644 --- a/stix/kernel/test-002.st +++ b/stix/kernel/test-002.st @@ -1,5 +1,5 @@ -#include 'Stix.st'. +#include 'Moo.st'. ################################################################# ## MAIN diff --git a/stix/kernel/test-003.st b/stix/kernel/test-003.st index efda704..23c3f1e 100644 --- a/stix/kernel/test-003.st +++ b/stix/kernel/test-003.st @@ -1,5 +1,5 @@ -#include 'Stix.st'. +#include 'Moo.st'. ################################################################# ## MAIN diff --git a/stix/kernel/test-004.st b/stix/kernel/test-004.st index cf35e82..c50312c 100644 --- a/stix/kernel/test-004.st +++ b/stix/kernel/test-004.st @@ -1,5 +1,5 @@ -#include 'Stix.st'. +#include 'Moo.st'. ################################################################# ## MAIN diff --git a/stix/kernel/test-005.st b/stix/kernel/test-005.st index ba3c9d7..ea7dd96 100644 --- a/stix/kernel/test-005.st +++ b/stix/kernel/test-005.st @@ -1,5 +1,5 @@ -#include 'Stix.st'. +#include 'Moo.st'. ################################################################# ## MAIN @@ -59,7 +59,7 @@ class MyObject(TestObject) ^a + 99. - ##a := Stix.MyCOM.HashTable new. + ##a := Moo.MyCOM.HashTable new. } method xxx: aBlock diff --git a/stix/kernel/test-006.st b/stix/kernel/test-006.st index e9905bd..863713d 100644 --- a/stix/kernel/test-006.st +++ b/stix/kernel/test-006.st @@ -1,5 +1,5 @@ -#include 'Stix.st'. +#include 'Moo.st'. ################################################################# ## MAIN diff --git a/stix/kernel/test-007.st b/stix/kernel/test-007.st index ca68222..f1a70ab 100644 --- a/stix/kernel/test-007.st +++ b/stix/kernel/test-007.st @@ -1,5 +1,5 @@ -#include 'Stix.st'. +#include 'Moo.st'. ################################################################# ## MAIN diff --git a/stix/kernel/test-008.st b/stix/kernel/test-008.st index 283ad53..80d5e6e 100644 --- a/stix/kernel/test-008.st +++ b/stix/kernel/test-008.st @@ -1,5 +1,5 @@ -#include 'Stix.st'. +#include 'Moo.st'. ################################################################# ## MAIN diff --git a/stix/kernel/test-009.st b/stix/kernel/test-009.st index daba64b..aaf6c59 100644 --- a/stix/kernel/test-009.st +++ b/stix/kernel/test-009.st @@ -1,5 +1,5 @@ -#include 'Stix.st'. +#include 'Moo.st'. ################################################################# ## MAIN diff --git a/stix/kernel/test-010.st b/stix/kernel/test-010.st index 093f486..ea6d053 100644 --- a/stix/kernel/test-010.st +++ b/stix/kernel/test-010.st @@ -1,5 +1,5 @@ -#include 'Stix.st'. +#include 'Moo.st'. ################################################################# ## MAIN diff --git a/stix/kernel/test-011.st b/stix/kernel/test-011.st index ec3f224..8b3bd9c 100644 --- a/stix/kernel/test-011.st +++ b/stix/kernel/test-011.st @@ -1,5 +1,5 @@ -#include 'Stix.st'. +#include 'Moo.st'. ################################################################# ## MAIN diff --git a/stix/kernel/test-013.st b/stix/kernel/test-013.st index 1b7223f..0c4dc85 100644 --- a/stix/kernel/test-013.st +++ b/stix/kernel/test-013.st @@ -1,5 +1,5 @@ -#include 'Stix.st'. +#include 'Moo.st'. ################################################################# ## MAIN diff --git a/stix/kernel/test-014.st b/stix/kernel/test-014.st index d414b75..b7c73f1 100644 --- a/stix/kernel/test-014.st +++ b/stix/kernel/test-014.st @@ -1,5 +1,5 @@ -#include 'Stix.st'. +#include 'Moo.st'. ################################################################# ## MAIN diff --git a/stix/lib/Makefile.am b/stix/lib/Makefile.am index 793202b..5d839a8 100644 --- a/stix/lib/Makefile.am +++ b/stix/lib/Makefile.am @@ -18,25 +18,25 @@ LIBADD_LIB_COMMON = $(LIBM) $(LIBLTDL) if WIN32 # you must adjust the value of DEFAULT_MODPOSTFIX according # to the first number in -version-info above -CPPFLAGS_LIB_COMMON += -DSTIX_DEFAULT_MODPREFIX=\"libstix-\" -DSTIX_DEFAULT_MODPOSTFIX=\"-1\" +CPPFLAGS_LIB_COMMON += -DMOO_DEFAULT_MODPREFIX=\"libmoo-\" -DMOO_DEFAULT_MODPOSTFIX=\"-1\" else -CPPFLAGS_LIB_COMMON += -DSTIX_DEFAULT_MODPREFIX=\"$(libdir)/libstix-\" -DSTIX_DEFAULT_MODPOSTFIX=\"\" +CPPFLAGS_LIB_COMMON += -DMOO_DEFAULT_MODPREFIX=\"$(libdir)/libmoo-\" -DMOO_DEFAULT_MODPOSTFIX=\"\" endif pkgincludedir = $(includedir) pkglibdir = $(libdir) pkginclude_HEADERS = \ - stix-cfg.h \ - stix-cmn.h \ - stix-rbt.h \ - stix-utl.h \ - stix.h + moo-cfg.h \ + moo-cmn.h \ + moo-rbt.h \ + moo-utl.h \ + moo.h -noinst_HEADERS = stix-prv.h +noinst_HEADERS = moo-prv.h -pkglib_LTLIBRARIES = libstix.la -libstix_la_SOURCES = \ +pkglib_LTLIBRARIES = libmoo.la +libmoo_la_SOURCES = \ bigint.c \ comp.c \ debug.c \ @@ -51,34 +51,34 @@ libstix_la_SOURCES = \ obj.c \ proc.c \ rbt.c \ - stix.c \ + moo.c \ sym.c \ utf8.c \ utl.c -libstix_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) -libstix_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) -libstix_la_LIBADD = $(LIBADD_LIB_COMMON) +libmoo_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) +libmoo_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) +libmoo_la_LIBADD = $(LIBADD_LIB_COMMON) if ENABLE_STATIC_MODULE -libstix_la_LDFLAGS += -L$(abs_builddir)/../mod -libstix_la_LIBADD += -lstix-console -lstix-stdio -ltermcap +libmoo_la_LDFLAGS += -L$(abs_builddir)/../mod +libmoo_la_LIBADD += -lmoo-console -lmoo-stdio -ltermcap endif -bin_PROGRAMS = stix -stix_SOURCES = main.c -stix_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) -stix_LDFLAGS = $(LDFLAGS_LIB_COMMON) -stix_LDADD = $(LIBADD_LIB_COMMON) -lstix #-ldyncall_s +bin_PROGRAMS = moo +moo_SOURCES = main.c +moo_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) +moo_LDFLAGS = $(LDFLAGS_LIB_COMMON) +moo_LDADD = $(LIBADD_LIB_COMMON) -lmoo #-ldyncall_s install-data-hook: - @echo "#ifndef _STIX_CFG_H_" > "$(DESTDIR)$(pkgincludedir)/stix-cfg.h" - @echo "#define _STIX_CFG_H_" >> "$(DESTDIR)$(pkgincludedir)/stix-cfg.h" - @$(EGREP) "#define[ ]+STIX_" "$(abs_builddir)/stix-cfg.h" >> "$(DESTDIR)$(pkgincludedir)/stix-cfg.h" - @echo "#endif" >> "$(DESTDIR)$(pkgincludedir)/stix-cfg.h" - @rm -f "$(DESTDIR)$(pkgincludedir)/stix-cfg.h.in" - @$(SED) 's|/\*#define STIX_HAVE_CFG_H\*/|#define STIX_HAVE_CFG_H|' "$(srcdir)/stix-cmn.h" > "$(DESTDIR)$(pkgincludedir)/stix-cmn.h" + @echo "#ifndef _MOO_CFG_H_" > "$(DESTDIR)$(pkgincludedir)/moo-cfg.h" + @echo "#define _MOO_CFG_H_" >> "$(DESTDIR)$(pkgincludedir)/moo-cfg.h" + @$(EGREP) "#define[ ]+MOO_" "$(abs_builddir)/moo-cfg.h" >> "$(DESTDIR)$(pkgincludedir)/moo-cfg.h" + @echo "#endif" >> "$(DESTDIR)$(pkgincludedir)/moo-cfg.h" + @rm -f "$(DESTDIR)$(pkgincludedir)/moo-cfg.h.in" + @$(SED) 's|/\*#define MOO_HAVE_CFG_H\*/|#define MOO_HAVE_CFG_H|' "$(srcdir)/moo-cmn.h" > "$(DESTDIR)$(pkgincludedir)/moo-cmn.h" uninstall-hook: - @rm -f "$(DESTDIR)$(pkgincludedir)/stix-cfg.h" + @rm -f "$(DESTDIR)$(pkgincludedir)/moo-cfg.h" diff --git a/stix/lib/Makefile.in b/stix/lib/Makefile.in index 55a32a5..f6b8eca 100644 --- a/stix/lib/Makefile.in +++ b/stix/lib/Makefile.in @@ -81,14 +81,14 @@ host_triplet = @host@ # you must adjust the value of DEFAULT_MODPOSTFIX according # to the first number in -version-info above -@WIN32_TRUE@am__append_1 = -DSTIX_DEFAULT_MODPREFIX=\"libstix-\" -DSTIX_DEFAULT_MODPOSTFIX=\"-1\" -@WIN32_FALSE@am__append_2 = -DSTIX_DEFAULT_MODPREFIX=\"$(libdir)/libstix-\" -DSTIX_DEFAULT_MODPOSTFIX=\"\" +@WIN32_TRUE@am__append_1 = -DMOO_DEFAULT_MODPREFIX=\"libmoo-\" -DMOO_DEFAULT_MODPOSTFIX=\"-1\" +@WIN32_FALSE@am__append_2 = -DMOO_DEFAULT_MODPREFIX=\"$(libdir)/libmoo-\" -DMOO_DEFAULT_MODPOSTFIX=\"\" @ENABLE_STATIC_MODULE_TRUE@am__append_3 = -L$(abs_builddir)/../mod -@ENABLE_STATIC_MODULE_TRUE@am__append_4 = -lstix-console -lstix-stdio -ltermcap -bin_PROGRAMS = stix$(EXEEXT) +@ENABLE_STATIC_MODULE_TRUE@am__append_4 = -lmoo-console -lmoo-stdio -ltermcap +bin_PROGRAMS = moo$(EXEEXT) subdir = lib DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ - $(srcdir)/stix-cfg.h.in $(top_srcdir)/ac/depcomp \ + $(srcdir)/moo-cfg.h.in $(top_srcdir)/ac/depcomp \ $(noinst_HEADERS) $(pkginclude_HEADERS) ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/argz.m4 \ @@ -100,7 +100,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/argz.m4 \ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d -CONFIG_HEADER = stix-cfg.h +CONFIG_HEADER = moo-cfg.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; @@ -135,28 +135,28 @@ am__installdirs = "$(DESTDIR)$(pkglibdir)" "$(DESTDIR)$(bindir)" \ LTLIBRARIES = $(pkglib_LTLIBRARIES) am__DEPENDENCIES_1 = am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) -libstix_la_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) -am_libstix_la_OBJECTS = libstix_la-bigint.lo libstix_la-comp.lo \ - libstix_la-debug.lo libstix_la-decode.lo libstix_la-dic.lo \ - libstix_la-err.lo libstix_la-exec.lo libstix_la-logfmt.lo \ - libstix_la-gc.lo libstix_la-heap.lo libstix_la-obj.lo \ - libstix_la-proc.lo libstix_la-rbt.lo libstix_la-stix.lo \ - libstix_la-sym.lo libstix_la-utf8.lo libstix_la-utl.lo -libstix_la_OBJECTS = $(am_libstix_la_OBJECTS) +libmoo_la_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) +am_libmoo_la_OBJECTS = libmoo_la-bigint.lo libmoo_la-comp.lo \ + libmoo_la-debug.lo libmoo_la-decode.lo libmoo_la-dic.lo \ + libmoo_la-err.lo libmoo_la-exec.lo libmoo_la-logfmt.lo \ + libmoo_la-gc.lo libmoo_la-heap.lo libmoo_la-obj.lo \ + libmoo_la-proc.lo libmoo_la-rbt.lo libmoo_la-moo.lo \ + libmoo_la-sym.lo libmoo_la-utf8.lo libmoo_la-utl.lo +libmoo_la_OBJECTS = $(am_libmoo_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = -libstix_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ +libmoo_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ - $(libstix_la_LDFLAGS) $(LDFLAGS) -o $@ + $(libmoo_la_LDFLAGS) $(LDFLAGS) -o $@ PROGRAMS = $(bin_PROGRAMS) -am_stix_OBJECTS = stix-main.$(OBJEXT) -stix_OBJECTS = $(am_stix_OBJECTS) -stix_DEPENDENCIES = $(am__DEPENDENCIES_2) -stix_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ +am_moo_OBJECTS = moo-main.$(OBJEXT) +moo_OBJECTS = $(am_moo_OBJECTS) +moo_DEPENDENCIES = $(am__DEPENDENCIES_2) +moo_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ - $(stix_LDFLAGS) $(LDFLAGS) -o $@ + $(moo_LDFLAGS) $(LDFLAGS) -o $@ AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false @@ -191,8 +191,8 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = -SOURCES = $(libstix_la_SOURCES) $(stix_SOURCES) -DIST_SOURCES = $(libstix_la_SOURCES) $(stix_SOURCES) +SOURCES = $(libmoo_la_SOURCES) $(moo_SOURCES) +DIST_SOURCES = $(libmoo_la_SOURCES) $(moo_SOURCES) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -200,7 +200,7 @@ am__can_run_installinfo = \ esac HEADERS = $(noinst_HEADERS) $(pkginclude_HEADERS) am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) \ - $(LISP)stix-cfg.h.in + $(LISP)moo-cfg.h.in # Read a list of newline-separated strings from the standard input, # and print each of them once, without duplicates. Input order is # *not* preserved. @@ -285,6 +285,20 @@ LT_DLPREOPEN = @LT_DLPREOPEN@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ +MOO_PROJECT_AUTHOR = @MOO_PROJECT_AUTHOR@ +MOO_PROJECT_URL = @MOO_PROJECT_URL@ +MOO_SIZEOF_CHAR = @MOO_SIZEOF_CHAR@ +MOO_SIZEOF_DOUBLE = @MOO_SIZEOF_DOUBLE@ +MOO_SIZEOF_FLOAT = @MOO_SIZEOF_FLOAT@ +MOO_SIZEOF_INT = @MOO_SIZEOF_INT@ +MOO_SIZEOF_LONG = @MOO_SIZEOF_LONG@ +MOO_SIZEOF_LONG_DOUBLE = @MOO_SIZEOF_LONG_DOUBLE@ +MOO_SIZEOF_LONG_LONG = @MOO_SIZEOF_LONG_LONG@ +MOO_SIZEOF_OFF64_T = @MOO_SIZEOF_OFF64_T@ +MOO_SIZEOF_OFF_T = @MOO_SIZEOF_OFF_T@ +MOO_SIZEOF_SHORT = @MOO_SIZEOF_SHORT@ +MOO_SIZEOF_VOID_P = @MOO_SIZEOF_VOID_P@ +MOO_SIZEOF_WCHAR_T = @MOO_SIZEOF_WCHAR_T@ NM = @NM@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ @@ -307,20 +321,6 @@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ -STIX_PROJECT_AUTHOR = @STIX_PROJECT_AUTHOR@ -STIX_PROJECT_URL = @STIX_PROJECT_URL@ -STIX_SIZEOF_CHAR = @STIX_SIZEOF_CHAR@ -STIX_SIZEOF_DOUBLE = @STIX_SIZEOF_DOUBLE@ -STIX_SIZEOF_FLOAT = @STIX_SIZEOF_FLOAT@ -STIX_SIZEOF_INT = @STIX_SIZEOF_INT@ -STIX_SIZEOF_LONG = @STIX_SIZEOF_LONG@ -STIX_SIZEOF_LONG_DOUBLE = @STIX_SIZEOF_LONG_DOUBLE@ -STIX_SIZEOF_LONG_LONG = @STIX_SIZEOF_LONG_LONG@ -STIX_SIZEOF_OFF64_T = @STIX_SIZEOF_OFF64_T@ -STIX_SIZEOF_OFF_T = @STIX_SIZEOF_OFF_T@ -STIX_SIZEOF_SHORT = @STIX_SIZEOF_SHORT@ -STIX_SIZEOF_VOID_P = @STIX_SIZEOF_VOID_P@ -STIX_SIZEOF_WCHAR_T = @STIX_SIZEOF_WCHAR_T@ STRIP = @STRIP@ UNICOWS_LIBS = @UNICOWS_LIBS@ VERSION = @VERSION@ @@ -397,15 +397,15 @@ CPPFLAGS_LIB_COMMON = $(CPPFLAGS_ALL_COMMON) $(LTDLINCL) \ LDFLAGS_LIB_COMMON = $(LDFLAGS_ALL_COMMON) -version-info 1:0:0 -no-undefined LIBADD_LIB_COMMON = $(LIBM) $(LIBLTDL) pkginclude_HEADERS = \ - stix-cfg.h \ - stix-cmn.h \ - stix-rbt.h \ - stix-utl.h \ - stix.h + moo-cfg.h \ + moo-cmn.h \ + moo-rbt.h \ + moo-utl.h \ + moo.h -noinst_HEADERS = stix-prv.h -pkglib_LTLIBRARIES = libstix.la -libstix_la_SOURCES = \ +noinst_HEADERS = moo-prv.h +pkglib_LTLIBRARIES = libmoo.la +libmoo_la_SOURCES = \ bigint.c \ comp.c \ debug.c \ @@ -420,19 +420,19 @@ libstix_la_SOURCES = \ obj.c \ proc.c \ rbt.c \ - stix.c \ + moo.c \ sym.c \ utf8.c \ utl.c -libstix_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) -libstix_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) $(am__append_3) -libstix_la_LIBADD = $(LIBADD_LIB_COMMON) $(am__append_4) -stix_SOURCES = main.c -stix_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) -stix_LDFLAGS = $(LDFLAGS_LIB_COMMON) -stix_LDADD = $(LIBADD_LIB_COMMON) -lstix #-ldyncall_s -all: stix-cfg.h +libmoo_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) +libmoo_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) $(am__append_3) +libmoo_la_LIBADD = $(LIBADD_LIB_COMMON) $(am__append_4) +moo_SOURCES = main.c +moo_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) +moo_LDFLAGS = $(LDFLAGS_LIB_COMMON) +moo_LDADD = $(LIBADD_LIB_COMMON) -lmoo #-ldyncall_s +all: moo-cfg.h $(MAKE) $(AM_MAKEFLAGS) all-am .SUFFIXES: @@ -468,20 +468,20 @@ $(ACLOCAL_M4): $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): -stix-cfg.h: stamp-h1 +moo-cfg.h: stamp-h1 @test -f $@ || rm -f stamp-h1 @test -f $@ || $(MAKE) $(AM_MAKEFLAGS) stamp-h1 -stamp-h1: $(srcdir)/stix-cfg.h.in $(top_builddir)/config.status +stamp-h1: $(srcdir)/moo-cfg.h.in $(top_builddir)/config.status @rm -f stamp-h1 - cd $(top_builddir) && $(SHELL) ./config.status lib/stix-cfg.h -$(srcdir)/stix-cfg.h.in: $(am__configure_deps) + cd $(top_builddir) && $(SHELL) ./config.status lib/moo-cfg.h +$(srcdir)/moo-cfg.h.in: $(am__configure_deps) ($(am__cd) $(top_srcdir) && $(AUTOHEADER)) rm -f stamp-h1 touch $@ distclean-hdr: - -rm -f stix-cfg.h stamp-h1 + -rm -f moo-cfg.h stamp-h1 install-pkglibLTLIBRARIES: $(pkglib_LTLIBRARIES) @$(NORMAL_INSTALL) @@ -518,8 +518,8 @@ clean-pkglibLTLIBRARIES: rm -f $${locs}; \ } -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) +libmoo.la: $(libmoo_la_OBJECTS) $(libmoo_la_DEPENDENCIES) $(EXTRA_libmoo_la_DEPENDENCIES) + $(AM_V_CCLD)$(libmoo_la_LINK) -rpath $(pkglibdir) $(libmoo_la_OBJECTS) $(libmoo_la_LIBADD) $(LIBS) install-binPROGRAMS: $(bin_PROGRAMS) @$(NORMAL_INSTALL) @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ @@ -570,9 +570,9 @@ clean-binPROGRAMS: echo " rm -f" $$list; \ rm -f $$list -stix$(EXEEXT): $(stix_OBJECTS) $(stix_DEPENDENCIES) $(EXTRA_stix_DEPENDENCIES) - @rm -f stix$(EXEEXT) - $(AM_V_CCLD)$(stix_LINK) $(stix_OBJECTS) $(stix_LDADD) $(LIBS) +moo$(EXEEXT): $(moo_OBJECTS) $(moo_DEPENDENCIES) $(EXTRA_moo_DEPENDENCIES) + @rm -f moo$(EXEEXT) + $(AM_V_CCLD)$(moo_LINK) $(moo_OBJECTS) $(moo_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -580,24 +580,24 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-bigint.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-comp.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-debug.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-decode.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-dic.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-err.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-exec.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-gc.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-heap.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-logfmt.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-proc.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-rbt.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_la-utl.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stix-main.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-bigint.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-comp.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-debug.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-decode.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-dic.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-err.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-exec.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-gc.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-heap.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-logfmt.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-moo.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-obj.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-proc.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-rbt.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-sym.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-utf8.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_la-utl.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/moo-main.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ @@ -623,138 +623,138 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< -libstix_la-bigint.lo: bigint.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-bigint.lo -MD -MP -MF $(DEPDIR)/libstix_la-bigint.Tpo -c -o libstix_la-bigint.lo `test -f 'bigint.c' || echo '$(srcdir)/'`bigint.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_la-bigint.Tpo $(DEPDIR)/libstix_la-bigint.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='bigint.c' object='libstix_la-bigint.lo' libtool=yes @AMDEPBACKSLASH@ +libmoo_la-bigint.lo: bigint.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-bigint.lo -MD -MP -MF $(DEPDIR)/libmoo_la-bigint.Tpo -c -o libmoo_la-bigint.lo `test -f 'bigint.c' || echo '$(srcdir)/'`bigint.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-bigint.Tpo $(DEPDIR)/libmoo_la-bigint.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='bigint.c' object='libmoo_la-bigint.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-bigint.lo `test -f 'bigint.c' || echo '$(srcdir)/'`bigint.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-bigint.lo `test -f 'bigint.c' || echo '$(srcdir)/'`bigint.c -libstix_la-comp.lo: comp.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-comp.lo -MD -MP -MF $(DEPDIR)/libstix_la-comp.Tpo -c -o libstix_la-comp.lo `test -f 'comp.c' || echo '$(srcdir)/'`comp.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_la-comp.Tpo $(DEPDIR)/libstix_la-comp.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='comp.c' object='libstix_la-comp.lo' libtool=yes @AMDEPBACKSLASH@ +libmoo_la-comp.lo: comp.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-comp.lo -MD -MP -MF $(DEPDIR)/libmoo_la-comp.Tpo -c -o libmoo_la-comp.lo `test -f 'comp.c' || echo '$(srcdir)/'`comp.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-comp.Tpo $(DEPDIR)/libmoo_la-comp.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='comp.c' object='libmoo_la-comp.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-comp.lo `test -f 'comp.c' || echo '$(srcdir)/'`comp.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-comp.lo `test -f 'comp.c' || echo '$(srcdir)/'`comp.c -libstix_la-debug.lo: debug.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-debug.lo -MD -MP -MF $(DEPDIR)/libstix_la-debug.Tpo -c -o libstix_la-debug.lo `test -f 'debug.c' || echo '$(srcdir)/'`debug.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_la-debug.Tpo $(DEPDIR)/libstix_la-debug.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='debug.c' object='libstix_la-debug.lo' libtool=yes @AMDEPBACKSLASH@ +libmoo_la-debug.lo: debug.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-debug.lo -MD -MP -MF $(DEPDIR)/libmoo_la-debug.Tpo -c -o libmoo_la-debug.lo `test -f 'debug.c' || echo '$(srcdir)/'`debug.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-debug.Tpo $(DEPDIR)/libmoo_la-debug.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='debug.c' object='libmoo_la-debug.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-debug.lo `test -f 'debug.c' || echo '$(srcdir)/'`debug.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-debug.lo `test -f 'debug.c' || echo '$(srcdir)/'`debug.c -libstix_la-decode.lo: decode.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-decode.lo -MD -MP -MF $(DEPDIR)/libstix_la-decode.Tpo -c -o libstix_la-decode.lo `test -f 'decode.c' || echo '$(srcdir)/'`decode.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_la-decode.Tpo $(DEPDIR)/libstix_la-decode.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='decode.c' object='libstix_la-decode.lo' libtool=yes @AMDEPBACKSLASH@ +libmoo_la-decode.lo: decode.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-decode.lo -MD -MP -MF $(DEPDIR)/libmoo_la-decode.Tpo -c -o libmoo_la-decode.lo `test -f 'decode.c' || echo '$(srcdir)/'`decode.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-decode.Tpo $(DEPDIR)/libmoo_la-decode.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='decode.c' object='libmoo_la-decode.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-decode.lo `test -f 'decode.c' || echo '$(srcdir)/'`decode.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-decode.lo `test -f 'decode.c' || echo '$(srcdir)/'`decode.c -libstix_la-dic.lo: dic.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-dic.lo -MD -MP -MF $(DEPDIR)/libstix_la-dic.Tpo -c -o libstix_la-dic.lo `test -f 'dic.c' || echo '$(srcdir)/'`dic.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_la-dic.Tpo $(DEPDIR)/libstix_la-dic.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='dic.c' object='libstix_la-dic.lo' libtool=yes @AMDEPBACKSLASH@ +libmoo_la-dic.lo: dic.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-dic.lo -MD -MP -MF $(DEPDIR)/libmoo_la-dic.Tpo -c -o libmoo_la-dic.lo `test -f 'dic.c' || echo '$(srcdir)/'`dic.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-dic.Tpo $(DEPDIR)/libmoo_la-dic.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='dic.c' object='libmoo_la-dic.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-dic.lo `test -f 'dic.c' || echo '$(srcdir)/'`dic.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-dic.lo `test -f 'dic.c' || echo '$(srcdir)/'`dic.c -libstix_la-err.lo: err.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-err.lo -MD -MP -MF $(DEPDIR)/libstix_la-err.Tpo -c -o libstix_la-err.lo `test -f 'err.c' || echo '$(srcdir)/'`err.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_la-err.Tpo $(DEPDIR)/libstix_la-err.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='err.c' object='libstix_la-err.lo' libtool=yes @AMDEPBACKSLASH@ +libmoo_la-err.lo: err.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-err.lo -MD -MP -MF $(DEPDIR)/libmoo_la-err.Tpo -c -o libmoo_la-err.lo `test -f 'err.c' || echo '$(srcdir)/'`err.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-err.Tpo $(DEPDIR)/libmoo_la-err.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='err.c' object='libmoo_la-err.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-err.lo `test -f 'err.c' || echo '$(srcdir)/'`err.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-err.lo `test -f 'err.c' || echo '$(srcdir)/'`err.c -libstix_la-exec.lo: exec.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-exec.lo -MD -MP -MF $(DEPDIR)/libstix_la-exec.Tpo -c -o libstix_la-exec.lo `test -f 'exec.c' || echo '$(srcdir)/'`exec.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_la-exec.Tpo $(DEPDIR)/libstix_la-exec.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='exec.c' object='libstix_la-exec.lo' libtool=yes @AMDEPBACKSLASH@ +libmoo_la-exec.lo: exec.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-exec.lo -MD -MP -MF $(DEPDIR)/libmoo_la-exec.Tpo -c -o libmoo_la-exec.lo `test -f 'exec.c' || echo '$(srcdir)/'`exec.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-exec.Tpo $(DEPDIR)/libmoo_la-exec.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='exec.c' object='libmoo_la-exec.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-exec.lo `test -f 'exec.c' || echo '$(srcdir)/'`exec.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-exec.lo `test -f 'exec.c' || echo '$(srcdir)/'`exec.c -libstix_la-logfmt.lo: logfmt.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-logfmt.lo -MD -MP -MF $(DEPDIR)/libstix_la-logfmt.Tpo -c -o libstix_la-logfmt.lo `test -f 'logfmt.c' || echo '$(srcdir)/'`logfmt.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_la-logfmt.Tpo $(DEPDIR)/libstix_la-logfmt.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='logfmt.c' object='libstix_la-logfmt.lo' libtool=yes @AMDEPBACKSLASH@ +libmoo_la-logfmt.lo: logfmt.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-logfmt.lo -MD -MP -MF $(DEPDIR)/libmoo_la-logfmt.Tpo -c -o libmoo_la-logfmt.lo `test -f 'logfmt.c' || echo '$(srcdir)/'`logfmt.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-logfmt.Tpo $(DEPDIR)/libmoo_la-logfmt.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='logfmt.c' object='libmoo_la-logfmt.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-logfmt.lo `test -f 'logfmt.c' || echo '$(srcdir)/'`logfmt.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-logfmt.lo `test -f 'logfmt.c' || echo '$(srcdir)/'`logfmt.c -libstix_la-gc.lo: gc.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-gc.lo -MD -MP -MF $(DEPDIR)/libstix_la-gc.Tpo -c -o libstix_la-gc.lo `test -f 'gc.c' || echo '$(srcdir)/'`gc.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_la-gc.Tpo $(DEPDIR)/libstix_la-gc.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='gc.c' object='libstix_la-gc.lo' libtool=yes @AMDEPBACKSLASH@ +libmoo_la-gc.lo: gc.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-gc.lo -MD -MP -MF $(DEPDIR)/libmoo_la-gc.Tpo -c -o libmoo_la-gc.lo `test -f 'gc.c' || echo '$(srcdir)/'`gc.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-gc.Tpo $(DEPDIR)/libmoo_la-gc.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='gc.c' object='libmoo_la-gc.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-gc.lo `test -f 'gc.c' || echo '$(srcdir)/'`gc.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-gc.lo `test -f 'gc.c' || echo '$(srcdir)/'`gc.c -libstix_la-heap.lo: heap.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-heap.lo -MD -MP -MF $(DEPDIR)/libstix_la-heap.Tpo -c -o libstix_la-heap.lo `test -f 'heap.c' || echo '$(srcdir)/'`heap.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_la-heap.Tpo $(DEPDIR)/libstix_la-heap.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='heap.c' object='libstix_la-heap.lo' libtool=yes @AMDEPBACKSLASH@ +libmoo_la-heap.lo: heap.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-heap.lo -MD -MP -MF $(DEPDIR)/libmoo_la-heap.Tpo -c -o libmoo_la-heap.lo `test -f 'heap.c' || echo '$(srcdir)/'`heap.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-heap.Tpo $(DEPDIR)/libmoo_la-heap.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='heap.c' object='libmoo_la-heap.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-heap.lo `test -f 'heap.c' || echo '$(srcdir)/'`heap.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-heap.lo `test -f 'heap.c' || echo '$(srcdir)/'`heap.c -libstix_la-obj.lo: obj.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-obj.lo -MD -MP -MF $(DEPDIR)/libstix_la-obj.Tpo -c -o libstix_la-obj.lo `test -f 'obj.c' || echo '$(srcdir)/'`obj.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_la-obj.Tpo $(DEPDIR)/libstix_la-obj.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='obj.c' object='libstix_la-obj.lo' libtool=yes @AMDEPBACKSLASH@ +libmoo_la-obj.lo: obj.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-obj.lo -MD -MP -MF $(DEPDIR)/libmoo_la-obj.Tpo -c -o libmoo_la-obj.lo `test -f 'obj.c' || echo '$(srcdir)/'`obj.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-obj.Tpo $(DEPDIR)/libmoo_la-obj.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='obj.c' object='libmoo_la-obj.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-obj.lo `test -f 'obj.c' || echo '$(srcdir)/'`obj.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-obj.lo `test -f 'obj.c' || echo '$(srcdir)/'`obj.c -libstix_la-proc.lo: proc.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-proc.lo -MD -MP -MF $(DEPDIR)/libstix_la-proc.Tpo -c -o libstix_la-proc.lo `test -f 'proc.c' || echo '$(srcdir)/'`proc.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_la-proc.Tpo $(DEPDIR)/libstix_la-proc.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='proc.c' object='libstix_la-proc.lo' libtool=yes @AMDEPBACKSLASH@ +libmoo_la-proc.lo: proc.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-proc.lo -MD -MP -MF $(DEPDIR)/libmoo_la-proc.Tpo -c -o libmoo_la-proc.lo `test -f 'proc.c' || echo '$(srcdir)/'`proc.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-proc.Tpo $(DEPDIR)/libmoo_la-proc.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='proc.c' object='libmoo_la-proc.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-proc.lo `test -f 'proc.c' || echo '$(srcdir)/'`proc.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-proc.lo `test -f 'proc.c' || echo '$(srcdir)/'`proc.c -libstix_la-rbt.lo: 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-rbt.lo -MD -MP -MF $(DEPDIR)/libstix_la-rbt.Tpo -c -o libstix_la-rbt.lo `test -f 'rbt.c' || echo '$(srcdir)/'`rbt.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_la-rbt.Tpo $(DEPDIR)/libstix_la-rbt.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rbt.c' object='libstix_la-rbt.lo' libtool=yes @AMDEPBACKSLASH@ +libmoo_la-rbt.lo: rbt.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-rbt.lo -MD -MP -MF $(DEPDIR)/libmoo_la-rbt.Tpo -c -o libmoo_la-rbt.lo `test -f 'rbt.c' || echo '$(srcdir)/'`rbt.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-rbt.Tpo $(DEPDIR)/libmoo_la-rbt.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rbt.c' object='libmoo_la-rbt.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-rbt.lo `test -f 'rbt.c' || echo '$(srcdir)/'`rbt.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-rbt.lo `test -f 'rbt.c' || echo '$(srcdir)/'`rbt.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 -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='stix.c' object='libstix_la-stix.lo' libtool=yes @AMDEPBACKSLASH@ +libmoo_la-moo.lo: moo.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-moo.lo -MD -MP -MF $(DEPDIR)/libmoo_la-moo.Tpo -c -o libmoo_la-moo.lo `test -f 'moo.c' || echo '$(srcdir)/'`moo.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-moo.Tpo $(DEPDIR)/libmoo_la-moo.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='moo.c' object='libmoo_la-moo.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.lo `test -f 'stix.c' || echo '$(srcdir)/'`stix.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-moo.lo `test -f 'moo.c' || echo '$(srcdir)/'`moo.c -libstix_la-sym.lo: sym.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-sym.lo -MD -MP -MF $(DEPDIR)/libstix_la-sym.Tpo -c -o libstix_la-sym.lo `test -f 'sym.c' || echo '$(srcdir)/'`sym.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_la-sym.Tpo $(DEPDIR)/libstix_la-sym.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='sym.c' object='libstix_la-sym.lo' libtool=yes @AMDEPBACKSLASH@ +libmoo_la-sym.lo: sym.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-sym.lo -MD -MP -MF $(DEPDIR)/libmoo_la-sym.Tpo -c -o libmoo_la-sym.lo `test -f 'sym.c' || echo '$(srcdir)/'`sym.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-sym.Tpo $(DEPDIR)/libmoo_la-sym.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='sym.c' object='libmoo_la-sym.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-sym.lo `test -f 'sym.c' || echo '$(srcdir)/'`sym.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-sym.lo `test -f 'sym.c' || echo '$(srcdir)/'`sym.c -libstix_la-utf8.lo: utf8.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-utf8.lo -MD -MP -MF $(DEPDIR)/libstix_la-utf8.Tpo -c -o libstix_la-utf8.lo `test -f 'utf8.c' || echo '$(srcdir)/'`utf8.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_la-utf8.Tpo $(DEPDIR)/libstix_la-utf8.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='utf8.c' object='libstix_la-utf8.lo' libtool=yes @AMDEPBACKSLASH@ +libmoo_la-utf8.lo: utf8.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-utf8.lo -MD -MP -MF $(DEPDIR)/libmoo_la-utf8.Tpo -c -o libmoo_la-utf8.lo `test -f 'utf8.c' || echo '$(srcdir)/'`utf8.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-utf8.Tpo $(DEPDIR)/libmoo_la-utf8.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='utf8.c' object='libmoo_la-utf8.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-utf8.lo `test -f 'utf8.c' || echo '$(srcdir)/'`utf8.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-utf8.lo `test -f 'utf8.c' || echo '$(srcdir)/'`utf8.c -libstix_la-utl.lo: 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-utl.lo -MD -MP -MF $(DEPDIR)/libstix_la-utl.Tpo -c -o libstix_la-utl.lo `test -f 'utl.c' || echo '$(srcdir)/'`utl.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_la-utl.Tpo $(DEPDIR)/libstix_la-utl.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='utl.c' object='libstix_la-utl.lo' libtool=yes @AMDEPBACKSLASH@ +libmoo_la-utl.lo: utl.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_la-utl.lo -MD -MP -MF $(DEPDIR)/libmoo_la-utl.Tpo -c -o libmoo_la-utl.lo `test -f 'utl.c' || echo '$(srcdir)/'`utl.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_la-utl.Tpo $(DEPDIR)/libmoo_la-utl.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='utl.c' object='libmoo_la-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-utl.lo `test -f 'utl.c' || echo '$(srcdir)/'`utl.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_la-utl.lo `test -f 'utl.c' || echo '$(srcdir)/'`utl.c -stix-main.o: main.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(stix_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT stix-main.o -MD -MP -MF $(DEPDIR)/stix-main.Tpo -c -o stix-main.o `test -f 'main.c' || echo '$(srcdir)/'`main.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/stix-main.Tpo $(DEPDIR)/stix-main.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='main.c' object='stix-main.o' libtool=no @AMDEPBACKSLASH@ +moo-main.o: main.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(moo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT moo-main.o -MD -MP -MF $(DEPDIR)/moo-main.Tpo -c -o moo-main.o `test -f 'main.c' || echo '$(srcdir)/'`main.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/moo-main.Tpo $(DEPDIR)/moo-main.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='main.c' object='moo-main.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(stix_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o stix-main.o `test -f 'main.c' || echo '$(srcdir)/'`main.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(moo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o moo-main.o `test -f 'main.c' || echo '$(srcdir)/'`main.c -stix-main.obj: main.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(stix_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT stix-main.obj -MD -MP -MF $(DEPDIR)/stix-main.Tpo -c -o stix-main.obj `if test -f 'main.c'; then $(CYGPATH_W) 'main.c'; else $(CYGPATH_W) '$(srcdir)/main.c'; fi` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/stix-main.Tpo $(DEPDIR)/stix-main.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='main.c' object='stix-main.obj' libtool=no @AMDEPBACKSLASH@ +moo-main.obj: main.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(moo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT moo-main.obj -MD -MP -MF $(DEPDIR)/moo-main.Tpo -c -o moo-main.obj `if test -f 'main.c'; then $(CYGPATH_W) 'main.c'; else $(CYGPATH_W) '$(srcdir)/main.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/moo-main.Tpo $(DEPDIR)/moo-main.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='main.c' object='moo-main.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(stix_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o stix-main.obj `if test -f 'main.c'; then $(CYGPATH_W) 'main.c'; else $(CYGPATH_W) '$(srcdir)/main.c'; fi` +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(moo_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o moo-main.obj `if test -f 'main.c'; then $(CYGPATH_W) 'main.c'; else $(CYGPATH_W) '$(srcdir)/main.c'; fi` mostlyclean-libtool: -rm -f *.lo @@ -867,7 +867,7 @@ distdir: $(DISTFILES) done check-am: all-am check: check-am -all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(HEADERS) stix-cfg.h +all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(HEADERS) moo-cfg.h installdirs: for dir in "$(DESTDIR)$(pkglibdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(pkgincludedir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ @@ -998,15 +998,15 @@ uninstall-am: uninstall-binPROGRAMS uninstall-pkgincludeHEADERS \ install-data-hook: - @echo "#ifndef _STIX_CFG_H_" > "$(DESTDIR)$(pkgincludedir)/stix-cfg.h" - @echo "#define _STIX_CFG_H_" >> "$(DESTDIR)$(pkgincludedir)/stix-cfg.h" - @$(EGREP) "#define[ ]+STIX_" "$(abs_builddir)/stix-cfg.h" >> "$(DESTDIR)$(pkgincludedir)/stix-cfg.h" - @echo "#endif" >> "$(DESTDIR)$(pkgincludedir)/stix-cfg.h" - @rm -f "$(DESTDIR)$(pkgincludedir)/stix-cfg.h.in" - @$(SED) 's|/\*#define STIX_HAVE_CFG_H\*/|#define STIX_HAVE_CFG_H|' "$(srcdir)/stix-cmn.h" > "$(DESTDIR)$(pkgincludedir)/stix-cmn.h" + @echo "#ifndef _MOO_CFG_H_" > "$(DESTDIR)$(pkgincludedir)/moo-cfg.h" + @echo "#define _MOO_CFG_H_" >> "$(DESTDIR)$(pkgincludedir)/moo-cfg.h" + @$(EGREP) "#define[ ]+MOO_" "$(abs_builddir)/moo-cfg.h" >> "$(DESTDIR)$(pkgincludedir)/moo-cfg.h" + @echo "#endif" >> "$(DESTDIR)$(pkgincludedir)/moo-cfg.h" + @rm -f "$(DESTDIR)$(pkgincludedir)/moo-cfg.h.in" + @$(SED) 's|/\*#define MOO_HAVE_CFG_H\*/|#define MOO_HAVE_CFG_H|' "$(srcdir)/moo-cmn.h" > "$(DESTDIR)$(pkgincludedir)/moo-cmn.h" uninstall-hook: - @rm -f "$(DESTDIR)$(pkgincludedir)/stix-cfg.h" + @rm -f "$(DESTDIR)$(pkgincludedir)/moo-cfg.h" # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/stix/lib/bigint.c b/stix/lib/bigint.c index 72215b6..641b5e1 100644 --- a/stix/lib/bigint.c +++ b/stix/lib/bigint.c @@ -54,20 +54,20 @@ */ -#include "stix-prv.h" +#include "moo-prv.h" #define ENABLE_KARATSUBA -#if defined(STIX_DEBUG_BIGINT) +#if defined(MOO_DEBUG_BIGINT) # define KARATSUBA_CUTOFF 3 #else # define KARATSUBA_CUTOFF 32 #endif -#if (STIX_LIW_BITS == STIX_OOW_BITS) +#if (MOO_LIW_BITS == MOO_OOW_BITS) /* nothing special */ -#elif (STIX_LIW_BITS == STIX_OOHW_BITS) -# define MAKE_WORD(hw1,hw2) ((stix_oow_t)(hw1) | (stix_oow_t)(hw2) << STIX_LIW_BITS) +#elif (MOO_LIW_BITS == MOO_OOHW_BITS) +# define MAKE_WORD(hw1,hw2) ((moo_oow_t)(hw1) | (moo_oow_t)(hw2) << MOO_LIW_BITS) #else # error UNSUPPORTED LIW BIT SIZE #endif @@ -81,78 +81,78 @@ static char* _digitc = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; /* exponent table */ -static stix_uint8_t _exp_tab[] = +static moo_uint8_t _exp_tab[] = { 0, 0, 1, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0 }; -#if (STIX_SIZEOF_OOW_T == STIX_SIZEOF_INT) && defined(STIX_HAVE_BUILTIN_UADD_OVERFLOW) +#if (MOO_SIZEOF_OOW_T == MOO_SIZEOF_INT) && defined(MOO_HAVE_BUILTIN_UADD_OVERFLOW) # define oow_add_overflow(a,b,c) __builtin_uadd_overflow(a,b,c) -#elif (STIX_SIZEOF_OOW_T == STIX_SIZEOF_LONG) && defined(STIX_HAVE_BUILTIN_UADDL_OVERFLOW) +#elif (MOO_SIZEOF_OOW_T == MOO_SIZEOF_LONG) && defined(MOO_HAVE_BUILTIN_UADDL_OVERFLOW) # define oow_add_overflow(a,b,c) __builtin_uaddl_overflow(a,b,c) -#elif (STIX_SIZEOF_OOW_T == STIX_SIZEOF_LONG_LONG) && defined(STIX_HAVE_BUILTIN_UADDLL_OVERFLOW) +#elif (MOO_SIZEOF_OOW_T == MOO_SIZEOF_LONG_LONG) && defined(MOO_HAVE_BUILTIN_UADDLL_OVERFLOW) # define oow_add_overflow(a,b,c) __builtin_uaddll_overflow(a,b,c) #else -static STIX_INLINE int oow_add_overflow (stix_oow_t a, stix_oow_t b, stix_oow_t* c) +static MOO_INLINE int oow_add_overflow (moo_oow_t a, moo_oow_t b, moo_oow_t* c) { *c = a + b; - return b > STIX_TYPE_MAX(stix_oow_t) - a; + return b > MOO_TYPE_MAX(moo_oow_t) - a; } #endif -#if (STIX_SIZEOF_OOW_T == STIX_SIZEOF_INT) && defined(STIX_HAVE_BUILTIN_UMUL_OVERFLOW) +#if (MOO_SIZEOF_OOW_T == MOO_SIZEOF_INT) && defined(MOO_HAVE_BUILTIN_UMUL_OVERFLOW) # define oow_mul_overflow(a,b,c) __builtin_umul_overflow(a,b,c) -#elif (STIX_SIZEOF_OOW_T == STIX_SIZEOF_LONG) && defined(STIX_HAVE_BUILTIN_UMULL_OVERFLOW) +#elif (MOO_SIZEOF_OOW_T == MOO_SIZEOF_LONG) && defined(MOO_HAVE_BUILTIN_UMULL_OVERFLOW) # define oow_mul_overflow(a,b,c) __builtin_umull_overflow(a,b,c) -#elif (STIX_SIZEOF_OOW_T == STIX_SIZEOF_LONG_LONG) && defined(STIX_HAVE_BUILTIN_UMULLL_OVERFLOW) +#elif (MOO_SIZEOF_OOW_T == MOO_SIZEOF_LONG_LONG) && defined(MOO_HAVE_BUILTIN_UMULLL_OVERFLOW) # define oow_mul_overflow(a,b,c) __builtin_umulll_overflow(a,b,c) #else -static STIX_INLINE int oow_mul_overflow (stix_oow_t a, stix_oow_t b, stix_oow_t* c) +static MOO_INLINE int oow_mul_overflow (moo_oow_t a, moo_oow_t b, moo_oow_t* c) { -#if (STIX_SIZEOF_UINTMAX_T > STIX_SIZEOF_OOW_T) - stix_uintmax_t k; - k = (stix_uintmax_t)a * (stix_uintmax_t)b; - *c = (stix_oow_t)k; - return (k >> STIX_OOW_BITS) > 0; - /*return k > STIX_TYPE_MAX(stix_oow_t);*/ +#if (MOO_SIZEOF_UINTMAX_T > MOO_SIZEOF_OOW_T) + moo_uintmax_t k; + k = (moo_uintmax_t)a * (moo_uintmax_t)b; + *c = (moo_oow_t)k; + return (k >> MOO_OOW_BITS) > 0; + /*return k > MOO_TYPE_MAX(moo_oow_t);*/ #else *c = a * b; - return b != 0 && a > STIX_TYPE_MAX(stix_oow_t) / b; /* works for unsigned types only */ + return b != 0 && a > MOO_TYPE_MAX(moo_oow_t) / b; /* works for unsigned types only */ #endif } #endif -#if (STIX_SIZEOF_OOI_T == STIX_SIZEOF_INT) && defined(STIX_HAVE_BUILTIN_SMUL_OVERFLOW) -# define smooi_mul_overflow(stix,a,b,c) __builtin_smul_overflow(a,b,c) -#elif (STIX_SIZEOF_OOI_T == STIX_SIZEOF_LONG) && defined(STIX_HAVE_BUILTIN_SMULL_OVERFLOW) -# define smooi_mul_overflow(stix,a,b,c) __builtin_smull_overflow(a,b,c) -#elif (STIX_SIZEOF_OOI_T == STIX_SIZEOF_LONG_LONG) && defined(STIX_HAVE_BUILTIN_SMULLL_OVERFLOW) -# define smooi_mul_overflow(stix,a,b,c) __builtin_smulll_overflow(a,b,c) +#if (MOO_SIZEOF_OOI_T == MOO_SIZEOF_INT) && defined(MOO_HAVE_BUILTIN_SMUL_OVERFLOW) +# define smooi_mul_overflow(moo,a,b,c) __builtin_smul_overflow(a,b,c) +#elif (MOO_SIZEOF_OOI_T == MOO_SIZEOF_LONG) && defined(MOO_HAVE_BUILTIN_SMULL_OVERFLOW) +# define smooi_mul_overflow(moo,a,b,c) __builtin_smull_overflow(a,b,c) +#elif (MOO_SIZEOF_OOI_T == MOO_SIZEOF_LONG_LONG) && defined(MOO_HAVE_BUILTIN_SMULLL_OVERFLOW) +# define smooi_mul_overflow(moo,a,b,c) __builtin_smulll_overflow(a,b,c) #else -static STIX_INLINE int smooi_mul_overflow (stix_t* stix, stix_ooi_t a, stix_ooi_t b, stix_ooi_t* c) +static MOO_INLINE int smooi_mul_overflow (moo_t* moo, moo_ooi_t a, moo_ooi_t b, moo_ooi_t* c) { /* take note that this function is not supposed to handle - * the whole stix_ooi_t range. it handles the smooi subrange */ + * the whole moo_ooi_t range. it handles the smooi subrange */ -#if (STIX_SIZEOF_UINTMAX_T > STIX_SIZEOF_OOI_T) - stix_intmax_t k; +#if (MOO_SIZEOF_UINTMAX_T > MOO_SIZEOF_OOI_T) + moo_intmax_t k; - STIX_ASSERT (stix, STIX_IN_SMOOI_RANGE(a)); - STIX_ASSERT (stix, STIX_IN_SMOOI_RANGE(b)); + MOO_ASSERT (moo, MOO_IN_SMOOI_RANGE(a)); + MOO_ASSERT (moo, MOO_IN_SMOOI_RANGE(b)); - k = (stix_intmax_t)a * (stix_intmax_t)b; - *c = (stix_ooi_t)k; + k = (moo_intmax_t)a * (moo_intmax_t)b; + *c = (moo_ooi_t)k; - return k > STIX_TYPE_MAX(stix_ooi_t) || k < STIX_TYPE_MIN(stix_ooi_t); + return k > MOO_TYPE_MAX(moo_ooi_t) || k < MOO_TYPE_MIN(moo_ooi_t); #else - stix_ooi_t ua, ub; + moo_ooi_t ua, ub; - STIX_ASSERT (stix, STIX_IN_SMOOI_RANGE(a)); - STIX_ASSERT (stix, STIX_IN_SMOOI_RANGE(b)); + MOO_ASSERT (moo, MOO_IN_SMOOI_RANGE(a)); + MOO_ASSERT (moo, MOO_IN_SMOOI_RANGE(b)); *c = a * b; @@ -163,120 +163,120 @@ static STIX_INLINE int smooi_mul_overflow (stix_t* stix, stix_ooi_t a, stix_ooi_ * the values used here are all absolute values and they fall in * a safe range to apply this fomula. the safe range is guaranteed because * the sources are supposed to be smoois. */ - return ub != 0 && ua > STIX_TYPE_MAX(stix_ooi_t) / ub; + return ub != 0 && ua > MOO_TYPE_MAX(moo_ooi_t) / ub; #endif } #endif -#if (STIX_SIZEOF_LIW_T == STIX_SIZEOF_INT) && defined(STIX_HAVE_BUILTIN_UADD_OVERFLOW) +#if (MOO_SIZEOF_LIW_T == MOO_SIZEOF_INT) && defined(MOO_HAVE_BUILTIN_UADD_OVERFLOW) # define liw_add_overflow(a,b,c) __builtin_uadd_overflow(a,b,c) -#elif (STIX_SIZEOF_LIW_T == STIX_SIZEOF_LONG) && defined(STIX_HAVE_BUILTIN_UADDL_OVERFLOW) +#elif (MOO_SIZEOF_LIW_T == MOO_SIZEOF_LONG) && defined(MOO_HAVE_BUILTIN_UADDL_OVERFLOW) # define liw_add_overflow(a,b,c) __builtin_uaddl_overflow(a,b,c) -#elif (STIX_SIZEOF_LIW_T == STIX_SIZEOF_LONG_LONG) && defined(STIX_HAVE_BUILTIN_UADDLL_OVERFLOW) +#elif (MOO_SIZEOF_LIW_T == MOO_SIZEOF_LONG_LONG) && defined(MOO_HAVE_BUILTIN_UADDLL_OVERFLOW) # define liw_add_overflow(a,b,c) __builtin_uaddll_overflow(a,b,c) #else -static STIX_INLINE int liw_add_overflow (stix_liw_t a, stix_liw_t b, stix_liw_t* c) +static MOO_INLINE int liw_add_overflow (moo_liw_t a, moo_liw_t b, moo_liw_t* c) { *c = a + b; - return b > STIX_TYPE_MAX(stix_liw_t) - a; + return b > MOO_TYPE_MAX(moo_liw_t) - a; } #endif -#if (STIX_SIZEOF_LIW_T == STIX_SIZEOF_INT) && defined(STIX_HAVE_BUILTIN_UMUL_OVERFLOW) +#if (MOO_SIZEOF_LIW_T == MOO_SIZEOF_INT) && defined(MOO_HAVE_BUILTIN_UMUL_OVERFLOW) # define liw_mul_overflow(a,b,c) __builtin_umul_overflow(a,b,c) -#elif (STIX_SIZEOF_LIW_T == STIX_SIZEOF_LONG) && defined(STIX_HAVE_BUILTIN_UMULL_OVERFLOW) +#elif (MOO_SIZEOF_LIW_T == MOO_SIZEOF_LONG) && defined(MOO_HAVE_BUILTIN_UMULL_OVERFLOW) # define liw_mul_overflow(a,b,c) __builtin_uaddl_overflow(a,b,c) -#elif (STIX_SIZEOF_LIW_T == STIX_SIZEOF_LONG_LONG) && defined(STIX_HAVE_BUILTIN_UMULLL_OVERFLOW) +#elif (MOO_SIZEOF_LIW_T == MOO_SIZEOF_LONG_LONG) && defined(MOO_HAVE_BUILTIN_UMULLL_OVERFLOW) # define liw_mul_overflow(a,b,c) __builtin_uaddll_overflow(a,b,c) #else -static STIX_INLINE int liw_mul_overflow (stix_liw_t a, stix_liw_t b, stix_liw_t* c) +static MOO_INLINE int liw_mul_overflow (moo_liw_t a, moo_liw_t b, moo_liw_t* c) { -#if (STIX_SIZEOF_UINTMAX_T > STIX_SIZEOF_LIW_T) - stix_uintmax_t k; - k = (stix_uintmax_t)a * (stix_uintmax_t)b; - *c = (stix_liw_t)k; - return (k >> STIX_LIW_BITS) > 0; - /*return k > STIX_TYPE_MAX(stix_liw_t);*/ +#if (MOO_SIZEOF_UINTMAX_T > MOO_SIZEOF_LIW_T) + moo_uintmax_t k; + k = (moo_uintmax_t)a * (moo_uintmax_t)b; + *c = (moo_liw_t)k; + return (k >> MOO_LIW_BITS) > 0; + /*return k > MOO_TYPE_MAX(moo_liw_t);*/ #else *c = a * b; - return b != 0 && a > STIX_TYPE_MAX(stix_liw_t) / b; /* works for unsigned types only */ + return b != 0 && a > MOO_TYPE_MAX(moo_liw_t) / b; /* works for unsigned types only */ #endif } #endif -static int is_normalized_integer (stix_t* stix, stix_oop_t oop) +static int is_normalized_integer (moo_t* moo, moo_oop_t oop) { - if (STIX_OOP_IS_SMOOI(oop)) return 1; - if (STIX_OOP_IS_POINTER(oop)) + if (MOO_OOP_IS_SMOOI(oop)) return 1; + if (MOO_OOP_IS_POINTER(oop)) { - stix_oop_t c; + moo_oop_t c; /* TODO: is it better to introduce a special integer mark into the class itself */ /* TODO: or should it check if it's a subclass, subsubclass, subsubsubclass, etc of a large_integer as well? */ - c = STIX_OBJ_GET_CLASS(oop); + c = MOO_OBJ_GET_CLASS(oop); - if (c == stix->_large_positive_integer || - c == stix->_large_negative_integer) + if (c == moo->_large_positive_integer || + c == moo->_large_negative_integer) { - stix_oow_t sz; + moo_oow_t sz; - sz = STIX_OBJ_GET_SIZE(oop); - STIX_ASSERT (stix, sz >= 1); + sz = MOO_OBJ_GET_SIZE(oop); + MOO_ASSERT (moo, sz >= 1); - return ((stix_oop_liword_t)oop)->slot[sz - 1] == 0? 0: 1; + return ((moo_oop_liword_t)oop)->slot[sz - 1] == 0? 0: 1; } } return 0; } -STIX_INLINE static int is_bigint (stix_t* stix, stix_oop_t x) +MOO_INLINE static int is_bigint (moo_t* moo, moo_oop_t x) { - stix_oop_t c; + moo_oop_t c; - STIX_ASSERT (stix, STIX_OOP_IS_POINTER(x)); + MOO_ASSERT (moo, MOO_OOP_IS_POINTER(x)); /* TODO: is it better to introduce a special integer mark into the class itself */ /* TODO: or should it check if it's a subclass, subsubclass, subsubsubclass, etc of a large_integer as well? */ - c = STIX_OBJ_GET_CLASS(x); + c = MOO_OBJ_GET_CLASS(x); - if (c == stix->_large_positive_integer || - c == stix->_large_negative_integer) return 1; + if (c == moo->_large_positive_integer || + c == moo->_large_negative_integer) return 1; return 0; } -STIX_INLINE int stix_isint (stix_t* stix, stix_oop_t x) +MOO_INLINE int moo_isint (moo_t* moo, moo_oop_t x) { - if (STIX_OOP_IS_SMOOI(x)) return 1; - if (STIX_OOP_IS_POINTER(x)) return is_bigint(stix, x); + if (MOO_OOP_IS_SMOOI(x)) return 1; + if (MOO_OOP_IS_POINTER(x)) return is_bigint(moo, x); return 0; } -static STIX_INLINE int bigint_to_oow (stix_t* stix, stix_oop_t num, stix_oow_t* w) +static MOO_INLINE int bigint_to_oow (moo_t* moo, moo_oop_t num, moo_oow_t* w) { - STIX_ASSERT (stix, STIX_OOP_IS_POINTER(num)); - STIX_ASSERT (stix, STIX_OBJ_GET_CLASS(num) == stix->_large_positive_integer || - STIX_OBJ_GET_CLASS(num) == stix->_large_negative_integer); + MOO_ASSERT (moo, MOO_OOP_IS_POINTER(num)); + MOO_ASSERT (moo, MOO_OBJ_GET_CLASS(num) == moo->_large_positive_integer || + MOO_OBJ_GET_CLASS(num) == moo->_large_negative_integer); -#if (STIX_LIW_BITS == STIX_OOW_BITS) - STIX_ASSERT (stix, STIX_OBJ_GET_SIZE(num) >= 1); - if (STIX_OBJ_GET_SIZE(num) == 1) +#if (MOO_LIW_BITS == MOO_OOW_BITS) + MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(num) >= 1); + if (MOO_OBJ_GET_SIZE(num) == 1) { - *w = ((stix_oop_word_t)num)->slot[0]; - return (STIX_OBJ_GET_CLASS(num) == stix->_large_negative_integer)? -1: 1; + *w = ((moo_oop_word_t)num)->slot[0]; + return (MOO_OBJ_GET_CLASS(num) == moo->_large_negative_integer)? -1: 1; } -#elif (STIX_LIW_BITS == STIX_OOHW_BITS) +#elif (MOO_LIW_BITS == MOO_OOHW_BITS) /* this function must be called with a real large integer. * a real large integer is at least 2 half-word long. * you must not call this function with an unnormalized * large integer. */ - STIX_ASSERT (stix, STIX_OBJ_GET_SIZE(num) >= 2); - if (STIX_OBJ_GET_SIZE(num) == 2) + MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(num) >= 2); + if (MOO_OBJ_GET_SIZE(num) == 2) { - *w = MAKE_WORD (((stix_oop_halfword_t)num)->slot[0], ((stix_oop_halfword_t)num)->slot[1]); - return (STIX_OBJ_GET_CLASS(num) == stix->_large_negative_integer)? -1: 1; + *w = MAKE_WORD (((moo_oop_halfword_t)num)->slot[0], ((moo_oop_halfword_t)num)->slot[1]); + return (MOO_OBJ_GET_CLASS(num) == moo->_large_negative_integer)? -1: 1; } #else # error UNSUPPORTED LIW BIT SIZE @@ -285,19 +285,19 @@ static STIX_INLINE int bigint_to_oow (stix_t* stix, stix_oop_t num, stix_oow_t* return 0; /* not convertable */ } -static STIX_INLINE int integer_to_oow (stix_t* stix, stix_oop_t x, stix_oow_t* w) +static MOO_INLINE int integer_to_oow (moo_t* moo, moo_oop_t x, moo_oow_t* w) { /* return value - * 1 - a positive number including 0 that can fit into stix_oow_t - * -1 - a negative number whose absolute value can fit into stix_oow_t + * 1 - a positive number including 0 that can fit into moo_oow_t + * -1 - a negative number whose absolute value can fit into moo_oow_t * 0 - number too large or too small */ - if (STIX_OOP_IS_SMOOI(x)) + if (MOO_OOP_IS_SMOOI(x)) { - stix_ooi_t v; + moo_ooi_t v; - v = STIX_OOP_TO_SMOOI(x); + v = MOO_OOP_TO_SMOOI(x); if (v < 0) { *w = -v; @@ -310,17 +310,17 @@ static STIX_INLINE int integer_to_oow (stix_t* stix, stix_oop_t x, stix_oow_t* w } } - STIX_ASSERT (stix, is_bigint(stix, x)); - return bigint_to_oow (stix, x, w); + MOO_ASSERT (moo, is_bigint(moo, x)); + return bigint_to_oow (moo, x, w); } -int stix_inttooow (stix_t* stix, stix_oop_t x, stix_oow_t* w) +int moo_inttooow (moo_t* moo, moo_oop_t x, moo_oow_t* w) { - if (STIX_OOP_IS_SMOOI(x)) + if (MOO_OOP_IS_SMOOI(x)) { - stix_ooi_t v; + moo_ooi_t v; - v = STIX_OOP_TO_SMOOI(x); + v = MOO_OOP_TO_SMOOI(x); if (v < 0) { *w = -v; @@ -333,238 +333,238 @@ int stix_inttooow (stix_t* stix, stix_oop_t x, stix_oow_t* w) } } - if (is_bigint(stix, x)) return bigint_to_oow (stix, x, w); + if (is_bigint(moo, x)) return bigint_to_oow (moo, x, w); return 0; /* not convertable - too big, too small, or not an integer */ } -static STIX_INLINE stix_oop_t make_bigint_with_oow (stix_t* stix, stix_oow_t w) +static MOO_INLINE moo_oop_t make_bigint_with_oow (moo_t* moo, moo_oow_t w) { -#if (STIX_LIW_BITS == STIX_OOW_BITS) - STIX_ASSERT (stix, STIX_SIZEOF(stix_oow_t) == STIX_SIZEOF(stix_liw_t)); - return stix_instantiate (stix, stix->_large_positive_integer, &w, 1); -#elif (STIX_LIW_BITS == STIX_OOHW_BITS) - stix_liw_t hw[2]; - hw[0] = w /*& STIX_LBMASK(stix_oow_t,STIX_LIW_BITS)*/; - hw[1] = w >> STIX_LIW_BITS; - return stix_instantiate (stix, stix->_large_positive_integer, &hw, (hw[1] > 0? 2: 1)); +#if (MOO_LIW_BITS == MOO_OOW_BITS) + MOO_ASSERT (moo, MOO_SIZEOF(moo_oow_t) == MOO_SIZEOF(moo_liw_t)); + return moo_instantiate (moo, moo->_large_positive_integer, &w, 1); +#elif (MOO_LIW_BITS == MOO_OOHW_BITS) + moo_liw_t hw[2]; + hw[0] = w /*& MOO_LBMASK(moo_oow_t,MOO_LIW_BITS)*/; + hw[1] = w >> MOO_LIW_BITS; + return moo_instantiate (moo, moo->_large_positive_integer, &hw, (hw[1] > 0? 2: 1)); #else # error UNSUPPORTED LIW BIT SIZE #endif } -static STIX_INLINE stix_oop_t make_bigint_with_ooi (stix_t* stix, stix_ooi_t i) +static MOO_INLINE moo_oop_t make_bigint_with_ooi (moo_t* moo, moo_ooi_t i) { -#if (STIX_LIW_BITS == STIX_OOW_BITS) - stix_oow_t w; +#if (MOO_LIW_BITS == MOO_OOW_BITS) + moo_oow_t w; - STIX_ASSERT (stix, STIX_SIZEOF(stix_oow_t) == STIX_SIZEOF(stix_liw_t)); + MOO_ASSERT (moo, MOO_SIZEOF(moo_oow_t) == MOO_SIZEOF(moo_liw_t)); if (i >= 0) { w = i; - return stix_instantiate (stix, stix->_large_positive_integer, &w, 1); + return moo_instantiate (moo, moo->_large_positive_integer, &w, 1); } else { /* The caller must ensure that i is greater than the smallest value - * that stix_ooi_t can represent. otherwise, the absolute value - * cannot be held in stix_ooi_t. */ - STIX_ASSERT (stix, i > STIX_TYPE_MIN(stix_ooi_t)); + * that moo_ooi_t can represent. otherwise, the absolute value + * cannot be held in moo_ooi_t. */ + MOO_ASSERT (moo, i > MOO_TYPE_MIN(moo_ooi_t)); w = -i; - return stix_instantiate (stix, stix->_large_negative_integer, &w, 1); + return moo_instantiate (moo, moo->_large_negative_integer, &w, 1); } -#elif (STIX_LIW_BITS == STIX_OOHW_BITS) - stix_liw_t hw[2]; - stix_oow_t w; +#elif (MOO_LIW_BITS == MOO_OOHW_BITS) + moo_liw_t hw[2]; + moo_oow_t w; if (i >= 0) { w = i; - hw[0] = w /*& STIX_LBMASK(stix_oow_t,STIX_LIW_BITS)*/; - hw[1] = w >> STIX_LIW_BITS; - return stix_instantiate (stix, stix->_large_positive_integer, &hw, (hw[1] > 0? 2: 1)); + hw[0] = w /*& MOO_LBMASK(moo_oow_t,MOO_LIW_BITS)*/; + hw[1] = w >> MOO_LIW_BITS; + return moo_instantiate (moo, moo->_large_positive_integer, &hw, (hw[1] > 0? 2: 1)); } else { - STIX_ASSERT (stix, i > STIX_TYPE_MIN(stix_ooi_t)); + MOO_ASSERT (moo, i > MOO_TYPE_MIN(moo_ooi_t)); w = -i; - hw[0] = w /*& STIX_LBMASK(stix_oow_t,STIX_LIW_BITS)*/; - hw[1] = w >> STIX_LIW_BITS; - return stix_instantiate (stix, stix->_large_negative_integer, &hw, (hw[1] > 0? 2: 1)); + hw[0] = w /*& MOO_LBMASK(moo_oow_t,MOO_LIW_BITS)*/; + hw[1] = w >> MOO_LIW_BITS; + return moo_instantiate (moo, moo->_large_negative_integer, &hw, (hw[1] > 0? 2: 1)); } #else # error UNSUPPORTED LIW BIT SIZE #endif } -static STIX_INLINE stix_oop_t make_bloated_bigint_with_ooi (stix_t* stix, stix_ooi_t i, stix_oow_t extra) +static MOO_INLINE moo_oop_t make_bloated_bigint_with_ooi (moo_t* moo, moo_ooi_t i, moo_oow_t extra) { -#if (STIX_LIW_BITS == STIX_OOW_BITS) - stix_oow_t w; - stix_oop_t z; +#if (MOO_LIW_BITS == MOO_OOW_BITS) + moo_oow_t w; + moo_oop_t z; - STIX_ASSERT (stix, extra <= STIX_OBJ_SIZE_MAX - 1); - STIX_ASSERT (stix, STIX_SIZEOF(stix_oow_t) == STIX_SIZEOF(stix_liw_t)); + MOO_ASSERT (moo, extra <= MOO_OBJ_SIZE_MAX - 1); + MOO_ASSERT (moo, MOO_SIZEOF(moo_oow_t) == MOO_SIZEOF(moo_liw_t)); if (i >= 0) { w = i; - z =stix_instantiate (stix, stix->_large_positive_integer, STIX_NULL, 1 + extra); + z =moo_instantiate (moo, moo->_large_positive_integer, MOO_NULL, 1 + extra); } else { - STIX_ASSERT (stix, i > STIX_TYPE_MIN(stix_ooi_t)); + MOO_ASSERT (moo, i > MOO_TYPE_MIN(moo_ooi_t)); w = -i; - z = stix_instantiate (stix, stix->_large_negative_integer, STIX_NULL, 1 + extra); + z = moo_instantiate (moo, moo->_large_negative_integer, MOO_NULL, 1 + extra); } - if (!z) return STIX_NULL; - ((stix_oop_liword_t)z)->slot[0] = w; + if (!z) return MOO_NULL; + ((moo_oop_liword_t)z)->slot[0] = w; return z; -#elif (STIX_LIW_BITS == STIX_OOHW_BITS) - stix_liw_t hw[2]; - stix_oow_t w; - stix_oop_t z; +#elif (MOO_LIW_BITS == MOO_OOHW_BITS) + moo_liw_t hw[2]; + moo_oow_t w; + moo_oop_t z; - STIX_ASSERT (stix, extra <= STIX_OBJ_SIZE_MAX - 2); + MOO_ASSERT (moo, extra <= MOO_OBJ_SIZE_MAX - 2); if (i >= 0) { w = i; - hw[0] = w /*& STIX_LBMASK(stix_oow_t,STIX_LIW_BITS)*/; - hw[1] = w >> STIX_LIW_BITS; - z = stix_instantiate (stix, stix->_large_positive_integer, STIX_NULL, (hw[1] > 0? 2: 1) + extra); + hw[0] = w /*& MOO_LBMASK(moo_oow_t,MOO_LIW_BITS)*/; + hw[1] = w >> MOO_LIW_BITS; + z = moo_instantiate (moo, moo->_large_positive_integer, MOO_NULL, (hw[1] > 0? 2: 1) + extra); } else { - STIX_ASSERT (stix, i > STIX_TYPE_MIN(stix_ooi_t)); + MOO_ASSERT (moo, i > MOO_TYPE_MIN(moo_ooi_t)); w = -i; - hw[0] = w /*& STIX_LBMASK(stix_oow_t,STIX_LIW_BITS)*/; - hw[1] = w >> STIX_LIW_BITS; - z = stix_instantiate (stix, stix->_large_negative_integer, STIX_NULL, (hw[1] > 0? 2: 1) + extra); + hw[0] = w /*& MOO_LBMASK(moo_oow_t,MOO_LIW_BITS)*/; + hw[1] = w >> MOO_LIW_BITS; + z = moo_instantiate (moo, moo->_large_negative_integer, MOO_NULL, (hw[1] > 0? 2: 1) + extra); } - if (!z) return STIX_NULL; - ((stix_oop_liword_t)z)->slot[0] = hw[0]; - if (hw[1] > 0) ((stix_oop_liword_t)z)->slot[1] = hw[1]; + if (!z) return MOO_NULL; + ((moo_oop_liword_t)z)->slot[0] = hw[0]; + if (hw[1] > 0) ((moo_oop_liword_t)z)->slot[1] = hw[1]; return z; #else # error UNSUPPORTED LIW BIT SIZE #endif } -static STIX_INLINE stix_oop_t make_bigint_with_intmax (stix_t* stix, stix_intmax_t v) +static MOO_INLINE moo_oop_t make_bigint_with_intmax (moo_t* moo, moo_intmax_t v) { - stix_oow_t len; - stix_liw_t buf[STIX_SIZEOF_INTMAX_T / STIX_SIZEOF_LIW_T]; - stix_uintmax_t ui; + moo_oow_t len; + moo_liw_t buf[MOO_SIZEOF_INTMAX_T / MOO_SIZEOF_LIW_T]; + moo_uintmax_t ui; /* this is not a generic function. it can't handle v - * if it's STIX_TYPE_MIN(stix_intmax_t) */ - STIX_ASSERT (stix, v > STIX_TYPE_MIN(stix_intmax_t)); + * if it's MOO_TYPE_MIN(moo_intmax_t) */ + MOO_ASSERT (moo, v > MOO_TYPE_MIN(moo_intmax_t)); ui = (v >= 0)? v: -v; len = 0; do { - buf[len++] = (stix_liw_t)ui; - ui = ui >> STIX_LIW_BITS; + buf[len++] = (moo_liw_t)ui; + ui = ui >> MOO_LIW_BITS; } while (ui > 0); - return stix_instantiate (stix, ((v >= 0)? stix->_large_positive_integer: stix->_large_negative_integer), buf, len); + return moo_instantiate (moo, ((v >= 0)? moo->_large_positive_integer: moo->_large_negative_integer), buf, len); } -stix_oop_t stix_oowtoint (stix_t* stix, stix_oow_t w) +moo_oop_t moo_oowtoint (moo_t* moo, moo_oow_t w) { - STIX_ASSERT (stix, STIX_TYPE_IS_UNSIGNED(stix_oow_t)); - /*if (STIX_IN_SMOOI_RANGE(w))*/ - if (w <= STIX_SMOOI_MAX) + MOO_ASSERT (moo, MOO_TYPE_IS_UNSIGNED(moo_oow_t)); + /*if (MOO_IN_SMOOI_RANGE(w))*/ + if (w <= MOO_SMOOI_MAX) { - return STIX_SMOOI_TO_OOP(w); + return MOO_SMOOI_TO_OOP(w); } else { - return make_bigint_with_oow(stix, w); + return make_bigint_with_oow(moo, w); } } -static STIX_INLINE stix_oop_t expand_bigint (stix_t* stix, stix_oop_t oop, stix_oow_t inc) +static MOO_INLINE moo_oop_t expand_bigint (moo_t* moo, moo_oop_t oop, moo_oow_t inc) { - stix_oop_t z; - stix_oow_t i; - stix_oow_t count; + moo_oop_t z; + moo_oow_t i; + moo_oow_t count; - STIX_ASSERT (stix, STIX_OOP_IS_POINTER(oop)); - count = STIX_OBJ_GET_SIZE(oop); + MOO_ASSERT (moo, MOO_OOP_IS_POINTER(oop)); + count = MOO_OBJ_GET_SIZE(oop); - if (inc > STIX_OBJ_SIZE_MAX - count) + if (inc > MOO_OBJ_SIZE_MAX - count) { - stix->errnum = STIX_EOOMEM; /* TODO: is it a soft failure or a hard failure? is this error code proper? */ - return STIX_NULL; + moo->errnum = MOO_EOOMEM; /* TODO: is it a soft failure or a hard failure? is this error code proper? */ + return MOO_NULL; } - stix_pushtmp (stix, &oop); - z = stix_instantiate (stix, STIX_OBJ_GET_CLASS(oop), STIX_NULL, count + inc); - stix_poptmp (stix); - if (!z) return STIX_NULL; + moo_pushtmp (moo, &oop); + z = moo_instantiate (moo, MOO_OBJ_GET_CLASS(oop), MOO_NULL, count + inc); + moo_poptmp (moo); + if (!z) return MOO_NULL; for (i = 0; i < count; i++) { - ((stix_oop_liword_t)z)->slot[i] = ((stix_oop_liword_t)oop)->slot[i]; + ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)oop)->slot[i]; } return z; } -static STIX_INLINE stix_oop_t _clone_bigint (stix_t* stix, stix_oop_t oop, stix_oow_t count, stix_oop_t _class) +static MOO_INLINE moo_oop_t _clone_bigint (moo_t* moo, moo_oop_t oop, moo_oow_t count, moo_oop_t _class) { - stix_oop_t z; - stix_oow_t i; + moo_oop_t z; + moo_oow_t i; - STIX_ASSERT (stix, STIX_OOP_IS_POINTER(oop)); - if (count <= 0) count = STIX_OBJ_GET_SIZE(oop); + MOO_ASSERT (moo, MOO_OOP_IS_POINTER(oop)); + if (count <= 0) count = MOO_OBJ_GET_SIZE(oop); - stix_pushtmp (stix, &oop); - z = stix_instantiate (stix, _class, STIX_NULL, count); - stix_poptmp (stix); - if (!z) return STIX_NULL; + moo_pushtmp (moo, &oop); + z = moo_instantiate (moo, _class, MOO_NULL, count); + moo_poptmp (moo); + if (!z) return MOO_NULL; for (i = 0; i < count; i++) { - ((stix_oop_liword_t)z)->slot[i] = ((stix_oop_liword_t)oop)->slot[i]; + ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)oop)->slot[i]; } return z; } -static STIX_INLINE stix_oop_t clone_bigint (stix_t* stix, stix_oop_t oop, stix_oow_t count) +static MOO_INLINE moo_oop_t clone_bigint (moo_t* moo, moo_oop_t oop, moo_oow_t count) { - return _clone_bigint (stix, oop, count, STIX_OBJ_GET_CLASS(oop)); + return _clone_bigint (moo, oop, count, MOO_OBJ_GET_CLASS(oop)); } -static STIX_INLINE stix_oop_t clone_bigint_negated (stix_t* stix, stix_oop_t oop, stix_oow_t count) +static MOO_INLINE moo_oop_t clone_bigint_negated (moo_t* moo, moo_oop_t oop, moo_oow_t count) { - stix_oop_t c; + moo_oop_t c; - STIX_ASSERT (stix, STIX_OOP_IS_POINTER(oop)); - if (STIX_OBJ_GET_CLASS(oop) == stix->_large_positive_integer) + MOO_ASSERT (moo, MOO_OOP_IS_POINTER(oop)); + if (MOO_OBJ_GET_CLASS(oop) == moo->_large_positive_integer) { - c = stix->_large_negative_integer; + c = moo->_large_negative_integer; } else { - STIX_ASSERT (stix, STIX_OBJ_GET_CLASS(oop) == stix->_large_negative_integer); - c = stix->_large_positive_integer; + MOO_ASSERT (moo, MOO_OBJ_GET_CLASS(oop) == moo->_large_negative_integer); + c = moo->_large_positive_integer; } - return _clone_bigint (stix, oop, count, c); + return _clone_bigint (moo, oop, count, c); } -static STIX_INLINE stix_oop_t clone_bigint_to_positive (stix_t* stix, stix_oop_t oop, stix_oow_t count) +static MOO_INLINE moo_oop_t clone_bigint_to_positive (moo_t* moo, moo_oop_t oop, moo_oow_t count) { - return _clone_bigint (stix, oop, count, stix->_large_positive_integer); + return _clone_bigint (moo, oop, count, moo->_large_positive_integer); } -static STIX_INLINE stix_oow_t count_effective (stix_liw_t* x, stix_oow_t xs) +static MOO_INLINE moo_oow_t count_effective (moo_liw_t* x, moo_oow_t xs) { #if 0 while (xs > 1 && x[xs - 1] == 0) xs--; @@ -575,88 +575,88 @@ static STIX_INLINE stix_oow_t count_effective (stix_liw_t* x, stix_oow_t xs) #endif } -static STIX_INLINE stix_oow_t count_effective_digits (stix_oop_t oop) +static MOO_INLINE moo_oow_t count_effective_digits (moo_oop_t oop) { - stix_oow_t i; + moo_oow_t i; - for (i = STIX_OBJ_GET_SIZE(oop); i > 1; ) + for (i = MOO_OBJ_GET_SIZE(oop); i > 1; ) { --i; - if (((stix_oop_liword_t)oop)->slot[i]) return i + 1; + if (((moo_oop_liword_t)oop)->slot[i]) return i + 1; } return 1; } -static stix_oop_t normalize_bigint (stix_t* stix, stix_oop_t oop) +static moo_oop_t normalize_bigint (moo_t* moo, moo_oop_t oop) { - stix_oow_t count; + moo_oow_t count; - STIX_ASSERT (stix, STIX_OOP_IS_POINTER(oop)); + MOO_ASSERT (moo, MOO_OOP_IS_POINTER(oop)); count = count_effective_digits (oop); -#if (STIX_LIW_BITS == STIX_OOW_BITS) +#if (MOO_LIW_BITS == MOO_OOW_BITS) if (count == 1) /* 1 word */ { - stix_oow_t w; + moo_oow_t w; - w = ((stix_oop_liword_t)oop)->slot[0]; - if (STIX_OBJ_GET_CLASS(oop) == stix->_large_positive_integer) + w = ((moo_oop_liword_t)oop)->slot[0]; + if (MOO_OBJ_GET_CLASS(oop) == moo->_large_positive_integer) { - if (w <= STIX_SMOOI_MAX) return STIX_SMOOI_TO_OOP(w); + if (w <= MOO_SMOOI_MAX) return MOO_SMOOI_TO_OOP(w); } else { - STIX_ASSERT (stix, -STIX_SMOOI_MAX == STIX_SMOOI_MIN); - STIX_ASSERT (stix, STIX_OBJ_GET_CLASS(oop) == stix->_large_negative_integer); - if (w <= STIX_SMOOI_MAX) return STIX_SMOOI_TO_OOP(-(stix_ooi_t)w); + MOO_ASSERT (moo, -MOO_SMOOI_MAX == MOO_SMOOI_MIN); + MOO_ASSERT (moo, MOO_OBJ_GET_CLASS(oop) == moo->_large_negative_integer); + if (w <= MOO_SMOOI_MAX) return MOO_SMOOI_TO_OOP(-(moo_ooi_t)w); } } -#elif (STIX_LIW_BITS == STIX_OOHW_BITS) +#elif (MOO_LIW_BITS == MOO_OOHW_BITS) if (count == 1) /* 1 half-word */ { - if (STIX_OBJ_GET_CLASS(oop) == stix->_large_positive_integer) + if (MOO_OBJ_GET_CLASS(oop) == moo->_large_positive_integer) { - return STIX_SMOOI_TO_OOP(((stix_oop_liword_t)oop)->slot[0]); + return MOO_SMOOI_TO_OOP(((moo_oop_liword_t)oop)->slot[0]); } else { - STIX_ASSERT (stix, STIX_OBJ_GET_CLASS(oop) == stix->_large_negative_integer); - return STIX_SMOOI_TO_OOP(-(stix_ooi_t)((stix_oop_liword_t)oop)->slot[0]); + MOO_ASSERT (moo, MOO_OBJ_GET_CLASS(oop) == moo->_large_negative_integer); + return MOO_SMOOI_TO_OOP(-(moo_ooi_t)((moo_oop_liword_t)oop)->slot[0]); } } else if (count == 2) /* 2 half-words */ { - stix_oow_t w; + moo_oow_t w; - w = MAKE_WORD (((stix_oop_liword_t)oop)->slot[0], ((stix_oop_liword_t)oop)->slot[1]); - if (STIX_OBJ_GET_CLASS(oop) == stix->_large_positive_integer) + w = MAKE_WORD (((moo_oop_liword_t)oop)->slot[0], ((moo_oop_liword_t)oop)->slot[1]); + if (MOO_OBJ_GET_CLASS(oop) == moo->_large_positive_integer) { - if (w <= STIX_SMOOI_MAX) return STIX_SMOOI_TO_OOP(w); + if (w <= MOO_SMOOI_MAX) return MOO_SMOOI_TO_OOP(w); } else { - STIX_ASSERT (stix, -STIX_SMOOI_MAX == STIX_SMOOI_MIN); - STIX_ASSERT (stix, STIX_OBJ_GET_CLASS(oop) == stix->_large_negative_integer); - if (w <= STIX_SMOOI_MAX) return STIX_SMOOI_TO_OOP(-(stix_ooi_t)w); + MOO_ASSERT (moo, -MOO_SMOOI_MAX == MOO_SMOOI_MIN); + MOO_ASSERT (moo, MOO_OBJ_GET_CLASS(oop) == moo->_large_negative_integer); + if (w <= MOO_SMOOI_MAX) return MOO_SMOOI_TO_OOP(-(moo_ooi_t)w); } } #else # error UNSUPPORTED LIW BIT SIZE #endif - if (STIX_OBJ_GET_SIZE(oop) == count) + if (MOO_OBJ_GET_SIZE(oop) == count) { /* no compaction is needed. return it as it is */ return oop; } - return clone_bigint (stix, oop, count); + return clone_bigint (moo, oop, count); } -static STIX_INLINE int is_less_unsigned_array (const stix_liw_t* x, stix_oow_t xs, const stix_liw_t* y, stix_oow_t ys) +static MOO_INLINE int is_less_unsigned_array (const moo_liw_t* x, moo_oow_t xs, const moo_liw_t* y, moo_oow_t ys) { - stix_oow_t i; + moo_oow_t i; if (xs != ys) return xs < ys; for (i = xs; i > 0; ) @@ -668,21 +668,21 @@ static STIX_INLINE int is_less_unsigned_array (const stix_liw_t* x, stix_oow_t x return 0; } -static STIX_INLINE int is_less_unsigned (stix_oop_t x, stix_oop_t y) +static MOO_INLINE int is_less_unsigned (moo_oop_t x, moo_oop_t y) { return is_less_unsigned_array ( - ((stix_oop_liword_t)x)->slot, STIX_OBJ_GET_SIZE(x), - ((stix_oop_liword_t)y)->slot, STIX_OBJ_GET_SIZE(y)); + ((moo_oop_liword_t)x)->slot, MOO_OBJ_GET_SIZE(x), + ((moo_oop_liword_t)y)->slot, MOO_OBJ_GET_SIZE(y)); } -static STIX_INLINE int is_less (stix_t* stix, stix_oop_t x, stix_oop_t y) +static MOO_INLINE int is_less (moo_t* moo, moo_oop_t x, moo_oop_t y) { - if (STIX_OBJ_GET_CLASS(x) != STIX_OBJ_GET_CLASS(y)) + if (MOO_OBJ_GET_CLASS(x) != MOO_OBJ_GET_CLASS(y)) { - return STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer; + return MOO_OBJ_GET_CLASS(x) == moo->_large_negative_integer; } - if (STIX_OBJ_GET_CLASS(x) == stix->_large_positive_integer) + if (MOO_OBJ_GET_CLASS(x) == moo->_large_positive_integer) { return is_less_unsigned (x, y); } @@ -692,9 +692,9 @@ static STIX_INLINE int is_less (stix_t* stix, stix_oop_t x, stix_oop_t y) } } -static STIX_INLINE int is_greater_unsigned_array (const stix_liw_t* x, stix_oow_t xs, const stix_liw_t* y, stix_oow_t ys) +static MOO_INLINE int is_greater_unsigned_array (const moo_liw_t* x, moo_oow_t xs, const moo_liw_t* y, moo_oow_t ys) { - stix_oow_t i; + moo_oow_t i; if (xs != ys) return xs > ys; for (i = xs; i > 0; ) @@ -706,21 +706,21 @@ static STIX_INLINE int is_greater_unsigned_array (const stix_liw_t* x, stix_oow_ return 0; } -static STIX_INLINE int is_greater_unsigned (stix_oop_t x, stix_oop_t y) +static MOO_INLINE int is_greater_unsigned (moo_oop_t x, moo_oop_t y) { return is_greater_unsigned_array ( - ((stix_oop_liword_t)x)->slot, STIX_OBJ_GET_SIZE(x), - ((stix_oop_liword_t)y)->slot, STIX_OBJ_GET_SIZE(y)); + ((moo_oop_liword_t)x)->slot, MOO_OBJ_GET_SIZE(x), + ((moo_oop_liword_t)y)->slot, MOO_OBJ_GET_SIZE(y)); } -static STIX_INLINE int is_greater (stix_t* stix, stix_oop_t x, stix_oop_t y) +static MOO_INLINE int is_greater (moo_t* moo, moo_oop_t x, moo_oop_t y) { - if (STIX_OBJ_GET_CLASS(x) != STIX_OBJ_GET_CLASS(y)) + if (MOO_OBJ_GET_CLASS(x) != MOO_OBJ_GET_CLASS(y)) { - return STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer; + return MOO_OBJ_GET_CLASS(y) == moo->_large_negative_integer; } - if (STIX_OBJ_GET_CLASS(x) == stix->_large_positive_integer) + if (MOO_OBJ_GET_CLASS(x) == moo->_large_positive_integer) { return is_greater_unsigned (x, y); } @@ -730,27 +730,27 @@ static STIX_INLINE int is_greater (stix_t* stix, stix_oop_t x, stix_oop_t y) } } -static STIX_INLINE int is_equal (stix_t* stix, stix_oop_t x, stix_oop_t y) +static MOO_INLINE int is_equal (moo_t* moo, moo_oop_t x, moo_oop_t y) { /* check if two large integers are equal to each other */ - return STIX_OBJ_GET_CLASS(x) == STIX_OBJ_GET_CLASS(y) && STIX_OBJ_GET_SIZE(x) == STIX_OBJ_GET_SIZE(y) && - STIX_MEMCMP(((stix_oop_liword_t)x)->slot, ((stix_oop_liword_t)y)->slot, STIX_OBJ_GET_SIZE(x) * STIX_SIZEOF(stix_liw_t)) == 0; + return MOO_OBJ_GET_CLASS(x) == MOO_OBJ_GET_CLASS(y) && MOO_OBJ_GET_SIZE(x) == MOO_OBJ_GET_SIZE(y) && + MOO_MEMCMP(((moo_oop_liword_t)x)->slot, ((moo_oop_liword_t)y)->slot, MOO_OBJ_GET_SIZE(x) * MOO_SIZEOF(moo_liw_t)) == 0; } -static void complement2_unsigned_array (stix_t* stix, const stix_liw_t* x, stix_oow_t xs, stix_liw_t* z) +static void complement2_unsigned_array (moo_t* moo, const moo_liw_t* x, moo_oow_t xs, moo_liw_t* z) { - stix_oow_t i; - stix_lidw_t w; - stix_lidw_t carry; + moo_oow_t i; + moo_lidw_t w; + moo_lidw_t carry; /* get 2's complement (~x + 1) */ carry = 1; for (i = 0; i < xs; i++) { - w = (stix_lidw_t)(~x[i]) + carry; - /*w = (stix_lidw_t)(x[i] ^ (~(stix_liw_t)0)) + carry;*/ - carry = w >> STIX_LIW_BITS; + w = (moo_lidw_t)(~x[i]) + carry; + /*w = (moo_lidw_t)(x[i] ^ (~(moo_liw_t)0)) + carry;*/ + carry = w >> MOO_LIW_BITS; z[i] = w; } @@ -762,14 +762,14 @@ static void complement2_unsigned_array (stix_t* stix, const stix_liw_t* x, stix_ * this function is not designed to handle such a case. * in fact, 0 is a small integer and it must not stand a change * to be given to this function */ - STIX_ASSERT (stix, carry == 0); + MOO_ASSERT (moo, carry == 0); } -static STIX_INLINE stix_oow_t add_unsigned_array (const stix_liw_t* x, stix_oow_t xs, const stix_liw_t* y, stix_oow_t ys, stix_liw_t* z) +static MOO_INLINE moo_oow_t add_unsigned_array (const moo_liw_t* x, moo_oow_t xs, const moo_liw_t* y, moo_oow_t ys, moo_liw_t* z) { #if 1 - register stix_oow_t i; - stix_lidw_t w; + register moo_oow_t i; + moo_lidw_t w; if (xs < ys) { @@ -778,25 +778,25 @@ static STIX_INLINE stix_oow_t add_unsigned_array (const stix_liw_t* x, stix_oow_ xs = ys; ys = i; - i = (stix_oow_t)x; + i = (moo_oow_t)x; x = y; - y = (stix_liw_t*)i; + y = (moo_liw_t*)i; } w = 0; i = 0; while (i < ys) { - w += (stix_lidw_t)x[i] + (stix_lidw_t)y[i]; - z[i++] = w & STIX_LBMASK(stix_lidw_t, STIX_LIW_BITS); - w >>= STIX_LIW_BITS; + w += (moo_lidw_t)x[i] + (moo_lidw_t)y[i]; + z[i++] = w & MOO_LBMASK(moo_lidw_t, MOO_LIW_BITS); + w >>= MOO_LIW_BITS; } while (w && i < xs) { w += x[i]; - z[i++] = w & STIX_LBMASK(stix_lidw_t, STIX_LIW_BITS); - w >>= STIX_LIW_BITS; + z[i++] = w & MOO_LBMASK(moo_lidw_t, MOO_LIW_BITS); + w >>= MOO_LIW_BITS; } while (i < xs) @@ -804,13 +804,13 @@ static STIX_INLINE stix_oow_t add_unsigned_array (const stix_liw_t* x, stix_oow_ z[i] = x[i]; i++; } - if (w) z[i++] = w & STIX_LBMASK(stix_lidw_t, STIX_LIW_BITS); + if (w) z[i++] = w & MOO_LBMASK(moo_lidw_t, MOO_LIW_BITS); return i; #else - register stix_oow_t i; - stix_lidw_t w; - stix_liw_t carry = 0; + register moo_oow_t i; + moo_lidw_t w; + moo_liw_t carry = 0; if (xs < ys) { @@ -819,26 +819,26 @@ static STIX_INLINE stix_oow_t add_unsigned_array (const stix_liw_t* x, stix_oow_ xs = ys; ys = i; - i = (stix_oow_t)x; + i = (moo_oow_t)x; x = y; - y = (stix_liw_t*)i; + y = (moo_liw_t*)i; } for (i = 0; i < ys; i++) { - w = (stix_lidw_t)x[i] + (stix_lidw_t)y[i] + carry; - carry = w >> STIX_LIW_BITS; - z[i] = w /*& STIX_LBMASK(stix_lidw_t, STIX_LIW_BITS) */; + w = (moo_lidw_t)x[i] + (moo_lidw_t)y[i] + carry; + carry = w >> MOO_LIW_BITS; + z[i] = w /*& MOO_LBMASK(moo_lidw_t, MOO_LIW_BITS) */; } if (x == z) { for (; carry && i < xs; i++) { - w = (stix_lidw_t)x[i] + carry; - carry = w >> STIX_LIW_BITS; - z[i] = w /*& STIX_LBMASK(stix_lidw_t, STIX_LIW_BITS) */; + w = (moo_lidw_t)x[i] + carry; + carry = w >> MOO_LIW_BITS; + z[i] = w /*& MOO_LBMASK(moo_lidw_t, MOO_LIW_BITS) */; } i = xs; } @@ -846,9 +846,9 @@ static STIX_INLINE stix_oow_t add_unsigned_array (const stix_liw_t* x, stix_oow_ { for (; i < xs; i++) { - w = (stix_lidw_t)x[i] + carry; - carry = w >> STIX_LIW_BITS; - z[i] = w /*& STIX_LBMASK(stix_lidw_t, STIX_LIW_BITS)*/; + w = (moo_lidw_t)x[i] + carry; + carry = w >> MOO_LIW_BITS; + z[i] = w /*& MOO_LBMASK(moo_lidw_t, MOO_LIW_BITS)*/; } } @@ -857,33 +857,33 @@ static STIX_INLINE stix_oow_t add_unsigned_array (const stix_liw_t* x, stix_oow_ #endif } -static STIX_INLINE stix_oow_t subtract_unsigned_array (stix_t* stix, const stix_liw_t* x, stix_oow_t xs, const stix_liw_t* y, stix_oow_t ys, stix_liw_t* z) +static MOO_INLINE moo_oow_t subtract_unsigned_array (moo_t* moo, const moo_liw_t* x, moo_oow_t xs, const moo_liw_t* y, moo_oow_t ys, moo_liw_t* z) { #if 1 - stix_oow_t i; - stix_lidi_t w = 0; + moo_oow_t i; + moo_lidi_t w = 0; if (x == y) { - STIX_ASSERT (stix, xs == ys); + MOO_ASSERT (moo, xs == ys); z[0] = 0; return 1; } - STIX_ASSERT (stix, !is_less_unsigned_array(x, xs, y, ys)); + MOO_ASSERT (moo, !is_less_unsigned_array(x, xs, y, ys)); for (i = 0; i < ys; i++) { - w += (stix_lidi_t)x[i] - (stix_lidi_t)y[i]; - z[i] = w & STIX_LBMASK(stix_lidw_t, STIX_LIW_BITS); - w >>= STIX_LIW_BITS; + w += (moo_lidi_t)x[i] - (moo_lidi_t)y[i]; + z[i] = w & MOO_LBMASK(moo_lidw_t, MOO_LIW_BITS); + w >>= MOO_LIW_BITS; } while (w && i < xs) { w += x[i]; - z[i++] = w & STIX_LBMASK(stix_lidw_t, STIX_LIW_BITS); - w >>= STIX_LIW_BITS; + z[i++] = w & MOO_LBMASK(moo_lidw_t, MOO_LIW_BITS); + w >>= MOO_LIW_BITS; } while (i < xs) @@ -896,32 +896,32 @@ static STIX_INLINE stix_oow_t subtract_unsigned_array (stix_t* stix, const stix_ return i; #else - stix_oow_t i; - stix_lidw_t w; - stix_lidw_t borrow = 0; - stix_lidw_t borrowed_word; + moo_oow_t i; + moo_lidw_t w; + moo_lidw_t borrow = 0; + moo_lidw_t borrowed_word; if (x == y) { - STIX_ASSERT (stix, xs == ys); + MOO_ASSERT (moo, xs == ys); z[0] = 0; return 1; } - STIX_ASSERT (stix, !is_less_unsigned_array(x, xs, y, ys)); + MOO_ASSERT (moo, !is_less_unsigned_array(x, xs, y, ys)); - borrowed_word = (stix_lidw_t)1 << STIX_LIW_BITS; + borrowed_word = (moo_lidw_t)1 << MOO_LIW_BITS; for (i = 0; i < ys; i++) { - w = (stix_lidw_t)y[i] + borrow; - if ((stix_lidw_t)x[i] >= w) + w = (moo_lidw_t)y[i] + borrow; + if ((moo_lidw_t)x[i] >= w) { z[i] = x[i] - w; borrow = 0; } else { - z[i] = (borrowed_word + (stix_lidw_t)x[i]) - w; + z[i] = (borrowed_word + (moo_lidw_t)x[i]) - w; borrow = 1; } } @@ -930,44 +930,44 @@ static STIX_INLINE stix_oow_t subtract_unsigned_array (stix_t* stix, const stix_ { if (x[i] >= borrow) { - z[i] = x[i] - (stix_liw_t)borrow; + z[i] = x[i] - (moo_liw_t)borrow; borrow = 0; } else { - z[i] = (borrowed_word + (stix_lidw_t)x[i]) - borrow; + z[i] = (borrowed_word + (moo_lidw_t)x[i]) - borrow; borrow = 1; } } - STIX_ASSERT (stix, borrow == 0); + MOO_ASSERT (moo, borrow == 0); while (i > 1 && z[i - 1] == 0) i--; return i; /* the number of effective digits in the result */ #endif } -static STIX_INLINE void multiply_unsigned_array (const stix_liw_t* x, stix_oow_t xs, const stix_liw_t* y, stix_oow_t ys, stix_liw_t* z) +static MOO_INLINE void multiply_unsigned_array (const moo_liw_t* x, moo_oow_t xs, const moo_liw_t* y, moo_oow_t ys, moo_liw_t* z) { - stix_lidw_t v; - stix_oow_t pa; + moo_lidw_t v; + moo_oow_t pa; if (xs < ys) { - stix_oow_t i; + moo_oow_t i; /* swap x and y */ i = xs; xs = ys; ys = i; - i = (stix_oow_t)x; + i = (moo_oow_t)x; x = y; - y = (stix_liw_t*)i; + y = (moo_liw_t*)i; } pa = xs; - if (pa <= ((stix_oow_t)1 << (STIX_LIDW_BITS - (STIX_LIW_BITS * 2)))) + if (pa <= ((moo_oow_t)1 << (MOO_LIDW_BITS - (MOO_LIW_BITS * 2)))) { /* Comba(column-array) multiplication */ @@ -976,7 +976,7 @@ static STIX_INLINE void multiply_unsigned_array (const stix_liw_t* x, stix_oow_t * affected badly. so we need to use this method only if * the input is short enough. */ - stix_oow_t pa, ix, iy, iz, tx, ty; + moo_oow_t pa, ix, iy, iz, tx, ty; pa = xs + ys; v = 0; @@ -988,17 +988,17 @@ static STIX_INLINE void multiply_unsigned_array (const stix_liw_t* x, stix_oow_t for (iz = 0; iz < iy; iz++) { - v = v + (stix_lidw_t)x[tx + iz] * (stix_lidw_t)y[ty - iz]; + v = v + (moo_lidw_t)x[tx + iz] * (moo_lidw_t)y[ty - iz]; } - z[ix] = (stix_liw_t)v; - v = v >> STIX_LIW_BITS; + z[ix] = (moo_liw_t)v; + v = v >> MOO_LIW_BITS; } } else { - stix_oow_t i, j; - stix_liw_t carry; + moo_oow_t i, j; + moo_liw_t carry; for (i = 0; i < xs; i++) { @@ -1012,9 +1012,9 @@ static STIX_INLINE void multiply_unsigned_array (const stix_liw_t* x, stix_oow_t for (j = 0; j < ys; j++) { - v = (stix_lidw_t)x[i] * (stix_lidw_t)y[j] + (stix_lidw_t)carry + (stix_lidw_t)z[i + j]; - z[i + j] = (stix_liw_t)v; - carry = (stix_liw_t)(v >> STIX_LIW_BITS); + v = (moo_lidw_t)x[i] * (moo_lidw_t)y[j] + (moo_lidw_t)carry + (moo_lidw_t)z[i + j]; + z[i + j] = (moo_liw_t)v; + carry = (moo_liw_t)(v >> MOO_LIW_BITS); } z[i + j] = carry; @@ -1074,10 +1074,10 @@ static STIX_INLINE void multiply_unsigned_array (const stix_liw_t* x, stix_oow_t * -------------------------------------------------------------------- * * Multiplying by B is t same as shifting by DIGIT_BITS. - * DIGIT_BITS in this implementation is STIX_LIW_BITS - * B => 2^STIX_LIW_BITS - * X * B^n => X << (STIX_LIW_BITS * n) - * X * B^2n => X << (STIX_LIW_BITS * n * 2) + * DIGIT_BITS in this implementation is MOO_LIW_BITS + * B => 2^MOO_LIW_BITS + * X * B^n => X << (MOO_LIW_BITS * n) + * X * B^2n => X << (MOO_LIW_BITS * n * 2) * -------------------------------------------------------------------- */ #define CANNOT_KARATSUBA(xs, ys) \ @@ -1085,34 +1085,34 @@ static STIX_INLINE void multiply_unsigned_array (const stix_liw_t* x, stix_oow_t ((xs) > (ys) && (ys) <= (((xs) + 1) / 2)) || \ ((xs) < (ys) && (xs) <= (((ys) + 1) / 2))) -static STIX_INLINE stix_oow_t multiply_unsigned_array_karatsuba (stix_t* stix, const stix_liw_t* x, stix_oow_t xs, const stix_liw_t* y, stix_oow_t ys, stix_liw_t* z) +static MOO_INLINE moo_oow_t multiply_unsigned_array_karatsuba (moo_t* moo, const moo_liw_t* x, moo_oow_t xs, const moo_liw_t* y, moo_oow_t ys, moo_liw_t* z) { #if 1 - stix_lidw_t nshifts; - stix_lidw_t ndigits_xh, ndigits_xl; - stix_lidw_t ndigits_yh, ndigits_yl; - stix_liw_t* tmp[2] = { STIX_NULL, STIX_NULL}; - stix_liw_t* zsp; - stix_oow_t tmplen[2]; - stix_oow_t xlen, zcapa; + moo_lidw_t nshifts; + moo_lidw_t ndigits_xh, ndigits_xl; + moo_lidw_t ndigits_yh, ndigits_yl; + moo_liw_t* tmp[2] = { MOO_NULL, MOO_NULL}; + moo_liw_t* zsp; + moo_oow_t tmplen[2]; + moo_oow_t xlen, zcapa; zcapa = xs + ys; /* the caller ensures this capacity for z at the minimum*/ if (xs < ys) { - stix_oow_t i; + moo_oow_t i; /* swap x and y */ i = xs; xs = ys; ys = i; - i = (stix_oow_t)x; + i = (moo_oow_t)x; x = y; - y = (stix_liw_t*)i; + y = (moo_liw_t*)i; } - /* calculate value of nshifts, that is 2^(STIX_LIW_BITS*nshifts) */ + /* calculate value of nshifts, that is 2^(MOO_LIW_BITS*nshifts) */ nshifts = (xs + 1) / 2; ndigits_xl = nshifts; /* ndigits of lower part of x */ @@ -1120,19 +1120,19 @@ static STIX_INLINE stix_oow_t multiply_unsigned_array_karatsuba (stix_t* stix, c ndigits_yl = nshifts; /* ndigits of lower part of y */ ndigits_yh = ys - nshifts; /* ndigits of uppoer part of y */ - STIX_ASSERT (stix, ndigits_xl >= ndigits_xh); - STIX_ASSERT (stix, ndigits_yl >= ndigits_yh); + MOO_ASSERT (moo, ndigits_xl >= ndigits_xh); + MOO_ASSERT (moo, ndigits_yl >= ndigits_yh); /* make a temporary buffer for (b0 + b1) and (a1 * b1) */ tmplen[0] = ndigits_xh + ndigits_yh; tmplen[1] = ndigits_yl + ndigits_yh + 1; if (tmplen[1] < tmplen[0]) tmplen[1] = tmplen[0]; - tmp[1] = stix_callocmem (stix, STIX_SIZEOF(stix_liw_t) * tmplen[1]); /* TODO: should i use the object memory? */ + tmp[1] = moo_callocmem (moo, MOO_SIZEOF(moo_liw_t) * tmplen[1]); /* TODO: should i use the object memory? */ if (!tmp[1]) goto oops; /* make a temporary for (a0 + a1) and (a0 * b0) */ tmplen[0] = ndigits_xl + ndigits_yl + 1; - tmp[0] = stix_callocmem (stix, STIX_SIZEOF(stix_liw_t) * tmplen[0]); + tmp[0] = moo_callocmem (moo, MOO_SIZEOF(moo_liw_t) * tmplen[0]); if (!tmp[0]) goto oops; /* tmp[0] = a0 + a1 */ @@ -1141,8 +1141,8 @@ static STIX_INLINE stix_oow_t multiply_unsigned_array_karatsuba (stix_t* stix, c /* tmp[1] = b0 + b1 */ tmplen[1] = add_unsigned_array (y, ndigits_yl, y + nshifts, ndigits_yh, tmp[1]); - /*STIX_DEBUG6 (stix, "karatsuba t %p u %p ndigits_xl %d ndigits_xh %d ndigits_yl %d ndigits_yh %d\n", tmp[0], tmp[1], (int)ndigits_xl, (int)ndigits_xh, (int)ndigits_yl, (int)ndigits_yh);*/ - /*STIX_DEBUG5 (stix, "zcapa %d, tmplen[0] %d tmplen[1] %d nshifts %d total %d\n", (int)zcapa, (int)tmplen[0], (int)tmplen[1], (int)nshifts, (int)(tmplen[0] + tmplen[1] + nshifts));*/ + /*MOO_DEBUG6 (moo, "karatsuba t %p u %p ndigits_xl %d ndigits_xh %d ndigits_yl %d ndigits_yh %d\n", tmp[0], tmp[1], (int)ndigits_xl, (int)ndigits_xh, (int)ndigits_yl, (int)ndigits_yh);*/ + /*MOO_DEBUG5 (moo, "zcapa %d, tmplen[0] %d tmplen[1] %d nshifts %d total %d\n", (int)zcapa, (int)tmplen[0], (int)tmplen[1], (int)nshifts, (int)(tmplen[0] + tmplen[1] + nshifts));*/ /* place (a0 + a1) * (b0 + b1) at the shifted position */ zsp = z + nshifts; @@ -1153,13 +1153,13 @@ static STIX_INLINE stix_oow_t multiply_unsigned_array_karatsuba (stix_t* stix, c } else { - xlen = multiply_unsigned_array_karatsuba(stix, tmp[0], tmplen[0], tmp[1], tmplen[1], zsp); + xlen = multiply_unsigned_array_karatsuba(moo, tmp[0], tmplen[0], tmp[1], tmplen[1], zsp); if (xlen == 0) goto oops; } /* tmp[0] = a0 * b0 */ tmplen[0] = ndigits_xl + ndigits_yl; - STIX_MEMSET (tmp[0], 0, sizeof(stix_liw_t) * tmplen[0]); + MOO_MEMSET (tmp[0], 0, sizeof(moo_liw_t) * tmplen[0]); if (CANNOT_KARATSUBA(ndigits_xl, ndigits_yl)) { multiply_unsigned_array (x, ndigits_xl, y, ndigits_yl, tmp[0]); @@ -1167,13 +1167,13 @@ static STIX_INLINE stix_oow_t multiply_unsigned_array_karatsuba (stix_t* stix, c } else { - tmplen[0] = multiply_unsigned_array_karatsuba (stix, x, ndigits_xl, y, ndigits_yl, tmp[0]); + tmplen[0] = multiply_unsigned_array_karatsuba (moo, x, ndigits_xl, y, ndigits_yl, tmp[0]); if (tmplen[0] <= 0) goto oops; } /* tmp[1] = a1 * b1 */ tmplen[1] = ndigits_xh + ndigits_yh; - STIX_MEMSET (tmp[1], 0, sizeof(stix_liw_t) * tmplen[1]); + MOO_MEMSET (tmp[1], 0, sizeof(moo_liw_t) * tmplen[1]); if (CANNOT_KARATSUBA(ndigits_xh, ndigits_yh)) { multiply_unsigned_array (x + nshifts, ndigits_xh, y + nshifts, ndigits_yh, tmp[1]); @@ -1181,15 +1181,15 @@ static STIX_INLINE stix_oow_t multiply_unsigned_array_karatsuba (stix_t* stix, c } else { - tmplen[1] = multiply_unsigned_array_karatsuba (stix, x + nshifts, ndigits_xh, y + nshifts, ndigits_yh, tmp[1]); + tmplen[1] = multiply_unsigned_array_karatsuba (moo, x + nshifts, ndigits_xh, y + nshifts, ndigits_yh, tmp[1]); if (tmplen[1] <= 0) goto oops; } /* (a0+a1)*(b0+b1) -(a0*b0) */ - xlen = subtract_unsigned_array(stix, zsp, xlen, tmp[0], tmplen[0], zsp); + xlen = subtract_unsigned_array(moo, zsp, xlen, tmp[0], tmplen[0], zsp); /* (a0+a1)*(b0+b1) - (a0*b0) - (a1*b1) */ - xlen = subtract_unsigned_array(stix, zsp, xlen, tmp[1], tmplen[1], zsp); + xlen = subtract_unsigned_array(moo, zsp, xlen, tmp[1], tmplen[1], zsp); /* a1b1 is in tmp[1]. add (a1b1 * B^2n) to the high part of 'z' */ zsp = z + (nshifts * 2); /* emulate shifting for "* B^2n". */ xlen = zcapa - (nshifts * 2); @@ -1198,41 +1198,41 @@ static STIX_INLINE stix_oow_t multiply_unsigned_array_karatsuba (stix_t* stix, c /* z = z + a0b0. a0b0 is in tmp[0] */ xlen = add_unsigned_array(z, zcapa, tmp[0], tmplen[0], z); - stix_freemem (stix, tmp[1]); - stix_freemem (stix, tmp[0]); + moo_freemem (moo, tmp[1]); + moo_freemem (moo, tmp[0]); return count_effective (z, xlen); oops: - if (tmp[1]) stix_freemem (stix, tmp[1]); - if (tmp[0]) stix_freemem (stix, tmp[0]); + if (tmp[1]) moo_freemem (moo, tmp[1]); + if (tmp[0]) moo_freemem (moo, tmp[0]); return 0; #else - stix_lidw_t nshifts; - stix_lidw_t ndigits_xh, ndigits_xl; - stix_lidw_t ndigits_yh, ndigits_yl; - stix_liw_t* tmp[3] = { STIX_NULL, STIX_NULL, STIX_NULL }; - stix_liw_t* zsp; - stix_oow_t tmplen[3]; - stix_oow_t xlen, zcapa; + moo_lidw_t nshifts; + moo_lidw_t ndigits_xh, ndigits_xl; + moo_lidw_t ndigits_yh, ndigits_yl; + moo_liw_t* tmp[3] = { MOO_NULL, MOO_NULL, MOO_NULL }; + moo_liw_t* zsp; + moo_oow_t tmplen[3]; + moo_oow_t xlen, zcapa; zcapa = xs + ys; /* the caller ensures this capacity for z at the minimum*/ if (xs < ys) { - stix_oow_t i; + moo_oow_t i; /* swap x and y */ i = xs; xs = ys; ys = i; - i = (stix_oow_t)x; + i = (moo_oow_t)x; x = y; - y = (stix_liw_t*)i; + y = (moo_liw_t*)i; } - /* calculate value of nshifts, that is 2^(STIX_LIW_BITS*nshifts) */ + /* calculate value of nshifts, that is 2^(MOO_LIW_BITS*nshifts) */ nshifts = (xs + 1) / 2; ndigits_xl = nshifts; /* ndigits of lower part of x */ @@ -1240,19 +1240,19 @@ oops: ndigits_yl = nshifts; /* ndigits of lower part of y */ ndigits_yh = ys - nshifts; /* ndigits of uppoer part of y */ - STIX_ASSERT (stix, ndigits_xl >= ndigits_xh); - STIX_ASSERT (stix, ndigits_yl >= ndigits_yh); + MOO_ASSERT (moo, ndigits_xl >= ndigits_xh); + MOO_ASSERT (moo, ndigits_yl >= ndigits_yh); /* make a temporary buffer for (b0 + b1) and (a1 * b1) */ tmplen[0] = ndigits_yl + ndigits_yh + 1; tmplen[1] = ndigits_xh + ndigits_yh; if (tmplen[1] < tmplen[0]) tmplen[1] = tmplen[0]; - tmp[1] = stix_callocmem (stix, STIX_SIZEOF(stix_liw_t) * tmplen[1]); + tmp[1] = moo_callocmem (moo, MOO_SIZEOF(moo_liw_t) * tmplen[1]); if (!tmp[1]) goto oops; /* make a temporary for (a0 + a1) and (a0 * b0) */ tmplen[0] = ndigits_xl + ndigits_yl; - tmp[0] = stix_callocmem (stix, STIX_SIZEOF(stix_liw_t) * tmplen[0]); + tmp[0] = moo_callocmem (moo, MOO_SIZEOF(moo_liw_t) * tmplen[0]); if (!tmp[0]) goto oops; /* tmp[0] = a0 + a1 */ @@ -1263,7 +1263,7 @@ oops: /* tmp[2] = (a0 + a1) * (b0 + b1) */ tmplen[2] = tmplen[0] + tmplen[1]; - tmp[2] = stix_callocmem (stix, STIX_SIZEOF(stix_liw_t) * tmplen[2]); + tmp[2] = moo_callocmem (moo, MOO_SIZEOF(moo_liw_t) * tmplen[2]); if (!tmp[2]) goto oops; if (CANNOT_KARATSUBA(tmplen[0], tmplen[1])) { @@ -1272,13 +1272,13 @@ oops: } else { - xlen = multiply_unsigned_array_karatsuba(stix, tmp[0], tmplen[0], tmp[1], tmplen[1], tmp[2]); + xlen = multiply_unsigned_array_karatsuba(moo, tmp[0], tmplen[0], tmp[1], tmplen[1], tmp[2]); if (xlen == 0) goto oops; } /* tmp[0] = a0 * b0 */ tmplen[0] = ndigits_xl + ndigits_yl; - STIX_MEMSET (tmp[0], 0, sizeof(stix_liw_t) * tmplen[0]); + MOO_MEMSET (tmp[0], 0, sizeof(moo_liw_t) * tmplen[0]); if (CANNOT_KARATSUBA(ndigits_xl, ndigits_yl)) { multiply_unsigned_array (x, ndigits_xl, y, ndigits_yl, tmp[0]); @@ -1286,13 +1286,13 @@ oops: } else { - tmplen[0] = multiply_unsigned_array_karatsuba (stix, x, ndigits_xl, y, ndigits_yl, tmp[0]); + tmplen[0] = multiply_unsigned_array_karatsuba (moo, x, ndigits_xl, y, ndigits_yl, tmp[0]); if (tmplen[0] <= 0) goto oops; } /* tmp[1] = a1 * b1 */ tmplen[1] = ndigits_xh + ndigits_yh; - STIX_MEMSET (tmp[1], 0, sizeof(stix_liw_t) * tmplen[1]); + MOO_MEMSET (tmp[1], 0, sizeof(moo_liw_t) * tmplen[1]); if (CANNOT_KARATSUBA(ndigits_xh, ndigits_yh)) { multiply_unsigned_array (x + nshifts, ndigits_xh, y + nshifts, ndigits_yh, tmp[1]); @@ -1300,16 +1300,16 @@ oops: } else { - tmplen[1] = multiply_unsigned_array_karatsuba (stix, x + nshifts, ndigits_xh, y + nshifts, ndigits_yh, tmp[1]); + tmplen[1] = multiply_unsigned_array_karatsuba (moo, x + nshifts, ndigits_xh, y + nshifts, ndigits_yh, tmp[1]); if (tmplen[1] <= 0) goto oops; } /* w = w - tmp[0] */ - xlen = subtract_unsigned_array(stix, tmp[2], xlen, tmp[0], tmplen[0], tmp[2]); + xlen = subtract_unsigned_array(moo, tmp[2], xlen, tmp[0], tmplen[0], tmp[2]); /* r = w - tmp[1] */ zsp = z + nshifts; /* emulate shifting for "* B^n" */ - xlen = subtract_unsigned_array(stix, tmp[2], xlen, tmp[1], tmplen[1], zsp); + xlen = subtract_unsigned_array(moo, tmp[2], xlen, tmp[1], tmplen[1], zsp); /* a1b1 is in tmp[1]. add (a1b1 * B^2n) to the high part of 'z' */ zsp = z + (nshifts * 2); /* emulate shifting for "* B^2n". */ @@ -1319,39 +1319,39 @@ oops: /* z = z + a0b0. a0b0 is in tmp[0] */ xlen = add_unsigned_array(z, zcapa, tmp[0], tmplen[0], z); - stix_freemem (stix, tmp[2]); - stix_freemem (stix, tmp[1]); - stix_freemem (stix, tmp[0]); + moo_freemem (moo, tmp[2]); + moo_freemem (moo, tmp[1]); + moo_freemem (moo, tmp[0]); return count_effective (z, xlen); oops: - if (tmp[2]) stix_freemem (stix, tmp[2]); - if (tmp[1]) stix_freemem (stix, tmp[1]); - if (tmp[0]) stix_freemem (stix, tmp[0]); + if (tmp[2]) moo_freemem (moo, tmp[2]); + if (tmp[1]) moo_freemem (moo, tmp[1]); + if (tmp[0]) moo_freemem (moo, tmp[0]); return 0; #endif } -static STIX_INLINE void lshift_unsigned_array (stix_liw_t* x, stix_oow_t xs, stix_oow_t bits) +static MOO_INLINE void lshift_unsigned_array (moo_liw_t* x, moo_oow_t xs, moo_oow_t bits) { /* this function doesn't grow/shrink the array. Shifting is performed * over the given array */ - stix_oow_t word_shifts, bit_shifts, bit_shifts_right; - stix_oow_t si, di; + moo_oow_t word_shifts, bit_shifts, bit_shifts_right; + moo_oow_t si, di; /* get how many words to shift */ - word_shifts = bits / STIX_LIW_BITS; + word_shifts = bits / MOO_LIW_BITS; if (word_shifts >= xs) { - STIX_MEMSET (x, 0, xs * STIX_SIZEOF(stix_liw_t)); + MOO_MEMSET (x, 0, xs * MOO_SIZEOF(moo_liw_t)); return; } /* get how many remaining bits to shift */ - bit_shifts = bits % STIX_LIW_BITS; - bit_shifts_right = STIX_LIW_BITS - bit_shifts; + bit_shifts = bits % MOO_LIW_BITS; + bit_shifts_right = MOO_LIW_BITS - bit_shifts; /* shift words and bits */ di = xs - 1; @@ -1365,28 +1365,28 @@ static STIX_INLINE void lshift_unsigned_array (stix_liw_t* x, stix_oow_t xs, sti /* fill the remaining part with zeros */ if (word_shifts > 0) - STIX_MEMSET (x, 0, word_shifts * STIX_SIZEOF(stix_liw_t)); + MOO_MEMSET (x, 0, word_shifts * MOO_SIZEOF(moo_liw_t)); } -static STIX_INLINE void rshift_unsigned_array (stix_liw_t* x, stix_oow_t xs, stix_oow_t bits) +static MOO_INLINE void rshift_unsigned_array (moo_liw_t* x, moo_oow_t xs, moo_oow_t bits) { /* this function doesn't grow/shrink the array. Shifting is performed * over the given array */ - stix_oow_t word_shifts, bit_shifts, bit_shifts_left; - stix_oow_t si, di, bound; + moo_oow_t word_shifts, bit_shifts, bit_shifts_left; + moo_oow_t si, di, bound; /* get how many words to shift */ - word_shifts = bits / STIX_LIW_BITS; + word_shifts = bits / MOO_LIW_BITS; if (word_shifts >= xs) { - STIX_MEMSET (x, 0, xs * STIX_SIZEOF(stix_liw_t)); + MOO_MEMSET (x, 0, xs * MOO_SIZEOF(moo_liw_t)); return; } /* get how many remaining bits to shift */ - bit_shifts = bits % STIX_LIW_BITS; - bit_shifts_left = STIX_LIW_BITS - bit_shifts; + bit_shifts = bits % MOO_LIW_BITS; + bit_shifts_left = MOO_LIW_BITS - bit_shifts; /* TODO: verify this function */ /* shift words and bits */ @@ -1402,10 +1402,10 @@ static STIX_INLINE void rshift_unsigned_array (stix_liw_t* x, stix_oow_t xs, sti /* fill the remaining part with zeros */ if (word_shifts > 0) - STIX_MEMSET (&x[xs - word_shifts], 0, word_shifts * STIX_SIZEOF(stix_liw_t)); + MOO_MEMSET (&x[xs - word_shifts], 0, word_shifts * MOO_SIZEOF(moo_liw_t)); } -static void divide_unsigned_array (stix_t* stix, const stix_liw_t* x, stix_oow_t xs, const stix_liw_t* y, stix_oow_t ys, stix_liw_t* q, stix_liw_t* r) +static void divide_unsigned_array (moo_t* moo, const moo_liw_t* x, moo_oow_t xs, const moo_liw_t* y, moo_oow_t ys, moo_liw_t* q, moo_liw_t* r) { /* TODO: this function needs to be rewritten for performance improvement. * the binary long division is extremely slow for a big number */ @@ -1425,220 +1425,220 @@ static void divide_unsigned_array (stix_t* stix, const stix_liw_t* x, stix_oow_t * end */ - stix_oow_t rs, i , j; + moo_oow_t rs, i , j; - STIX_ASSERT (stix, xs >= ys); - STIX_MEMSET (q, 0, STIX_SIZEOF(*q) * xs); - STIX_MEMSET (r, 0, STIX_SIZEOF(*q) * xs); + MOO_ASSERT (moo, xs >= ys); + MOO_MEMSET (q, 0, MOO_SIZEOF(*q) * xs); + MOO_MEMSET (r, 0, MOO_SIZEOF(*q) * xs); for (i = xs; i > 0; ) { --i; - for (j = STIX_LIW_BITS; j > 0;) + for (j = MOO_LIW_BITS; j > 0;) { --j; lshift_unsigned_array (r, xs, 1); - STIX_SETBITS (stix_liw_t, r[0], 0, 1, STIX_GETBITS(stix_liw_t, x[i], j, 1)); + MOO_SETBITS (moo_liw_t, r[0], 0, 1, MOO_GETBITS(moo_liw_t, x[i], j, 1)); rs = count_effective (r, xs); if (!is_less_unsigned_array (r, rs, y, ys)) { - subtract_unsigned_array (stix, r, rs, y, ys, r); - STIX_SETBITS (stix_liw_t, q[i], j, 1, 1); + subtract_unsigned_array (moo, r, rs, y, ys, r); + MOO_SETBITS (moo_liw_t, q[i], j, 1, 1); } } } } -static stix_oop_t add_unsigned_integers (stix_t* stix, stix_oop_t x, stix_oop_t y) +static moo_oop_t add_unsigned_integers (moo_t* moo, moo_oop_t x, moo_oop_t y) { - stix_oow_t as, bs, zs; - stix_oop_t z; + moo_oow_t as, bs, zs; + moo_oop_t z; - as = STIX_OBJ_GET_SIZE(x); - bs = STIX_OBJ_GET_SIZE(y); + as = MOO_OBJ_GET_SIZE(x); + bs = MOO_OBJ_GET_SIZE(y); zs = (as >= bs? as: bs); - if (zs >= STIX_OBJ_SIZE_MAX) + if (zs >= MOO_OBJ_SIZE_MAX) { - stix->errnum = STIX_EOOMEM; /* TOOD: is it a soft failure or hard failure? */ - return STIX_NULL; + moo->errnum = MOO_EOOMEM; /* TOOD: is it a soft failure or hard failure? */ + return MOO_NULL; } zs++; - stix_pushtmp (stix, &x); - stix_pushtmp (stix, &y); - z = stix_instantiate (stix, STIX_OBJ_GET_CLASS(x), STIX_NULL, zs); - stix_poptmps (stix, 2); - if (!z) return STIX_NULL; + moo_pushtmp (moo, &x); + moo_pushtmp (moo, &y); + z = moo_instantiate (moo, MOO_OBJ_GET_CLASS(x), MOO_NULL, zs); + moo_poptmps (moo, 2); + if (!z) return MOO_NULL; add_unsigned_array ( - ((stix_oop_liword_t)x)->slot, as, - ((stix_oop_liword_t)y)->slot, bs, - ((stix_oop_liword_t)z)->slot + ((moo_oop_liword_t)x)->slot, as, + ((moo_oop_liword_t)y)->slot, bs, + ((moo_oop_liword_t)z)->slot ); return z; } -static stix_oop_t subtract_unsigned_integers (stix_t* stix, stix_oop_t x, stix_oop_t y) +static moo_oop_t subtract_unsigned_integers (moo_t* moo, moo_oop_t x, moo_oop_t y) { - stix_oop_t z; + moo_oop_t z; - STIX_ASSERT (stix, !is_less_unsigned(x, y)); + MOO_ASSERT (moo, !is_less_unsigned(x, y)); - stix_pushtmp (stix, &x); - stix_pushtmp (stix, &y); - z = stix_instantiate (stix, stix->_large_positive_integer, STIX_NULL, STIX_OBJ_GET_SIZE(x)); - stix_poptmps (stix, 2); - if (!z) return STIX_NULL; + moo_pushtmp (moo, &x); + moo_pushtmp (moo, &y); + z = moo_instantiate (moo, moo->_large_positive_integer, MOO_NULL, MOO_OBJ_GET_SIZE(x)); + moo_poptmps (moo, 2); + if (!z) return MOO_NULL; - subtract_unsigned_array (stix, - ((stix_oop_liword_t)x)->slot, STIX_OBJ_GET_SIZE(x), - ((stix_oop_liword_t)y)->slot, STIX_OBJ_GET_SIZE(y), - ((stix_oop_liword_t)z)->slot); + subtract_unsigned_array (moo, + ((moo_oop_liword_t)x)->slot, MOO_OBJ_GET_SIZE(x), + ((moo_oop_liword_t)y)->slot, MOO_OBJ_GET_SIZE(y), + ((moo_oop_liword_t)z)->slot); return z; } -static stix_oop_t multiply_unsigned_integers (stix_t* stix, stix_oop_t x, stix_oop_t y) +static moo_oop_t multiply_unsigned_integers (moo_t* moo, moo_oop_t x, moo_oop_t y) { - stix_oop_t z; - stix_oow_t xs, ys; + moo_oop_t z; + moo_oow_t xs, ys; - xs = STIX_OBJ_GET_SIZE(x); - ys = STIX_OBJ_GET_SIZE(y); + xs = MOO_OBJ_GET_SIZE(x); + ys = MOO_OBJ_GET_SIZE(y); - if (ys > STIX_OBJ_SIZE_MAX - xs) + if (ys > MOO_OBJ_SIZE_MAX - xs) { - stix->errnum = STIX_EOOMEM; /* TOOD: is it a soft failure or hard failure? */ - return STIX_NULL; + moo->errnum = MOO_EOOMEM; /* TOOD: is it a soft failure or hard failure? */ + return MOO_NULL; } - stix_pushtmp (stix, &x); - stix_pushtmp (stix, &y); - z = stix_instantiate (stix, stix->_large_positive_integer, STIX_NULL, xs + ys); - stix_poptmps (stix, 2); - if (!z) return STIX_NULL; + moo_pushtmp (moo, &x); + moo_pushtmp (moo, &y); + z = moo_instantiate (moo, moo->_large_positive_integer, MOO_NULL, xs + ys); + moo_poptmps (moo, 2); + if (!z) return MOO_NULL; #if defined(ENABLE_KARATSUBA) if (CANNOT_KARATSUBA (xs, ys)) { #endif multiply_unsigned_array ( - ((stix_oop_liword_t)x)->slot, STIX_OBJ_GET_SIZE(x), - ((stix_oop_liword_t)y)->slot, STIX_OBJ_GET_SIZE(y), - ((stix_oop_liword_t)z)->slot); + ((moo_oop_liword_t)x)->slot, MOO_OBJ_GET_SIZE(x), + ((moo_oop_liword_t)y)->slot, MOO_OBJ_GET_SIZE(y), + ((moo_oop_liword_t)z)->slot); #if defined(ENABLE_KARATSUBA) } else { if (multiply_unsigned_array_karatsuba ( - stix, - ((stix_oop_liword_t)x)->slot, STIX_OBJ_GET_SIZE(x), - ((stix_oop_liword_t)y)->slot, STIX_OBJ_GET_SIZE(y), - ((stix_oop_liword_t)z)->slot) == 0) return STIX_NULL; + moo, + ((moo_oop_liword_t)x)->slot, MOO_OBJ_GET_SIZE(x), + ((moo_oop_liword_t)y)->slot, MOO_OBJ_GET_SIZE(y), + ((moo_oop_liword_t)z)->slot) == 0) return MOO_NULL; } #endif return z; } -static stix_oop_t divide_unsigned_integers (stix_t* stix, stix_oop_t x, stix_oop_t y, stix_oop_t* r) +static moo_oop_t divide_unsigned_integers (moo_t* moo, moo_oop_t x, moo_oop_t y, moo_oop_t* r) { - stix_oop_t qq, rr; + moo_oop_t qq, rr; /* the caller must ensure that x >= y */ - STIX_ASSERT (stix, !is_less_unsigned (x, y)); - stix_pushtmp (stix, &x); - stix_pushtmp (stix, &y); - qq = stix_instantiate (stix, stix->_large_positive_integer, STIX_NULL, STIX_OBJ_GET_SIZE(x)); + MOO_ASSERT (moo, !is_less_unsigned (x, y)); + moo_pushtmp (moo, &x); + moo_pushtmp (moo, &y); + qq = moo_instantiate (moo, moo->_large_positive_integer, MOO_NULL, MOO_OBJ_GET_SIZE(x)); if (!qq) { - stix_poptmps (stix, 2); - return STIX_NULL; + moo_poptmps (moo, 2); + return MOO_NULL; } - stix_pushtmp (stix, &qq); - rr = stix_instantiate (stix, stix->_large_positive_integer, STIX_NULL, STIX_OBJ_GET_SIZE(x)); - stix_poptmps (stix, 3); - if (!rr) return STIX_NULL; + moo_pushtmp (moo, &qq); + rr = moo_instantiate (moo, moo->_large_positive_integer, MOO_NULL, MOO_OBJ_GET_SIZE(x)); + moo_poptmps (moo, 3); + if (!rr) return MOO_NULL; - divide_unsigned_array (stix, - ((stix_oop_liword_t)x)->slot, STIX_OBJ_GET_SIZE(x), - ((stix_oop_liword_t)y)->slot, STIX_OBJ_GET_SIZE(y), - ((stix_oop_liword_t)qq)->slot, ((stix_oop_liword_t)rr)->slot); + divide_unsigned_array (moo, + ((moo_oop_liword_t)x)->slot, MOO_OBJ_GET_SIZE(x), + ((moo_oop_liword_t)y)->slot, MOO_OBJ_GET_SIZE(y), + ((moo_oop_liword_t)qq)->slot, ((moo_oop_liword_t)rr)->slot); *r = rr; return qq; } -stix_oop_t stix_addints (stix_t* stix, stix_oop_t x, stix_oop_t y) +moo_oop_t moo_addints (moo_t* moo, moo_oop_t x, moo_oop_t y) { - stix_oop_t z; + moo_oop_t z; - if (STIX_OOP_IS_SMOOI(x) && STIX_OOP_IS_SMOOI(y)) + if (MOO_OOP_IS_SMOOI(x) && MOO_OOP_IS_SMOOI(y)) { - stix_ooi_t i; + moo_ooi_t i; /* no integer overflow/underflow must occur as the possible integer * range is narrowed by the tag bits used */ - STIX_ASSERT (stix, STIX_SMOOI_MAX + STIX_SMOOI_MAX < STIX_TYPE_MAX(stix_ooi_t)); - STIX_ASSERT (stix, STIX_SMOOI_MIN + STIX_SMOOI_MIN > STIX_TYPE_MIN(stix_ooi_t)); + MOO_ASSERT (moo, MOO_SMOOI_MAX + MOO_SMOOI_MAX < MOO_TYPE_MAX(moo_ooi_t)); + MOO_ASSERT (moo, MOO_SMOOI_MIN + MOO_SMOOI_MIN > MOO_TYPE_MIN(moo_ooi_t)); - i = STIX_OOP_TO_SMOOI(x) + STIX_OOP_TO_SMOOI(y); - if (STIX_IN_SMOOI_RANGE(i)) return STIX_SMOOI_TO_OOP(i); + i = MOO_OOP_TO_SMOOI(x) + MOO_OOP_TO_SMOOI(y); + if (MOO_IN_SMOOI_RANGE(i)) return MOO_SMOOI_TO_OOP(i); - return make_bigint_with_ooi (stix, i); + return make_bigint_with_ooi (moo, i); } else { - stix_ooi_t v; + moo_ooi_t v; - if (STIX_OOP_IS_SMOOI(x)) + if (MOO_OOP_IS_SMOOI(x)) { - if (!is_bigint(stix,y)) goto oops_einval; + if (!is_bigint(moo,y)) goto oops_einval; - v = STIX_OOP_TO_SMOOI(x); - if (v == 0) return clone_bigint (stix, y, STIX_OBJ_GET_SIZE(y)); + v = MOO_OOP_TO_SMOOI(x); + if (v == 0) return clone_bigint (moo, y, MOO_OBJ_GET_SIZE(y)); - stix_pushtmp (stix, &y); - x = make_bigint_with_ooi (stix, v); - stix_poptmp (stix); - if (!x) return STIX_NULL; + moo_pushtmp (moo, &y); + x = make_bigint_with_ooi (moo, v); + moo_poptmp (moo); + if (!x) return MOO_NULL; } - else if (STIX_OOP_IS_SMOOI(y)) + else if (MOO_OOP_IS_SMOOI(y)) { - if (!is_bigint(stix,x)) goto oops_einval; + if (!is_bigint(moo,x)) goto oops_einval; - v = STIX_OOP_TO_SMOOI(y); - if (v == 0) return clone_bigint (stix, x, STIX_OBJ_GET_SIZE(x)); + v = MOO_OOP_TO_SMOOI(y); + if (v == 0) return clone_bigint (moo, x, MOO_OBJ_GET_SIZE(x)); - stix_pushtmp (stix, &x); - y = make_bigint_with_ooi (stix, v); - stix_poptmp (stix); - if (!y) return STIX_NULL; + moo_pushtmp (moo, &x); + y = make_bigint_with_ooi (moo, v); + moo_poptmp (moo); + if (!y) return MOO_NULL; } else { - if (!is_bigint(stix,x)) goto oops_einval; - if (!is_bigint(stix,y)) goto oops_einval; + if (!is_bigint(moo,x)) goto oops_einval; + if (!is_bigint(moo,y)) goto oops_einval; } - if (STIX_OBJ_GET_CLASS(x) != STIX_OBJ_GET_CLASS(y)) + if (MOO_OBJ_GET_CLASS(x) != MOO_OBJ_GET_CLASS(y)) { - if (STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer) + if (MOO_OBJ_GET_CLASS(x) == moo->_large_negative_integer) { /* x is negative, y is positive */ if (is_less_unsigned (x, y)) { - z = subtract_unsigned_integers (stix, y, x); - if (!z) return STIX_NULL; + z = subtract_unsigned_integers (moo, y, x); + if (!z) return MOO_NULL; } else { - z = subtract_unsigned_integers (stix, x, y); - if (!z) return STIX_NULL; - STIX_OBJ_SET_CLASS(z, stix->_large_negative_integer); + z = subtract_unsigned_integers (moo, x, y); + if (!z) return MOO_NULL; + MOO_OBJ_SET_CLASS(z, moo->_large_negative_integer); } } else @@ -1646,14 +1646,14 @@ stix_oop_t stix_addints (stix_t* stix, stix_oop_t x, stix_oop_t y) /* x is positive, y is negative */ if (is_less_unsigned (x, y)) { - z = subtract_unsigned_integers (stix, y, x); - if (!z) return STIX_NULL; - STIX_OBJ_SET_CLASS(z, stix->_large_negative_integer); + z = subtract_unsigned_integers (moo, y, x); + if (!z) return MOO_NULL; + MOO_OBJ_SET_CLASS(z, moo->_large_negative_integer); } else { - z = subtract_unsigned_integers (stix, x, y); - if (!z) return STIX_NULL; + z = subtract_unsigned_integers (moo, x, y); + if (!z) return MOO_NULL; } } } @@ -1661,237 +1661,237 @@ stix_oop_t stix_addints (stix_t* stix, stix_oop_t x, stix_oop_t y) { int neg; /* both are positive or negative */ - neg = (STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer); - z = add_unsigned_integers (stix, x, y); - if (!z) return STIX_NULL; - if (neg) STIX_OBJ_SET_CLASS(z, stix->_large_negative_integer); + neg = (MOO_OBJ_GET_CLASS(x) == moo->_large_negative_integer); + z = add_unsigned_integers (moo, x, y); + if (!z) return MOO_NULL; + if (neg) MOO_OBJ_SET_CLASS(z, moo->_large_negative_integer); } } - return normalize_bigint (stix, z); + return normalize_bigint (moo, z); oops_einval: - stix->errnum = STIX_EINVAL; - return STIX_NULL; + moo->errnum = MOO_EINVAL; + return MOO_NULL; } -stix_oop_t stix_subints (stix_t* stix, stix_oop_t x, stix_oop_t y) +moo_oop_t moo_subints (moo_t* moo, moo_oop_t x, moo_oop_t y) { - stix_oop_t z; + moo_oop_t z; - if (STIX_OOP_IS_SMOOI(x) && STIX_OOP_IS_SMOOI(y)) + if (MOO_OOP_IS_SMOOI(x) && MOO_OOP_IS_SMOOI(y)) { - stix_ooi_t i; + moo_ooi_t i; /* no integer overflow/underflow must occur as the possible integer * range is narrowed by the tag bits used */ - STIX_ASSERT (stix, STIX_SMOOI_MAX - STIX_SMOOI_MIN < STIX_TYPE_MAX(stix_ooi_t)); - STIX_ASSERT (stix, STIX_SMOOI_MIN - STIX_SMOOI_MAX > STIX_TYPE_MIN(stix_ooi_t)); + MOO_ASSERT (moo, MOO_SMOOI_MAX - MOO_SMOOI_MIN < MOO_TYPE_MAX(moo_ooi_t)); + MOO_ASSERT (moo, MOO_SMOOI_MIN - MOO_SMOOI_MAX > MOO_TYPE_MIN(moo_ooi_t)); - i = STIX_OOP_TO_SMOOI(x) - STIX_OOP_TO_SMOOI(y); - if (STIX_IN_SMOOI_RANGE(i)) return STIX_SMOOI_TO_OOP(i); + i = MOO_OOP_TO_SMOOI(x) - MOO_OOP_TO_SMOOI(y); + if (MOO_IN_SMOOI_RANGE(i)) return MOO_SMOOI_TO_OOP(i); - return make_bigint_with_ooi (stix, i); + return make_bigint_with_ooi (moo, i); } else { - stix_ooi_t v; + moo_ooi_t v; int neg; - if (STIX_OOP_IS_SMOOI(x)) + if (MOO_OOP_IS_SMOOI(x)) { - if (!is_bigint(stix,y)) goto oops_einval; + if (!is_bigint(moo,y)) goto oops_einval; - v = STIX_OOP_TO_SMOOI(x); + v = MOO_OOP_TO_SMOOI(x); if (v == 0) { /* switch the sign to the opposite and return it */ - return clone_bigint_negated (stix, y, STIX_OBJ_GET_SIZE(y)); + return clone_bigint_negated (moo, y, MOO_OBJ_GET_SIZE(y)); } - stix_pushtmp (stix, &y); - x = make_bigint_with_ooi (stix, v); - stix_poptmp (stix); - if (!x) return STIX_NULL; + moo_pushtmp (moo, &y); + x = make_bigint_with_ooi (moo, v); + moo_poptmp (moo); + if (!x) return MOO_NULL; } - else if (STIX_OOP_IS_SMOOI(y)) + else if (MOO_OOP_IS_SMOOI(y)) { - if (!is_bigint(stix,x)) goto oops_einval; + if (!is_bigint(moo,x)) goto oops_einval; - v = STIX_OOP_TO_SMOOI(y); - if (v == 0) return clone_bigint (stix, x, STIX_OBJ_GET_SIZE(x)); + v = MOO_OOP_TO_SMOOI(y); + if (v == 0) return clone_bigint (moo, x, MOO_OBJ_GET_SIZE(x)); - stix_pushtmp (stix, &x); - y = make_bigint_with_ooi (stix, v); - stix_poptmp (stix); - if (!y) return STIX_NULL; + moo_pushtmp (moo, &x); + y = make_bigint_with_ooi (moo, v); + moo_poptmp (moo); + if (!y) return MOO_NULL; } else { - if (!is_bigint(stix,x)) goto oops_einval; - if (!is_bigint(stix,y)) goto oops_einval; + if (!is_bigint(moo,x)) goto oops_einval; + if (!is_bigint(moo,y)) goto oops_einval; } - if (STIX_OBJ_GET_CLASS(x) != STIX_OBJ_GET_CLASS(y)) + if (MOO_OBJ_GET_CLASS(x) != MOO_OBJ_GET_CLASS(y)) { - neg = (STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer); - z = add_unsigned_integers (stix, x, y); - if (!z) return STIX_NULL; - if (neg) STIX_OBJ_SET_CLASS(z, stix->_large_negative_integer); + neg = (MOO_OBJ_GET_CLASS(x) == moo->_large_negative_integer); + z = add_unsigned_integers (moo, x, y); + if (!z) return MOO_NULL; + if (neg) MOO_OBJ_SET_CLASS(z, moo->_large_negative_integer); } else { /* both are positive or negative */ if (is_less_unsigned (x, y)) { - neg = (STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer); - z = subtract_unsigned_integers (stix, y, x); - if (!z) return STIX_NULL; - if (!neg) STIX_OBJ_SET_CLASS(z, stix->_large_negative_integer); + neg = (MOO_OBJ_GET_CLASS(x) == moo->_large_negative_integer); + z = subtract_unsigned_integers (moo, y, x); + if (!z) return MOO_NULL; + if (!neg) MOO_OBJ_SET_CLASS(z, moo->_large_negative_integer); } else { - neg = (STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer); - z = subtract_unsigned_integers (stix, x, y); /* take x's sign */ - if (!z) return STIX_NULL; - if (neg) STIX_OBJ_SET_CLASS(z, stix->_large_negative_integer); + neg = (MOO_OBJ_GET_CLASS(x) == moo->_large_negative_integer); + z = subtract_unsigned_integers (moo, x, y); /* take x's sign */ + if (!z) return MOO_NULL; + if (neg) MOO_OBJ_SET_CLASS(z, moo->_large_negative_integer); } } } - return normalize_bigint (stix, z); + return normalize_bigint (moo, z); oops_einval: - stix->errnum = STIX_EINVAL; - return STIX_NULL; + moo->errnum = MOO_EINVAL; + return MOO_NULL; } -stix_oop_t stix_mulints (stix_t* stix, stix_oop_t x, stix_oop_t y) +moo_oop_t moo_mulints (moo_t* moo, moo_oop_t x, moo_oop_t y) { - stix_oop_t z; + moo_oop_t z; - if (STIX_OOP_IS_SMOOI(x) && STIX_OOP_IS_SMOOI(y)) + if (MOO_OOP_IS_SMOOI(x) && MOO_OOP_IS_SMOOI(y)) { - #if STIX_SIZEOF_INTMAX_T > STIX_SIZEOF_OOI_T - stix_intmax_t i; - i = (stix_intmax_t)STIX_OOP_TO_SMOOI(x) * (stix_intmax_t)STIX_OOP_TO_SMOOI(y); - if (STIX_IN_SMOOI_RANGE(i)) return STIX_SMOOI_TO_OOP((stix_ooi_t)i); - return make_bigint_with_intmax (stix, i); + #if MOO_SIZEOF_INTMAX_T > MOO_SIZEOF_OOI_T + moo_intmax_t i; + i = (moo_intmax_t)MOO_OOP_TO_SMOOI(x) * (moo_intmax_t)MOO_OOP_TO_SMOOI(y); + if (MOO_IN_SMOOI_RANGE(i)) return MOO_SMOOI_TO_OOP((moo_ooi_t)i); + return make_bigint_with_intmax (moo, i); #else - stix_ooi_t i; - stix_ooi_t xv, yv; + moo_ooi_t i; + moo_ooi_t xv, yv; - xv = STIX_OOP_TO_SMOOI(x); - yv = STIX_OOP_TO_SMOOI(y); - if (smooi_mul_overflow (stix, xv, yv, &i)) + xv = MOO_OOP_TO_SMOOI(x); + yv = MOO_OOP_TO_SMOOI(y); + if (smooi_mul_overflow (moo, xv, yv, &i)) { /* overflowed - convert x and y normal objects and carry on */ - /* no need to call stix_pushtmp before creating x because + /* no need to call moo_pushtmp before creating x because * xv and yv contains actual values needed */ - x = make_bigint_with_ooi (stix, xv); - if (!x) return STIX_NULL; + x = make_bigint_with_ooi (moo, xv); + if (!x) return MOO_NULL; - stix_pushtmp (stix, &x); /* protect x made above */ - y = make_bigint_with_ooi (stix, yv); - stix_poptmp (stix); - if (!y) return STIX_NULL; + moo_pushtmp (moo, &x); /* protect x made above */ + y = make_bigint_with_ooi (moo, yv); + moo_poptmp (moo); + if (!y) return MOO_NULL; goto normal; } else { - if (STIX_IN_SMOOI_RANGE(i)) return STIX_SMOOI_TO_OOP(i); - return make_bigint_with_ooi (stix, i); + if (MOO_IN_SMOOI_RANGE(i)) return MOO_SMOOI_TO_OOP(i); + return make_bigint_with_ooi (moo, i); } #endif } else { - stix_ooi_t v; + moo_ooi_t v; - if (STIX_OOP_IS_SMOOI(x)) + if (MOO_OOP_IS_SMOOI(x)) { - if (!is_bigint(stix,y)) goto oops_einval; + if (!is_bigint(moo,y)) goto oops_einval; - v = STIX_OOP_TO_SMOOI(x); + v = MOO_OOP_TO_SMOOI(x); switch (v) { case 0: - return STIX_SMOOI_TO_OOP(0); + return MOO_SMOOI_TO_OOP(0); case 1: - return clone_bigint (stix, y, STIX_OBJ_GET_SIZE(y)); + return clone_bigint (moo, y, MOO_OBJ_GET_SIZE(y)); case -1: - return clone_bigint_negated (stix, y, STIX_OBJ_GET_SIZE(y)); + return clone_bigint_negated (moo, y, MOO_OBJ_GET_SIZE(y)); } - stix_pushtmp (stix, &y); - x = make_bigint_with_ooi (stix, v); - stix_poptmp (stix); - if (!x) return STIX_NULL; + moo_pushtmp (moo, &y); + x = make_bigint_with_ooi (moo, v); + moo_poptmp (moo); + if (!x) return MOO_NULL; } - else if (STIX_OOP_IS_SMOOI(y)) + else if (MOO_OOP_IS_SMOOI(y)) { - if (!is_bigint(stix,x)) goto oops_einval; + if (!is_bigint(moo,x)) goto oops_einval; - v = STIX_OOP_TO_SMOOI(y); + v = MOO_OOP_TO_SMOOI(y); switch (v) { case 0: - return STIX_SMOOI_TO_OOP(0); + return MOO_SMOOI_TO_OOP(0); case 1: - return clone_bigint (stix, x, STIX_OBJ_GET_SIZE(x)); + return clone_bigint (moo, x, MOO_OBJ_GET_SIZE(x)); case -1: - return clone_bigint_negated (stix, x, STIX_OBJ_GET_SIZE(x)); + return clone_bigint_negated (moo, x, MOO_OBJ_GET_SIZE(x)); } - stix_pushtmp (stix, &x); - y = make_bigint_with_ooi (stix, v); - stix_poptmp (stix); - if (!y) return STIX_NULL; + moo_pushtmp (moo, &x); + y = make_bigint_with_ooi (moo, v); + moo_poptmp (moo); + if (!y) return MOO_NULL; } else { - if (!is_bigint(stix,x)) goto oops_einval; - if (!is_bigint(stix,y)) goto oops_einval; + if (!is_bigint(moo,x)) goto oops_einval; + if (!is_bigint(moo,y)) goto oops_einval; } normal: - z = multiply_unsigned_integers (stix, x, y); - if (!z) return STIX_NULL; - if (STIX_OBJ_GET_CLASS(x) != STIX_OBJ_GET_CLASS(y)) - STIX_OBJ_SET_CLASS(z, stix->_large_negative_integer); + z = multiply_unsigned_integers (moo, x, y); + if (!z) return MOO_NULL; + if (MOO_OBJ_GET_CLASS(x) != MOO_OBJ_GET_CLASS(y)) + MOO_OBJ_SET_CLASS(z, moo->_large_negative_integer); } - return normalize_bigint (stix, z); + return normalize_bigint (moo, z); oops_einval: - stix->errnum = STIX_EINVAL; - return STIX_NULL; + moo->errnum = MOO_EINVAL; + return MOO_NULL; } -stix_oop_t stix_divints (stix_t* stix, stix_oop_t x, stix_oop_t y, int modulo, stix_oop_t* rem) +moo_oop_t moo_divints (moo_t* moo, moo_oop_t x, moo_oop_t y, int modulo, moo_oop_t* rem) { - stix_oop_t z, r; + moo_oop_t z, r; int x_neg, y_neg; - if (STIX_OOP_IS_SMOOI(x) && STIX_OOP_IS_SMOOI(y)) + if (MOO_OOP_IS_SMOOI(x) && MOO_OOP_IS_SMOOI(y)) { - stix_ooi_t xv, yv, q, r; + moo_ooi_t xv, yv, q, r; - xv = STIX_OOP_TO_SMOOI(x); - yv = STIX_OOP_TO_SMOOI(y); + xv = MOO_OOP_TO_SMOOI(x); + yv = MOO_OOP_TO_SMOOI(y); if (yv == 0) { - stix->errnum = STIX_EDIVBY0; - return STIX_NULL; + moo->errnum = MOO_EDIVBY0; + return MOO_NULL; } if (xv == 0) { - if (rem) *rem = STIX_SMOOI_TO_OOP(0); - return STIX_SMOOI_TO_OOP(0); + if (rem) *rem = MOO_SMOOI_TO_OOP(0); + return MOO_SMOOI_TO_OOP(0); } /* In C89, integer division with a negative number is @@ -1913,7 +1913,7 @@ stix_oop_t stix_divints (stix_t* stix, stix_oop_t x, stix_oop_t y, int modulo, s */ q = xv / yv; - STIX_ASSERT (stix, STIX_IN_SMOOI_RANGE(q)); + MOO_ASSERT (moo, MOO_IN_SMOOI_RANGE(q)); r = xv - yv * q; /* xv % yv; */ if (r) @@ -1938,7 +1938,7 @@ stix_oop_t stix_divints (stix_t* stix, stix_oop_t x, stix_oop_t y, int modulo, s * change the sign of r to the divisor's sign */ r += yv; --q; - STIX_ASSERT (stix, r && !IS_SIGN_DIFF(yv, r)); + MOO_ASSERT (moo, r && !IS_SIGN_DIFF(yv, r)); } } else @@ -1962,63 +1962,63 @@ stix_oop_t stix_divints (stix_t* stix, stix_oop_t x, stix_oop_t y, int modulo, s * architecture. */ r -= yv; ++q; - STIX_ASSERT (stix, xv && !IS_SIGN_DIFF(xv, r)); + MOO_ASSERT (moo, xv && !IS_SIGN_DIFF(xv, r)); } } } if (rem) { - STIX_ASSERT (stix, STIX_IN_SMOOI_RANGE(r)); - *rem = STIX_SMOOI_TO_OOP(r); + MOO_ASSERT (moo, MOO_IN_SMOOI_RANGE(r)); + *rem = MOO_SMOOI_TO_OOP(r); } - return STIX_SMOOI_TO_OOP((stix_ooi_t)q); + return MOO_SMOOI_TO_OOP((moo_ooi_t)q); } else { - if (STIX_OOP_IS_SMOOI(x)) + if (MOO_OOP_IS_SMOOI(x)) { - stix_ooi_t v; + moo_ooi_t v; - if (!is_bigint(stix,y)) goto oops_einval; + if (!is_bigint(moo,y)) goto oops_einval; - v = STIX_OOP_TO_SMOOI(x); + v = MOO_OOP_TO_SMOOI(x); if (v == 0) { - if (rem) *rem = STIX_SMOOI_TO_OOP(0); - return STIX_SMOOI_TO_OOP(0); + if (rem) *rem = MOO_SMOOI_TO_OOP(0); + return MOO_SMOOI_TO_OOP(0); } - stix_pushtmp (stix, &y); - x = make_bigint_with_ooi (stix, v); - stix_poptmp (stix); - if (!x) return STIX_NULL; + moo_pushtmp (moo, &y); + x = make_bigint_with_ooi (moo, v); + moo_poptmp (moo); + if (!x) return MOO_NULL; } - else if (STIX_OOP_IS_SMOOI(y)) + else if (MOO_OOP_IS_SMOOI(y)) { - stix_ooi_t v; + moo_ooi_t v; - if (!is_bigint(stix,x)) goto oops_einval; + if (!is_bigint(moo,x)) goto oops_einval; - v = STIX_OOP_TO_SMOOI(y); + v = MOO_OOP_TO_SMOOI(y); switch (v) { case 0: - stix->errnum = STIX_EDIVBY0; - return STIX_NULL; + moo->errnum = MOO_EDIVBY0; + return MOO_NULL; case 1: - z = clone_bigint (stix, x, STIX_OBJ_GET_SIZE(x)); - if (!z) return STIX_NULL; - if (rem) *rem = STIX_SMOOI_TO_OOP(0); + z = clone_bigint (moo, x, MOO_OBJ_GET_SIZE(x)); + if (!z) return MOO_NULL; + if (rem) *rem = MOO_SMOOI_TO_OOP(0); return z; case -1: - z = clone_bigint_negated (stix, x, STIX_OBJ_GET_SIZE(x)); - if (!z) return STIX_NULL; - if (rem) *rem = STIX_SMOOI_TO_OOP(0); + z = clone_bigint_negated (moo, x, MOO_OBJ_GET_SIZE(x)); + if (!z) return MOO_NULL; + if (rem) *rem = MOO_SMOOI_TO_OOP(0); return z; /* @@ -2029,69 +2029,69 @@ stix_oop_t stix_divints (stix_t* stix, stix_oop_t x, stix_oop_t y, int modulo, s DO SHIFTING. how to get remainder.. if v is powerof2, do shifting??? - z = clone_bigint_negated (stix, x, STIX_OBJ_GET_SIZE(x)); - rshift_unsigned_array (z, STIX_OBJ_GET_SIZE(z), 10); + z = clone_bigint_negated (moo, x, MOO_OBJ_GET_SIZE(x)); + rshift_unsigned_array (z, MOO_OBJ_GET_SIZE(z), 10); } */ } - stix_pushtmp (stix, &x); - y = make_bigint_with_ooi (stix, v); - stix_poptmp (stix); - if (!y) return STIX_NULL; + moo_pushtmp (moo, &x); + y = make_bigint_with_ooi (moo, v); + moo_poptmp (moo); + if (!y) return MOO_NULL; } else { - if (!is_bigint(stix,x)) goto oops_einval; - if (!is_bigint(stix,y)) goto oops_einval; + if (!is_bigint(moo,x)) goto oops_einval; + if (!is_bigint(moo,y)) goto oops_einval; } } - x_neg = (STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer); - y_neg = (STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer); + x_neg = (MOO_OBJ_GET_CLASS(x) == moo->_large_negative_integer); + y_neg = (MOO_OBJ_GET_CLASS(y) == moo->_large_negative_integer); - stix_pushtmp (stix, &x); - stix_pushtmp (stix, &y); - z = divide_unsigned_integers (stix, x, y, &r); - stix_poptmps (stix, 2); - if (!z) return STIX_NULL; + moo_pushtmp (moo, &x); + moo_pushtmp (moo, &y); + z = divide_unsigned_integers (moo, x, y, &r); + moo_poptmps (moo, 2); + if (!z) return MOO_NULL; if (x_neg) { /* the class on r must be set before normalize_bigint() * because it can get changed to a small integer */ - STIX_OBJ_SET_CLASS(r, stix->_large_negative_integer); + MOO_OBJ_SET_CLASS(r, moo->_large_negative_integer); } if (x_neg != y_neg) { - STIX_OBJ_SET_CLASS(z, stix->_large_negative_integer); + MOO_OBJ_SET_CLASS(z, moo->_large_negative_integer); - stix_pushtmp (stix, &z); - stix_pushtmp (stix, &y); - r = normalize_bigint (stix, r); - stix_poptmps (stix, 2); - if (!r) return STIX_NULL; + moo_pushtmp (moo, &z); + moo_pushtmp (moo, &y); + r = normalize_bigint (moo, r); + moo_poptmps (moo, 2); + if (!r) return MOO_NULL; - if (r != STIX_SMOOI_TO_OOP(0) && modulo) + if (r != MOO_SMOOI_TO_OOP(0) && modulo) { if (rem) { - stix_pushtmp (stix, &z); - stix_pushtmp (stix, &y); - r = stix_addints (stix, r, y); - stix_poptmps (stix, 2); - if (!r) return STIX_NULL; + moo_pushtmp (moo, &z); + moo_pushtmp (moo, &y); + r = moo_addints (moo, r, y); + moo_poptmps (moo, 2); + if (!r) return MOO_NULL; - stix_pushtmp (stix, &r); - z = normalize_bigint (stix, z); - stix_poptmp (stix); - if (!z) return STIX_NULL; + moo_pushtmp (moo, &r); + z = normalize_bigint (moo, z); + moo_poptmp (moo); + if (!z) return MOO_NULL; - stix_pushtmp (stix, &r); - z = stix_subints (stix, z, STIX_SMOOI_TO_OOP(1)); - stix_poptmp (stix); - if (!z) return STIX_NULL; + moo_pushtmp (moo, &r); + z = moo_subints (moo, z, MOO_SMOOI_TO_OOP(1)); + moo_poptmp (moo); + if (!z) return MOO_NULL; *rem = r; return z; @@ -2100,171 +2100,171 @@ stix_oop_t stix_divints (stix_t* stix, stix_oop_t x, stix_oop_t y, int modulo, s { /* remainder is not needed at all */ /* TODO: subtract 1 without normalization??? */ - z = normalize_bigint (stix, z); - if (!z) return STIX_NULL; - return stix_subints (stix, z, STIX_SMOOI_TO_OOP(1)); + z = normalize_bigint (moo, z); + if (!z) return MOO_NULL; + return moo_subints (moo, z, MOO_SMOOI_TO_OOP(1)); } } } else { - stix_pushtmp (stix, &z); - r = normalize_bigint (stix, r); - stix_poptmp (stix); - if (!r) return STIX_NULL; + moo_pushtmp (moo, &z); + r = normalize_bigint (moo, r); + moo_poptmp (moo); + if (!r) return MOO_NULL; } if (rem) *rem = r; - return normalize_bigint (stix, z); + return normalize_bigint (moo, z); oops_einval: - stix->errnum = STIX_EINVAL; - return STIX_NULL; + moo->errnum = MOO_EINVAL; + return MOO_NULL; } -stix_oop_t stix_negateint (stix_t* stix, stix_oop_t x) +moo_oop_t moo_negateint (moo_t* moo, moo_oop_t x) { - if (STIX_OOP_IS_SMOOI(x)) + if (MOO_OOP_IS_SMOOI(x)) { - stix_ooi_t v; - v = STIX_OOP_TO_SMOOI(x); - return STIX_SMOOI_TO_OOP(-v); + moo_ooi_t v; + v = MOO_OOP_TO_SMOOI(x); + return MOO_SMOOI_TO_OOP(-v); } else { - if (!is_bigint(stix, x)) goto oops_einval; - return clone_bigint_negated (stix, x, STIX_OBJ_GET_SIZE(x)); + if (!is_bigint(moo, x)) goto oops_einval; + return clone_bigint_negated (moo, x, MOO_OBJ_GET_SIZE(x)); } oops_einval: - stix->errnum = STIX_EINVAL; - return STIX_NULL; + moo->errnum = MOO_EINVAL; + return MOO_NULL; } -stix_oop_t stix_bitatint (stix_t* stix, stix_oop_t x, stix_oop_t y) +moo_oop_t moo_bitatint (moo_t* moo, moo_oop_t x, moo_oop_t y) { /* y is 0-based */ - if (STIX_OOP_IS_SMOOI(x) && STIX_OOP_IS_SMOOI(y)) + if (MOO_OOP_IS_SMOOI(x) && MOO_OOP_IS_SMOOI(y)) { - stix_ooi_t v1, v2, v3; + moo_ooi_t v1, v2, v3; - v1 = STIX_OOP_TO_SMOOI(x); - v2 = STIX_OOP_TO_SMOOI(y); + v1 = MOO_OOP_TO_SMOOI(x); + v2 = MOO_OOP_TO_SMOOI(y); - if (v2 < 0) return STIX_SMOOI_TO_OOP(0); + if (v2 < 0) return MOO_SMOOI_TO_OOP(0); if (v1 >= 0) { /* the absolute value may be composed of up to - * STIX_SMOOI_BITS - 1 bits as there is a sign bit.*/ - if (v2 >= STIX_SMOOI_BITS - 1) return STIX_SMOOI_TO_OOP(0); - v3 = ((stix_oow_t)v1 >> v2) & 1; + * MOO_SMOOI_BITS - 1 bits as there is a sign bit.*/ + if (v2 >= MOO_SMOOI_BITS - 1) return MOO_SMOOI_TO_OOP(0); + v3 = ((moo_oow_t)v1 >> v2) & 1; } else { - if (v2 >= STIX_SMOOI_BITS - 1) return STIX_SMOOI_TO_OOP(1); - v3 = ((~(stix_oow_t)-v1 + 1) >> v2) & 1; + if (v2 >= MOO_SMOOI_BITS - 1) return MOO_SMOOI_TO_OOP(1); + v3 = ((~(moo_oow_t)-v1 + 1) >> v2) & 1; } - return STIX_SMOOI_TO_OOP(v3); + return MOO_SMOOI_TO_OOP(v3); } - else if (STIX_OOP_IS_SMOOI(x)) + else if (MOO_OOP_IS_SMOOI(x)) { - if (!is_bigint(stix, y)) goto oops_einval; + if (!is_bigint(moo, y)) goto oops_einval; - if (STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer) return STIX_SMOOI_TO_OOP(0); + if (MOO_OBJ_GET_CLASS(y) == moo->_large_negative_integer) return MOO_SMOOI_TO_OOP(0); - /* y is definitely >= STIX_SMOOI_BITS */ - if (STIX_OOP_TO_SMOOI(x) >= 0) - return STIX_SMOOI_TO_OOP(0); + /* y is definitely >= MOO_SMOOI_BITS */ + if (MOO_OOP_TO_SMOOI(x) >= 0) + return MOO_SMOOI_TO_OOP(0); else - return STIX_SMOOI_TO_OOP(1); + return MOO_SMOOI_TO_OOP(1); } - else if (STIX_OOP_IS_SMOOI(y)) + else if (MOO_OOP_IS_SMOOI(y)) { - stix_ooi_t v; - stix_oow_t wp, bp, xs; + moo_ooi_t v; + moo_oow_t wp, bp, xs; - if (!is_bigint(stix, x)) goto oops_einval; - v = STIX_OOP_TO_SMOOI(y); + if (!is_bigint(moo, x)) goto oops_einval; + v = MOO_OOP_TO_SMOOI(y); - if (v < 0) return STIX_SMOOI_TO_OOP(0); - wp = v / STIX_LIW_BITS; - bp = v - (wp * STIX_LIW_BITS); + if (v < 0) return MOO_SMOOI_TO_OOP(0); + wp = v / MOO_LIW_BITS; + bp = v - (wp * MOO_LIW_BITS); - xs = STIX_OBJ_GET_SIZE(x); - if (STIX_OBJ_GET_CLASS(x) == stix->_large_positive_integer) + xs = MOO_OBJ_GET_SIZE(x); + if (MOO_OBJ_GET_CLASS(x) == moo->_large_positive_integer) { - if (wp >= xs) return STIX_SMOOI_TO_OOP(0); - v = (((stix_oop_liword_t)x)->slot[wp] >> bp) & 1; + if (wp >= xs) return MOO_SMOOI_TO_OOP(0); + v = (((moo_oop_liword_t)x)->slot[wp] >> bp) & 1; } else { - stix_lidw_t w, carry; - stix_oow_t i; + moo_lidw_t w, carry; + moo_oow_t i; - if (wp >= xs) return STIX_SMOOI_TO_OOP(1); + if (wp >= xs) return MOO_SMOOI_TO_OOP(1); carry = 1; for (i = 0; i <= wp; i++) { - w = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)x)->slot[i]) + carry; - carry = w >> STIX_LIW_BITS; + w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry; + carry = w >> MOO_LIW_BITS; } - v = ((stix_oow_t)w >> bp) & 1; + v = ((moo_oow_t)w >> bp) & 1; } - return STIX_SMOOI_TO_OOP(v); + return MOO_SMOOI_TO_OOP(v); } else { - #if defined(STIX_LIMIT_OBJ_SIZE) + #if defined(MOO_LIMIT_OBJ_SIZE) /* nothing */ #else - stix_oow_t w, wp, bp, xs; - stix_ooi_t v; + moo_oow_t w, wp, bp, xs; + moo_ooi_t v; int sign; #endif - if (!is_bigint(stix, x) || !is_bigint(stix, y)) goto oops_einval; + if (!is_bigint(moo, x) || !is_bigint(moo, y)) goto oops_einval; - #if defined(STIX_LIMIT_OBJ_SIZE) - if (STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer) return STIX_SMOOI_TO_OOP(0); + #if defined(MOO_LIMIT_OBJ_SIZE) + if (MOO_OBJ_GET_CLASS(y) == moo->_large_negative_integer) return MOO_SMOOI_TO_OOP(0); - STIX_ASSERT (stix, STIX_OBJ_SIZE_BITS_MAX <= STIX_TYPE_MAX(stix_oow_t)); - if (STIX_OBJ_GET_CLASS(x) == stix->_large_positive_integer) + MOO_ASSERT (moo, MOO_OBJ_SIZE_BITS_MAX <= MOO_TYPE_MAX(moo_oow_t)); + if (MOO_OBJ_GET_CLASS(x) == moo->_large_positive_integer) { - return STIX_SMOOI_TO_OOP (0); + return MOO_SMOOI_TO_OOP (0); } else { - return STIX_SMOOI_TO_OOP (1); + return MOO_SMOOI_TO_OOP (1); } #else - xs = STIX_OBJ_GET_SIZE(x); + xs = MOO_OBJ_GET_SIZE(x); - if (STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer) return STIX_SMOOI_TO_OOP(0); + if (MOO_OBJ_GET_CLASS(y) == moo->_large_negative_integer) return MOO_SMOOI_TO_OOP(0); - sign = bigint_to_oow (stix, y, &w); - STIX_ASSERT (stix, sign >= 0); + sign = bigint_to_oow (moo, y, &w); + MOO_ASSERT (moo, sign >= 0); if (sign >= 1) { - wp = w / STIX_LIW_BITS; - bp = w - (wp * STIX_LIW_BITS); + wp = w / MOO_LIW_BITS; + bp = w - (wp * MOO_LIW_BITS); } else { - stix_oop_t quo, rem; + moo_oop_t quo, rem; - STIX_ASSERT (stix, sign == 0); + MOO_ASSERT (moo, sign == 0); - stix_pushtmp (stix, &x); - quo = stix_divints (stix, y, STIX_SMOOI_TO_OOP(STIX_LIW_BITS), 0, &rem); - stix_poptmp (stix); - if (!quo) return STIX_NULL; + moo_pushtmp (moo, &x); + quo = moo_divints (moo, y, MOO_SMOOI_TO_OOP(MOO_LIW_BITS), 0, &rem); + moo_poptmp (moo); + if (!quo) return MOO_NULL; - sign = integer_to_oow (stix, quo, &wp); - STIX_ASSERT (stix, sign >= 0); + sign = integer_to_oow (moo, quo, &wp); + MOO_ASSERT (moo, sign >= 0); if (sign == 0) { /* too large. set it to xs so that it gets out of @@ -2272,97 +2272,97 @@ stix_oop_t stix_bitatint (stix_t* stix, stix_oop_t x, stix_oop_t y) wp = xs; } - STIX_ASSERT (stix, STIX_OOP_IS_SMOOI(rem)); - bp = STIX_OOP_TO_SMOOI(rem); - STIX_ASSERT (stix, bp >= 0 && bp < STIX_LIW_BITS); + MOO_ASSERT (moo, MOO_OOP_IS_SMOOI(rem)); + bp = MOO_OOP_TO_SMOOI(rem); + MOO_ASSERT (moo, bp >= 0 && bp < MOO_LIW_BITS); } - if (STIX_OBJ_GET_CLASS(x) == stix->_large_positive_integer) + if (MOO_OBJ_GET_CLASS(x) == moo->_large_positive_integer) { - if (wp >= xs) return STIX_SMOOI_TO_OOP(0); - v = (((stix_oop_liword_t)x)->slot[wp] >> bp) & 1; + if (wp >= xs) return MOO_SMOOI_TO_OOP(0); + v = (((moo_oop_liword_t)x)->slot[wp] >> bp) & 1; } else { - stix_lidw_t w, carry; - stix_oow_t i; + moo_lidw_t w, carry; + moo_oow_t i; - if (wp >= xs) return STIX_SMOOI_TO_OOP(1); + if (wp >= xs) return MOO_SMOOI_TO_OOP(1); carry = 1; for (i = 0; i <= wp; i++) { - w = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)x)->slot[i]) + carry; - carry = w >> STIX_LIW_BITS; + w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry; + carry = w >> MOO_LIW_BITS; } - v = ((stix_oow_t)w >> bp) & 1; + v = ((moo_oow_t)w >> bp) & 1; } - return STIX_SMOOI_TO_OOP(v); + return MOO_SMOOI_TO_OOP(v); #endif } oops_einval: - stix->errnum = STIX_EINVAL; - return STIX_NULL; + moo->errnum = MOO_EINVAL; + return MOO_NULL; } -stix_oop_t stix_bitandints (stix_t* stix, stix_oop_t x, stix_oop_t y) +moo_oop_t moo_bitandints (moo_t* moo, moo_oop_t x, moo_oop_t y) { - if (STIX_OOP_IS_SMOOI(x) && STIX_OOP_IS_SMOOI(y)) + if (MOO_OOP_IS_SMOOI(x) && MOO_OOP_IS_SMOOI(y)) { - stix_ooi_t v1, v2, v3; + moo_ooi_t v1, v2, v3; - v1 = STIX_OOP_TO_SMOOI(x); - v2 = STIX_OOP_TO_SMOOI(y); + v1 = MOO_OOP_TO_SMOOI(x); + v2 = MOO_OOP_TO_SMOOI(y); v3 = v1 & v2; - if (STIX_IN_SMOOI_RANGE(v3)) return STIX_SMOOI_TO_OOP(v3); - return make_bigint_with_ooi (stix, v3); + if (MOO_IN_SMOOI_RANGE(v3)) return MOO_SMOOI_TO_OOP(v3); + return make_bigint_with_ooi (moo, v3); } - else if (STIX_OOP_IS_SMOOI(x)) + else if (MOO_OOP_IS_SMOOI(x)) { - stix_ooi_t v; + moo_ooi_t v; - if (!is_bigint(stix, y)) goto oops_einval; + if (!is_bigint(moo, y)) goto oops_einval; - v = STIX_OOP_TO_SMOOI(x); - if (v == 0) return STIX_SMOOI_TO_OOP(0); + v = MOO_OOP_TO_SMOOI(x); + if (v == 0) return MOO_SMOOI_TO_OOP(0); - stix_pushtmp (stix, &y); - x = make_bigint_with_ooi (stix, v); - stix_poptmp (stix); - if (!x) return STIX_NULL; + moo_pushtmp (moo, &y); + x = make_bigint_with_ooi (moo, v); + moo_poptmp (moo); + if (!x) return MOO_NULL; goto bigint_and_bigint; } - else if (STIX_OOP_IS_SMOOI(y)) + else if (MOO_OOP_IS_SMOOI(y)) { - stix_ooi_t v; + moo_ooi_t v; - if (!is_bigint(stix, x)) goto oops_einval; + if (!is_bigint(moo, x)) goto oops_einval; - v = STIX_OOP_TO_SMOOI(y); - if (v == 0) return STIX_SMOOI_TO_OOP(0); + v = MOO_OOP_TO_SMOOI(y); + if (v == 0) return MOO_SMOOI_TO_OOP(0); - stix_pushtmp (stix, &x); - y = make_bigint_with_ooi (stix, v); - stix_poptmp (stix); - if (!x) return STIX_NULL; + moo_pushtmp (moo, &x); + y = make_bigint_with_ooi (moo, v); + moo_poptmp (moo); + if (!x) return MOO_NULL; goto bigint_and_bigint; } else { - stix_oop_t z; - stix_oow_t i, xs, ys, zs, zalloc; + moo_oop_t z; + moo_oow_t i, xs, ys, zs, zalloc; int negx, negy; - if (!is_bigint(stix,x) || !is_bigint(stix, y)) goto oops_einval; + if (!is_bigint(moo,x) || !is_bigint(moo, y)) goto oops_einval; bigint_and_bigint: - xs = STIX_OBJ_GET_SIZE(x); - ys = STIX_OBJ_GET_SIZE(y); + xs = MOO_OBJ_GET_SIZE(x); + ys = MOO_OBJ_GET_SIZE(y); if (xs < ys) { @@ -2375,8 +2375,8 @@ stix_oop_t stix_bitandints (stix_t* stix, stix_oop_t x, stix_oop_t y) xs = zs; } - negx = (STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer)? 1: 0; - negy = (STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer)? 1: 0; + negx = (MOO_OBJ_GET_CLASS(x) == moo->_large_negative_integer)? 1: 0; + negy = (MOO_OBJ_GET_CLASS(y) == moo->_large_negative_integer)? 1: 0; if (negx && negy) { @@ -2399,67 +2399,67 @@ stix_oop_t stix_bitandints (stix_t* stix, stix_oop_t x, stix_oop_t y) zs = ys; } - stix_pushtmp (stix, &x); - stix_pushtmp (stix, &y); - z = stix_instantiate (stix, stix->_large_positive_integer, STIX_NULL, zalloc); - stix_poptmps (stix, 2); - if (!z) return STIX_NULL; + moo_pushtmp (moo, &x); + moo_pushtmp (moo, &y); + z = moo_instantiate (moo, moo->_large_positive_integer, MOO_NULL, zalloc); + moo_poptmps (moo, 2); + if (!z) return MOO_NULL; if (negx && negy) { /* both are negative */ - stix_lidw_t w[2]; - stix_lidw_t carry[2]; + moo_lidw_t w[2]; + moo_lidw_t carry[2]; carry[0] = 1; carry[1] = 1; /* 2's complement on both x and y and perform bitwise-and */ for (i = 0; i < ys; i++) { - w[0] = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)x)->slot[i]) + carry[0]; - carry[0] = w[0] >> STIX_LIW_BITS; + w[0] = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry[0]; + carry[0] = w[0] >> MOO_LIW_BITS; - w[1] = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)y)->slot[i]) + carry[1]; - carry[1] = w[1] >> STIX_LIW_BITS; + w[1] = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)y)->slot[i]) + carry[1]; + carry[1] = w[1] >> MOO_LIW_BITS; - ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w[0] & (stix_liw_t)w[1]; + ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w[0] & (moo_liw_t)w[1]; } - STIX_ASSERT (stix, carry[1] == 0); + MOO_ASSERT (moo, carry[1] == 0); /* 2's complement on the remaining part of x. the lacking part * in y is treated as if they are all 1s. */ for (; i < xs; i++) { - w[0] = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)x)->slot[i]) + carry[0]; - carry[0] = w[0] >> STIX_LIW_BITS; - ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w[0]; + w[0] = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry[0]; + carry[0] = w[0] >> MOO_LIW_BITS; + ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w[0]; } - STIX_ASSERT (stix, carry[0] == 0); + MOO_ASSERT (moo, carry[0] == 0); /* 2's complement on the final result */ - ((stix_oop_liword_t)z)->slot[zs] = ~(stix_liw_t)0; + ((moo_oop_liword_t)z)->slot[zs] = ~(moo_liw_t)0; carry[0] = 1; for (i = 0; i <= zs; i++) { - w[0] = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)z)->slot[i]) + carry[0]; - carry[0] = w[0] >> STIX_LIW_BITS; - ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w[0]; + w[0] = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)z)->slot[i]) + carry[0]; + carry[0] = w[0] >> MOO_LIW_BITS; + ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w[0]; } - STIX_ASSERT (stix, carry[0] == 0); + MOO_ASSERT (moo, carry[0] == 0); - STIX_OBJ_SET_CLASS (z, stix->_large_negative_integer); + MOO_OBJ_SET_CLASS (z, moo->_large_negative_integer); } else if (negx) { /* x is negative, y is positive */ - stix_lidw_t w, carry; + moo_lidw_t w, carry; carry = 1; for (i = 0; i < ys; i++) { - w = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)x)->slot[i]) + carry; - carry = w >> STIX_LIW_BITS; - ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w & ((stix_oop_liword_t)y)->slot[i]; + w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry; + carry = w >> MOO_LIW_BITS; + ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w & ((moo_oop_liword_t)y)->slot[i]; } /* the lacking part in y is all 0's. the remaining part in x is @@ -2469,17 +2469,17 @@ stix_oop_t stix_bitandints (stix_t* stix, stix_oop_t x, stix_oop_t y) else if (negy) { /* x is positive, y is negative */ - stix_lidw_t w, carry; + moo_lidw_t w, carry; /* x & 2's complement on y up to ys */ carry = 1; for (i = 0; i < ys; i++) { - w = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)y)->slot[i]) + carry; - carry = w >> STIX_LIW_BITS; - ((stix_oop_liword_t)z)->slot[i] = ((stix_oop_liword_t)x)->slot[i] & (stix_liw_t)w; + w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)y)->slot[i]) + carry; + carry = w >> MOO_LIW_BITS; + ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)x)->slot[i] & (moo_liw_t)w; } - STIX_ASSERT (stix, carry == 0); + MOO_ASSERT (moo, carry == 0); /* handle the longer part in x than y * @@ -2500,7 +2500,7 @@ stix_oop_t stix_bitandints (stix_t* stix, stix_oop_t x, stix_oop_t y) */ for (; i < xs; i++) { - ((stix_oop_liword_t)z)->slot[i] = ((stix_oop_liword_t)x)->slot[i]; + ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)x)->slot[i]; } } else @@ -2508,74 +2508,74 @@ stix_oop_t stix_bitandints (stix_t* stix, stix_oop_t x, stix_oop_t y) /* both are positive */ for (i = 0; i < ys; i++) { - ((stix_oop_liword_t)z)->slot[i] = ((stix_oop_liword_t)x)->slot[i] & ((stix_oop_liword_t)y)->slot[i]; + ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)x)->slot[i] & ((moo_oop_liword_t)y)->slot[i]; } } - return normalize_bigint(stix, z); + return normalize_bigint(moo, z); } oops_einval: - stix->errnum = STIX_EINVAL; - return STIX_NULL; + moo->errnum = MOO_EINVAL; + return MOO_NULL; } -stix_oop_t stix_bitorints (stix_t* stix, stix_oop_t x, stix_oop_t y) +moo_oop_t moo_bitorints (moo_t* moo, moo_oop_t x, moo_oop_t y) { - if (STIX_OOP_IS_SMOOI(x) && STIX_OOP_IS_SMOOI(y)) + if (MOO_OOP_IS_SMOOI(x) && MOO_OOP_IS_SMOOI(y)) { - stix_ooi_t v1, v2, v3; + moo_ooi_t v1, v2, v3; - v1 = STIX_OOP_TO_SMOOI(x); - v2 = STIX_OOP_TO_SMOOI(y); + v1 = MOO_OOP_TO_SMOOI(x); + v2 = MOO_OOP_TO_SMOOI(y); v3 = v1 | v2; - if (STIX_IN_SMOOI_RANGE(v3)) return STIX_SMOOI_TO_OOP(v3); - return make_bigint_with_ooi (stix, v3); + if (MOO_IN_SMOOI_RANGE(v3)) return MOO_SMOOI_TO_OOP(v3); + return make_bigint_with_ooi (moo, v3); } - else if (STIX_OOP_IS_SMOOI(x)) + else if (MOO_OOP_IS_SMOOI(x)) { - stix_ooi_t v; + moo_ooi_t v; - if (!is_bigint(stix, y)) goto oops_einval; + if (!is_bigint(moo, y)) goto oops_einval; - v = STIX_OOP_TO_SMOOI(x); - if (v == 0) return clone_bigint(stix, y, STIX_OBJ_GET_SIZE(y)); + v = MOO_OOP_TO_SMOOI(x); + if (v == 0) return clone_bigint(moo, y, MOO_OBJ_GET_SIZE(y)); - stix_pushtmp (stix, &y); - x = make_bigint_with_ooi (stix, v); - stix_poptmp (stix); - if (!x) return STIX_NULL; + moo_pushtmp (moo, &y); + x = make_bigint_with_ooi (moo, v); + moo_poptmp (moo); + if (!x) return MOO_NULL; goto bigint_and_bigint; } - else if (STIX_OOP_IS_SMOOI(y)) + else if (MOO_OOP_IS_SMOOI(y)) { - stix_ooi_t v; + moo_ooi_t v; - if (!is_bigint(stix, x)) goto oops_einval; + if (!is_bigint(moo, x)) goto oops_einval; - v = STIX_OOP_TO_SMOOI(y); - if (v == 0) return clone_bigint(stix, x, STIX_OBJ_GET_SIZE(x)); + v = MOO_OOP_TO_SMOOI(y); + if (v == 0) return clone_bigint(moo, x, MOO_OBJ_GET_SIZE(x)); - stix_pushtmp (stix, &x); - y = make_bigint_with_ooi (stix, v); - stix_poptmp (stix); - if (!x) return STIX_NULL; + moo_pushtmp (moo, &x); + y = make_bigint_with_ooi (moo, v); + moo_poptmp (moo); + if (!x) return MOO_NULL; goto bigint_and_bigint; } else { - stix_oop_t z; - stix_oow_t i, xs, ys, zs, zalloc; + moo_oop_t z; + moo_oow_t i, xs, ys, zs, zalloc; int negx, negy; - if (!is_bigint(stix,x) || !is_bigint(stix, y)) goto oops_einval; + if (!is_bigint(moo,x) || !is_bigint(moo, y)) goto oops_einval; bigint_and_bigint: - xs = STIX_OBJ_GET_SIZE(x); - ys = STIX_OBJ_GET_SIZE(y); + xs = MOO_OBJ_GET_SIZE(x); + ys = MOO_OBJ_GET_SIZE(y); if (xs < ys) { @@ -2588,8 +2588,8 @@ stix_oop_t stix_bitorints (stix_t* stix, stix_oop_t x, stix_oop_t y) xs = zs; } - negx = (STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer)? 1: 0; - negy = (STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer)? 1: 0; + negx = (MOO_OBJ_GET_CLASS(x) == moo->_large_negative_integer)? 1: 0; + negy = (MOO_OBJ_GET_CLASS(y) == moo->_large_negative_integer)? 1: 0; if (negx && negy) { @@ -2615,36 +2615,36 @@ stix_oop_t stix_bitorints (stix_t* stix, stix_oop_t x, stix_oop_t y) if (zalloc < zs) { /* overflow in zalloc calculation above */ - stix->errnum = STIX_EOOMEM; /* TODO: is it a soft failure or hard failure? */ - return STIX_NULL; + moo->errnum = MOO_EOOMEM; /* TODO: is it a soft failure or hard failure? */ + return MOO_NULL; } - stix_pushtmp (stix, &x); - stix_pushtmp (stix, &y); - z = stix_instantiate (stix, stix->_large_positive_integer, STIX_NULL, zalloc); - stix_poptmps (stix, 2); - if (!z) return STIX_NULL; + moo_pushtmp (moo, &x); + moo_pushtmp (moo, &y); + z = moo_instantiate (moo, moo->_large_positive_integer, MOO_NULL, zalloc); + moo_poptmps (moo, 2); + if (!z) return MOO_NULL; if (negx && negy) { /* both are negative */ - stix_lidw_t w[2]; - stix_lidw_t carry[2]; + moo_lidw_t w[2]; + moo_lidw_t carry[2]; carry[0] = 1; carry[1] = 1; /* 2's complement on both x and y and perform bitwise-and */ for (i = 0; i < ys; i++) { - w[0] = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)x)->slot[i]) + carry[0]; - carry[0] = w[0] >> STIX_LIW_BITS; + w[0] = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry[0]; + carry[0] = w[0] >> MOO_LIW_BITS; - w[1] = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)y)->slot[i]) + carry[1]; - carry[1] = w[1] >> STIX_LIW_BITS; + w[1] = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)y)->slot[i]) + carry[1]; + carry[1] = w[1] >> MOO_LIW_BITS; - ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w[0] | (stix_liw_t)w[1]; + ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w[0] | (moo_liw_t)w[1]; } - STIX_ASSERT (stix, carry[1] == 0); + MOO_ASSERT (moo, carry[1] == 0); /* do nothing about the extra part in x and the lacking part * in y for the reason shown in [NOTE] in the 'else if' block @@ -2652,55 +2652,55 @@ stix_oop_t stix_bitorints (stix_t* stix, stix_oop_t x, stix_oop_t y) adjust_to_negative: /* 2's complement on the final result */ - ((stix_oop_liword_t)z)->slot[zs] = ~(stix_liw_t)0; + ((moo_oop_liword_t)z)->slot[zs] = ~(moo_liw_t)0; carry[0] = 1; for (i = 0; i <= zs; i++) { - w[0] = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)z)->slot[i]) + carry[0]; - carry[0] = w[0] >> STIX_LIW_BITS; - ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w[0]; + w[0] = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)z)->slot[i]) + carry[0]; + carry[0] = w[0] >> MOO_LIW_BITS; + ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w[0]; } - STIX_ASSERT (stix, carry[0] == 0); + MOO_ASSERT (moo, carry[0] == 0); - STIX_OBJ_SET_CLASS (z, stix->_large_negative_integer); + MOO_OBJ_SET_CLASS (z, moo->_large_negative_integer); } else if (negx) { /* x is negative, y is positive */ - stix_lidw_t w, carry; + moo_lidw_t w, carry; carry = 1; for (i = 0; i < ys; i++) { - w = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)x)->slot[i]) + carry; - carry = w >> STIX_LIW_BITS; - ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w | ((stix_oop_liword_t)y)->slot[i]; + w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry; + carry = w >> MOO_LIW_BITS; + ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w | ((moo_oop_liword_t)y)->slot[i]; } for (; i < xs; i++) { - w = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)x)->slot[i]) + carry; - carry = w >> STIX_LIW_BITS; - ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w; + w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry; + carry = w >> MOO_LIW_BITS; + ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w; } - STIX_ASSERT (stix, carry == 0); + MOO_ASSERT (moo, carry == 0); goto adjust_to_negative; } else if (negy) { /* x is positive, y is negative */ - stix_lidw_t w, carry; + moo_lidw_t w, carry; /* x & 2's complement on y up to ys */ carry = 1; for (i = 0; i < ys; i++) { - w = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)y)->slot[i]) + carry; - carry = w >> STIX_LIW_BITS; - ((stix_oop_liword_t)z)->slot[i] = ((stix_oop_liword_t)x)->slot[i] | (stix_liw_t)w; + w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)y)->slot[i]) + carry; + carry = w >> MOO_LIW_BITS; + ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)x)->slot[i] | (moo_liw_t)w; } - STIX_ASSERT (stix, carry == 0); + MOO_ASSERT (moo, carry == 0); /* [NOTE] * in theory, the lacking part in ys is all 1s when y is @@ -2711,7 +2711,7 @@ stix_oop_t stix_bitorints (stix_t* stix, stix_oop_t x, stix_oop_t y) * redundant. for (; i < xs; i++) { - ((stix_oop_liword_t)z)->slot[i] = ~(stix_liw_t)0; + ((moo_oop_liword_t)z)->slot[i] = ~(moo_liw_t)0; } */ goto adjust_to_negative; @@ -2721,79 +2721,79 @@ stix_oop_t stix_bitorints (stix_t* stix, stix_oop_t x, stix_oop_t y) /* both are positive */ for (i = 0; i < ys; i++) { - ((stix_oop_liword_t)z)->slot[i] = ((stix_oop_liword_t)x)->slot[i] | ((stix_oop_liword_t)y)->slot[i]; + ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)x)->slot[i] | ((moo_oop_liword_t)y)->slot[i]; } for (; i < xs; i++) { - ((stix_oop_liword_t)z)->slot[i] = ((stix_oop_liword_t)x)->slot[i]; + ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)x)->slot[i]; } } - return normalize_bigint(stix, z); + return normalize_bigint(moo, z); } oops_einval: - stix->errnum = STIX_EINVAL; - return STIX_NULL; + moo->errnum = MOO_EINVAL; + return MOO_NULL; } -stix_oop_t stix_bitxorints (stix_t* stix, stix_oop_t x, stix_oop_t y) +moo_oop_t moo_bitxorints (moo_t* moo, moo_oop_t x, moo_oop_t y) { - if (STIX_OOP_IS_SMOOI(x) && STIX_OOP_IS_SMOOI(y)) + if (MOO_OOP_IS_SMOOI(x) && MOO_OOP_IS_SMOOI(y)) { - stix_ooi_t v1, v2, v3; + moo_ooi_t v1, v2, v3; - v1 = STIX_OOP_TO_SMOOI(x); - v2 = STIX_OOP_TO_SMOOI(y); + v1 = MOO_OOP_TO_SMOOI(x); + v2 = MOO_OOP_TO_SMOOI(y); v3 = v1 ^ v2; - if (STIX_IN_SMOOI_RANGE(v3)) return STIX_SMOOI_TO_OOP(v3); - return make_bigint_with_ooi (stix, v3); + if (MOO_IN_SMOOI_RANGE(v3)) return MOO_SMOOI_TO_OOP(v3); + return make_bigint_with_ooi (moo, v3); } - else if (STIX_OOP_IS_SMOOI(x)) + else if (MOO_OOP_IS_SMOOI(x)) { - stix_ooi_t v; + moo_ooi_t v; - if (!is_bigint(stix, y)) goto oops_einval; + if (!is_bigint(moo, y)) goto oops_einval; - v = STIX_OOP_TO_SMOOI(x); - if (v == 0) return clone_bigint(stix, y, STIX_OBJ_GET_SIZE(y)); + v = MOO_OOP_TO_SMOOI(x); + if (v == 0) return clone_bigint(moo, y, MOO_OBJ_GET_SIZE(y)); - stix_pushtmp (stix, &y); - x = make_bigint_with_ooi (stix, v); - stix_poptmp (stix); - if (!x) return STIX_NULL; + moo_pushtmp (moo, &y); + x = make_bigint_with_ooi (moo, v); + moo_poptmp (moo); + if (!x) return MOO_NULL; goto bigint_and_bigint; } - else if (STIX_OOP_IS_SMOOI(y)) + else if (MOO_OOP_IS_SMOOI(y)) { - stix_ooi_t v; + moo_ooi_t v; - if (!is_bigint(stix, x)) goto oops_einval; + if (!is_bigint(moo, x)) goto oops_einval; - v = STIX_OOP_TO_SMOOI(y); - if (v == 0) return clone_bigint(stix, x, STIX_OBJ_GET_SIZE(x)); + v = MOO_OOP_TO_SMOOI(y); + if (v == 0) return clone_bigint(moo, x, MOO_OBJ_GET_SIZE(x)); - stix_pushtmp (stix, &x); - y = make_bigint_with_ooi (stix, v); - stix_poptmp (stix); - if (!x) return STIX_NULL; + moo_pushtmp (moo, &x); + y = make_bigint_with_ooi (moo, v); + moo_poptmp (moo); + if (!x) return MOO_NULL; goto bigint_and_bigint; } else { - stix_oop_t z; - stix_oow_t i, xs, ys, zs, zalloc; + moo_oop_t z; + moo_oow_t i, xs, ys, zs, zalloc; int negx, negy; - if (!is_bigint(stix,x) || !is_bigint(stix, y)) goto oops_einval; + if (!is_bigint(moo,x) || !is_bigint(moo, y)) goto oops_einval; bigint_and_bigint: - xs = STIX_OBJ_GET_SIZE(x); - ys = STIX_OBJ_GET_SIZE(y); + xs = MOO_OBJ_GET_SIZE(x); + ys = MOO_OBJ_GET_SIZE(y); if (xs < ys) { @@ -2806,8 +2806,8 @@ stix_oop_t stix_bitxorints (stix_t* stix, stix_oop_t x, stix_oop_t y) xs = zs; } - negx = (STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer)? 1: 0; - negy = (STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer)? 1: 0; + negx = (MOO_OBJ_GET_CLASS(x) == moo->_large_negative_integer)? 1: 0; + negy = (MOO_OBJ_GET_CLASS(y) == moo->_large_negative_integer)? 1: 0; if (negx && negy) { @@ -2833,101 +2833,101 @@ stix_oop_t stix_bitxorints (stix_t* stix, stix_oop_t x, stix_oop_t y) if (zalloc < zs) { /* overflow in zalloc calculation above */ - stix->errnum = STIX_EOOMEM; /* TODO: is it a soft failure or hard failure? */ - return STIX_NULL; + moo->errnum = MOO_EOOMEM; /* TODO: is it a soft failure or hard failure? */ + return MOO_NULL; } - stix_pushtmp (stix, &x); - stix_pushtmp (stix, &y); - z = stix_instantiate (stix, stix->_large_positive_integer, STIX_NULL, zalloc); - stix_poptmps (stix, 2); - if (!z) return STIX_NULL; + moo_pushtmp (moo, &x); + moo_pushtmp (moo, &y); + z = moo_instantiate (moo, moo->_large_positive_integer, MOO_NULL, zalloc); + moo_poptmps (moo, 2); + if (!z) return MOO_NULL; if (negx && negy) { /* both are negative */ - stix_lidw_t w[2]; - stix_lidw_t carry[2]; + moo_lidw_t w[2]; + moo_lidw_t carry[2]; carry[0] = 1; carry[1] = 1; /* 2's complement on both x and y and perform bitwise-and */ for (i = 0; i < ys; i++) { - w[0] = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)x)->slot[i]) + carry[0]; - carry[0] = w[0] >> STIX_LIW_BITS; + w[0] = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry[0]; + carry[0] = w[0] >> MOO_LIW_BITS; - w[1] = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)y)->slot[i]) + carry[1]; - carry[1] = w[1] >> STIX_LIW_BITS; + w[1] = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)y)->slot[i]) + carry[1]; + carry[1] = w[1] >> MOO_LIW_BITS; - ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w[0] ^ (stix_liw_t)w[1]; + ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w[0] ^ (moo_liw_t)w[1]; } - STIX_ASSERT (stix, carry[1] == 0); + MOO_ASSERT (moo, carry[1] == 0); /* treat the lacking part in y as all 1s */ for (; i < xs; i++) { - w[0] = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)x)->slot[i]) + carry[0]; - carry[0] = w[0] >> STIX_LIW_BITS; - ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w[0] ^ (~(stix_liw_t)0); + w[0] = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry[0]; + carry[0] = w[0] >> MOO_LIW_BITS; + ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w[0] ^ (~(moo_liw_t)0); } - STIX_ASSERT (stix, carry[0] == 0); + MOO_ASSERT (moo, carry[0] == 0); } else if (negx) { /* x is negative, y is positive */ - stix_lidw_t w, carry; + moo_lidw_t w, carry; carry = 1; for (i = 0; i < ys; i++) { - w = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)x)->slot[i]) + carry; - carry = w >> STIX_LIW_BITS; - ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w ^ ((stix_oop_liword_t)y)->slot[i]; + w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry; + carry = w >> MOO_LIW_BITS; + ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w ^ ((moo_oop_liword_t)y)->slot[i]; } /* treat the lacking part in y as all 0s */ for (; i < xs; i++) { - w = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)x)->slot[i]) + carry; - carry = w >> STIX_LIW_BITS; - ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w; + w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry; + carry = w >> MOO_LIW_BITS; + ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w; } - STIX_ASSERT (stix, carry == 0); + MOO_ASSERT (moo, carry == 0); adjust_to_negative: /* 2's complement on the final result */ - ((stix_oop_liword_t)z)->slot[zs] = ~(stix_liw_t)0; + ((moo_oop_liword_t)z)->slot[zs] = ~(moo_liw_t)0; carry = 1; for (i = 0; i <= zs; i++) { - w = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)z)->slot[i]) + carry; - carry = w >> STIX_LIW_BITS; - ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w; + w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)z)->slot[i]) + carry; + carry = w >> MOO_LIW_BITS; + ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w; } - STIX_ASSERT (stix, carry == 0); + MOO_ASSERT (moo, carry == 0); - STIX_OBJ_SET_CLASS (z, stix->_large_negative_integer); + MOO_OBJ_SET_CLASS (z, moo->_large_negative_integer); } else if (negy) { /* x is positive, y is negative */ - stix_lidw_t w, carry; + moo_lidw_t w, carry; /* x & 2's complement on y up to ys */ carry = 1; for (i = 0; i < ys; i++) { - w = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)y)->slot[i]) + carry; - carry = w >> STIX_LIW_BITS; - ((stix_oop_liword_t)z)->slot[i] = ((stix_oop_liword_t)x)->slot[i] ^ (stix_liw_t)w; + w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)y)->slot[i]) + carry; + carry = w >> MOO_LIW_BITS; + ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)x)->slot[i] ^ (moo_liw_t)w; } - STIX_ASSERT (stix, carry == 0); + MOO_ASSERT (moo, carry == 0); /* treat the lacking part in y as all 1s */ for (; i < xs; i++) { - ((stix_oop_liword_t)z)->slot[i] = ((stix_oop_liword_t)x)->slot[i] ^ (~(stix_liw_t)0); + ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)x)->slot[i] ^ (~(moo_liw_t)0); } goto adjust_to_negative; @@ -2937,46 +2937,46 @@ stix_oop_t stix_bitxorints (stix_t* stix, stix_oop_t x, stix_oop_t y) /* both are positive */ for (i = 0; i < ys; i++) { - ((stix_oop_liword_t)z)->slot[i] = ((stix_oop_liword_t)x)->slot[i] ^ ((stix_oop_liword_t)y)->slot[i]; + ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)x)->slot[i] ^ ((moo_oop_liword_t)y)->slot[i]; } /* treat the lacking part in y as all 0s */ for (; i < xs; i++) { - ((stix_oop_liword_t)z)->slot[i] = ((stix_oop_liword_t)x)->slot[i]; + ((moo_oop_liword_t)z)->slot[i] = ((moo_oop_liword_t)x)->slot[i]; } } - return normalize_bigint(stix, z); + return normalize_bigint(moo, z); } oops_einval: - stix->errnum = STIX_EINVAL; - return STIX_NULL; + moo->errnum = MOO_EINVAL; + return MOO_NULL; } -stix_oop_t stix_bitinvint (stix_t* stix, stix_oop_t x) +moo_oop_t moo_bitinvint (moo_t* moo, moo_oop_t x) { - if (STIX_OOP_IS_SMOOI(x)) + if (MOO_OOP_IS_SMOOI(x)) { - stix_ooi_t v; + moo_ooi_t v; - v = STIX_OOP_TO_SMOOI(x); + v = MOO_OOP_TO_SMOOI(x); v = ~v; - if (STIX_IN_SMOOI_RANGE(v)) return STIX_SMOOI_TO_OOP(v); - return make_bigint_with_ooi (stix, v); + if (MOO_IN_SMOOI_RANGE(v)) return MOO_SMOOI_TO_OOP(v); + return make_bigint_with_ooi (moo, v); } else { - stix_oop_t z; - stix_oow_t i, xs, zs, zalloc; + moo_oop_t z; + moo_oow_t i, xs, zs, zalloc; int negx; - if (!is_bigint(stix,x)) goto oops_einval; + if (!is_bigint(moo,x)) goto oops_einval; - xs = STIX_OBJ_GET_SIZE(x); - negx = (STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer)? 1: 0; + xs = MOO_OBJ_GET_SIZE(x); + negx = (MOO_OBJ_GET_CLASS(x) == moo->_large_negative_integer)? 1: 0; if (negx) { @@ -2992,336 +2992,336 @@ stix_oop_t stix_bitinvint (stix_t* stix, stix_oop_t x) if (zalloc < zs) { /* overflow in zalloc calculation above */ - stix->errnum = STIX_EOOMEM; /* TODO: is it a soft failure or hard failure? */ - return STIX_NULL; + moo->errnum = MOO_EOOMEM; /* TODO: is it a soft failure or hard failure? */ + return MOO_NULL; } - stix_pushtmp (stix, &x); - z = stix_instantiate (stix, stix->_large_positive_integer, STIX_NULL, zalloc); - stix_poptmp (stix); - if (!z) return STIX_NULL; + moo_pushtmp (moo, &x); + z = moo_instantiate (moo, moo->_large_positive_integer, MOO_NULL, zalloc); + moo_poptmp (moo); + if (!z) return MOO_NULL; if (negx) { - stix_lidw_t w, carry; + moo_lidw_t w, carry; carry = 1; for (i = 0; i < xs; i++) { - w = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)x)->slot[i]) + carry; - carry = w >> STIX_LIW_BITS; - ((stix_oop_liword_t)z)->slot[i] = ~(stix_liw_t)w; + w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry; + carry = w >> MOO_LIW_BITS; + ((moo_oop_liword_t)z)->slot[i] = ~(moo_liw_t)w; } - STIX_ASSERT (stix, carry == 0); + MOO_ASSERT (moo, carry == 0); } else { - stix_lidw_t w, carry; + moo_lidw_t w, carry; #if 0 for (i = 0; i < xs; i++) { - ((stix_oop_liword_t)z)->slot[i] = ~((stix_oop_liword_t)x)->slot[i]; + ((moo_oop_liword_t)z)->slot[i] = ~((moo_oop_liword_t)x)->slot[i]; } - ((stix_oop_liword_t)z)->slot[zs] = ~(stix_liw_t)0; + ((moo_oop_liword_t)z)->slot[zs] = ~(moo_liw_t)0; carry = 1; for (i = 0; i <= zs; i++) { - w = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)z)->slot[i]) + carry; - carry = w >> STIX_LIW_BITS; - ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w; + w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)z)->slot[i]) + carry; + carry = w >> MOO_LIW_BITS; + ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w; } - STIX_ASSERT (stix, carry == 0); + MOO_ASSERT (moo, carry == 0); #else carry = 1; for (i = 0; i < xs; i++) { - w = (stix_lidw_t)(((stix_oop_liword_t)x)->slot[i]) + carry; - carry = w >> STIX_LIW_BITS; - ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w; + w = (moo_lidw_t)(((moo_oop_liword_t)x)->slot[i]) + carry; + carry = w >> MOO_LIW_BITS; + ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w; } - STIX_ASSERT (stix, i == zs); - ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)carry; - STIX_ASSERT (stix, (carry >> STIX_LIW_BITS) == 0); + MOO_ASSERT (moo, i == zs); + ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)carry; + MOO_ASSERT (moo, (carry >> MOO_LIW_BITS) == 0); #endif - STIX_OBJ_SET_CLASS (z, stix->_large_negative_integer); + MOO_OBJ_SET_CLASS (z, moo->_large_negative_integer); } - return normalize_bigint(stix, z); + return normalize_bigint(moo, z); } oops_einval: - stix->errnum = STIX_EINVAL; - return STIX_NULL; + moo->errnum = MOO_EINVAL; + return MOO_NULL; } -static STIX_INLINE stix_oop_t rshift_negative_bigint (stix_t* stix, stix_oop_t x, stix_oow_t shift) +static MOO_INLINE moo_oop_t rshift_negative_bigint (moo_t* moo, moo_oop_t x, moo_oow_t shift) { - stix_oop_t z; - stix_lidw_t w; - stix_lidw_t carry; - stix_oow_t i, xs; + moo_oop_t z; + moo_lidw_t w; + moo_lidw_t carry; + moo_oow_t i, xs; - STIX_ASSERT (stix, STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer); - xs = STIX_OBJ_GET_SIZE(x); + MOO_ASSERT (moo, MOO_OBJ_GET_CLASS(x) == moo->_large_negative_integer); + xs = MOO_OBJ_GET_SIZE(x); - stix_pushtmp (stix, &x); + moo_pushtmp (moo, &x); /* +1 for the second inversion below */ - z = stix_instantiate (stix, stix->_large_negative_integer, STIX_NULL, xs + 1); - stix_poptmp (stix); - if (!z) return STIX_NULL; + z = moo_instantiate (moo, moo->_large_negative_integer, MOO_NULL, xs + 1); + moo_poptmp (moo); + if (!z) return MOO_NULL; - /* the following lines roughly for 'z = stix_bitinv (stix, x)' */ + /* the following lines roughly for 'z = moo_bitinv (moo, x)' */ carry = 1; for (i = 0; i < xs; i++) { - w = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)x)->slot[i]) + carry; - carry = w >> STIX_LIW_BITS; - ((stix_oop_liword_t)z)->slot[i] = ~(stix_liw_t)w; + w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)x)->slot[i]) + carry; + carry = w >> MOO_LIW_BITS; + ((moo_oop_liword_t)z)->slot[i] = ~(moo_liw_t)w; } - STIX_ASSERT (stix, carry == 0); + MOO_ASSERT (moo, carry == 0); /* shift to the right */ - rshift_unsigned_array (((stix_oop_liword_t)z)->slot, xs, shift); + rshift_unsigned_array (((moo_oop_liword_t)z)->slot, xs, shift); - /* the following lines roughly for 'z = stix_bitinv (stix, z)' */ + /* the following lines roughly for 'z = moo_bitinv (moo, z)' */ #if 0 for (i = 0; i < xs; i++) { - ((stix_oop_liword_t)z)->slot[i] = ~((stix_oop_liword_t)z)->slot[i]; + ((moo_oop_liword_t)z)->slot[i] = ~((moo_oop_liword_t)z)->slot[i]; } - ((stix_oop_liword_t)z)->slot[xs] = ~(stix_liw_t)0; + ((moo_oop_liword_t)z)->slot[xs] = ~(moo_liw_t)0; carry = 1; for (i = 0; i <= xs; i++) { - w = (stix_lidw_t)((stix_liw_t)~((stix_oop_liword_t)z)->slot[i]) + carry; - carry = w >> STIX_LIW_BITS; - ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w; + w = (moo_lidw_t)((moo_liw_t)~((moo_oop_liword_t)z)->slot[i]) + carry; + carry = w >> MOO_LIW_BITS; + ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w; } - STIX_ASSERT (stix, carry == 0); + MOO_ASSERT (moo, carry == 0); #else carry = 1; for (i = 0; i < xs; i++) { - w = (stix_lidw_t)(((stix_oop_liword_t)z)->slot[i]) + carry; - carry = w >> STIX_LIW_BITS; - ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w; + w = (moo_lidw_t)(((moo_oop_liword_t)z)->slot[i]) + carry; + carry = w >> MOO_LIW_BITS; + ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)w; } - ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)carry; - STIX_ASSERT (stix, (carry >> STIX_LIW_BITS) == 0); + ((moo_oop_liword_t)z)->slot[i] = (moo_liw_t)carry; + MOO_ASSERT (moo, (carry >> MOO_LIW_BITS) == 0); #endif return z; /* z is not normalized */ } -#if defined(STIX_LIMIT_OBJ_SIZE) +#if defined(MOO_LIMIT_OBJ_SIZE) /* nothing */ #else -static STIX_INLINE stix_oop_t rshift_negative_bigint_and_normalize (stix_t* stix, stix_oop_t x, stix_oop_t y) +static MOO_INLINE moo_oop_t rshift_negative_bigint_and_normalize (moo_t* moo, moo_oop_t x, moo_oop_t y) { - stix_oop_t z; - stix_oow_t shift; + moo_oop_t z; + moo_oow_t shift; int sign; - STIX_ASSERT (stix, STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer); - STIX_ASSERT (stix, STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer); + MOO_ASSERT (moo, MOO_OBJ_GET_CLASS(x) == moo->_large_negative_integer); + MOO_ASSERT (moo, MOO_OBJ_GET_CLASS(y) == moo->_large_negative_integer); /* for convenience in subtraction below. - * it could be STIX_TYPE_MAX(stix_oow_t) + * it could be MOO_TYPE_MAX(moo_oow_t) * if make_bigint_with_intmax() or something - * similar were used instead of STIX_SMOOI_TO_OOP().*/ - shift = STIX_SMOOI_MAX; + * similar were used instead of MOO_SMOOI_TO_OOP().*/ + shift = MOO_SMOOI_MAX; do { - stix_pushtmp (stix, &y); - z = rshift_negative_bigint (stix, x, shift); - stix_poptmp (stix); - if (!z) return STIX_NULL; + moo_pushtmp (moo, &y); + z = rshift_negative_bigint (moo, x, shift); + moo_poptmp (moo); + if (!z) return MOO_NULL; - /* y is a negative number. use stix_addints() until it becomes 0 */ - stix_pushtmp (stix, &z); - y = stix_addints (stix, y, STIX_SMOOI_TO_OOP(shift)); - stix_poptmp (stix); - if (!y) return STIX_NULL; + /* y is a negative number. use moo_addints() until it becomes 0 */ + moo_pushtmp (moo, &z); + y = moo_addints (moo, y, MOO_SMOOI_TO_OOP(shift)); + moo_poptmp (moo); + if (!y) return MOO_NULL; - sign = integer_to_oow (stix, y, &shift); - if (sign == 0) shift = STIX_SMOOI_MAX; + sign = integer_to_oow (moo, y, &shift); + if (sign == 0) shift = MOO_SMOOI_MAX; else { if (shift == 0) { /* no more shift */ - return normalize_bigint (stix, z); + return normalize_bigint (moo, z); } - STIX_ASSERT (stix, sign <= -1); + MOO_ASSERT (moo, sign <= -1); } - stix_pushtmp (stix, &y); - x = normalize_bigint (stix, z); - stix_poptmp (stix); - if (!x) return STIX_NULL; + moo_pushtmp (moo, &y); + x = normalize_bigint (moo, z); + moo_poptmp (moo); + if (!x) return MOO_NULL; - if (STIX_OOP_IS_SMOOI(x)) + if (MOO_OOP_IS_SMOOI(x)) { /* for normaization above, x can become a small integer */ - stix_ooi_t v; + moo_ooi_t v; - v = STIX_OOP_TO_SMOOI(x); - STIX_ASSERT (stix, v < 0); + v = MOO_OOP_TO_SMOOI(x); + MOO_ASSERT (moo, v < 0); /* normal right shift of a small negative integer */ - if (shift >= STIX_OOI_BITS - 1) + if (shift >= MOO_OOI_BITS - 1) { /* when y is still a large integer, this condition is met - * met as STIX_SMOOI_MAX > STIX_OOI_BITS. so i can simly + * met as MOO_SMOOI_MAX > MOO_OOI_BITS. so i can simly * terminate the loop after this */ - return STIX_SMOOI_TO_OOP(-1); + return MOO_SMOOI_TO_OOP(-1); } else { - v = (stix_ooi_t)(((stix_oow_t)v >> shift) | STIX_HBMASK(stix_oow_t, shift)); - if (STIX_IN_SMOOI_RANGE(v)) - return STIX_SMOOI_TO_OOP(v); + v = (moo_ooi_t)(((moo_oow_t)v >> shift) | MOO_HBMASK(moo_oow_t, shift)); + if (MOO_IN_SMOOI_RANGE(v)) + return MOO_SMOOI_TO_OOP(v); else - return make_bigint_with_ooi (stix, v); + return make_bigint_with_ooi (moo, v); } } } while (1); /* this part must not be reached */ - STIX_ASSERT (stix, !"internal error - must not happen"); - stix->errnum = STIX_EINTERN; - return STIX_NULL; + MOO_ASSERT (moo, !"internal error - must not happen"); + moo->errnum = MOO_EINTERN; + return MOO_NULL; } -static STIX_INLINE stix_oop_t rshift_positive_bigint_and_normalize (stix_t* stix, stix_oop_t x, stix_oop_t y) +static MOO_INLINE moo_oop_t rshift_positive_bigint_and_normalize (moo_t* moo, moo_oop_t x, moo_oop_t y) { - stix_oop_t z; - stix_oow_t zs, shift; + moo_oop_t z; + moo_oow_t zs, shift; int sign; - STIX_ASSERT (stix, STIX_OBJ_GET_CLASS(x) == stix->_large_positive_integer); - STIX_ASSERT (stix, STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer); + MOO_ASSERT (moo, MOO_OBJ_GET_CLASS(x) == moo->_large_positive_integer); + MOO_ASSERT (moo, MOO_OBJ_GET_CLASS(y) == moo->_large_negative_integer); - zs = STIX_OBJ_GET_SIZE(x); + zs = MOO_OBJ_GET_SIZE(x); - stix_pushtmp (stix, &y); - z = clone_bigint (stix, x, zs); - stix_poptmp (stix); - if (!z) return STIX_NULL; + moo_pushtmp (moo, &y); + z = clone_bigint (moo, x, zs); + moo_poptmp (moo); + if (!z) return MOO_NULL; /* for convenience in subtraction below. - * it could be STIX_TYPE_MAX(stix_oow_t) + * it could be MOO_TYPE_MAX(moo_oow_t) * if make_bigint_with_intmax() or something - * similar were used instead of STIX_SMOOI_TO_OOP().*/ - shift = STIX_SMOOI_MAX; + * similar were used instead of MOO_SMOOI_TO_OOP().*/ + shift = MOO_SMOOI_MAX; do { - rshift_unsigned_array (((stix_oop_liword_t)z)->slot, zs, shift); - if (count_effective (((stix_oop_liword_t)z)->slot, zs) == 1 && - ((stix_oop_liword_t)z)->slot[0] == 0) + rshift_unsigned_array (((moo_oop_liword_t)z)->slot, zs, shift); + if (count_effective (((moo_oop_liword_t)z)->slot, zs) == 1 && + ((moo_oop_liword_t)z)->slot[0] == 0) { /* if z is 0, i don't have to go on */ break; } - /* y is a negative number. use stix_addints() until it becomes 0 */ - stix_pushtmp (stix, &z); - y = stix_addints (stix, y, STIX_SMOOI_TO_OOP(shift)); - stix_poptmp (stix); - if (!y) return STIX_NULL; + /* y is a negative number. use moo_addints() until it becomes 0 */ + moo_pushtmp (moo, &z); + y = moo_addints (moo, y, MOO_SMOOI_TO_OOP(shift)); + moo_poptmp (moo); + if (!y) return MOO_NULL; - sign = integer_to_oow (stix, y, &shift); - if (sign == 0) shift = STIX_SMOOI_MAX; + sign = integer_to_oow (moo, y, &shift); + if (sign == 0) shift = MOO_SMOOI_MAX; else { if (shift == 0) break; - STIX_ASSERT (stix, sign <= -1); + MOO_ASSERT (moo, sign <= -1); } } while (1); - return normalize_bigint(stix, z); + return normalize_bigint(moo, z); } -static STIX_INLINE stix_oop_t lshift_bigint_and_normalize (stix_t* stix, stix_oop_t x, stix_oop_t y) +static MOO_INLINE moo_oop_t lshift_bigint_and_normalize (moo_t* moo, moo_oop_t x, moo_oop_t y) { - stix_oop_t z; - stix_oow_t wshift, shift; + moo_oop_t z; + moo_oow_t wshift, shift; int sign; - STIX_ASSERT (stix, STIX_OBJ_GET_CLASS(y) == stix->_large_positive_integer); + MOO_ASSERT (moo, MOO_OBJ_GET_CLASS(y) == moo->_large_positive_integer); /* this loop is very inefficient as shifting is repeated * with lshift_unsigned_array(). however, this part of the * code is not likey to be useful because the amount of * memory available is certainly not enough to support - * huge shifts greater than STIX_TYPE_MAX(stix_oow_t) */ - shift = STIX_SMOOI_MAX; + * huge shifts greater than MOO_TYPE_MAX(moo_oow_t) */ + shift = MOO_SMOOI_MAX; do { /* for convenience only in subtraction below. - * should it be between STIX_SMOOI_MAX and STIX_TYPE_MAX(stix_oow_t), - * the second parameter to stix_subints() can't be composed - * using STIX_SMOOI_TO_OOP() */ - wshift = shift / STIX_LIW_BITS; - if (shift > wshift * STIX_LIW_BITS) wshift++; + * should it be between MOO_SMOOI_MAX and MOO_TYPE_MAX(moo_oow_t), + * the second parameter to moo_subints() can't be composed + * using MOO_SMOOI_TO_OOP() */ + wshift = shift / MOO_LIW_BITS; + if (shift > wshift * MOO_LIW_BITS) wshift++; - stix_pushtmp (stix, &y); - z = expand_bigint (stix, x, wshift); - stix_poptmp (stix); - if (!z) return STIX_NULL; + moo_pushtmp (moo, &y); + z = expand_bigint (moo, x, wshift); + moo_poptmp (moo); + if (!z) return MOO_NULL; - lshift_unsigned_array (((stix_oop_liword_t)z)->slot, STIX_OBJ_GET_SIZE(z), shift); + lshift_unsigned_array (((moo_oop_liword_t)z)->slot, MOO_OBJ_GET_SIZE(z), shift); - stix_pushtmp (stix, &y); - x = normalize_bigint (stix, z); - stix_poptmp (stix); - if (!x) return STIX_NULL; + moo_pushtmp (moo, &y); + x = normalize_bigint (moo, z); + moo_poptmp (moo); + if (!x) return MOO_NULL; - stix_pushtmp (stix, &x); - y = stix_subints (stix, y, STIX_SMOOI_TO_OOP(shift)); - stix_poptmp (stix); - if (!y) return STIX_NULL; + moo_pushtmp (moo, &x); + y = moo_subints (moo, y, MOO_SMOOI_TO_OOP(shift)); + moo_poptmp (moo); + if (!y) return MOO_NULL; - sign = integer_to_oow (stix, y, &shift); - if (sign == 0) shift = STIX_SMOOI_MAX; + sign = integer_to_oow (moo, y, &shift); + if (sign == 0) shift = MOO_SMOOI_MAX; else { if (shift == 0) { - STIX_ASSERT (stix, is_normalized_integer (stix, x)); + MOO_ASSERT (moo, is_normalized_integer (moo, x)); return x; } - STIX_ASSERT (stix, sign >= 1); + MOO_ASSERT (moo, sign >= 1); } } while (1); /* this part must not be reached */ - STIX_ASSERT (stix, !"internal error - must not happen"); - stix->errnum = STIX_EINTERN; - return STIX_NULL; + MOO_ASSERT (moo, !"internal error - must not happen"); + moo->errnum = MOO_EINTERN; + return MOO_NULL; } #endif -stix_oop_t stix_bitshiftint (stix_t* stix, stix_oop_t x, stix_oop_t y) +moo_oop_t moo_bitshiftint (moo_t* moo, moo_oop_t x, moo_oop_t y) { /* left shift if y is positive, * right shift if y is negative */ - if (STIX_OOP_IS_SMOOI(x) && STIX_OOP_IS_SMOOI(y)) + if (MOO_OOP_IS_SMOOI(x) && MOO_OOP_IS_SMOOI(y)) { - stix_ooi_t v1, v2; + moo_ooi_t v1, v2; - v1 = STIX_OOP_TO_SMOOI(x); - v2 = STIX_OOP_TO_SMOOI(y); + v1 = MOO_OOP_TO_SMOOI(x); + v2 = MOO_OOP_TO_SMOOI(y); if (v1 == 0 || v2 == 0) { /* return without cloning as x is a small integer */ @@ -3331,22 +3331,22 @@ stix_oop_t stix_bitshiftint (stix_t* stix, stix_oop_t x, stix_oop_t y) if (v2 > 0) { /* left shift */ - stix_oop_t z; - stix_oow_t wshift; + moo_oop_t z; + moo_oow_t wshift; - wshift = v2 / STIX_LIW_BITS; - if (v2 > wshift * STIX_LIW_BITS) wshift++; + wshift = v2 / MOO_LIW_BITS; + if (v2 > wshift * MOO_LIW_BITS) wshift++; - z = make_bloated_bigint_with_ooi (stix, v1, wshift); - if (!z) return STIX_NULL; + z = make_bloated_bigint_with_ooi (moo, v1, wshift); + if (!z) return MOO_NULL; - lshift_unsigned_array (((stix_oop_liword_t)z)->slot, STIX_OBJ_GET_SIZE(z), v2); - return normalize_bigint (stix, z); + lshift_unsigned_array (((moo_oop_liword_t)z)->slot, MOO_OBJ_GET_SIZE(z), v2); + return normalize_bigint (moo, z); } else { /* right shift */ - stix_ooi_t v; + moo_ooi_t v; v2 = -v2; if (v1 < 0) @@ -3367,64 +3367,64 @@ stix_oop_t stix_bitshiftint (stix_t* stix, stix_oop_t x, stix_oop_t y) * 11111111 (-1) 8 */ - if (v2 >= STIX_OOI_BITS - 1) v = -1; + if (v2 >= MOO_OOI_BITS - 1) v = -1; else { - /* STIX_HBMASK_SAFE(stix_oow_t, v2 + 1) could also be + /* MOO_HBMASK_SAFE(moo_oow_t, v2 + 1) could also be * used as a mask. but the sign bit is shifted in. * so, masking up to 'v2' bits is sufficient */ - v = (stix_ooi_t)(((stix_oow_t)v1 >> v2) | STIX_HBMASK(stix_oow_t, v2)); + v = (moo_ooi_t)(((moo_oow_t)v1 >> v2) | MOO_HBMASK(moo_oow_t, v2)); } } else { - if (v2 >= STIX_OOI_BITS) v = 0; + if (v2 >= MOO_OOI_BITS) v = 0; else v = v1 >> v2; } - if (STIX_IN_SMOOI_RANGE(v)) return STIX_SMOOI_TO_OOP(v); - return make_bigint_with_ooi (stix, v); + if (MOO_IN_SMOOI_RANGE(v)) return MOO_SMOOI_TO_OOP(v); + return make_bigint_with_ooi (moo, v); } } else { int sign, negx, negy; - stix_oow_t shift; + moo_oow_t shift; - if (STIX_OOP_IS_SMOOI(x)) + if (MOO_OOP_IS_SMOOI(x)) { - stix_ooi_t v; + moo_ooi_t v; - if (!is_bigint(stix,y)) goto oops_einval; + if (!is_bigint(moo,y)) goto oops_einval; - v = STIX_OOP_TO_SMOOI(x); - if (v == 0) return STIX_SMOOI_TO_OOP(0); + v = MOO_OOP_TO_SMOOI(x); + if (v == 0) return MOO_SMOOI_TO_OOP(0); - if (STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer) + if (MOO_OBJ_GET_CLASS(y) == moo->_large_negative_integer) { /* right shift - special case. * x is a small integer. it is just a few bytes long. * y is a large negative integer. its smallest absolute value - * is STIX_SMOOI_MAX. i know the final answer. */ - return (v < 0)? STIX_SMOOI_TO_OOP(-1): STIX_SMOOI_TO_OOP(0); + * is MOO_SMOOI_MAX. i know the final answer. */ + return (v < 0)? MOO_SMOOI_TO_OOP(-1): MOO_SMOOI_TO_OOP(0); } - stix_pushtmp (stix, &y); - x = make_bigint_with_ooi (stix, v); - stix_poptmp (stix); - if (!x) return STIX_NULL; + moo_pushtmp (moo, &y); + x = make_bigint_with_ooi (moo, v); + moo_poptmp (moo); + if (!x) return MOO_NULL; goto bigint_and_bigint; } - else if (STIX_OOP_IS_SMOOI(y)) + else if (MOO_OOP_IS_SMOOI(y)) { - stix_ooi_t v; + moo_ooi_t v; - if (!is_bigint(stix,x)) goto oops_einval; + if (!is_bigint(moo,x)) goto oops_einval; - v = STIX_OOP_TO_SMOOI(y); - if (v == 0) return clone_bigint (stix, x, STIX_OBJ_GET_SIZE(x)); + v = MOO_OOP_TO_SMOOI(y); + if (v == 0) return clone_bigint (moo, x, MOO_OBJ_GET_SIZE(x)); - negx = (STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer)? 1: 0; + negx = (MOO_OBJ_GET_CLASS(x) == moo->_large_negative_integer)? 1: 0; if (v > 0) { sign = 1; @@ -3442,94 +3442,94 @@ stix_oop_t stix_bitshiftint (stix_t* stix, stix_oop_t x, stix_oop_t y) } else { - stix_oop_t z; + moo_oop_t z; - if (!is_bigint(stix,x) || !is_bigint(stix, y)) goto oops_einval; + if (!is_bigint(moo,x) || !is_bigint(moo, y)) goto oops_einval; bigint_and_bigint: - negx = (STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer)? 1: 0; - negy = (STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer)? 1: 0; + negx = (MOO_OBJ_GET_CLASS(x) == moo->_large_negative_integer)? 1: 0; + negy = (MOO_OBJ_GET_CLASS(y) == moo->_large_negative_integer)? 1: 0; - sign = bigint_to_oow (stix, y, &shift); + sign = bigint_to_oow (moo, y, &shift); if (sign == 0) { /* y is too big or too small */ if (negy) { /* right shift */ - #if defined(STIX_LIMIT_OBJ_SIZE) + #if defined(MOO_LIMIT_OBJ_SIZE) /* the maximum number of bit shifts are guaranteed to be - * small enough to fit into the stix_oow_t type. so i can + * small enough to fit into the moo_oow_t type. so i can * easily assume that all bits are shifted out */ - STIX_ASSERT (stix, STIX_OBJ_SIZE_BITS_MAX <= STIX_TYPE_MAX(stix_oow_t)); - return (negx)? STIX_SMOOI_TO_OOP(-1): STIX_SMOOI_TO_OOP(0); + MOO_ASSERT (moo, MOO_OBJ_SIZE_BITS_MAX <= MOO_TYPE_MAX(moo_oow_t)); + return (negx)? MOO_SMOOI_TO_OOP(-1): MOO_SMOOI_TO_OOP(0); #else if (negx) - return rshift_negative_bigint_and_normalize (stix, x, y); + return rshift_negative_bigint_and_normalize (moo, x, y); else - return rshift_positive_bigint_and_normalize (stix, x, y); + return rshift_positive_bigint_and_normalize (moo, x, y); #endif } else { /* left shift */ - #if defined(STIX_LIMIT_OBJ_SIZE) + #if defined(MOO_LIMIT_OBJ_SIZE) /* the maximum number of bit shifts are guaranteed to be - * small enough to fit into the stix_oow_t type. so i can + * small enough to fit into the moo_oow_t type. so i can * simply return a failure here becuase it's surely too * large after shifting */ - STIX_ASSERT (stix, STIX_TYPE_MAX(stix_oow_t) >= STIX_OBJ_SIZE_BITS_MAX); - stix->errnum = STIX_EOOMEM; /* is it a soft failure or a hard failure? is this error code proper? */ - return STIX_NULL; + MOO_ASSERT (moo, MOO_TYPE_MAX(moo_oow_t) >= MOO_OBJ_SIZE_BITS_MAX); + moo->errnum = MOO_EOOMEM; /* is it a soft failure or a hard failure? is this error code proper? */ + return MOO_NULL; #else - return lshift_bigint_and_normalize (stix, x, y); + return lshift_bigint_and_normalize (moo, x, y); #endif } } else if (sign >= 1) { /* left shift */ - stix_oow_t wshift; + moo_oow_t wshift; bigint_and_positive_oow: - wshift = shift / STIX_LIW_BITS; - if (shift > wshift * STIX_LIW_BITS) wshift++; + wshift = shift / MOO_LIW_BITS; + if (shift > wshift * MOO_LIW_BITS) wshift++; - z = expand_bigint (stix, x, wshift); - if (!z) return STIX_NULL; + z = expand_bigint (moo, x, wshift); + if (!z) return MOO_NULL; - lshift_unsigned_array (((stix_oop_liword_t)z)->slot, STIX_OBJ_GET_SIZE(z), shift); + lshift_unsigned_array (((moo_oop_liword_t)z)->slot, MOO_OBJ_GET_SIZE(z), shift); } else { /* right shift */ bigint_and_negative_oow: - STIX_ASSERT (stix, sign <= -1); + MOO_ASSERT (moo, sign <= -1); if (negx) { - z = rshift_negative_bigint (stix, x, shift); - if (!z) return STIX_NULL; + z = rshift_negative_bigint (moo, x, shift); + if (!z) return MOO_NULL; } else { - z = clone_bigint (stix, x, STIX_OBJ_GET_SIZE(x)); - if (!z) return STIX_NULL; - rshift_unsigned_array (((stix_oop_liword_t)z)->slot, STIX_OBJ_GET_SIZE(z), shift); + z = clone_bigint (moo, x, MOO_OBJ_GET_SIZE(x)); + if (!z) return MOO_NULL; + rshift_unsigned_array (((moo_oop_liword_t)z)->slot, MOO_OBJ_GET_SIZE(z), shift); } } - return normalize_bigint(stix, z); + return normalize_bigint(moo, z); } } oops_einval: - stix->errnum = STIX_EINVAL; - return STIX_NULL; + moo->errnum = MOO_EINVAL; + return MOO_NULL; } -static stix_uint8_t ooch_val_tab[] = +static moo_uint8_t ooch_val_tab[] = { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, @@ -3541,14 +3541,14 @@ static stix_uint8_t ooch_val_tab[] = 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 99, 99, 99, 99, 99 }; -stix_oop_t stix_strtoint (stix_t* stix, const stix_ooch_t* str, stix_oow_t len, int radix) +moo_oop_t moo_strtoint (moo_t* moo, const moo_ooch_t* str, moo_oow_t len, int radix) { int sign = 1; - const stix_ooch_t* ptr, * start, * end; - stix_lidw_t w, v; - stix_liw_t hw[16], * hwp = STIX_NULL; - stix_oow_t hwlen, outlen; - stix_oop_t res; + const moo_ooch_t* ptr, * start, * end; + moo_lidw_t w, v; + moo_liw_t hw[16], * hwp = MOO_NULL; + moo_oow_t hwlen, outlen; + moo_oop_t res; if (radix < 0) { @@ -3557,7 +3557,7 @@ stix_oop_t stix_strtoint (stix_t* stix, const stix_ooch_t* str, stix_oow_t len, radix = -radix; } - STIX_ASSERT (stix, radix >= 2 && radix <= 36); + MOO_ASSERT (moo, radix >= 2 && radix <= 36); ptr = str; end = str + len; @@ -3582,7 +3582,7 @@ stix_oop_t stix_strtoint (stix_t* stix, const stix_ooch_t* str, stix_oow_t len, if (ptr >= end) { /* all zeros */ - return STIX_SMOOI_TO_OOP(0); + return MOO_SMOOI_TO_OOP(0); } hwlen = 0; @@ -3596,7 +3596,7 @@ stix_oop_t stix_strtoint (stix_t* stix, const stix_ooch_t* str, stix_oow_t len, /* get log2(radix) in a fast way under the fact that * radix is a power of 2. the exponent acquired is * the number of bits that a digit of the given radix takes up */ - #if defined(STIX_HAVE_BUILTIN_CTZ) + #if defined(MOO_HAVE_BUILTIN_CTZ) exp = __builtin_ctz(radix); #elif defined(__GNUC__) && (defined(__x86_64) || defined(__amd64) || defined(__i386) || defined(i386)) @@ -3618,7 +3618,7 @@ stix_oop_t stix_strtoint (stix_t* stix, const stix_ooch_t* str, stix_oow_t len, : "=r"(exp) /* output */ : "r"(radix) /* input */ ); - exp = (STIX_SIZEOF(exp) * 8) - exp - 1; + exp = (MOO_SIZEOF(exp) * 8) - exp - 1; /* TODO: PPC - use cntlz, cntlzw, cntlzd, SPARC - use lzcnt, MIPS clz */ #else @@ -3626,14 +3626,14 @@ stix_oop_t stix_strtoint (stix_t* stix, const stix_ooch_t* str, stix_oow_t len, #endif /* bytes */ - outlen = ((stix_oow_t)(end - str) * exp + 7) / 8; - /* number of stix_liw_t */ - outlen = (outlen + STIX_SIZEOF(hw[0]) - 1) / STIX_SIZEOF(hw[0]); + outlen = ((moo_oow_t)(end - str) * exp + 7) / 8; + /* number of moo_liw_t */ + outlen = (outlen + MOO_SIZEOF(hw[0]) - 1) / MOO_SIZEOF(hw[0]); - if (outlen > STIX_COUNTOF(hw)) + if (outlen > MOO_COUNTOF(hw)) { - hwp = stix_allocmem (stix, outlen * STIX_SIZEOF(hw[0])); - if (!hwp) return STIX_NULL; + hwp = moo_allocmem (moo, outlen * MOO_SIZEOF(hw[0])); + if (!hwp) return MOO_NULL; } else { @@ -3646,49 +3646,49 @@ stix_oop_t stix_strtoint (stix_t* stix, const stix_ooch_t* str, stix_oow_t len, while (ptr >= start) { - if (*ptr < 0 || *ptr >= STIX_COUNTOF(ooch_val_tab)) goto oops_einval; + if (*ptr < 0 || *ptr >= MOO_COUNTOF(ooch_val_tab)) goto oops_einval; v = ooch_val_tab[*ptr]; if (v >= radix) goto oops_einval; w |= (v << bitcnt); bitcnt += exp; - if (bitcnt >= STIX_LIW_BITS) + if (bitcnt >= MOO_LIW_BITS) { - bitcnt -= STIX_LIW_BITS; - hwp[hwlen++] = w; /*(stix_liw_t)(w & STIX_LBMASK(stix_lidw_t, STIX_LIW_BITS));*/ - w >>= STIX_LIW_BITS; + bitcnt -= MOO_LIW_BITS; + hwp[hwlen++] = w; /*(moo_liw_t)(w & MOO_LBMASK(moo_lidw_t, MOO_LIW_BITS));*/ + w >>= MOO_LIW_BITS; } ptr--; } - STIX_ASSERT (stix, w <= STIX_TYPE_MAX(stix_liw_t)); + MOO_ASSERT (moo, w <= MOO_TYPE_MAX(moo_liw_t)); if (hwlen == 0 || w > 0) hwp[hwlen++] = w; } else { - stix_lidw_t r1, r2; - stix_liw_t multiplier; + moo_lidw_t r1, r2; + moo_liw_t multiplier; int dg, i, safe_ndigits; w = 0; ptr = start; - safe_ndigits = stix->bigint[radix].safe_ndigits; - multiplier = (stix_liw_t)stix->bigint[radix].multiplier; + safe_ndigits = moo->bigint[radix].safe_ndigits; + multiplier = (moo_liw_t)moo->bigint[radix].multiplier; outlen = (end - str) / safe_ndigits + 1; - if (outlen > STIX_COUNTOF(hw)) + if (outlen > MOO_COUNTOF(hw)) { - hwp = stix_allocmem (stix, outlen * STIX_SIZEOF(stix_liw_t)); - if (!hwp) return STIX_NULL; + hwp = moo_allocmem (moo, outlen * MOO_SIZEOF(moo_liw_t)); + if (!hwp) return MOO_NULL; } else { hwp = hw; } - STIX_ASSERT (stix, ptr < end); + MOO_ASSERT (moo, ptr < end); do { r1 = 0; @@ -3701,11 +3701,11 @@ stix_oop_t stix_strtoint (stix_t* stix, const stix_ooch_t* str, stix_oow_t len, break; } - if (*ptr < 0 || *ptr >= STIX_COUNTOF(ooch_val_tab)) goto oops_einval; + if (*ptr < 0 || *ptr >= MOO_COUNTOF(ooch_val_tab)) goto oops_einval; v = ooch_val_tab[*ptr]; if (v >= radix) goto oops_einval; - r1 = r1 * radix + (stix_liw_t)v; + r1 = r1 * radix + (moo_liw_t)v; ptr++; } @@ -3713,11 +3713,11 @@ stix_oop_t stix_strtoint (stix_t* stix, const stix_ooch_t* str, stix_oow_t len, r2 = r1; for (i = 0; i < hwlen; i++) { - stix_liw_t high, low; + moo_liw_t high, low; - v = (stix_lidw_t)hwp[i] * multiplier; - high = (stix_liw_t)(v >> STIX_LIW_BITS); - low = (stix_liw_t)(v /*& STIX_LBMASK(stix_oow_t, STIX_LIW_BITS)*/); + v = (moo_lidw_t)hwp[i] * multiplier; + high = (moo_liw_t)(v >> MOO_LIW_BITS); + low = (moo_liw_t)(v /*& MOO_LBMASK(moo_oow_t, MOO_LIW_BITS)*/); #if defined(liw_add_overflow) /* use liw_add_overflow() only if it's compiler-builtin. */ @@ -3725,56 +3725,56 @@ stix_oop_t stix_strtoint (stix_t* stix, const stix_ooch_t* str, stix_oow_t len, #else /* don't use the fall-back version of liw_add_overflow() */ low += r2; - r2 = (stix_lidw_t)high + (low < r2); + r2 = (moo_lidw_t)high + (low < r2); #endif hwp[i] = low; } - if (r2) hwp[hwlen++] = (stix_liw_t)r2; + if (r2) hwp[hwlen++] = (moo_liw_t)r2; } while (ptr < end); } - STIX_ASSERT (stix, hwlen >= 1); + MOO_ASSERT (moo, hwlen >= 1); -#if (STIX_LIW_BITS == STIX_OOW_BITS) +#if (MOO_LIW_BITS == MOO_OOW_BITS) if (hwlen == 1) { w = hwp[0]; - STIX_ASSERT (stix, -STIX_SMOOI_MAX == STIX_SMOOI_MIN); - if (w <= STIX_SMOOI_MAX) return STIX_SMOOI_TO_OOP((stix_ooi_t)w * sign); + MOO_ASSERT (moo, -MOO_SMOOI_MAX == MOO_SMOOI_MIN); + if (w <= MOO_SMOOI_MAX) return MOO_SMOOI_TO_OOP((moo_ooi_t)w * sign); } -#elif (STIX_LIW_BITS == STIX_OOHW_BITS) +#elif (MOO_LIW_BITS == MOO_OOHW_BITS) if (hwlen == 1) { - STIX_ASSERT (stix, hwp[0] <= STIX_SMOOI_MAX); - return STIX_SMOOI_TO_OOP((stix_ooi_t)hwp[0] * sign); + MOO_ASSERT (moo, hwp[0] <= MOO_SMOOI_MAX); + return MOO_SMOOI_TO_OOP((moo_ooi_t)hwp[0] * sign); } else if (hwlen == 2) { w = MAKE_WORD(hwp[0], hwp[1]); - STIX_ASSERT (stix, -STIX_SMOOI_MAX == STIX_SMOOI_MIN); - if (w <= STIX_SMOOI_MAX) return STIX_SMOOI_TO_OOP((stix_ooi_t)w * sign); + MOO_ASSERT (moo, -MOO_SMOOI_MAX == MOO_SMOOI_MIN); + if (w <= MOO_SMOOI_MAX) return MOO_SMOOI_TO_OOP((moo_ooi_t)w * sign); } #else # error UNSUPPORTED LIW BIT SIZE #endif - res = stix_instantiate (stix, (sign < 0? stix->_large_negative_integer: stix->_large_positive_integer), hwp, hwlen); - if (hwp && hw != hwp) stix_freemem (stix, hwp); + res = moo_instantiate (moo, (sign < 0? moo->_large_negative_integer: moo->_large_positive_integer), hwp, hwlen); + if (hwp && hw != hwp) moo_freemem (moo, hwp); return res; oops_einval: - if (hwp && hw != hwp) stix_freemem (stix, hwp); - stix->errnum = STIX_EINVAL; - return STIX_NULL; + if (hwp && hw != hwp) moo_freemem (moo, hwp); + moo->errnum = MOO_EINVAL; + return MOO_NULL; } -static stix_oow_t oow_to_text (stix_t* stix, stix_oow_t w, int radix, stix_ooch_t* buf) +static moo_oow_t oow_to_text (moo_t* moo, moo_oow_t w, int radix, moo_ooch_t* buf) { - stix_ooch_t* ptr; - STIX_ASSERT (stix, radix >= 2 && radix <= 36); + moo_ooch_t* ptr; + MOO_ASSERT (moo, radix >= 2 && radix <= 36); ptr = buf; do @@ -3787,11 +3787,11 @@ static stix_oow_t oow_to_text (stix_t* stix, stix_oow_t w, int radix, stix_ooch_ return ptr - buf; } -static void reverse_string (stix_ooch_t* str, stix_oow_t len) +static void reverse_string (moo_ooch_t* str, moo_oow_t len) { - stix_ooch_t ch; - stix_ooch_t* start = str; - stix_ooch_t* end = str + len - 1; + moo_ooch_t ch; + moo_ooch_t* start = str; + moo_ooch_t* end = str + len - 1; while (start < end) { @@ -3801,178 +3801,178 @@ static void reverse_string (stix_ooch_t* str, stix_oow_t len) } } -stix_oop_t stix_eqints (stix_t* stix, stix_oop_t x, stix_oop_t y) +moo_oop_t moo_eqints (moo_t* moo, moo_oop_t x, moo_oop_t y) { - if (STIX_OOP_IS_SMOOI(x) && STIX_OOP_IS_SMOOI(y)) + if (MOO_OOP_IS_SMOOI(x) && MOO_OOP_IS_SMOOI(y)) { - return (STIX_OOP_TO_SMOOI(x) == STIX_OOP_TO_SMOOI(y))? stix->_true: stix->_false; + return (MOO_OOP_TO_SMOOI(x) == MOO_OOP_TO_SMOOI(y))? moo->_true: moo->_false; } - else if (STIX_OOP_IS_SMOOI(x) || STIX_OOP_IS_SMOOI(y)) + else if (MOO_OOP_IS_SMOOI(x) || MOO_OOP_IS_SMOOI(y)) { - return stix->_false; + return moo->_false; } else { - if (!is_bigint(stix, x) || !is_bigint(stix, y)) goto oops_einval; - return is_equal(stix, x, y)? stix->_true: stix->_false; + if (!is_bigint(moo, x) || !is_bigint(moo, y)) goto oops_einval; + return is_equal(moo, x, y)? moo->_true: moo->_false; } oops_einval: - stix->errnum = STIX_EINVAL; - return STIX_NULL; + moo->errnum = MOO_EINVAL; + return MOO_NULL; } -stix_oop_t stix_neints (stix_t* stix, stix_oop_t x, stix_oop_t y) +moo_oop_t moo_neints (moo_t* moo, moo_oop_t x, moo_oop_t y) { - if (STIX_OOP_IS_SMOOI(x) && STIX_OOP_IS_SMOOI(y)) + if (MOO_OOP_IS_SMOOI(x) && MOO_OOP_IS_SMOOI(y)) { - return (STIX_OOP_TO_SMOOI(x) != STIX_OOP_TO_SMOOI(y))? stix->_true: stix->_false; + return (MOO_OOP_TO_SMOOI(x) != MOO_OOP_TO_SMOOI(y))? moo->_true: moo->_false; } - else if (STIX_OOP_IS_SMOOI(x) || STIX_OOP_IS_SMOOI(y)) + else if (MOO_OOP_IS_SMOOI(x) || MOO_OOP_IS_SMOOI(y)) { - return stix->_true; + return moo->_true; } else { - if (!is_bigint(stix, x) || !is_bigint(stix, y)) goto oops_einval; - return !is_equal(stix, x, y)? stix->_true: stix->_false; + if (!is_bigint(moo, x) || !is_bigint(moo, y)) goto oops_einval; + return !is_equal(moo, x, y)? moo->_true: moo->_false; } oops_einval: - stix->errnum = STIX_EINVAL; - return STIX_NULL; + moo->errnum = MOO_EINVAL; + return MOO_NULL; } -stix_oop_t stix_gtints (stix_t* stix, stix_oop_t x, stix_oop_t y) +moo_oop_t moo_gtints (moo_t* moo, moo_oop_t x, moo_oop_t y) { - if (STIX_OOP_IS_SMOOI(x) && STIX_OOP_IS_SMOOI(y)) + if (MOO_OOP_IS_SMOOI(x) && MOO_OOP_IS_SMOOI(y)) { - return (STIX_OOP_TO_SMOOI(x) > STIX_OOP_TO_SMOOI(y))? stix->_true: stix->_false; + return (MOO_OOP_TO_SMOOI(x) > MOO_OOP_TO_SMOOI(y))? moo->_true: moo->_false; } - else if (STIX_OOP_IS_SMOOI(x)) + else if (MOO_OOP_IS_SMOOI(x)) { - if (!is_bigint(stix, y)) goto oops_einval; - return (STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer)? stix->_true: stix->_false; + if (!is_bigint(moo, y)) goto oops_einval; + return (MOO_OBJ_GET_CLASS(y) == moo->_large_negative_integer)? moo->_true: moo->_false; } - else if (STIX_OOP_IS_SMOOI(y)) + else if (MOO_OOP_IS_SMOOI(y)) { - if (!is_bigint(stix, x)) goto oops_einval; - return (STIX_OBJ_GET_CLASS(x) == stix->_large_positive_integer)? stix->_true: stix->_false; + if (!is_bigint(moo, x)) goto oops_einval; + return (MOO_OBJ_GET_CLASS(x) == moo->_large_positive_integer)? moo->_true: moo->_false; } else { - if (!is_bigint(stix, x) || !is_bigint(stix, y)) goto oops_einval; - return is_greater(stix, x, y)? stix->_true: stix->_false; + if (!is_bigint(moo, x) || !is_bigint(moo, y)) goto oops_einval; + return is_greater(moo, x, y)? moo->_true: moo->_false; } oops_einval: - stix->errnum = STIX_EINVAL; - return STIX_NULL; + moo->errnum = MOO_EINVAL; + return MOO_NULL; } -stix_oop_t stix_geints (stix_t* stix, stix_oop_t x, stix_oop_t y) +moo_oop_t moo_geints (moo_t* moo, moo_oop_t x, moo_oop_t y) { - if (STIX_OOP_IS_SMOOI(x) && STIX_OOP_IS_SMOOI(y)) + if (MOO_OOP_IS_SMOOI(x) && MOO_OOP_IS_SMOOI(y)) { - return (STIX_OOP_TO_SMOOI(x) >= STIX_OOP_TO_SMOOI(y))? stix->_true: stix->_false; + return (MOO_OOP_TO_SMOOI(x) >= MOO_OOP_TO_SMOOI(y))? moo->_true: moo->_false; } - else if (STIX_OOP_IS_SMOOI(x)) + else if (MOO_OOP_IS_SMOOI(x)) { - if (!is_bigint(stix, y)) goto oops_einval; - return (STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer)? stix->_true: stix->_false; + if (!is_bigint(moo, y)) goto oops_einval; + return (MOO_OBJ_GET_CLASS(y) == moo->_large_negative_integer)? moo->_true: moo->_false; } - else if (STIX_OOP_IS_SMOOI(y)) + else if (MOO_OOP_IS_SMOOI(y)) { - if (!is_bigint(stix, x)) goto oops_einval; - return (STIX_OBJ_GET_CLASS(x) == stix->_large_positive_integer)? stix->_true: stix->_false; + if (!is_bigint(moo, x)) goto oops_einval; + return (MOO_OBJ_GET_CLASS(x) == moo->_large_positive_integer)? moo->_true: moo->_false; } else { - if (!is_bigint(stix, x) || !is_bigint(stix, y)) goto oops_einval; - return (is_greater(stix, x, y) || is_equal(stix, x, y))? stix->_true: stix->_false; + if (!is_bigint(moo, x) || !is_bigint(moo, y)) goto oops_einval; + return (is_greater(moo, x, y) || is_equal(moo, x, y))? moo->_true: moo->_false; } oops_einval: - stix->errnum = STIX_EINVAL; - return STIX_NULL; + moo->errnum = MOO_EINVAL; + return MOO_NULL; } -stix_oop_t stix_ltints (stix_t* stix, stix_oop_t x, stix_oop_t y) +moo_oop_t moo_ltints (moo_t* moo, moo_oop_t x, moo_oop_t y) { - if (STIX_OOP_IS_SMOOI(x) && STIX_OOP_IS_SMOOI(y)) + if (MOO_OOP_IS_SMOOI(x) && MOO_OOP_IS_SMOOI(y)) { - return (STIX_OOP_TO_SMOOI(x) < STIX_OOP_TO_SMOOI(y))? stix->_true: stix->_false; + return (MOO_OOP_TO_SMOOI(x) < MOO_OOP_TO_SMOOI(y))? moo->_true: moo->_false; } - else if (STIX_OOP_IS_SMOOI(x)) + else if (MOO_OOP_IS_SMOOI(x)) { - if (!is_bigint(stix, y)) goto oops_einval; - return (STIX_OBJ_GET_CLASS(y) == stix->_large_positive_integer)? stix->_true: stix->_false; + if (!is_bigint(moo, y)) goto oops_einval; + return (MOO_OBJ_GET_CLASS(y) == moo->_large_positive_integer)? moo->_true: moo->_false; } - else if (STIX_OOP_IS_SMOOI(y)) + else if (MOO_OOP_IS_SMOOI(y)) { - if (!is_bigint(stix, x)) goto oops_einval; - return (STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer)? stix->_true: stix->_false; + if (!is_bigint(moo, x)) goto oops_einval; + return (MOO_OBJ_GET_CLASS(x) == moo->_large_negative_integer)? moo->_true: moo->_false; } else { - if (!is_bigint(stix, x) || !is_bigint(stix, y)) goto oops_einval; - return is_less(stix, x, y)? stix->_true: stix->_false; + if (!is_bigint(moo, x) || !is_bigint(moo, y)) goto oops_einval; + return is_less(moo, x, y)? moo->_true: moo->_false; } oops_einval: - stix->errnum = STIX_EINVAL; - return STIX_NULL; + moo->errnum = MOO_EINVAL; + return MOO_NULL; } -stix_oop_t stix_leints (stix_t* stix, stix_oop_t x, stix_oop_t y) +moo_oop_t moo_leints (moo_t* moo, moo_oop_t x, moo_oop_t y) { - if (STIX_OOP_IS_SMOOI(x) && STIX_OOP_IS_SMOOI(y)) + if (MOO_OOP_IS_SMOOI(x) && MOO_OOP_IS_SMOOI(y)) { - return (STIX_OOP_TO_SMOOI(x) <= STIX_OOP_TO_SMOOI(y))? stix->_true: stix->_false; + return (MOO_OOP_TO_SMOOI(x) <= MOO_OOP_TO_SMOOI(y))? moo->_true: moo->_false; } - else if (STIX_OOP_IS_SMOOI(x)) + else if (MOO_OOP_IS_SMOOI(x)) { - if (!is_bigint(stix, y)) goto oops_einval; - return (STIX_OBJ_GET_CLASS(y) == stix->_large_positive_integer)? stix->_true: stix->_false; + if (!is_bigint(moo, y)) goto oops_einval; + return (MOO_OBJ_GET_CLASS(y) == moo->_large_positive_integer)? moo->_true: moo->_false; } - else if (STIX_OOP_IS_SMOOI(y)) + else if (MOO_OOP_IS_SMOOI(y)) { - if (!is_bigint(stix, x)) goto oops_einval; - return (STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer)? stix->_true: stix->_false; + if (!is_bigint(moo, x)) goto oops_einval; + return (MOO_OBJ_GET_CLASS(x) == moo->_large_negative_integer)? moo->_true: moo->_false; } else { - if (!is_bigint(stix, x) || !is_bigint(stix, y)) goto oops_einval; - return (is_less(stix, x, y) || is_equal(stix, x, y))? stix->_true: stix->_false; + if (!is_bigint(moo, x) || !is_bigint(moo, y)) goto oops_einval; + return (is_less(moo, x, y) || is_equal(moo, x, y))? moo->_true: moo->_false; } oops_einval: - stix->errnum = STIX_EINVAL; - return STIX_NULL; + moo->errnum = MOO_EINVAL; + return MOO_NULL; } -stix_oop_t stix_inttostr (stix_t* stix, stix_oop_t num, int radix) +moo_oop_t moo_inttostr (moo_t* moo, moo_oop_t num, int radix) { - stix_ooi_t v = 0; - stix_oow_t w; - stix_oow_t as, bs, rs; -#if (STIX_LIW_BITS == STIX_OOW_BITS) - stix_liw_t b[1]; -#elif (STIX_LIW_BITS == STIX_OOHW_BITS) - stix_liw_t b[2]; + moo_ooi_t v = 0; + moo_oow_t w; + moo_oow_t as, bs, rs; +#if (MOO_LIW_BITS == MOO_OOW_BITS) + moo_liw_t b[1]; +#elif (MOO_LIW_BITS == MOO_OOHW_BITS) + moo_liw_t b[2]; #else # error UNSUPPORTED LIW BIT SIZE #endif - stix_liw_t* a, * q, * r; - stix_liw_t* t = STIX_NULL; - stix_ooch_t* xbuf = STIX_NULL; - stix_oow_t xlen = 0, seglen; - stix_oop_t s; + moo_liw_t* a, * q, * r; + moo_liw_t* t = MOO_NULL; + moo_ooch_t* xbuf = MOO_NULL; + moo_oow_t xlen = 0, seglen; + moo_oop_t s; - STIX_ASSERT (stix, radix >= 2 && radix <= 36); + MOO_ASSERT (moo, radix >= 2 && radix <= 36); - if (!stix_isint(stix,num)) goto oops_einval; - v = integer_to_oow (stix, num, &w); + if (!moo_isint(moo,num)) goto oops_einval; + v = integer_to_oow (moo, num, &w); if (v) { @@ -3981,30 +3981,30 @@ stix_oop_t stix_inttostr (stix_t* stix, stix_oop_t num, int radix) * For a binary conversion(radix 2), the number of bits is * the maximum number of digits that can be produced. +1 is * needed for the sign. */ - stix_ooch_t buf[STIX_OOW_BITS + 1]; - stix_oow_t len; + moo_ooch_t buf[MOO_OOW_BITS + 1]; + moo_oow_t len; - len = oow_to_text (stix, w, radix, buf); + len = oow_to_text (moo, w, radix, buf); if (v < 0) buf[len++] = '-'; reverse_string (buf, len); - return stix_makestring (stix, buf, len); + return moo_makestring (moo, buf, len); } - as = STIX_OBJ_GET_SIZE(num); + as = MOO_OBJ_GET_SIZE(num); if (IS_POWER_OF_2(radix)) { unsigned int exp, accbits; - stix_lidw_t acc; - stix_oow_t xpos; + moo_lidw_t acc; + moo_oow_t xpos; exp = _exp_tab[radix]; - xlen = as * ((STIX_LIW_BITS + exp) / exp) + 1; + xlen = as * ((MOO_LIW_BITS + exp) / exp) + 1; xpos = xlen; - xbuf = (stix_ooch_t*)stix_allocmem (stix, STIX_SIZEOF(*xbuf) * xlen); - if (!xbuf) return STIX_NULL; + xbuf = (moo_ooch_t*)moo_allocmem (moo, MOO_SIZEOF(*xbuf) * xlen); + if (!xbuf) return MOO_NULL; acc = 0; accbits = 0; @@ -4012,8 +4012,8 @@ stix_oop_t stix_inttostr (stix_t* stix, stix_oop_t num, int radix) w = 0; while (w < as) { - acc |= (stix_lidw_t)((stix_oop_liword_t)num)->slot[w] << accbits; - accbits += STIX_LIW_BITS; + acc |= (moo_lidw_t)((moo_oop_liword_t)num)->slot[w] << accbits; + accbits += MOO_LIW_BITS; w++; do @@ -4033,33 +4033,33 @@ stix_oop_t stix_inttostr (stix_t* stix, stix_oop_t num, int radix) while (1); } - STIX_ASSERT (stix, xpos >= 1); - if (STIX_OBJ_GET_CLASS(num) == stix->_large_negative_integer) xbuf[--xpos] = '-'; + MOO_ASSERT (moo, xpos >= 1); + if (MOO_OBJ_GET_CLASS(num) == moo->_large_negative_integer) xbuf[--xpos] = '-'; - s = stix_makestring (stix, &xbuf[xpos], xlen - xpos); - stix_freemem (stix, xbuf); + s = moo_makestring (moo, &xbuf[xpos], xlen - xpos); + moo_freemem (moo, xbuf); return s; } /* Do it in a hard way for other cases */ -/* TODO: migrate these buffers into stix_t? */ +/* TODO: migrate these buffers into moo_t? */ /* TODO: find an optimial buffer size */ - xbuf = (stix_ooch_t*)stix_allocmem (stix, STIX_SIZEOF(*xbuf) * (as * STIX_LIW_BITS + 1)); - if (!xbuf) return STIX_NULL; + xbuf = (moo_ooch_t*)moo_allocmem (moo, MOO_SIZEOF(*xbuf) * (as * MOO_LIW_BITS + 1)); + if (!xbuf) return MOO_NULL; - t = (stix_liw_t*)stix_callocmem (stix, STIX_SIZEOF(*t) * as * 3); + t = (moo_liw_t*)moo_callocmem (moo, MOO_SIZEOF(*t) * as * 3); if (!t) { - stix_freemem (stix, xbuf); - return STIX_NULL; + moo_freemem (moo, xbuf); + return MOO_NULL; } -#if (STIX_LIW_BITS == STIX_OOW_BITS) - b[0] = stix->bigint[radix].multiplier; /* block divisor */ +#if (MOO_LIW_BITS == MOO_OOW_BITS) + b[0] = moo->bigint[radix].multiplier; /* block divisor */ bs = 1; -#elif (STIX_LIW_BITS == STIX_OOHW_BITS) - b[0] = stix->bigint[radix].multiplier /*& STIX_LBMASK(stix_oow_t, STIX_LIW_BITS)*/; - b[1] = stix->bigint[radix].multiplier >> STIX_LIW_BITS; +#elif (MOO_LIW_BITS == MOO_OOHW_BITS) + b[0] = moo->bigint[radix].multiplier /*& MOO_LBMASK(moo_oow_t, MOO_LIW_BITS)*/; + b[1] = moo->bigint[radix].multiplier >> MOO_LIW_BITS; bs = (b[1] > 0)? 2: 1; #else # error UNSUPPORTED LIW BIT SIZE @@ -4069,15 +4069,15 @@ stix_oop_t stix_inttostr (stix_t* stix, stix_oop_t num, int radix) q = &t[as]; r = &t[as * 2]; - STIX_MEMCPY (a, ((stix_oop_liword_t)num)->slot, STIX_SIZEOF(*a) * as); + MOO_MEMCPY (a, ((moo_oop_liword_t)num)->slot, MOO_SIZEOF(*a) * as); do { if (is_less_unsigned_array (b, bs, a, as)) { - stix_liw_t* tmp; + moo_liw_t* tmp; - divide_unsigned_array (stix, a, as, b, bs, q, r); + divide_unsigned_array (moo, a, as, b, bs, q, r); /* get 'rs' before 'as' gets changed */ rs = count_effective (r, as); @@ -4096,26 +4096,26 @@ stix_oop_t stix_inttostr (stix_t* stix, stix_oop_t num, int radix) rs = as; } - #if (STIX_LIW_BITS == STIX_OOW_BITS) - STIX_ASSERT (stix, rs == 1); + #if (MOO_LIW_BITS == MOO_OOW_BITS) + MOO_ASSERT (moo, rs == 1); w = r[0]; - #elif (STIX_LIW_BITS == STIX_OOHW_BITS) + #elif (MOO_LIW_BITS == MOO_OOHW_BITS) if (rs == 1) w = r[0]; else { - STIX_ASSERT (stix, rs == 2); + MOO_ASSERT (moo, rs == 2); w = MAKE_WORD (r[0], r[1]); } #else # error UNSUPPORTED LIW BIT SIZE #endif - seglen = oow_to_text (stix, w, radix, &xbuf[xlen]); + seglen = oow_to_text (moo, w, radix, &xbuf[xlen]); xlen += seglen; if (r == a) break; /* reached the last block */ /* fill unfilled leading digits with zeros as it's not * the last block */ - while (seglen < stix->bigint[radix].safe_ndigits) + while (seglen < moo->bigint[radix].safe_ndigits) { xbuf[xlen++] = '0'; seglen++; @@ -4123,15 +4123,15 @@ stix_oop_t stix_inttostr (stix_t* stix, stix_oop_t num, int radix) } while (1); - if (STIX_OBJ_GET_CLASS(num) == stix->_large_negative_integer) xbuf[xlen++] = '-'; + if (MOO_OBJ_GET_CLASS(num) == moo->_large_negative_integer) xbuf[xlen++] = '-'; reverse_string (xbuf, xlen); - s = stix_makestring (stix, xbuf, xlen); + s = moo_makestring (moo, xbuf, xlen); - stix_freemem (stix, t); - stix_freemem (stix, xbuf); + moo_freemem (moo, t); + moo_freemem (moo, xbuf); return s; oops_einval: - stix->errnum = STIX_EINVAL; - return STIX_NULL; + moo->errnum = MOO_EINVAL; + return MOO_NULL; } diff --git a/stix/lib/comp.c b/stix/lib/comp.c index 772be27..407f4b9 100644 --- a/stix/lib/comp.c +++ b/stix/lib/comp.c @@ -24,7 +24,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "stix-prv.h" +#include "moo-prv.h" #define CLASS_BUFFER_ALIGN 64 #define LITERAL_BUFFER_ALIGN 64 @@ -48,7 +48,7 @@ enum class_mod_t enum var_type_t { /* NEVER Change the order and the value of 3 items below. - * stix->c->cls.vars and stix->c->cls.var_count relies on them. */ + * moo->c->cls.vars and moo->c->cls.var_count relies on them. */ VAR_INSTANCE = 0, VAR_CLASS = 1, VAR_CLASSINST = 2, @@ -63,16 +63,16 @@ typedef enum var_type_t var_type_t; struct var_info_t { var_type_t type; - stix_ooi_t pos; /* not used for VAR_GLOBAL */ - stix_oop_class_t cls; /* useful if type is VAR_CLASS. note STIX_NULL indicates the self class. */ - stix_oop_association_t gbl; /* used for VAR_GLOBAL only */ + moo_ooi_t pos; /* not used for VAR_GLOBAL */ + moo_oop_class_t cls; /* useful if type is VAR_CLASS. note MOO_NULL indicates the self class. */ + moo_oop_association_t gbl; /* used for VAR_GLOBAL only */ }; typedef struct var_info_t var_info_t; static struct voca_t { - stix_oow_t len; - stix_ooch_t str[11]; + moo_oow_t len; + moo_ooch_t str[11]; } vocas[] = { { 5, { '#','b','y','t','e' } }, { 10, { '#','c','h','a','r','a','c','t','e','r' } }, @@ -88,6 +88,7 @@ static struct voca_t { 5, { 'f','a','l','s','e' } }, { 4, { 'f','r','o','m' } }, { 9, { '#','h','a','l','f','w','o','r','d' } }, + { 2, { 'i','f' } }, { 8, { '#','i','n','c','l','u','d','e' } }, { 7, { '#','l','i','w','o','r','d' } }, { 6, { 'm','e','t','h','o','d' } }, @@ -126,6 +127,7 @@ enum voca_id_t VOCA_FALSE, VOCA_FROM, VOCA_HALFWORD_S, + VOCA_IF, VOCA_INCLUDE_S, VOCA_LIWORD_S, VOCA_METHOD, @@ -149,12 +151,12 @@ enum voca_id_t }; typedef enum voca_id_t voca_id_t; -static int compile_block_statement (stix_t* stix); -static int compile_method_statement (stix_t* stix); -static int compile_method_expression (stix_t* stix, int pop); -static int add_literal (stix_t* stix, stix_oop_t lit, stix_oow_t* index); +static int compile_block_statement (moo_t* moo); +static int compile_method_statement (moo_t* moo); +static int compile_method_expression (moo_t* moo, int pop); +static int add_literal (moo_t* moo, moo_oop_t lit, moo_oow_t* index); -static STIX_INLINE int is_spacechar (stix_ooci_t c) +static MOO_INLINE int is_spacechar (moo_ooci_t c) { /* TODO: handle other space unicode characters */ switch (c) @@ -173,25 +175,25 @@ static STIX_INLINE int is_spacechar (stix_ooci_t c) } -static STIX_INLINE int is_alphachar (stix_ooci_t c) +static MOO_INLINE int is_alphachar (moo_ooci_t c) { /* TODO: support full unicode */ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); } -static STIX_INLINE int is_digitchar (stix_ooci_t c) +static MOO_INLINE int is_digitchar (moo_ooci_t c) { /* TODO: support full unicode */ return (c >= '0' && c <= '9'); } -static STIX_INLINE int is_alnumchar (stix_ooci_t c) +static MOO_INLINE int is_alnumchar (moo_ooci_t c) { /* TODO: support full unicode */ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'); } -static STIX_INLINE int is_binselchar (stix_ooci_t c) +static MOO_INLINE int is_binselchar (moo_ooci_t c) { /* * binary-selector-character := @@ -223,17 +225,17 @@ static STIX_INLINE int is_binselchar (stix_ooci_t c) } } -static STIX_INLINE int is_leadidentchar (stix_ooci_t c) +static MOO_INLINE int is_leadidentchar (moo_ooci_t c) { return is_alphachar(c) || c == '_'; } -static STIX_INLINE int is_identchar (stix_ooci_t c) +static MOO_INLINE int is_identchar (moo_ooci_t c) { return is_alnumchar(c) || c == '_'; } -static STIX_INLINE int is_closing_char (stix_ooci_t c) +static MOO_INLINE int is_closing_char (moo_ooci_t c) { switch (c) { @@ -250,13 +252,13 @@ static STIX_INLINE int is_closing_char (stix_ooci_t c) } } -static STIX_INLINE int is_word (const stix_oocs_t* oocs, voca_id_t id) +static MOO_INLINE int is_word (const moo_oocs_t* oocs, voca_id_t id) { return oocs->len == vocas[id].len && - stix_equaloochars(oocs->ptr, vocas[id].str, vocas[id].len); + moo_equaloochars(oocs->ptr, vocas[id].str, vocas[id].len); } -static int is_reserved_word (const stix_oocs_t* ucs) +static int is_reserved_word (const moo_oocs_t* ucs) { static int rw[] = { @@ -268,10 +270,11 @@ static int is_reserved_word (const stix_oocs_t* ucs) VOCA_ERROR, VOCA_THIS_CONTEXT, VOCA_THIS_PROCESS, + VOCA_IF }; int i; - for (i = 0; i < STIX_COUNTOF(rw); i++) + for (i = 0; i < MOO_COUNTOF(rw); i++) { if (is_word(ucs, rw[i])) return 1; } @@ -279,7 +282,7 @@ static int is_reserved_word (const stix_oocs_t* ucs) return 0; } -static int is_restricted_word (const stix_oocs_t* ucs) +static int is_restricted_word (const moo_oocs_t* ucs) { /* not fully reserved. but restricted in a certain context */ @@ -295,7 +298,7 @@ static int is_restricted_word (const stix_oocs_t* ucs) }; int i; - for (i = 0; i < STIX_COUNTOF(rw); i++) + for (i = 0; i < MOO_COUNTOF(rw); i++) { if (is_word(ucs, rw[i])) return 1; } @@ -303,35 +306,35 @@ static int is_restricted_word (const stix_oocs_t* ucs) return 0; } -static int begin_include (stix_t* stix); -static int end_include (stix_t* stix); +static int begin_include (moo_t* moo); +static int end_include (moo_t* moo); -static void set_syntax_error (stix_t* stix, stix_synerrnum_t num, const stix_ioloc_t* loc, const stix_oocs_t* tgt) +static void set_syntax_error (moo_t* moo, moo_synerrnum_t num, const moo_ioloc_t* loc, const moo_oocs_t* tgt) { - stix->errnum = STIX_ESYNTAX; - stix->c->synerr.num = num; + moo->errnum = MOO_ESYNTAX; + moo->c->synerr.num = num; /* The SCO compiler complains of this ternary operation saying: * error: operands have incompatible types: op ":" * it seems to complain of type mismatch between *loc and - * stix->c->tok.loc due to 'const' prefixed to loc. */ - /*stix->c->synerr.loc = loc? *loc: stix->c->tok.loc;*/ + * moo->c->tok.loc due to 'const' prefixed to loc. */ + /*moo->c->synerr.loc = loc? *loc: moo->c->tok.loc;*/ if (loc) - stix->c->synerr.loc = *loc; + moo->c->synerr.loc = *loc; else - stix->c->synerr.loc = stix->c->tok.loc; + moo->c->synerr.loc = moo->c->tok.loc; - if (tgt) stix->c->synerr.tgt = *tgt; + if (tgt) moo->c->synerr.tgt = *tgt; else { - stix->c->synerr.tgt.ptr = STIX_NULL; - stix->c->synerr.tgt.len = 0; + moo->c->synerr.tgt.ptr = MOO_NULL; + moo->c->synerr.tgt.len = 0; } } -static int copy_string_to (stix_t* stix, const stix_oocs_t* src, stix_oocs_t* dst, stix_oow_t* dst_capa, int append, stix_ooch_t add_delim) +static int copy_string_to (moo_t* moo, const moo_oocs_t* src, moo_oocs_t* dst, moo_oow_t* dst_capa, int append, moo_ooch_t add_delim) { - stix_oow_t len, pos; + moo_oow_t len, pos; if (append) { @@ -347,12 +350,12 @@ static int copy_string_to (stix_t* stix, const stix_oocs_t* src, stix_oocs_t* ds if (len > *dst_capa) { - stix_ooch_t* tmp; - stix_oow_t capa; + moo_ooch_t* tmp; + moo_oow_t capa; - capa = STIX_ALIGN(len, CLASS_BUFFER_ALIGN); + capa = MOO_ALIGN(len, CLASS_BUFFER_ALIGN); - tmp = stix_reallocmem (stix, dst->ptr, STIX_SIZEOF(*tmp) * capa); + tmp = moo_reallocmem (moo, dst->ptr, MOO_SIZEOF(*tmp) * capa); if (!tmp) return -1; dst->ptr = tmp; @@ -360,12 +363,12 @@ static int copy_string_to (stix_t* stix, const stix_oocs_t* src, stix_oocs_t* ds } if (append && add_delim) dst->ptr[pos++] = add_delim; - stix_copyoochars (&dst->ptr[pos], src->ptr, src->len); + moo_copyoochars (&dst->ptr[pos], src->ptr, src->len); dst->len = len; return 0; } -static int find_word_in_string (const stix_oocs_t* haystack, const stix_oocs_t* name, stix_oow_t* xindex) +static int find_word_in_string (const moo_oocs_t* haystack, const moo_oocs_t* name, moo_oow_t* xindex) { /* this function is inefficient. but considering the typical number * of arguments and temporary variables, the inefficiency can be @@ -373,8 +376,8 @@ static int find_word_in_string (const stix_oocs_t* haystack, const stix_oocs_t* * table from a name to an index should be greater than this simple * inefficient lookup */ - stix_ooch_t* t, * e; - stix_oow_t index, i; + moo_ooch_t* t, * e; + moo_oow_t index, i; t = haystack->ptr; e = t + haystack->len; @@ -417,21 +420,21 @@ static int find_word_in_string (const stix_oocs_t* haystack, const stix_oocs_t* (c >= 'A' && c <= 'Z')? ((c - 'A' + 10 < base)? (c - 'A' + 10): base): \ (c >= 'a' && c <= 'z')? ((c - 'a' + 10 < base)? (c - 'a' + 10): base): base) -static int string_to_smooi (stix_t* stix, stix_oocs_t* str, int radixed, stix_ooi_t* num) +static int string_to_smooi (moo_t* moo, moo_oocs_t* str, int radixed, moo_ooi_t* num) { /* it is not a generic conversion function. * it assumes a certain pre-sanity check on the string * done by the lexical analyzer */ int v, negsign, base; - const stix_ooch_t* ptr, * end; - stix_oow_t value, old_value; + const moo_ooch_t* ptr, * end; + moo_oow_t value, old_value; negsign = 0; ptr = str->ptr, end = str->ptr + str->len; - STIX_ASSERT (stix, ptr < end); + MOO_ASSERT (moo, ptr < end); if (*ptr == '+' || *ptr == '-') { @@ -441,7 +444,7 @@ static int string_to_smooi (stix_t* stix, stix_oocs_t* str, int radixed, stix_oo if (radixed) { - STIX_ASSERT (stix, ptr < end); + MOO_ASSERT (moo, ptr < end); base = 0; do @@ -455,7 +458,7 @@ static int string_to_smooi (stix_t* stix, stix_oocs_t* str, int radixed, stix_oo } else base = 10; - STIX_ASSERT (stix, ptr < end); + MOO_ASSERT (moo, ptr < end); value = old_value = 0; while (ptr < end && (v = CHAR_TO_NUM(*ptr, base)) < base) @@ -464,7 +467,7 @@ static int string_to_smooi (stix_t* stix, stix_oocs_t* str, int radixed, stix_oo if (value < old_value) { /* overflow must have occurred */ - stix->errnum = STIX_ERANGE; + moo->errnum = MOO_ERANGE; return -1; } old_value = value; @@ -474,14 +477,14 @@ static int string_to_smooi (stix_t* stix, stix_oocs_t* str, int radixed, stix_oo if (ptr < end) { /* trailing garbage? */ - stix->errnum = STIX_EINVAL; + moo->errnum = MOO_EINVAL; return -1; } - STIX_ASSERT (stix, -STIX_SMOOI_MAX == STIX_SMOOI_MIN); - if (value > STIX_SMOOI_MAX) + MOO_ASSERT (moo, -MOO_SMOOI_MAX == MOO_SMOOI_MIN); + if (value > MOO_SMOOI_MAX) { - stix->errnum = STIX_ERANGE; + moo->errnum = MOO_ERANGE; return -1; } @@ -491,16 +494,16 @@ static int string_to_smooi (stix_t* stix, stix_oocs_t* str, int radixed, stix_oo return 0; } -static stix_oop_t string_to_num (stix_t* stix, stix_oocs_t* str, int radixed) +static moo_oop_t string_to_num (moo_t* moo, moo_oocs_t* str, int radixed) { int negsign, base; - const stix_ooch_t* ptr, * end; + const moo_ooch_t* ptr, * end; negsign = 0; ptr = str->ptr, end = str->ptr + str->len; - STIX_ASSERT (stix, ptr < end); + MOO_ASSERT (moo, ptr < end); if (*ptr == '+' || *ptr == '-') { @@ -510,7 +513,7 @@ static stix_oop_t string_to_num (stix_t* stix, stix_oocs_t* str, int radixed) if (radixed) { - STIX_ASSERT (stix, ptr < end); + MOO_ASSERT (moo, ptr < end); base = 0; do @@ -526,13 +529,13 @@ static stix_oop_t string_to_num (stix_t* stix, stix_oocs_t* str, int radixed) /* TODO: handle floating point numbers ... etc */ if (negsign) base = -base; - return stix_strtoint (stix, ptr, end - ptr, base); + return moo_strtoint (moo, ptr, end - ptr, base); } -static stix_oop_t string_to_error (stix_t* stix, stix_oocs_t* str) +static moo_oop_t string_to_error (moo_t* moo, moo_oocs_t* str) { - stix_ooi_t num = 0; - const stix_ooch_t* ptr, * end; + moo_ooi_t num = 0; + const moo_ooch_t* ptr, * end; ptr = str->ptr, end = str->ptr + str->len; @@ -546,156 +549,156 @@ static stix_oop_t string_to_error (stix_t* stix, stix_oocs_t* str) ptr++; } - return STIX_ERROR_TO_OOP(num); + return MOO_ERROR_TO_OOP(num); } /* --------------------------------------------------------------------- * Tokenizer * --------------------------------------------------------------------- */ -#define GET_CHAR(stix) \ - do { if (get_char(stix) <= -1) return -1; } while (0) +#define GET_CHAR(moo) \ + do { if (get_char(moo) <= -1) return -1; } while (0) -#define GET_CHAR_TO(stix,c) \ +#define GET_CHAR_TO(moo,c) \ do { \ - if (get_char(stix) <= -1) return -1; \ - c = (stix)->c->lxc.c; \ + if (get_char(moo) <= -1) return -1; \ + c = (moo)->c->lxc.c; \ } while(0) -#define GET_TOKEN(stix) \ - do { if (get_token(stix) <= -1) return -1; } while (0) +#define GET_TOKEN(moo) \ + do { if (get_token(moo) <= -1) return -1; } while (0) -#define GET_TOKEN_WITH_ERRRET(stix, v_ret) \ - do { if (get_token(stix) <= -1) return v_ret; } while (0) +#define GET_TOKEN_WITH_ERRRET(moo, v_ret) \ + do { if (get_token(moo) <= -1) return v_ret; } while (0) -#define ADD_TOKEN_STR(stix,s,l) \ - do { if (add_token_str(stix, s, l) <= -1) return -1; } while (0) +#define ADD_TOKEN_STR(moo,s,l) \ + do { if (add_token_str(moo, s, l) <= -1) return -1; } while (0) -#define ADD_TOKEN_CHAR(stix,c) \ - do { if (add_token_char(stix, c) <= -1) return -1; } while (0) +#define ADD_TOKEN_CHAR(moo,c) \ + do { if (add_token_char(moo, c) <= -1) return -1; } while (0) -#define CLEAR_TOKEN_NAME(stix) ((stix)->c->tok.name.len = 0) -#define SET_TOKEN_TYPE(stix,tv) ((stix)->c->tok.type = (tv)) +#define CLEAR_TOKEN_NAME(moo) ((moo)->c->tok.name.len = 0) +#define SET_TOKEN_TYPE(moo,tv) ((moo)->c->tok.type = (tv)) -#define TOKEN_TYPE(stix) ((stix)->c->tok.type) -#define TOKEN_NAME(stix) (&(stix)->c->tok.name) -#define TOKEN_NAME_CAPA(stix) ((stix)->c->tok.name_capa) -#define TOKEN_NAME_PTR(stix) ((stix)->c->tok.name.ptr) -#define TOKEN_NAME_LEN(stix) ((stix)->c->tok.name.len) -#define TOKEN_LOC(stix) (&(stix)->c->tok.loc) -#define LEXER_LOC(stix) (&(stix)->c->lxc.l) +#define TOKEN_TYPE(moo) ((moo)->c->tok.type) +#define TOKEN_NAME(moo) (&(moo)->c->tok.name) +#define TOKEN_NAME_CAPA(moo) ((moo)->c->tok.name_capa) +#define TOKEN_NAME_PTR(moo) ((moo)->c->tok.name.ptr) +#define TOKEN_NAME_LEN(moo) ((moo)->c->tok.name.len) +#define TOKEN_LOC(moo) (&(moo)->c->tok.loc) +#define LEXER_LOC(moo) (&(moo)->c->lxc.l) -static STIX_INLINE int does_token_name_match (stix_t* stix, voca_id_t id) +static MOO_INLINE int does_token_name_match (moo_t* moo, voca_id_t id) { - return TOKEN_NAME_LEN(stix) == vocas[id].len && - stix_equaloochars(TOKEN_NAME_PTR(stix), vocas[id].str, vocas[id].len); + return TOKEN_NAME_LEN(moo) == vocas[id].len && + moo_equaloochars(TOKEN_NAME_PTR(moo), vocas[id].str, vocas[id].len); } -static STIX_INLINE int is_token_symbol (stix_t* stix, voca_id_t id) +static MOO_INLINE int is_token_symbol (moo_t* moo, voca_id_t id) { - return TOKEN_TYPE(stix) == STIX_IOTOK_SYMLIT && does_token_name_match(stix, id); + return TOKEN_TYPE(moo) == MOO_IOTOK_SYMLIT && does_token_name_match(moo, id); } -static STIX_INLINE int is_token_word (stix_t* stix, voca_id_t id) +static MOO_INLINE int is_token_word (moo_t* moo, voca_id_t id) { - return TOKEN_TYPE(stix) == STIX_IOTOK_IDENT && does_token_name_match(stix, id); + return TOKEN_TYPE(moo) == MOO_IOTOK_IDENT && does_token_name_match(moo, id); } -static STIX_INLINE int is_token_binary_selector (stix_t* stix, voca_id_t id) +static MOO_INLINE int is_token_binary_selector (moo_t* moo, voca_id_t id) { - return TOKEN_TYPE(stix) == STIX_IOTOK_BINSEL && does_token_name_match(stix, id); + return TOKEN_TYPE(moo) == MOO_IOTOK_BINSEL && does_token_name_match(moo, id); } -static STIX_INLINE int is_token_keyword (stix_t* stix, voca_id_t id) +static MOO_INLINE int is_token_keyword (moo_t* moo, voca_id_t id) { - return TOKEN_TYPE(stix) == STIX_IOTOK_KEYWORD && does_token_name_match(stix, id); + return TOKEN_TYPE(moo) == MOO_IOTOK_KEYWORD && does_token_name_match(moo, id); } -static STIX_INLINE int add_token_str (stix_t* stix, const stix_ooch_t* ptr, stix_oow_t len) +static MOO_INLINE int add_token_str (moo_t* moo, const moo_ooch_t* ptr, moo_oow_t len) { - stix_oocs_t tmp; + moo_oocs_t tmp; - tmp.ptr = (stix_ooch_t*)ptr; + tmp.ptr = (moo_ooch_t*)ptr; tmp.len = len; - return copy_string_to (stix, &tmp, TOKEN_NAME(stix), &TOKEN_NAME_CAPA(stix), 1, '\0'); + return copy_string_to (moo, &tmp, TOKEN_NAME(moo), &TOKEN_NAME_CAPA(moo), 1, '\0'); } -static STIX_INLINE int add_token_char (stix_t* stix, stix_ooch_t c) +static MOO_INLINE int add_token_char (moo_t* moo, moo_ooch_t c) { - stix_oocs_t tmp; + moo_oocs_t tmp; tmp.ptr = &c; tmp.len = 1; - return copy_string_to (stix, &tmp, TOKEN_NAME(stix), &TOKEN_NAME_CAPA(stix), 1, '\0'); + return copy_string_to (moo, &tmp, TOKEN_NAME(moo), &TOKEN_NAME_CAPA(moo), 1, '\0'); } -static STIX_INLINE void unget_char (stix_t* stix, const stix_iolxc_t* c) +static MOO_INLINE void unget_char (moo_t* moo, const moo_iolxc_t* c) { /* Make sure that the unget buffer is large enough */ - STIX_ASSERT (stix, stix->c->nungots < STIX_COUNTOF(stix->c->ungot)); - stix->c->ungot[stix->c->nungots++] = *c; + MOO_ASSERT (moo, moo->c->nungots < MOO_COUNTOF(moo->c->ungot)); + moo->c->ungot[moo->c->nungots++] = *c; } -static int get_char (stix_t* stix) +static int get_char (moo_t* moo) { - stix_ooi_t n; - stix_ooci_t lc, ec; + moo_ooi_t n; + moo_ooci_t lc, ec; - if (stix->c->nungots > 0) + if (moo->c->nungots > 0) { /* something in the unget buffer */ - stix->c->lxc = stix->c->ungot[--stix->c->nungots]; + moo->c->lxc = moo->c->ungot[--moo->c->nungots]; return 0; } - if (stix->c->curinp->b.state == -1) + if (moo->c->curinp->b.state == -1) { - stix->c->curinp->b.state = 0; + moo->c->curinp->b.state = 0; return -1; } - else if (stix->c->curinp->b.state == 1) + else if (moo->c->curinp->b.state == 1) { - stix->c->curinp->b.state = 0; + moo->c->curinp->b.state = 0; goto return_eof; } - if (stix->c->curinp->b.pos >= stix->c->curinp->b.len) + if (moo->c->curinp->b.pos >= moo->c->curinp->b.len) { - n = stix->c->impl (stix, STIX_IO_READ, stix->c->curinp); + n = moo->c->impl (moo, MOO_IO_READ, moo->c->curinp); if (n <= -1) return -1; if (n == 0) { return_eof: - stix->c->curinp->lxc.c = STIX_UCI_EOF; - stix->c->curinp->lxc.l.line = stix->c->curinp->line; - stix->c->curinp->lxc.l.colm = stix->c->curinp->colm; - stix->c->curinp->lxc.l.file = stix->c->curinp->name; - stix->c->lxc = stix->c->curinp->lxc; + moo->c->curinp->lxc.c = MOO_UCI_EOF; + moo->c->curinp->lxc.l.line = moo->c->curinp->line; + moo->c->curinp->lxc.l.colm = moo->c->curinp->colm; + moo->c->curinp->lxc.l.file = moo->c->curinp->name; + moo->c->lxc = moo->c->curinp->lxc; /* indicate that EOF has been read. lxc.c is also set to EOF. */ return 0; } - stix->c->curinp->b.pos = 0; - stix->c->curinp->b.len = n; + moo->c->curinp->b.pos = 0; + moo->c->curinp->b.len = n; } - if (stix->c->curinp->lxc.c == '\n' || stix->c->curinp->lxc.c == '\r') + if (moo->c->curinp->lxc.c == '\n' || moo->c->curinp->lxc.c == '\r') { - /* stix->c->curinp->lxc.c is a previous character. the new character - * to be read is still in the buffer (stix->c->curinp->buf). - * stix->cu->curinp->colm has been incremented when the previous + /* moo->c->curinp->lxc.c is a previous character. the new character + * to be read is still in the buffer (moo->c->curinp->buf). + * moo->cu->curinp->colm has been incremented when the previous * character has been read. */ - if (stix->c->curinp->line > 1 && - stix->c->curinp->colm == 2 && - stix->c->curinp->nl != stix->c->curinp->lxc.c) + if (moo->c->curinp->line > 1 && + moo->c->curinp->colm == 2 && + moo->c->curinp->nl != moo->c->curinp->lxc.c) { /* most likely, it's the second character in '\r\n' or '\n\r' * sequence. let's not update the line and column number. */ - /*stix->c->curinp->colm = 1;*/ + /*moo->c->curinp->colm = 1;*/ } else { @@ -704,67 +707,67 @@ static int get_char (stix_t* stix) * incrementing the line number here instead of * updating inp->lxc causes the line number for * TOK_EOF to be the same line as the lxc newline. */ - stix->c->curinp->line++; - stix->c->curinp->colm = 1; - stix->c->curinp->nl = stix->c->curinp->lxc.c; + moo->c->curinp->line++; + moo->c->curinp->colm = 1; + moo->c->curinp->nl = moo->c->curinp->lxc.c; } } - lc = stix->c->curinp->buf[stix->c->curinp->b.pos++]; + lc = moo->c->curinp->buf[moo->c->curinp->b.pos++]; - stix->c->curinp->lxc.c = lc; - stix->c->curinp->lxc.l.line = stix->c->curinp->line; - stix->c->curinp->lxc.l.colm = stix->c->curinp->colm++; - stix->c->curinp->lxc.l.file = stix->c->curinp->name; - stix->c->lxc = stix->c->curinp->lxc; + moo->c->curinp->lxc.c = lc; + moo->c->curinp->lxc.l.line = moo->c->curinp->line; + moo->c->curinp->lxc.l.colm = moo->c->curinp->colm++; + moo->c->curinp->lxc.l.file = moo->c->curinp->name; + moo->c->lxc = moo->c->curinp->lxc; return 1; /* indicate that a normal character has been read */ } -static STIX_INLINE int skip_spaces (stix_t* stix) +static MOO_INLINE int skip_spaces (moo_t* moo) { - while (is_spacechar(stix->c->lxc.c)) GET_CHAR (stix); + while (is_spacechar(moo->c->lxc.c)) GET_CHAR (moo); return 0; } -static int skip_comment (stix_t* stix) +static int skip_comment (moo_t* moo) { - stix_ooci_t c = stix->c->lxc.c; - stix_iolxc_t lc; + moo_ooci_t c = moo->c->lxc.c; + moo_iolxc_t lc; if (c == '"') { /* skip up to the closing " */ do { - GET_CHAR_TO (stix, c); - if (c == STIX_UCI_EOF) goto unterminated; + GET_CHAR_TO (moo, c); + if (c == MOO_UCI_EOF) goto unterminated; } while (c != '"'); - if (c == '"') GET_CHAR (stix); /* keep the next character in lxc */ + if (c == '"') GET_CHAR (moo); /* keep the next character in lxc */ return 1; /* double-quoted comment */ } else if (c == '(') { /* handle (* ... *) */ - lc = stix->c->lxc; - GET_CHAR_TO (stix, c); + lc = moo->c->lxc; + GET_CHAR_TO (moo, c); if (c != '*') goto not_comment; do { - GET_CHAR_TO (stix, c); - if (c == STIX_UCI_EOF) goto unterminated; + GET_CHAR_TO (moo, c); + if (c == MOO_UCI_EOF) goto unterminated; if (c == '*') { - GET_CHAR_TO (stix, c); - if (c == STIX_UCI_EOF) goto unterminated; + GET_CHAR_TO (moo, c); + if (c == MOO_UCI_EOF) goto unterminated; if (c == ')') { - GET_CHAR (stix); /* keep the first meaningful character in lxc */ + GET_CHAR (moo); /* keep the first meaningful character in lxc */ break; } } @@ -778,22 +781,22 @@ static int skip_comment (stix_t* stix) /* handle #! or ## */ /* save the last character */ - lc = stix->c->lxc; + lc = moo->c->lxc; /* read a new character */ - GET_CHAR_TO (stix, c); + GET_CHAR_TO (moo, c); if (c != '!' && c != '#') goto not_comment; do { - GET_CHAR_TO (stix, c); - if (c == STIX_UCI_EOF) + GET_CHAR_TO (moo, c); + if (c == MOO_UCI_EOF) { /* EOF on the comment line is ok for a single-line comment */ break; } else if (c == '\r' || c == '\n') { - GET_CHAR (stix); /* keep the first meaningful character in lxc */ + GET_CHAR (moo); /* keep the first meaningful character in lxc */ break; } } @@ -810,87 +813,87 @@ static int skip_comment (stix_t* stix) not_comment: /* unget the leading '#' */ - unget_char (stix, &stix->c->lxc); + unget_char (moo, &moo->c->lxc); /* restore the previous state */ - stix->c->lxc = lc; + moo->c->lxc = lc; return 0; unterminated: - set_syntax_error (stix, STIX_SYNERR_CMTNC, LEXER_LOC(stix), STIX_NULL); + set_syntax_error (moo, MOO_SYNERR_CMTNC, LEXER_LOC(moo), MOO_NULL); return -1; } -static int get_ident (stix_t* stix, stix_ooci_t char_read_ahead) +static int get_ident (moo_t* moo, moo_ooci_t char_read_ahead) { /* * identifier := alpha-char (alpha-char | digit-char)* * keyword := identifier ":" */ - stix_ooci_t c; + moo_ooci_t c; - c = stix->c->lxc.c; - SET_TOKEN_TYPE (stix, STIX_IOTOK_IDENT); + c = moo->c->lxc.c; + SET_TOKEN_TYPE (moo, MOO_IOTOK_IDENT); - if (char_read_ahead != STIX_UCI_EOF) + if (char_read_ahead != MOO_UCI_EOF) { - ADD_TOKEN_CHAR(stix, char_read_ahead); + ADD_TOKEN_CHAR(moo, char_read_ahead); } do { - ADD_TOKEN_CHAR (stix, c); - GET_CHAR_TO (stix, c); + ADD_TOKEN_CHAR (moo, c); + GET_CHAR_TO (moo, c); } while (is_identchar(c)); - if (c == '(' && is_token_word(stix, VOCA_ERROR)) + if (c == '(' && is_token_word(moo, VOCA_ERROR)) { /* error(NN) */ - ADD_TOKEN_CHAR (stix, c); - GET_CHAR_TO (stix, c); + ADD_TOKEN_CHAR (moo, c); + GET_CHAR_TO (moo, c); if (!is_digitchar(c)) { - ADD_TOKEN_CHAR (stix, c); - set_syntax_error (stix, STIX_SYNERR_ERRLIT, TOKEN_LOC(stix), TOKEN_NAME(stix)); + ADD_TOKEN_CHAR (moo, c); + set_syntax_error (moo, MOO_SYNERR_ERRLIT, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } do { - ADD_TOKEN_CHAR (stix, c); - GET_CHAR_TO (stix, c); + ADD_TOKEN_CHAR (moo, c); + GET_CHAR_TO (moo, c); } while (is_digitchar(c)); if (c != ')') { - set_syntax_error (stix, STIX_SYNERR_RPAREN, LEXER_LOC(stix), STIX_NULL); + set_syntax_error (moo, MOO_SYNERR_RPAREN, LEXER_LOC(moo), MOO_NULL); return -1; } /* TODO: error number range check */ - ADD_TOKEN_CHAR (stix, c); - SET_TOKEN_TYPE (stix, STIX_IOTOK_ERRLIT); + ADD_TOKEN_CHAR (moo, c); + SET_TOKEN_TYPE (moo, MOO_IOTOK_ERRLIT); } else if (c == ':') { read_more_kwsym: - ADD_TOKEN_CHAR (stix, c); - SET_TOKEN_TYPE (stix, STIX_IOTOK_KEYWORD); - GET_CHAR_TO (stix, c); + ADD_TOKEN_CHAR (moo, c); + SET_TOKEN_TYPE (moo, MOO_IOTOK_KEYWORD); + GET_CHAR_TO (moo, c); - if (stix->c->in_array && is_leadidentchar(c)) + if (moo->c->in_array && is_leadidentchar(c)) { /* when reading an array literal, read as many characters as * would compose a normal keyword symbol literal */ do { - ADD_TOKEN_CHAR (stix, c); - GET_CHAR_TO (stix, c); + ADD_TOKEN_CHAR (moo, c); + GET_CHAR_TO (moo, c); } while (is_identchar(c)); @@ -898,93 +901,97 @@ static int get_ident (stix_t* stix, stix_ooci_t char_read_ahead) else { /* the last character is not a colon */ - set_syntax_error (stix, STIX_SYNERR_COLON, LEXER_LOC(stix), STIX_NULL); + set_syntax_error (moo, MOO_SYNERR_COLON, LEXER_LOC(moo), MOO_NULL); return -1; } } else { - unget_char (stix, &stix->c->lxc); + unget_char (moo, &moo->c->lxc); } } else { if (c == '.') { - stix_iolxc_t period; + moo_iolxc_t period; - period = stix->c->lxc; + period = moo->c->lxc; read_more_seg: - GET_CHAR_TO (stix, c); + GET_CHAR_TO (moo, c); if (is_leadidentchar(c)) { - SET_TOKEN_TYPE (stix, STIX_IOTOK_IDENT_DOTTED); + SET_TOKEN_TYPE (moo, MOO_IOTOK_IDENT_DOTTED); - ADD_TOKEN_CHAR (stix, '.'); + ADD_TOKEN_CHAR (moo, '.'); do { - ADD_TOKEN_CHAR (stix, c); - GET_CHAR_TO (stix, c); + ADD_TOKEN_CHAR (moo, c); + GET_CHAR_TO (moo, c); } while (is_identchar(c)); if (c == '.') goto read_more_seg; - else unget_char (stix, &stix->c->lxc); + else unget_char (moo, &moo->c->lxc); } else { - unget_char (stix, &stix->c->lxc); + unget_char (moo, &moo->c->lxc); /* unget the period itself */ - unget_char (stix, &period); + unget_char (moo, &period); } } else { - unget_char (stix, &stix->c->lxc); + unget_char (moo, &moo->c->lxc); } /* handle reserved words */ - if (is_token_word(stix, VOCA_SELF)) + if (is_token_word(moo, VOCA_SELF)) { - SET_TOKEN_TYPE (stix, STIX_IOTOK_SELF); + SET_TOKEN_TYPE (moo, MOO_IOTOK_SELF); } - else if (is_token_word(stix, VOCA_SUPER)) + else if (is_token_word(moo, VOCA_SUPER)) { - SET_TOKEN_TYPE (stix, STIX_IOTOK_SUPER); + SET_TOKEN_TYPE (moo, MOO_IOTOK_SUPER); } - else if (is_token_word(stix, VOCA_NIL)) + else if (is_token_word(moo, VOCA_NIL)) { - SET_TOKEN_TYPE (stix, STIX_IOTOK_NIL); + SET_TOKEN_TYPE (moo, MOO_IOTOK_NIL); } - else if (is_token_word(stix, VOCA_TRUE)) + else if (is_token_word(moo, VOCA_TRUE)) { - SET_TOKEN_TYPE (stix, STIX_IOTOK_TRUE); + SET_TOKEN_TYPE (moo, MOO_IOTOK_TRUE); } - else if (is_token_word(stix, VOCA_FALSE)) + else if (is_token_word(moo, VOCA_FALSE)) { - SET_TOKEN_TYPE (stix, STIX_IOTOK_FALSE); + SET_TOKEN_TYPE (moo, MOO_IOTOK_FALSE); } - else if (is_token_word(stix, VOCA_ERROR)) + else if (is_token_word(moo, VOCA_ERROR)) { - SET_TOKEN_TYPE (stix, STIX_IOTOK_ERROR); + SET_TOKEN_TYPE (moo, MOO_IOTOK_ERROR); } - else if (is_token_word(stix, VOCA_THIS_CONTEXT)) + else if (is_token_word(moo, VOCA_THIS_CONTEXT)) { - SET_TOKEN_TYPE (stix, STIX_IOTOK_THIS_CONTEXT); + SET_TOKEN_TYPE (moo, MOO_IOTOK_THIS_CONTEXT); } - else if (is_token_word(stix, VOCA_THIS_PROCESS)) + else if (is_token_word(moo, VOCA_THIS_PROCESS)) { - SET_TOKEN_TYPE (stix, STIX_IOTOK_THIS_PROCESS); + SET_TOKEN_TYPE (moo, MOO_IOTOK_THIS_PROCESS); + } + else if (is_token_word(moo, VOCA_IF)) + { + SET_TOKEN_TYPE (moo, MOO_IOTOK_IF); } } return 0; } -static int get_numlit (stix_t* stix, int negated) +static int get_numlit (moo_t* moo, int negated) { /* * number-literal := number | ("-" number) @@ -1004,12 +1011,12 @@ static int get_numlit (stix_t* stix, int negated) * fractionalDigits := decimal-integer */ - stix_ooci_t c; + moo_ooci_t c; int radix = 0, r; - c = stix->c->lxc.c; - SET_TOKEN_TYPE (stix, STIX_IOTOK_NUMLIT); + c = moo->c->lxc.c; + SET_TOKEN_TYPE (moo, MOO_IOTOK_NUMLIT); /*TODO: support a complex numeric literal */ do @@ -1018,21 +1025,21 @@ static int get_numlit (stix_t* stix, int negated) { /* collect the potential radix specifier */ r = CHAR_TO_NUM (c, 10); - STIX_ASSERT (stix, r < 10); + MOO_ASSERT (moo, r < 10); radix = radix * 10 + r; } - ADD_TOKEN_CHAR(stix, c); - GET_CHAR_TO (stix, c); + ADD_TOKEN_CHAR(moo, c); + GET_CHAR_TO (moo, c); if (c == '_') { - stix_iolxc_t underscore; - underscore = stix->c->lxc; - GET_CHAR_TO(stix, c); + moo_iolxc_t underscore; + underscore = moo->c->lxc; + GET_CHAR_TO(moo, c); if (!is_digitchar(c)) { - unget_char (stix, &stix->c->lxc); - unget_char (stix, &underscore); + unget_char (moo, &moo->c->lxc); + unget_char (moo, &underscore); break; } else continue; @@ -1047,33 +1054,33 @@ static int get_numlit (stix_t* stix, int negated) if (radix < 2 || radix > 36) { /* no digit after the radix specifier */ - set_syntax_error (stix, STIX_SYNERR_RADIX, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_RADIX, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - ADD_TOKEN_CHAR(stix, c); - GET_CHAR_TO (stix, c); + ADD_TOKEN_CHAR(moo, c); + GET_CHAR_TO (moo, c); if (CHAR_TO_NUM(c, radix) >= radix) { /* no digit after the radix specifier */ - set_syntax_error (stix, STIX_SYNERR_RADNUMLIT, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_RADNUMLIT, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } do { - ADD_TOKEN_CHAR(stix, c); - GET_CHAR_TO (stix, c); + ADD_TOKEN_CHAR(moo, c); + GET_CHAR_TO (moo, c); if (c == '_') { - stix_iolxc_t underscore; - underscore = stix->c->lxc; - GET_CHAR_TO(stix, c); + moo_iolxc_t underscore; + underscore = moo->c->lxc; + GET_CHAR_TO(moo, c); if (CHAR_TO_NUM(c, radix) >= radix) { - unget_char (stix, &stix->c->lxc); - unget_char (stix, &underscore); + unget_char (moo, &moo->c->lxc); + unget_char (moo, &underscore); break; } else continue; @@ -1081,10 +1088,10 @@ static int get_numlit (stix_t* stix, int negated) } while (CHAR_TO_NUM(c, radix) < radix); - SET_TOKEN_TYPE (stix, STIX_IOTOK_RADNUMLIT); + SET_TOKEN_TYPE (moo, MOO_IOTOK_RADNUMLIT); } - unget_char (stix, &stix->c->lxc); + unget_char (moo, &moo->c->lxc); /* * TODO: handle floating point number @@ -1092,26 +1099,26 @@ static int get_numlit (stix_t* stix, int negated) return 0; } -static int get_charlit (stix_t* stix) +static int get_charlit (moo_t* moo) { /* * character-literal := "$" character * character := normal-character | "'" */ - stix_ooci_t c = stix->c->lxc.c; /* even a new-line or white space would be taken */ - if (c == STIX_UCI_EOF) + moo_ooci_t c = moo->c->lxc.c; /* even a new-line or white space would be taken */ + if (c == MOO_UCI_EOF) { - set_syntax_error (stix, STIX_SYNERR_CLTNT, LEXER_LOC(stix), STIX_NULL); + set_syntax_error (moo, MOO_SYNERR_CLTNT, LEXER_LOC(moo), MOO_NULL); return -1; } - SET_TOKEN_TYPE (stix, STIX_IOTOK_CHARLIT); - ADD_TOKEN_CHAR(stix, c); + SET_TOKEN_TYPE (moo, MOO_IOTOK_CHARLIT); + ADD_TOKEN_CHAR(moo, c); return 0; } -static int get_strlit (stix_t* stix) +static int get_strlit (moo_t* moo) { /* * string-literal := single-quote string-character* single-quote @@ -1120,51 +1127,51 @@ static int get_strlit (stix_t* stix) * normal-character := character-except-single-quote */ - stix_ooci_t c = stix->c->lxc.c; - SET_TOKEN_TYPE (stix, STIX_IOTOK_STRLIT); + moo_ooci_t c = moo->c->lxc.c; + SET_TOKEN_TYPE (moo, MOO_IOTOK_STRLIT); do { do { - ADD_TOKEN_CHAR (stix, c); - GET_CHAR_TO (stix, c); + ADD_TOKEN_CHAR (moo, c); + GET_CHAR_TO (moo, c); - if (c == STIX_UCI_EOF) + if (c == MOO_UCI_EOF) { /* string not closed */ - set_syntax_error (stix, STIX_SYNERR_STRNC, TOKEN_LOC(stix) /*&stix->c->lxc.l*/, STIX_NULL); + set_syntax_error (moo, MOO_SYNERR_STRNC, TOKEN_LOC(moo) /*&moo->c->lxc.l*/, MOO_NULL); return -1; } } while (c != '\''); /* 'c' must be a single quote at this point*/ - GET_CHAR_TO (stix, c); + GET_CHAR_TO (moo, c); } while (c == '\''); /* if the next character is a single quote, it becomes a literal single quote character. */ - unget_char (stix, &stix->c->lxc); + unget_char (moo, &moo->c->lxc); return 0; } -static int get_string (stix_t* stix, stix_ooch_t end_char, stix_ooch_t esc_char, int regex, stix_oow_t preescaped) +static int get_string (moo_t* moo, moo_ooch_t end_char, moo_ooch_t esc_char, int regex, moo_oow_t preescaped) { - stix_ooci_t c; - stix_oow_t escaped = preescaped; - stix_oow_t digit_count = 0; - stix_ooci_t c_acc = 0; + moo_ooci_t c; + moo_oow_t escaped = preescaped; + moo_oow_t digit_count = 0; + moo_ooci_t c_acc = 0; - SET_TOKEN_TYPE (stix, STIX_IOTOK_STRLIT); + SET_TOKEN_TYPE (moo, MOO_IOTOK_STRLIT); while (1) { - GET_CHAR_TO (stix, c); + GET_CHAR_TO (moo, c); - if (c == STIX_UCI_EOF) + if (c == MOO_UCI_EOF) { - set_syntax_error (stix, STIX_SYNERR_STRNC, TOKEN_LOC(stix) /*&stix->c->lxc.l*/, STIX_NULL); + set_syntax_error (moo, MOO_SYNERR_STRNC, TOKEN_LOC(moo) /*&moo->c->lxc.l*/, MOO_NULL); return -1; } @@ -1178,14 +1185,14 @@ static int get_string (stix_t* stix, stix_ooch_t end_char, stix_ooch_t esc_char, { /* should i limit the max to 0xFF/0377? * if (c_acc > 0377) c_acc = 0377;*/ - ADD_TOKEN_CHAR (stix, c_acc); + ADD_TOKEN_CHAR (moo, c_acc); escaped = 0; } continue; } else { - ADD_TOKEN_CHAR (stix, c_acc); + ADD_TOKEN_CHAR (moo, c_acc); escaped = 0; } } @@ -1197,7 +1204,7 @@ static int get_string (stix_t* stix, stix_ooch_t end_char, stix_ooch_t esc_char, digit_count++; if (digit_count >= escaped) { - ADD_TOKEN_CHAR (stix, c_acc); + ADD_TOKEN_CHAR (moo, c_acc); escaped = 0; } continue; @@ -1208,7 +1215,7 @@ static int get_string (stix_t* stix, stix_ooch_t end_char, stix_ooch_t esc_char, digit_count++; if (digit_count >= escaped) { - ADD_TOKEN_CHAR (stix, c_acc); + ADD_TOKEN_CHAR (moo, c_acc); escaped = 0; } continue; @@ -1219,20 +1226,20 @@ static int get_string (stix_t* stix, stix_ooch_t end_char, stix_ooch_t esc_char, digit_count++; if (digit_count >= escaped) { - ADD_TOKEN_CHAR (stix, c_acc); + ADD_TOKEN_CHAR (moo, c_acc); escaped = 0; } continue; } else { - stix_ooch_t rc; + moo_ooch_t rc; rc = (escaped == 2)? 'x': (escaped == 4)? 'u': 'U'; if (digit_count == 0) - ADD_TOKEN_CHAR (stix, rc); - else ADD_TOKEN_CHAR (stix, c_acc); + ADD_TOKEN_CHAR (moo, rc); + else ADD_TOKEN_CHAR (moo, c_acc); escaped = 0; } @@ -1275,14 +1282,14 @@ static int get_string (stix_t* stix, stix_ooch_t end_char, stix_ooch_t esc_char, c_acc = 0; continue; } - else if (c == 'u' && STIX_SIZEOF(stix_ooch_t) >= 2) + else if (c == 'u' && MOO_SIZEOF(moo_ooch_t) >= 2) { escaped = 4; digit_count = 0; c_acc = 0; continue; } - else if (c == 'U' && STIX_SIZEOF(stix_ooch_t) >= 4) + else if (c == 'U' && MOO_SIZEOF(moo_ooch_t) >= 4) { escaped = 8; digit_count = 0; @@ -1296,194 +1303,194 @@ static int get_string (stix_t* stix, stix_ooch_t end_char, stix_ooch_t esc_char, * an unhandled escape sequence can be handled * outside this function since the escape character * is preserved.*/ - ADD_TOKEN_CHAR (stix, esc_char); + ADD_TOKEN_CHAR (moo, esc_char); } escaped = 0; } - ADD_TOKEN_CHAR (stix, c); + ADD_TOKEN_CHAR (moo, c); } return 0; } -static int get_binsel (stix_t* stix) +static int get_binsel (moo_t* moo) { /* * binary-selector := binary-selector-character+ */ - stix_ooci_t oc; + moo_ooci_t oc; - oc = stix->c->lxc.c; - ADD_TOKEN_CHAR (stix, oc); + oc = moo->c->lxc.c; + ADD_TOKEN_CHAR (moo, oc); - GET_CHAR (stix); + GET_CHAR (moo); /* special case if a minus is followed by a digit immediately */ - if (oc == '-' && is_digitchar(stix->c->lxc.c)) return get_numlit (stix, 1); + if (oc == '-' && is_digitchar(moo->c->lxc.c)) return get_numlit (moo, 1); #if 1 /* up to 2 characters only */ - if (is_binselchar (stix->c->lxc.c)) + if (is_binselchar (moo->c->lxc.c)) { - ADD_TOKEN_CHAR (stix, stix->c->lxc.c); + ADD_TOKEN_CHAR (moo, moo->c->lxc.c); } else { - unget_char (stix, &stix->c->lxc); + unget_char (moo, &moo->c->lxc); } #else /* or up to any occurrences */ - while (is_binselchar(stix->c->lxc.c)) + while (is_binselchar(moo->c->lxc.c)) { - ADD_TOKEN_CHAR (stix, c); - GET_CHAR (stix); + ADD_TOKEN_CHAR (moo, c); + GET_CHAR (moo); } - unget_char (stix, &stix->c->lxc); + unget_char (moo, &moo->c->lxc); #endif - SET_TOKEN_TYPE (stix, STIX_IOTOK_BINSEL); + SET_TOKEN_TYPE (moo, MOO_IOTOK_BINSEL); return 0; } -static int get_token (stix_t* stix) +static int get_token (moo_t* moo) { - stix_ooci_t c; + moo_ooci_t c; int n; retry: - GET_CHAR (stix); + GET_CHAR (moo); do { /* skip spaces */ - while (is_spacechar(stix->c->lxc.c)) GET_CHAR (stix); - /* the first character after the last space is in stix->c->lxc */ - if ((n = skip_comment(stix)) <= -1) return -1; + while (is_spacechar(moo->c->lxc.c)) GET_CHAR (moo); + /* the first character after the last space is in moo->c->lxc */ + if ((n = skip_comment(moo)) <= -1) return -1; } while (n >= 1); /* clear the token name, reset its location */ - SET_TOKEN_TYPE (stix, STIX_IOTOK_EOF); /* is it correct? */ - CLEAR_TOKEN_NAME (stix); - stix->c->tok.loc = stix->c->lxc.l; /* remember token location */ + SET_TOKEN_TYPE (moo, MOO_IOTOK_EOF); /* is it correct? */ + CLEAR_TOKEN_NAME (moo); + moo->c->tok.loc = moo->c->lxc.l; /* remember token location */ - c = stix->c->lxc.c; + c = moo->c->lxc.c; switch (c) { - case STIX_UCI_EOF: + case MOO_UCI_EOF: { int n; - n = end_include (stix); + n = end_include (moo); if (n <= -1) return -1; if (n >= 1) goto retry; - SET_TOKEN_TYPE (stix, STIX_IOTOK_EOF); - ADD_TOKEN_STR(stix, vocas[VOCA_EOF].str, vocas[VOCA_EOF].len); + SET_TOKEN_TYPE (moo, MOO_IOTOK_EOF); + ADD_TOKEN_STR(moo, vocas[VOCA_EOF].str, vocas[VOCA_EOF].len); break; } case '$': /* character literal */ - GET_CHAR (stix); - if (get_charlit(stix) <= -1) return -1; + GET_CHAR (moo); + if (get_charlit(moo) <= -1) return -1; break; case '\'': /* string literal */ - GET_CHAR (stix); - if (get_strlit(stix) <= -1) return -1; + GET_CHAR (moo); + if (get_strlit(moo) <= -1) return -1; break; case ':': - SET_TOKEN_TYPE (stix, STIX_IOTOK_COLON); - ADD_TOKEN_CHAR (stix, c); - GET_CHAR_TO (stix, c); + SET_TOKEN_TYPE (moo, MOO_IOTOK_COLON); + ADD_TOKEN_CHAR (moo, c); + GET_CHAR_TO (moo, c); if (c == '=') { - SET_TOKEN_TYPE (stix, STIX_IOTOK_ASSIGN); - ADD_TOKEN_CHAR (stix, c); + SET_TOKEN_TYPE (moo, MOO_IOTOK_ASSIGN); + ADD_TOKEN_CHAR (moo, c); } else { - unget_char (stix, &stix->c->lxc); + unget_char (moo, &moo->c->lxc); } break; case '^': - SET_TOKEN_TYPE (stix, STIX_IOTOK_RETURN); - ADD_TOKEN_CHAR(stix, c); + SET_TOKEN_TYPE (moo, MOO_IOTOK_RETURN); + ADD_TOKEN_CHAR(moo, c); #if 0 - GET_CHAR_TO (stix, c); + GET_CHAR_TO (moo, c); /* TODO: support explicit block return */ if (c == '^') { /* ^^ */ - TOKEN_TYPE(stix) == STIX_IOTOK_BLKRET; - ADD_TOKEN_CHAR (stix, c); + TOKEN_TYPE(moo) == MOO_IOTOK_BLKRET; + ADD_TOKEN_CHAR (moo, c); } else { - unget_char (stix, &stix->c->lxc); + unget_char (moo, &moo->c->lxc); } #endif break; case '{': /* extension */ - SET_TOKEN_TYPE (stix, STIX_IOTOK_LBRACE); + SET_TOKEN_TYPE (moo, MOO_IOTOK_LBRACE); goto single_char_token; case '}': /* extension */ - SET_TOKEN_TYPE (stix, STIX_IOTOK_RBRACE); + SET_TOKEN_TYPE (moo, MOO_IOTOK_RBRACE); goto single_char_token; case '[': - SET_TOKEN_TYPE (stix, STIX_IOTOK_LBRACK); + SET_TOKEN_TYPE (moo, MOO_IOTOK_LBRACK); goto single_char_token; case ']': - SET_TOKEN_TYPE (stix, STIX_IOTOK_RBRACK); + SET_TOKEN_TYPE (moo, MOO_IOTOK_RBRACK); goto single_char_token; case '(': - SET_TOKEN_TYPE (stix, STIX_IOTOK_LPAREN); + SET_TOKEN_TYPE (moo, MOO_IOTOK_LPAREN); goto single_char_token; case ')': - SET_TOKEN_TYPE (stix, STIX_IOTOK_RPAREN); + SET_TOKEN_TYPE (moo, MOO_IOTOK_RPAREN); goto single_char_token; case '.': - SET_TOKEN_TYPE (stix, STIX_IOTOK_PERIOD); + SET_TOKEN_TYPE (moo, MOO_IOTOK_PERIOD); goto single_char_token; case ',': - SET_TOKEN_TYPE (stix, STIX_IOTOK_COMMA); + SET_TOKEN_TYPE (moo, MOO_IOTOK_COMMA); goto single_char_token; case ';': - SET_TOKEN_TYPE (stix, STIX_IOTOK_SEMICOLON); + SET_TOKEN_TYPE (moo, MOO_IOTOK_SEMICOLON); goto single_char_token; case '#': - ADD_TOKEN_CHAR(stix, c); - GET_CHAR_TO (stix, c); + ADD_TOKEN_CHAR(moo, c); + GET_CHAR_TO (moo, c); switch (c) { - case STIX_UCI_EOF: - set_syntax_error (stix, STIX_SYNERR_HLTNT, LEXER_LOC(stix), STIX_NULL); + case MOO_UCI_EOF: + set_syntax_error (moo, MOO_SYNERR_HLTNT, LEXER_LOC(moo), MOO_NULL); return -1; case '(': /* #( */ - ADD_TOKEN_CHAR(stix, c); - SET_TOKEN_TYPE (stix, STIX_IOTOK_ARPAREN); + ADD_TOKEN_CHAR(moo, c); + SET_TOKEN_TYPE (moo, MOO_IOTOK_ARPAREN); break; case '[': /* #[ - byte array literal */ - ADD_TOKEN_CHAR(stix, c); - SET_TOKEN_TYPE (stix, STIX_IOTOK_BAPAREN); + ADD_TOKEN_CHAR(moo, c); + SET_TOKEN_TYPE (moo, MOO_IOTOK_BAPAREN); break; case '\'': /* quoted symbol literal */ - GET_CHAR (stix); - if (get_strlit(stix) <= -1) return -1; - SET_TOKEN_TYPE (stix, STIX_IOTOK_SYMLIT); + GET_CHAR (moo); + if (get_strlit(moo) <= -1) return -1; + SET_TOKEN_TYPE (moo, MOO_IOTOK_SYMLIT); break; default: @@ -1496,19 +1503,19 @@ retry: { do { - ADD_TOKEN_CHAR (stix, c); - GET_CHAR_TO (stix, c); + ADD_TOKEN_CHAR (moo, c); + GET_CHAR_TO (moo, c); } while (is_binselchar(c)); - unget_char (stix, &stix->c->lxc); + unget_char (moo, &moo->c->lxc); } else if (is_leadidentchar(c)) { do { - ADD_TOKEN_CHAR (stix, c); - GET_CHAR_TO (stix, c); + ADD_TOKEN_CHAR (moo, c); + GET_CHAR_TO (moo, c); } while (is_identchar(c)); @@ -1516,15 +1523,15 @@ retry: { /* keyword symbol - e.g. #ifTrue:ifFalse: */ read_more_word: - ADD_TOKEN_CHAR (stix, c); - GET_CHAR_TO (stix, c); + ADD_TOKEN_CHAR (moo, c); + GET_CHAR_TO (moo, c); if (is_leadidentchar(c)) { do { - ADD_TOKEN_CHAR (stix, c); - GET_CHAR_TO (stix, c); + ADD_TOKEN_CHAR (moo, c); + GET_CHAR_TO (moo, c); } while (is_identchar(c)); @@ -1534,57 +1541,57 @@ retry: /* if a colon is found in the middle of a symbol, * the last charater is expected to be a colon as well. * but, the last character is not a colon */ - set_syntax_error (stix, STIX_SYNERR_COLON, LEXER_LOC(stix), STIX_NULL); + set_syntax_error (moo, MOO_SYNERR_COLON, LEXER_LOC(moo), MOO_NULL); return -1; } } else { - unget_char (stix, &stix->c->lxc); + unget_char (moo, &moo->c->lxc); } } else if (c == '.') { /* dotted symbol e.g. #Planet.Earth.Object */ - stix_iolxc_t period; + moo_iolxc_t period; - period = stix->c->lxc; + period = moo->c->lxc; read_more_seg: - GET_CHAR_TO (stix, c); + GET_CHAR_TO (moo, c); if (is_leadidentchar(c)) { - ADD_TOKEN_CHAR (stix, '.'); + ADD_TOKEN_CHAR (moo, '.'); do { - ADD_TOKEN_CHAR (stix, c); - GET_CHAR_TO (stix, c); + ADD_TOKEN_CHAR (moo, c); + GET_CHAR_TO (moo, c); } while (is_identchar(c)); if (c == '.') goto read_more_seg; - else unget_char (stix, &stix->c->lxc); + else unget_char (moo, &moo->c->lxc); } else { - unget_char (stix, &stix->c->lxc); - unget_char (stix, &period); + unget_char (moo, &moo->c->lxc); + unget_char (moo, &period); } } else { - unget_char (stix, &stix->c->lxc); + unget_char (moo, &moo->c->lxc); } } else { - set_syntax_error (stix, STIX_SYNERR_HLTNT, LEXER_LOC(stix), STIX_NULL); + set_syntax_error (moo, MOO_SYNERR_HLTNT, LEXER_LOC(moo), MOO_NULL); return -1; } - SET_TOKEN_TYPE (stix, STIX_IOTOK_SYMLIT); + SET_TOKEN_TYPE (moo, MOO_IOTOK_SYMLIT); break; } @@ -1594,31 +1601,31 @@ retry: case 'S': /* a string with a C-style escape sequences */ case 'M': /* a symbol with a C-style escape sequences */ { - stix_ooci_t saved_c = c; + moo_ooci_t saved_c = c; - GET_CHAR_TO (stix, c); + GET_CHAR_TO (moo, c); if (c == '\'') { - /*GET_CHAR (stix);*/ - if (get_string(stix, '\'', '\\', 0, 0) <= -1) return -1; + /*GET_CHAR (moo);*/ + if (get_string(moo, '\'', '\\', 0, 0) <= -1) return -1; if (saved_c == 'C') { - if (stix->c->tok.name.len != 1) + if (moo->c->tok.name.len != 1) { - set_syntax_error (stix, STIX_SYNERR_CHARLIT, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_CHARLIT, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - SET_TOKEN_TYPE (stix, STIX_IOTOK_CHARLIT); + SET_TOKEN_TYPE (moo, MOO_IOTOK_CHARLIT); } else if (saved_c == 'M') { - SET_TOKEN_TYPE (stix, STIX_IOTOK_SYMLIT); + SET_TOKEN_TYPE (moo, MOO_IOTOK_SYMLIT); } } else { - if (get_ident(stix, saved_c) <= -1) return -1; + if (get_ident(moo, saved_c) <= -1) return -1; } break; @@ -1628,15 +1635,15 @@ retry: /* case 'R': TODO: regular expression? - GET_CHAR_TO (stix, c); + GET_CHAR_TO (moo, c); if (c == '\'') { - GET_CHAR (stix); - if (get_rexlit(stix) <= -1) return -1; + GET_CHAR (moo); + if (get_rexlit(moo) <= -1) return -1; } else { - if (get_ident(stix, 'R') <= -1) return -1; + if (get_ident(moo, 'R') <= -1) return -1; } break; */ @@ -1644,145 +1651,145 @@ retry: default: if (is_leadidentchar(c)) { - if (get_ident(stix, STIX_UCI_EOF) <= -1) return -1; + if (get_ident(moo, MOO_UCI_EOF) <= -1) return -1; } else if (is_digitchar(c)) { - if (get_numlit(stix, 0) <= -1) return -1; + if (get_numlit(moo, 0) <= -1) return -1; } else if (is_binselchar(c)) { /* binary selector */ - if (get_binsel(stix) <= -1) return -1; + if (get_binsel(moo) <= -1) return -1; } else { - stix->c->ilchr = (stix_ooch_t)c; - set_syntax_error (stix, STIX_SYNERR_ILCHR, LEXER_LOC(stix), &stix->c->ilchr_ucs); + moo->c->ilchr = (moo_ooch_t)c; + set_syntax_error (moo, MOO_SYNERR_ILCHR, LEXER_LOC(moo), &moo->c->ilchr_ucs); return -1; } break; single_char_token: - ADD_TOKEN_CHAR(stix, c); + ADD_TOKEN_CHAR(moo, c); break; } -STIX_DEBUG2 (stix, "TOKEN: [%.*js]\n", (stix_ooi_t)stix->c->tok.name.len, stix->c->tok.name.ptr); +MOO_DEBUG2 (moo, "TOKEN: [%.*js]\n", (moo_ooi_t)moo->c->tok.name.len, moo->c->tok.name.ptr); return 0; } -static void clear_io_names (stix_t* stix) +static void clear_io_names (moo_t* moo) { - stix_iolink_t* cur; + moo_iolink_t* cur; - STIX_ASSERT (stix, stix->c != STIX_NULL); + MOO_ASSERT (moo, moo->c != MOO_NULL); - while (stix->c->io_names) + while (moo->c->io_names) { - cur = stix->c->io_names; - stix->c->io_names = cur->link; - stix_freemem (stix, cur); + cur = moo->c->io_names; + moo->c->io_names = cur->link; + moo_freemem (moo, cur); } } -static const stix_ooch_t* add_io_name (stix_t* stix, const stix_oocs_t* name) +static const moo_ooch_t* add_io_name (moo_t* moo, const moo_oocs_t* name) { - stix_iolink_t* link; - stix_ooch_t* ptr; + moo_iolink_t* link; + moo_ooch_t* ptr; - link = (stix_iolink_t*) stix_callocmem (stix, STIX_SIZEOF(*link) + STIX_SIZEOF(stix_ooch_t) * (name->len + 1)); - if (!link) return STIX_NULL; + link = (moo_iolink_t*) moo_callocmem (moo, MOO_SIZEOF(*link) + MOO_SIZEOF(moo_ooch_t) * (name->len + 1)); + if (!link) return MOO_NULL; - ptr = (stix_ooch_t*)(link + 1); + ptr = (moo_ooch_t*)(link + 1); - stix_copyoochars (ptr, name->ptr, name->len); + moo_copyoochars (ptr, name->ptr, name->len); ptr[name->len] = '\0'; - link->link = stix->c->io_names; - stix->c->io_names = link; + link->link = moo->c->io_names; + moo->c->io_names = link; return ptr; } -static int begin_include (stix_t* stix) +static int begin_include (moo_t* moo) { - stix_ioarg_t* arg; - const stix_ooch_t* io_name; + moo_ioarg_t* arg; + const moo_ooch_t* io_name; - io_name = add_io_name (stix, TOKEN_NAME(stix)); + io_name = add_io_name (moo, TOKEN_NAME(moo)); if (!io_name) return -1; - arg = (stix_ioarg_t*) stix_callocmem (stix, STIX_SIZEOF(*arg)); + arg = (moo_ioarg_t*) moo_callocmem (moo, MOO_SIZEOF(*arg)); if (!arg) goto oops; arg->name = io_name; arg->line = 1; arg->colm = 1; /*arg->nl = '\0';*/ - arg->includer = stix->c->curinp; + arg->includer = moo->c->curinp; - if (stix->c->impl (stix, STIX_IO_OPEN, arg) <= -1) + if (moo->c->impl (moo, MOO_IO_OPEN, arg) <= -1) { - set_syntax_error (stix, STIX_SYNERR_INCLUDE, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_INCLUDE, TOKEN_LOC(moo), TOKEN_NAME(moo)); goto oops; } - GET_TOKEN (stix); - if (TOKEN_TYPE(stix) != STIX_IOTOK_PERIOD) + GET_TOKEN (moo); + if (TOKEN_TYPE(moo) != MOO_IOTOK_PERIOD) { /* check if a period is following the includee name */ - set_syntax_error (stix, STIX_SYNERR_PERIOD, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_PERIOD, TOKEN_LOC(moo), TOKEN_NAME(moo)); goto oops; } /* switch to the includee's stream */ - stix->c->curinp = arg; - /* stix->c->depth.incl++; */ + moo->c->curinp = arg; + /* moo->c->depth.incl++; */ /* read in the first character in the included file. * so the next call to get_token() sees the character read * from this file. */ - if (get_token(stix) <= -1) + if (get_token(moo) <= -1) { - end_include (stix); + end_include (moo); /* i don't jump to oops since i've called - * end_include() which frees stix->c->curinp/arg */ + * end_include() which frees moo->c->curinp/arg */ return -1; } return 0; oops: - if (arg) stix_freemem (stix, arg); + if (arg) moo_freemem (moo, arg); return -1; } -static int end_include (stix_t* stix) +static int end_include (moo_t* moo) { int x; - stix_ioarg_t* cur; + moo_ioarg_t* cur; - if (stix->c->curinp == &stix->c->arg) return 0; /* no include */ + if (moo->c->curinp == &moo->c->arg) return 0; /* no include */ /* if it is an included file, close it and * retry to read a character from an outer file */ - x = stix->c->impl (stix, STIX_IO_CLOSE, stix->c->curinp); + x = moo->c->impl (moo, MOO_IO_CLOSE, moo->c->curinp); /* if closing has failed, still destroy the * sio structure first as normal and return * the failure below. this way, the caller - * does not call STIX_IO_CLOSE on - * stix->c->curinp again. */ + * does not call MOO_IO_CLOSE on + * moo->c->curinp again. */ - cur = stix->c->curinp; - stix->c->curinp = stix->c->curinp->includer; + cur = moo->c->curinp; + moo->c->curinp = moo->c->curinp->includer; - STIX_ASSERT (stix, cur->name != STIX_NULL); - stix_freemem (stix, cur); - /* stix->parse.depth.incl--; */ + MOO_ASSERT (moo, cur->name != MOO_NULL); + moo_freemem (moo, cur); + /* moo->parse.depth.incl--; */ if (x != 0) { @@ -1790,7 +1797,7 @@ static int end_include (stix_t* stix) return -1; } - stix->c->lxc = stix->c->curinp->lxc; + moo->c->lxc = moo->c->curinp->lxc; return 1; /* ended the included file successfully */ } @@ -1798,40 +1805,40 @@ static int end_include (stix_t* stix) * Byte-Code Generator * --------------------------------------------------------------------- */ -static STIX_INLINE int emit_byte_instruction (stix_t* stix, stix_oob_t code) +static MOO_INLINE int emit_byte_instruction (moo_t* moo, moo_oob_t code) { /* the context object has the ip field. it should be representable * in a small integer. for simplicity, limit the total byte code length * to fit in a small integer. because 'ip' points to the next instruction * to execute, he upper bound should be (max - 1) so that i stays * at the max when incremented */ - if (stix->c->mth.code.len == STIX_SMOOI_MAX - 1) + if (moo->c->mth.code.len == MOO_SMOOI_MAX - 1) { - stix->errnum = STIX_EBCFULL; /* byte code too big */ + moo->errnum = MOO_EBCFULL; /* byte code too big */ return -1; } - if (stix->c->mth.code.len >= stix->c->mth.code_capa) + if (moo->c->mth.code.len >= moo->c->mth.code_capa) { - stix_oob_t* tmp; - stix_oow_t newcapa; + moo_oob_t* tmp; + moo_oow_t newcapa; - newcapa = STIX_ALIGN (stix->c->mth.code.len + 1, CODE_BUFFER_ALIGN); + newcapa = MOO_ALIGN (moo->c->mth.code.len + 1, CODE_BUFFER_ALIGN); - tmp = stix_reallocmem (stix, stix->c->mth.code.ptr, newcapa * STIX_SIZEOF(*tmp)); + tmp = moo_reallocmem (moo, moo->c->mth.code.ptr, newcapa * MOO_SIZEOF(*tmp)); if (!tmp) return -1; - stix->c->mth.code.ptr = tmp; - stix->c->mth.code_capa = newcapa; + moo->c->mth.code.ptr = tmp; + moo->c->mth.code_capa = newcapa; } - stix->c->mth.code.ptr[stix->c->mth.code.len++] = code; + moo->c->mth.code.ptr[moo->c->mth.code.len++] = code; return 0; } -static int emit_single_param_instruction (stix_t* stix, int cmd, stix_oow_t param_1) +static int emit_single_param_instruction (moo_t* moo, int cmd, moo_oow_t param_1) { - stix_oob_t bc; + moo_oob_t bc; switch (cmd) { @@ -1845,7 +1852,7 @@ static int emit_single_param_instruction (stix_t* stix, int cmd, stix_oow_t para if (param_1 < 8) { /* low 3 bits to hold the parameter */ - bc = (stix_oob_t)(cmd & 0xF8) | (stix_oob_t)param_1; + bc = (moo_oob_t)(cmd & 0xF8) | (moo_oob_t)param_1; goto write_short; } else @@ -1865,7 +1872,7 @@ static int emit_single_param_instruction (stix_t* stix, int cmd, stix_oow_t para if (param_1 < 4) { /* low 2 bits to hold the parameter */ - bc = (stix_oob_t)(cmd & 0xFC) | (stix_oob_t)param_1; + bc = (moo_oob_t)(cmd & 0xFC) | (moo_oob_t)param_1; goto write_short; } else @@ -1884,34 +1891,34 @@ static int emit_single_param_instruction (stix_t* stix, int cmd, stix_oow_t para goto write_long; } - stix->errnum = STIX_EINVAL; + moo->errnum = MOO_EINVAL; return -1; write_short: - if (emit_byte_instruction(stix, bc) <= -1) return -1; + if (emit_byte_instruction(moo, bc) <= -1) return -1; return 0; write_long: if (param_1 > MAX_CODE_PARAM) { - stix->errnum = STIX_ERANGE; + moo->errnum = MOO_ERANGE; return -1; } -#if (STIX_BCODE_LONG_PARAM_SIZE == 2) - if (emit_byte_instruction(stix, bc) <= -1 || - emit_byte_instruction(stix, (param_1 >> 8) & 0xFF) <= -1 || - emit_byte_instruction(stix, param_1 & 0xFF) <= -1) return -1; +#if (MOO_BCODE_LONG_PARAM_SIZE == 2) + if (emit_byte_instruction(moo, bc) <= -1 || + emit_byte_instruction(moo, (param_1 >> 8) & 0xFF) <= -1 || + emit_byte_instruction(moo, param_1 & 0xFF) <= -1) return -1; #else - if (emit_byte_instruction(stix, bc) <= -1 || - emit_byte_instruction(stix, param_1) <= -1) return -1; + if (emit_byte_instruction(moo, bc) <= -1 || + emit_byte_instruction(moo, param_1) <= -1) return -1; #endif return 0; } -static int emit_double_param_instruction (stix_t* stix, int cmd, stix_oow_t param_1, stix_oow_t param_2) +static int emit_double_param_instruction (moo_t* moo, int cmd, moo_oow_t param_1, moo_oow_t param_2) { - stix_oob_t bc; + moo_oob_t bc; switch (cmd) { @@ -1926,7 +1933,7 @@ static int emit_double_param_instruction (stix_t* stix, int cmd, stix_oow_t para if (param_1 < 4 && param_2 < 0xFF) { /* low 2 bits of the instruction code is the first parameter */ - bc = (stix_oob_t)(cmd & 0xFC) | (stix_oob_t)param_1; + bc = (moo_oob_t)(cmd & 0xFC) | (moo_oob_t)param_1; goto write_short; } else @@ -1941,80 +1948,80 @@ static int emit_double_param_instruction (stix_t* stix, int cmd, stix_oow_t para goto write_long; } - stix->errnum = STIX_EINVAL; + moo->errnum = MOO_EINVAL; return -1; write_short: - if (emit_byte_instruction(stix, bc) <= -1 || - emit_byte_instruction(stix, param_2) <= -1) return -1; + if (emit_byte_instruction(moo, bc) <= -1 || + emit_byte_instruction(moo, param_2) <= -1) return -1; return 0; write_long: if (param_1 > MAX_CODE_PARAM || param_2 > MAX_CODE_PARAM) { - stix->errnum = STIX_ERANGE; + moo->errnum = MOO_ERANGE; return -1; } -#if (STIX_BCODE_LONG_PARAM_SIZE == 2) - if (emit_byte_instruction(stix, bc) <= -1 || - emit_byte_instruction(stix, (param_1 >> 8) & 0xFF) <= -1 || - emit_byte_instruction(stix, param_1 & 0xFF) <= -1 || - emit_byte_instruction(stix, (param_2 >> 8) & 0xFF) <= -1 || - emit_byte_instruction(stix, param_2 & 0xFF) <= -1) return -1; +#if (MOO_BCODE_LONG_PARAM_SIZE == 2) + if (emit_byte_instruction(moo, bc) <= -1 || + emit_byte_instruction(moo, (param_1 >> 8) & 0xFF) <= -1 || + emit_byte_instruction(moo, param_1 & 0xFF) <= -1 || + emit_byte_instruction(moo, (param_2 >> 8) & 0xFF) <= -1 || + emit_byte_instruction(moo, param_2 & 0xFF) <= -1) return -1; #else - if (emit_byte_instruction(stix, bc) <= -1 || - emit_byte_instruction(stix, param_1) <= -1 || - emit_byte_instruction(stix, param_2) <= -1) return -1; + if (emit_byte_instruction(moo, bc) <= -1 || + emit_byte_instruction(moo, param_1) <= -1 || + emit_byte_instruction(moo, param_2) <= -1) return -1; #endif return 0; } -static int emit_push_smooi_literal (stix_t* stix, stix_ooi_t i) +static int emit_push_smooi_literal (moo_t* moo, moo_ooi_t i) { - stix_oow_t index; + moo_oow_t index; switch (i) { case -1: - return emit_byte_instruction (stix, BCODE_PUSH_NEGONE); + return emit_byte_instruction (moo, BCODE_PUSH_NEGONE); case 0: - return emit_byte_instruction (stix, BCODE_PUSH_ZERO); + return emit_byte_instruction (moo, BCODE_PUSH_ZERO); case 1: - return emit_byte_instruction (stix, BCODE_PUSH_ONE); + return emit_byte_instruction (moo, BCODE_PUSH_ONE); case 2: - return emit_byte_instruction (stix, BCODE_PUSH_TWO); + return emit_byte_instruction (moo, BCODE_PUSH_TWO); } if (i >= 0 && i <= MAX_CODE_PARAM) { - return emit_single_param_instruction(stix, BCODE_PUSH_INTLIT, i); + return emit_single_param_instruction(moo, BCODE_PUSH_INTLIT, i); } - else if (i < 0 && i >= -(stix_ooi_t)MAX_CODE_PARAM) + else if (i < 0 && i >= -(moo_ooi_t)MAX_CODE_PARAM) { - return emit_single_param_instruction(stix, BCODE_PUSH_NEGINTLIT, -i); + return emit_single_param_instruction(moo, BCODE_PUSH_NEGINTLIT, -i); } - if (add_literal(stix, STIX_SMOOI_TO_OOP(i), &index) <= -1 || - emit_single_param_instruction(stix, BCODE_PUSH_LITERAL_0, index) <= -1) return -1; + if (add_literal(moo, MOO_SMOOI_TO_OOP(i), &index) <= -1 || + emit_single_param_instruction(moo, BCODE_PUSH_LITERAL_0, index) <= -1) return -1; return 0; } -static int emit_push_character_literal (stix_t* stix, stix_ooch_t ch) +static int emit_push_character_literal (moo_t* moo, moo_ooch_t ch) { - stix_oow_t index; + moo_oow_t index; if (ch >= 0 && ch <= MAX_CODE_PARAM) { - return emit_single_param_instruction (stix, BCODE_PUSH_CHARLIT, ch); + return emit_single_param_instruction (moo, BCODE_PUSH_CHARLIT, ch); } - if (add_literal(stix, STIX_CHAR_TO_OOP(ch), &index) <= -1 || - emit_single_param_instruction(stix, BCODE_PUSH_LITERAL_0, index) <= -1) return -1; + if (add_literal(moo, MOO_CHAR_TO_OOP(ch), &index) <= -1 || + emit_single_param_instruction(moo, BCODE_PUSH_LITERAL_0, index) <= -1) return -1; return 0; } @@ -2023,138 +2030,138 @@ static int emit_push_character_literal (stix_t* stix, stix_ooch_t ch) * --------------------------------------------------------------------- */ -static int add_literal (stix_t* stix, stix_oop_t lit, stix_oow_t* index) +static int add_literal (moo_t* moo, moo_oop_t lit, moo_oow_t* index) { - stix_oow_t i; + moo_oow_t i; - for (i = 0; i < stix->c->mth.literal_count; i++) + for (i = 0; i < moo->c->mth.literal_count; i++) { /* * this removes redundancy of symbols, characters, and small integers. * more complex redundacy check may be done somewhere else like * in add_string_literal(). */ - if (stix->c->mth.literals[i] == lit) + if (moo->c->mth.literals[i] == lit) { *index = i; return i; } } - if (stix->c->mth.literal_count >= stix->c->mth.literal_capa) + if (moo->c->mth.literal_count >= moo->c->mth.literal_capa) { - stix_oop_t* tmp; - stix_oow_t new_capa; + moo_oop_t* tmp; + moo_oow_t new_capa; - new_capa = STIX_ALIGN (stix->c->mth.literal_count + 1, LITERAL_BUFFER_ALIGN); - tmp = (stix_oop_t*)stix_reallocmem (stix, stix->c->mth.literals, new_capa * STIX_SIZEOF(*tmp)); + new_capa = MOO_ALIGN (moo->c->mth.literal_count + 1, LITERAL_BUFFER_ALIGN); + tmp = (moo_oop_t*)moo_reallocmem (moo, moo->c->mth.literals, new_capa * MOO_SIZEOF(*tmp)); if (!tmp) return -1; - stix->c->mth.literal_capa = new_capa; - stix->c->mth.literals = tmp; + moo->c->mth.literal_capa = new_capa; + moo->c->mth.literals = tmp; } - *index = stix->c->mth.literal_count; - stix->c->mth.literals[stix->c->mth.literal_count++] = lit; + *index = moo->c->mth.literal_count; + moo->c->mth.literals[moo->c->mth.literal_count++] = lit; return 0; } -static int add_string_literal (stix_t* stix, const stix_oocs_t* str, stix_oow_t* index) +static int add_string_literal (moo_t* moo, const moo_oocs_t* str, moo_oow_t* index) { - stix_oop_t lit; - stix_oow_t i; + moo_oop_t lit; + moo_oow_t i; - for (i = 0; i < stix->c->mth.literal_count; i++) + for (i = 0; i < moo->c->mth.literal_count; i++) { - lit = stix->c->mth.literals[i]; + lit = moo->c->mth.literals[i]; - if (STIX_CLASSOF(stix, lit) == stix->_string && - STIX_OBJ_GET_SIZE(lit) == str->len && - stix_equaloochars(((stix_oop_char_t)lit)->slot, str->ptr, str->len)) + if (MOO_CLASSOF(moo, lit) == moo->_string && + MOO_OBJ_GET_SIZE(lit) == str->len && + moo_equaloochars(((moo_oop_char_t)lit)->slot, str->ptr, str->len)) { *index = i; return 0; } } - lit = stix_instantiate (stix, stix->_string, str->ptr, str->len); + lit = moo_instantiate (moo, moo->_string, str->ptr, str->len); if (!lit) return -1; - return add_literal (stix, lit, index); + return add_literal (moo, lit, index); } -static int add_symbol_literal (stix_t* stix, const stix_oocs_t* str, int offset, stix_oow_t* index) +static int add_symbol_literal (moo_t* moo, const moo_oocs_t* str, int offset, moo_oow_t* index) { - stix_oop_t tmp; + moo_oop_t tmp; - tmp = stix_makesymbol (stix, str->ptr + offset, str->len - offset); + tmp = moo_makesymbol (moo, str->ptr + offset, str->len - offset); if (!tmp) return -1; - return add_literal (stix, tmp, index); + return add_literal (moo, tmp, index); } -static STIX_INLINE int set_class_fqn (stix_t* stix, const stix_oocs_t* name) +static MOO_INLINE int set_class_fqn (moo_t* moo, const moo_oocs_t* name) { - if (copy_string_to (stix, name, &stix->c->cls.fqn, &stix->c->cls.fqn_capa, 0, '\0') <= -1) return -1; - stix->c->cls.name = stix->c->cls.fqn; + if (copy_string_to (moo, name, &moo->c->cls.fqn, &moo->c->cls.fqn_capa, 0, '\0') <= -1) return -1; + moo->c->cls.name = moo->c->cls.fqn; return 0; } -static STIX_INLINE int set_superclass_fqn (stix_t* stix, const stix_oocs_t* name) +static MOO_INLINE int set_superclass_fqn (moo_t* moo, const moo_oocs_t* name) { - if (copy_string_to (stix, name, &stix->c->cls.superfqn, &stix->c->cls.superfqn_capa, 0, '\0') <= -1) return -1; - stix->c->cls.supername = stix->c->cls.superfqn; + if (copy_string_to (moo, name, &moo->c->cls.superfqn, &moo->c->cls.superfqn_capa, 0, '\0') <= -1) return -1; + moo->c->cls.supername = moo->c->cls.superfqn; return 0; } -static STIX_INLINE int add_class_level_variable (stix_t* stix, var_type_t index, const stix_oocs_t* name) +static MOO_INLINE int add_class_level_variable (moo_t* moo, var_type_t index, const moo_oocs_t* name) { int n; - n = copy_string_to (stix, name, &stix->c->cls.vars[index], &stix->c->cls.vars_capa[index], 1, ' '); + n = copy_string_to (moo, name, &moo->c->cls.vars[index], &moo->c->cls.vars_capa[index], 1, ' '); if (n >= 0) { - stix->c->cls.var_count[index]++; -/* TODO: check if it exceeds STIX_MAX_NAMED_INSTVARS, STIX_MAX_CLASSVARS, STIX_MAX_CLASSINSTVARS */ + moo->c->cls.var_count[index]++; +/* TODO: check if it exceeds MOO_MAX_NAMED_INSTVARS, MOO_MAX_CLASSVARS, MOO_MAX_CLASSINSTVARS */ } return n; } -static STIX_INLINE int add_pool_dictionary (stix_t* stix, const stix_oocs_t* name, stix_oop_set_t pooldic_oop) +static MOO_INLINE int add_pool_dictionary (moo_t* moo, const moo_oocs_t* name, moo_oop_set_t pooldic_oop) { - if (stix->c->cls.pooldic_count >= stix->c->cls.pooldic_imp_oops_capa) + if (moo->c->cls.pooldic_count >= moo->c->cls.pooldic_imp_oops_capa) { - stix_oow_t new_capa; - stix_oop_set_t* tmp; + moo_oow_t new_capa; + moo_oop_set_t* tmp; - new_capa = STIX_ALIGN(stix->c->cls.pooldic_imp_oops_capa + 1, POOLDIC_OOP_BUFFER_ALIGN); - tmp = stix_reallocmem (stix, stix->c->cls.pooldic_imp_oops, new_capa * STIX_SIZEOF(stix_oop_set_t)); + new_capa = MOO_ALIGN(moo->c->cls.pooldic_imp_oops_capa + 1, POOLDIC_OOP_BUFFER_ALIGN); + tmp = moo_reallocmem (moo, moo->c->cls.pooldic_imp_oops, new_capa * MOO_SIZEOF(moo_oop_set_t)); if (!tmp) return -1; - stix->c->cls.pooldic_imp_oops_capa = new_capa; - stix->c->cls.pooldic_imp_oops = tmp; + moo->c->cls.pooldic_imp_oops_capa = new_capa; + moo->c->cls.pooldic_imp_oops = tmp; } - stix->c->cls.pooldic_imp_oops[stix->c->cls.pooldic_count] = pooldic_oop; - stix->c->cls.pooldic_count++; + moo->c->cls.pooldic_imp_oops[moo->c->cls.pooldic_count] = pooldic_oop; + moo->c->cls.pooldic_count++; /* TODO: check if pooldic_count overflows */ return 0; } -static stix_ooi_t find_class_level_variable (stix_t* stix, stix_oop_class_t self, const stix_oocs_t* name, var_info_t* var) +static moo_ooi_t find_class_level_variable (moo_t* moo, moo_oop_class_t self, const moo_oocs_t* name, var_info_t* var) { - stix_oow_t pos; - stix_oop_t super; - stix_oop_char_t v; - stix_oop_char_t* vv; - stix_oocs_t hs; + moo_oow_t pos; + moo_oop_t super; + moo_oop_char_t v; + moo_oop_char_t* vv; + moo_oocs_t hs; int index; if (self) { - STIX_ASSERT (stix, STIX_CLASSOF(stix, self) == stix->_class); + MOO_ASSERT (moo, MOO_CLASSOF(moo, self) == moo->_class); /* [NOTE] * the loop here assumes that the class has the following @@ -2168,13 +2175,13 @@ static stix_ooi_t find_class_level_variable (stix_t* stix, stix_oop_class_t self { v = vv[index]; hs.ptr = v->slot; - hs.len = STIX_OBJ_GET_SIZE(v); + hs.len = MOO_OBJ_GET_SIZE(v); if (find_word_in_string(&hs, name, &pos) >= 0) { super = self->superclass; - /* 'self' may be STIX_NULL if STIX_NULL has been given for it. + /* 'self' may be MOO_NULL if MOO_NULL has been given for it. * the caller must take good care when interpreting the meaning of * this field */ var->cls = self; @@ -2190,19 +2197,19 @@ static stix_ooi_t find_class_level_variable (stix_t* stix, stix_oop_class_t self * find the variable in the compiler's own list */ for (index = VAR_INSTANCE; index <= VAR_CLASSINST; index++) { - if (find_word_in_string(&stix->c->cls.vars[index], name, &pos) >= 0) + if (find_word_in_string(&moo->c->cls.vars[index], name, &pos) >= 0) { - super = stix->c->cls.super_oop; + super = moo->c->cls.super_oop; var->cls = self; goto done; } } - super = stix->c->cls.super_oop; + super = moo->c->cls.super_oop; } - while (super != stix->_nil) + while (super != moo->_nil) { - STIX_ASSERT (stix, STIX_CLASSOF(stix, super) == stix->_class); + MOO_ASSERT (moo, MOO_CLASSOF(moo, super) == moo->_class); /* [NOTE] * the loop here assumes that the class has the following @@ -2211,12 +2218,12 @@ static stix_ooi_t find_class_level_variable (stix_t* stix, stix_oop_class_t self * classvars * classinstvars */ - vv = &((stix_oop_class_t)super)->instvars; + vv = &((moo_oop_class_t)super)->instvars; for (index = VAR_INSTANCE; index <= VAR_CLASSINST; index++) { v = vv[index]; hs.ptr = v->slot; - hs.len = STIX_OBJ_GET_SIZE(v); + hs.len = MOO_OBJ_GET_SIZE(v); if (find_word_in_string(&hs, name, &pos) >= 0) { @@ -2226,26 +2233,26 @@ static stix_ooi_t find_class_level_variable (stix_t* stix, stix_oop_class_t self * class variable. on the other hand, instance variables and * class instance variables live in the current class being * compiled as they are inherited. */ - var->cls = (index == VAR_CLASS)? (stix_oop_class_t)super: self; - super = ((stix_oop_class_t)super)->superclass; + var->cls = (index == VAR_CLASS)? (moo_oop_class_t)super: self; + super = ((moo_oop_class_t)super)->superclass; goto done; } } - super = ((stix_oop_class_t)super)->superclass; + super = ((moo_oop_class_t)super)->superclass; } - stix->errnum = STIX_ENOENT; + moo->errnum = MOO_ENOENT; return -1; done: - if (super != stix->_nil) + if (super != moo->_nil) { - stix_oow_t spec; + moo_oow_t spec; /* the class being compiled has a superclass */ - STIX_ASSERT (stix, STIX_CLASSOF(stix, super) == stix->_class); + MOO_ASSERT (moo, MOO_CLASSOF(moo, super) == moo->_class); switch (index) { case VAR_INSTANCE: @@ -2253,8 +2260,8 @@ done: * accumulated for inheritance. the position found in the * local variable string can be adjusted by adding the * number in the superclass */ - spec = STIX_OOP_TO_SMOOI(((stix_oop_class_t)super)->spec); - pos += STIX_CLASS_SPEC_NAMED_INSTVAR(spec); + spec = MOO_OOP_TO_SMOOI(((moo_oop_class_t)super)->spec); + pos += MOO_CLASS_SPEC_NAMED_INSTVAR(spec); break; case VAR_CLASS: @@ -2268,8 +2275,8 @@ done: break; case VAR_CLASSINST: - spec = STIX_OOP_TO_SMOOI(((stix_oop_class_t)super)->selfspec); - pos += STIX_CLASS_SELFSPEC_CLASSINSTVAR(spec); + spec = MOO_OOP_TO_SMOOI(((moo_oop_class_t)super)->selfspec); + pos += MOO_CLASS_SELFSPEC_CLASSINSTVAR(spec); break; } } @@ -2279,127 +2286,127 @@ done: return pos; } -static int clone_assignee (stix_t* stix, const stix_oocs_t* name, stix_oow_t* offset) +static int clone_assignee (moo_t* moo, const moo_oocs_t* name, moo_oow_t* offset) { int n; - stix_oow_t old_len; + moo_oow_t old_len; - old_len = stix->c->mth.assignees.len; - n = copy_string_to (stix, name, &stix->c->mth.assignees, &stix->c->mth.assignees_capa, 1, '\0'); + old_len = moo->c->mth.assignees.len; + n = copy_string_to (moo, name, &moo->c->mth.assignees, &moo->c->mth.assignees_capa, 1, '\0'); if (n <= -1) return -1; /* update the pointer to of the name. its length is the same. */ - /*name->ptr = stix->c->mth.assignees.ptr + old_len;*/ + /*name->ptr = moo->c->mth.assignees.ptr + old_len;*/ *offset = old_len; return 0; } -static int clone_binary_selector (stix_t* stix, const stix_oocs_t* name, stix_oow_t* offset) +static int clone_binary_selector (moo_t* moo, const moo_oocs_t* name, moo_oow_t* offset) { int n; - stix_oow_t old_len; + moo_oow_t old_len; - old_len = stix->c->mth.binsels.len; - n = copy_string_to (stix, name, &stix->c->mth.binsels, &stix->c->mth.binsels_capa, 1, '\0'); + old_len = moo->c->mth.binsels.len; + n = copy_string_to (moo, name, &moo->c->mth.binsels, &moo->c->mth.binsels_capa, 1, '\0'); if (n <= -1) return -1; /* update the pointer to of the name. its length is the same. */ - /*name->ptr = stix->c->mth.binsels.ptr + old_len;*/ + /*name->ptr = moo->c->mth.binsels.ptr + old_len;*/ *offset = old_len; return 0; } -static int clone_keyword (stix_t* stix, const stix_oocs_t* name, stix_oow_t* offset) +static int clone_keyword (moo_t* moo, const moo_oocs_t* name, moo_oow_t* offset) { int n; - stix_oow_t old_len; + moo_oow_t old_len; - old_len = stix->c->mth.kwsels.len; - n = copy_string_to (stix, name, &stix->c->mth.kwsels, &stix->c->mth.kwsels_capa, 1, '\0'); + old_len = moo->c->mth.kwsels.len; + n = copy_string_to (moo, name, &moo->c->mth.kwsels, &moo->c->mth.kwsels_capa, 1, '\0'); if (n <= -1) return -1; /* update the pointer to of the name. its length is the same. */ - /*name->ptr = stix->c->mth.kwsels.ptr + old_len;*/ + /*name->ptr = moo->c->mth.kwsels.ptr + old_len;*/ *offset = old_len; return 0; } -static int add_method_name_fragment (stix_t* stix, const stix_oocs_t* name) +static int add_method_name_fragment (moo_t* moo, const moo_oocs_t* name) { /* method name fragments are concatenated without any delimiters */ - return copy_string_to (stix, name, &stix->c->mth.name, &stix->c->mth.name_capa, 1, '\0'); + return copy_string_to (moo, name, &moo->c->mth.name, &moo->c->mth.name_capa, 1, '\0'); } -static int method_exists (stix_t* stix, const stix_oocs_t* name) +static int method_exists (moo_t* moo, const moo_oocs_t* name) { /* check if the current class contains a method of the given name */ #ifdef MTHDIC - return stix_lookupdic (stix, stix->c->cls.mthdic_oop[stix->c->mth.type], name) != STIX_NULL; + return moo_lookupdic (moo, moo->c->cls.mthdic_oop[moo->c->mth.type], name) != MOO_NULL; #else - return stix_lookupdic (stix, stix->c->cls.self_oop->mthdic[stix->c->mth.type], name) != STIX_NULL; + return moo_lookupdic (moo, moo->c->cls.self_oop->mthdic[moo->c->mth.type], name) != MOO_NULL; #endif } -static int add_temporary_variable (stix_t* stix, const stix_oocs_t* name) +static int add_temporary_variable (moo_t* moo, const moo_oocs_t* name) { /* temporary variable names are added to the string with leading * space if it's not the first variable */ - return copy_string_to (stix, name, &stix->c->mth.tmprs, &stix->c->mth.tmprs_capa, 1, ' '); + return copy_string_to (moo, name, &moo->c->mth.tmprs, &moo->c->mth.tmprs_capa, 1, ' '); } -static STIX_INLINE int find_temporary_variable (stix_t* stix, const stix_oocs_t* name, stix_oow_t* xindex) +static MOO_INLINE int find_temporary_variable (moo_t* moo, const moo_oocs_t* name, moo_oow_t* xindex) { - return find_word_in_string (&stix->c->mth.tmprs, name, xindex); + return find_word_in_string (&moo->c->mth.tmprs, name, xindex); } -static stix_oop_set_t add_namespace (stix_t* stix, stix_oop_set_t dic, const stix_oocs_t* name) +static moo_oop_set_t add_namespace (moo_t* moo, moo_oop_set_t dic, const moo_oocs_t* name) { - stix_oow_t tmp_count = 0; - stix_oop_t sym; - stix_oop_set_t ns; - stix_oop_association_t ass; + moo_oow_t tmp_count = 0; + moo_oop_t sym; + moo_oop_set_t ns; + moo_oop_association_t ass; - stix_pushtmp (stix, (stix_oop_t*)&dic); tmp_count++; + moo_pushtmp (moo, (moo_oop_t*)&dic); tmp_count++; - sym = stix_makesymbol (stix, name->ptr, name->len); + sym = moo_makesymbol (moo, name->ptr, name->len); if (!sym) goto oops; - stix_pushtmp (stix, &sym); tmp_count++; + moo_pushtmp (moo, &sym); tmp_count++; - ns = stix_makedic (stix, stix->_namespace, NAMESPACE_SIZE); + ns = moo_makedic (moo, moo->_namespace, NAMESPACE_SIZE); if (!ns) goto oops; - /*stix_pushtmp (stix, &ns); tmp_count++;*/ + /*moo_pushtmp (moo, &ns); tmp_count++;*/ - ass = stix_putatdic (stix, dic, sym, (stix_oop_t)ns); + ass = moo_putatdic (moo, dic, sym, (moo_oop_t)ns); if (!ass) goto oops; - stix_poptmps (stix, tmp_count); - return (stix_oop_set_t)ass->value; + moo_poptmps (moo, tmp_count); + return (moo_oop_set_t)ass->value; oops: - stix_poptmps (stix, tmp_count); - return STIX_NULL; + moo_poptmps (moo, tmp_count); + return MOO_NULL; } -static int preprocess_dotted_name (stix_t* stix, int dont_add_ns, int accept_pooldic_as_ns, const stix_oocs_t* fqn, const stix_ioloc_t* fqn_loc, stix_oocs_t* name, stix_oop_set_t* ns_oop) +static int preprocess_dotted_name (moo_t* moo, int dont_add_ns, int accept_pooldic_as_ns, const moo_oocs_t* fqn, const moo_ioloc_t* fqn_loc, moo_oocs_t* name, moo_oop_set_t* ns_oop) { - const stix_ooch_t* ptr, * dot; - stix_oow_t len; - stix_oocs_t seg; - stix_oop_set_t dic; - stix_oop_association_t ass; + const moo_ooch_t* ptr, * dot; + moo_oow_t len; + moo_oocs_t seg; + moo_oop_set_t dic; + moo_oop_association_t ass; int pooldic_gotten = 0; - dic = stix->sysdic; + dic = moo->sysdic; ptr = fqn->ptr; len = fqn->len; while (1) { - seg.ptr = (stix_ooch_t*)ptr; + seg.ptr = (moo_ooch_t*)ptr; - dot = stix_findoochar (ptr, len, '.'); + dot = moo_findoochar (ptr, len, '.'); if (dot) { if (pooldic_gotten) goto wrong_name; @@ -2408,23 +2415,23 @@ static int preprocess_dotted_name (stix_t* stix, int dont_add_ns, int accept_poo if (is_reserved_word(&seg)) goto wrong_name; - ass = stix_lookupdic (stix, dic, &seg); + ass = moo_lookupdic (moo, dic, &seg); if (ass) { - if (STIX_CLASSOF(stix, ass->value) == stix->_namespace || - (seg.ptr == fqn->ptr && ass->value == (stix_oop_t)stix->sysdic)) + if (MOO_CLASSOF(moo, ass->value) == moo->_namespace || + (seg.ptr == fqn->ptr && ass->value == (moo_oop_t)moo->sysdic)) { /* ok */ - dic = (stix_oop_set_t)ass->value; + dic = (moo_oop_set_t)ass->value; } else { - if (accept_pooldic_as_ns && STIX_CLASSOF(stix, ass->value) == stix->_pool_dictionary) + if (accept_pooldic_as_ns && MOO_CLASSOF(moo, ass->value) == moo->_pool_dictionary) { /* A pool dictionary is treated as if it's a name space. * However, the pool dictionary can only act as a name space * if it's the second last segment. */ - dic = (stix_oop_set_t)ass->value; + dic = (moo_oop_set_t)ass->value; pooldic_gotten = 1; } else @@ -2435,7 +2442,7 @@ static int preprocess_dotted_name (stix_t* stix, int dont_add_ns, int accept_poo } else { - stix_oop_set_t t; + moo_oop_set_t t; /* the segment does not exist. add it */ if (dont_add_ns) @@ -2446,7 +2453,7 @@ static int preprocess_dotted_name (stix_t* stix, int dont_add_ns, int accept_poo } /* When definining a new class, add a missing namespace */ - t = add_namespace (stix, dic, &seg); + t = add_namespace (moo, dic, &seg); if (!t) return -1; dic = t; @@ -2474,42 +2481,42 @@ static int preprocess_dotted_name (stix_t* stix, int dont_add_ns, int accept_poo wrong_name: seg.len += seg.ptr - fqn->ptr; seg.ptr = fqn->ptr; - set_syntax_error (stix, STIX_SYNERR_NAMESPACE, fqn_loc, &seg); + set_syntax_error (moo, MOO_SYNERR_NAMESPACE, fqn_loc, &seg); return -1; } -static int resolve_pooldic (stix_t* stix, int dotted, const stix_oocs_t* name) +static int resolve_pooldic (moo_t* moo, int dotted, const moo_oocs_t* name) { - stix_oocs_t last; /* the last segment */ - stix_oop_set_t ns_oop; /* name space */ - stix_oop_association_t ass; - stix_oow_t i; + moo_oocs_t last; /* the last segment */ + moo_oop_set_t ns_oop; /* name space */ + moo_oop_association_t ass; + moo_oow_t i; if (dotted) { - if (preprocess_dotted_name(stix, 0, 0, name, TOKEN_LOC(stix), &last, &ns_oop) <= -1) return -1; + if (preprocess_dotted_name(moo, 0, 0, name, TOKEN_LOC(moo), &last, &ns_oop) <= -1) return -1; } else { last = *name; /* it falls back to the name space of the class */ - ns_oop = stix->c->cls.ns_oop; + ns_oop = moo->c->cls.ns_oop; } /* check if the name refers to a pool dictionary */ - ass = stix_lookupdic (stix, ns_oop, &last); - if (!ass || STIX_CLASSOF(stix, ass->value) != stix->_pool_dictionary) + ass = moo_lookupdic (moo, ns_oop, &last); + if (!ass || MOO_CLASSOF(moo, ass->value) != moo->_pool_dictionary) { - set_syntax_error (stix, STIX_SYNERR_POOLDIC, TOKEN_LOC(stix), name); + set_syntax_error (moo, MOO_SYNERR_POOLDIC, TOKEN_LOC(moo), name); return -1; } /* check if the same dictionary pool has been declared for import */ - for (i = 0; i < stix->c->cls.pooldic_count; i++) + for (i = 0; i < moo->c->cls.pooldic_count; i++) { - if ((stix_oop_set_t)ass->value == stix->c->cls.pooldic_imp_oops[i]) + if ((moo_oop_set_t)ass->value == moo->c->cls.pooldic_imp_oops[i]) { - set_syntax_error (stix, STIX_SYNERR_POOLDICDUP, TOKEN_LOC(stix), name); + set_syntax_error (moo, MOO_SYNERR_POOLDICDUP, TOKEN_LOC(moo), name); return -1; } } @@ -2517,99 +2524,99 @@ static int resolve_pooldic (stix_t* stix, int dotted, const stix_oocs_t* name) return 0; } -static int import_pool_dictionary (stix_t* stix, stix_oop_set_t ns_oop, const stix_oocs_t* tok_lastseg, const stix_oocs_t* tok_name, const stix_ioloc_t* tok_loc) +static int import_pool_dictionary (moo_t* moo, moo_oop_set_t ns_oop, const moo_oocs_t* tok_lastseg, const moo_oocs_t* tok_name, const moo_ioloc_t* tok_loc) { - stix_oop_association_t ass; - stix_oow_t i; + moo_oop_association_t ass; + moo_oow_t i; /* check if the name refers to a pool dictionary */ - ass = stix_lookupdic (stix, ns_oop, tok_lastseg); - if (!ass || STIX_CLASSOF(stix, ass->value) != stix->_pool_dictionary) + ass = moo_lookupdic (moo, ns_oop, tok_lastseg); + if (!ass || MOO_CLASSOF(moo, ass->value) != moo->_pool_dictionary) { - set_syntax_error (stix, STIX_SYNERR_POOLDIC, tok_loc, tok_name); + set_syntax_error (moo, MOO_SYNERR_POOLDIC, tok_loc, tok_name); return -1; } /* check if the same dictionary pool has been declared for import */ - for (i = 0; i < stix->c->cls.pooldic_count; i++) + for (i = 0; i < moo->c->cls.pooldic_count; i++) { - if ((stix_oop_set_t)ass->value == stix->c->cls.pooldic_imp_oops[i]) + if ((moo_oop_set_t)ass->value == moo->c->cls.pooldic_imp_oops[i]) { - set_syntax_error (stix, STIX_SYNERR_POOLDICDUP, tok_loc, tok_name); + set_syntax_error (moo, MOO_SYNERR_POOLDICDUP, tok_loc, tok_name); return -1; } } - if (add_pool_dictionary(stix, tok_name, (stix_oop_set_t)ass->value) <= -1) return -1; - if (copy_string_to (stix, tok_name, &stix->c->cls.pooldic, &stix->c->cls.pooldic_capa, 1, ' ') <= -1) + if (add_pool_dictionary(moo, tok_name, (moo_oop_set_t)ass->value) <= -1) return -1; + if (copy_string_to (moo, tok_name, &moo->c->cls.pooldic, &moo->c->cls.pooldic_capa, 1, ' ') <= -1) { - stix->c->cls.pooldic_count--; /* roll back add_pool_dictionary() */ + moo->c->cls.pooldic_count--; /* roll back add_pool_dictionary() */ return -1; } return 0; } -static int compile_class_level_variables (stix_t* stix) +static int compile_class_level_variables (moo_t* moo) { var_type_t dcl_type = VAR_INSTANCE; - if (TOKEN_TYPE(stix) == STIX_IOTOK_LPAREN) + if (TOKEN_TYPE(moo) == MOO_IOTOK_LPAREN) { /* process variable modifiers */ - GET_TOKEN (stix); + GET_TOKEN (moo); - if (is_token_symbol(stix, VOCA_CLASS_S)) + if (is_token_symbol(moo, VOCA_CLASS_S)) { /* dcl(#class) */ dcl_type = VAR_CLASS; - GET_TOKEN (stix); + GET_TOKEN (moo); } - else if (is_token_symbol(stix, VOCA_CLASSINST_S)) + else if (is_token_symbol(moo, VOCA_CLASSINST_S)) { /* dcl(#classinst) */ dcl_type = VAR_CLASSINST; - GET_TOKEN (stix); + GET_TOKEN (moo); } - else if (is_token_symbol(stix, VOCA_POOLDIC_S)) + else if (is_token_symbol(moo, VOCA_POOLDIC_S)) { /* dcl(#pooldic) - import a pool dictionary */ dcl_type = VAR_GLOBAL; /* this is not a real type. use for branching below */ - GET_TOKEN (stix); + GET_TOKEN (moo); } - if (TOKEN_TYPE(stix) != STIX_IOTOK_RPAREN) + if (TOKEN_TYPE(moo) != MOO_IOTOK_RPAREN) { - set_syntax_error (stix, STIX_SYNERR_RPAREN, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_RPAREN, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - GET_TOKEN (stix); + GET_TOKEN (moo); } if (dcl_type == VAR_GLOBAL) { /* pool dictionary import declaration * #dcl(#pooldic) ... */ - stix_oocs_t last; - stix_oop_set_t ns_oop; + moo_oocs_t last; + moo_oop_set_t ns_oop; do { - if (TOKEN_TYPE(stix) == STIX_IOTOK_IDENT_DOTTED) + if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT_DOTTED) { - if (preprocess_dotted_name(stix, 0, 0, TOKEN_NAME(stix), TOKEN_LOC(stix), &last, &ns_oop) <= -1) return -1; + if (preprocess_dotted_name(moo, 0, 0, TOKEN_NAME(moo), TOKEN_LOC(moo), &last, &ns_oop) <= -1) return -1; } - else if (TOKEN_TYPE(stix) == STIX_IOTOK_IDENT) + else if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT) { - last = stix->c->tok.name; + last = moo->c->tok.name; /* it falls back to the name space of the class */ - ns_oop = stix->c->cls.ns_oop; + ns_oop = moo->c->cls.ns_oop; } else break; - if (import_pool_dictionary(stix, ns_oop, &last, TOKEN_NAME(stix), TOKEN_LOC(stix)) <= -1) return -1; - GET_TOKEN (stix); + if (import_pool_dictionary(moo, ns_oop, &last, TOKEN_NAME(moo), TOKEN_LOC(moo)) <= -1) return -1; + GET_TOKEN (moo); } while (1); } @@ -2618,7 +2625,7 @@ static int compile_class_level_variables (stix_t* stix) /* variable declaration */ do { - if (TOKEN_TYPE(stix) == STIX_IOTOK_IDENT) + if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT) { var_info_t var; @@ -2631,168 +2638,168 @@ if super is variable-pointer, self must be a variable-pointer. can't be fixed ei if super is variable-nonpointer, self must be a variable-nonpointer of the same type. can't be fixed either if super is variable-nonpointer, no instance variable is allowed. */ - if (dcl_type == VAR_INSTANCE && (stix->c->cls.flags & CLASS_INDEXED) && (stix->c->cls.indexed_type != STIX_OBJ_TYPE_OOP)) + if (dcl_type == VAR_INSTANCE && (moo->c->cls.flags & CLASS_INDEXED) && (moo->c->cls.indexed_type != MOO_OBJ_TYPE_OOP)) { - set_syntax_error (stix, STIX_SYNERR_VARNAMEDUP, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_VARNAMEDUP, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - if (find_class_level_variable(stix, STIX_NULL, TOKEN_NAME(stix), &var) >= 0 || - stix_lookupdic (stix, stix->sysdic, TOKEN_NAME(stix)) || /* conflicts with a top global name */ - stix_lookupdic (stix, stix->c->cls.ns_oop, TOKEN_NAME(stix))) /* conflicts with a global name in the class'es name space */ + if (find_class_level_variable(moo, MOO_NULL, TOKEN_NAME(moo), &var) >= 0 || + moo_lookupdic (moo, moo->sysdic, TOKEN_NAME(moo)) || /* conflicts with a top global name */ + moo_lookupdic (moo, moo->c->cls.ns_oop, TOKEN_NAME(moo))) /* conflicts with a global name in the class'es name space */ { - set_syntax_error (stix, STIX_SYNERR_VARNAMEDUP, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_VARNAMEDUP, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - if (add_class_level_variable(stix, dcl_type, TOKEN_NAME(stix)) <= -1) return -1; + if (add_class_level_variable(moo, dcl_type, TOKEN_NAME(moo)) <= -1) return -1; } else { break; } - GET_TOKEN (stix); + GET_TOKEN (moo); } while (1); } - if (TOKEN_TYPE(stix) != STIX_IOTOK_PERIOD) + if (TOKEN_TYPE(moo) != MOO_IOTOK_PERIOD) { - set_syntax_error (stix, STIX_SYNERR_PERIOD, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_PERIOD, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - GET_TOKEN (stix); + GET_TOKEN (moo); return 0; } -static int compile_unary_method_name (stix_t* stix) +static int compile_unary_method_name (moo_t* moo) { - STIX_ASSERT (stix, stix->c->mth.name.len == 0); - STIX_ASSERT (stix, stix->c->mth.tmpr_nargs == 0); + MOO_ASSERT (moo, moo->c->mth.name.len == 0); + MOO_ASSERT (moo, moo->c->mth.tmpr_nargs == 0); - if (add_method_name_fragment(stix, TOKEN_NAME(stix)) <= -1) return -1; - GET_TOKEN (stix); + if (add_method_name_fragment(moo, TOKEN_NAME(moo)) <= -1) return -1; + GET_TOKEN (moo); - if (TOKEN_TYPE(stix) == STIX_IOTOK_LPAREN) + if (TOKEN_TYPE(moo) == MOO_IOTOK_LPAREN) { /* this is a procedural style method */ - STIX_ASSERT (stix, stix->c->mth.tmpr_nargs == 0); + MOO_ASSERT (moo, moo->c->mth.tmpr_nargs == 0); - GET_TOKEN (stix); - if (TOKEN_TYPE(stix) != STIX_IOTOK_RPAREN) + GET_TOKEN (moo); + if (TOKEN_TYPE(moo) != MOO_IOTOK_RPAREN) { do { - if (TOKEN_TYPE(stix) != STIX_IOTOK_IDENT) + if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT) { /* wrong argument name. identifier is expected */ - set_syntax_error (stix, STIX_SYNERR_IDENT, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_IDENT, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - if (find_temporary_variable(stix, TOKEN_NAME(stix), STIX_NULL) >= 0) + if (find_temporary_variable(moo, TOKEN_NAME(moo), MOO_NULL) >= 0) { - set_syntax_error (stix, STIX_SYNERR_ARGNAMEDUP, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_ARGNAMEDUP, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - if (add_temporary_variable(stix, TOKEN_NAME(stix)) <= -1) return -1; - stix->c->mth.tmpr_nargs++; - GET_TOKEN (stix); + if (add_temporary_variable(moo, TOKEN_NAME(moo)) <= -1) return -1; + moo->c->mth.tmpr_nargs++; + GET_TOKEN (moo); - if (TOKEN_TYPE(stix) == STIX_IOTOK_RPAREN) break; + if (TOKEN_TYPE(moo) == MOO_IOTOK_RPAREN) break; - if (TOKEN_TYPE(stix) != STIX_IOTOK_COMMA) + if (TOKEN_TYPE(moo) != MOO_IOTOK_COMMA) { - set_syntax_error (stix, STIX_SYNERR_COMMA, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_COMMA, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - GET_TOKEN (stix); + GET_TOKEN (moo); } while (1); } /* indicate that the unary method name is followed by a parameter list */ - stix->c->mth.variadic = 1; - GET_TOKEN (stix); + moo->c->mth.variadic = 1; + GET_TOKEN (moo); } return 0; } -static int compile_binary_method_name (stix_t* stix) +static int compile_binary_method_name (moo_t* moo) { - STIX_ASSERT (stix, stix->c->mth.name.len == 0); - STIX_ASSERT (stix, stix->c->mth.tmpr_nargs == 0); + MOO_ASSERT (moo, moo->c->mth.name.len == 0); + MOO_ASSERT (moo, moo->c->mth.tmpr_nargs == 0); - if (add_method_name_fragment(stix, TOKEN_NAME(stix)) <= -1) return -1; - GET_TOKEN (stix); + if (add_method_name_fragment(moo, TOKEN_NAME(moo)) <= -1) return -1; + GET_TOKEN (moo); /* collect the argument name */ - if (TOKEN_TYPE(stix) != STIX_IOTOK_IDENT) + if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT) { /* wrong argument name. identifier expected */ - set_syntax_error (stix, STIX_SYNERR_IDENT, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_IDENT, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - STIX_ASSERT (stix, stix->c->mth.tmpr_nargs == 0); + MOO_ASSERT (moo, moo->c->mth.tmpr_nargs == 0); /* no duplication check is performed against class-level variable names. * a duplcate name will shade a previsouly defined variable. */ - if (add_temporary_variable(stix, TOKEN_NAME(stix)) <= -1) return -1; - stix->c->mth.tmpr_nargs++; + if (add_temporary_variable(moo, TOKEN_NAME(moo)) <= -1) return -1; + moo->c->mth.tmpr_nargs++; - STIX_ASSERT (stix, stix->c->mth.tmpr_nargs == 1); + MOO_ASSERT (moo, moo->c->mth.tmpr_nargs == 1); /* this check should not be not necessary - if (stix->c->mth.tmpr_nargs > MAX_CODE_NARGS) + if (moo->c->mth.tmpr_nargs > MAX_CODE_NARGS) { - set_syntax_error (stix, STIX_SYNERR_ARGFLOOD, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_ARGFLOOD, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } */ - GET_TOKEN (stix); + GET_TOKEN (moo); return 0; } -static int compile_keyword_method_name (stix_t* stix) +static int compile_keyword_method_name (moo_t* moo) { - STIX_ASSERT (stix, stix->c->mth.name.len == 0); - STIX_ASSERT (stix, stix->c->mth.tmpr_nargs == 0); + MOO_ASSERT (moo, moo->c->mth.name.len == 0); + MOO_ASSERT (moo, moo->c->mth.tmpr_nargs == 0); do { - if (add_method_name_fragment(stix, TOKEN_NAME(stix)) <= -1) return -1; + if (add_method_name_fragment(moo, TOKEN_NAME(moo)) <= -1) return -1; - GET_TOKEN (stix); - if (TOKEN_TYPE(stix) != STIX_IOTOK_IDENT) + GET_TOKEN (moo); + if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT) { /* wrong argument name. identifier is expected */ - set_syntax_error (stix, STIX_SYNERR_IDENT, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_IDENT, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - if (find_temporary_variable(stix, TOKEN_NAME(stix), STIX_NULL) >= 0) + if (find_temporary_variable(moo, TOKEN_NAME(moo), MOO_NULL) >= 0) { - set_syntax_error (stix, STIX_SYNERR_ARGNAMEDUP, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_ARGNAMEDUP, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - if (add_temporary_variable(stix, TOKEN_NAME(stix)) <= -1) return -1; - stix->c->mth.tmpr_nargs++; + if (add_temporary_variable(moo, TOKEN_NAME(moo)) <= -1) return -1; + moo->c->mth.tmpr_nargs++; - GET_TOKEN (stix); + GET_TOKEN (moo); } - while (TOKEN_TYPE(stix) == STIX_IOTOK_KEYWORD); + while (TOKEN_TYPE(moo) == MOO_IOTOK_KEYWORD); return 0; } -static int compile_method_name (stix_t* stix) +static int compile_method_name (moo_t* moo) { /* * method-name := unary-method-name | binary-method-name | keyword-method-name @@ -2804,92 +2811,92 @@ static int compile_method_name (stix_t* stix) */ int n; - STIX_ASSERT (stix, stix->c->mth.tmpr_count == 0); + MOO_ASSERT (moo, moo->c->mth.tmpr_count == 0); - stix->c->mth.name_loc = stix->c->tok.loc; - switch (TOKEN_TYPE(stix)) + moo->c->mth.name_loc = moo->c->tok.loc; + switch (TOKEN_TYPE(moo)) { - case STIX_IOTOK_IDENT: - n = compile_unary_method_name(stix); + case MOO_IOTOK_IDENT: + n = compile_unary_method_name(moo); break; - case STIX_IOTOK_BINSEL: - n = compile_binary_method_name(stix); + case MOO_IOTOK_BINSEL: + n = compile_binary_method_name(moo); break; - case STIX_IOTOK_KEYWORD: - n = compile_keyword_method_name(stix); + case MOO_IOTOK_KEYWORD: + n = compile_keyword_method_name(moo); break; default: /* illegal method name */ - set_syntax_error (stix, STIX_SYNERR_MTHNAME, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_MTHNAME, TOKEN_LOC(moo), TOKEN_NAME(moo)); n = -1; } if (n >= 0) { - if (method_exists(stix, &stix->c->mth.name)) + if (method_exists(moo, &moo->c->mth.name)) { - set_syntax_error (stix, STIX_SYNERR_MTHNAMEDUP, &stix->c->mth.name_loc, &stix->c->mth.name); + set_syntax_error (moo, MOO_SYNERR_MTHNAMEDUP, &moo->c->mth.name_loc, &moo->c->mth.name); return -1; } } - STIX_ASSERT (stix, stix->c->mth.tmpr_nargs < MAX_CODE_NARGS); + MOO_ASSERT (moo, moo->c->mth.tmpr_nargs < MAX_CODE_NARGS); /* the total number of temporaries is equal to the number of * arguments after having processed the message pattern. it's because - * stix treats arguments the same as temporaries */ - stix->c->mth.tmpr_count = stix->c->mth.tmpr_nargs; + * moo treats arguments the same as temporaries */ + moo->c->mth.tmpr_count = moo->c->mth.tmpr_nargs; return n; } -static int compile_method_temporaries (stix_t* stix) +static int compile_method_temporaries (moo_t* moo) { /* * method-temporaries := "|" variable-list "|" * variable-list := identifier* */ - if (!is_token_binary_selector(stix, VOCA_VBAR)) + if (!is_token_binary_selector(moo, VOCA_VBAR)) { /* return without doing anything if | is not found. * this is not an error condition */ return 0; } - GET_TOKEN (stix); - while (TOKEN_TYPE(stix) == STIX_IOTOK_IDENT) + GET_TOKEN (moo); + while (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT) { - if (find_temporary_variable(stix, TOKEN_NAME(stix), STIX_NULL) >= 0) + if (find_temporary_variable(moo, TOKEN_NAME(moo), MOO_NULL) >= 0) { - set_syntax_error (stix, STIX_SYNERR_TMPRNAMEDUP, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_TMPRNAMEDUP, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - if (add_temporary_variable(stix, TOKEN_NAME(stix)) <= -1) return -1; - stix->c->mth.tmpr_count++; + if (add_temporary_variable(moo, TOKEN_NAME(moo)) <= -1) return -1; + moo->c->mth.tmpr_count++; - if (stix->c->mth.tmpr_count > MAX_CODE_NARGS) + if (moo->c->mth.tmpr_count > MAX_CODE_NARGS) { - set_syntax_error (stix, STIX_SYNERR_TMPRFLOOD, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_TMPRFLOOD, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - GET_TOKEN (stix); + GET_TOKEN (moo); } - if (!is_token_binary_selector(stix, VOCA_VBAR)) + if (!is_token_binary_selector(moo, VOCA_VBAR)) { - set_syntax_error (stix, STIX_SYNERR_VBAR, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_VBAR, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - GET_TOKEN (stix); + GET_TOKEN (moo); return 0; } -static int compile_method_primitive (stix_t* stix) +static int compile_method_primitive (moo_t* moo) { /* * method-primitive := "<" "primitive:" integer ">" | @@ -2897,120 +2904,120 @@ static int compile_method_primitive (stix_t* stix) * "<" "exception" ">" | * "<" "ensure" ">" */ - stix_ooi_t pfnum; - const stix_ooch_t* ptr, * end; + moo_ooi_t pfnum; + const moo_ooch_t* ptr, * end; - if (!is_token_binary_selector(stix, VOCA_LT)) + if (!is_token_binary_selector(moo, VOCA_LT)) { /* return if < is not seen. it is not an error condition */ return 0; } - GET_TOKEN (stix); - if (is_token_keyword(stix, VOCA_PRIMITIVE_COLON)) + GET_TOKEN (moo); + if (is_token_keyword(moo, VOCA_PRIMITIVE_COLON)) { - GET_TOKEN (stix); - switch (TOKEN_TYPE(stix)) + GET_TOKEN (moo); + switch (TOKEN_TYPE(moo)) { - case STIX_IOTOK_NUMLIT: /* TODO: allow only an integer */ + case MOO_IOTOK_NUMLIT: /* TODO: allow only an integer */ /*TODO: more checks the validity of the primitive number. support number with radix and so on support more extensive syntax. support primitive name, not number*/ - ptr = TOKEN_NAME_PTR(stix); - end = ptr + TOKEN_NAME_LEN(stix); + ptr = TOKEN_NAME_PTR(moo); + end = ptr + TOKEN_NAME_LEN(moo); pfnum = 0; while (ptr < end && is_digitchar(*ptr)) { pfnum = pfnum * 10 + (*ptr - '0'); - if (!STIX_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(pfnum)) + if (!MOO_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(pfnum)) { - set_syntax_error (stix, STIX_SYNERR_PFNUM, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_PFNUM, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } ptr++; } - stix->c->mth.pfnum = pfnum; + moo->c->mth.pfnum = pfnum; break; - case STIX_IOTOK_SYMLIT: + case MOO_IOTOK_SYMLIT: { - const stix_ooch_t* tptr; - stix_oow_t tlen; + const moo_ooch_t* tptr; + moo_oow_t tlen; - tptr = TOKEN_NAME_PTR(stix) + 1; - tlen = TOKEN_NAME_LEN(stix) - 1; + tptr = TOKEN_NAME_PTR(moo) + 1; + tlen = TOKEN_NAME_LEN(moo) - 1; /* attempt get a primitive function number by name */ - pfnum = stix_getpfnum (stix, tptr, tlen); + pfnum = moo_getpfnum (moo, tptr, tlen); if (pfnum <= -1) { /* a built-in primitive function is not found * check if it is a primitive function identifier */ - stix_oow_t lit_idx; + moo_oow_t lit_idx; - if (stix_findoochar (tptr, tlen, '.') && - add_symbol_literal(stix, TOKEN_NAME(stix), 1, &lit_idx) >= 0 && - STIX_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(lit_idx)) + if (moo_findoochar (tptr, tlen, '.') && + add_symbol_literal(moo, TOKEN_NAME(moo), 1, &lit_idx) >= 0 && + MOO_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(lit_idx)) { /* external named primitive containing a period. */ - stix->c->mth.pftype = 2; - stix->c->mth.pfnum = lit_idx; + moo->c->mth.pftype = 2; + moo->c->mth.pfnum = lit_idx; break; } /* wrong primitive number */ - set_syntax_error (stix, STIX_SYNERR_PFID, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_PFID, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - else if (!STIX_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(pfnum)) + else if (!MOO_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(pfnum)) { - set_syntax_error (stix, STIX_SYNERR_PFID, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_PFID, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - stix->c->mth.pftype = 1; - stix->c->mth.pfnum = pfnum; + moo->c->mth.pftype = 1; + moo->c->mth.pfnum = pfnum; break; } default: - set_syntax_error (stix, STIX_SYNERR_INTEGER, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_INTEGER, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } } - else if (is_token_word(stix, VOCA_EXCEPTION)) + else if (is_token_word(moo, VOCA_EXCEPTION)) { /* TODO: exception handler is supposed to be used by BlockContext on:do:. * it needs to check the number of arguments at least */ - stix->c->mth.pftype = 3; + moo->c->mth.pftype = 3; } - else if (is_token_word(stix, VOCA_ENSURE)) + else if (is_token_word(moo, VOCA_ENSURE)) { - stix->c->mth.pftype = 4; + moo->c->mth.pftype = 4; } else { - set_syntax_error (stix, STIX_SYNERR_PRIMITIVE, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_PRIMITIVE, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - GET_TOKEN (stix); - if (!is_token_binary_selector(stix, VOCA_GT)) + GET_TOKEN (moo); + if (!is_token_binary_selector(moo, VOCA_GT)) { - set_syntax_error (stix, STIX_SYNERR_GT, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_GT, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - GET_TOKEN (stix); + GET_TOKEN (moo); return 0; } -static int get_variable_info (stix_t* stix, const stix_oocs_t* name, const stix_ioloc_t* name_loc, int name_dotted, var_info_t* var) +static int get_variable_info (moo_t* moo, const moo_oocs_t* name, const moo_ioloc_t* name_loc, int name_dotted, var_info_t* var) { - stix_oow_t index; + moo_oow_t index; - STIX_MEMSET (var, 0, STIX_SIZEOF(*var)); + MOO_MEMSET (var, 0, MOO_SIZEOF(*var)); if (name_dotted) { @@ -3020,18 +3027,18 @@ static int get_variable_info (stix_t* stix, const stix_oocs_t* name, const stix_ * A.B.C - namespace or pool dictionary related reference. */ - stix_oocs_t last; - stix_oop_set_t ns_oop; - stix_oop_association_t ass; - const stix_ooch_t* dot; + moo_oocs_t last; + moo_oop_set_t ns_oop; + moo_oop_association_t ass; + const moo_ooch_t* dot; - dot = stix_findoochar (name->ptr, name->len, '.'); - STIX_ASSERT (stix, dot != STIX_NULL); - if (dot - (const stix_ooch_t*)name->ptr == 4 && - stix_equaloochars(name->ptr, vocas[VOCA_SELF].str, 4)) + dot = moo_findoochar (name->ptr, name->len, '.'); + MOO_ASSERT (moo, dot != MOO_NULL); + if (dot - (const moo_ooch_t*)name->ptr == 4 && + moo_equaloochars(name->ptr, vocas[VOCA_SELF].str, 4)) { /* the dotted name begins with self. */ - dot = stix_findoochar (dot + 1, name->len - 5, '.'); + dot = moo_findoochar (dot + 1, name->len - 5, '.'); if (!dot) { /* the dotted name is composed of 2 segments only */ @@ -3039,23 +3046,23 @@ static int get_variable_info (stix_t* stix, const stix_oocs_t* name, const stix_ last.len = name->len - 5; if (!is_reserved_word(&last)) { - if (find_class_level_variable(stix, stix->c->cls.self_oop, &last, var) >= 0) + if (find_class_level_variable(moo, moo->c->cls.self_oop, &last, var) >= 0) { goto class_level_variable; } else { /* undeclared identifier */ - set_syntax_error (stix, STIX_SYNERR_VARUNDCL, name_loc, name); + set_syntax_error (moo, MOO_SYNERR_VARUNDCL, name_loc, name); return -1; } } } } - if (preprocess_dotted_name (stix, 1, 1, name, name_loc, &last, &ns_oop) <= -1) return -1; + if (preprocess_dotted_name (moo, 1, 1, name, name_loc, &last, &ns_oop) <= -1) return -1; - ass = stix_lookupdic (stix, ns_oop, &last); + ass = moo_lookupdic (moo, ns_oop, &last); if (ass) { var->type = VAR_GLOBAL; @@ -3064,73 +3071,73 @@ static int get_variable_info (stix_t* stix, const stix_oocs_t* name, const stix_ else { /* undeclared identifier */ - set_syntax_error (stix, STIX_SYNERR_VARUNDCL, name_loc, name); + set_syntax_error (moo, MOO_SYNERR_VARUNDCL, name_loc, name); return -1; } return 0; } - if (find_temporary_variable (stix, name, &index) >= 0) + if (find_temporary_variable (moo, name, &index) >= 0) { - var->type = (index < stix->c->mth.tmpr_nargs)? VAR_ARGUMENT: VAR_TEMPORARY; + var->type = (index < moo->c->mth.tmpr_nargs)? VAR_ARGUMENT: VAR_TEMPORARY; var->pos = index; } else { - if (find_class_level_variable(stix, stix->c->cls.self_oop, name, var) >= 0) + if (find_class_level_variable(moo, moo->c->cls.self_oop, name, var) >= 0) { class_level_variable: switch (var->type) { case VAR_INSTANCE: - if (stix->c->mth.type == STIX_METHOD_CLASS) + if (moo->c->mth.type == MOO_METHOD_CLASS) { /* a class method cannot access an instance variable */ - set_syntax_error (stix, STIX_SYNERR_VARINACC, name_loc, name); + set_syntax_error (moo, MOO_SYNERR_VARINACC, name_loc, name); return -1; } break; case VAR_CLASS: /* a class variable can be access by both instance methods and class methods */ - STIX_ASSERT (stix, var->cls != STIX_NULL); - STIX_ASSERT (stix, STIX_CLASSOF(stix, var->cls) == stix->_class); + MOO_ASSERT (moo, var->cls != MOO_NULL); + MOO_ASSERT (moo, MOO_CLASSOF(moo, var->cls) == moo->_class); /* increment the position by the number of class instance variables * as the class variables are placed after the class instance variables */ - var->pos += STIX_CLASS_NAMED_INSTVARS + - STIX_CLASS_SELFSPEC_CLASSINSTVAR(STIX_OOP_TO_SMOOI(var->cls->selfspec)); + var->pos += MOO_CLASS_NAMED_INSTVARS + + MOO_CLASS_SELFSPEC_CLASSINSTVAR(MOO_OOP_TO_SMOOI(var->cls->selfspec)); break; case VAR_CLASSINST: /* class instance variable can be accessed by only class methods */ - if (stix->c->mth.type == STIX_METHOD_INSTANCE) + if (moo->c->mth.type == MOO_METHOD_INSTANCE) { /* an instance method cannot access a class-instance variable */ - set_syntax_error (stix, STIX_SYNERR_VARINACC, name_loc, name); + set_syntax_error (moo, MOO_SYNERR_VARINACC, name_loc, name); return -1; } /* to a class object itself, a class-instance variable is * just an instance variriable. but these are located * after the named instance variables. */ - var->pos += STIX_CLASS_NAMED_INSTVARS; + var->pos += MOO_CLASS_NAMED_INSTVARS; break; default: /* internal error - it must not happen */ - stix->errnum = STIX_EINTERN; + moo->errnum = MOO_EINTERN; return -1; } } else { - stix_oop_association_t ass; - /*ass = stix_lookupsysdic (stix, name);*/ - ass = stix_lookupdic (stix, stix->c->cls.ns_oop, name); - if (!ass && stix->c->cls.ns_oop != stix->sysdic) - ass = stix_lookupdic (stix, stix->sysdic, name); + moo_oop_association_t ass; + /*ass = moo_lookupsysdic (moo, name);*/ + ass = moo_lookupdic (moo, moo->c->cls.ns_oop, name); + if (!ass && moo->c->cls.ns_oop != moo->sysdic) + ass = moo_lookupdic (moo, moo->sysdic, name); if (ass) { @@ -3139,19 +3146,19 @@ static int get_variable_info (stix_t* stix, const stix_oocs_t* name, const stix_ } else { - stix_oow_t i; - stix_oop_association_t ass2 = STIX_NULL; + moo_oow_t i; + moo_oop_association_t ass2 = MOO_NULL; /* attempt to find the variable in pool dictionaries */ - for (i = 0; i < stix->c->cls.pooldic_count; i++) + for (i = 0; i < moo->c->cls.pooldic_count; i++) { - ass = stix_lookupdic (stix, stix->c->cls.pooldic_imp_oops[i], name); + ass = moo_lookupdic (moo, moo->c->cls.pooldic_imp_oops[i], name); if (ass) { if (ass2) { /* the variable name has been found at least in 2 dictionaries */ - set_syntax_error (stix, STIX_SYNERR_VARAMBIG, name_loc, name); + set_syntax_error (moo, MOO_SYNERR_VARAMBIG, name_loc, name); return -1; } ass2 = ass; @@ -3166,7 +3173,7 @@ static int get_variable_info (stix_t* stix, const stix_oocs_t* name, const stix_ else { /* undeclared identifier */ - set_syntax_error (stix, STIX_SYNERR_VARUNDCL, name_loc, name); + set_syntax_error (moo, MOO_SYNERR_VARUNDCL, name_loc, name); return -1; } } @@ -3177,86 +3184,86 @@ static int get_variable_info (stix_t* stix, const stix_oocs_t* name, const stix_ { /* the assignee is not usable because its index is too large * to be expressed in byte-codes. */ - set_syntax_error (stix, STIX_SYNERR_VARUNUSE, name_loc, name); + set_syntax_error (moo, MOO_SYNERR_VARUNUSE, name_loc, name); return -1; } return 0; } -static int compile_block_temporaries (stix_t* stix) +static int compile_block_temporaries (moo_t* moo) { /* * block-temporaries := "|" variable-list "|" * variable-list := identifier* */ - if (!is_token_binary_selector(stix, VOCA_VBAR)) + if (!is_token_binary_selector(moo, VOCA_VBAR)) { /* return without doing anything if | is not found. * this is not an error condition */ return 0; } - GET_TOKEN (stix); - while (TOKEN_TYPE(stix) == STIX_IOTOK_IDENT) + GET_TOKEN (moo); + while (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT) { - if (find_temporary_variable(stix, TOKEN_NAME(stix), STIX_NULL) >= 0) + if (find_temporary_variable(moo, TOKEN_NAME(moo), MOO_NULL) >= 0) { - set_syntax_error (stix, STIX_SYNERR_TMPRNAMEDUP, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_TMPRNAMEDUP, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - if (add_temporary_variable(stix, TOKEN_NAME(stix)) <= -1) return -1; - stix->c->mth.tmpr_count++; - if (stix->c->mth.tmpr_count > MAX_CODE_NTMPRS) + if (add_temporary_variable(moo, TOKEN_NAME(moo)) <= -1) return -1; + moo->c->mth.tmpr_count++; + if (moo->c->mth.tmpr_count > MAX_CODE_NTMPRS) { - set_syntax_error (stix, STIX_SYNERR_TMPRFLOOD, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_TMPRFLOOD, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - GET_TOKEN (stix); + GET_TOKEN (moo); } - if (!is_token_binary_selector(stix, VOCA_VBAR)) + if (!is_token_binary_selector(moo, VOCA_VBAR)) { - set_syntax_error (stix, STIX_SYNERR_VBAR, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_VBAR, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - GET_TOKEN (stix); + GET_TOKEN (moo); return 0; } -static int store_tmpr_count_for_block (stix_t* stix, stix_oow_t tmpr_count) +static int store_tmpr_count_for_block (moo_t* moo, moo_oow_t tmpr_count) { - if (stix->c->mth.blk_depth >= stix->c->mth.blk_tmprcnt_capa) + if (moo->c->mth.blk_depth >= moo->c->mth.blk_tmprcnt_capa) { - stix_oow_t* tmp; - stix_oow_t new_capa; + moo_oow_t* tmp; + moo_oow_t new_capa; - new_capa = STIX_ALIGN (stix->c->mth.blk_depth + 1, BLK_TMPRCNT_BUFFER_ALIGN); - tmp = (stix_oow_t*)stix_reallocmem (stix, stix->c->mth.blk_tmprcnt, new_capa * STIX_SIZEOF(*tmp)); + new_capa = MOO_ALIGN (moo->c->mth.blk_depth + 1, BLK_TMPRCNT_BUFFER_ALIGN); + tmp = (moo_oow_t*)moo_reallocmem (moo, moo->c->mth.blk_tmprcnt, new_capa * MOO_SIZEOF(*tmp)); if (!tmp) return -1; - stix->c->mth.blk_tmprcnt_capa = new_capa; - stix->c->mth.blk_tmprcnt = tmp; + moo->c->mth.blk_tmprcnt_capa = new_capa; + moo->c->mth.blk_tmprcnt = tmp; } /* [NOTE] i don't increment blk_depth here. it's updated * by the caller after this function has been called for * a new block entered. */ - stix->c->mth.blk_tmprcnt[stix->c->mth.blk_depth] = tmpr_count; + moo->c->mth.blk_tmprcnt[moo->c->mth.blk_depth] = tmpr_count; return 0; } -static int compile_block_expression (stix_t* stix) +static int compile_block_expression (moo_t* moo) { - stix_oow_t jump_inst_pos; - stix_oow_t saved_tmpr_count, saved_tmprs_len; - stix_oow_t block_arg_count, block_tmpr_count; - stix_oow_t block_code_size; - stix_ioloc_t block_loc, colon_loc, tmpr_loc; + moo_oow_t jump_inst_pos; + moo_oow_t saved_tmpr_count, saved_tmprs_len; + moo_oow_t block_arg_count, block_tmpr_count; + moo_oow_t block_code_size; + moo_ioloc_t block_loc, colon_loc, tmpr_loc; /* * block-expression := "[" block-body "]" @@ -3265,147 +3272,147 @@ static int compile_block_expression (stix_t* stix) */ /* this function expects [ not to be consumed away */ - STIX_ASSERT (stix, TOKEN_TYPE(stix) == STIX_IOTOK_LBRACK); - block_loc = stix->c->tok.loc; - GET_TOKEN (stix); + MOO_ASSERT (moo, TOKEN_TYPE(moo) == MOO_IOTOK_LBRACK); + block_loc = moo->c->tok.loc; + GET_TOKEN (moo); - saved_tmprs_len = stix->c->mth.tmprs.len; - saved_tmpr_count = stix->c->mth.tmpr_count; - STIX_ASSERT (stix, stix->c->mth.blk_depth > 0); - STIX_ASSERT (stix, stix->c->mth.blk_tmprcnt[stix->c->mth.blk_depth - 1] == saved_tmpr_count); + saved_tmprs_len = moo->c->mth.tmprs.len; + saved_tmpr_count = moo->c->mth.tmpr_count; + MOO_ASSERT (moo, moo->c->mth.blk_depth > 0); + MOO_ASSERT (moo, moo->c->mth.blk_tmprcnt[moo->c->mth.blk_depth - 1] == saved_tmpr_count); - if (TOKEN_TYPE(stix) == STIX_IOTOK_COLON) + if (TOKEN_TYPE(moo) == MOO_IOTOK_COLON) { - colon_loc = stix->c->tok.loc; + colon_loc = moo->c->tok.loc; /* block temporary variables */ do { - GET_TOKEN (stix); + GET_TOKEN (moo); - if (TOKEN_TYPE(stix) != STIX_IOTOK_IDENT) + if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT) { /* wrong argument name. identifier expected */ - set_syntax_error (stix, STIX_SYNERR_IDENT, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_IDENT, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } /* TODO: check conflicting names as well */ - if (find_temporary_variable(stix, TOKEN_NAME(stix), STIX_NULL) >= 0) + if (find_temporary_variable(moo, TOKEN_NAME(moo), MOO_NULL) >= 0) { - set_syntax_error (stix, STIX_SYNERR_BLKARGNAMEDUP, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_BLKARGNAMEDUP, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - if (add_temporary_variable(stix, TOKEN_NAME(stix)) <= -1) return -1; - stix->c->mth.tmpr_count++; - if (stix->c->mth.tmpr_count > MAX_CODE_NARGS) + if (add_temporary_variable(moo, TOKEN_NAME(moo)) <= -1) return -1; + moo->c->mth.tmpr_count++; + if (moo->c->mth.tmpr_count > MAX_CODE_NARGS) { - set_syntax_error (stix, STIX_SYNERR_BLKARGFLOOD, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_BLKARGFLOOD, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - GET_TOKEN (stix); + GET_TOKEN (moo); } - while (TOKEN_TYPE(stix) == STIX_IOTOK_COLON); + while (TOKEN_TYPE(moo) == MOO_IOTOK_COLON); - if (!is_token_binary_selector(stix, VOCA_VBAR)) + if (!is_token_binary_selector(moo, VOCA_VBAR)) { - set_syntax_error (stix, STIX_SYNERR_VBAR, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_VBAR, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - GET_TOKEN (stix); + GET_TOKEN (moo); } - block_arg_count = stix->c->mth.tmpr_count - saved_tmpr_count; + block_arg_count = moo->c->mth.tmpr_count - saved_tmpr_count; if (block_arg_count > MAX_CODE_NBLKARGS) { /* while an integer object is pused to indicate the number of * block arguments, evaluation which is done by message passing * limits the number of arguments that can be passed. so the * check is implemented */ - set_syntax_error (stix, STIX_SYNERR_BLKARGFLOOD, &colon_loc, STIX_NULL); + set_syntax_error (moo, MOO_SYNERR_BLKARGFLOOD, &colon_loc, MOO_NULL); return -1; } - tmpr_loc = stix->c->tok.loc; - if (compile_block_temporaries(stix) <= -1) return -1; + tmpr_loc = moo->c->tok.loc; + if (compile_block_temporaries(moo) <= -1) return -1; /* this is a block-local temporary count including arguments */ - block_tmpr_count = stix->c->mth.tmpr_count - saved_tmpr_count; + block_tmpr_count = moo->c->mth.tmpr_count - saved_tmpr_count; if (block_tmpr_count > MAX_CODE_NBLKTMPRS) { - set_syntax_error (stix, STIX_SYNERR_BLKTMPRFLOOD, &tmpr_loc, STIX_NULL); + set_syntax_error (moo, MOO_SYNERR_BLKTMPRFLOOD, &tmpr_loc, MOO_NULL); return -1; } /* store the accumulated number of temporaries for the current block. * block depth is not raised as it's not entering a new block but * updating the temporaries count for the current block. */ - if (store_tmpr_count_for_block (stix, stix->c->mth.tmpr_count) <= -1) return -1; + if (store_tmpr_count_for_block (moo, moo->c->mth.tmpr_count) <= -1) return -1; -#if defined(STIX_USE_MAKE_BLOCK) - if (emit_double_param_instruction(stix, BCODE_MAKE_BLOCK, block_arg_count, stix->c->mth.tmpr_count/*block_tmpr_count*/) <= -1) return -1; +#if defined(MOO_USE_MAKE_BLOCK) + if (emit_double_param_instruction(moo, BCODE_MAKE_BLOCK, block_arg_count, moo->c->mth.tmpr_count/*block_tmpr_count*/) <= -1) return -1; #else - if (emit_byte_instruction(stix, BCODE_PUSH_CONTEXT) <= -1 || - emit_push_smooi_literal(stix, block_arg_count) <= -1 || - emit_push_smooi_literal(stix, stix->c->mth.tmpr_count/*block_tmpr_count*/) <= -1 || - emit_byte_instruction(stix, BCODE_SEND_BLOCK_COPY) <= -1) return -1; + if (emit_byte_instruction(moo, BCODE_PUSH_CONTEXT) <= -1 || + emit_push_smooi_literal(moo, block_arg_count) <= -1 || + emit_push_smooi_literal(moo, moo->c->mth.tmpr_count/*block_tmpr_count*/) <= -1 || + emit_byte_instruction(moo, BCODE_SEND_BLOCK_COPY) <= -1) return -1; #endif /* insert dummy instructions before replacing them with a jump instruction */ - jump_inst_pos = stix->c->mth.code.len; + jump_inst_pos = moo->c->mth.code.len; /* specifying MAX_CODE_JUMP causes emit_single_param_instruction() to * produce the long jump instruction (BCODE_JUMP_FORWARD_X) */ - if (emit_single_param_instruction (stix, BCODE_JUMP_FORWARD_0, MAX_CODE_JUMP) <= -1) return -1; + if (emit_single_param_instruction (moo, BCODE_JUMP_FORWARD_0, MAX_CODE_JUMP) <= -1) return -1; /* compile statements inside a block */ - if (TOKEN_TYPE(stix) == STIX_IOTOK_RBRACK) + if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACK) { /* the block is empty */ - if (emit_byte_instruction (stix, BCODE_PUSH_NIL) <= -1) return -1; + if (emit_byte_instruction (moo, BCODE_PUSH_NIL) <= -1) return -1; } else { - while (TOKEN_TYPE(stix) != STIX_IOTOK_EOF) + while (TOKEN_TYPE(moo) != MOO_IOTOK_EOF) { - if (compile_block_statement(stix) <= -1) return -1; + if (compile_block_statement(moo) <= -1) return -1; - if (TOKEN_TYPE(stix) == STIX_IOTOK_RBRACK) break; - else if (TOKEN_TYPE(stix) == STIX_IOTOK_PERIOD) + if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACK) break; + else if (TOKEN_TYPE(moo) == MOO_IOTOK_PERIOD) { - GET_TOKEN (stix); - if (TOKEN_TYPE(stix) == STIX_IOTOK_RBRACK) break; - if (emit_byte_instruction(stix, BCODE_POP_STACKTOP) <= -1) return -1; + GET_TOKEN (moo); + if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACK) break; + if (emit_byte_instruction(moo, BCODE_POP_STACKTOP) <= -1) return -1; } else { - set_syntax_error (stix, STIX_SYNERR_RBRACK, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_RBRACK, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } } } - if (emit_byte_instruction(stix, BCODE_RETURN_FROM_BLOCK) <= -1) return -1; + if (emit_byte_instruction(moo, BCODE_RETURN_FROM_BLOCK) <= -1) return -1; - /* STIX_BCODE_LONG_PARAM_SIZE + 1 => size of the long JUMP_FORWARD instruction */ - block_code_size = stix->c->mth.code.len - jump_inst_pos - (STIX_BCODE_LONG_PARAM_SIZE + 1); + /* MOO_BCODE_LONG_PARAM_SIZE + 1 => size of the long JUMP_FORWARD instruction */ + block_code_size = moo->c->mth.code.len - jump_inst_pos - (MOO_BCODE_LONG_PARAM_SIZE + 1); if (block_code_size > MAX_CODE_JUMP * 2) { - set_syntax_error (stix, STIX_SYNERR_BLKFLOOD, &block_loc, STIX_NULL); + set_syntax_error (moo, MOO_SYNERR_BLKFLOOD, &block_loc, MOO_NULL); return -1; } else { - stix_oow_t jump_offset; + moo_oow_t jump_offset; if (block_code_size > MAX_CODE_JUMP) { /* switch to JUMP2 instruction to allow a bigger jump offset. * up to twice MAX_CODE_JUMP only */ - stix->c->mth.code.ptr[jump_inst_pos] = BCODE_JUMP2_FORWARD; + moo->c->mth.code.ptr[jump_inst_pos] = BCODE_JUMP2_FORWARD; jump_offset = block_code_size - MAX_CODE_JUMP; } else @@ -3413,102 +3420,102 @@ static int compile_block_expression (stix_t* stix) jump_offset = block_code_size; } - #if (STIX_BCODE_LONG_PARAM_SIZE == 2) - stix->c->mth.code.ptr[jump_inst_pos + 1] = jump_offset >> 8; - stix->c->mth.code.ptr[jump_inst_pos + 2] = jump_offset & 0xFF; + #if (MOO_BCODE_LONG_PARAM_SIZE == 2) + moo->c->mth.code.ptr[jump_inst_pos + 1] = jump_offset >> 8; + moo->c->mth.code.ptr[jump_inst_pos + 2] = jump_offset & 0xFF; #else - stix->c->mth.code.ptr[jump_inst_pos + 1] = jump_offset; + moo->c->mth.code.ptr[jump_inst_pos + 1] = jump_offset; #endif } /* restore the temporary count */ - stix->c->mth.tmprs.len = saved_tmprs_len; - stix->c->mth.tmpr_count = saved_tmpr_count; + moo->c->mth.tmprs.len = saved_tmprs_len; + moo->c->mth.tmpr_count = saved_tmpr_count; - GET_TOKEN (stix); + GET_TOKEN (moo); return 0; } -static int add_to_byte_array_literal_buffer (stix_t* stix, stix_oob_t b) +static int add_to_byte_array_literal_buffer (moo_t* moo, moo_oob_t b) { - if (stix->c->mth.balit_count >= stix->c->mth.balit_capa) + if (moo->c->mth.balit_count >= moo->c->mth.balit_capa) { - stix_oob_t* tmp; - stix_oow_t new_capa; + moo_oob_t* tmp; + moo_oow_t new_capa; - new_capa = STIX_ALIGN (stix->c->mth.balit_count + 1, BALIT_BUFFER_ALIGN); - tmp = (stix_oob_t*)stix_reallocmem (stix, stix->c->mth.balit, new_capa * STIX_SIZEOF(*tmp)); + new_capa = MOO_ALIGN (moo->c->mth.balit_count + 1, BALIT_BUFFER_ALIGN); + tmp = (moo_oob_t*)moo_reallocmem (moo, moo->c->mth.balit, new_capa * MOO_SIZEOF(*tmp)); if (!tmp) return -1; - stix->c->mth.balit_capa = new_capa; - stix->c->mth.balit = tmp; + moo->c->mth.balit_capa = new_capa; + moo->c->mth.balit = tmp; } -/* TODO: overflow check of stix->c->mth.balit_count itself */ - stix->c->mth.balit[stix->c->mth.balit_count++] = b; +/* TODO: overflow check of moo->c->mth.balit_count itself */ + moo->c->mth.balit[moo->c->mth.balit_count++] = b; return 0; } -static int add_to_array_literal_buffer (stix_t* stix, stix_oop_t item) +static int add_to_array_literal_buffer (moo_t* moo, moo_oop_t item) { - if (stix->c->mth.arlit_count >= stix->c->mth.arlit_capa) + if (moo->c->mth.arlit_count >= moo->c->mth.arlit_capa) { - stix_oop_t* tmp; - stix_oow_t new_capa; + moo_oop_t* tmp; + moo_oow_t new_capa; - new_capa = STIX_ALIGN (stix->c->mth.arlit_count + 1, ARLIT_BUFFER_ALIGN); - tmp = (stix_oop_t*)stix_reallocmem (stix, stix->c->mth.arlit, new_capa * STIX_SIZEOF(*tmp)); + new_capa = MOO_ALIGN (moo->c->mth.arlit_count + 1, ARLIT_BUFFER_ALIGN); + tmp = (moo_oop_t*)moo_reallocmem (moo, moo->c->mth.arlit, new_capa * MOO_SIZEOF(*tmp)); if (!tmp) return -1; - stix->c->mth.arlit_capa = new_capa; - stix->c->mth.arlit = tmp; + moo->c->mth.arlit_capa = new_capa; + moo->c->mth.arlit = tmp; } -/* TODO: overflow check of stix->c->mth.arlit_count itself */ - stix->c->mth.arlit[stix->c->mth.arlit_count++] = item; +/* TODO: overflow check of moo->c->mth.arlit_count itself */ + moo->c->mth.arlit[moo->c->mth.arlit_count++] = item; return 0; } -static int __read_byte_array_literal (stix_t* stix, stix_oop_t* xlit) +static int __read_byte_array_literal (moo_t* moo, moo_oop_t* xlit) { - stix_ooi_t tmp; - stix_oop_t ba; + moo_ooi_t tmp; + moo_oop_t ba; - stix->c->mth.balit_count = 0; + moo->c->mth.balit_count = 0; - while (TOKEN_TYPE(stix) == STIX_IOTOK_NUMLIT || TOKEN_TYPE(stix) == STIX_IOTOK_RADNUMLIT) + while (TOKEN_TYPE(moo) == MOO_IOTOK_NUMLIT || TOKEN_TYPE(moo) == MOO_IOTOK_RADNUMLIT) { /* TODO: check if the number is an integer */ - if (string_to_smooi(stix, TOKEN_NAME(stix), TOKEN_TYPE(stix) == STIX_IOTOK_RADNUMLIT, &tmp) <= -1) + if (string_to_smooi(moo, TOKEN_NAME(moo), TOKEN_TYPE(moo) == MOO_IOTOK_RADNUMLIT, &tmp) <= -1) { /* the token reader reads a valid token. no other errors * than the range error must not occur */ - STIX_ASSERT (stix, stix->errnum == STIX_ERANGE); + MOO_ASSERT (moo, moo->errnum == MOO_ERANGE); /* if the token is out of the SMOOI range, it's too big or * to small to be a byte */ - set_syntax_error (stix, STIX_SYNERR_BYTERANGE, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_BYTERANGE, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } else if (tmp < 0 || tmp > 255) { - set_syntax_error (stix, STIX_SYNERR_BYTERANGE, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_BYTERANGE, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - if (add_to_byte_array_literal_buffer(stix, tmp) <= -1) return -1; - GET_TOKEN (stix); + if (add_to_byte_array_literal_buffer(moo, tmp) <= -1) return -1; + GET_TOKEN (moo); } - if (TOKEN_TYPE(stix) != STIX_IOTOK_RBRACK) + if (TOKEN_TYPE(moo) != MOO_IOTOK_RBRACK) { - set_syntax_error (stix, STIX_SYNERR_RBRACK, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_RBRACK, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - ba = stix_instantiate (stix, stix->_byte_array, stix->c->mth.balit, stix->c->mth.balit_count); + ba = moo_instantiate (moo, moo->_byte_array, moo->c->mth.balit, moo->c->mth.balit_count); if (!ba) return -1; *xlit = ba; @@ -3517,176 +3524,176 @@ static int __read_byte_array_literal (stix_t* stix, stix_oop_t* xlit) struct arlit_info_t { - stix_oow_t pos; - stix_oow_t len; + moo_oow_t pos; + moo_oow_t len; }; typedef struct arlit_info_t arlit_info_t; -static int __read_array_literal (stix_t* stix, stix_oop_t* xlit) +static int __read_array_literal (moo_t* moo, moo_oop_t* xlit) { - stix_oop_t lit, a; - stix_oow_t i, saved_arlit_count; + moo_oop_t lit, a; + moo_oow_t i, saved_arlit_count; arlit_info_t info; - info.pos = stix->c->mth.arlit_count; + info.pos = moo->c->mth.arlit_count; info.len = 0; do { - switch (TOKEN_TYPE(stix)) + switch (TOKEN_TYPE(moo)) { /* TODO: floating pointer number */ - case STIX_IOTOK_NUMLIT: - case STIX_IOTOK_RADNUMLIT: - lit = string_to_num (stix, TOKEN_NAME(stix), TOKEN_TYPE(stix) == STIX_IOTOK_RADNUMLIT); + case MOO_IOTOK_NUMLIT: + case MOO_IOTOK_RADNUMLIT: + lit = string_to_num (moo, TOKEN_NAME(moo), TOKEN_TYPE(moo) == MOO_IOTOK_RADNUMLIT); break; - case STIX_IOTOK_CHARLIT: - STIX_ASSERT (stix, TOKEN_NAME_LEN(stix) == 1); - lit = STIX_CHAR_TO_OOP(TOKEN_NAME_PTR(stix)[0]); + case MOO_IOTOK_CHARLIT: + MOO_ASSERT (moo, TOKEN_NAME_LEN(moo) == 1); + lit = MOO_CHAR_TO_OOP(TOKEN_NAME_PTR(moo)[0]); break; - case STIX_IOTOK_STRLIT: - lit = stix_instantiate (stix, stix->_string, TOKEN_NAME_PTR(stix), TOKEN_NAME_LEN(stix)); + case MOO_IOTOK_STRLIT: + lit = moo_instantiate (moo, moo->_string, TOKEN_NAME_PTR(moo), TOKEN_NAME_LEN(moo)); break; - case STIX_IOTOK_SYMLIT: - lit = stix_makesymbol (stix, TOKEN_NAME_PTR(stix) + 1, TOKEN_NAME_LEN(stix) - 1); + case MOO_IOTOK_SYMLIT: + lit = moo_makesymbol (moo, TOKEN_NAME_PTR(moo) + 1, TOKEN_NAME_LEN(moo) - 1); break; - case STIX_IOTOK_IDENT: - case STIX_IOTOK_IDENT_DOTTED: - case STIX_IOTOK_BINSEL: - case STIX_IOTOK_KEYWORD: - case STIX_IOTOK_SELF: - case STIX_IOTOK_SUPER: - case STIX_IOTOK_THIS_CONTEXT: - case STIX_IOTOK_THIS_PROCESS: - lit = stix_makesymbol (stix, TOKEN_NAME_PTR(stix), TOKEN_NAME_LEN(stix)); + case MOO_IOTOK_IDENT: + case MOO_IOTOK_IDENT_DOTTED: + case MOO_IOTOK_BINSEL: + case MOO_IOTOK_KEYWORD: + case MOO_IOTOK_SELF: + case MOO_IOTOK_SUPER: + case MOO_IOTOK_THIS_CONTEXT: + case MOO_IOTOK_THIS_PROCESS: + lit = moo_makesymbol (moo, TOKEN_NAME_PTR(moo), TOKEN_NAME_LEN(moo)); break; - case STIX_IOTOK_NIL: - lit = stix->_nil; + case MOO_IOTOK_NIL: + lit = moo->_nil; break; - case STIX_IOTOK_TRUE: - lit = stix->_true; + case MOO_IOTOK_TRUE: + lit = moo->_true; break; - case STIX_IOTOK_FALSE: - lit = stix->_false; + case MOO_IOTOK_FALSE: + lit = moo->_false; break; - case STIX_IOTOK_ERROR: - lit = STIX_ERROR_TO_OOP(STIX_EGENERIC); + case MOO_IOTOK_ERROR: + lit = MOO_ERROR_TO_OOP(MOO_EGENERIC); break; - case STIX_IOTOK_ERRLIT: - lit = string_to_error (stix, TOKEN_NAME(stix)); + case MOO_IOTOK_ERRLIT: + lit = string_to_error (moo, TOKEN_NAME(moo)); break; - case STIX_IOTOK_ARPAREN: /* #( */ - case STIX_IOTOK_LPAREN: /* ( */ - saved_arlit_count = stix->c->mth.arlit_count; + case MOO_IOTOK_ARPAREN: /* #( */ + case MOO_IOTOK_LPAREN: /* ( */ + saved_arlit_count = moo->c->mth.arlit_count; /* TODO: get rid of recursion?? */ - GET_TOKEN (stix); - if (__read_array_literal (stix, &lit) <= -1) return -1; - stix->c->mth.arlit_count = saved_arlit_count; + GET_TOKEN (moo); + if (__read_array_literal (moo, &lit) <= -1) return -1; + moo->c->mth.arlit_count = saved_arlit_count; break; - case STIX_IOTOK_BAPAREN: /* #[ */ - case STIX_IOTOK_LBRACK: /* [ */ - GET_TOKEN (stix); - if (__read_byte_array_literal (stix, &lit) <= -1) return -1; + case MOO_IOTOK_BAPAREN: /* #[ */ + case MOO_IOTOK_LBRACK: /* [ */ + GET_TOKEN (moo); + if (__read_byte_array_literal (moo, &lit) <= -1) return -1; break; default: goto done; } - if (!lit || add_to_array_literal_buffer(stix, lit) <= -1) return -1; + if (!lit || add_to_array_literal_buffer(moo, lit) <= -1) return -1; info.len++; - GET_TOKEN (stix); + GET_TOKEN (moo); } while (1); done: - if (TOKEN_TYPE(stix) != STIX_IOTOK_RPAREN) + if (TOKEN_TYPE(moo) != MOO_IOTOK_RPAREN) { - set_syntax_error (stix, STIX_SYNERR_RPAREN, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_RPAREN, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - a = stix_instantiate (stix, stix->_array, STIX_NULL, info.len); + a = moo_instantiate (moo, moo->_array, MOO_NULL, info.len); if (!a) return -1; for (i = 0; i < info.len; i++) { - ((stix_oop_oop_t)a)->slot[i] = stix->c->mth.arlit[info.pos + i]; + ((moo_oop_oop_t)a)->slot[i] = moo->c->mth.arlit[info.pos + i]; } *xlit = a; return 0; } -static STIX_INLINE int read_byte_array_literal (stix_t* stix, stix_oop_t* xlit) +static MOO_INLINE int read_byte_array_literal (moo_t* moo, moo_oop_t* xlit) { - GET_TOKEN (stix); /* skip #[ and read the next token */ - return __read_byte_array_literal(stix, xlit); + GET_TOKEN (moo); /* skip #[ and read the next token */ + return __read_byte_array_literal(moo, xlit); } -static int compile_byte_array_literal (stix_t* stix) +static int compile_byte_array_literal (moo_t* moo) { - stix_oop_t lit; - stix_oow_t index; + moo_oop_t lit; + moo_oow_t index; - if (read_byte_array_literal(stix, &lit) <= -1 || - add_literal(stix, lit, &index) <= -1 || - emit_single_param_instruction(stix, BCODE_PUSH_LITERAL_0, index) <= -1) return -1; + if (read_byte_array_literal(moo, &lit) <= -1 || + add_literal(moo, lit, &index) <= -1 || + emit_single_param_instruction(moo, BCODE_PUSH_LITERAL_0, index) <= -1) return -1; - GET_TOKEN (stix); + GET_TOKEN (moo); return 0; } -static int read_array_literal (stix_t* stix, stix_oop_t* xlit) +static int read_array_literal (moo_t* moo, moo_oop_t* xlit) { int x; - stix_oow_t saved_arlit_count; + moo_oow_t saved_arlit_count; - stix->c->in_array = 1; - if (get_token(stix) <= -1) + moo->c->in_array = 1; + if (get_token(moo) <= -1) { /* skip #( and read the next token */ - stix->c->in_array = 0; + moo->c->in_array = 0; return -1; } - saved_arlit_count = stix->c->mth.arlit_count; - x = __read_array_literal (stix, xlit); - stix->c->mth.arlit_count = saved_arlit_count; - stix->c->in_array = 0; + saved_arlit_count = moo->c->mth.arlit_count; + x = __read_array_literal (moo, xlit); + moo->c->mth.arlit_count = saved_arlit_count; + moo->c->in_array = 0; return x; } -static int compile_array_literal (stix_t* stix) +static int compile_array_literal (moo_t* moo) { - stix_oop_t lit; - stix_oow_t index; + moo_oop_t lit; + moo_oow_t index; - STIX_ASSERT (stix, stix->c->mth.arlit_count == 0); + MOO_ASSERT (moo, moo->c->mth.arlit_count == 0); - if (read_array_literal(stix, &lit) <= -1 || - add_literal(stix, lit, &index) <= -1 || - emit_single_param_instruction(stix, BCODE_PUSH_LITERAL_0, index) <= -1) return -1; + if (read_array_literal(moo, &lit) <= -1 || + add_literal(moo, lit, &index) <= -1 || + emit_single_param_instruction(moo, BCODE_PUSH_LITERAL_0, index) <= -1) return -1; - GET_TOKEN (stix); + GET_TOKEN (moo); return 0; } -static int compile_expression_primary (stix_t* stix, const stix_oocs_t* ident, const stix_ioloc_t* ident_loc, int ident_dotted, int* to_super) +static int compile_expression_primary (moo_t* moo, const moo_oocs_t* ident, const moo_ioloc_t* ident_loc, int ident_dotted, int* to_super) { /* * expression-primary := identifier | literal | block-constructor | ( "(" method-expression ")" ) @@ -3694,7 +3701,7 @@ static int compile_expression_primary (stix_t* stix, const stix_oocs_t* ident, c var_info_t var; int read_next_token = 0; - stix_oow_t index; + moo_oow_t index; *to_super = 0; @@ -3702,45 +3709,45 @@ static int compile_expression_primary (stix_t* stix, const stix_oocs_t* ident, c { /* the caller has read the identifier and the next word */ handle_ident: - if (get_variable_info(stix, ident, ident_loc, ident_dotted, &var) <= -1) return -1; + if (get_variable_info(moo, ident, ident_loc, ident_dotted, &var) <= -1) return -1; switch (var.type) { case VAR_ARGUMENT: case VAR_TEMPORARY: { - #if defined(STIX_USE_CTXTEMPVAR) - if (stix->c->mth.blk_depth > 0) + #if defined(MOO_USE_CTXTEMPVAR) + if (moo->c->mth.blk_depth > 0) { - stix_oow_t i; + moo_oow_t i; /* if a temporary variable is accessed inside a block, * use a special instruction to indicate it */ - STIX_ASSERT (stix, var.pos < stix->c->mth.blk_tmprcnt[stix->c->mth.blk_depth]); - for (i = stix->c->mth.blk_depth; i > 0; i--) + MOO_ASSERT (moo, var.pos < moo->c->mth.blk_tmprcnt[moo->c->mth.blk_depth]); + for (i = moo->c->mth.blk_depth; i > 0; i--) { - if (var.pos >= stix->c->mth.blk_tmprcnt[i - 1]) + if (var.pos >= moo->c->mth.blk_tmprcnt[i - 1]) { - if (emit_double_param_instruction(stix, BCODE_PUSH_CTXTEMPVAR_0, stix->c->mth.blk_depth - i, var.pos - stix->c->mth.blk_tmprcnt[i - 1]) <= -1) return -1; + if (emit_double_param_instruction(moo, BCODE_PUSH_CTXTEMPVAR_0, moo->c->mth.blk_depth - i, var.pos - moo->c->mth.blk_tmprcnt[i - 1]) <= -1) return -1; goto temporary_done; } } } #endif - if (emit_single_param_instruction(stix, BCODE_PUSH_TEMPVAR_0, var.pos) <= -1) return -1; + if (emit_single_param_instruction(moo, BCODE_PUSH_TEMPVAR_0, var.pos) <= -1) return -1; temporary_done: break; } case VAR_INSTANCE: case VAR_CLASSINST: - if (emit_single_param_instruction(stix, BCODE_PUSH_INSTVAR_0, var.pos) <= -1) return -1; + if (emit_single_param_instruction(moo, BCODE_PUSH_INSTVAR_0, var.pos) <= -1) return -1; break; case VAR_CLASS: - if (add_literal(stix, (stix_oop_t)var.cls, &index) <= -1 || - emit_double_param_instruction(stix, BCODE_PUSH_OBJVAR_0, var.pos, index) <= -1) return -1; + if (add_literal(moo, (moo_oop_t)var.cls, &index) <= -1 || + emit_double_param_instruction(moo, BCODE_PUSH_OBJVAR_0, var.pos, index) <= -1) return -1; break; case VAR_GLOBAL: @@ -3753,171 +3760,171 @@ static int compile_expression_primary (stix_t* stix, const stix_oocs_t* ident, c * the code compiled before the deletion will still access * the deleted association */ - if (add_literal(stix, (stix_oop_t)var.gbl, &index) <= -1 || - emit_single_param_instruction(stix, BCODE_PUSH_OBJECT_0, index) <= -1) return -1; + if (add_literal(moo, (moo_oop_t)var.gbl, &index) <= -1 || + emit_single_param_instruction(moo, BCODE_PUSH_OBJECT_0, index) <= -1) return -1; break; default: - stix->errnum = STIX_EINTERN; + moo->errnum = MOO_EINTERN; return -1; } - if (read_next_token) GET_TOKEN (stix); + if (read_next_token) GET_TOKEN (moo); } else { - switch (TOKEN_TYPE(stix)) + switch (TOKEN_TYPE(moo)) { - case STIX_IOTOK_IDENT_DOTTED: + case MOO_IOTOK_IDENT_DOTTED: ident_dotted = 1; - case STIX_IOTOK_IDENT: - ident = TOKEN_NAME(stix); - ident_loc = TOKEN_LOC(stix); + case MOO_IOTOK_IDENT: + ident = TOKEN_NAME(moo); + ident_loc = TOKEN_LOC(moo); read_next_token = 1; goto handle_ident; - case STIX_IOTOK_SELF: - if (emit_byte_instruction(stix, BCODE_PUSH_RECEIVER) <= -1) return -1; - GET_TOKEN (stix); + case MOO_IOTOK_SELF: + if (emit_byte_instruction(moo, BCODE_PUSH_RECEIVER) <= -1) return -1; + GET_TOKEN (moo); break; - case STIX_IOTOK_SUPER: - if (emit_byte_instruction(stix, BCODE_PUSH_RECEIVER) <= -1) return -1; - GET_TOKEN (stix); + case MOO_IOTOK_SUPER: + if (emit_byte_instruction(moo, BCODE_PUSH_RECEIVER) <= -1) return -1; + GET_TOKEN (moo); *to_super = 1; break; - case STIX_IOTOK_NIL: - if (emit_byte_instruction(stix, BCODE_PUSH_NIL) <= -1) return -1; - GET_TOKEN (stix); + case MOO_IOTOK_NIL: + if (emit_byte_instruction(moo, BCODE_PUSH_NIL) <= -1) return -1; + GET_TOKEN (moo); break; - case STIX_IOTOK_TRUE: - if (emit_byte_instruction(stix, BCODE_PUSH_TRUE) <= -1) return -1; - GET_TOKEN (stix); + case MOO_IOTOK_TRUE: + if (emit_byte_instruction(moo, BCODE_PUSH_TRUE) <= -1) return -1; + GET_TOKEN (moo); break; - case STIX_IOTOK_FALSE: - if (emit_byte_instruction(stix, BCODE_PUSH_FALSE) <= -1) return -1; - GET_TOKEN (stix); + case MOO_IOTOK_FALSE: + if (emit_byte_instruction(moo, BCODE_PUSH_FALSE) <= -1) return -1; + GET_TOKEN (moo); break; - case STIX_IOTOK_ERROR: - if (add_literal(stix, STIX_ERROR_TO_OOP(STIX_EGENERIC), &index) <= -1 || - emit_single_param_instruction(stix, BCODE_PUSH_LITERAL_0, index) <= -1) return -1; - GET_TOKEN (stix); + case MOO_IOTOK_ERROR: + if (add_literal(moo, MOO_ERROR_TO_OOP(MOO_EGENERIC), &index) <= -1 || + emit_single_param_instruction(moo, BCODE_PUSH_LITERAL_0, index) <= -1) return -1; + GET_TOKEN (moo); break; - case STIX_IOTOK_ERRLIT: + case MOO_IOTOK_ERRLIT: { - stix_oop_t tmp; + moo_oop_t tmp; - tmp = string_to_error (stix, TOKEN_NAME(stix)); + tmp = string_to_error (moo, TOKEN_NAME(moo)); if (!tmp) return -1; - if (add_literal(stix, tmp, &index) <= -1 || - emit_single_param_instruction(stix, BCODE_PUSH_LITERAL_0, index) <= -1) return -1; + if (add_literal(moo, tmp, &index) <= -1 || + emit_single_param_instruction(moo, BCODE_PUSH_LITERAL_0, index) <= -1) return -1; - GET_TOKEN (stix); + GET_TOKEN (moo); break; } - case STIX_IOTOK_THIS_CONTEXT: - if (emit_byte_instruction(stix, BCODE_PUSH_CONTEXT) <= -1) return -1; - GET_TOKEN (stix); + case MOO_IOTOK_THIS_CONTEXT: + if (emit_byte_instruction(moo, BCODE_PUSH_CONTEXT) <= -1) return -1; + GET_TOKEN (moo); break; - case STIX_IOTOK_THIS_PROCESS: - if (emit_byte_instruction(stix, BCODE_PUSH_PROCESS) <= -1) return -1; - GET_TOKEN (stix); + case MOO_IOTOK_THIS_PROCESS: + if (emit_byte_instruction(moo, BCODE_PUSH_PROCESS) <= -1) return -1; + GET_TOKEN (moo); break; - case STIX_IOTOK_CHARLIT: - STIX_ASSERT (stix, TOKEN_NAME_LEN(stix) == 1); - if (emit_push_character_literal(stix, TOKEN_NAME_PTR(stix)[0]) <= -1) return -1; - GET_TOKEN (stix); + case MOO_IOTOK_CHARLIT: + MOO_ASSERT (moo, TOKEN_NAME_LEN(moo) == 1); + if (emit_push_character_literal(moo, TOKEN_NAME_PTR(moo)[0]) <= -1) return -1; + GET_TOKEN (moo); break; - case STIX_IOTOK_STRLIT: - if (add_string_literal(stix, TOKEN_NAME(stix), &index) <= -1 || - emit_single_param_instruction(stix, BCODE_PUSH_LITERAL_0, index) <= -1) return -1; - GET_TOKEN (stix); + case MOO_IOTOK_STRLIT: + if (add_string_literal(moo, TOKEN_NAME(moo), &index) <= -1 || + emit_single_param_instruction(moo, BCODE_PUSH_LITERAL_0, index) <= -1) return -1; + GET_TOKEN (moo); break; - case STIX_IOTOK_SYMLIT: - if (add_symbol_literal(stix, TOKEN_NAME(stix), 1, &index) <= -1 || - emit_single_param_instruction(stix, BCODE_PUSH_LITERAL_0, index) <= -1) return -1; - GET_TOKEN (stix); + case MOO_IOTOK_SYMLIT: + if (add_symbol_literal(moo, TOKEN_NAME(moo), 1, &index) <= -1 || + emit_single_param_instruction(moo, BCODE_PUSH_LITERAL_0, index) <= -1) return -1; + GET_TOKEN (moo); break; - case STIX_IOTOK_NUMLIT: - case STIX_IOTOK_RADNUMLIT: + case MOO_IOTOK_NUMLIT: + case MOO_IOTOK_RADNUMLIT: { /* TODO: floating pointer number */ /* TODO: other types of numbers, etc */ - stix_oop_t tmp; + moo_oop_t tmp; - tmp = string_to_num (stix, TOKEN_NAME(stix), TOKEN_TYPE(stix) == STIX_IOTOK_RADNUMLIT); + tmp = string_to_num (moo, TOKEN_NAME(moo), TOKEN_TYPE(moo) == MOO_IOTOK_RADNUMLIT); if (!tmp) return -1; - if (STIX_OOP_IS_SMOOI(tmp)) + if (MOO_OOP_IS_SMOOI(tmp)) { - if (emit_push_smooi_literal(stix, STIX_OOP_TO_SMOOI(tmp)) <= -1) return -1; + if (emit_push_smooi_literal(moo, MOO_OOP_TO_SMOOI(tmp)) <= -1) return -1; } else { - if (add_literal(stix, tmp, &index) <= -1 || - emit_single_param_instruction(stix, BCODE_PUSH_LITERAL_0, index) <= -1) return -1; + if (add_literal(moo, tmp, &index) <= -1 || + emit_single_param_instruction(moo, BCODE_PUSH_LITERAL_0, index) <= -1) return -1; } - GET_TOKEN (stix); + GET_TOKEN (moo); break; } - case STIX_IOTOK_BAPAREN: /* #[ */ - /*GET_TOKEN (stix);*/ - if (compile_byte_array_literal(stix) <= -1) return -1; + case MOO_IOTOK_BAPAREN: /* #[ */ + /*GET_TOKEN (moo);*/ + if (compile_byte_array_literal(moo) <= -1) return -1; break; - case STIX_IOTOK_ARPAREN: /* #( */ - /*GET_TOKEN (stix);*/ - if (compile_array_literal(stix) <= -1) return -1; + case MOO_IOTOK_ARPAREN: /* #( */ + /*GET_TOKEN (moo);*/ + if (compile_array_literal(moo) <= -1) return -1; break; /* TODO: dynamic array, non constant array #<> or #{} or what is a better bracket? */ - case STIX_IOTOK_LBRACK: /* [ */ + case MOO_IOTOK_LBRACK: /* [ */ { int n; - /*GET_TOKEN (stix);*/ - if (store_tmpr_count_for_block (stix, stix->c->mth.tmpr_count) <= -1) return -1; - stix->c->mth.blk_depth++; + /*GET_TOKEN (moo);*/ + if (store_tmpr_count_for_block (moo, moo->c->mth.tmpr_count) <= -1) return -1; + moo->c->mth.blk_depth++; /* - * stix->c->mth.tmpr_count[0] contains the number of temporaries for a method. - * stix->c->mth.tmpr_count[1] contains the number of temporaries for the block plus the containing method. + * moo->c->mth.tmpr_count[0] contains the number of temporaries for a method. + * moo->c->mth.tmpr_count[1] contains the number of temporaries for the block plus the containing method. * ... - * stix->c->mth.tmpr_count[n] contains the number of temporaries for the block plus all containing method and blocks. + * moo->c->mth.tmpr_count[n] contains the number of temporaries for the block plus all containing method and blocks. */ - n = compile_block_expression(stix); - stix->c->mth.blk_depth--; + n = compile_block_expression(moo); + moo->c->mth.blk_depth--; if (n <= -1) return -1; break; } - case STIX_IOTOK_LPAREN: - GET_TOKEN (stix); - if (compile_method_expression(stix, 0) <= -1) return -1; - if (TOKEN_TYPE(stix) != STIX_IOTOK_RPAREN) + case MOO_IOTOK_LPAREN: + GET_TOKEN (moo); + if (compile_method_expression(moo, 0) <= -1) return -1; + if (TOKEN_TYPE(moo) != MOO_IOTOK_RPAREN) { - set_syntax_error (stix, STIX_SYNERR_RPAREN, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_RPAREN, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - GET_TOKEN (stix); + GET_TOKEN (moo); break; default: - set_syntax_error (stix, STIX_SYNERR_PRIMARY, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_PRIMARY, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } } @@ -3925,167 +3932,167 @@ static int compile_expression_primary (stix_t* stix, const stix_oocs_t* ident, c return 0; } -static stix_oob_t send_message_cmd[] = +static moo_oob_t send_message_cmd[] = { BCODE_SEND_MESSAGE_0, BCODE_SEND_MESSAGE_TO_SUPER_0 }; -static int compile_unary_message (stix_t* stix, int to_super) +static int compile_unary_message (moo_t* moo, int to_super) { - stix_oow_t index; - stix_oow_t nargs; + moo_oow_t index; + moo_oow_t nargs; - STIX_ASSERT (stix, TOKEN_TYPE(stix) == STIX_IOTOK_IDENT); + MOO_ASSERT (moo, TOKEN_TYPE(moo) == MOO_IOTOK_IDENT); do { nargs = 0; - if (add_symbol_literal(stix, TOKEN_NAME(stix), 0, &index) <= -1) return -1; + if (add_symbol_literal(moo, TOKEN_NAME(moo), 0, &index) <= -1) return -1; - GET_TOKEN (stix); - if (TOKEN_TYPE(stix) == STIX_IOTOK_LPAREN) + GET_TOKEN (moo); + if (TOKEN_TYPE(moo) == MOO_IOTOK_LPAREN) { /* parameterized procedure call */ - GET_TOKEN(stix); - if (TOKEN_TYPE(stix) != STIX_IOTOK_RPAREN) + GET_TOKEN(moo); + if (TOKEN_TYPE(moo) != MOO_IOTOK_RPAREN) { do { - if (compile_method_expression (stix, 0) <= -1) return -1; + if (compile_method_expression (moo, 0) <= -1) return -1; nargs++; - if (TOKEN_TYPE(stix) == STIX_IOTOK_RPAREN) break; + if (TOKEN_TYPE(moo) == MOO_IOTOK_RPAREN) break; - if (TOKEN_TYPE(stix) != STIX_IOTOK_COMMA) + if (TOKEN_TYPE(moo) != MOO_IOTOK_COMMA) { - set_syntax_error (stix, STIX_SYNERR_COMMA, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_COMMA, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - GET_TOKEN(stix); + GET_TOKEN(moo); } while (1); } - GET_TOKEN(stix); + GET_TOKEN(moo); /* NOTE: since the actual method may not be known at the compile time, * i can't check if nargs will match the number of arguments * expected by the method */ } - if (emit_double_param_instruction(stix, send_message_cmd[to_super], nargs, index) <= -1) return -1; + if (emit_double_param_instruction(moo, send_message_cmd[to_super], nargs, index) <= -1) return -1; } - while (TOKEN_TYPE(stix) == STIX_IOTOK_IDENT); + while (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT); return 0; } -static int compile_binary_message (stix_t* stix, int to_super) +static int compile_binary_message (moo_t* moo, int to_super) { /* * binary-message := binary-selector binary-argument * binary-argument := expression-primary unary-message* */ - stix_oow_t index; + moo_oow_t index; int to_super2; - stix_oocs_t binsel; - stix_oow_t saved_binsels_len, binsel_offset; + moo_oocs_t binsel; + moo_oow_t saved_binsels_len, binsel_offset; - STIX_ASSERT (stix, TOKEN_TYPE(stix) == STIX_IOTOK_BINSEL); + MOO_ASSERT (moo, TOKEN_TYPE(moo) == MOO_IOTOK_BINSEL); do { - binsel = stix->c->tok.name; - saved_binsels_len = stix->c->mth.binsels.len; + binsel = moo->c->tok.name; + saved_binsels_len = moo->c->mth.binsels.len; - if (clone_binary_selector(stix, &binsel, &binsel_offset) <= -1) goto oops; + if (clone_binary_selector(moo, &binsel, &binsel_offset) <= -1) goto oops; - GET_TOKEN (stix); + GET_TOKEN (moo); - if (compile_expression_primary(stix, STIX_NULL, STIX_NULL, 0, &to_super2) <= -1) goto oops; + if (compile_expression_primary(moo, MOO_NULL, MOO_NULL, 0, &to_super2) <= -1) goto oops; - if (TOKEN_TYPE(stix) == STIX_IOTOK_IDENT && compile_unary_message(stix, to_super2) <= -1) goto oops; + if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT && compile_unary_message(moo, to_super2) <= -1) goto oops; /* update the pointer to the cloned selector now * to be free from reallocation risk for the recursive call * to compile_expression_primary(). */ - binsel.ptr = &stix->c->mth.binsels.ptr[binsel_offset]; - if (add_symbol_literal(stix, &binsel, 0, &index) <= -1 || - emit_double_param_instruction(stix, send_message_cmd[to_super], 1, index) <= -1) goto oops; + binsel.ptr = &moo->c->mth.binsels.ptr[binsel_offset]; + if (add_symbol_literal(moo, &binsel, 0, &index) <= -1 || + emit_double_param_instruction(moo, send_message_cmd[to_super], 1, index) <= -1) goto oops; - stix->c->mth.binsels.len = saved_binsels_len; + moo->c->mth.binsels.len = saved_binsels_len; } - while (TOKEN_TYPE(stix) == STIX_IOTOK_BINSEL); + while (TOKEN_TYPE(moo) == MOO_IOTOK_BINSEL); return 0; oops: - stix->c->mth.binsels.len = saved_binsels_len; + moo->c->mth.binsels.len = saved_binsels_len; return -1; } -static int compile_keyword_message (stix_t* stix, int to_super) +static int compile_keyword_message (moo_t* moo, int to_super) { /* * keyword-message := (keyword keyword-argument)+ * keyword-argument := expression-primary unary-message* binary-message* */ - stix_oow_t index; + moo_oow_t index; int to_super2; - stix_oocs_t kw, kwsel; - stix_ioloc_t saved_kwsel_loc; - stix_oow_t saved_kwsel_len; - stix_oow_t kw_offset; - stix_oow_t nargs = 0; + moo_oocs_t kw, kwsel; + moo_ioloc_t saved_kwsel_loc; + moo_oow_t saved_kwsel_len; + moo_oow_t kw_offset; + moo_oow_t nargs = 0; - saved_kwsel_loc = stix->c->tok.loc; - saved_kwsel_len = stix->c->mth.kwsels.len; + saved_kwsel_loc = moo->c->tok.loc; + saved_kwsel_len = moo->c->mth.kwsels.len; /* TODO: optimization for ifTrue: ifFalse: whileTrue: whileFalse .. */ do { - kw = stix->c->tok.name; - if (clone_keyword(stix, &kw, &kw_offset) <= -1) goto oops; + kw = moo->c->tok.name; + if (clone_keyword(moo, &kw, &kw_offset) <= -1) goto oops; - GET_TOKEN (stix); + GET_TOKEN (moo); - if (compile_expression_primary(stix, STIX_NULL, STIX_NULL, 0, &to_super2) <= -1) goto oops; - if (TOKEN_TYPE(stix) == STIX_IOTOK_IDENT && compile_unary_message(stix, to_super2) <= -1) goto oops; - if (TOKEN_TYPE(stix) == STIX_IOTOK_BINSEL && compile_binary_message(stix, to_super2) <= -1) goto oops; + if (compile_expression_primary(moo, MOO_NULL, MOO_NULL, 0, &to_super2) <= -1) goto oops; + if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT && compile_unary_message(moo, to_super2) <= -1) goto oops; + if (TOKEN_TYPE(moo) == MOO_IOTOK_BINSEL && compile_binary_message(moo, to_super2) <= -1) goto oops; - kw.ptr = &stix->c->mth.kwsels.ptr[kw_offset]; + kw.ptr = &moo->c->mth.kwsels.ptr[kw_offset]; if (nargs >= MAX_CODE_NARGS) { /* 'kw' points to only one segment of the full keyword message. * if it parses an expression like 'aBlock value: 10 with: 20', * 'kw' may point to 'value:' or 'with:'. */ - set_syntax_error (stix, STIX_SYNERR_ARGFLOOD, &saved_kwsel_loc, &kw); + set_syntax_error (moo, MOO_SYNERR_ARGFLOOD, &saved_kwsel_loc, &kw); goto oops; } nargs++; } - while (TOKEN_TYPE(stix) == STIX_IOTOK_KEYWORD); + while (TOKEN_TYPE(moo) == MOO_IOTOK_KEYWORD); - kwsel.ptr = &stix->c->mth.kwsels.ptr[saved_kwsel_len]; - kwsel.len = stix->c->mth.kwsels.len - saved_kwsel_len; + kwsel.ptr = &moo->c->mth.kwsels.ptr[saved_kwsel_len]; + kwsel.len = moo->c->mth.kwsels.len - saved_kwsel_len; - if (add_symbol_literal(stix, &kwsel, 0, &index) <= -1 || - emit_double_param_instruction(stix, send_message_cmd[to_super], nargs, index) <= -1) goto oops; + if (add_symbol_literal(moo, &kwsel, 0, &index) <= -1 || + emit_double_param_instruction(moo, send_message_cmd[to_super], nargs, index) <= -1) goto oops; - stix->c->mth.kwsels.len = saved_kwsel_len; + moo->c->mth.kwsels.len = saved_kwsel_len; return 0; oops: - stix->c->mth.kwsels.len = saved_kwsel_len; + moo->c->mth.kwsels.len = saved_kwsel_len; return -1; } -static int compile_message_expression (stix_t* stix, int to_super) +static int compile_message_expression (moo_t* moo, int to_super) { /* * message-expression := single-message cascaded-message @@ -4101,65 +4108,65 @@ static int compile_message_expression (stix_t* stix, int to_super) * unary-message := unary-selector * cascaded-message := (";" single-message)* */ - stix_oow_t noop_pos; + moo_oow_t noop_pos; do { - switch (TOKEN_TYPE(stix)) + switch (TOKEN_TYPE(moo)) { - case STIX_IOTOK_IDENT: + case MOO_IOTOK_IDENT: /* insert NOOP to change to DUP_STACKTOP if there is a * cascaded message */ - noop_pos = stix->c->mth.code.len; - if (emit_byte_instruction(stix, BCODE_NOOP) <= -1) return -1; + noop_pos = moo->c->mth.code.len; + if (emit_byte_instruction(moo, BCODE_NOOP) <= -1) return -1; - if (compile_unary_message(stix, to_super) <= -1) return -1; + if (compile_unary_message(moo, to_super) <= -1) return -1; - if (TOKEN_TYPE(stix) == STIX_IOTOK_BINSEL) + if (TOKEN_TYPE(moo) == MOO_IOTOK_BINSEL) { - STIX_ASSERT (stix, stix->c->mth.code.len > noop_pos); - STIX_MEMMOVE (&stix->c->mth.code.ptr[noop_pos], &stix->c->mth.code.ptr[noop_pos + 1], stix->c->mth.code.len - noop_pos - 1); - stix->c->mth.code.len--; + MOO_ASSERT (moo, moo->c->mth.code.len > noop_pos); + MOO_MEMMOVE (&moo->c->mth.code.ptr[noop_pos], &moo->c->mth.code.ptr[noop_pos + 1], moo->c->mth.code.len - noop_pos - 1); + moo->c->mth.code.len--; - noop_pos = stix->c->mth.code.len; - if (emit_byte_instruction(stix, BCODE_NOOP) <= -1) return -1; - if (compile_binary_message(stix, to_super) <= -1) return -1; + noop_pos = moo->c->mth.code.len; + if (emit_byte_instruction(moo, BCODE_NOOP) <= -1) return -1; + if (compile_binary_message(moo, to_super) <= -1) return -1; } - if (TOKEN_TYPE(stix) == STIX_IOTOK_KEYWORD) + if (TOKEN_TYPE(moo) == MOO_IOTOK_KEYWORD) { - STIX_ASSERT (stix, stix->c->mth.code.len > noop_pos); - STIX_MEMMOVE (&stix->c->mth.code.ptr[noop_pos], &stix->c->mth.code.ptr[noop_pos + 1], stix->c->mth.code.len - noop_pos - 1); - stix->c->mth.code.len--; + MOO_ASSERT (moo, moo->c->mth.code.len > noop_pos); + MOO_MEMMOVE (&moo->c->mth.code.ptr[noop_pos], &moo->c->mth.code.ptr[noop_pos + 1], moo->c->mth.code.len - noop_pos - 1); + moo->c->mth.code.len--; - noop_pos = stix->c->mth.code.len; - if (emit_byte_instruction(stix, BCODE_NOOP) <= -1) return -1; - if (compile_keyword_message(stix, to_super) <= -1) return -1; + noop_pos = moo->c->mth.code.len; + if (emit_byte_instruction(moo, BCODE_NOOP) <= -1) return -1; + if (compile_keyword_message(moo, to_super) <= -1) return -1; } break; - case STIX_IOTOK_BINSEL: - noop_pos = stix->c->mth.code.len; - if (emit_byte_instruction(stix, BCODE_NOOP) <= -1) return -1; + case MOO_IOTOK_BINSEL: + noop_pos = moo->c->mth.code.len; + if (emit_byte_instruction(moo, BCODE_NOOP) <= -1) return -1; - if (compile_binary_message(stix, to_super) <= -1) return -1; - if (TOKEN_TYPE(stix) == STIX_IOTOK_KEYWORD) + if (compile_binary_message(moo, to_super) <= -1) return -1; + if (TOKEN_TYPE(moo) == MOO_IOTOK_KEYWORD) { - STIX_ASSERT (stix, stix->c->mth.code.len > noop_pos); - STIX_MEMMOVE (&stix->c->mth.code.ptr[noop_pos], &stix->c->mth.code.ptr[noop_pos + 1], stix->c->mth.code.len - noop_pos - 1); - stix->c->mth.code.len--; + MOO_ASSERT (moo, moo->c->mth.code.len > noop_pos); + MOO_MEMMOVE (&moo->c->mth.code.ptr[noop_pos], &moo->c->mth.code.ptr[noop_pos + 1], moo->c->mth.code.len - noop_pos - 1); + moo->c->mth.code.len--; - noop_pos = stix->c->mth.code.len; - if (emit_byte_instruction(stix, BCODE_NOOP) <= -1) return -1; - if (compile_keyword_message(stix, to_super) <= -1) return -1; + noop_pos = moo->c->mth.code.len; + if (emit_byte_instruction(moo, BCODE_NOOP) <= -1) return -1; + if (compile_keyword_message(moo, to_super) <= -1) return -1; } break; - case STIX_IOTOK_KEYWORD: - noop_pos = stix->c->mth.code.len; - if (emit_byte_instruction(stix, BCODE_NOOP) <= -1) return -1; + case MOO_IOTOK_KEYWORD: + noop_pos = moo->c->mth.code.len; + if (emit_byte_instruction(moo, BCODE_NOOP) <= -1) return -1; - if (compile_keyword_message(stix, to_super) <= -1) return -1; + if (compile_keyword_message(moo, to_super) <= -1) return -1; break; default: @@ -4167,18 +4174,18 @@ static int compile_message_expression (stix_t* stix, int to_super) } - if (TOKEN_TYPE(stix) == STIX_IOTOK_SEMICOLON) + if (TOKEN_TYPE(moo) == MOO_IOTOK_SEMICOLON) { - stix->c->mth.code.ptr[noop_pos] = BCODE_DUP_STACKTOP; - if (emit_byte_instruction(stix, BCODE_POP_STACKTOP) <= -1) return -1; - GET_TOKEN(stix); + moo->c->mth.code.ptr[noop_pos] = BCODE_DUP_STACKTOP; + if (emit_byte_instruction(moo, BCODE_POP_STACKTOP) <= -1) return -1; + GET_TOKEN(moo); } else { /* delete the NOOP instruction inserted */ - STIX_ASSERT (stix, stix->c->mth.code.len > noop_pos); - STIX_MEMMOVE (&stix->c->mth.code.ptr[noop_pos], &stix->c->mth.code.ptr[noop_pos + 1], stix->c->mth.code.len - noop_pos - 1); - stix->c->mth.code.len--; + MOO_ASSERT (moo, moo->c->mth.code.len > noop_pos); + MOO_MEMMOVE (&moo->c->mth.code.ptr[noop_pos], &moo->c->mth.code.ptr[noop_pos + 1], moo->c->mth.code.len - noop_pos - 1); + moo->c->mth.code.len--; goto done; } } @@ -4188,74 +4195,79 @@ done: return 0; } -static int compile_basic_expression (stix_t* stix, const stix_oocs_t* ident, const stix_ioloc_t* ident_loc, int ident_dotted) +static int compile_basic_expression (moo_t* moo, const moo_oocs_t* ident, const moo_ioloc_t* ident_loc, int ident_dotted) { /* * basic-expression := expression-primary message-expression? */ int to_super; - if (compile_expression_primary(stix, ident, ident_loc, ident_dotted, &to_super) <= -1) return -1; + if (compile_expression_primary(moo, ident, ident_loc, ident_dotted, &to_super) <= -1) return -1; #if 0 - if (TOKEN_TYPE(stix) != STIX_IOTOK_EOF && - TOKEN_TYPE(stix) != STIX_IOTOK_RBRACE && - TOKEN_TYPE(stix) != STIX_IOTOK_PERIOD && - TOKEN_TYPE(stix) != STIX_IOTOK_SEMICOLON) + if (TOKEN_TYPE(moo) != MOO_IOTOK_EOF && + TOKEN_TYPE(moo) != MOO_IOTOK_RBRACE && + TOKEN_TYPE(moo) != MOO_IOTOK_PERIOD && + TOKEN_TYPE(moo) != MOO_IOTOK_SEMICOLON) { - if (compile_message_expression(stix, to_super) <= -1) return -1; + if (compile_message_expression(moo, to_super) <= -1) return -1; } #else - if (TOKEN_TYPE(stix) == STIX_IOTOK_IDENT || - TOKEN_TYPE(stix) == STIX_IOTOK_BINSEL || - TOKEN_TYPE(stix) == STIX_IOTOK_KEYWORD) + if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT || + TOKEN_TYPE(moo) == MOO_IOTOK_BINSEL || + TOKEN_TYPE(moo) == MOO_IOTOK_KEYWORD) { - if (compile_message_expression(stix, to_super) <= -1) return -1; + if (compile_message_expression(moo, to_super) <= -1) return -1; } #endif return 0; } -static int compile_method_expression (stix_t* stix, int pop) +static int compile_method_expression (moo_t* moo, int pop) { /* - * method-expression := method-assignment-expression | basic-expression + * method-expression := method-assignment-expression | basic-expression | if-expression * method-assignment-expression := identifier ":=" method-expression + * if-expression := if ( ) { } else { }. */ - stix_oocs_t assignee; - stix_oow_t index; + moo_oocs_t assignee; + moo_oow_t index; int ret = 0; - STIX_ASSERT (stix, pop == 0 || pop == 1); - STIX_MEMSET (&assignee, 0, STIX_SIZEOF(assignee)); + MOO_ASSERT (moo, pop == 0 || pop == 1); + MOO_MEMSET (&assignee, 0, MOO_SIZEOF(assignee)); - if (TOKEN_TYPE(stix) == STIX_IOTOK_IDENT || - TOKEN_TYPE(stix) == STIX_IOTOK_IDENT_DOTTED) + if (TOKEN_TYPE(moo) == MOO_IOTOK_IF) { - stix_ioloc_t assignee_loc; - stix_oow_t assignee_offset; +/* TODO: ... */ + } + else if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT || + TOKEN_TYPE(moo) == MOO_IOTOK_IDENT_DOTTED) + { + moo_ioloc_t assignee_loc; + moo_oow_t assignee_offset; int assignee_dotted; /* store the assignee name to the internal buffer * to make it valid after the token buffer has been overwritten */ - assignee = stix->c->tok.name; + assignee = moo->c->tok.name; - if (clone_assignee(stix, &assignee, &assignee_offset) <= -1) return -1; + if (clone_assignee(moo, &assignee, &assignee_offset) <= -1) return -1; - assignee_loc = stix->c->tok.loc; - assignee_dotted = (TOKEN_TYPE(stix) == STIX_IOTOK_IDENT_DOTTED); + assignee_loc = moo->c->tok.loc; + assignee_dotted = (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT_DOTTED); - GET_TOKEN (stix); - if (TOKEN_TYPE(stix) == STIX_IOTOK_ASSIGN) + GET_TOKEN (moo); + if (TOKEN_TYPE(moo) == MOO_IOTOK_ASSIGN) { /* assignment expression */ var_info_t var; - GET_TOKEN (stix); + GET_TOKEN (moo); - if (compile_method_expression(stix, 0) <= -1) goto oops; + if (compile_method_expression(moo, 0) <= -1) goto oops; /* compile_method_expression() is called after clone_assignee(). * clone_assignee() may reallocate a single buffer to hold @@ -4263,38 +4275,38 @@ static int compile_method_expression (stix_t* stix, int pop) * fragile as it can change. use the offset of the cloned * assignee to update the actual pointer after the recursive * compile_method_expression() call */ - assignee.ptr = &stix->c->mth.assignees.ptr[assignee_offset]; - if (get_variable_info(stix, &assignee, &assignee_loc, assignee_dotted, &var) <= -1) goto oops; + assignee.ptr = &moo->c->mth.assignees.ptr[assignee_offset]; + if (get_variable_info(moo, &assignee, &assignee_loc, assignee_dotted, &var) <= -1) goto oops; switch (var.type) { case VAR_ARGUMENT: /* assigning to an argument is not allowed */ - set_syntax_error (stix, STIX_SYNERR_VARARG, &assignee_loc, &assignee); + set_syntax_error (moo, MOO_SYNERR_VARARG, &assignee_loc, &assignee); goto oops; case VAR_TEMPORARY: { - #if defined(STIX_USE_CTXTEMPVAR) - if (stix->c->mth.blk_depth > 0) + #if defined(MOO_USE_CTXTEMPVAR) + if (moo->c->mth.blk_depth > 0) { - stix_oow_t i; + moo_oow_t i; /* if a temporary variable is accessed inside a block, * use a special instruction to indicate it */ - STIX_ASSERT (stix, var.pos < stix->c->mth.blk_tmprcnt[stix->c->mth.blk_depth]); - for (i = stix->c->mth.blk_depth; i > 0; i--) + MOO_ASSERT (moo, var.pos < moo->c->mth.blk_tmprcnt[moo->c->mth.blk_depth]); + for (i = moo->c->mth.blk_depth; i > 0; i--) { - if (var.pos >= stix->c->mth.blk_tmprcnt[i - 1]) + if (var.pos >= moo->c->mth.blk_tmprcnt[i - 1]) { - if (emit_double_param_instruction(stix, (pop? BCODE_POP_INTO_CTXTEMPVAR_0: BCODE_STORE_INTO_CTXTEMPVAR_0), stix->c->mth.blk_depth - i, var.pos - stix->c->mth.blk_tmprcnt[i - 1]) <= -1) return -1; + if (emit_double_param_instruction(moo, (pop? BCODE_POP_INTO_CTXTEMPVAR_0: BCODE_STORE_INTO_CTXTEMPVAR_0), moo->c->mth.blk_depth - i, var.pos - moo->c->mth.blk_tmprcnt[i - 1]) <= -1) return -1; goto temporary_done; } } } #endif - if (emit_single_param_instruction (stix, (pop? BCODE_POP_INTO_TEMPVAR_0: BCODE_STORE_INTO_TEMPVAR_0), var.pos) <= -1) goto oops; + if (emit_single_param_instruction (moo, (pop? BCODE_POP_INTO_TEMPVAR_0: BCODE_STORE_INTO_TEMPVAR_0), var.pos) <= -1) goto oops; temporary_done: ret = pop; @@ -4303,24 +4315,24 @@ static int compile_method_expression (stix_t* stix, int pop) case VAR_INSTANCE: case VAR_CLASSINST: - if (emit_single_param_instruction (stix, (pop? BCODE_POP_INTO_INSTVAR_0: BCODE_STORE_INTO_INSTVAR_0), var.pos) <= -1) goto oops; + if (emit_single_param_instruction (moo, (pop? BCODE_POP_INTO_INSTVAR_0: BCODE_STORE_INTO_INSTVAR_0), var.pos) <= -1) goto oops; ret = pop; break; case VAR_CLASS: - if (add_literal (stix, (stix_oop_t)var.cls, &index) <= -1 || - emit_double_param_instruction (stix, (pop? BCODE_POP_INTO_OBJVAR_0: BCODE_STORE_INTO_OBJVAR_0), var.pos, index) <= -1) goto oops; + if (add_literal (moo, (moo_oop_t)var.cls, &index) <= -1 || + emit_double_param_instruction (moo, (pop? BCODE_POP_INTO_OBJVAR_0: BCODE_STORE_INTO_OBJVAR_0), var.pos, index) <= -1) goto oops; ret = pop; break; case VAR_GLOBAL: - if (add_literal(stix, (stix_oop_t)var.gbl, &index) <= -1 || - emit_single_param_instruction(stix, (pop? BCODE_POP_INTO_OBJECT_0: BCODE_STORE_INTO_OBJECT_0), index) <= -1) return -1; + if (add_literal(moo, (moo_oop_t)var.gbl, &index) <= -1 || + emit_single_param_instruction(moo, (pop? BCODE_POP_INTO_OBJECT_0: BCODE_STORE_INTO_OBJECT_0), index) <= -1) return -1; ret = pop; break; default: - stix->errnum = STIX_EINTERN; + moo->errnum = MOO_EINTERN; goto oops; } } @@ -4329,55 +4341,55 @@ static int compile_method_expression (stix_t* stix, int pop) /* what is held in assignee is not an assignee any more. * potentially it is a variable or object reference * to be pused on to the stack */ - assignee.ptr = &stix->c->mth.assignees.ptr[assignee_offset]; - if (compile_basic_expression(stix, &assignee, &assignee_loc, assignee_dotted) <= -1) goto oops; + assignee.ptr = &moo->c->mth.assignees.ptr[assignee_offset]; + if (compile_basic_expression(moo, &assignee, &assignee_loc, assignee_dotted) <= -1) goto oops; } } else { assignee.len = 0; - if (compile_basic_expression(stix, STIX_NULL, STIX_NULL, 0) <= -1) goto oops; + if (compile_basic_expression(moo, MOO_NULL, MOO_NULL, 0) <= -1) goto oops; } - stix->c->mth.assignees.len -= assignee.len; + moo->c->mth.assignees.len -= assignee.len; return ret; oops: - stix->c->mth.assignees.len -= assignee.len; + moo->c->mth.assignees.len -= assignee.len; return -1; } -static int compile_block_statement (stix_t* stix) +static int compile_block_statement (moo_t* moo) { /* compile_block_statement() is a simpler version of * of compile_method_statement(). it doesn't cater for * popping the stack top */ - if (TOKEN_TYPE(stix) == STIX_IOTOK_RETURN) + if (TOKEN_TYPE(moo) == MOO_IOTOK_RETURN) { /* handle the return statement */ - GET_TOKEN (stix); - if (compile_method_expression(stix, 0) <= -1) return -1; - return emit_byte_instruction (stix, BCODE_RETURN_STACKTOP); + GET_TOKEN (moo); + if (compile_method_expression(moo, 0) <= -1) return -1; + return emit_byte_instruction (moo, BCODE_RETURN_STACKTOP); } else { - return compile_method_expression(stix, 0); + return compile_method_expression(moo, 0); } } -static int compile_method_statement (stix_t* stix) +static int compile_method_statement (moo_t* moo) { /* * method-statement := method-return-statement | method-expression * method-return-statement := "^" method-expression */ - if (TOKEN_TYPE(stix) == STIX_IOTOK_RETURN) + if (TOKEN_TYPE(moo) == MOO_IOTOK_RETURN) { /* handle the return statement */ - GET_TOKEN (stix); - if (compile_method_expression(stix, 0) <= -1) return -1; - return emit_byte_instruction (stix, BCODE_RETURN_STACKTOP); + GET_TOKEN (moo); + if (compile_method_expression(moo, 0) <= -1) return -1; + return emit_byte_instruction (moo, BCODE_RETURN_STACKTOP); } else { @@ -4389,47 +4401,47 @@ static int compile_method_statement (stix_t* stix) * can optimize some instruction sequencese. for example, two * consecutive store and pop intructions can be transformed to * a more specialized single pop-and-store instruction. */ - n = compile_method_expression(stix, 1); + n = compile_method_expression(moo, 1); if (n <= -1) return -1; /* if n is 1, no stack popping is required */ if (n == 0) { - return emit_byte_instruction (stix, BCODE_POP_STACKTOP); + return emit_byte_instruction (moo, BCODE_POP_STACKTOP); } return 0; } } -static int compile_method_statements (stix_t* stix) +static int compile_method_statements (moo_t* moo) { /* * method-statements := method-statement ("." | ("." method-statements))* */ - if (TOKEN_TYPE(stix) != STIX_IOTOK_EOF && - TOKEN_TYPE(stix) != STIX_IOTOK_RBRACE) + if (TOKEN_TYPE(moo) != MOO_IOTOK_EOF && + TOKEN_TYPE(moo) != MOO_IOTOK_RBRACE) { do { - if (compile_method_statement(stix) <= -1) return -1; + if (compile_method_statement(moo) <= -1) return -1; - if (TOKEN_TYPE(stix) == STIX_IOTOK_PERIOD) + if (TOKEN_TYPE(moo) == MOO_IOTOK_PERIOD) { /* period after a statement */ - GET_TOKEN (stix); + GET_TOKEN (moo); - if (TOKEN_TYPE(stix) == STIX_IOTOK_EOF || - TOKEN_TYPE(stix) == STIX_IOTOK_RBRACE) break; + if (TOKEN_TYPE(moo) == MOO_IOTOK_EOF || + TOKEN_TYPE(moo) == MOO_IOTOK_RBRACE) break; } else { - if (TOKEN_TYPE(stix) == STIX_IOTOK_EOF || - TOKEN_TYPE(stix) == STIX_IOTOK_RBRACE) break; + if (TOKEN_TYPE(moo) == MOO_IOTOK_EOF || + TOKEN_TYPE(moo) == MOO_IOTOK_RBRACE) break; /* not a period, EOF, nor } */ - set_syntax_error (stix, STIX_SYNERR_PERIOD, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_PERIOD, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } } @@ -4438,103 +4450,103 @@ static int compile_method_statements (stix_t* stix) /* arrange to return the receiver if execution reached * the end of the method without explicit return */ - return emit_byte_instruction (stix, BCODE_RETURN_RECEIVER); + return emit_byte_instruction (moo, BCODE_RETURN_RECEIVER); } -static int add_compiled_method (stix_t* stix) +static int add_compiled_method (moo_t* moo) { - stix_oop_char_t name; /* selector */ - stix_oop_method_t mth; /* method */ -#if defined(STIX_USE_OBJECT_TRAILER) + moo_oop_char_t name; /* selector */ + moo_oop_method_t mth; /* method */ +#if defined(MOO_USE_OBJECT_TRAILER) /* nothing extra */ #else - stix_oop_byte_t code; + moo_oop_byte_t code; #endif - stix_oow_t tmp_count = 0; - stix_oow_t i; - stix_ooi_t preamble_code, preamble_index, preamble_flags; + moo_oow_t tmp_count = 0; + moo_oow_t i; + moo_ooi_t preamble_code, preamble_index, preamble_flags; - name = (stix_oop_char_t)stix_makesymbol (stix, stix->c->mth.name.ptr, stix->c->mth.name.len); + name = (moo_oop_char_t)moo_makesymbol (moo, moo->c->mth.name.ptr, moo->c->mth.name.len); if (!name) return -1; - stix_pushtmp (stix, (stix_oop_t*)&name); tmp_count++; + moo_pushtmp (moo, (moo_oop_t*)&name); tmp_count++; - /* The variadic data part passed to stix_instantiate() is not GC-safe */ -#if defined(STIX_USE_OBJECT_TRAILER) - mth = (stix_oop_method_t)stix_instantiatewithtrailer (stix, stix->_method, stix->c->mth.literal_count, stix->c->mth.code.ptr, stix->c->mth.code.len); + /* The variadic data part passed to moo_instantiate() is not GC-safe */ +#if defined(MOO_USE_OBJECT_TRAILER) + mth = (moo_oop_method_t)moo_instantiatewithtrailer (moo, moo->_method, moo->c->mth.literal_count, moo->c->mth.code.ptr, moo->c->mth.code.len); #else - mth = (stix_oop_method_t)stix_instantiate (stix, stix->_method, STIX_NULL, stix->c->mth.literal_count); + mth = (moo_oop_method_t)moo_instantiate (moo, moo->_method, MOO_NULL, moo->c->mth.literal_count); #endif if (!mth) goto oops; - for (i = 0; i < stix->c->mth.literal_count; i++) + for (i = 0; i < moo->c->mth.literal_count; i++) { /* let's do the variadic data initialization here */ - mth->slot[i] = stix->c->mth.literals[i]; + mth->slot[i] = moo->c->mth.literals[i]; } - stix_pushtmp (stix, (stix_oop_t*)&mth); tmp_count++; + moo_pushtmp (moo, (moo_oop_t*)&mth); tmp_count++; -#if defined(STIX_USE_OBJECT_TRAILER) +#if defined(MOO_USE_OBJECT_TRAILER) /* do nothing */ #else - code = (stix_oop_byte_t)stix_instantiate (stix, stix->_byte_array, stix->c->mth.code.ptr, stix->c->mth.code.len); + code = (moo_oop_byte_t)moo_instantiate (moo, moo->_byte_array, moo->c->mth.code.ptr, moo->c->mth.code.len); if (!code) goto oops; - stix_pushtmp (stix, (stix_oop_t*)&code); tmp_count++; + moo_pushtmp (moo, (moo_oop_t*)&code); tmp_count++; #endif - preamble_code = STIX_METHOD_PREAMBLE_NONE; + preamble_code = MOO_METHOD_PREAMBLE_NONE; preamble_index = 0; preamble_flags = 0; - if (stix->c->mth.pftype <= 0) + if (moo->c->mth.pftype <= 0) { /* no primitive is set */ - if (stix->c->mth.code.len <= 0) + if (moo->c->mth.code.len <= 0) { - preamble_code = STIX_METHOD_PREAMBLE_RETURN_RECEIVER; + preamble_code = MOO_METHOD_PREAMBLE_RETURN_RECEIVER; } else { - if (stix->c->mth.code.ptr[0] == BCODE_RETURN_RECEIVER) + if (moo->c->mth.code.ptr[0] == BCODE_RETURN_RECEIVER) { - preamble_code = STIX_METHOD_PREAMBLE_RETURN_RECEIVER; + preamble_code = MOO_METHOD_PREAMBLE_RETURN_RECEIVER; } - else if (stix->c->mth.code.len > 1 && stix->c->mth.code.ptr[1] == BCODE_RETURN_STACKTOP) + else if (moo->c->mth.code.len > 1 && moo->c->mth.code.ptr[1] == BCODE_RETURN_STACKTOP) { - switch (stix->c->mth.code.ptr[0]) + switch (moo->c->mth.code.ptr[0]) { case BCODE_PUSH_RECEIVER: - preamble_code = STIX_METHOD_PREAMBLE_RETURN_RECEIVER; + preamble_code = MOO_METHOD_PREAMBLE_RETURN_RECEIVER; break; case BCODE_PUSH_NIL: - preamble_code = STIX_METHOD_PREAMBLE_RETURN_NIL; + preamble_code = MOO_METHOD_PREAMBLE_RETURN_NIL; break; case BCODE_PUSH_TRUE: - preamble_code = STIX_METHOD_PREAMBLE_RETURN_TRUE; + preamble_code = MOO_METHOD_PREAMBLE_RETURN_TRUE; break; case BCODE_PUSH_FALSE: - preamble_code = STIX_METHOD_PREAMBLE_RETURN_FALSE; + preamble_code = MOO_METHOD_PREAMBLE_RETURN_FALSE; break; case BCODE_PUSH_NEGONE: - preamble_code = STIX_METHOD_PREAMBLE_RETURN_NEGINDEX; + preamble_code = MOO_METHOD_PREAMBLE_RETURN_NEGINDEX; preamble_index = 1; break; case BCODE_PUSH_ZERO: - preamble_code = STIX_METHOD_PREAMBLE_RETURN_INDEX; + preamble_code = MOO_METHOD_PREAMBLE_RETURN_INDEX; preamble_index = 0; break; case BCODE_PUSH_ONE: - preamble_code = STIX_METHOD_PREAMBLE_RETURN_INDEX; + preamble_code = MOO_METHOD_PREAMBLE_RETURN_INDEX; preamble_index = 1; break; case BCODE_PUSH_TWO: - preamble_code = STIX_METHOD_PREAMBLE_RETURN_INDEX; + preamble_code = MOO_METHOD_PREAMBLE_RETURN_INDEX; preamble_index = 2; break; @@ -4546,211 +4558,211 @@ static int add_compiled_method (stix_t* stix) case BCODE_PUSH_INSTVAR_5: case BCODE_PUSH_INSTVAR_6: case BCODE_PUSH_INSTVAR_7: - preamble_code = STIX_METHOD_PREAMBLE_RETURN_INSTVAR; - preamble_index = stix->c->mth.code.ptr[0] & 0x7; /* low 3 bits */ + preamble_code = MOO_METHOD_PREAMBLE_RETURN_INSTVAR; + preamble_index = moo->c->mth.code.ptr[0] & 0x7; /* low 3 bits */ break; } } - else if (stix->c->mth.code.len > STIX_BCODE_LONG_PARAM_SIZE + 1 && - stix->c->mth.code.ptr[STIX_BCODE_LONG_PARAM_SIZE + 1] == BCODE_RETURN_STACKTOP) + else if (moo->c->mth.code.len > MOO_BCODE_LONG_PARAM_SIZE + 1 && + moo->c->mth.code.ptr[MOO_BCODE_LONG_PARAM_SIZE + 1] == BCODE_RETURN_STACKTOP) { int i; - switch (stix->c->mth.code.ptr[0]) + switch (moo->c->mth.code.ptr[0]) { case BCODE_PUSH_INSTVAR_X: - preamble_code = STIX_METHOD_PREAMBLE_RETURN_INSTVAR; + preamble_code = MOO_METHOD_PREAMBLE_RETURN_INSTVAR; goto set_preamble_index; case BCODE_PUSH_INTLIT: - preamble_code = STIX_METHOD_PREAMBLE_RETURN_INDEX; + preamble_code = MOO_METHOD_PREAMBLE_RETURN_INDEX; goto set_preamble_index; case BCODE_PUSH_NEGINTLIT: - preamble_code = STIX_METHOD_PREAMBLE_RETURN_NEGINDEX; + preamble_code = MOO_METHOD_PREAMBLE_RETURN_NEGINDEX; goto set_preamble_index; set_preamble_index: preamble_index = 0; - for (i = 1; i <= STIX_BCODE_LONG_PARAM_SIZE; i++) + for (i = 1; i <= MOO_BCODE_LONG_PARAM_SIZE; i++) { - preamble_index = (preamble_index << 8) | stix->c->mth.code.ptr[i]; + preamble_index = (preamble_index << 8) | moo->c->mth.code.ptr[i]; } - if (!STIX_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(preamble_index)) + if (!MOO_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(preamble_index)) { /* the index got out of the range */ - preamble_code = STIX_METHOD_PREAMBLE_NONE; + preamble_code = MOO_METHOD_PREAMBLE_NONE; preamble_index = 0; } } } } } - else if (stix->c->mth.pftype == 1) + else if (moo->c->mth.pftype == 1) { - preamble_code = STIX_METHOD_PREAMBLE_PRIMITIVE; - preamble_index = stix->c->mth.pfnum; + preamble_code = MOO_METHOD_PREAMBLE_PRIMITIVE; + preamble_index = moo->c->mth.pfnum; } - else if (stix->c->mth.pftype == 2) + else if (moo->c->mth.pftype == 2) { - preamble_code = STIX_METHOD_PREAMBLE_NAMED_PRIMITIVE; - preamble_index = stix->c->mth.pfnum; /* index to literal frame */ + preamble_code = MOO_METHOD_PREAMBLE_NAMED_PRIMITIVE; + preamble_index = moo->c->mth.pfnum; /* index to literal frame */ } - else if (stix->c->mth.pftype == 3) + else if (moo->c->mth.pftype == 3) { - preamble_code = STIX_METHOD_PREAMBLE_EXCEPTION; + preamble_code = MOO_METHOD_PREAMBLE_EXCEPTION; preamble_index = 0; } else { - STIX_ASSERT (stix, stix->c->mth.pftype == 4); - preamble_code = STIX_METHOD_PREAMBLE_ENSURE; + MOO_ASSERT (moo, moo->c->mth.pftype == 4); + preamble_code = MOO_METHOD_PREAMBLE_ENSURE; preamble_index = 0; } - if (stix->c->mth.variadic /*&& stix->c->mth.tmpr_nargs > 0*/) - preamble_flags |= STIX_METHOD_PREAMBLE_FLAG_VARIADIC; + if (moo->c->mth.variadic /*&& moo->c->mth.tmpr_nargs > 0*/) + preamble_flags |= MOO_METHOD_PREAMBLE_FLAG_VARIADIC; - STIX_ASSERT (stix, STIX_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(preamble_index)); + MOO_ASSERT (moo, MOO_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(preamble_index)); - mth->owner = stix->c->cls.self_oop; + mth->owner = moo->c->cls.self_oop; mth->name = name; - mth->preamble = STIX_SMOOI_TO_OOP(STIX_METHOD_MAKE_PREAMBLE(preamble_code, preamble_index, preamble_flags)); - mth->preamble_data[0] = STIX_SMOOI_TO_OOP(0); - mth->preamble_data[1] = STIX_SMOOI_TO_OOP(0); - mth->tmpr_count = STIX_SMOOI_TO_OOP(stix->c->mth.tmpr_count); - mth->tmpr_nargs = STIX_SMOOI_TO_OOP(stix->c->mth.tmpr_nargs); + mth->preamble = MOO_SMOOI_TO_OOP(MOO_METHOD_MAKE_PREAMBLE(preamble_code, preamble_index, preamble_flags)); + mth->preamble_data[0] = MOO_SMOOI_TO_OOP(0); + mth->preamble_data[1] = MOO_SMOOI_TO_OOP(0); + mth->tmpr_count = MOO_SMOOI_TO_OOP(moo->c->mth.tmpr_count); + mth->tmpr_nargs = MOO_SMOOI_TO_OOP(moo->c->mth.tmpr_nargs); -#if defined(STIX_USE_OBJECT_TRAILER) +#if defined(MOO_USE_OBJECT_TRAILER) /* do nothing */ #else mth->code = code; #endif - /*TODO: preserve source??? mth->text = stix->c->mth.text + /*TODO: preserve source??? mth->text = moo->c->mth.text the compiler must collect all source method string collected so far. need to write code to collect string. */ -#if defined(STIX_DEBUG_COMPILER) - stix_decode (stix, mth, &stix->c->cls.fqn); +#if defined(MOO_DEBUG_COMPILER) + moo_decode (moo, mth, &moo->c->cls.fqn); #endif - stix_poptmps (stix, tmp_count); tmp_count = 0; + moo_poptmps (moo, tmp_count); tmp_count = 0; #ifdef MTHDIC - if (!stix_putatdic(stix, stix->c->cls.mthdic_oop[stix->c->mth.type], (stix_oop_t)name, (stix_oop_t)mth)) goto oops; + if (!moo_putatdic(moo, moo->c->cls.mthdic_oop[moo->c->mth.type], (moo_oop_t)name, (moo_oop_t)mth)) goto oops; #else - if (!stix_putatdic(stix, stix->c->cls.self_oop->mthdic[stix->c->mth.type], (stix_oop_t)name, (stix_oop_t)mth)) goto oops; + if (!moo_putatdic(moo, moo->c->cls.self_oop->mthdic[moo->c->mth.type], (moo_oop_t)name, (moo_oop_t)mth)) goto oops; #endif return 0; oops: - stix_poptmps (stix, tmp_count); + moo_poptmps (moo, tmp_count); return -1; } -static int compile_method_definition (stix_t* stix) +static int compile_method_definition (moo_t* moo) { /* clear data required to compile a method */ - stix->c->mth.type = STIX_METHOD_INSTANCE; - stix->c->mth.text.len = 0; - stix->c->mth.assignees.len = 0; - stix->c->mth.binsels.len = 0; - stix->c->mth.kwsels.len = 0; - stix->c->mth.name.len = 0; - STIX_MEMSET (&stix->c->mth.name_loc, 0, STIX_SIZEOF(stix->c->mth.name_loc)); - stix->c->mth.variadic = 0; - stix->c->mth.tmprs.len = 0; - stix->c->mth.tmpr_count = 0; - stix->c->mth.tmpr_nargs = 0; - stix->c->mth.literal_count = 0; - stix->c->mth.balit_count = 0; - stix->c->mth.arlit_count = 0; - stix->c->mth.pftype = 0; - stix->c->mth.pfnum = 0; - stix->c->mth.blk_depth = 0; - stix->c->mth.code.len = 0; + moo->c->mth.type = MOO_METHOD_INSTANCE; + moo->c->mth.text.len = 0; + moo->c->mth.assignees.len = 0; + moo->c->mth.binsels.len = 0; + moo->c->mth.kwsels.len = 0; + moo->c->mth.name.len = 0; + MOO_MEMSET (&moo->c->mth.name_loc, 0, MOO_SIZEOF(moo->c->mth.name_loc)); + moo->c->mth.variadic = 0; + moo->c->mth.tmprs.len = 0; + moo->c->mth.tmpr_count = 0; + moo->c->mth.tmpr_nargs = 0; + moo->c->mth.literal_count = 0; + moo->c->mth.balit_count = 0; + moo->c->mth.arlit_count = 0; + moo->c->mth.pftype = 0; + moo->c->mth.pfnum = 0; + moo->c->mth.blk_depth = 0; + moo->c->mth.code.len = 0; - if (TOKEN_TYPE(stix) == STIX_IOTOK_LPAREN) + if (TOKEN_TYPE(moo) == MOO_IOTOK_LPAREN) { /* process method modifiers */ - GET_TOKEN (stix); + GET_TOKEN (moo); - if (is_token_symbol(stix, VOCA_CLASS_S)) + if (is_token_symbol(moo, VOCA_CLASS_S)) { /* method(#class) */ - stix->c->mth.type = STIX_METHOD_CLASS; - GET_TOKEN (stix); + moo->c->mth.type = MOO_METHOD_CLASS; + GET_TOKEN (moo); } - if (TOKEN_TYPE(stix) != STIX_IOTOK_RPAREN) + if (TOKEN_TYPE(moo) != MOO_IOTOK_RPAREN) { /* ) expected */ - set_syntax_error (stix, STIX_SYNERR_RPAREN, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_RPAREN, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - GET_TOKEN (stix); + GET_TOKEN (moo); } - if (compile_method_name(stix) <= -1) return -1; + if (compile_method_name(moo) <= -1) return -1; - if (TOKEN_TYPE(stix) != STIX_IOTOK_LBRACE) + if (TOKEN_TYPE(moo) != MOO_IOTOK_LBRACE) { /* { expected */ - set_syntax_error (stix, STIX_SYNERR_LBRACE, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_LBRACE, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - GET_TOKEN (stix); + GET_TOKEN (moo); - if (compile_method_temporaries(stix) <= -1 || - compile_method_primitive(stix) <= -1 || - compile_method_statements(stix) <= -1) return -1; + if (compile_method_temporaries(moo) <= -1 || + compile_method_primitive(moo) <= -1 || + compile_method_statements(moo) <= -1) return -1; - if (TOKEN_TYPE(stix) != STIX_IOTOK_RBRACE) + if (TOKEN_TYPE(moo) != MOO_IOTOK_RBRACE) { /* } expected */ - set_syntax_error (stix, STIX_SYNERR_RBRACE, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_RBRACE, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - GET_TOKEN (stix); + GET_TOKEN (moo); /* add a compiled method to the method dictionary */ - if (add_compiled_method(stix) <= -1) return -1; + if (add_compiled_method(moo) <= -1) return -1; return 0; } -static int make_defined_class (stix_t* stix) +static int make_defined_class (moo_t* moo) { /* this function make a class object with no functions/methods */ - stix_oop_t tmp; - stix_oow_t spec, self_spec; + moo_oop_t tmp; + moo_oow_t spec, self_spec; int just_made = 0; - spec = STIX_CLASS_SPEC_MAKE (stix->c->cls.var_count[VAR_INSTANCE], - ((stix->c->cls.flags & CLASS_INDEXED)? 1: 0), - stix->c->cls.indexed_type); + spec = MOO_CLASS_SPEC_MAKE (moo->c->cls.var_count[VAR_INSTANCE], + ((moo->c->cls.flags & CLASS_INDEXED)? 1: 0), + moo->c->cls.indexed_type); - self_spec = STIX_CLASS_SELFSPEC_MAKE (stix->c->cls.var_count[VAR_CLASS], - stix->c->cls.var_count[VAR_CLASSINST]); + self_spec = MOO_CLASS_SELFSPEC_MAKE (moo->c->cls.var_count[VAR_CLASS], + moo->c->cls.var_count[VAR_CLASSINST]); - if (stix->c->cls.self_oop) + if (moo->c->cls.self_oop) { /* this is an internally created class object being defined. */ - STIX_ASSERT (stix, STIX_CLASSOF(stix, stix->c->cls.self_oop) == stix->_class); - STIX_ASSERT (stix, STIX_OBJ_GET_FLAGS_KERNEL (stix->c->cls.self_oop) == 1); + MOO_ASSERT (moo, MOO_CLASSOF(moo, moo->c->cls.self_oop) == moo->_class); + MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_KERNEL (moo->c->cls.self_oop) == 1); - if (spec != STIX_OOP_TO_SMOOI(stix->c->cls.self_oop->spec) || - self_spec != STIX_OOP_TO_SMOOI(stix->c->cls.self_oop->selfspec)) + if (spec != MOO_OOP_TO_SMOOI(moo->c->cls.self_oop->spec) || + self_spec != MOO_OOP_TO_SMOOI(moo->c->cls.self_oop->selfspec)) { /* it conflicts with internal definition */ - set_syntax_error (stix, STIX_SYNERR_CLASSCONTRA, &stix->c->cls.fqn_loc, &stix->c->cls.name); + set_syntax_error (moo, MOO_SYNERR_CLASSCONTRA, &moo->c->cls.fqn_loc, &moo->c->cls.name); return -1; } } @@ -4758,63 +4770,63 @@ static int make_defined_class (stix_t* stix) { /* the class variables and class instance variables are placed * inside the class object after the fixed part. */ - tmp = stix_instantiate (stix, stix->_class, STIX_NULL, - stix->c->cls.var_count[VAR_CLASSINST] + stix->c->cls.var_count[VAR_CLASS]); + tmp = moo_instantiate (moo, moo->_class, MOO_NULL, + moo->c->cls.var_count[VAR_CLASSINST] + moo->c->cls.var_count[VAR_CLASS]); if (!tmp) return -1; just_made = 1; - stix->c->cls.self_oop = (stix_oop_class_t)tmp; + moo->c->cls.self_oop = (moo_oop_class_t)tmp; - STIX_ASSERT (stix, STIX_CLASSOF(stix, stix->c->cls.self_oop) == stix->_class); + MOO_ASSERT (moo, MOO_CLASSOF(moo, moo->c->cls.self_oop) == moo->_class); - stix->c->cls.self_oop->spec = STIX_SMOOI_TO_OOP(spec); - stix->c->cls.self_oop->selfspec = STIX_SMOOI_TO_OOP(self_spec); + moo->c->cls.self_oop->spec = MOO_SMOOI_TO_OOP(spec); + moo->c->cls.self_oop->selfspec = MOO_SMOOI_TO_OOP(self_spec); } /* TODO: check if the current class definition conflicts with the superclass. * if superclass is byte variable, the current class cannot be word variable or something else. * TODO: TODO: TODO: */ - STIX_OBJ_SET_FLAGS_KERNEL (stix->c->cls.self_oop, 2); + MOO_OBJ_SET_FLAGS_KERNEL (moo->c->cls.self_oop, 2); - stix->c->cls.self_oop->superclass = stix->c->cls.super_oop; + moo->c->cls.self_oop->superclass = moo->c->cls.super_oop; - tmp = stix_makesymbol (stix, stix->c->cls.name.ptr, stix->c->cls.name.len); + tmp = moo_makesymbol (moo, moo->c->cls.name.ptr, moo->c->cls.name.len); if (!tmp) return -1; - stix->c->cls.self_oop->name = (stix_oop_char_t)tmp; + moo->c->cls.self_oop->name = (moo_oop_char_t)tmp; - tmp = stix_makestring (stix, stix->c->cls.vars[VAR_INSTANCE].ptr, stix->c->cls.vars[VAR_INSTANCE].len); + tmp = moo_makestring (moo, moo->c->cls.vars[VAR_INSTANCE].ptr, moo->c->cls.vars[VAR_INSTANCE].len); if (!tmp) return -1; - stix->c->cls.self_oop->instvars = (stix_oop_char_t)tmp; + moo->c->cls.self_oop->instvars = (moo_oop_char_t)tmp; - tmp = stix_makestring (stix, stix->c->cls.vars[VAR_CLASS].ptr, stix->c->cls.vars[VAR_CLASS].len); + tmp = moo_makestring (moo, moo->c->cls.vars[VAR_CLASS].ptr, moo->c->cls.vars[VAR_CLASS].len); if (!tmp) return -1; - stix->c->cls.self_oop->classvars = (stix_oop_char_t)tmp; + moo->c->cls.self_oop->classvars = (moo_oop_char_t)tmp; - tmp = stix_makestring (stix, stix->c->cls.vars[VAR_CLASSINST].ptr, stix->c->cls.vars[VAR_CLASSINST].len); + tmp = moo_makestring (moo, moo->c->cls.vars[VAR_CLASSINST].ptr, moo->c->cls.vars[VAR_CLASSINST].len); if (!tmp) return -1; - stix->c->cls.self_oop->classinstvars = (stix_oop_char_t)tmp; + moo->c->cls.self_oop->classinstvars = (moo_oop_char_t)tmp; - tmp = stix_makestring (stix, stix->c->cls.pooldic.ptr, stix->c->cls.pooldic.len); + tmp = moo_makestring (moo, moo->c->cls.pooldic.ptr, moo->c->cls.pooldic.len); if (!tmp) return -1; - stix->c->cls.self_oop->pooldics = (stix_oop_char_t)tmp; + moo->c->cls.self_oop->pooldics = (moo_oop_char_t)tmp; /* TOOD: good dictionary size */ - tmp = (stix_oop_t)stix_makedic (stix, stix->_method_dictionary, INSTANCE_METHOD_DICTIONARY_SIZE); + tmp = (moo_oop_t)moo_makedic (moo, moo->_method_dictionary, INSTANCE_METHOD_DICTIONARY_SIZE); if (!tmp) return -1; #ifdef MTHDIC - stix->c->cls.mthdic_oop[STIX_METHOD_INSTANCE] = (stix_oop_set_t)tmp; + moo->c->cls.mthdic_oop[MOO_METHOD_INSTANCE] = (moo_oop_set_t)tmp; #else - stix->c->cls.self_oop->mthdic[STIX_METHOD_INSTANCE] = (stix_oop_set_t)tmp; + moo->c->cls.self_oop->mthdic[MOO_METHOD_INSTANCE] = (moo_oop_set_t)tmp; #endif /* TOOD: good dictionary size */ - tmp = (stix_oop_t)stix_makedic (stix, stix->_method_dictionary, CLASS_METHOD_DICTIONARY_SIZE); + tmp = (moo_oop_t)moo_makedic (moo, moo->_method_dictionary, CLASS_METHOD_DICTIONARY_SIZE); if (!tmp) return -1; #ifdef MTHDIC - stix->c->cls.mthdic_oop[STIX_METHOD_CLASS] = (stix_oop_set_t)tmp; + moo->c->cls.mthdic_oop[MOO_METHOD_CLASS] = (moo_oop_set_t)tmp; #else - stix->c->cls.self_oop->mthdic[STIX_METHOD_CLASS] = (stix_oop_set_t)tmp; + moo->c->cls.self_oop->mthdic[MOO_METHOD_CLASS] = (moo_oop_set_t)tmp; #endif /* TODO: initialize more fields??? whatelse. */ @@ -4824,14 +4836,14 @@ static int make_defined_class (stix_t* stix) if (just_made) { /* register the class to the system dictionary */ - /*if (!stix_putatsysdic(stix, (stix_oop_t)stix->c->cls.self_oop->name, (stix_oop_t)stix->c->cls.self_oop)) return -1;*/ - if (!stix_putatdic(stix, stix->c->cls.ns_oop, (stix_oop_t)stix->c->cls.self_oop->name, (stix_oop_t)stix->c->cls.self_oop)) return -1; + /*if (!moo_putatsysdic(moo, (moo_oop_t)moo->c->cls.self_oop->name, (moo_oop_t)moo->c->cls.self_oop)) return -1;*/ + if (!moo_putatdic(moo, moo->c->cls.ns_oop, (moo_oop_t)moo->c->cls.self_oop->name, (moo_oop_t)moo->c->cls.self_oop)) return -1; } return 0; } -static int __compile_class_definition (stix_t* stix, int extend) +static int __compile_class_definition (moo_t* moo, int extend) { /* * class-definition := #class class-modifier? class-name (class-body | class-module-import) @@ -4850,224 +4862,224 @@ static int __compile_class_definition (stix_t* stix, int extend) * * NOTE: when extending a class, class-module-import and variable-definition are not allowed. */ - stix_oop_association_t ass; - stix_ooch_t modname[STIX_MOD_NAME_LEN_MAX + 1]; - stix_oow_t modnamelen = 0; + moo_oop_association_t ass; + moo_ooch_t modname[MOO_MOD_NAME_LEN_MAX + 1]; + moo_oow_t modnamelen = 0; - if (!extend && TOKEN_TYPE(stix) == STIX_IOTOK_LPAREN) + if (!extend && TOKEN_TYPE(moo) == MOO_IOTOK_LPAREN) { /* process class modifiers */ - GET_TOKEN (stix); + GET_TOKEN (moo); - if (is_token_symbol(stix, VOCA_BYTE_S)) + if (is_token_symbol(moo, VOCA_BYTE_S)) { /* class(#byte) */ - stix->c->cls.flags |= CLASS_INDEXED; - stix->c->cls.indexed_type = STIX_OBJ_TYPE_BYTE; - GET_TOKEN (stix); + moo->c->cls.flags |= CLASS_INDEXED; + moo->c->cls.indexed_type = MOO_OBJ_TYPE_BYTE; + GET_TOKEN (moo); } - else if (is_token_symbol(stix, VOCA_CHARACTER_S)) + else if (is_token_symbol(moo, VOCA_CHARACTER_S)) { /* class(#character) */ - stix->c->cls.flags |= CLASS_INDEXED; - stix->c->cls.indexed_type = STIX_OBJ_TYPE_CHAR; - GET_TOKEN (stix); + moo->c->cls.flags |= CLASS_INDEXED; + moo->c->cls.indexed_type = MOO_OBJ_TYPE_CHAR; + GET_TOKEN (moo); } - else if (is_token_symbol(stix, VOCA_HALFWORD_S)) + else if (is_token_symbol(moo, VOCA_HALFWORD_S)) { /* class(#halfword) */ - stix->c->cls.flags |= CLASS_INDEXED; - stix->c->cls.indexed_type = STIX_OBJ_TYPE_HALFWORD; - GET_TOKEN (stix); + moo->c->cls.flags |= CLASS_INDEXED; + moo->c->cls.indexed_type = MOO_OBJ_TYPE_HALFWORD; + GET_TOKEN (moo); } - else if (is_token_symbol(stix, VOCA_WORD_S)) + else if (is_token_symbol(moo, VOCA_WORD_S)) { /* class(#word) */ - stix->c->cls.flags |= CLASS_INDEXED; - stix->c->cls.indexed_type = STIX_OBJ_TYPE_WORD; - GET_TOKEN (stix); + moo->c->cls.flags |= CLASS_INDEXED; + moo->c->cls.indexed_type = MOO_OBJ_TYPE_WORD; + GET_TOKEN (moo); } - else if (is_token_symbol(stix, VOCA_POINTER_S)) + else if (is_token_symbol(moo, VOCA_POINTER_S)) { /* class(#pointer) */ - stix->c->cls.flags |= CLASS_INDEXED; - stix->c->cls.indexed_type = STIX_OBJ_TYPE_OOP; - GET_TOKEN (stix); + moo->c->cls.flags |= CLASS_INDEXED; + moo->c->cls.indexed_type = MOO_OBJ_TYPE_OOP; + GET_TOKEN (moo); } - else if (is_token_symbol(stix, VOCA_LIWORD_S)) + else if (is_token_symbol(moo, VOCA_LIWORD_S)) { /* class(#liword) */ - stix->c->cls.flags |= CLASS_INDEXED; - stix->c->cls.indexed_type = STIX_OBJ_TYPE_LIWORD; - GET_TOKEN (stix); + moo->c->cls.flags |= CLASS_INDEXED; + moo->c->cls.indexed_type = MOO_OBJ_TYPE_LIWORD; + GET_TOKEN (moo); } - if (TOKEN_TYPE(stix) != STIX_IOTOK_RPAREN) + if (TOKEN_TYPE(moo) != MOO_IOTOK_RPAREN) { - set_syntax_error (stix, STIX_SYNERR_RPAREN, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_RPAREN, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - GET_TOKEN (stix); + GET_TOKEN (moo); } - if (TOKEN_TYPE(stix) != STIX_IOTOK_IDENT && - TOKEN_TYPE(stix) != STIX_IOTOK_IDENT_DOTTED) + if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT && + TOKEN_TYPE(moo) != MOO_IOTOK_IDENT_DOTTED) { /* class name expected. */ - set_syntax_error (stix, STIX_SYNERR_IDENT, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_IDENT, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } #if 0 - if (TOKEN_TYPE(stix) == STIX_IOTOK_IDENT && is_restricted_word (TOKEN_NAME(stix))) + if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT && is_restricted_word (TOKEN_NAME(moo))) { /* wrong class name */ - set_syntax_error (stix, STIX_SYNERR_CLASSNAME, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_CLASSNAME, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } #endif /* copy the class name */ - if (set_class_fqn(stix, TOKEN_NAME(stix)) <= -1) return -1; - stix->c->cls.fqn_loc = stix->c->tok.loc; - if (TOKEN_TYPE(stix) == STIX_IOTOK_IDENT_DOTTED) + if (set_class_fqn(moo, TOKEN_NAME(moo)) <= -1) return -1; + moo->c->cls.fqn_loc = moo->c->tok.loc; + if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT_DOTTED) { - if (preprocess_dotted_name(stix, extend, 0, &stix->c->cls.fqn, &stix->c->cls.fqn_loc, &stix->c->cls.name, &stix->c->cls.ns_oop) <= -1) return -1; + if (preprocess_dotted_name(moo, extend, 0, &moo->c->cls.fqn, &moo->c->cls.fqn_loc, &moo->c->cls.name, &moo->c->cls.ns_oop) <= -1) return -1; } else { - stix->c->cls.ns_oop = stix->sysdic; + moo->c->cls.ns_oop = moo->sysdic; } - GET_TOKEN (stix); + GET_TOKEN (moo); if (extend) { /* extending class */ - STIX_ASSERT (stix, stix->c->cls.flags == 0); + MOO_ASSERT (moo, moo->c->cls.flags == 0); - /*ass = stix_lookupsysdic(stix, &stix->c->cls.name);*/ - ass = stix_lookupdic(stix, stix->c->cls.ns_oop, &stix->c->cls.name); + /*ass = moo_lookupsysdic(moo, &moo->c->cls.name);*/ + ass = moo_lookupdic(moo, moo->c->cls.ns_oop, &moo->c->cls.name); if (ass && - STIX_CLASSOF(stix, ass->value) == stix->_class && - STIX_OBJ_GET_FLAGS_KERNEL(ass->value) != 1) + MOO_CLASSOF(moo, ass->value) == moo->_class && + MOO_OBJ_GET_FLAGS_KERNEL(ass->value) != 1) { /* the value must be a class object. * and it must be either a user-defined(0) or * completed kernel built-in(2). * an incomplete kernel built-in class object(1) can not be * extended */ - stix->c->cls.self_oop = (stix_oop_class_t)ass->value; + moo->c->cls.self_oop = (moo_oop_class_t)ass->value; } else { /* only an existing class can be extended. */ - set_syntax_error (stix, STIX_SYNERR_CLASSUNDEF, &stix->c->cls.fqn_loc, &stix->c->cls.name); + set_syntax_error (moo, MOO_SYNERR_CLASSUNDEF, &moo->c->cls.fqn_loc, &moo->c->cls.name); return -1; } - stix->c->cls.super_oop = stix->c->cls.self_oop->superclass; + moo->c->cls.super_oop = moo->c->cls.self_oop->superclass; - STIX_ASSERT (stix, (stix_oop_t)stix->c->cls.super_oop == stix->_nil || - STIX_CLASSOF(stix, stix->c->cls.super_oop) == stix->_class); + MOO_ASSERT (moo, (moo_oop_t)moo->c->cls.super_oop == moo->_nil || + MOO_CLASSOF(moo, moo->c->cls.super_oop) == moo->_class); } else { int super_is_nil = 0; - STIX_INFO2 (stix, "Defining a class %.*js\n", stix->c->cls.fqn.len, stix->c->cls.fqn.ptr); + MOO_INFO2 (moo, "Defining a class %.*js\n", moo->c->cls.fqn.len, moo->c->cls.fqn.ptr); - if (TOKEN_TYPE(stix) == STIX_IOTOK_LPAREN) + if (TOKEN_TYPE(moo) == MOO_IOTOK_LPAREN) { /* superclass is specified. new class defintion. * for example, #class Class(Stix) */ - GET_TOKEN (stix); /* read superclass name */ + GET_TOKEN (moo); /* read superclass name */ /* TODO: multiple inheritance */ - if (TOKEN_TYPE(stix) == STIX_IOTOK_NIL) + if (TOKEN_TYPE(moo) == MOO_IOTOK_NIL) { super_is_nil = 1; } - else if (TOKEN_TYPE(stix) != STIX_IOTOK_IDENT && - TOKEN_TYPE(stix) != STIX_IOTOK_IDENT_DOTTED) + else if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT && + TOKEN_TYPE(moo) != MOO_IOTOK_IDENT_DOTTED) { /* superclass name expected */ - set_syntax_error (stix, STIX_SYNERR_IDENT, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_IDENT, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - if (set_superclass_fqn(stix, TOKEN_NAME(stix)) <= -1) return -1; - stix->c->cls.superfqn_loc = stix->c->tok.loc; + if (set_superclass_fqn(moo, TOKEN_NAME(moo)) <= -1) return -1; + moo->c->cls.superfqn_loc = moo->c->tok.loc; - if (TOKEN_TYPE(stix) == STIX_IOTOK_IDENT_DOTTED) + if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT_DOTTED) { - if (preprocess_dotted_name(stix, 1, 0, &stix->c->cls.superfqn, &stix->c->cls.superfqn_loc, &stix->c->cls.supername, &stix->c->cls.superns_oop) <= -1) return -1; + if (preprocess_dotted_name(moo, 1, 0, &moo->c->cls.superfqn, &moo->c->cls.superfqn_loc, &moo->c->cls.supername, &moo->c->cls.superns_oop) <= -1) return -1; } else { /* if no fully qualified name is specified for the super class name, * the name is searched in the name space that the class being defined - * belongs to first and in the 'stix->sysdic'. */ - stix->c->cls.superns_oop = stix->c->cls.ns_oop; + * belongs to first and in the 'moo->sysdic'. */ + moo->c->cls.superns_oop = moo->c->cls.ns_oop; } - GET_TOKEN (stix); - if (TOKEN_TYPE(stix) != STIX_IOTOK_RPAREN) + GET_TOKEN (moo); + if (TOKEN_TYPE(moo) != MOO_IOTOK_RPAREN) { - set_syntax_error (stix, STIX_SYNERR_RPAREN, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_RPAREN, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - GET_TOKEN (stix); + GET_TOKEN (moo); } else { super_is_nil = 1; } - /*ass = stix_lookupsysdic(stix, &stix->c->cls.name);*/ - ass = stix_lookupdic (stix, stix->c->cls.ns_oop, &stix->c->cls.name); + /*ass = moo_lookupsysdic(moo, &moo->c->cls.name);*/ + ass = moo_lookupdic (moo, moo->c->cls.ns_oop, &moo->c->cls.name); if (ass) { - if (STIX_CLASSOF(stix, ass->value) != stix->_class || - STIX_OBJ_GET_FLAGS_KERNEL(ass->value) > 1) + if (MOO_CLASSOF(moo, ass->value) != moo->_class || + MOO_OBJ_GET_FLAGS_KERNEL(ass->value) > 1) { /* the object found with the name is not a class object * or the the class object found is a fully defined kernel * class object */ - set_syntax_error (stix, STIX_SYNERR_CLASSDUP, &stix->c->cls.fqn_loc, &stix->c->cls.name); + set_syntax_error (moo, MOO_SYNERR_CLASSDUP, &moo->c->cls.fqn_loc, &moo->c->cls.name); return -1; } - stix->c->cls.self_oop = (stix_oop_class_t)ass->value; + moo->c->cls.self_oop = (moo_oop_class_t)ass->value; } else { /* no class of such a name is found. it's a new definition, * which is normal for most new classes. */ - STIX_ASSERT (stix, stix->c->cls.self_oop == STIX_NULL); + MOO_ASSERT (moo, moo->c->cls.self_oop == MOO_NULL); } if (super_is_nil) { - stix->c->cls.super_oop = stix->_nil; + moo->c->cls.super_oop = moo->_nil; } else { - /* ass = stix_lookupsysdic(stix, &stix->c->cls.supername); */ - ass = stix_lookupdic (stix, stix->c->cls.superns_oop, &stix->c->cls.supername); - if (!ass && stix->c->cls.superns_oop != stix->sysdic) - ass = stix_lookupdic (stix, stix->sysdic, &stix->c->cls.supername); + /* ass = moo_lookupsysdic(moo, &moo->c->cls.supername); */ + ass = moo_lookupdic (moo, moo->c->cls.superns_oop, &moo->c->cls.supername); + if (!ass && moo->c->cls.superns_oop != moo->sysdic) + ass = moo_lookupdic (moo, moo->sysdic, &moo->c->cls.supername); if (ass && - STIX_CLASSOF(stix, ass->value) == stix->_class && - STIX_OBJ_GET_FLAGS_KERNEL(ass->value) != 1) + MOO_CLASSOF(moo, ass->value) == moo->_class && + MOO_OBJ_GET_FLAGS_KERNEL(ass->value) != 1) { /* the value found must be a class and it must not be * an incomplete internal class object */ - stix->c->cls.super_oop = ass->value; + moo->c->cls.super_oop = ass->value; } else { @@ -5075,98 +5087,98 @@ static int __compile_class_definition (stix_t* stix, int extend) * the object found with the name is not a class object. or, * the class object found is a internally defined kernel * class object. */ - set_syntax_error (stix, STIX_SYNERR_CLASSUNDEF, &stix->c->cls.superfqn_loc, &stix->c->cls.superfqn); + set_syntax_error (moo, MOO_SYNERR_CLASSUNDEF, &moo->c->cls.superfqn_loc, &moo->c->cls.superfqn); return -1; } } - if (is_token_word (stix, VOCA_FROM)) + if (is_token_word (moo, VOCA_FROM)) { - GET_TOKEN (stix); - if (TOKEN_TYPE(stix) != STIX_IOTOK_STRLIT) + GET_TOKEN (moo); + if (TOKEN_TYPE(moo) != MOO_IOTOK_STRLIT) { - set_syntax_error (stix, STIX_SYNERR_STRING, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_STRING, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - if (TOKEN_NAME_LEN(stix) < 1 || - TOKEN_NAME_LEN(stix) > STIX_MOD_NAME_LEN_MAX || - stix_findoochar(TOKEN_NAME_PTR(stix), TOKEN_NAME_LEN(stix), '_')) + if (TOKEN_NAME_LEN(moo) < 1 || + TOKEN_NAME_LEN(moo) > MOO_MOD_NAME_LEN_MAX || + moo_findoochar(TOKEN_NAME_PTR(moo), TOKEN_NAME_LEN(moo), '_')) { - set_syntax_error (stix, STIX_SYNERR_MODNAME, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_MODNAME, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - modnamelen = TOKEN_NAME_LEN(stix); - stix_copyoochars (modname, TOKEN_NAME_PTR(stix), modnamelen); + modnamelen = TOKEN_NAME_LEN(moo); + moo_copyoochars (modname, TOKEN_NAME_PTR(moo), modnamelen); - GET_TOKEN (stix); + GET_TOKEN (moo); } } - if (TOKEN_TYPE(stix) != STIX_IOTOK_LBRACE) + if (TOKEN_TYPE(moo) != MOO_IOTOK_LBRACE) { - set_syntax_error (stix, STIX_SYNERR_LBRACE, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_LBRACE, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - if (stix->c->cls.super_oop != stix->_nil) + if (moo->c->cls.super_oop != moo->_nil) { /* adjust the instance variable count and the class instance variable * count to include that of a superclass */ - stix_oop_class_t c; - stix_oow_t spec, self_spec; + moo_oop_class_t c; + moo_oow_t spec, self_spec; - c = (stix_oop_class_t)stix->c->cls.super_oop; - spec = STIX_OOP_TO_SMOOI(c->spec); - self_spec = STIX_OOP_TO_SMOOI(c->selfspec); - stix->c->cls.var_count[VAR_INSTANCE] = STIX_CLASS_SPEC_NAMED_INSTVAR(spec); - stix->c->cls.var_count[VAR_CLASSINST] = STIX_CLASS_SELFSPEC_CLASSINSTVAR(self_spec); + c = (moo_oop_class_t)moo->c->cls.super_oop; + spec = MOO_OOP_TO_SMOOI(c->spec); + self_spec = MOO_OOP_TO_SMOOI(c->selfspec); + moo->c->cls.var_count[VAR_INSTANCE] = MOO_CLASS_SPEC_NAMED_INSTVAR(spec); + moo->c->cls.var_count[VAR_CLASSINST] = MOO_CLASS_SELFSPEC_CLASSINSTVAR(self_spec); } - GET_TOKEN (stix); + GET_TOKEN (moo); if (extend) { - stix_oop_char_t pds; + moo_oop_char_t pds; /* when a class is extended, a new variable cannot be added */ - if (is_token_word(stix, VOCA_DCL) || is_token_word(stix, VOCA_DECLARE)) + if (is_token_word(moo, VOCA_DCL) || is_token_word(moo, VOCA_DECLARE)) { - set_syntax_error (stix, STIX_SYNERR_DCLBANNED, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_DCLBANNED, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } #ifdef MTHDIC /* use the method dictionary of an existing class object */ - stix->c->cls.mthdic_oop[STIX_METHOD_INSTANCE] = stix->c->cls.self_oop->mthdic[STIX_METHOD_INSTANCE]; - stix->c->cls.mthdic_oop[STIX_METHOD_CLASS] = stix->c->cls.self_oop->mthdic[STIX_METHOD_CLASS]; + moo->c->cls.mthdic_oop[MOO_METHOD_INSTANCE] = moo->c->cls.self_oop->mthdic[MOO_METHOD_INSTANCE]; + moo->c->cls.mthdic_oop[MOO_METHOD_CLASS] = moo->c->cls.self_oop->mthdic[MOO_METHOD_CLASS]; #endif /* load the pooldic definition from the existing class object */ - pds = stix->c->cls.self_oop->pooldics; - if ((stix_oop_t)pds != stix->_nil) + pds = moo->c->cls.self_oop->pooldics; + if ((moo_oop_t)pds != moo->_nil) { - stix_ooch_t* ptr, * end; + moo_ooch_t* ptr, * end; - STIX_ASSERT (stix, STIX_CLASSOF(stix, pds) == stix->_string); + MOO_ASSERT (moo, MOO_CLASSOF(moo, pds) == moo->_string); ptr = pds->slot; - end = pds->slot + STIX_OBJ_GET_SIZE(pds); + end = pds->slot + MOO_OBJ_GET_SIZE(pds); /* this loop handles the pooldics string as if it's a pooldic import. * see compile_class_level_variables() for mostly identical code except token handling */ do { - stix_oocs_t last, tok; - stix_ioloc_t loc; + moo_oocs_t last, tok; + moo_ioloc_t loc; int dotted = 0; - stix_oop_set_t ns_oop; + moo_oop_set_t ns_oop; while (ptr < end && is_spacechar(*ptr)) ptr++; if (ptr >= end) break; - STIX_MEMSET (&loc, 0, STIX_SIZEOF(loc)); /* fake location */ + MOO_MEMSET (&loc, 0, MOO_SIZEOF(loc)); /* fake location */ tok.ptr = ptr; while (ptr < end && !is_spacechar(*ptr)) @@ -5175,20 +5187,20 @@ static int __compile_class_definition (stix_t* stix, int extend) ptr++; } tok.len = ptr - tok.ptr; - STIX_ASSERT (stix, tok.len > 0); + MOO_ASSERT (moo, tok.len > 0); if (dotted) { - if (preprocess_dotted_name(stix, 0, 0, &tok, &loc, &last, &ns_oop) <= -1) return -1; + if (preprocess_dotted_name(moo, 0, 0, &tok, &loc, &last, &ns_oop) <= -1) return -1; } else { last = tok; /* it falls back to the name space of the class */ - ns_oop = stix->c->cls.ns_oop; + ns_oop = moo->c->cls.ns_oop; } - if (import_pool_dictionary(stix, ns_oop, &last, &tok, &loc) <= -1) return -1; + if (import_pool_dictionary(moo, ns_oop, &last, &tok, &loc) <= -1) return -1; } while (1); } @@ -5197,31 +5209,31 @@ static int __compile_class_definition (stix_t* stix, int extend) { /* a new class including an internally defined class object */ - while (is_token_word(stix, VOCA_DCL) || is_token_word(stix, VOCA_DECLARE)) + while (is_token_word(moo, VOCA_DCL) || is_token_word(moo, VOCA_DECLARE)) { /* variable definition. dcl or declare */ - GET_TOKEN (stix); - if (compile_class_level_variables(stix) <= -1) return -1; + GET_TOKEN (moo); + if (compile_class_level_variables(moo) <= -1) return -1; } - if (make_defined_class(stix) <= -1) return -1; + if (make_defined_class(moo) <= -1) return -1; if (modnamelen > 0) { - if (stix_importmod (stix, (stix_oop_t)stix->c->cls.self_oop, modname, modnamelen) <= -1) return -1; + if (moo_importmod (moo, (moo_oop_t)moo->c->cls.self_oop, modname, modnamelen) <= -1) return -1; } } - while (is_token_word(stix, VOCA_METHOD)) + while (is_token_word(moo, VOCA_METHOD)) { /* method definition. method */ - GET_TOKEN (stix); - if (compile_method_definition(stix) <= -1) return -1; + GET_TOKEN (moo); + if (compile_method_definition(moo) <= -1) return -1; } - if (TOKEN_TYPE(stix) != STIX_IOTOK_RBRACE) + if (TOKEN_TYPE(moo) != MOO_IOTOK_RBRACE) { - set_syntax_error (stix, STIX_SYNERR_RBRACE, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_RBRACE, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } @@ -5230,300 +5242,300 @@ static int __compile_class_definition (stix_t* stix, int extend) { /* link the method dictionaries created to the actual class object */ /* TODO: anything else to set? */ - stix->c->cls.self_oop->mthdic[STIX_CLASS_MTHDIC_INSTANCE] = stix->c->cls.mthdic_oop[STIX_METHOD_INSTANCE]; - stix->c->cls.self_oop->mthdic[STIX_CLASS_MTHDIC_CLASS] = stix->c->cls.mthdic_oop[STIX_METHOD_CLASS]; + moo->c->cls.self_oop->mthdic[MOO_CLASS_MTHDIC_INSTANCE] = moo->c->cls.mthdic_oop[MOO_METHOD_INSTANCE]; + moo->c->cls.self_oop->mthdic[MOO_CLASS_MTHDIC_CLASS] = moo->c->cls.mthdic_oop[MOO_METHOD_CLASS]; } #endif - GET_TOKEN (stix); + GET_TOKEN (moo); return 0; } -static int compile_class_definition (stix_t* stix, int extend) +static int compile_class_definition (moo_t* moo, int extend) { int n; - stix_oow_t i; + moo_oow_t i; /* reset the structure to hold information about a class to be compiled */ - stix->c->cls.flags = 0; - stix->c->cls.indexed_type = STIX_OBJ_TYPE_OOP; + moo->c->cls.flags = 0; + moo->c->cls.indexed_type = MOO_OBJ_TYPE_OOP; - stix->c->cls.name.len = 0; - stix->c->cls.supername.len = 0; - STIX_MEMSET (&stix->c->cls.fqn_loc, 0, STIX_SIZEOF(stix->c->cls.fqn_loc)); - STIX_MEMSET (&stix->c->cls.superfqn_loc, 0, STIX_SIZEOF(stix->c->cls.superfqn_loc)); + moo->c->cls.name.len = 0; + moo->c->cls.supername.len = 0; + MOO_MEMSET (&moo->c->cls.fqn_loc, 0, MOO_SIZEOF(moo->c->cls.fqn_loc)); + MOO_MEMSET (&moo->c->cls.superfqn_loc, 0, MOO_SIZEOF(moo->c->cls.superfqn_loc)); - STIX_ASSERT (stix, STIX_COUNTOF(stix->c->cls.var_count) == STIX_COUNTOF(stix->c->cls.vars)); - for (i = 0; i < STIX_COUNTOF(stix->c->cls.var_count); i++) + MOO_ASSERT (moo, MOO_COUNTOF(moo->c->cls.var_count) == MOO_COUNTOF(moo->c->cls.vars)); + for (i = 0; i < MOO_COUNTOF(moo->c->cls.var_count); i++) { - stix->c->cls.var_count[i] = 0; - stix->c->cls.vars[i].len = 0; + moo->c->cls.var_count[i] = 0; + moo->c->cls.vars[i].len = 0; } - stix->c->cls.pooldic_count = 0; - stix->c->cls.pooldic.len = 0; + moo->c->cls.pooldic_count = 0; + moo->c->cls.pooldic.len = 0; - stix->c->cls.self_oop = STIX_NULL; - stix->c->cls.super_oop = STIX_NULL; + moo->c->cls.self_oop = MOO_NULL; + moo->c->cls.super_oop = MOO_NULL; #ifdef MTHDIC - stix->c->cls.mthdic_oop[STIX_METHOD_INSTANCE] = STIX_NULL; - stix->c->cls.mthdic_oop[STIX_METHOD_CLASS] = STIX_NULL; + moo->c->cls.mthdic_oop[MOO_METHOD_INSTANCE] = MOO_NULL; + moo->c->cls.mthdic_oop[MOO_METHOD_CLASS] = MOO_NULL; #endif - stix->c->cls.ns_oop = STIX_NULL; - stix->c->cls.superns_oop = STIX_NULL; - stix->c->mth.literal_count = 0; - stix->c->mth.balit_count = 0; - stix->c->mth.arlit_count = 0; + moo->c->cls.ns_oop = MOO_NULL; + moo->c->cls.superns_oop = MOO_NULL; + moo->c->mth.literal_count = 0; + moo->c->mth.balit_count = 0; + moo->c->mth.arlit_count = 0; /* do main compilation work */ - n = __compile_class_definition (stix, extend); + n = __compile_class_definition (moo, extend); /* reset these oops plus literal pointers not to confuse gc_compiler() */ - stix->c->cls.self_oop = STIX_NULL; - stix->c->cls.super_oop = STIX_NULL; + moo->c->cls.self_oop = MOO_NULL; + moo->c->cls.super_oop = MOO_NULL; #ifdef MTHDIC - stix->c->cls.mthdic_oop[STIX_METHOD_INSTANCE] = STIX_NULL; - stix->c->cls.mthdic_oop[STIX_METHOD_CLASS] = STIX_NULL; + moo->c->cls.mthdic_oop[MOO_METHOD_INSTANCE] = MOO_NULL; + moo->c->cls.mthdic_oop[MOO_METHOD_CLASS] = MOO_NULL; #endif - stix->c->cls.ns_oop = STIX_NULL; - stix->c->cls.superns_oop = STIX_NULL; - stix->c->mth.literal_count = 0; - stix->c->mth.balit_count = 0; - stix->c->mth.arlit_count = 0; + moo->c->cls.ns_oop = MOO_NULL; + moo->c->cls.superns_oop = MOO_NULL; + moo->c->mth.literal_count = 0; + moo->c->mth.balit_count = 0; + moo->c->mth.arlit_count = 0; - stix->c->cls.pooldic_count = 0; + moo->c->cls.pooldic_count = 0; return n; } -static int __compile_pooldic_definition (stix_t* stix) +static int __compile_pooldic_definition (moo_t* moo) { - stix_oop_t lit; - stix_ooi_t tally; - stix_oow_t i; + moo_oop_t lit; + moo_ooi_t tally; + moo_oow_t i; - if (TOKEN_TYPE(stix) != STIX_IOTOK_IDENT && - TOKEN_TYPE(stix) != STIX_IOTOK_IDENT_DOTTED) + if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT && + TOKEN_TYPE(moo) != MOO_IOTOK_IDENT_DOTTED) { - set_syntax_error (stix, STIX_SYNERR_IDENT, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_IDENT, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } /* [NOTE] - * reuse stix->c->cls.fqn and related fields are reused + * reuse moo->c->cls.fqn and related fields are reused * to store the pool dictionary name */ - if (set_class_fqn(stix, TOKEN_NAME(stix)) <= -1) return -1; - stix->c->cls.fqn_loc = stix->c->tok.loc; + if (set_class_fqn(moo, TOKEN_NAME(moo)) <= -1) return -1; + moo->c->cls.fqn_loc = moo->c->tok.loc; - if (TOKEN_TYPE(stix) == STIX_IOTOK_IDENT_DOTTED) + if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT_DOTTED) { - if (preprocess_dotted_name(stix, 0, 0, &stix->c->cls.fqn, &stix->c->cls.fqn_loc, &stix->c->cls.name, &stix->c->cls.ns_oop) <= -1) return -1; + if (preprocess_dotted_name(moo, 0, 0, &moo->c->cls.fqn, &moo->c->cls.fqn_loc, &moo->c->cls.name, &moo->c->cls.ns_oop) <= -1) return -1; } else { - stix->c->cls.ns_oop = stix->sysdic; + moo->c->cls.ns_oop = moo->sysdic; } - if (stix_lookupdic (stix, stix->c->cls.ns_oop, &stix->c->cls.name)) + if (moo_lookupdic (moo, moo->c->cls.ns_oop, &moo->c->cls.name)) { /* a conflicting entry has been found */ - set_syntax_error (stix, STIX_SYNERR_POOLDICDUP, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_POOLDICDUP, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - GET_TOKEN (stix); - if (TOKEN_TYPE(stix) != STIX_IOTOK_LBRACE) + GET_TOKEN (moo); + if (TOKEN_TYPE(moo) != MOO_IOTOK_LBRACE) { - set_syntax_error (stix, STIX_SYNERR_LBRACE, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_LBRACE, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - STIX_INFO2 (stix, "Defining a pool dictionary %.*js\n", stix->c->cls.fqn.len, stix->c->cls.fqn.ptr); + MOO_INFO2 (moo, "Defining a pool dictionary %.*js\n", moo->c->cls.fqn.len, moo->c->cls.fqn.ptr); - GET_TOKEN (stix); + GET_TOKEN (moo); - while (TOKEN_TYPE(stix) == STIX_IOTOK_SYMLIT) + while (TOKEN_TYPE(moo) == MOO_IOTOK_SYMLIT) { - lit = stix_makesymbol (stix, TOKEN_NAME_PTR(stix) + 1, TOKEN_NAME_LEN(stix) - 1); - if (!lit || add_to_array_literal_buffer (stix, lit) <= -1) return -1; + lit = moo_makesymbol (moo, TOKEN_NAME_PTR(moo) + 1, TOKEN_NAME_LEN(moo) - 1); + if (!lit || add_to_array_literal_buffer (moo, lit) <= -1) return -1; - GET_TOKEN (stix); + GET_TOKEN (moo); - if (TOKEN_TYPE(stix) != STIX_IOTOK_ASSIGN) + if (TOKEN_TYPE(moo) != MOO_IOTOK_ASSIGN) { - set_syntax_error (stix, STIX_SYNERR_ASSIGN, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_ASSIGN, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - GET_TOKEN (stix); + GET_TOKEN (moo); - switch (TOKEN_TYPE(stix)) + switch (TOKEN_TYPE(moo)) { - case STIX_IOTOK_NIL: - lit = stix->_nil; + case MOO_IOTOK_NIL: + lit = moo->_nil; goto add_literal; - case STIX_IOTOK_TRUE: - lit = stix->_true; + case MOO_IOTOK_TRUE: + lit = moo->_true; goto add_literal; - case STIX_IOTOK_FALSE: - lit = stix->_false; + case MOO_IOTOK_FALSE: + lit = moo->_false; goto add_literal; - case STIX_IOTOK_ERROR: - lit = STIX_ERROR_TO_OOP(STIX_EGENERIC); + case MOO_IOTOK_ERROR: + lit = MOO_ERROR_TO_OOP(MOO_EGENERIC); goto add_literal; - case STIX_IOTOK_ERRLIT: - lit = string_to_error (stix, TOKEN_NAME(stix)); + case MOO_IOTOK_ERRLIT: + lit = string_to_error (moo, TOKEN_NAME(moo)); goto add_literal; - case STIX_IOTOK_CHARLIT: - STIX_ASSERT (stix, TOKEN_NAME_LEN(stix) == 1); - lit = STIX_CHAR_TO_OOP(TOKEN_NAME_PTR(stix)[0]); + case MOO_IOTOK_CHARLIT: + MOO_ASSERT (moo, TOKEN_NAME_LEN(moo) == 1); + lit = MOO_CHAR_TO_OOP(TOKEN_NAME_PTR(moo)[0]); goto add_literal; - case STIX_IOTOK_STRLIT: - lit = stix_instantiate (stix, stix->_string, TOKEN_NAME_PTR(stix), TOKEN_NAME_LEN(stix)); + case MOO_IOTOK_STRLIT: + lit = moo_instantiate (moo, moo->_string, TOKEN_NAME_PTR(moo), TOKEN_NAME_LEN(moo)); if (!lit) return -1; goto add_literal; - case STIX_IOTOK_SYMLIT: - lit = stix_makesymbol (stix, TOKEN_NAME_PTR(stix) + 1, TOKEN_NAME_LEN(stix) - 1); + case MOO_IOTOK_SYMLIT: + lit = moo_makesymbol (moo, TOKEN_NAME_PTR(moo) + 1, TOKEN_NAME_LEN(moo) - 1); if (!lit) return -1; goto add_literal; - case STIX_IOTOK_NUMLIT: - case STIX_IOTOK_RADNUMLIT: - lit = string_to_num (stix, TOKEN_NAME(stix), TOKEN_TYPE(stix) == STIX_IOTOK_RADNUMLIT); + case MOO_IOTOK_NUMLIT: + case MOO_IOTOK_RADNUMLIT: + lit = string_to_num (moo, TOKEN_NAME(moo), TOKEN_TYPE(moo) == MOO_IOTOK_RADNUMLIT); if (!lit) return -1; goto add_literal; - case STIX_IOTOK_BAPAREN: /* #[ - byte array parenthesis */ - if (read_byte_array_literal(stix, &lit) <= -1) return -1; + case MOO_IOTOK_BAPAREN: /* #[ - byte array parenthesis */ + if (read_byte_array_literal(moo, &lit) <= -1) return -1; goto add_literal; - case STIX_IOTOK_ARPAREN: /* #( - array parenthesis */ - if (read_array_literal(stix, &lit) <= -1) return -1; + case MOO_IOTOK_ARPAREN: /* #( - array parenthesis */ + if (read_array_literal(moo, &lit) <= -1) return -1; goto add_literal; add_literal: /* * for this definition, #pooldic MyPoolDic { #a := 10. #b := 20 }, * arlit_buffer contains (#a 10 #b 20) when the 'while' loop is over. */ - if (add_to_array_literal_buffer(stix, lit) <= -1) return -1; - GET_TOKEN (stix); + if (add_to_array_literal_buffer(moo, lit) <= -1) return -1; + GET_TOKEN (moo); break; default: - set_syntax_error (stix, STIX_SYNERR_LITERAL, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_LITERAL, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - /*if (TOKEN_TYPE(stix) == STIX_IOTOK_RBRACE) goto done; - else*/ if (TOKEN_TYPE(stix) != STIX_IOTOK_PERIOD) + /*if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACE) goto done; + else*/ if (TOKEN_TYPE(moo) != MOO_IOTOK_PERIOD) { - set_syntax_error (stix, STIX_SYNERR_PERIOD, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_PERIOD, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - GET_TOKEN (stix); + GET_TOKEN (moo); } - if (TOKEN_TYPE(stix) != STIX_IOTOK_RBRACE) + if (TOKEN_TYPE(moo) != MOO_IOTOK_RBRACE) { - set_syntax_error (stix, STIX_SYNERR_RBRACE, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_RBRACE, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } /*done:*/ - GET_TOKEN (stix); + GET_TOKEN (moo); - tally = stix->c->mth.arlit_count / 2; + tally = moo->c->mth.arlit_count / 2; /*TODO: tally and arlit_count range check */ - /*if (!STIX_IN_SMOOI_RANGE(tally)) ERROR??*/ + /*if (!MOO_IN_SMOOI_RANGE(tally)) ERROR??*/ /* i use mthdic_oop[0] when compling #pooldic. it's not a real method dictionary. * i just use it not to declare another field into the compiler */ - stix->c->cls.pooldic_oop = stix_makedic (stix, stix->_pool_dictionary, STIX_ALIGN(tally + 10, POOL_DICTIONARY_SIZE_ALIGN)); - if (!stix->c->cls.pooldic_oop) return -1; + moo->c->cls.pooldic_oop = moo_makedic (moo, moo->_pool_dictionary, MOO_ALIGN(tally + 10, POOL_DICTIONARY_SIZE_ALIGN)); + if (!moo->c->cls.pooldic_oop) return -1; - for (i = 0; i < stix->c->mth.arlit_count; i += 2) + for (i = 0; i < moo->c->mth.arlit_count; i += 2) { /* TODO: handle duplicate keys? */ - if (!stix_putatdic(stix, stix->c->cls.pooldic_oop, stix->c->mth.arlit[i], stix->c->mth.arlit[i + 1])) return -1; + if (!moo_putatdic(moo, moo->c->cls.pooldic_oop, moo->c->mth.arlit[i], moo->c->mth.arlit[i + 1])) return -1; } /* eveything seems ok. register the pool dictionary to the main * system dictionary or to the name space it belongs to */ - lit = stix_makesymbol (stix, stix->c->cls.name.ptr, stix->c->cls.name.len); - if (!lit || !stix_putatdic (stix, stix->c->cls.ns_oop, lit, (stix_oop_t)stix->c->cls.pooldic_oop)) return -1; + lit = moo_makesymbol (moo, moo->c->cls.name.ptr, moo->c->cls.name.len); + if (!lit || !moo_putatdic (moo, moo->c->cls.ns_oop, lit, (moo_oop_t)moo->c->cls.pooldic_oop)) return -1; return 0; } -static int compile_pooldic_definition (stix_t* stix) +static int compile_pooldic_definition (moo_t* moo) { int n; /* reset the structure to hold information about a pool dictionary to be compiled. * i'll be reusing some fields reserved for compling a class */ - stix->c->cls.name.len = 0; - STIX_MEMSET (&stix->c->cls.fqn_loc, 0, STIX_SIZEOF(stix->c->cls.fqn_loc)); - stix->c->cls.pooldic_oop = STIX_NULL; - stix->c->cls.ns_oop = STIX_NULL; - stix->c->mth.balit_count = 0; - stix->c->mth.arlit_count = 0; + moo->c->cls.name.len = 0; + MOO_MEMSET (&moo->c->cls.fqn_loc, 0, MOO_SIZEOF(moo->c->cls.fqn_loc)); + moo->c->cls.pooldic_oop = MOO_NULL; + moo->c->cls.ns_oop = MOO_NULL; + moo->c->mth.balit_count = 0; + moo->c->mth.arlit_count = 0; - n = __compile_pooldic_definition (stix); + n = __compile_pooldic_definition (moo); /* reset these oops plus literal pointers not to confuse gc_compiler() */ - stix->c->cls.pooldic_oop = STIX_NULL; - stix->c->cls.ns_oop = STIX_NULL; - stix->c->mth.balit_count = 0; - stix->c->mth.arlit_count = 0; + moo->c->cls.pooldic_oop = MOO_NULL; + moo->c->cls.ns_oop = MOO_NULL; + moo->c->mth.balit_count = 0; + moo->c->mth.arlit_count = 0; return n; } -static int compile_stream (stix_t* stix) +static int compile_stream (moo_t* moo) { - GET_TOKEN (stix); + GET_TOKEN (moo); - while (TOKEN_TYPE(stix) != STIX_IOTOK_EOF) + while (TOKEN_TYPE(moo) != MOO_IOTOK_EOF) { - if (is_token_symbol(stix, VOCA_INCLUDE_S)) + if (is_token_symbol(moo, VOCA_INCLUDE_S)) { /* #include 'xxxx' */ - GET_TOKEN (stix); - if (TOKEN_TYPE(stix) != STIX_IOTOK_STRLIT) + GET_TOKEN (moo); + if (TOKEN_TYPE(moo) != MOO_IOTOK_STRLIT) { - set_syntax_error (stix, STIX_SYNERR_STRING, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error (moo, MOO_SYNERR_STRING, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } - if (begin_include(stix) <= -1) return -1; + if (begin_include(moo) <= -1) return -1; } - else if (is_token_word(stix, VOCA_CLASS)) + else if (is_token_word(moo, VOCA_CLASS)) { /* class Selfclass(Superclass) { } */ - GET_TOKEN (stix); - if (compile_class_definition(stix, 0) <= -1) return -1; + GET_TOKEN (moo); + if (compile_class_definition(moo, 0) <= -1) return -1; } - else if (is_token_word(stix, VOCA_EXTEND)) + else if (is_token_word(moo, VOCA_EXTEND)) { /* extend Selfclass {} */ - GET_TOKEN (stix); - if (compile_class_definition(stix, 1) <= -1) return -1; + GET_TOKEN (moo); + if (compile_class_definition(moo, 1) <= -1) return -1; } - else if (is_token_word(stix, VOCA_POOLDIC)) + else if (is_token_word(moo, VOCA_POOLDIC)) { /* pooldic SharedPoolDic { #ABC := 20. #DEFG := 'ayz' } */ - GET_TOKEN (stix); - if (compile_pooldic_definition(stix) <= -1) return -1; + GET_TOKEN (moo); + if (compile_pooldic_definition(moo) <= -1) return -1; } #if 0 - else if (is_token_symbol(stix, VOCA_MAIN)) + else if (is_token_symbol(moo, VOCA_MAIN)) { /* #main */ /* TODO: implement this */ @@ -5532,7 +5544,7 @@ static int compile_stream (stix_t* stix) #endif else { - set_syntax_error(stix, STIX_SYNERR_DIRECTIVE, TOKEN_LOC(stix), TOKEN_NAME(stix)); + set_syntax_error(moo, MOO_SYNERR_DIRECTIVE, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; } } @@ -5540,151 +5552,151 @@ static int compile_stream (stix_t* stix) return 0; } -static void gc_compiler (stix_t* stix) +static void gc_compiler (moo_t* moo) { /* called when garbage collection is performed */ - if (stix->c) + if (moo->c) { - stix_oow_t i; + moo_oow_t i; - if (stix->c->cls.self_oop) - stix->c->cls.self_oop = (stix_oop_class_t)stix_moveoop (stix, (stix_oop_t)stix->c->cls.self_oop); + if (moo->c->cls.self_oop) + moo->c->cls.self_oop = (moo_oop_class_t)moo_moveoop (moo, (moo_oop_t)moo->c->cls.self_oop); - if (stix->c->cls.super_oop) - stix->c->cls.super_oop = stix_moveoop (stix, stix->c->cls.super_oop); + if (moo->c->cls.super_oop) + moo->c->cls.super_oop = moo_moveoop (moo, moo->c->cls.super_oop); #ifdef MTHDIC - if (stix->c->cls.mthdic_oop[STIX_METHOD_INSTANCE]) - stix->c->cls.mthdic_oop[STIX_METHOD_INSTANCE] = (stix_oop_set_t)stix_moveoop (stix, (stix_oop_t)stix->c->cls.mthdic_oop[STIX_METHOD_INSTANCE]); + if (moo->c->cls.mthdic_oop[MOO_METHOD_INSTANCE]) + moo->c->cls.mthdic_oop[MOO_METHOD_INSTANCE] = (moo_oop_set_t)moo_moveoop (moo, (moo_oop_t)moo->c->cls.mthdic_oop[MOO_METHOD_INSTANCE]); - if (stix->c->cls.mthdic_oop[STIX_METHOD_CLASS]) - stix->c->cls.mthdic_oop[STIX_METHOD_CLASS] = (stix_oop_set_t)stix_moveoop (stix, (stix_oop_t)stix->c->cls.mthdic_oop[STIX_METHOD_CLASS]); + if (moo->c->cls.mthdic_oop[MOO_METHOD_CLASS]) + moo->c->cls.mthdic_oop[MOO_METHOD_CLASS] = (moo_oop_set_t)moo_moveoop (moo, (moo_oop_t)moo->c->cls.mthdic_oop[MOO_METHOD_CLASS]); #endif - if (stix->c->cls.pooldic_oop) - stix->c->cls.pooldic_oop = (stix_oop_set_t)stix_moveoop (stix, (stix_oop_t)stix->c->cls.pooldic_oop); + if (moo->c->cls.pooldic_oop) + moo->c->cls.pooldic_oop = (moo_oop_set_t)moo_moveoop (moo, (moo_oop_t)moo->c->cls.pooldic_oop); - if (stix->c->cls.ns_oop) - stix->c->cls.ns_oop = (stix_oop_set_t)stix_moveoop (stix, (stix_oop_t)stix->c->cls.ns_oop); + if (moo->c->cls.ns_oop) + moo->c->cls.ns_oop = (moo_oop_set_t)moo_moveoop (moo, (moo_oop_t)moo->c->cls.ns_oop); - if (stix->c->cls.superns_oop) - stix->c->cls.superns_oop = (stix_oop_set_t)stix_moveoop (stix, (stix_oop_t)stix->c->cls.superns_oop); + if (moo->c->cls.superns_oop) + moo->c->cls.superns_oop = (moo_oop_set_t)moo_moveoop (moo, (moo_oop_t)moo->c->cls.superns_oop); - for (i = 0; i < stix->c->cls.pooldic_count; i++) + for (i = 0; i < moo->c->cls.pooldic_count; i++) { - stix->c->cls.pooldic_imp_oops[i] = (stix_oop_set_t)stix_moveoop (stix, (stix_oop_t)stix->c->cls.pooldic_imp_oops[i]); + moo->c->cls.pooldic_imp_oops[i] = (moo_oop_set_t)moo_moveoop (moo, (moo_oop_t)moo->c->cls.pooldic_imp_oops[i]); } - for (i = 0; i < stix->c->mth.literal_count; i++) + for (i = 0; i < moo->c->mth.literal_count; i++) { - stix->c->mth.literals[i] = stix_moveoop (stix, stix->c->mth.literals[i]); + moo->c->mth.literals[i] = moo_moveoop (moo, moo->c->mth.literals[i]); } - for (i = 0; i < stix->c->mth.arlit_count; i++) + for (i = 0; i < moo->c->mth.arlit_count; i++) { - stix->c->mth.arlit[i] = stix_moveoop (stix, stix->c->mth.arlit[i]); + moo->c->mth.arlit[i] = moo_moveoop (moo, moo->c->mth.arlit[i]); } } } -static void fini_compiler (stix_t* stix) +static void fini_compiler (moo_t* moo) { - /* called before the stix object is closed */ - if (stix->c) + /* called before the moo object is closed */ + if (moo->c) { - stix_oow_t i; + moo_oow_t i; - clear_io_names (stix); + clear_io_names (moo); - if (stix->c->tok.name.ptr) stix_freemem (stix, stix->c->tok.name.ptr); - if (stix->c->cls.fqn.ptr) stix_freemem (stix, stix->c->cls.fqn.ptr); - if (stix->c->cls.superfqn.ptr) stix_freemem (stix, stix->c->cls.superfqn.ptr); + if (moo->c->tok.name.ptr) moo_freemem (moo, moo->c->tok.name.ptr); + if (moo->c->cls.fqn.ptr) moo_freemem (moo, moo->c->cls.fqn.ptr); + if (moo->c->cls.superfqn.ptr) moo_freemem (moo, moo->c->cls.superfqn.ptr); - for (i = 0; i < STIX_COUNTOF(stix->c->cls.vars); i++) + for (i = 0; i < MOO_COUNTOF(moo->c->cls.vars); i++) { - if (stix->c->cls.vars[i].ptr) stix_freemem (stix, stix->c->cls.vars[i].ptr); + if (moo->c->cls.vars[i].ptr) moo_freemem (moo, moo->c->cls.vars[i].ptr); } - if (stix->c->cls.pooldic.ptr) stix_freemem (stix, stix->c->cls.pooldic.ptr); - if (stix->c->cls.pooldic_imp_oops) stix_freemem (stix, stix->c->cls.pooldic_imp_oops); + if (moo->c->cls.pooldic.ptr) moo_freemem (moo, moo->c->cls.pooldic.ptr); + if (moo->c->cls.pooldic_imp_oops) moo_freemem (moo, moo->c->cls.pooldic_imp_oops); - if (stix->c->mth.text.ptr) stix_freemem (stix, stix->c->mth.text.ptr); - if (stix->c->mth.assignees.ptr) stix_freemem (stix, stix->c->mth.assignees.ptr); - if (stix->c->mth.binsels.ptr) stix_freemem (stix, stix->c->mth.binsels.ptr); - if (stix->c->mth.kwsels.ptr) stix_freemem (stix, stix->c->mth.kwsels.ptr); - if (stix->c->mth.name.ptr) stix_freemem (stix, stix->c->mth.name.ptr); - if (stix->c->mth.tmprs.ptr) stix_freemem (stix, stix->c->mth.tmprs.ptr); - if (stix->c->mth.code.ptr) stix_freemem (stix, stix->c->mth.code.ptr); - if (stix->c->mth.literals) stix_freemem (stix, stix->c->mth.literals); - if (stix->c->mth.balit) stix_freemem (stix, stix->c->mth.balit); - if (stix->c->mth.arlit) stix_freemem (stix, stix->c->mth.arlit); - if (stix->c->mth.blk_tmprcnt) stix_freemem (stix, stix->c->mth.blk_tmprcnt); + if (moo->c->mth.text.ptr) moo_freemem (moo, moo->c->mth.text.ptr); + if (moo->c->mth.assignees.ptr) moo_freemem (moo, moo->c->mth.assignees.ptr); + if (moo->c->mth.binsels.ptr) moo_freemem (moo, moo->c->mth.binsels.ptr); + if (moo->c->mth.kwsels.ptr) moo_freemem (moo, moo->c->mth.kwsels.ptr); + if (moo->c->mth.name.ptr) moo_freemem (moo, moo->c->mth.name.ptr); + if (moo->c->mth.tmprs.ptr) moo_freemem (moo, moo->c->mth.tmprs.ptr); + if (moo->c->mth.code.ptr) moo_freemem (moo, moo->c->mth.code.ptr); + if (moo->c->mth.literals) moo_freemem (moo, moo->c->mth.literals); + if (moo->c->mth.balit) moo_freemem (moo, moo->c->mth.balit); + if (moo->c->mth.arlit) moo_freemem (moo, moo->c->mth.arlit); + if (moo->c->mth.blk_tmprcnt) moo_freemem (moo, moo->c->mth.blk_tmprcnt); - stix_freemem (stix, stix->c); - stix->c = STIX_NULL; + moo_freemem (moo, moo->c); + moo->c = MOO_NULL; } } -int stix_compile (stix_t* stix, stix_ioimpl_t io) +int moo_compile (moo_t* moo, moo_ioimpl_t io) { int n; if (!io) { - stix->errnum = STIX_EINVAL; + moo->errnum = MOO_EINVAL; return -1; } - if (!stix->c) + if (!moo->c) { - stix_cb_t cb, * cbp; + moo_cb_t cb, * cbp; - STIX_MEMSET (&cb, 0, STIX_SIZEOF(cb)); + MOO_MEMSET (&cb, 0, MOO_SIZEOF(cb)); cb.gc = gc_compiler; cb.fini = fini_compiler; - cbp = stix_regcb (stix, &cb); + cbp = moo_regcb (moo, &cb); if (!cbp) return -1; - stix->c = stix_callocmem (stix, STIX_SIZEOF(*stix->c)); - if (!stix->c) + moo->c = moo_callocmem (moo, MOO_SIZEOF(*moo->c)); + if (!moo->c) { - stix_deregcb (stix, cbp); + moo_deregcb (moo, cbp); return -1; } - stix->c->ilchr_ucs.ptr = &stix->c->ilchr; - stix->c->ilchr_ucs.len = 1; + moo->c->ilchr_ucs.ptr = &moo->c->ilchr; + moo->c->ilchr_ucs.len = 1; } /* Some IO names could have been stored in earlier calls to this function. * I clear such names before i begin this function. i don't clear it * at the end of this function because i may be referenced as an error * location */ - clear_io_names (stix); + clear_io_names (moo); /* initialize some key fields */ - stix->c->impl = io; - stix->c->nungots = 0; + moo->c->impl = io; + moo->c->nungots = 0; - /* The name field and the includer field are STIX_NULL + /* The name field and the includer field are MOO_NULL * for the main stream */ - STIX_MEMSET (&stix->c->arg, 0, STIX_SIZEOF(stix->c->arg)); - stix->c->arg.line = 1; - stix->c->arg.colm = 1; + MOO_MEMSET (&moo->c->arg, 0, MOO_SIZEOF(moo->c->arg)); + moo->c->arg.line = 1; + moo->c->arg.colm = 1; /* open the top-level stream */ - n = stix->c->impl (stix, STIX_IO_OPEN, &stix->c->arg); + n = moo->c->impl (moo, MOO_IO_OPEN, &moo->c->arg); if (n <= -1) return -1; /* the stream is open. set it as the current input stream */ - stix->c->curinp = &stix->c->arg; + moo->c->curinp = &moo->c->arg; /* compile the contents of the stream */ - if (compile_stream (stix) <= -1) goto oops; + if (compile_stream (moo) <= -1) goto oops; /* close the stream */ - STIX_ASSERT (stix, stix->c->curinp == &stix->c->arg); - stix->c->impl (stix, STIX_IO_CLOSE, stix->c->curinp); + MOO_ASSERT (moo, moo->c->curinp == &moo->c->arg); + moo->c->impl (moo, MOO_IO_CLOSE, moo->c->curinp); return 0; @@ -5692,25 +5704,25 @@ oops: /* an error occurred and control has reached here * probably, some included files might not have been * closed. close them */ - while (stix->c->curinp != &stix->c->arg) + while (moo->c->curinp != &moo->c->arg) { - stix_ioarg_t* prev; + moo_ioarg_t* prev; /* nothing much to do about a close error */ - stix->c->impl (stix, STIX_IO_CLOSE, stix->c->curinp); + moo->c->impl (moo, MOO_IO_CLOSE, moo->c->curinp); - prev = stix->c->curinp->includer; - STIX_ASSERT (stix, stix->c->curinp->name != STIX_NULL); - STIX_MMGR_FREE (stix->mmgr, stix->c->curinp); - stix->c->curinp = prev; + prev = moo->c->curinp->includer; + MOO_ASSERT (moo, moo->c->curinp->name != MOO_NULL); + MOO_MMGR_FREE (moo->mmgr, moo->c->curinp); + moo->c->curinp = prev; } - stix->c->impl (stix, STIX_IO_CLOSE, stix->c->curinp); + moo->c->impl (moo, MOO_IO_CLOSE, moo->c->curinp); return -1; } -void stix_getsynerr (stix_t* stix, stix_synerr_t* synerr) +void moo_getsynerr (moo_t* moo, moo_synerr_t* synerr) { - STIX_ASSERT (stix, stix->c != STIX_NULL); - if (synerr) *synerr = stix->c->synerr; + MOO_ASSERT (moo, moo->c != MOO_NULL); + if (synerr) *synerr = moo->c->synerr; } diff --git a/stix/lib/debug.c b/stix/lib/debug.c index a012163..2d3399b 100644 --- a/stix/lib/debug.c +++ b/stix/lib/debug.c @@ -24,47 +24,47 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "stix-prv.h" +#include "moo-prv.h" -void stix_dumpsymtab (stix_t* stix) +void moo_dumpsymtab (moo_t* moo) { - stix_oow_t i; - stix_oop_char_t symbol; + moo_oow_t i; + moo_oop_char_t symbol; - STIX_DEBUG0 (stix, "--------------------------------------------\n"); - STIX_DEBUG1 (stix, "Stix Symbol Table %zu\n", STIX_OBJ_GET_SIZE(stix->symtab->bucket)); - STIX_DEBUG0 (stix, "--------------------------------------------\n"); + MOO_DEBUG0 (moo, "--------------------------------------------\n"); + MOO_DEBUG1 (moo, "Stix Symbol Table %zu\n", MOO_OBJ_GET_SIZE(moo->symtab->bucket)); + MOO_DEBUG0 (moo, "--------------------------------------------\n"); - for (i = 0; i < STIX_OBJ_GET_SIZE(stix->symtab->bucket); i++) + for (i = 0; i < MOO_OBJ_GET_SIZE(moo->symtab->bucket); i++) { - symbol = (stix_oop_char_t)stix->symtab->bucket->slot[i]; - if ((stix_oop_t)symbol != stix->_nil) + symbol = (moo_oop_char_t)moo->symtab->bucket->slot[i]; + if ((moo_oop_t)symbol != moo->_nil) { - STIX_DEBUG2 (stix, " %07zu %O\n", i, symbol); + MOO_DEBUG2 (moo, " %07zu %O\n", i, symbol); } } - STIX_DEBUG0 (stix, "--------------------------------------------\n"); + MOO_DEBUG0 (moo, "--------------------------------------------\n"); } -void stix_dumpdic (stix_t* stix, stix_oop_set_t dic, const stix_bch_t* title) +void moo_dumpdic (moo_t* moo, moo_oop_set_t dic, const moo_bch_t* title) { - stix_oow_t i, j; - stix_oop_association_t ass; + moo_oow_t i, j; + moo_oop_association_t ass; - STIX_DEBUG0 (stix, "--------------------------------------------\n"); - STIX_DEBUG2 (stix, "%s %zu\n", title, STIX_OBJ_GET_SIZE(dic->bucket)); - STIX_DEBUG0 (stix, "--------------------------------------------\n"); + MOO_DEBUG0 (moo, "--------------------------------------------\n"); + MOO_DEBUG2 (moo, "%s %zu\n", title, MOO_OBJ_GET_SIZE(dic->bucket)); + MOO_DEBUG0 (moo, "--------------------------------------------\n"); - for (i = 0; i < STIX_OBJ_GET_SIZE(dic->bucket); i++) + for (i = 0; i < MOO_OBJ_GET_SIZE(dic->bucket); i++) { - ass = (stix_oop_association_t)dic->bucket->slot[i]; - if ((stix_oop_t)ass != stix->_nil) + ass = (moo_oop_association_t)dic->bucket->slot[i]; + if ((moo_oop_t)ass != moo->_nil) { - STIX_DEBUG2 (stix, " %07zu %O\n", i, ass->key); + MOO_DEBUG2 (moo, " %07zu %O\n", i, ass->key); } } - STIX_DEBUG0 (stix, "--------------------------------------------\n"); + MOO_DEBUG0 (moo, "--------------------------------------------\n"); } diff --git a/stix/lib/decode.c b/stix/lib/decode.c index 41ac6bf..c8e4722 100644 --- a/stix/lib/decode.c +++ b/stix/lib/decode.c @@ -24,54 +24,54 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "stix-prv.h" +#include "moo-prv.h" -#define DECODE_LOG_MASK (STIX_LOG_MNEMONIC) +#define DECODE_LOG_MASK (MOO_LOG_MNEMONIC) -#define LOG_INST_0(stix,fmt) STIX_LOG1(stix, DECODE_LOG_MASK, " %06zd " fmt "\n", fetched_instruction_pointer) -#define LOG_INST_1(stix,fmt,a1) STIX_LOG2(stix, DECODE_LOG_MASK, " %06zd " fmt "\n", fetched_instruction_pointer, a1) -#define LOG_INST_2(stix,fmt,a1,a2) STIX_LOG3(stix, DECODE_LOG_MASK, " %06zd " fmt "\n", fetched_instruction_pointer, a1, a2) -#define LOG_INST_3(stix,fmt,a1,a2,a3) STIX_LOG4(stix, DECODE_LOG_MASK, " %06zd " fmt "\n", fetched_instruction_pointer, a1, a2, a3) +#define LOG_INST_0(moo,fmt) MOO_LOG1(moo, DECODE_LOG_MASK, " %06zd " fmt "\n", fetched_instruction_pointer) +#define LOG_INST_1(moo,fmt,a1) MOO_LOG2(moo, DECODE_LOG_MASK, " %06zd " fmt "\n", fetched_instruction_pointer, a1) +#define LOG_INST_2(moo,fmt,a1,a2) MOO_LOG3(moo, DECODE_LOG_MASK, " %06zd " fmt "\n", fetched_instruction_pointer, a1, a2) +#define LOG_INST_3(moo,fmt,a1,a2,a3) MOO_LOG4(moo, DECODE_LOG_MASK, " %06zd " fmt "\n", fetched_instruction_pointer, a1, a2, a3) -#define FETCH_BYTE_CODE(stix) (cdptr[ip++]) -#define FETCH_BYTE_CODE_TO(stix,v_oow) (v_oow = FETCH_BYTE_CODE(stix)) -#if (STIX_BCODE_LONG_PARAM_SIZE == 2) -# define FETCH_PARAM_CODE_TO(stix,v_oow) \ +#define FETCH_BYTE_CODE(moo) (cdptr[ip++]) +#define FETCH_BYTE_CODE_TO(moo,v_oow) (v_oow = FETCH_BYTE_CODE(moo)) +#if (MOO_BCODE_LONG_PARAM_SIZE == 2) +# define FETCH_PARAM_CODE_TO(moo,v_oow) \ do { \ - v_oow = FETCH_BYTE_CODE(stix); \ - v_oow = (v_oow << 8) | FETCH_BYTE_CODE(stix); \ + v_oow = FETCH_BYTE_CODE(moo); \ + v_oow = (v_oow << 8) | FETCH_BYTE_CODE(moo); \ } while (0) #else -# define FETCH_PARAM_CODE_TO(stix,v_oow) (v_oow = FETCH_BYTE_CODE(stix)) +# define FETCH_PARAM_CODE_TO(moo,v_oow) (v_oow = FETCH_BYTE_CODE(moo)) #endif /* TODO: check if ip shoots beyond the maximum length in fetching code and parameters */ -int stix_decode (stix_t* stix, stix_oop_method_t mth, const stix_oocs_t* classfqn) +int moo_decode (moo_t* moo, moo_oop_method_t mth, const moo_oocs_t* classfqn) { - stix_oob_t bcode, * cdptr; - stix_ooi_t ip = 0, cdlen; /* byte code length is limited by the compiler. so stix_ooi_t is good enough */ - stix_ooi_t fetched_instruction_pointer; - stix_oow_t b1, b2; + moo_oob_t bcode, * cdptr; + moo_ooi_t ip = 0, cdlen; /* byte code length is limited by the compiler. so moo_ooi_t is good enough */ + moo_ooi_t fetched_instruction_pointer; + moo_oow_t b1, b2; - cdptr = STIX_METHOD_GET_CODE_BYTE(mth); - cdlen = STIX_METHOD_GET_CODE_SIZE(mth); + cdptr = MOO_METHOD_GET_CODE_BYTE(mth); + cdlen = MOO_METHOD_GET_CODE_SIZE(mth); if (classfqn) - STIX_LOG3 (stix, DECODE_LOG_MASK, "%.*js>>%O\n", classfqn->len, classfqn->ptr, mth->name); + MOO_LOG3 (moo, DECODE_LOG_MASK, "%.*js>>%O\n", classfqn->len, classfqn->ptr, mth->name); else - STIX_LOG2 (stix, DECODE_LOG_MASK, "%O>>%O\n", mth->owner, mth->name); + MOO_LOG2 (moo, DECODE_LOG_MASK, "%O>>%O\n", mth->owner, mth->name); /* TODO: check if ip increases beyond bcode when fetching parameters too */ while (ip < cdlen) { fetched_instruction_pointer = ip; - FETCH_BYTE_CODE_TO(stix, bcode); + FETCH_BYTE_CODE_TO(moo, bcode); switch (bcode) { case BCODE_PUSH_INSTVAR_X: - FETCH_PARAM_CODE_TO (stix, b1); + FETCH_PARAM_CODE_TO (moo, b1); goto push_instvar; case BCODE_PUSH_INSTVAR_0: case BCODE_PUSH_INSTVAR_1: @@ -83,13 +83,13 @@ int stix_decode (stix_t* stix, stix_oop_method_t mth, const stix_oocs_t* classfq case BCODE_PUSH_INSTVAR_7: b1 = bcode & 0x7; /* low 3 bits */ push_instvar: - LOG_INST_1 (stix, "push_instvar %zu", b1); + LOG_INST_1 (moo, "push_instvar %zu", b1); break; /* ------------------------------------------------- */ case BCODE_STORE_INTO_INSTVAR_X: - FETCH_PARAM_CODE_TO (stix, b1); + FETCH_PARAM_CODE_TO (moo, b1); goto store_instvar; case BCODE_STORE_INTO_INSTVAR_0: case BCODE_STORE_INTO_INSTVAR_1: @@ -101,11 +101,11 @@ int stix_decode (stix_t* stix, stix_oop_method_t mth, const stix_oocs_t* classfq case BCODE_STORE_INTO_INSTVAR_7: b1 = bcode & 0x7; /* low 3 bits */ store_instvar: - LOG_INST_1 (stix, "store_into_instvar %zu", b1); + LOG_INST_1 (moo, "store_into_instvar %zu", b1); break; case BCODE_POP_INTO_INSTVAR_X: - FETCH_PARAM_CODE_TO (stix, b1); + FETCH_PARAM_CODE_TO (moo, b1); goto pop_into_instvar; case BCODE_POP_INTO_INSTVAR_0: case BCODE_POP_INTO_INSTVAR_1: @@ -117,14 +117,14 @@ int stix_decode (stix_t* stix, stix_oop_method_t mth, const stix_oocs_t* classfq case BCODE_POP_INTO_INSTVAR_7: b1 = bcode & 0x7; /* low 3 bits */ pop_into_instvar: - LOG_INST_1 (stix, "pop_into_instvar %zu", b1); + LOG_INST_1 (moo, "pop_into_instvar %zu", b1); break; /* ------------------------------------------------- */ case BCODE_PUSH_TEMPVAR_X: case BCODE_STORE_INTO_TEMPVAR_X: case BCODE_POP_INTO_TEMPVAR_X: - FETCH_PARAM_CODE_TO (stix, b1); + FETCH_PARAM_CODE_TO (moo, b1); goto handle_tempvar; case BCODE_PUSH_TEMPVAR_0: @@ -157,7 +157,7 @@ int stix_decode (stix_t* stix, stix_oop_method_t mth, const stix_oocs_t* classfq if ((bcode >> 4) & 1) { /* push - bit 4 on */ - LOG_INST_1 (stix, "push_tempvar %zu", b1); + LOG_INST_1 (moo, "push_tempvar %zu", b1); } else { @@ -165,18 +165,18 @@ int stix_decode (stix_t* stix, stix_oop_method_t mth, const stix_oocs_t* classfq if ((bcode >> 3) & 1) { /* pop - bit 3 on */ - LOG_INST_1 (stix, "pop_into_tempvar %zu", b1); + LOG_INST_1 (moo, "pop_into_tempvar %zu", b1); } else { - LOG_INST_1 (stix, "store_into_tempvar %zu", b1); + LOG_INST_1 (moo, "store_into_tempvar %zu", b1); } } break; /* ------------------------------------------------- */ case BCODE_PUSH_LITERAL_X: - FETCH_PARAM_CODE_TO (stix, b1); + FETCH_PARAM_CODE_TO (moo, b1); goto push_literal; case BCODE_PUSH_LITERAL_0: @@ -189,14 +189,14 @@ int stix_decode (stix_t* stix, stix_oop_method_t mth, const stix_oocs_t* classfq case BCODE_PUSH_LITERAL_7: b1 = bcode & 0x7; /* low 3 bits */ push_literal: - LOG_INST_1 (stix, "push_literal @%zu", b1); + LOG_INST_1 (moo, "push_literal @%zu", b1); break; /* ------------------------------------------------- */ case BCODE_PUSH_OBJECT_X: case BCODE_STORE_INTO_OBJECT_X: case BCODE_POP_INTO_OBJECT_X: - FETCH_PARAM_CODE_TO (stix, b1); + FETCH_PARAM_CODE_TO (moo, b1); goto handle_object; case BCODE_PUSH_OBJECT_0: @@ -217,44 +217,44 @@ int stix_decode (stix_t* stix, stix_oop_method_t mth, const stix_oocs_t* classfq { if ((bcode >> 2) & 1) { - LOG_INST_1 (stix, "pop_into_object @%zu", b1); + LOG_INST_1 (moo, "pop_into_object @%zu", b1); } else { - LOG_INST_1 (stix, "store_into_object @%zu", b1); + LOG_INST_1 (moo, "store_into_object @%zu", b1); } } else { - LOG_INST_1 (stix, "push_object @%zu", b1); + LOG_INST_1 (moo, "push_object @%zu", b1); } break; /* -------------------------------------------------------- */ case BCODE_JUMP_FORWARD_X: - FETCH_PARAM_CODE_TO (stix, b1); - LOG_INST_1 (stix, "jump_forward %zu", b1); + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST_1 (moo, "jump_forward %zu", b1); break; case BCODE_JUMP_FORWARD_0: case BCODE_JUMP_FORWARD_1: case BCODE_JUMP_FORWARD_2: case BCODE_JUMP_FORWARD_3: - LOG_INST_1 (stix, "jump_forward %zu", (stix_oow_t)(bcode & 0x3)); /* low 2 bits */ + LOG_INST_1 (moo, "jump_forward %zu", (moo_oow_t)(bcode & 0x3)); /* low 2 bits */ break; case BCODE_JUMP_BACKWARD_X: - FETCH_PARAM_CODE_TO (stix, b1); - LOG_INST_1 (stix, "jump_backward %zu", b1); - stix->ip += b1; + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST_1 (moo, "jump_backward %zu", b1); + moo->ip += b1; break; case BCODE_JUMP_BACKWARD_0: case BCODE_JUMP_BACKWARD_1: case BCODE_JUMP_BACKWARD_2: case BCODE_JUMP_BACKWARD_3: - LOG_INST_1 (stix, "jump_backward %zu", (stix_oow_t)(bcode & 0x3)); /* low 2 bits */ + LOG_INST_1 (moo, "jump_backward %zu", (moo_oow_t)(bcode & 0x3)); /* low 2 bits */ break; case BCODE_JUMP_IF_TRUE_X: @@ -267,18 +267,18 @@ int stix_decode (stix_t* stix, stix_oop_method_t mth, const stix_oocs_t* classfq case BCODE_JUMP_IF_FALSE_1: case BCODE_JUMP_IF_FALSE_2: case BCODE_JUMP_IF_FALSE_3: -LOG_INST_0 (stix, "<<<<<<<<<<<<<< JUMP NOT IMPLEMENTED YET >>>>>>>>>>>>"); -stix->errnum = STIX_ENOIMPL; +LOG_INST_0 (moo, "<<<<<<<<<<<<<< JUMP NOT IMPLEMENTED YET >>>>>>>>>>>>"); +moo->errnum = MOO_ENOIMPL; return -1; case BCODE_JUMP2_FORWARD: - FETCH_PARAM_CODE_TO (stix, b1); - LOG_INST_1 (stix, "jump2_forward %zu", b1); + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST_1 (moo, "jump2_forward %zu", b1); break; case BCODE_JUMP2_BACKWARD: - FETCH_PARAM_CODE_TO (stix, b1); - LOG_INST_1 (stix, "jump2_backward %zu", b1); + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST_1 (moo, "jump2_backward %zu", b1); break; /* -------------------------------------------------------- */ @@ -286,8 +286,8 @@ return -1; case BCODE_PUSH_CTXTEMPVAR_X: case BCODE_STORE_INTO_CTXTEMPVAR_X: case BCODE_POP_INTO_CTXTEMPVAR_X: - FETCH_PARAM_CODE_TO (stix, b1); - FETCH_PARAM_CODE_TO (stix, b2); + FETCH_PARAM_CODE_TO (moo, b1); + FETCH_PARAM_CODE_TO (moo, b2); goto handle_ctxtempvar; case BCODE_PUSH_CTXTEMPVAR_0: case BCODE_PUSH_CTXTEMPVAR_1: @@ -302,7 +302,7 @@ return -1; case BCODE_POP_INTO_CTXTEMPVAR_2: case BCODE_POP_INTO_CTXTEMPVAR_3: b1 = bcode & 0x3; /* low 2 bits */ - FETCH_BYTE_CODE_TO (stix, b2); + FETCH_BYTE_CODE_TO (moo, b2); handle_ctxtempvar: if ((bcode >> 3) & 1) @@ -311,17 +311,17 @@ return -1; if ((bcode >> 2) & 1) { - LOG_INST_2 (stix, "pop_into_ctxtempvar %zu %zu", b1, b2); + LOG_INST_2 (moo, "pop_into_ctxtempvar %zu %zu", b1, b2); } else { - LOG_INST_2 (stix, "store_into_ctxtempvar %zu %zu", b1, b2); + LOG_INST_2 (moo, "store_into_ctxtempvar %zu %zu", b1, b2); } } else { /* push */ - LOG_INST_2 (stix, "push_ctxtempvar %zu %zu", b1, b2); + LOG_INST_2 (moo, "push_ctxtempvar %zu %zu", b1, b2); } break; @@ -330,8 +330,8 @@ return -1; case BCODE_PUSH_OBJVAR_X: case BCODE_STORE_INTO_OBJVAR_X: case BCODE_POP_INTO_OBJVAR_X: - FETCH_PARAM_CODE_TO (stix, b1); - FETCH_PARAM_CODE_TO (stix, b2); + FETCH_PARAM_CODE_TO (moo, b1); + FETCH_PARAM_CODE_TO (moo, b2); goto handle_objvar; case BCODE_PUSH_OBJVAR_0: @@ -349,7 +349,7 @@ return -1; /* b1 -> variable index to the object indicated by b2. * b2 -> object index stored in the literal frame. */ b1 = bcode & 0x3; /* low 2 bits */ - FETCH_BYTE_CODE_TO (stix, b2); + FETCH_BYTE_CODE_TO (moo, b2); handle_objvar: if ((bcode >> 3) & 1) @@ -357,16 +357,16 @@ return -1; /* store or pop */ if ((bcode >> 2) & 1) { - LOG_INST_2 (stix, "pop_into_objvar %zu %zu", b1, b2); + LOG_INST_2 (moo, "pop_into_objvar %zu %zu", b1, b2); } else { - LOG_INST_2 (stix, "store_into_objvar %zu %zu", b1, b2); + LOG_INST_2 (moo, "store_into_objvar %zu %zu", b1, b2); } } else { - LOG_INST_2 (stix, "push_objvar %zu %zu", b1, b2); + LOG_INST_2 (moo, "push_objvar %zu %zu", b1, b2); } break; @@ -376,8 +376,8 @@ return -1; case BCODE_SEND_MESSAGE_TO_SUPER_X: /* b1 -> number of arguments * b2 -> selector index stored in the literal frame */ - FETCH_PARAM_CODE_TO (stix, b1); - FETCH_PARAM_CODE_TO (stix, b2); + FETCH_PARAM_CODE_TO (moo, b1); + FETCH_PARAM_CODE_TO (moo, b2); goto handle_send_message; case BCODE_SEND_MESSAGE_0: @@ -389,123 +389,123 @@ return -1; case BCODE_SEND_MESSAGE_TO_SUPER_2: case BCODE_SEND_MESSAGE_TO_SUPER_3: b1 = bcode & 0x3; /* low 2 bits */ - FETCH_BYTE_CODE_TO (stix, b2); + FETCH_BYTE_CODE_TO (moo, b2); handle_send_message: - LOG_INST_3 (stix, "send_message%hs %zu @%zu", (((bcode >> 2) & 1)? "_to_super": ""), b1, b2); + LOG_INST_3 (moo, "send_message%hs %zu @%zu", (((bcode >> 2) & 1)? "_to_super": ""), b1, b2); break; /* -------------------------------------------------------- */ case BCODE_PUSH_RECEIVER: - LOG_INST_0 (stix, "push_receiver"); + LOG_INST_0 (moo, "push_receiver"); break; case BCODE_PUSH_NIL: - LOG_INST_0 (stix, "push_nil"); + LOG_INST_0 (moo, "push_nil"); break; case BCODE_PUSH_TRUE: - LOG_INST_0 (stix, "push_true"); + LOG_INST_0 (moo, "push_true"); break; case BCODE_PUSH_FALSE: - LOG_INST_0 (stix, "push_false"); + LOG_INST_0 (moo, "push_false"); break; case BCODE_PUSH_CONTEXT: - LOG_INST_0 (stix, "push_context"); + LOG_INST_0 (moo, "push_context"); break; case BCODE_PUSH_PROCESS: - LOG_INST_0 (stix, "push_process"); + LOG_INST_0 (moo, "push_process"); break; case BCODE_PUSH_NEGONE: - LOG_INST_0 (stix, "push_negone"); + LOG_INST_0 (moo, "push_negone"); break; case BCODE_PUSH_ZERO: - LOG_INST_0 (stix, "push_zero"); + LOG_INST_0 (moo, "push_zero"); break; case BCODE_PUSH_ONE: - LOG_INST_0 (stix, "push_one"); + LOG_INST_0 (moo, "push_one"); break; case BCODE_PUSH_TWO: - LOG_INST_0 (stix, "push_two"); + LOG_INST_0 (moo, "push_two"); break; case BCODE_PUSH_INTLIT: - FETCH_PARAM_CODE_TO (stix, b1); - LOG_INST_1 (stix, "push_intlit %zu", b1); + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST_1 (moo, "push_intlit %zu", b1); break; case BCODE_PUSH_NEGINTLIT: - FETCH_PARAM_CODE_TO (stix, b1); - LOG_INST_1 (stix, "push_negintlit %zu", b1); + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST_1 (moo, "push_negintlit %zu", b1); break; case BCODE_PUSH_CHARLIT: - FETCH_PARAM_CODE_TO (stix, b1); - LOG_INST_1 (stix, "push_charlit %zu", b1); + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST_1 (moo, "push_charlit %zu", b1); break; /* -------------------------------------------------------- */ case BCODE_DUP_STACKTOP: - LOG_INST_0 (stix, "dup_stacktop"); + LOG_INST_0 (moo, "dup_stacktop"); break; case BCODE_POP_STACKTOP: - LOG_INST_0 (stix, "pop_stacktop"); + LOG_INST_0 (moo, "pop_stacktop"); break; case BCODE_RETURN_STACKTOP: - LOG_INST_0 (stix, "return_stacktop"); + LOG_INST_0 (moo, "return_stacktop"); break; case BCODE_RETURN_RECEIVER: - LOG_INST_0 (stix, "return_receiver"); + LOG_INST_0 (moo, "return_receiver"); break; case BCODE_RETURN_FROM_BLOCK: - LOG_INST_0 (stix, "return_from_block"); + LOG_INST_0 (moo, "return_from_block"); break; case BCODE_MAKE_BLOCK: /* b1 - number of block arguments * b2 - number of block temporaries */ - FETCH_PARAM_CODE_TO (stix, b1); - FETCH_PARAM_CODE_TO (stix, b2); + FETCH_PARAM_CODE_TO (moo, b1); + FETCH_PARAM_CODE_TO (moo, b2); - LOG_INST_2 (stix, "make_block %zu %zu", b1, b2); + LOG_INST_2 (moo, "make_block %zu %zu", b1, b2); - STIX_ASSERT (stix, b1 >= 0); - STIX_ASSERT (stix, b2 >= b1); + MOO_ASSERT (moo, b1 >= 0); + MOO_ASSERT (moo, b2 >= b1); break; case BCODE_SEND_BLOCK_COPY: - LOG_INST_0 (stix, "send_block_copy"); + LOG_INST_0 (moo, "send_block_copy"); break; case BCODE_NOOP: /* do nothing */ - LOG_INST_0 (stix, "noop"); + LOG_INST_0 (moo, "noop"); break; default: - LOG_INST_1 (stix, "UNKNOWN BYTE CODE ENCOUNTERED %x", (int)bcode); - stix->errnum = STIX_EINTERN; + LOG_INST_1 (moo, "UNKNOWN BYTE CODE ENCOUNTERED %x", (int)bcode); + moo->errnum = MOO_EINTERN; break; } } /* print literal frame contents */ - for (ip = 0; ip < STIX_OBJ_GET_SIZE(mth) - STIX_METHOD_NAMED_INSTVARS; ip++) + for (ip = 0; ip < MOO_OBJ_GET_SIZE(mth) - MOO_METHOD_NAMED_INSTVARS; ip++) { - STIX_LOG2(stix, DECODE_LOG_MASK, " @%-5zd %O\n", ip, mth->slot[ip]); + MOO_LOG2(moo, DECODE_LOG_MASK, " @%-5zd %O\n", ip, mth->slot[ip]); } return 0; diff --git a/stix/lib/dic.c b/stix/lib/dic.c index 4753270..4caa3be 100644 --- a/stix/lib/dic.c +++ b/stix/lib/dic.c @@ -24,16 +24,16 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "stix-prv.h" +#include "moo-prv.h" -static stix_oop_oop_t expand_bucket (stix_t* stix, stix_oop_oop_t oldbuc) +static moo_oop_oop_t expand_bucket (moo_t* moo, moo_oop_oop_t oldbuc) { - stix_oop_oop_t newbuc; - stix_oow_t oldsz, newsz, index; - stix_oop_association_t ass; - stix_oop_char_t key; + moo_oop_oop_t newbuc; + moo_oow_t oldsz, newsz, index; + moo_oop_association_t ass; + moo_oop_char_t key; - oldsz = STIX_OBJ_GET_SIZE(oldbuc); + oldsz = MOO_OBJ_GET_SIZE(oldbuc); /* TODO: better growth policy? */ if (oldsz < 5000) newsz = oldsz + oldsz; @@ -45,111 +45,111 @@ static stix_oop_oop_t expand_bucket (stix_t* stix, stix_oop_oop_t oldbuc) else if (oldsz < 1600000) newsz = oldsz + (oldsz / 64); else { - stix_oow_t inc, inc_max; + moo_oow_t inc, inc_max; inc = oldsz / 128; - inc_max = STIX_OBJ_SIZE_MAX - oldsz; + inc_max = MOO_OBJ_SIZE_MAX - oldsz; if (inc > inc_max) { if (inc_max > 0) inc = inc_max; else { - stix->errnum = STIX_EOOMEM; - return STIX_NULL; + moo->errnum = MOO_EOOMEM; + return MOO_NULL; } } newsz = oldsz + inc; } - stix_pushtmp (stix, (stix_oop_t*)&oldbuc); - newbuc = (stix_oop_oop_t)stix_instantiate (stix, stix->_array, STIX_NULL, newsz); - stix_poptmp (stix); - if (!newbuc) return STIX_NULL; + moo_pushtmp (moo, (moo_oop_t*)&oldbuc); + newbuc = (moo_oop_oop_t)moo_instantiate (moo, moo->_array, MOO_NULL, newsz); + moo_poptmp (moo); + if (!newbuc) return MOO_NULL; while (oldsz > 0) { - ass = (stix_oop_association_t)oldbuc->slot[--oldsz]; - if ((stix_oop_t)ass != stix->_nil) + ass = (moo_oop_association_t)oldbuc->slot[--oldsz]; + if ((moo_oop_t)ass != moo->_nil) { - STIX_ASSERT (stix, STIX_CLASSOF(stix,ass) == stix->_association); + MOO_ASSERT (moo, MOO_CLASSOF(moo,ass) == moo->_association); - key = (stix_oop_char_t)ass->key; - STIX_ASSERT (stix, STIX_CLASSOF(stix,key) == (stix_oop_t)stix->_symbol); + key = (moo_oop_char_t)ass->key; + MOO_ASSERT (moo, MOO_CLASSOF(moo,key) == (moo_oop_t)moo->_symbol); - index = stix_hashoochars(key->slot, STIX_OBJ_GET_SIZE(key)) % newsz; - while (newbuc->slot[index] != stix->_nil) index = (index + 1) % newsz; - newbuc->slot[index] = (stix_oop_t)ass; + index = moo_hashoochars(key->slot, MOO_OBJ_GET_SIZE(key)) % newsz; + while (newbuc->slot[index] != moo->_nil) index = (index + 1) % newsz; + newbuc->slot[index] = (moo_oop_t)ass; } } return newbuc; } -static stix_oop_association_t find_or_upsert (stix_t* stix, stix_oop_set_t dic, stix_oop_char_t key, stix_oop_t value) +static moo_oop_association_t find_or_upsert (moo_t* moo, moo_oop_set_t dic, moo_oop_char_t key, moo_oop_t value) { - stix_ooi_t tally; - stix_oow_t hv, index; - stix_oop_association_t ass; - stix_oow_t tmp_count = 0; + moo_ooi_t tally; + moo_oow_t hv, index; + moo_oop_association_t ass; + moo_oow_t tmp_count = 0; /* the system dictionary is not a generic dictionary. * it accepts only a symbol as a key. */ - STIX_ASSERT (stix, STIX_CLASSOF(stix,key) == stix->_symbol); - STIX_ASSERT (stix, STIX_CLASSOF(stix,dic->tally) == stix->_small_integer); - STIX_ASSERT (stix, STIX_CLASSOF(stix,dic->bucket) == stix->_array); + MOO_ASSERT (moo, MOO_CLASSOF(moo,key) == moo->_symbol); + MOO_ASSERT (moo, MOO_CLASSOF(moo,dic->tally) == moo->_small_integer); + MOO_ASSERT (moo, MOO_CLASSOF(moo,dic->bucket) == moo->_array); - hv = stix_hashoochars(key->slot, STIX_OBJ_GET_SIZE(key)); - index = hv % STIX_OBJ_GET_SIZE(dic->bucket); + hv = moo_hashoochars(key->slot, MOO_OBJ_GET_SIZE(key)); + index = hv % MOO_OBJ_GET_SIZE(dic->bucket); /* find */ - while (dic->bucket->slot[index] != stix->_nil) + while (dic->bucket->slot[index] != moo->_nil) { - ass = (stix_oop_association_t)dic->bucket->slot[index]; + ass = (moo_oop_association_t)dic->bucket->slot[index]; - STIX_ASSERT (stix, STIX_CLASSOF(stix,ass) == stix->_association); - STIX_ASSERT (stix, STIX_CLASSOF(stix,ass->key) == stix->_symbol); + MOO_ASSERT (moo, MOO_CLASSOF(moo,ass) == moo->_association); + MOO_ASSERT (moo, MOO_CLASSOF(moo,ass->key) == moo->_symbol); - if (STIX_OBJ_GET_SIZE(key) == STIX_OBJ_GET_SIZE(ass->key) && - stix_equaloochars (key->slot, ((stix_oop_char_t)ass->key)->slot, STIX_OBJ_GET_SIZE(key))) + if (MOO_OBJ_GET_SIZE(key) == MOO_OBJ_GET_SIZE(ass->key) && + moo_equaloochars (key->slot, ((moo_oop_char_t)ass->key)->slot, MOO_OBJ_GET_SIZE(key))) { - /* the value of STIX_NULL indicates no insertion or update. */ + /* the value of MOO_NULL indicates no insertion or update. */ if (value) ass->value = value; /* update */ return ass; } - index = (index + 1) % STIX_OBJ_GET_SIZE(dic->bucket); + index = (index + 1) % MOO_OBJ_GET_SIZE(dic->bucket); } if (!value) { - /* when value is STIX_NULL, perform no insertion. - * the value of STIX_NULL indicates no insertion or update. */ - stix->errnum = STIX_ENOENT; - return STIX_NULL; + /* when value is MOO_NULL, perform no insertion. + * the value of MOO_NULL indicates no insertion or update. */ + moo->errnum = MOO_ENOENT; + return MOO_NULL; } /* the key is not found. insert it. */ - STIX_ASSERT (stix, STIX_OOP_IS_SMOOI(dic->tally)); - tally = STIX_OOP_TO_SMOOI(dic->tally); - if (tally >= STIX_SMOOI_MAX) + MOO_ASSERT (moo, MOO_OOP_IS_SMOOI(dic->tally)); + tally = MOO_OOP_TO_SMOOI(dic->tally); + if (tally >= MOO_SMOOI_MAX) { /* this built-in dictionary is not allowed to hold more than - * STIX_SMOOI_MAX items for efficiency sake */ - stix->errnum = STIX_EDFULL; - return STIX_NULL; + * MOO_SMOOI_MAX items for efficiency sake */ + moo->errnum = MOO_EDFULL; + return MOO_NULL; } - stix_pushtmp (stix, (stix_oop_t*)&dic); tmp_count++; - stix_pushtmp (stix, (stix_oop_t*)&key); tmp_count++; - stix_pushtmp (stix, &value); tmp_count++; + moo_pushtmp (moo, (moo_oop_t*)&dic); tmp_count++; + moo_pushtmp (moo, (moo_oop_t*)&key); tmp_count++; + moo_pushtmp (moo, &value); tmp_count++; - /* no conversion to stix_oow_t is necessary for tally + 1. - * the maximum value of tally is checked to be STIX_SMOOI_MAX - 1. - * tally + 1 can produce at most STIX_SMOOI_MAX. above all, - * STIX_SMOOI_MAX is way smaller than STIX_TYPE_MAX(stix_ooi_t). */ - if (tally + 1 >= STIX_OBJ_GET_SIZE(dic->bucket)) + /* no conversion to moo_oow_t is necessary for tally + 1. + * the maximum value of tally is checked to be MOO_SMOOI_MAX - 1. + * tally + 1 can produce at most MOO_SMOOI_MAX. above all, + * MOO_SMOOI_MAX is way smaller than MOO_TYPE_MAX(moo_ooi_t). */ + if (tally + 1 >= MOO_OBJ_GET_SIZE(dic->bucket)) { - stix_oop_oop_t bucket; + moo_oop_oop_t bucket; /* TODO: make the growth policy configurable instead of growing it just before it gets full. The polcy can be grow it @@ -159,133 +159,133 @@ static stix_oop_association_t find_or_upsert (stix_t* stix, stix_oop_set_t dic, * make sure that it has at least one free slot left * after having added a new symbol. this is to help * traversal end at a _nil slot if no entry is found. */ - bucket = expand_bucket (stix, dic->bucket); + bucket = expand_bucket (moo, dic->bucket); if (!bucket) goto oops; dic->bucket = bucket; /* recalculate the index for the expanded bucket */ - index = hv % STIX_OBJ_GET_SIZE(dic->bucket); + index = hv % MOO_OBJ_GET_SIZE(dic->bucket); - while (dic->bucket->slot[index] != stix->_nil) - index = (index + 1) % STIX_OBJ_GET_SIZE(dic->bucket); + while (dic->bucket->slot[index] != moo->_nil) + index = (index + 1) % MOO_OBJ_GET_SIZE(dic->bucket); } /* create a new assocation of a key and a value since * the key isn't found in the root dictionary */ - ass = (stix_oop_association_t)stix_instantiate (stix, stix->_association, STIX_NULL, 0); + ass = (moo_oop_association_t)moo_instantiate (moo, moo->_association, MOO_NULL, 0); if (!ass) goto oops; - ass->key = (stix_oop_t)key; + ass->key = (moo_oop_t)key; ass->value = value; /* the current tally must be less than the maximum value. otherwise, * it overflows after increment below */ - STIX_ASSERT (stix, tally < STIX_SMOOI_MAX); - dic->tally = STIX_SMOOI_TO_OOP(tally + 1); - dic->bucket->slot[index] = (stix_oop_t)ass; + MOO_ASSERT (moo, tally < MOO_SMOOI_MAX); + dic->tally = MOO_SMOOI_TO_OOP(tally + 1); + dic->bucket->slot[index] = (moo_oop_t)ass; - stix_poptmps (stix, tmp_count); + moo_poptmps (moo, tmp_count); return ass; oops: - stix_poptmps (stix, tmp_count); - return STIX_NULL; + moo_poptmps (moo, tmp_count); + return MOO_NULL; } -static stix_oop_association_t lookup (stix_t* stix, stix_oop_set_t dic, const stix_oocs_t* name) +static moo_oop_association_t lookup (moo_t* moo, moo_oop_set_t dic, const moo_oocs_t* name) { - /* this is special version of stix_getatsysdic() that performs + /* this is special version of moo_getatsysdic() that performs * lookup using a plain string specified */ - stix_oow_t index; - stix_oop_association_t ass; + moo_oow_t index; + moo_oop_association_t ass; - STIX_ASSERT (stix, STIX_CLASSOF(stix,dic->tally) == stix->_small_integer); - STIX_ASSERT (stix, STIX_CLASSOF(stix,dic->bucket) == stix->_array); + MOO_ASSERT (moo, MOO_CLASSOF(moo,dic->tally) == moo->_small_integer); + MOO_ASSERT (moo, MOO_CLASSOF(moo,dic->bucket) == moo->_array); - index = stix_hashoochars(name->ptr, name->len) % STIX_OBJ_GET_SIZE(dic->bucket); + index = moo_hashoochars(name->ptr, name->len) % MOO_OBJ_GET_SIZE(dic->bucket); - while (dic->bucket->slot[index] != stix->_nil) + while (dic->bucket->slot[index] != moo->_nil) { - ass = (stix_oop_association_t)dic->bucket->slot[index]; + ass = (moo_oop_association_t)dic->bucket->slot[index]; - STIX_ASSERT (stix, STIX_CLASSOF(stix,ass) == stix->_association); - STIX_ASSERT (stix, STIX_CLASSOF(stix,ass->key) == stix->_symbol); + MOO_ASSERT (moo, MOO_CLASSOF(moo,ass) == moo->_association); + MOO_ASSERT (moo, MOO_CLASSOF(moo,ass->key) == moo->_symbol); - if (name->len == STIX_OBJ_GET_SIZE(ass->key) && - stix_equaloochars(name->ptr, ((stix_oop_char_t)ass->key)->slot, name->len)) + if (name->len == MOO_OBJ_GET_SIZE(ass->key) && + moo_equaloochars(name->ptr, ((moo_oop_char_t)ass->key)->slot, name->len)) { return ass; } - index = (index + 1) % STIX_OBJ_GET_SIZE(dic->bucket); + index = (index + 1) % MOO_OBJ_GET_SIZE(dic->bucket); } - /* when value is STIX_NULL, perform no insertion */ - stix->errnum = STIX_ENOENT; - return STIX_NULL; + /* when value is MOO_NULL, perform no insertion */ + moo->errnum = MOO_ENOENT; + return MOO_NULL; } -stix_oop_association_t stix_putatsysdic (stix_t* stix, stix_oop_t key, stix_oop_t value) +moo_oop_association_t moo_putatsysdic (moo_t* moo, moo_oop_t key, moo_oop_t value) { - STIX_ASSERT (stix, STIX_CLASSOF(stix,key) == stix->_symbol); - return find_or_upsert (stix, stix->sysdic, (stix_oop_char_t)key, value); + MOO_ASSERT (moo, MOO_CLASSOF(moo,key) == moo->_symbol); + return find_or_upsert (moo, moo->sysdic, (moo_oop_char_t)key, value); } -stix_oop_association_t stix_getatsysdic (stix_t* stix, stix_oop_t key) +moo_oop_association_t moo_getatsysdic (moo_t* moo, moo_oop_t key) { - STIX_ASSERT (stix, STIX_CLASSOF(stix,key) == stix->_symbol); - return find_or_upsert (stix, stix->sysdic, (stix_oop_char_t)key, STIX_NULL); + MOO_ASSERT (moo, MOO_CLASSOF(moo,key) == moo->_symbol); + return find_or_upsert (moo, moo->sysdic, (moo_oop_char_t)key, MOO_NULL); } -stix_oop_association_t stix_lookupsysdic (stix_t* stix, const stix_oocs_t* name) +moo_oop_association_t moo_lookupsysdic (moo_t* moo, const moo_oocs_t* name) { - return lookup (stix, stix->sysdic, name); + return lookup (moo, moo->sysdic, name); } -stix_oop_association_t stix_putatdic (stix_t* stix, stix_oop_set_t dic, stix_oop_t key, stix_oop_t value) +moo_oop_association_t moo_putatdic (moo_t* moo, moo_oop_set_t dic, moo_oop_t key, moo_oop_t value) { - STIX_ASSERT (stix, STIX_CLASSOF(stix,key) == stix->_symbol); - return find_or_upsert (stix, dic, (stix_oop_char_t)key, value); + MOO_ASSERT (moo, MOO_CLASSOF(moo,key) == moo->_symbol); + return find_or_upsert (moo, dic, (moo_oop_char_t)key, value); } -stix_oop_association_t stix_getatdic (stix_t* stix, stix_oop_set_t dic, stix_oop_t key) +moo_oop_association_t moo_getatdic (moo_t* moo, moo_oop_set_t dic, moo_oop_t key) { - STIX_ASSERT (stix, STIX_CLASSOF(stix,key) == stix->_symbol); - return find_or_upsert (stix, dic, (stix_oop_char_t)key, STIX_NULL); + MOO_ASSERT (moo, MOO_CLASSOF(moo,key) == moo->_symbol); + return find_or_upsert (moo, dic, (moo_oop_char_t)key, MOO_NULL); } -stix_oop_association_t stix_lookupdic (stix_t* stix, stix_oop_set_t dic, const stix_oocs_t* name) +moo_oop_association_t moo_lookupdic (moo_t* moo, moo_oop_set_t dic, const moo_oocs_t* name) { - return lookup (stix, dic, name); + return lookup (moo, dic, name); } -int stix_deletedic (stix_t* stix, stix_oop_set_t dic, const stix_oocs_t* name) +int moo_deletedic (moo_t* moo, moo_oop_set_t dic, const moo_oocs_t* name) { - stix_ooi_t tally; - stix_oow_t hv, index, bs, i, x, y, z; - stix_oop_association_t ass; + moo_ooi_t tally; + moo_oow_t hv, index, bs, i, x, y, z; + moo_oop_association_t ass; - STIX_ASSERT (stix, STIX_CLASSOF(stix,dic->tally) == stix->_small_integer); - STIX_ASSERT (stix, STIX_CLASSOF(stix,dic->bucket) == stix->_array); + MOO_ASSERT (moo, MOO_CLASSOF(moo,dic->tally) == moo->_small_integer); + MOO_ASSERT (moo, MOO_CLASSOF(moo,dic->bucket) == moo->_array); - tally = STIX_OOP_TO_SMOOI(dic->tally); + tally = MOO_OOP_TO_SMOOI(dic->tally); - bs = STIX_OBJ_GET_SIZE(dic->bucket); - hv = stix_hashoochars(name->ptr, name->len) % bs; + bs = MOO_OBJ_GET_SIZE(dic->bucket); + hv = moo_hashoochars(name->ptr, name->len) % bs; index = hv % bs; /* find */ - while (dic->bucket->slot[index] != stix->_nil) + while (dic->bucket->slot[index] != moo->_nil) { - ass = (stix_oop_association_t)dic->bucket->slot[index]; + ass = (moo_oop_association_t)dic->bucket->slot[index]; - STIX_ASSERT (stix, STIX_CLASSOF(stix,ass) == stix->_association); - STIX_ASSERT (stix, STIX_CLASSOF(stix,ass->key) == stix->_symbol); + MOO_ASSERT (moo, MOO_CLASSOF(moo,ass) == moo->_association); + MOO_ASSERT (moo, MOO_CLASSOF(moo,ass->key) == moo->_symbol); - if (name->len == STIX_OBJ_GET_SIZE(ass->key) && - stix_equaloochars(name->ptr, ((stix_oop_char_t)ass->key)->slot, name->len)) + if (name->len == MOO_OBJ_GET_SIZE(ass->key) && + moo_equaloochars(name->ptr, ((moo_oop_char_t)ass->key)->slot, name->len)) { goto found; } @@ -293,7 +293,7 @@ int stix_deletedic (stix_t* stix, stix_oop_set_t dic, const stix_oocs_t* name) index = (index + 1) % bs; } - stix->errnum = STIX_ENOENT; + moo->errnum = MOO_ENOENT; return -1; found: @@ -303,12 +303,12 @@ found: y = (y + 1) % bs; /* done if the slot at the current index is empty */ - if (dic->bucket->slot[y] == stix->_nil) break; + if (dic->bucket->slot[y] == moo->_nil) break; /* get the natural hash index for the data in the slot at * the current hash index */ - ass = (stix_oop_association_t)dic->bucket->slot[y]; - z = stix_hashoochars(((stix_oop_char_t)ass->key)->slot, STIX_OBJ_GET_SIZE(ass->key)) % bs; + ass = (moo_oop_association_t)dic->bucket->slot[y]; + z = moo_hashoochars(((moo_oop_char_t)ass->key)->slot, MOO_OBJ_GET_SIZE(ass->key)) % bs; /* move an element if necesary */ if ((y > x && (z <= x || z > y)) || @@ -319,36 +319,36 @@ found: } } - dic->bucket->slot[x] = stix->_nil; + dic->bucket->slot[x] = moo->_nil; tally--; - dic->tally = STIX_SMOOI_TO_OOP(tally); + dic->tally = MOO_SMOOI_TO_OOP(tally); return 0; } -stix_oop_set_t stix_makedic (stix_t* stix, stix_oop_t cls, stix_oow_t size) +moo_oop_set_t moo_makedic (moo_t* moo, moo_oop_t cls, moo_oow_t size) { - stix_oop_set_t dic; - stix_oop_t tmp; + moo_oop_set_t dic; + moo_oop_t tmp; - STIX_ASSERT (stix, STIX_CLASSOF(stix,cls) == stix->_class); + MOO_ASSERT (moo, MOO_CLASSOF(moo,cls) == moo->_class); - dic = (stix_oop_set_t)stix_instantiate (stix, cls, STIX_NULL, 0); - if (!dic) return STIX_NULL; + dic = (moo_oop_set_t)moo_instantiate (moo, cls, MOO_NULL, 0); + if (!dic) return MOO_NULL; - STIX_ASSERT (stix, STIX_OBJ_GET_SIZE(dic) == STIX_SET_NAMED_INSTVARS); + MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(dic) == MOO_SET_NAMED_INSTVARS); - stix_pushtmp (stix, (stix_oop_t*)&dic); - tmp = stix_instantiate (stix, stix->_array, STIX_NULL, size); - stix_poptmp (stix); - if (!tmp) return STIX_NULL; + moo_pushtmp (moo, (moo_oop_t*)&dic); + tmp = moo_instantiate (moo, moo->_array, MOO_NULL, size); + moo_poptmp (moo); + if (!tmp) return MOO_NULL; - dic->tally = STIX_SMOOI_TO_OOP(0); - dic->bucket = (stix_oop_oop_t)tmp; + dic->tally = MOO_SMOOI_TO_OOP(0); + dic->bucket = (moo_oop_oop_t)tmp; - STIX_ASSERT (stix, STIX_OBJ_GET_SIZE(dic) == STIX_SET_NAMED_INSTVARS); - STIX_ASSERT (stix, STIX_OBJ_GET_SIZE(dic->bucket) == size); + MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(dic) == MOO_SET_NAMED_INSTVARS); + MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(dic->bucket) == size); return dic; } diff --git a/stix/lib/err.c b/stix/lib/err.c index 6c4718b..d00840b 100644 --- a/stix/lib/err.c +++ b/stix/lib/err.c @@ -24,41 +24,41 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "stix-prv.h" +#include "moo-prv.h" /* BEGIN: GENERATED WITH generr.st */ -static stix_ooch_t errstr_0[] = {'n','o',' ','e','r','r','o','r','\0'}; -static stix_ooch_t errstr_1[] = {'g','e','n','e','r','i','c',' ','e','r','r','o','r','\0'}; -static stix_ooch_t errstr_2[] = {'n','o','t',' ','i','m','p','l','e','m','e','n','t','e','d','\0'}; -static stix_ooch_t errstr_3[] = {'s','u','b','s','y','s','t','e','m',' ','e','r','r','o','r','\0'}; -static stix_ooch_t errstr_4[] = {'i','n','t','e','r','n','a','l',' ','e','r','r','o','r',' ','t','h','a','t',' ','s','h','o','u','l','d',' ','n','e','v','e','r',' ','h','a','v','e',' ','h','a','p','p','e','n','e','d','\0'}; -static stix_ooch_t errstr_5[] = {'i','n','s','u','f','f','i','c','i','e','n','t',' ','s','y','s','t','e','m',' ','m','e','m','o','r','y','\0'}; -static stix_ooch_t errstr_6[] = {'i','n','s','u','f','f','i','c','i','e','n','t',' ','o','b','j','e','c','t',' ','m','e','m','o','r','y','\0'}; -static stix_ooch_t errstr_7[] = {'i','n','v','a','l','i','d',' ','p','a','r','a','m','e','t','e','r',' ','o','r',' ','a','r','g','u','m','e','n','t','\0'}; -static stix_ooch_t errstr_8[] = {'d','a','t','a',' ','n','o','t',' ','f','o','u','n','d','\0'}; -static stix_ooch_t errstr_9[] = {'e','x','i','s','t','i','n','g','/','d','u','p','l','i','c','a','t','e',' ','d','a','t','a','\0'}; -static stix_ooch_t errstr_10[] = {'b','u','s','y','\0'}; -static stix_ooch_t errstr_11[] = {'a','c','c','e','s','s',' ','d','e','n','i','e','d','\0'}; -static stix_ooch_t errstr_12[] = {'o','p','e','r','a','t','i','o','n',' ','n','o','t',' ','p','e','r','m','i','t','t','e','d','\0'}; -static stix_ooch_t errstr_13[] = {'n','o','t',' ','a',' ','d','i','r','e','c','t','o','r','y','\0'}; -static stix_ooch_t errstr_14[] = {'i','n','t','e','r','r','u','p','t','e','d','\0'}; -static stix_ooch_t errstr_15[] = {'p','i','p','e',' ','e','r','r','o','r','\0'}; -static stix_ooch_t errstr_16[] = {'r','e','s','o','u','r','c','e',' ','t','e','m','p','o','r','a','r','i','l','y',' ','u','n','a','v','a','i','l','a','b','l','e','\0'}; -static stix_ooch_t errstr_17[] = {'d','a','t','a',' ','t','o','o',' ','l','a','r','g','e','\0'}; -static stix_ooch_t errstr_18[] = {'m','e','s','s','a','g','e',' ','s','e','n','d','i','n','g',' ','e','r','r','o','r','\0'}; -static stix_ooch_t errstr_19[] = {'r','a','n','g','e',' ','e','r','r','o','r','\0'}; -static stix_ooch_t errstr_20[] = {'b','y','t','e','-','c','o','d','e',' ','f','u','l','l','\0'}; -static stix_ooch_t errstr_21[] = {'d','i','c','t','i','o','n','a','r','y',' ','f','u','l','l','\0'}; -static stix_ooch_t errstr_22[] = {'p','r','o','c','e','s','s','o','r',' ','f','u','l','l','\0'}; -static stix_ooch_t errstr_23[] = {'s','e','m','a','p','h','o','r','e',' ','h','e','a','p',' ','f','u','l','l','\0'}; -static stix_ooch_t errstr_24[] = {'s','e','m','a','p','h','o','r','e',' ','l','i','s','t',' ','f','u','l','l','\0'}; -static stix_ooch_t errstr_25[] = {'d','i','v','i','d','e',' ','b','y',' ','z','e','r','o','\0'}; -static stix_ooch_t errstr_26[] = {'I','/','O',' ','e','r','r','o','r','\0'}; -static stix_ooch_t errstr_27[] = {'e','n','c','o','d','i','n','g',' ','c','o','n','v','e','r','s','i','o','n',' ','e','r','r','o','r','\0'}; -static stix_ooch_t* errstr[] = +static moo_ooch_t errstr_0[] = {'n','o',' ','e','r','r','o','r','\0'}; +static moo_ooch_t errstr_1[] = {'g','e','n','e','r','i','c',' ','e','r','r','o','r','\0'}; +static moo_ooch_t errstr_2[] = {'n','o','t',' ','i','m','p','l','e','m','e','n','t','e','d','\0'}; +static moo_ooch_t errstr_3[] = {'s','u','b','s','y','s','t','e','m',' ','e','r','r','o','r','\0'}; +static moo_ooch_t errstr_4[] = {'i','n','t','e','r','n','a','l',' ','e','r','r','o','r',' ','t','h','a','t',' ','s','h','o','u','l','d',' ','n','e','v','e','r',' ','h','a','v','e',' ','h','a','p','p','e','n','e','d','\0'}; +static moo_ooch_t errstr_5[] = {'i','n','s','u','f','f','i','c','i','e','n','t',' ','s','y','s','t','e','m',' ','m','e','m','o','r','y','\0'}; +static moo_ooch_t errstr_6[] = {'i','n','s','u','f','f','i','c','i','e','n','t',' ','o','b','j','e','c','t',' ','m','e','m','o','r','y','\0'}; +static moo_ooch_t errstr_7[] = {'i','n','v','a','l','i','d',' ','p','a','r','a','m','e','t','e','r',' ','o','r',' ','a','r','g','u','m','e','n','t','\0'}; +static moo_ooch_t errstr_8[] = {'d','a','t','a',' ','n','o','t',' ','f','o','u','n','d','\0'}; +static moo_ooch_t errstr_9[] = {'e','x','i','s','t','i','n','g','/','d','u','p','l','i','c','a','t','e',' ','d','a','t','a','\0'}; +static moo_ooch_t errstr_10[] = {'b','u','s','y','\0'}; +static moo_ooch_t errstr_11[] = {'a','c','c','e','s','s',' ','d','e','n','i','e','d','\0'}; +static moo_ooch_t errstr_12[] = {'o','p','e','r','a','t','i','o','n',' ','n','o','t',' ','p','e','r','m','i','t','t','e','d','\0'}; +static moo_ooch_t errstr_13[] = {'n','o','t',' ','a',' ','d','i','r','e','c','t','o','r','y','\0'}; +static moo_ooch_t errstr_14[] = {'i','n','t','e','r','r','u','p','t','e','d','\0'}; +static moo_ooch_t errstr_15[] = {'p','i','p','e',' ','e','r','r','o','r','\0'}; +static moo_ooch_t errstr_16[] = {'r','e','s','o','u','r','c','e',' ','t','e','m','p','o','r','a','r','i','l','y',' ','u','n','a','v','a','i','l','a','b','l','e','\0'}; +static moo_ooch_t errstr_17[] = {'d','a','t','a',' ','t','o','o',' ','l','a','r','g','e','\0'}; +static moo_ooch_t errstr_18[] = {'m','e','s','s','a','g','e',' ','s','e','n','d','i','n','g',' ','e','r','r','o','r','\0'}; +static moo_ooch_t errstr_19[] = {'r','a','n','g','e',' ','e','r','r','o','r','\0'}; +static moo_ooch_t errstr_20[] = {'b','y','t','e','-','c','o','d','e',' ','f','u','l','l','\0'}; +static moo_ooch_t errstr_21[] = {'d','i','c','t','i','o','n','a','r','y',' ','f','u','l','l','\0'}; +static moo_ooch_t errstr_22[] = {'p','r','o','c','e','s','s','o','r',' ','f','u','l','l','\0'}; +static moo_ooch_t errstr_23[] = {'s','e','m','a','p','h','o','r','e',' ','h','e','a','p',' ','f','u','l','l','\0'}; +static moo_ooch_t errstr_24[] = {'s','e','m','a','p','h','o','r','e',' ','l','i','s','t',' ','f','u','l','l','\0'}; +static moo_ooch_t errstr_25[] = {'d','i','v','i','d','e',' ','b','y',' ','z','e','r','o','\0'}; +static moo_ooch_t errstr_26[] = {'I','/','O',' ','e','r','r','o','r','\0'}; +static moo_ooch_t errstr_27[] = {'e','n','c','o','d','i','n','g',' ','c','o','n','v','e','r','s','i','o','n',' ','e','r','r','o','r','\0'}; +static moo_ooch_t* errstr[] = { errstr_0, errstr_1, errstr_2, errstr_3, errstr_4, errstr_5, errstr_6, errstr_7, errstr_8, errstr_9, errstr_10, errstr_11, errstr_12, errstr_13, errstr_14, errstr_15, @@ -66,65 +66,65 @@ static stix_ooch_t* errstr[] = errstr_24, errstr_25, errstr_26, errstr_27 }; -#if defined(STIX_INCLUDE_COMPILER) -static stix_ooch_t synerrstr_0[] = {'n','o',' ','e','r','r','o','r','\0'}; -static stix_ooch_t synerrstr_1[] = {'i','l','l','e','g','a','l',' ','c','h','a','r','a','c','t','e','r','\0'}; -static stix_ooch_t synerrstr_2[] = {'c','o','m','m','e','n','t',' ','n','o','t',' ','c','l','o','s','e','d','\0'}; -static stix_ooch_t synerrstr_3[] = {'s','t','r','i','n','g',' ','n','o','t',' ','c','l','o','s','e','d','\0'}; -static stix_ooch_t synerrstr_4[] = {'n','o',' ','c','h','a','r','a','c','t','e','r',' ','a','f','t','e','r',' ','$','\0'}; -static stix_ooch_t synerrstr_5[] = {'n','o',' ','v','a','l','i','d',' ','c','h','a','r','a','c','t','e','r',' ','a','f','t','e','r',' ','#','\0'}; -static stix_ooch_t synerrstr_6[] = {'w','r','o','n','g',' ','c','h','a','r','a','c','t','e','r',' ','l','i','t','e','r','a','l','\0'}; -static stix_ooch_t synerrstr_7[] = {'c','o','l','o','n',' ','e','x','p','e','c','t','e','d','\0'}; -static stix_ooch_t synerrstr_8[] = {'s','t','r','i','n','g',' ','e','x','p','e','c','t','e','d','\0'}; -static stix_ooch_t synerrstr_9[] = {'i','n','v','a','l','i','d',' ','r','a','d','i','x','\0'}; -static stix_ooch_t synerrstr_10[] = {'i','n','v','a','l','i','d',' ','n','u','m','e','r','i','c',' ','l','i','t','e','r','a','l','\0'}; -static stix_ooch_t synerrstr_11[] = {'b','y','t','e',' ','t','o','o',' ','s','m','a','l','l',' ','o','r',' ','t','o','o',' ','l','a','r','g','e','\0'}; -static stix_ooch_t synerrstr_12[] = {'w','r','o','n','g',' ','e','r','r','o','r',' ','l','i','t','e','r','a','l','\0'}; -static stix_ooch_t synerrstr_13[] = {'{',' ','e','x','p','e','c','t','e','d','\0'}; -static stix_ooch_t synerrstr_14[] = {'}',' ','e','x','p','e','c','t','e','d','\0'}; -static stix_ooch_t synerrstr_15[] = {'(',' ','e','x','p','e','c','t','e','d','\0'}; -static stix_ooch_t synerrstr_16[] = {')',' ','e','x','p','e','c','t','e','d','\0'}; -static stix_ooch_t synerrstr_17[] = {']',' ','e','x','p','e','c','t','e','d','\0'}; -static stix_ooch_t synerrstr_18[] = {'.',' ','e','x','p','e','c','t','e','d','\0'}; -static stix_ooch_t synerrstr_19[] = {' ','e','x','p','e','c','t','e','d','\0'}; -static stix_ooch_t synerrstr_20[] = {'|',' ','e','x','p','e','c','t','e','d','\0'}; -static stix_ooch_t synerrstr_21[] = {'>',' ','e','x','p','e','c','t','e','d','\0'}; -static stix_ooch_t synerrstr_22[] = {':','=',' ','e','x','p','e','c','t','e','d','\0'}; -static stix_ooch_t synerrstr_23[] = {'i','d','e','n','t','i','f','i','e','r',' ','e','x','p','e','c','t','e','d','\0'}; -static stix_ooch_t synerrstr_24[] = {'i','n','t','e','g','e','r',' ','e','x','p','e','c','t','e','d','\0'}; -static stix_ooch_t synerrstr_25[] = {'p','r','i','m','i','t','i','v','e',':',' ','e','x','p','e','c','t','e','d','\0'}; -static stix_ooch_t synerrstr_26[] = {'w','r','o','n','g',' ','d','i','r','e','c','t','i','v','e','\0'}; -static stix_ooch_t synerrstr_27[] = {'u','n','d','e','f','i','n','e','d',' ','c','l','a','s','s','\0'}; -static stix_ooch_t synerrstr_28[] = {'d','u','p','l','i','c','a','t','e',' ','c','l','a','s','s','\0'}; -static stix_ooch_t synerrstr_29[] = {'c','o','n','t','r','a','d','i','c','t','o','r','y',' ','c','l','a','s','s',' ','d','e','f','i','n','i','t','i','o','n','\0'}; -static stix_ooch_t synerrstr_30[] = {'w','r','o','n','g',' ','c','l','a','s','s',' ','n','a','m','e','\0'}; -static stix_ooch_t synerrstr_31[] = {'#','d','c','l',' ','n','o','t',' ','a','l','l','o','w','e','d','\0'}; -static stix_ooch_t synerrstr_32[] = {'w','r','o','n','g',' ','m','e','t','h','o','d',' ','n','a','m','e','\0'}; -static stix_ooch_t synerrstr_33[] = {'d','u','p','l','i','c','a','t','e',' ','m','e','t','h','o','d',' ','n','a','m','e','\0'}; -static stix_ooch_t synerrstr_34[] = {'d','u','p','l','i','c','a','t','e',' ','a','r','g','u','m','e','n','t',' ','n','a','m','e','\0'}; -static stix_ooch_t synerrstr_35[] = {'d','u','p','l','i','c','a','t','e',' ','t','e','m','p','o','r','a','r','y',' ','v','a','r','i','a','b','l','e',' ','n','a','m','e','\0'}; -static stix_ooch_t synerrstr_36[] = {'d','u','p','l','i','c','a','t','e',' ','v','a','r','i','a','b','l','e',' ','n','a','m','e','\0'}; -static stix_ooch_t synerrstr_37[] = {'d','u','p','l','i','c','a','t','e',' ','b','l','o','c','k',' ','a','r','g','u','m','e','n','t',' ','n','a','m','e','\0'}; -static stix_ooch_t synerrstr_38[] = {'c','a','n','n','o','t',' ','a','s','s','i','g','n',' ','t','o',' ','a','r','g','u','m','e','n','t','\0'}; -static stix_ooch_t synerrstr_39[] = {'u','n','d','e','c','l','a','r','e','d',' ','v','a','r','i','a','b','l','e','\0'}; -static stix_ooch_t synerrstr_40[] = {'u','n','u','s','a','b','l','e',' ','v','a','r','i','a','b','l','e',' ','i','n',' ','c','o','m','p','i','l','e','d',' ','c','o','d','e','\0'}; -static stix_ooch_t synerrstr_41[] = {'i','n','a','c','c','e','s','s','i','b','l','e',' ','v','a','r','i','a','b','l','e','\0'}; -static stix_ooch_t synerrstr_42[] = {'a','m','b','i','g','u','o','u','s',' ','v','a','r','i','a','b','l','e','\0'}; -static stix_ooch_t synerrstr_43[] = {'w','r','o','n','g',' ','e','x','p','r','e','s','s','i','o','n',' ','p','r','i','m','a','r','y','\0'}; -static stix_ooch_t synerrstr_44[] = {'t','o','o',' ','m','a','n','y',' ','t','e','m','p','o','r','a','r','i','e','s','\0'}; -static stix_ooch_t synerrstr_45[] = {'t','o','o',' ','m','a','n','y',' ','a','r','g','u','m','e','n','t','s','\0'}; -static stix_ooch_t synerrstr_46[] = {'t','o','o',' ','m','a','n','y',' ','b','l','o','c','k',' ','t','e','m','p','o','r','a','r','i','e','s','\0'}; -static stix_ooch_t synerrstr_47[] = {'t','o','o',' ','m','a','n','y',' ','b','l','o','c','k',' ','a','r','g','u','m','e','n','t','s','\0'}; -static stix_ooch_t synerrstr_48[] = {'t','o','o',' ','l','a','r','g','e',' ','b','l','o','c','k','\0'}; -static stix_ooch_t synerrstr_49[] = {'w','r','o','n','g',' ','p','r','i','m','i','t','i','v','e',' ','f','u','n','c','t','i','o','n',' ','n','u','m','b','e','r','\0'}; -static stix_ooch_t synerrstr_50[] = {'w','r','o','n','g',' ','p','r','i','m','i','t','i','v','e',' ','f','u','n','c','t','i','o','n',' ','i','d','e','n','t','i','f','i','e','r','\0'}; -static stix_ooch_t synerrstr_51[] = {'w','r','o','n','g',' ','m','o','d','u','l','e',' ','n','a','m','e','\0'}; -static stix_ooch_t synerrstr_52[] = {'#','i','n','c','l','u','d','e',' ','e','r','r','o','r','\0'}; -static stix_ooch_t synerrstr_53[] = {'w','r','o','n','g',' ','n','a','m','e','s','p','a','c','e',' ','n','a','m','e','\0'}; -static stix_ooch_t synerrstr_54[] = {'w','r','o','n','g',' ','p','o','o','l',' ','d','i','c','t','i','o','n','a','r','y',' ','n','a','m','e','\0'}; -static stix_ooch_t synerrstr_55[] = {'d','u','p','l','i','c','a','t','e',' ','p','o','o','l',' ','d','i','c','t','i','o','n','a','r','y',' ','n','a','m','e','\0'}; -static stix_ooch_t synerrstr_56[] = {'l','i','t','e','r','a','l',' ','e','x','p','e','c','t','e','d','\0'}; -static stix_ooch_t* synerrstr[] = +#if defined(MOO_INCLUDE_COMPILER) +static moo_ooch_t synerrstr_0[] = {'n','o',' ','e','r','r','o','r','\0'}; +static moo_ooch_t synerrstr_1[] = {'i','l','l','e','g','a','l',' ','c','h','a','r','a','c','t','e','r','\0'}; +static moo_ooch_t synerrstr_2[] = {'c','o','m','m','e','n','t',' ','n','o','t',' ','c','l','o','s','e','d','\0'}; +static moo_ooch_t synerrstr_3[] = {'s','t','r','i','n','g',' ','n','o','t',' ','c','l','o','s','e','d','\0'}; +static moo_ooch_t synerrstr_4[] = {'n','o',' ','c','h','a','r','a','c','t','e','r',' ','a','f','t','e','r',' ','$','\0'}; +static moo_ooch_t synerrstr_5[] = {'n','o',' ','v','a','l','i','d',' ','c','h','a','r','a','c','t','e','r',' ','a','f','t','e','r',' ','#','\0'}; +static moo_ooch_t synerrstr_6[] = {'w','r','o','n','g',' ','c','h','a','r','a','c','t','e','r',' ','l','i','t','e','r','a','l','\0'}; +static moo_ooch_t synerrstr_7[] = {'c','o','l','o','n',' ','e','x','p','e','c','t','e','d','\0'}; +static moo_ooch_t synerrstr_8[] = {'s','t','r','i','n','g',' ','e','x','p','e','c','t','e','d','\0'}; +static moo_ooch_t synerrstr_9[] = {'i','n','v','a','l','i','d',' ','r','a','d','i','x','\0'}; +static moo_ooch_t synerrstr_10[] = {'i','n','v','a','l','i','d',' ','n','u','m','e','r','i','c',' ','l','i','t','e','r','a','l','\0'}; +static moo_ooch_t synerrstr_11[] = {'b','y','t','e',' ','t','o','o',' ','s','m','a','l','l',' ','o','r',' ','t','o','o',' ','l','a','r','g','e','\0'}; +static moo_ooch_t synerrstr_12[] = {'w','r','o','n','g',' ','e','r','r','o','r',' ','l','i','t','e','r','a','l','\0'}; +static moo_ooch_t synerrstr_13[] = {'{',' ','e','x','p','e','c','t','e','d','\0'}; +static moo_ooch_t synerrstr_14[] = {'}',' ','e','x','p','e','c','t','e','d','\0'}; +static moo_ooch_t synerrstr_15[] = {'(',' ','e','x','p','e','c','t','e','d','\0'}; +static moo_ooch_t synerrstr_16[] = {')',' ','e','x','p','e','c','t','e','d','\0'}; +static moo_ooch_t synerrstr_17[] = {']',' ','e','x','p','e','c','t','e','d','\0'}; +static moo_ooch_t synerrstr_18[] = {'.',' ','e','x','p','e','c','t','e','d','\0'}; +static moo_ooch_t synerrstr_19[] = {' ','e','x','p','e','c','t','e','d','\0'}; +static moo_ooch_t synerrstr_20[] = {'|',' ','e','x','p','e','c','t','e','d','\0'}; +static moo_ooch_t synerrstr_21[] = {'>',' ','e','x','p','e','c','t','e','d','\0'}; +static moo_ooch_t synerrstr_22[] = {':','=',' ','e','x','p','e','c','t','e','d','\0'}; +static moo_ooch_t synerrstr_23[] = {'i','d','e','n','t','i','f','i','e','r',' ','e','x','p','e','c','t','e','d','\0'}; +static moo_ooch_t synerrstr_24[] = {'i','n','t','e','g','e','r',' ','e','x','p','e','c','t','e','d','\0'}; +static moo_ooch_t synerrstr_25[] = {'p','r','i','m','i','t','i','v','e',':',' ','e','x','p','e','c','t','e','d','\0'}; +static moo_ooch_t synerrstr_26[] = {'w','r','o','n','g',' ','d','i','r','e','c','t','i','v','e','\0'}; +static moo_ooch_t synerrstr_27[] = {'u','n','d','e','f','i','n','e','d',' ','c','l','a','s','s','\0'}; +static moo_ooch_t synerrstr_28[] = {'d','u','p','l','i','c','a','t','e',' ','c','l','a','s','s','\0'}; +static moo_ooch_t synerrstr_29[] = {'c','o','n','t','r','a','d','i','c','t','o','r','y',' ','c','l','a','s','s',' ','d','e','f','i','n','i','t','i','o','n','\0'}; +static moo_ooch_t synerrstr_30[] = {'w','r','o','n','g',' ','c','l','a','s','s',' ','n','a','m','e','\0'}; +static moo_ooch_t synerrstr_31[] = {'#','d','c','l',' ','n','o','t',' ','a','l','l','o','w','e','d','\0'}; +static moo_ooch_t synerrstr_32[] = {'w','r','o','n','g',' ','m','e','t','h','o','d',' ','n','a','m','e','\0'}; +static moo_ooch_t synerrstr_33[] = {'d','u','p','l','i','c','a','t','e',' ','m','e','t','h','o','d',' ','n','a','m','e','\0'}; +static moo_ooch_t synerrstr_34[] = {'d','u','p','l','i','c','a','t','e',' ','a','r','g','u','m','e','n','t',' ','n','a','m','e','\0'}; +static moo_ooch_t synerrstr_35[] = {'d','u','p','l','i','c','a','t','e',' ','t','e','m','p','o','r','a','r','y',' ','v','a','r','i','a','b','l','e',' ','n','a','m','e','\0'}; +static moo_ooch_t synerrstr_36[] = {'d','u','p','l','i','c','a','t','e',' ','v','a','r','i','a','b','l','e',' ','n','a','m','e','\0'}; +static moo_ooch_t synerrstr_37[] = {'d','u','p','l','i','c','a','t','e',' ','b','l','o','c','k',' ','a','r','g','u','m','e','n','t',' ','n','a','m','e','\0'}; +static moo_ooch_t synerrstr_38[] = {'c','a','n','n','o','t',' ','a','s','s','i','g','n',' ','t','o',' ','a','r','g','u','m','e','n','t','\0'}; +static moo_ooch_t synerrstr_39[] = {'u','n','d','e','c','l','a','r','e','d',' ','v','a','r','i','a','b','l','e','\0'}; +static moo_ooch_t synerrstr_40[] = {'u','n','u','s','a','b','l','e',' ','v','a','r','i','a','b','l','e',' ','i','n',' ','c','o','m','p','i','l','e','d',' ','c','o','d','e','\0'}; +static moo_ooch_t synerrstr_41[] = {'i','n','a','c','c','e','s','s','i','b','l','e',' ','v','a','r','i','a','b','l','e','\0'}; +static moo_ooch_t synerrstr_42[] = {'a','m','b','i','g','u','o','u','s',' ','v','a','r','i','a','b','l','e','\0'}; +static moo_ooch_t synerrstr_43[] = {'w','r','o','n','g',' ','e','x','p','r','e','s','s','i','o','n',' ','p','r','i','m','a','r','y','\0'}; +static moo_ooch_t synerrstr_44[] = {'t','o','o',' ','m','a','n','y',' ','t','e','m','p','o','r','a','r','i','e','s','\0'}; +static moo_ooch_t synerrstr_45[] = {'t','o','o',' ','m','a','n','y',' ','a','r','g','u','m','e','n','t','s','\0'}; +static moo_ooch_t synerrstr_46[] = {'t','o','o',' ','m','a','n','y',' ','b','l','o','c','k',' ','t','e','m','p','o','r','a','r','i','e','s','\0'}; +static moo_ooch_t synerrstr_47[] = {'t','o','o',' ','m','a','n','y',' ','b','l','o','c','k',' ','a','r','g','u','m','e','n','t','s','\0'}; +static moo_ooch_t synerrstr_48[] = {'t','o','o',' ','l','a','r','g','e',' ','b','l','o','c','k','\0'}; +static moo_ooch_t synerrstr_49[] = {'w','r','o','n','g',' ','p','r','i','m','i','t','i','v','e',' ','f','u','n','c','t','i','o','n',' ','n','u','m','b','e','r','\0'}; +static moo_ooch_t synerrstr_50[] = {'w','r','o','n','g',' ','p','r','i','m','i','t','i','v','e',' ','f','u','n','c','t','i','o','n',' ','i','d','e','n','t','i','f','i','e','r','\0'}; +static moo_ooch_t synerrstr_51[] = {'w','r','o','n','g',' ','m','o','d','u','l','e',' ','n','a','m','e','\0'}; +static moo_ooch_t synerrstr_52[] = {'#','i','n','c','l','u','d','e',' ','e','r','r','o','r','\0'}; +static moo_ooch_t synerrstr_53[] = {'w','r','o','n','g',' ','n','a','m','e','s','p','a','c','e',' ','n','a','m','e','\0'}; +static moo_ooch_t synerrstr_54[] = {'w','r','o','n','g',' ','p','o','o','l',' ','d','i','c','t','i','o','n','a','r','y',' ','n','a','m','e','\0'}; +static moo_ooch_t synerrstr_55[] = {'d','u','p','l','i','c','a','t','e',' ','p','o','o','l',' ','d','i','c','t','i','o','n','a','r','y',' ','n','a','m','e','\0'}; +static moo_ooch_t synerrstr_56[] = {'l','i','t','e','r','a','l',' ','e','x','p','e','c','t','e','d','\0'}; +static moo_ooch_t* synerrstr[] = { synerrstr_0, synerrstr_1, synerrstr_2, synerrstr_3, synerrstr_4, synerrstr_5, synerrstr_6, synerrstr_7, synerrstr_8, synerrstr_9, synerrstr_10, synerrstr_11, synerrstr_12, synerrstr_13, synerrstr_14, synerrstr_15, @@ -141,17 +141,17 @@ static stix_ooch_t* synerrstr[] = /* -------------------------------------------------------------------------- * ERROR NUMBER TO STRING CONVERSION * -------------------------------------------------------------------------- */ -const stix_ooch_t* stix_errnumtoerrstr (stix_errnum_t errnum) +const moo_ooch_t* moo_errnumtoerrstr (moo_errnum_t errnum) { - static stix_ooch_t e_unknown[] = {'u','n','k','n','o','w','n',' ','e','r','r','o','r','\0'}; - return (errnum >= 0 && errnum < STIX_COUNTOF(errstr))? errstr[errnum]: e_unknown; + static moo_ooch_t e_unknown[] = {'u','n','k','n','o','w','n',' ','e','r','r','o','r','\0'}; + return (errnum >= 0 && errnum < MOO_COUNTOF(errstr))? errstr[errnum]: e_unknown; } -#if defined(STIX_INCLUDE_COMPILER) -const stix_ooch_t* stix_synerrnumtoerrstr (stix_synerrnum_t errnum) +#if defined(MOO_INCLUDE_COMPILER) +const moo_ooch_t* moo_synerrnumtoerrstr (moo_synerrnum_t errnum) { - static stix_ooch_t e_unknown[] = {'u','n','k','n','o','w','n',' ','e','r','r','o','r','\0'}; - return (errnum >= 0 && errnum < STIX_COUNTOF(synerrstr))? synerrstr[errnum]: e_unknown; + static moo_ooch_t e_unknown[] = {'u','n','k','n','o','w','n',' ','e','r','r','o','r','\0'}; + return (errnum >= 0 && errnum < MOO_COUNTOF(synerrstr))? synerrstr[errnum]: e_unknown; } #endif @@ -184,29 +184,29 @@ const stix_ooch_t* stix_synerrnumtoerrstr (stix_synerrnum_t errnum) # include #endif -stix_errnum_t stix_syserrtoerrnum (int e) +moo_errnum_t moo_syserrtoerrnum (int e) { switch (e) { - case ENOMEM: return STIX_ESYSMEM; - case EINVAL: return STIX_EINVAL; - case EBUSY: return STIX_EBUSY; - case EACCES: return STIX_EACCES; - case EPERM: return STIX_EPERM; - case ENOTDIR: return STIX_ENOTDIR; - case ENOENT: return STIX_ENOENT; - case EEXIST: return STIX_EEXIST; - case EINTR: return STIX_EINTR; - case EPIPE: return STIX_EPIPE; + case ENOMEM: return MOO_ESYSMEM; + case EINVAL: return MOO_EINVAL; + case EBUSY: return MOO_EBUSY; + case EACCES: return MOO_EACCES; + case EPERM: return MOO_EPERM; + case ENOTDIR: return MOO_ENOTDIR; + case ENOENT: return MOO_ENOENT; + case EEXIST: return MOO_EEXIST; + case EINTR: return MOO_EINTR; + case EPIPE: return MOO_EPIPE; #if defined(EAGAIN) && defined(EWOULDBLOCK) && (EAGAIN != EWOULDBLOCK) case EAGAIN: - case EWOULDBLOCK: return STIX_EAGAIN; + case EWOULDBLOCK: return MOO_EAGAIN; #elif defined(EAGAIN) - case EAGAIN: return STIX_EAGAIN; + case EAGAIN: return MOO_EAGAIN; #elif defined(EWOULDBLOCK) - case EWOULDBLOCK: return STIX_EAGAIN; + case EWOULDBLOCK: return MOO_EAGAIN; #endif - default: return STIX_ESYSERR; + default: return MOO_ESYSERR; } } @@ -214,9 +214,9 @@ stix_errnum_t stix_syserrtoerrnum (int e) * ASSERTION FAILURE HANDLER * -------------------------------------------------------------------------- */ -void stix_assertfailed (stix_t* stix, const stix_bch_t* expr, const stix_bch_t* file, stix_oow_t line) +void moo_assertfailed (moo_t* moo, const moo_bch_t* expr, const moo_bch_t* file, moo_oow_t line) { - stix_logbfmt (stix, STIX_LOG_DEBUG, "ASSERTION FAILURE: %s at %s:%zu\n", expr, file, line); + moo_logbfmt (moo, MOO_LOG_DEBUG, "ASSERTION FAILURE: %s at %s:%zu\n", expr, file, line); #if defined(_WIN32) ExitProcess (249); diff --git a/stix/lib/exec.c b/stix/lib/exec.c index f821b41..23de083 100644 --- a/stix/lib/exec.c +++ b/stix/lib/exec.c @@ -24,7 +24,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "stix-prv.h" +#include "moo-prv.h" /* TODO: remove these headers after having migrated system-dependent functions of of this file */ #if defined(_WIN32) @@ -72,66 +72,66 @@ #define SEM_HEAP_RIGHT(x) ((x) * 2 + 2) #define SEM_HEAP_EARLIER_THAN(stx,x,y) ( \ - (STIX_OOP_TO_SMOOI((x)->heap_ftime_sec) < STIX_OOP_TO_SMOOI((y)->heap_ftime_sec)) || \ - (STIX_OOP_TO_SMOOI((x)->heap_ftime_sec) == STIX_OOP_TO_SMOOI((y)->heap_ftime_sec) && STIX_OOP_TO_SMOOI((x)->heap_ftime_nsec) < STIX_OOP_TO_SMOOI((y)->heap_ftime_nsec)) \ + (MOO_OOP_TO_SMOOI((x)->heap_ftime_sec) < MOO_OOP_TO_SMOOI((y)->heap_ftime_sec)) || \ + (MOO_OOP_TO_SMOOI((x)->heap_ftime_sec) == MOO_OOP_TO_SMOOI((y)->heap_ftime_sec) && MOO_OOP_TO_SMOOI((x)->heap_ftime_nsec) < MOO_OOP_TO_SMOOI((y)->heap_ftime_nsec)) \ ) -#define LOAD_IP(stix, v_ctx) ((stix)->ip = STIX_OOP_TO_SMOOI((v_ctx)->ip)) -#define STORE_IP(stix, v_ctx) ((v_ctx)->ip = STIX_SMOOI_TO_OOP((stix)->ip)) +#define LOAD_IP(moo, v_ctx) ((moo)->ip = MOO_OOP_TO_SMOOI((v_ctx)->ip)) +#define STORE_IP(moo, v_ctx) ((v_ctx)->ip = MOO_SMOOI_TO_OOP((moo)->ip)) -#define LOAD_SP(stix, v_ctx) ((stix)->sp = STIX_OOP_TO_SMOOI((v_ctx)->sp)) -#define STORE_SP(stix, v_ctx) ((v_ctx)->sp = STIX_SMOOI_TO_OOP((stix)->sp)) +#define LOAD_SP(moo, v_ctx) ((moo)->sp = MOO_OOP_TO_SMOOI((v_ctx)->sp)) +#define STORE_SP(moo, v_ctx) ((v_ctx)->sp = MOO_SMOOI_TO_OOP((moo)->sp)) -#define LOAD_ACTIVE_IP(stix) LOAD_IP(stix, (stix)->active_context) -#define STORE_ACTIVE_IP(stix) STORE_IP(stix, (stix)->active_context) +#define LOAD_ACTIVE_IP(moo) LOAD_IP(moo, (moo)->active_context) +#define STORE_ACTIVE_IP(moo) STORE_IP(moo, (moo)->active_context) -#define LOAD_ACTIVE_SP(stix) LOAD_SP(stix, (stix)->processor->active) -#define STORE_ACTIVE_SP(stix) STORE_SP(stix, (stix)->processor->active) +#define LOAD_ACTIVE_SP(moo) LOAD_SP(moo, (moo)->processor->active) +#define STORE_ACTIVE_SP(moo) STORE_SP(moo, (moo)->processor->active) -#define SWITCH_ACTIVE_CONTEXT(stix,v_ctx) \ +#define SWITCH_ACTIVE_CONTEXT(moo,v_ctx) \ do \ { \ - STORE_ACTIVE_IP (stix); \ - (stix)->active_context = (v_ctx); \ - (stix)->active_method = (stix_oop_method_t)(stix)->active_context->origin->method_or_nargs; \ - SET_ACTIVE_METHOD_CODE(stix); \ - LOAD_ACTIVE_IP (stix); \ - (stix)->processor->active->current_context = (stix)->active_context; \ + STORE_ACTIVE_IP (moo); \ + (moo)->active_context = (v_ctx); \ + (moo)->active_method = (moo_oop_method_t)(moo)->active_context->origin->method_or_nargs; \ + SET_ACTIVE_METHOD_CODE(moo); \ + LOAD_ACTIVE_IP (moo); \ + (moo)->processor->active->current_context = (moo)->active_context; \ } while (0) -#define FETCH_BYTE_CODE(stix) ((stix)->active_code[(stix)->ip++]) -#define FETCH_BYTE_CODE_TO(stix, v_ooi) (v_ooi = FETCH_BYTE_CODE(stix)) -#if (STIX_BCODE_LONG_PARAM_SIZE == 2) -# define FETCH_PARAM_CODE_TO(stix, v_ooi) \ +#define FETCH_BYTE_CODE(moo) ((moo)->active_code[(moo)->ip++]) +#define FETCH_BYTE_CODE_TO(moo, v_ooi) (v_ooi = FETCH_BYTE_CODE(moo)) +#if (MOO_BCODE_LONG_PARAM_SIZE == 2) +# define FETCH_PARAM_CODE_TO(moo, v_ooi) \ do { \ - v_ooi = FETCH_BYTE_CODE(stix); \ - v_ooi = (v_ooi << 8) | FETCH_BYTE_CODE(stix); \ + v_ooi = FETCH_BYTE_CODE(moo); \ + v_ooi = (v_ooi << 8) | FETCH_BYTE_CODE(moo); \ } while (0) #else -# define FETCH_PARAM_CODE_TO(stix, v_ooi) (v_ooi = FETCH_BYTE_CODE(stix)) +# define FETCH_PARAM_CODE_TO(moo, v_ooi) (v_ooi = FETCH_BYTE_CODE(moo)) #endif -#if defined(STIX_DEBUG_VM_EXEC) -# define LOG_MASK_INST (STIX_LOG_IC | STIX_LOG_MNEMONIC) +#if defined(MOO_DEBUG_VM_EXEC) +# define LOG_MASK_INST (MOO_LOG_IC | MOO_LOG_MNEMONIC) /* TODO: for send_message, display the method name. or include the method name before 'ip' */ -# define LOG_INST_0(stix,fmt) STIX_LOG1(stix, LOG_MASK_INST, " %06zd " fmt "\n", fetched_instruction_pointer) -# define LOG_INST_1(stix,fmt,a1) STIX_LOG2(stix, LOG_MASK_INST, " %06zd " fmt "\n",fetched_instruction_pointer, a1) -# define LOG_INST_2(stix,fmt,a1,a2) STIX_LOG3(stix, LOG_MASK_INST, " %06zd " fmt "\n", fetched_instruction_pointer, a1, a2) -# define LOG_INST_3(stix,fmt,a1,a2,a3) STIX_LOG4(stix, LOG_MASK_INST, " %06zd " fmt "\n", fetched_instruction_pointer, a1, a2, a3) +# define LOG_INST_0(moo,fmt) MOO_LOG1(moo, LOG_MASK_INST, " %06zd " fmt "\n", fetched_instruction_pointer) +# define LOG_INST_1(moo,fmt,a1) MOO_LOG2(moo, LOG_MASK_INST, " %06zd " fmt "\n",fetched_instruction_pointer, a1) +# define LOG_INST_2(moo,fmt,a1,a2) MOO_LOG3(moo, LOG_MASK_INST, " %06zd " fmt "\n", fetched_instruction_pointer, a1, a2) +# define LOG_INST_3(moo,fmt,a1,a2,a3) MOO_LOG4(moo, LOG_MASK_INST, " %06zd " fmt "\n", fetched_instruction_pointer, a1, a2, a3) #else -# define LOG_INST_0(stix,fmt) -# define LOG_INST_1(stix,fmt,a1) -# define LOG_INST_2(stix,fmt,a1,a2) -# define LOG_INST_3(stix,fmt,a1,a2,a3) +# define LOG_INST_0(moo,fmt) +# define LOG_INST_1(moo,fmt,a1) +# define LOG_INST_2(moo,fmt,a1,a2) +# define LOG_INST_3(moo,fmt,a1,a2,a3) #endif #define __PRIMITIVE_NAME__ (&__FUNCTION__[4]) /* ------------------------------------------------------------------------- */ -static STIX_INLINE void vm_gettime (stix_t* stix, stix_ntime_t* now) +static MOO_INLINE void vm_gettime (moo_t* moo, moo_ntime_t* now) { #if defined(_WIN32) @@ -142,10 +142,10 @@ static STIX_INLINE void vm_gettime (stix_t* stix, stix_ntime_t* now) /* TODO: handle overflow?? */ /* TODO: use DosTmrQueryTime() and DosTmrQueryFreq()? */ - DosQuerySysInfo (QSV_MS_COUNT, QSV_MS_COUNT, &out, STIX_SIZEOF(out)); /* milliseconds */ + DosQuerySysInfo (QSV_MS_COUNT, QSV_MS_COUNT, &out, MOO_SIZEOF(out)); /* milliseconds */ /* it must return NO_ERROR */ - STIX_INITNTIME (now, STIX_MSEC_TO_SEC(out), STIX_MSEC_TO_NSEC(out)); + MOO_INITNTIME (now, MOO_MSEC_TO_SEC(out), MOO_MSEC_TO_NSEC(out)); #elif defined(__MSDOS__) && defined(_INTELC32_) clock_t c; @@ -153,9 +153,9 @@ static STIX_INLINE void vm_gettime (stix_t* stix, stix_ntime_t* now) c = clock (); now->sec = c / CLOCKS_PER_SEC; #if (CLOCKS_PER_SEC == 1000) - now->nsec = STIX_MSEC_TO_NSEC(c % CLOCKS_PER_SEC); + now->nsec = MOO_MSEC_TO_NSEC(c % CLOCKS_PER_SEC); #elif (CLOCKS_PER_SEC == 1000000L) - now->nsec = STIX_USEC_TO_NSEC(c % CLOCKS_PER_SEC); + now->nsec = MOO_USEC_TO_NSEC(c % CLOCKS_PER_SEC); #elif (CLOCKS_PER_SEC == 1000000000L) now->nsec = (c % CLOCKS_PER_SEC); #else @@ -163,57 +163,57 @@ static STIX_INLINE void vm_gettime (stix_t* stix, stix_ntime_t* now) #endif #elif defined(macintosh) UnsignedWide tick; - stix_uint64_t tick64; + moo_uint64_t tick64; Microseconds (&tick); - tick64 = *(stix_uint64_t*)&tick; - STIX_INITNTIME (now, STIX_USEC_TO_SEC(tick64), STIX_USEC_TO_NSEC(tick64)); + tick64 = *(moo_uint64_t*)&tick; + MOO_INITNTIME (now, MOO_USEC_TO_SEC(tick64), MOO_USEC_TO_NSEC(tick64)); #elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) struct timespec ts; clock_gettime (CLOCK_MONOTONIC, &ts); - STIX_INITNTIME(now, ts.tv_sec, ts.tv_nsec); + MOO_INITNTIME(now, ts.tv_sec, ts.tv_nsec); #elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_REALTIME) struct timespec ts; clock_gettime (CLOCK_REALTIME, &ts); - STIX_INITNTIME(now, ts.tv_sec, ts.tv_nsec); - STIX_SUBNTIME (now, now, &stix->vm_time_offset); /* offset */ + MOO_INITNTIME(now, ts.tv_sec, ts.tv_nsec); + MOO_SUBNTIME (now, now, &moo->vm_time_offset); /* offset */ #else struct timeval tv; - gettimeofday (&tv, STIX_NULL); - STIX_INITNTIME(now, tv.tv_sec, STIX_USEC_TO_NSEC(tv.tv_usec)); + gettimeofday (&tv, MOO_NULL); + MOO_INITNTIME(now, tv.tv_sec, MOO_USEC_TO_NSEC(tv.tv_usec)); /* at the first call, vm_time_offset should be 0. so subtraction takes * no effect. once it becomes non-zero, it offsets the actual time. * this is to keep the returned time small enough to be held in a * small integer on platforms where the small integer is not large enough */ - STIX_SUBNTIME (now, now, &stix->vm_time_offset); + MOO_SUBNTIME (now, now, &moo->vm_time_offset); #endif } -static STIX_INLINE void vm_sleep (stix_t* stix, const stix_ntime_t* dur) +static MOO_INLINE void vm_sleep (moo_t* moo, const moo_ntime_t* dur) { #if defined(_WIN32) - if (stix->waitable_timer) + if (moo->waitable_timer) { LARGE_INTEGER li; - li.QuadPart = -STIX_SECNSEC_TO_NSEC(dur->sec, dur->nsec); - if(SetWaitableTimer(timer, &li, 0, STIX_NULL, STIX_NULL, FALSE) == FALSE) goto normal_sleep; + li.QuadPart = -MOO_SECNSEC_TO_NSEC(dur->sec, dur->nsec); + if(SetWaitableTimer(timer, &li, 0, MOO_NULL, MOO_NULL, FALSE) == FALSE) goto normal_sleep; WaitForSingleObject(timer, INFINITE); } else { normal_sleep: /* fallback to normal Sleep() */ - Sleep (STIX_SECNSEC_TO_MSEC(dur->sec,dur->nsec)); + Sleep (MOO_SECNSEC_TO_MSEC(dur->sec,dur->nsec)); } #elif defined(__OS2__) /* TODO: in gui mode, this is not a desirable method??? * this must be made event-driven coupled with the main event loop */ - DosSleep (STIX_SECNSEC_TO_MSEC(dur->sec,dur->nsec)); + DosSleep (MOO_SECNSEC_TO_MSEC(dur->sec,dur->nsec)); #elif defined(macintosh) @@ -226,9 +226,9 @@ static STIX_INLINE void vm_sleep (stix_t* stix, const stix_ntime_t* dur) c = clock (); c += dur->sec * CLOCKS_PER_SEC; #if (CLOCKS_PER_SEC == 1000) - c += STIX_NSEC_TO_MSEC(dur->nsec); + c += MOO_NSEC_TO_MSEC(dur->nsec); #elif (CLOCKS_PER_SEC == 1000000L) - c += STIX_NSEC_TO_USEC(dur->nsec); + c += MOO_NSEC_TO_USEC(dur->nsec); #elif (CLOCKS_PER_SEC == 1000000000L) c += dur->nsec; #else @@ -243,202 +243,202 @@ static STIX_INLINE void vm_sleep (stix_t* stix, const stix_ntime_t* dur) struct timespec ts; ts.tv_sec = dur->sec; ts.tv_nsec = dur->nsec; - nanosleep (&ts, STIX_NULL); + nanosleep (&ts, MOO_NULL); #endif } -static void vm_startup (stix_t* stix) +static void vm_startup (moo_t* moo) { - stix_ntime_t now; + moo_ntime_t now; #if defined(_WIN32) - stix->waitable_timer = CreateWaitableTimer(STIX_NULL, TRUE, STIX_NULL); + moo->waitable_timer = CreateWaitableTimer(MOO_NULL, TRUE, MOO_NULL); #endif - /* reset stix->vm_time_offset so that vm_gettime is not affected */ - STIX_INITNTIME(&stix->vm_time_offset, 0, 0); - vm_gettime (stix, &now); - stix->vm_time_offset = now; + /* reset moo->vm_time_offset so that vm_gettime is not affected */ + MOO_INITNTIME(&moo->vm_time_offset, 0, 0); + vm_gettime (moo, &now); + moo->vm_time_offset = now; } -static void vm_cleanup (stix_t* stix) +static void vm_cleanup (moo_t* moo) { #if defined(_WIN32) - if (stix->waitable_timer) + if (moo->waitable_timer) { - CloseHandle (stix->waitable_timer); - stix->waitable_timer = STIX_NULL; + CloseHandle (moo->waitable_timer); + moo->waitable_timer = MOO_NULL; } #endif } /* ------------------------------------------------------------------------- */ -static stix_oop_process_t make_process (stix_t* stix, stix_oop_context_t c) +static moo_oop_process_t make_process (moo_t* moo, moo_oop_context_t c) { - stix_oop_process_t proc; + moo_oop_process_t proc; - stix_pushtmp (stix, (stix_oop_t*)&c); - proc = (stix_oop_process_t)stix_instantiate (stix, stix->_process, STIX_NULL, stix->option.dfl_procstk_size); - stix_poptmp (stix); - if (!proc) return STIX_NULL; + moo_pushtmp (moo, (moo_oop_t*)&c); + proc = (moo_oop_process_t)moo_instantiate (moo, moo->_process, MOO_NULL, moo->option.dfl_procstk_size); + moo_poptmp (moo); + if (!proc) return MOO_NULL; - proc->state = STIX_SMOOI_TO_OOP(PROC_STATE_SUSPENDED); + proc->state = MOO_SMOOI_TO_OOP(PROC_STATE_SUSPENDED); proc->initial_context = c; proc->current_context = c; - proc->sp = STIX_SMOOI_TO_OOP(-1); + proc->sp = MOO_SMOOI_TO_OOP(-1); - STIX_ASSERT (stix, (stix_oop_t)c->sender == stix->_nil); + MOO_ASSERT (moo, (moo_oop_t)c->sender == moo->_nil); -#if defined(STIX_DEBUG_VM_PROCESSOR) - STIX_LOG2 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "Processor - made process %O of size %zu\n", proc, STIX_OBJ_GET_SIZE(proc)); +#if defined(MOO_DEBUG_VM_PROCESSOR) + MOO_LOG2 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - made process %O of size %zu\n", proc, MOO_OBJ_GET_SIZE(proc)); #endif return proc; } -static STIX_INLINE void sleep_active_process (stix_t* stix, int state) +static MOO_INLINE void sleep_active_process (moo_t* moo, int state) { -#if defined(STIX_DEBUG_VM_PROCESSOR) - STIX_LOG3 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "Processor - put process %O context %O ip=%zd to sleep\n", stix->processor->active, stix->active_context, stix->ip); +#if defined(MOO_DEBUG_VM_PROCESSOR) + MOO_LOG3 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - put process %O context %O ip=%zd to sleep\n", moo->processor->active, moo->active_context, moo->ip); #endif - STORE_ACTIVE_SP(stix); + STORE_ACTIVE_SP(moo); /* store the current active context to the current process. * it is the suspended context of the process to be suspended */ - STIX_ASSERT (stix, stix->processor->active != stix->nil_process); - stix->processor->active->current_context = stix->active_context; - stix->processor->active->state = STIX_SMOOI_TO_OOP(state); + MOO_ASSERT (moo, moo->processor->active != moo->nil_process); + moo->processor->active->current_context = moo->active_context; + moo->processor->active->state = MOO_SMOOI_TO_OOP(state); } -static STIX_INLINE void wake_new_process (stix_t* stix, stix_oop_process_t proc) +static MOO_INLINE void wake_new_process (moo_t* moo, moo_oop_process_t proc) { /* activate the given process */ - proc->state = STIX_SMOOI_TO_OOP(PROC_STATE_RUNNING); - stix->processor->active = proc; + proc->state = MOO_SMOOI_TO_OOP(PROC_STATE_RUNNING); + moo->processor->active = proc; - LOAD_ACTIVE_SP(stix); + LOAD_ACTIVE_SP(moo); /* activate the suspended context of the new process */ - SWITCH_ACTIVE_CONTEXT (stix, proc->current_context); + SWITCH_ACTIVE_CONTEXT (moo, proc->current_context); -#if defined(STIX_DEBUG_VM_PROCESSOR) - STIX_LOG3 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "Processor - woke up process %O context %O ip=%zd\n", stix->processor->active, stix->active_context, stix->ip); +#if defined(MOO_DEBUG_VM_PROCESSOR) + MOO_LOG3 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - woke up process %O context %O ip=%zd\n", moo->processor->active, moo->active_context, moo->ip); #endif } -static void switch_to_process (stix_t* stix, stix_oop_process_t proc, int new_state_for_old_active) +static void switch_to_process (moo_t* moo, moo_oop_process_t proc, int new_state_for_old_active) { /* the new process must not be the currently active process */ - STIX_ASSERT (stix, stix->processor->active != proc); + MOO_ASSERT (moo, moo->processor->active != proc); /* the new process must be in the runnable state */ - STIX_ASSERT (stix, proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_RUNNABLE) || - proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_WAITING)); + MOO_ASSERT (moo, proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_RUNNABLE) || + proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_WAITING)); - sleep_active_process (stix, new_state_for_old_active); - wake_new_process (stix, proc); + sleep_active_process (moo, new_state_for_old_active); + wake_new_process (moo, proc); - stix->proc_switched = 1; + moo->proc_switched = 1; } -static STIX_INLINE stix_oop_process_t find_next_runnable_process (stix_t* stix) +static MOO_INLINE moo_oop_process_t find_next_runnable_process (moo_t* moo) { - stix_oop_process_t npr; + moo_oop_process_t npr; - STIX_ASSERT (stix, stix->processor->active->state == STIX_SMOOI_TO_OOP(PROC_STATE_RUNNING)); - npr = stix->processor->active->next; - if ((stix_oop_t)npr == stix->_nil) npr = stix->processor->runnable_head; + MOO_ASSERT (moo, moo->processor->active->state == MOO_SMOOI_TO_OOP(PROC_STATE_RUNNING)); + npr = moo->processor->active->next; + if ((moo_oop_t)npr == moo->_nil) npr = moo->processor->runnable_head; return npr; } -static STIX_INLINE void switch_to_next_runnable_process (stix_t* stix) +static MOO_INLINE void switch_to_next_runnable_process (moo_t* moo) { - stix_oop_process_t nrp; + moo_oop_process_t nrp; - nrp = find_next_runnable_process (stix); - if (nrp != stix->processor->active) switch_to_process (stix, nrp, PROC_STATE_RUNNABLE); + nrp = find_next_runnable_process (moo); + if (nrp != moo->processor->active) switch_to_process (moo, nrp, PROC_STATE_RUNNABLE); } -static STIX_INLINE int chain_into_processor (stix_t* stix, stix_oop_process_t proc) +static MOO_INLINE int chain_into_processor (moo_t* moo, moo_oop_process_t proc) { /* the process is not scheduled at all. * link it to the processor's process list. */ - stix_ooi_t tally; + moo_ooi_t tally; - STIX_ASSERT (stix, (stix_oop_t)proc->prev == stix->_nil); - STIX_ASSERT (stix, (stix_oop_t)proc->next == stix->_nil); + MOO_ASSERT (moo, (moo_oop_t)proc->prev == moo->_nil); + MOO_ASSERT (moo, (moo_oop_t)proc->next == moo->_nil); - STIX_ASSERT (stix, proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_SUSPENDED)); + MOO_ASSERT (moo, proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_SUSPENDED)); - tally = STIX_OOP_TO_SMOOI(stix->processor->tally); + tally = MOO_OOP_TO_SMOOI(moo->processor->tally); - STIX_ASSERT (stix, tally >= 0); - if (tally >= STIX_SMOOI_MAX) + MOO_ASSERT (moo, tally >= 0); + if (tally >= MOO_SMOOI_MAX) { -#if defined(STIX_DEBUG_VM_PROCESSOR) - STIX_LOG0 (stix, STIX_LOG_IC | STIX_LOG_FATAL, "Processor - too many process\n"); +#if defined(MOO_DEBUG_VM_PROCESSOR) + MOO_LOG0 (moo, MOO_LOG_IC | MOO_LOG_FATAL, "Processor - too many process\n"); #endif - stix->errnum = STIX_EPFULL; + moo->errnum = MOO_EPFULL; return -1; } /* append to the runnable list */ if (tally > 0) { - proc->prev = stix->processor->runnable_tail; - stix->processor->runnable_tail->next = proc; + proc->prev = moo->processor->runnable_tail; + moo->processor->runnable_tail->next = proc; } else { - stix->processor->runnable_head = proc; + moo->processor->runnable_head = proc; } - stix->processor->runnable_tail = proc; + moo->processor->runnable_tail = proc; tally++; - stix->processor->tally = STIX_SMOOI_TO_OOP(tally); + moo->processor->tally = MOO_SMOOI_TO_OOP(tally); return 0; } -static STIX_INLINE void unchain_from_processor (stix_t* stix, stix_oop_process_t proc, int state) +static MOO_INLINE void unchain_from_processor (moo_t* moo, moo_oop_process_t proc, int state) { - stix_ooi_t tally; + moo_ooi_t tally; /* the processor's process chain must be composed of running/runnable * processes only */ - STIX_ASSERT (stix, proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_RUNNING) || - proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_RUNNABLE)); + MOO_ASSERT (moo, proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_RUNNING) || + proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_RUNNABLE)); - tally = STIX_OOP_TO_SMOOI(stix->processor->tally); - STIX_ASSERT (stix, tally > 0); + tally = MOO_OOP_TO_SMOOI(moo->processor->tally); + MOO_ASSERT (moo, tally > 0); - if ((stix_oop_t)proc->prev != stix->_nil) proc->prev->next = proc->next; - else stix->processor->runnable_head = proc->next; - if ((stix_oop_t)proc->next != stix->_nil) proc->next->prev = proc->prev; - else stix->processor->runnable_tail = proc->prev; + if ((moo_oop_t)proc->prev != moo->_nil) proc->prev->next = proc->next; + else moo->processor->runnable_head = proc->next; + if ((moo_oop_t)proc->next != moo->_nil) proc->next->prev = proc->prev; + else moo->processor->runnable_tail = proc->prev; - proc->prev = (stix_oop_process_t)stix->_nil; - proc->next = (stix_oop_process_t)stix->_nil; - proc->state = STIX_SMOOI_TO_OOP(state); + proc->prev = (moo_oop_process_t)moo->_nil; + proc->next = (moo_oop_process_t)moo->_nil; + proc->state = MOO_SMOOI_TO_OOP(state); tally--; - if (tally == 0) stix->processor->active = stix->nil_process; - stix->processor->tally = STIX_SMOOI_TO_OOP(tally); + if (tally == 0) moo->processor->active = moo->nil_process; + moo->processor->tally = MOO_SMOOI_TO_OOP(tally); } -static STIX_INLINE void chain_into_semaphore (stix_t* stix, stix_oop_process_t proc, stix_oop_semaphore_t sem) +static MOO_INLINE void chain_into_semaphore (moo_t* moo, moo_oop_process_t proc, moo_oop_semaphore_t sem) { /* append a process to the process list of a semaphore*/ - STIX_ASSERT (stix, (stix_oop_t)proc->sem == stix->_nil); - STIX_ASSERT (stix, (stix_oop_t)proc->prev == stix->_nil); - STIX_ASSERT (stix, (stix_oop_t)proc->next == stix->_nil); + MOO_ASSERT (moo, (moo_oop_t)proc->sem == moo->_nil); + MOO_ASSERT (moo, (moo_oop_t)proc->prev == moo->_nil); + MOO_ASSERT (moo, (moo_oop_t)proc->next == moo->_nil); - if ((stix_oop_t)sem->waiting_head == stix->_nil) + if ((moo_oop_t)sem->waiting_head == moo->_nil) { - STIX_ASSERT (stix, (stix_oop_t)sem->waiting_tail == stix->_nil); + MOO_ASSERT (moo, (moo_oop_t)sem->waiting_tail == moo->_nil); sem->waiting_head = proc; } else @@ -451,322 +451,322 @@ static STIX_INLINE void chain_into_semaphore (stix_t* stix, stix_oop_process_t p proc->sem = sem; } -static STIX_INLINE void unchain_from_semaphore (stix_t* stix, stix_oop_process_t proc) +static MOO_INLINE void unchain_from_semaphore (moo_t* moo, moo_oop_process_t proc) { - stix_oop_semaphore_t sem; + moo_oop_semaphore_t sem; - STIX_ASSERT (stix, (stix_oop_t)proc->sem != stix->_nil); + MOO_ASSERT (moo, (moo_oop_t)proc->sem != moo->_nil); sem = proc->sem; - if ((stix_oop_t)proc->prev != stix->_nil) proc->prev->next = proc->next; + if ((moo_oop_t)proc->prev != moo->_nil) proc->prev->next = proc->next; else sem->waiting_head = proc->next; - if ((stix_oop_t)proc->next != stix->_nil) proc->next->prev = proc->prev; + if ((moo_oop_t)proc->next != moo->_nil) proc->next->prev = proc->prev; else sem->waiting_tail = proc->prev; - proc->prev = (stix_oop_process_t)stix->_nil; - proc->next = (stix_oop_process_t)stix->_nil; + proc->prev = (moo_oop_process_t)moo->_nil; + proc->next = (moo_oop_process_t)moo->_nil; - proc->sem = (stix_oop_semaphore_t)stix->_nil; + proc->sem = (moo_oop_semaphore_t)moo->_nil; } -static void terminate_process (stix_t* stix, stix_oop_process_t proc) +static void terminate_process (moo_t* moo, moo_oop_process_t proc) { - if (proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_RUNNING) || - proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_RUNNABLE)) + if (proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_RUNNING) || + proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_RUNNABLE)) { /* RUNNING/RUNNABLE ---> TERMINATED */ - #if defined(STIX_DEBUG_VM_PROCESSOR) - STIX_LOG1 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "Processor - process %O RUNNING/RUNNABLE->TERMINATED\n", proc); + #if defined(MOO_DEBUG_VM_PROCESSOR) + MOO_LOG1 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process %O RUNNING/RUNNABLE->TERMINATED\n", proc); #endif - if (proc == stix->processor->active) + if (proc == moo->processor->active) { - stix_oop_process_t nrp; + moo_oop_process_t nrp; - nrp = find_next_runnable_process (stix); + nrp = find_next_runnable_process (moo); - unchain_from_processor (stix, proc, PROC_STATE_TERMINATED); - proc->sp = STIX_SMOOI_TO_OOP(-1); /* invalidate the process stack */ + unchain_from_processor (moo, proc, PROC_STATE_TERMINATED); + proc->sp = MOO_SMOOI_TO_OOP(-1); /* invalidate the process stack */ proc->current_context = proc->initial_context; /* not needed but just in case */ /* a runnable or running process must not be chanined to the * process list of a semaphore */ - STIX_ASSERT (stix, (stix_oop_t)proc->sem == stix->_nil); + MOO_ASSERT (moo, (moo_oop_t)proc->sem == moo->_nil); if (nrp == proc) { /* no runnable process after termination */ - STIX_ASSERT (stix, stix->processor->active == stix->nil_process); - STIX_LOG0 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "No runnable process after process termination\n"); + MOO_ASSERT (moo, moo->processor->active == moo->nil_process); + MOO_LOG0 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "No runnable process after process termination\n"); } else { - switch_to_process (stix, nrp, PROC_STATE_TERMINATED); + switch_to_process (moo, nrp, PROC_STATE_TERMINATED); } } else { - unchain_from_processor (stix, proc, PROC_STATE_TERMINATED); - proc->sp = STIX_SMOOI_TO_OOP(-1); /* invalidate the process stack */ + unchain_from_processor (moo, proc, PROC_STATE_TERMINATED); + proc->sp = MOO_SMOOI_TO_OOP(-1); /* invalidate the process stack */ } } - else if (proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_SUSPENDED)) + else if (proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_SUSPENDED)) { /* SUSPENDED ---> TERMINATED */ - #if defined(STIX_DEBUG_VM_PROCESSOR) - STIX_LOG1 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "Processor - process %O SUSPENDED->TERMINATED\n", proc); + #if defined(MOO_DEBUG_VM_PROCESSOR) + MOO_LOG1 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process %O SUSPENDED->TERMINATED\n", proc); #endif - proc->state = STIX_SMOOI_TO_OOP(PROC_STATE_TERMINATED); - proc->sp = STIX_SMOOI_TO_OOP(-1); /* invalidate the proce stack */ + proc->state = MOO_SMOOI_TO_OOP(PROC_STATE_TERMINATED); + proc->sp = MOO_SMOOI_TO_OOP(-1); /* invalidate the proce stack */ - if ((stix_oop_t)proc->sem != stix->_nil) + if ((moo_oop_t)proc->sem != moo->_nil) { - unchain_from_semaphore (stix, proc); + unchain_from_semaphore (moo, proc); } } - else if (proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_WAITING)) + else if (proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_WAITING)) { /* WAITING ---> TERMINATED */ /* TODO: */ } } -static void resume_process (stix_t* stix, stix_oop_process_t proc) +static void resume_process (moo_t* moo, moo_oop_process_t proc) { - if (proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_SUSPENDED)) + if (proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_SUSPENDED)) { /* SUSPENED ---> RUNNING */ - STIX_ASSERT (stix, (stix_oop_t)proc->prev == stix->_nil); - STIX_ASSERT (stix, (stix_oop_t)proc->next == stix->_nil); + MOO_ASSERT (moo, (moo_oop_t)proc->prev == moo->_nil); + MOO_ASSERT (moo, (moo_oop_t)proc->next == moo->_nil); - #if defined(STIX_DEBUG_VM_PROCESSOR) - STIX_LOG1 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "Processor - process %O SUSPENDED->RUNNING\n", proc); + #if defined(MOO_DEBUG_VM_PROCESSOR) + MOO_LOG1 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process %O SUSPENDED->RUNNING\n", proc); #endif - chain_into_processor (stix, proc); /* TODO: error check */ + chain_into_processor (moo, proc); /* TODO: error check */ /*proc->current_context = proc->initial_context;*/ - proc->state = STIX_SMOOI_TO_OOP(PROC_STATE_RUNNABLE); + proc->state = MOO_SMOOI_TO_OOP(PROC_STATE_RUNNABLE); /* don't switch to this process. just set the state to RUNNING */ } #if 0 - else if (proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_RUNNABLE)) + else if (proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_RUNNABLE)) { /* RUNNABLE ---> RUNNING */ /* TODO: should i allow this? */ - STIX_ASSERT (stix, stix->processor->active != proc); - switch_to_process (stix, proc, PROC_STATE_RUNNABLE); + MOO_ASSERT (moo, moo->processor->active != proc); + switch_to_process (moo, proc, PROC_STATE_RUNNABLE); } #endif } -static void suspend_process (stix_t* stix, stix_oop_process_t proc) +static void suspend_process (moo_t* moo, moo_oop_process_t proc) { - if (proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_RUNNING) || - proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_RUNNABLE)) + if (proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_RUNNING) || + proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_RUNNABLE)) { /* RUNNING/RUNNABLE ---> SUSPENDED */ - #if defined(STIX_DEBUG_VM_PROCESSOR) - STIX_LOG1 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "Processor - process %O RUNNING/RUNNABLE->SUSPENDED\n", proc); + #if defined(MOO_DEBUG_VM_PROCESSOR) + MOO_LOG1 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process %O RUNNING/RUNNABLE->SUSPENDED\n", proc); #endif - if (proc == stix->processor->active) + if (proc == moo->processor->active) { - stix_oop_process_t nrp; + moo_oop_process_t nrp; - nrp = find_next_runnable_process (stix); + nrp = find_next_runnable_process (moo); if (nrp == proc) { /* no runnable process after suspension */ - sleep_active_process (stix, PROC_STATE_RUNNABLE); - unchain_from_processor (stix, proc, PROC_STATE_SUSPENDED); + sleep_active_process (moo, PROC_STATE_RUNNABLE); + unchain_from_processor (moo, proc, PROC_STATE_SUSPENDED); /* the last running/runnable process has been unchained * from the processor and set to SUSPENDED. the active * process must be the nil process */ - STIX_ASSERT (stix, stix->processor->active == stix->nil_process); + MOO_ASSERT (moo, moo->processor->active == moo->nil_process); } else { /* keep the unchained process at the runnable state for * the immediate call to switch_to_process() below */ - unchain_from_processor (stix, proc, PROC_STATE_RUNNABLE); + unchain_from_processor (moo, proc, PROC_STATE_RUNNABLE); /* unchain_from_processor() leaves the active process * untouched unless the unchained process is the last * running/runnable process. so calling switch_to_process() * which expects the active process to be valid is safe */ - STIX_ASSERT (stix, stix->processor->active != stix->nil_process); - switch_to_process (stix, nrp, PROC_STATE_SUSPENDED); + MOO_ASSERT (moo, moo->processor->active != moo->nil_process); + switch_to_process (moo, nrp, PROC_STATE_SUSPENDED); } } else { - unchain_from_processor (stix, proc, PROC_STATE_SUSPENDED); + unchain_from_processor (moo, proc, PROC_STATE_SUSPENDED); } } } -static void yield_process (stix_t* stix, stix_oop_process_t proc) +static void yield_process (moo_t* moo, moo_oop_process_t proc) { - if (proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_RUNNING)) + if (proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_RUNNING)) { /* RUNNING --> RUNNABLE */ - stix_oop_process_t nrp; + moo_oop_process_t nrp; - STIX_ASSERT (stix, proc == stix->processor->active); + MOO_ASSERT (moo, proc == moo->processor->active); - nrp = find_next_runnable_process (stix); + nrp = find_next_runnable_process (moo); /* if there are more than 1 runnable processes, the next * runnable process must be different from proc */ if (nrp != proc) { - #if defined(STIX_DEBUG_VM_PROCESSOR) - STIX_LOG1 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "Processor - process %O RUNNING->RUNNABLE\n", proc); + #if defined(MOO_DEBUG_VM_PROCESSOR) + MOO_LOG1 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "Processor - process %O RUNNING->RUNNABLE\n", proc); #endif - switch_to_process (stix, nrp, PROC_STATE_RUNNABLE); + switch_to_process (moo, nrp, PROC_STATE_RUNNABLE); } } } -static int async_signal_semaphore (stix_t* stix, stix_oop_semaphore_t sem) +static int async_signal_semaphore (moo_t* moo, moo_oop_semaphore_t sem) { - if (stix->sem_list_count >= SEM_LIST_MAX) + if (moo->sem_list_count >= SEM_LIST_MAX) { - stix->errnum = STIX_ESLFULL; + moo->errnum = MOO_ESLFULL; return -1; } - if (stix->sem_list_count >= stix->sem_list_capa) + if (moo->sem_list_count >= moo->sem_list_capa) { - stix_oow_t new_capa; - stix_oop_semaphore_t* tmp; + moo_oow_t new_capa; + moo_oop_semaphore_t* tmp; - new_capa = stix->sem_list_capa + SEM_LIST_INC; /* TODO: overflow check.. */ - tmp = stix_reallocmem (stix, stix->sem_list, STIX_SIZEOF(stix_oop_semaphore_t) * new_capa); + new_capa = moo->sem_list_capa + SEM_LIST_INC; /* TODO: overflow check.. */ + tmp = moo_reallocmem (moo, moo->sem_list, MOO_SIZEOF(moo_oop_semaphore_t) * new_capa); if (!tmp) return -1; - stix->sem_list = tmp; - stix->sem_list_capa = new_capa; + moo->sem_list = tmp; + moo->sem_list_capa = new_capa; } - stix->sem_list[stix->sem_list_count] = sem; - stix->sem_list_count++; + moo->sem_list[moo->sem_list_count] = sem; + moo->sem_list_count++; return 0; } -static stix_oop_process_t signal_semaphore (stix_t* stix, stix_oop_semaphore_t sem) +static moo_oop_process_t signal_semaphore (moo_t* moo, moo_oop_semaphore_t sem) { - stix_oop_process_t proc; - stix_ooi_t count; + moo_oop_process_t proc; + moo_ooi_t count; - if ((stix_oop_t)sem->waiting_head == stix->_nil) + if ((moo_oop_t)sem->waiting_head == moo->_nil) { /* no process is waiting on this semaphore */ - count = STIX_OOP_TO_SMOOI(sem->count); + count = MOO_OOP_TO_SMOOI(sem->count); count++; - sem->count = STIX_SMOOI_TO_OOP(count); + sem->count = MOO_SMOOI_TO_OOP(count); /* no process has been resumed */ - return (stix_oop_process_t)stix->_nil; + return (moo_oop_process_t)moo->_nil; } else { proc = sem->waiting_head; - /* [NOTE] no GC must occur as 'proc' isn't protected with stix_pushtmp(). */ + /* [NOTE] no GC must occur as 'proc' isn't protected with moo_pushtmp(). */ - unchain_from_semaphore (stix, proc); - resume_process (stix, proc); /* TODO: error check */ + unchain_from_semaphore (moo, proc); + resume_process (moo, proc); /* TODO: error check */ /* return the resumed process */ return proc; } } -static void await_semaphore (stix_t* stix, stix_oop_semaphore_t sem) +static void await_semaphore (moo_t* moo, moo_oop_semaphore_t sem) { - stix_oop_process_t proc; - stix_ooi_t count; + moo_oop_process_t proc; + moo_ooi_t count; - count = STIX_OOP_TO_SMOOI(sem->count); + count = MOO_OOP_TO_SMOOI(sem->count); if (count > 0) { /* it's already signalled */ count--; - sem->count = STIX_SMOOI_TO_OOP(count); + sem->count = MOO_SMOOI_TO_OOP(count); } else { /* not signaled. need to wait */ - proc = stix->processor->active; + proc = moo->processor->active; /* suspend the active process */ - suspend_process (stix, proc); + suspend_process (moo, proc); /* link the suspended process to the semaphore's process list */ - chain_into_semaphore (stix, proc, sem); + chain_into_semaphore (moo, proc, sem); - STIX_ASSERT (stix, sem->waiting_tail == proc); + MOO_ASSERT (moo, sem->waiting_tail == proc); - STIX_ASSERT (stix, stix->processor->active != proc); + MOO_ASSERT (moo, moo->processor->active != proc); } } -static void sift_up_sem_heap (stix_t* stix, stix_ooi_t index) +static void sift_up_sem_heap (moo_t* moo, moo_ooi_t index) { if (index > 0) { - stix_ooi_t parent; - stix_oop_semaphore_t sem, parsem; + moo_ooi_t parent; + moo_oop_semaphore_t sem, parsem; parent = SEM_HEAP_PARENT(index); - sem = stix->sem_heap[index]; - parsem = stix->sem_heap[parent]; - if (SEM_HEAP_EARLIER_THAN(stix, sem, parsem)) + sem = moo->sem_heap[index]; + parsem = moo->sem_heap[parent]; + if (SEM_HEAP_EARLIER_THAN(moo, sem, parsem)) { do { /* move down the parent to the current position */ - parsem->heap_index = STIX_SMOOI_TO_OOP(index); - stix->sem_heap[index] = parsem; + parsem->heap_index = MOO_SMOOI_TO_OOP(index); + moo->sem_heap[index] = parsem; /* traverse up */ index = parent; if (index <= 0) break; parent = SEM_HEAP_PARENT(parent); - parsem = stix->sem_heap[parent]; + parsem = moo->sem_heap[parent]; } - while (SEM_HEAP_EARLIER_THAN(stix, sem, parsem)); + while (SEM_HEAP_EARLIER_THAN(moo, sem, parsem)); - sem->heap_index = STIX_SMOOI_TO_OOP(index); - stix->sem_heap[index] = sem; + sem->heap_index = MOO_SMOOI_TO_OOP(index); + moo->sem_heap[index] = sem; } } } -static void sift_down_sem_heap (stix_t* stix, stix_ooi_t index) +static void sift_down_sem_heap (moo_t* moo, moo_ooi_t index) { - stix_ooi_t base = stix->sem_heap_count / 2; + moo_ooi_t base = moo->sem_heap_count / 2; if (index < base) /* at least 1 child is under the 'index' position */ { - stix_ooi_t left, right, child; - stix_oop_semaphore_t sem, chisem; + moo_ooi_t left, right, child; + moo_oop_semaphore_t sem, chisem; - sem = stix->sem_heap[index]; + sem = moo->sem_heap[index]; do { left = SEM_HEAP_LEFT(index); right = SEM_HEAP_RIGHT(index); - if (right < stix->sem_heap_count && SEM_HEAP_EARLIER_THAN(stix, stix->sem_heap[left], stix->sem_heap[right])) + if (right < moo->sem_heap_count && SEM_HEAP_EARLIER_THAN(moo, moo->sem_heap[left], moo->sem_heap[right])) { child = right; } @@ -775,146 +775,146 @@ static void sift_down_sem_heap (stix_t* stix, stix_ooi_t index) child = left; } - chisem = stix->sem_heap[child]; - if (SEM_HEAP_EARLIER_THAN(stix, sem, chisem)) break; + chisem = moo->sem_heap[child]; + if (SEM_HEAP_EARLIER_THAN(moo, sem, chisem)) break; - chisem->heap_index = STIX_SMOOI_TO_OOP(index); - stix->sem_heap[index ] = chisem; + chisem->heap_index = MOO_SMOOI_TO_OOP(index); + moo->sem_heap[index ] = chisem; index = child; } while (index < base); - sem->heap_index = STIX_SMOOI_TO_OOP(index); - stix->sem_heap[index] = sem; + sem->heap_index = MOO_SMOOI_TO_OOP(index); + moo->sem_heap[index] = sem; } } -static int add_to_sem_heap (stix_t* stix, stix_oop_semaphore_t sem) +static int add_to_sem_heap (moo_t* moo, moo_oop_semaphore_t sem) { - stix_ooi_t index; + moo_ooi_t index; - if (stix->sem_heap_count >= SEM_HEAP_MAX) + if (moo->sem_heap_count >= SEM_HEAP_MAX) { - stix->errnum = STIX_ESHFULL; + moo->errnum = MOO_ESHFULL; return -1; } - if (stix->sem_heap_count >= stix->sem_heap_capa) + if (moo->sem_heap_count >= moo->sem_heap_capa) { - stix_oow_t new_capa; - stix_oop_semaphore_t* tmp; + moo_oow_t new_capa; + moo_oop_semaphore_t* tmp; /* no overflow check when calculating the new capacity * owing to SEM_HEAP_MAX check above */ - new_capa = stix->sem_heap_capa + SEM_HEAP_INC; - tmp = stix_reallocmem (stix, stix->sem_heap, STIX_SIZEOF(stix_oop_semaphore_t) * new_capa); + new_capa = moo->sem_heap_capa + SEM_HEAP_INC; + tmp = moo_reallocmem (moo, moo->sem_heap, MOO_SIZEOF(moo_oop_semaphore_t) * new_capa); if (!tmp) return -1; - stix->sem_heap = tmp; - stix->sem_heap_capa = new_capa; + moo->sem_heap = tmp; + moo->sem_heap_capa = new_capa; } - STIX_ASSERT (stix, stix->sem_heap_count <= STIX_SMOOI_MAX); + MOO_ASSERT (moo, moo->sem_heap_count <= MOO_SMOOI_MAX); - index = stix->sem_heap_count; - stix->sem_heap[index] = sem; - sem->heap_index = STIX_SMOOI_TO_OOP(index); - stix->sem_heap_count++; + index = moo->sem_heap_count; + moo->sem_heap[index] = sem; + sem->heap_index = MOO_SMOOI_TO_OOP(index); + moo->sem_heap_count++; - sift_up_sem_heap (stix, index); + sift_up_sem_heap (moo, index); return 0; } -static void delete_from_sem_heap (stix_t* stix, stix_ooi_t index) +static void delete_from_sem_heap (moo_t* moo, moo_ooi_t index) { - stix_oop_semaphore_t sem, lastsem; + moo_oop_semaphore_t sem, lastsem; - sem = stix->sem_heap[index]; - sem->heap_index = STIX_SMOOI_TO_OOP(-1); + sem = moo->sem_heap[index]; + sem->heap_index = MOO_SMOOI_TO_OOP(-1); - stix->sem_heap_count--; - if (stix->sem_heap_count > 0 && index != stix->sem_heap_count) + moo->sem_heap_count--; + if (moo->sem_heap_count > 0 && index != moo->sem_heap_count) { /* move the last item to the deletion position */ - lastsem = stix->sem_heap[stix->sem_heap_count]; - lastsem->heap_index = STIX_SMOOI_TO_OOP(index); - stix->sem_heap[index] = lastsem; + lastsem = moo->sem_heap[moo->sem_heap_count]; + lastsem->heap_index = MOO_SMOOI_TO_OOP(index); + moo->sem_heap[index] = lastsem; - if (SEM_HEAP_EARLIER_THAN(stix, lastsem, sem)) - sift_up_sem_heap (stix, index); + if (SEM_HEAP_EARLIER_THAN(moo, lastsem, sem)) + sift_up_sem_heap (moo, index); else - sift_down_sem_heap (stix, index); + sift_down_sem_heap (moo, index); } } -static void update_sem_heap (stix_t* stix, stix_ooi_t index, stix_oop_semaphore_t newsem) +static void update_sem_heap (moo_t* moo, moo_ooi_t index, moo_oop_semaphore_t newsem) { - stix_oop_semaphore_t sem; + moo_oop_semaphore_t sem; - sem = stix->sem_heap[index]; - sem->heap_index = STIX_SMOOI_TO_OOP(-1); + sem = moo->sem_heap[index]; + sem->heap_index = MOO_SMOOI_TO_OOP(-1); - newsem->heap_index = STIX_SMOOI_TO_OOP(index); - stix->sem_heap[index] = newsem; + newsem->heap_index = MOO_SMOOI_TO_OOP(index); + moo->sem_heap[index] = newsem; - if (SEM_HEAP_EARLIER_THAN(stix, newsem, sem)) - sift_up_sem_heap (stix, index); + if (SEM_HEAP_EARLIER_THAN(moo, newsem, sem)) + sift_up_sem_heap (moo, index); else - sift_down_sem_heap (stix, index); + sift_down_sem_heap (moo, index); } -static stix_oop_process_t start_initial_process (stix_t* stix, stix_oop_context_t c) +static moo_oop_process_t start_initial_process (moo_t* moo, moo_oop_context_t c) { - stix_oop_process_t proc; + moo_oop_process_t proc; /* there must be no active process when this function is called */ - STIX_ASSERT (stix, stix->processor->tally == STIX_SMOOI_TO_OOP(0)); - STIX_ASSERT (stix, stix->processor->active == stix->nil_process); + MOO_ASSERT (moo, moo->processor->tally == MOO_SMOOI_TO_OOP(0)); + MOO_ASSERT (moo, moo->processor->active == moo->nil_process); - proc = make_process (stix, c); - if (!proc) return STIX_NULL; + proc = make_process (moo, c); + if (!proc) return MOO_NULL; - if (chain_into_processor (stix, proc) <= -1) return STIX_NULL; - proc->state = STIX_SMOOI_TO_OOP(PROC_STATE_RUNNING); /* skip RUNNABLE and go to RUNNING */ - stix->processor->active = proc; + if (chain_into_processor (moo, proc) <= -1) return MOO_NULL; + proc->state = MOO_SMOOI_TO_OOP(PROC_STATE_RUNNING); /* skip RUNNABLE and go to RUNNING */ + moo->processor->active = proc; /* do somthing that resume_process() would do with less overhead */ - STIX_ASSERT (stix, (stix_oop_t)proc->current_context != stix->_nil); - STIX_ASSERT (stix, proc->current_context == proc->initial_context); - SWITCH_ACTIVE_CONTEXT (stix, proc->current_context); + MOO_ASSERT (moo, (moo_oop_t)proc->current_context != moo->_nil); + MOO_ASSERT (moo, proc->current_context == proc->initial_context); + SWITCH_ACTIVE_CONTEXT (moo, proc->current_context); return proc; } -static STIX_INLINE int activate_new_method (stix_t* stix, stix_oop_method_t mth, stix_ooi_t actual_nargs) +static MOO_INLINE int activate_new_method (moo_t* moo, moo_oop_method_t mth, moo_ooi_t actual_nargs) { - stix_oop_context_t ctx; - stix_ooi_t i, j; - stix_ooi_t ntmprs, nargs, actual_ntmprs; + moo_oop_context_t ctx; + moo_ooi_t i, j; + moo_ooi_t ntmprs, nargs, actual_ntmprs; - ntmprs = STIX_OOP_TO_SMOOI(mth->tmpr_count); - nargs = STIX_OOP_TO_SMOOI(mth->tmpr_nargs); + ntmprs = MOO_OOP_TO_SMOOI(mth->tmpr_count); + nargs = MOO_OOP_TO_SMOOI(mth->tmpr_nargs); - STIX_ASSERT (stix, ntmprs >= 0); - STIX_ASSERT (stix, nargs <= ntmprs); + MOO_ASSERT (moo, ntmprs >= 0); + MOO_ASSERT (moo, nargs <= ntmprs); if (actual_nargs > nargs) { /* more arguments than the method specification have been passed in. * it must be a variadic unary method. othewise, the compiler is buggy */ - STIX_ASSERT (stix, STIX_METHOD_GET_PREAMBLE_FLAGS(STIX_OOP_TO_SMOOI(mth->preamble)) & STIX_METHOD_PREAMBLE_FLAG_VARIADIC); + MOO_ASSERT (moo, MOO_METHOD_GET_PREAMBLE_FLAGS(MOO_OOP_TO_SMOOI(mth->preamble)) & MOO_METHOD_PREAMBLE_FLAG_VARIADIC); actual_ntmprs = ntmprs + (actual_nargs - nargs); } else actual_ntmprs = ntmprs; - stix_pushtmp (stix, (stix_oop_t*)&mth); - ctx = (stix_oop_context_t)stix_instantiate (stix, stix->_method_context, STIX_NULL, actual_ntmprs); - stix_poptmp (stix); + moo_pushtmp (moo, (moo_oop_t*)&mth); + ctx = (moo_oop_context_t)moo_instantiate (moo, moo->_method_context, MOO_NULL, actual_ntmprs); + moo_poptmp (moo); if (!ctx) return -1; - ctx->sender = stix->active_context; - ctx->ip = STIX_SMOOI_TO_OOP(0); + ctx->sender = moo->active_context; + ctx->ip = MOO_SMOOI_TO_OOP(0); /* ctx->sp will be set further down */ /* A context is compose of a fixed part and a variable part. @@ -936,10 +936,10 @@ static STIX_INLINE int activate_new_method (stix_t* stix, stix_oop_method_t mth, * +---------------------+ */ - ctx->ntmprs = STIX_SMOOI_TO_OOP(ntmprs); - ctx->method_or_nargs = (stix_oop_t)mth; - /* the 'home' field of a method context is always stix->_nil. - ctx->home = stix->_nil;*/ + ctx->ntmprs = MOO_SMOOI_TO_OOP(ntmprs); + ctx->method_or_nargs = (moo_oop_t)mth; + /* the 'home' field of a method context is always moo->_nil. + ctx->home = moo->_nil;*/ ctx->origin = ctx; /* point to self */ /* @@ -968,15 +968,15 @@ static STIX_INLINE int activate_new_method (stix_t* stix, stix_oop_method_t mth, for (i = actual_nargs, j = ntmprs + (actual_nargs - nargs); i > nargs; i--) { /* place variadic arguments after local temporaries */ - ctx->slot[--j] = STIX_STACK_GETTOP (stix); - STIX_STACK_POP (stix); + ctx->slot[--j] = MOO_STACK_GETTOP (moo); + MOO_STACK_POP (moo); } - STIX_ASSERT (stix, i == nargs); + MOO_ASSERT (moo, i == nargs); while (i > 0) { /* place normal argument before local temporaries */ - ctx->slot[--i] = STIX_STACK_GETTOP (stix); - STIX_STACK_POP (stix); + ctx->slot[--i] = MOO_STACK_GETTOP (moo); + MOO_STACK_POP (moo); } } else @@ -984,107 +984,107 @@ static STIX_INLINE int activate_new_method (stix_t* stix, stix_oop_method_t mth, for (i = actual_nargs; i > 0; ) { /* place normal argument before local temporaries */ - ctx->slot[--i] = STIX_STACK_GETTOP (stix); - STIX_STACK_POP (stix); + ctx->slot[--i] = MOO_STACK_GETTOP (moo); + MOO_STACK_POP (moo); } } /* copy receiver */ - ctx->receiver_or_source = STIX_STACK_GETTOP (stix); - STIX_STACK_POP (stix); + ctx->receiver_or_source = MOO_STACK_GETTOP (moo); + MOO_STACK_POP (moo); - STIX_ASSERT (stix, stix->sp >= -1); + MOO_ASSERT (moo, moo->sp >= -1); /* the stack pointer in a context is a stack pointer of a process * before it is activated. this stack pointer is stored to the context * so that it is used to restore the process stack pointer upon returning * from a method context. */ - ctx->sp = STIX_SMOOI_TO_OOP(stix->sp); + ctx->sp = MOO_SMOOI_TO_OOP(moo->sp); /* switch the active context to the newly instantiated one*/ - SWITCH_ACTIVE_CONTEXT (stix, ctx); + SWITCH_ACTIVE_CONTEXT (moo, ctx); return 0; } -static stix_oop_method_t find_method (stix_t* stix, stix_oop_t receiver, const stix_oocs_t* message, int super) +static moo_oop_method_t find_method (moo_t* moo, moo_oop_t receiver, const moo_oocs_t* message, int super) { - stix_oop_class_t cls; - stix_oop_association_t ass; - stix_oop_t c; - stix_oop_set_t mthdic; + moo_oop_class_t cls; + moo_oop_association_t ass; + moo_oop_t c; + moo_oop_set_t mthdic; int dic_no; /* TODO: implement method lookup cache */ - cls = (stix_oop_class_t)STIX_CLASSOF(stix, receiver); - if ((stix_oop_t)cls == stix->_class) + cls = (moo_oop_class_t)MOO_CLASSOF(moo, receiver); + if ((moo_oop_t)cls == moo->_class) { /* receiver is a class object (an instance of Class) */ c = receiver; - dic_no = STIX_METHOD_CLASS; + dic_no = MOO_METHOD_CLASS; } else { /* receiver is not a class object. so take its class */ - c = (stix_oop_t)cls; - dic_no = STIX_METHOD_INSTANCE; + c = (moo_oop_t)cls; + dic_no = MOO_METHOD_INSTANCE; } - STIX_ASSERT (stix, c != stix->_nil); + MOO_ASSERT (moo, c != moo->_nil); if (super) { /* - stix_oop_method_t m; - STIX_ASSERT (stix, STIX_CLASSOF(stix, stix->active_context->origin) == stix->_method_context); - m = (stix_oop_method_t)stix->active_context->origin->method_or_nargs; - c = ((stix_oop_class_t)m->owner)->superclass; + moo_oop_method_t m; + MOO_ASSERT (moo, MOO_CLASSOF(moo, moo->active_context->origin) == moo->_method_context); + m = (moo_oop_method_t)moo->active_context->origin->method_or_nargs; + c = ((moo_oop_class_t)m->owner)->superclass; */ - STIX_ASSERT (stix, stix->active_method); - STIX_ASSERT (stix, stix->active_method->owner); - c = ((stix_oop_class_t)stix->active_method->owner)->superclass; - if (c == stix->_nil) goto not_found; /* reached the top of the hierarchy */ + MOO_ASSERT (moo, moo->active_method); + MOO_ASSERT (moo, moo->active_method->owner); + c = ((moo_oop_class_t)moo->active_method->owner)->superclass; + if (c == moo->_nil) goto not_found; /* reached the top of the hierarchy */ } do { - mthdic = ((stix_oop_class_t)c)->mthdic[dic_no]; - STIX_ASSERT (stix, (stix_oop_t)mthdic != stix->_nil); - STIX_ASSERT (stix, STIX_CLASSOF(stix, mthdic) == stix->_method_dictionary); + mthdic = ((moo_oop_class_t)c)->mthdic[dic_no]; + MOO_ASSERT (moo, (moo_oop_t)mthdic != moo->_nil); + MOO_ASSERT (moo, MOO_CLASSOF(moo, mthdic) == moo->_method_dictionary); - ass = (stix_oop_association_t)stix_lookupdic (stix, mthdic, message); + ass = (moo_oop_association_t)moo_lookupdic (moo, mthdic, message); if (ass) { /* found the method */ - STIX_ASSERT (stix, STIX_CLASSOF(stix, ass->value) == stix->_method); - return (stix_oop_method_t)ass->value; + MOO_ASSERT (moo, MOO_CLASSOF(moo, ass->value) == moo->_method); + return (moo_oop_method_t)ass->value; } - c = ((stix_oop_class_t)c)->superclass; + c = ((moo_oop_class_t)c)->superclass; } - while (c != stix->_nil); + while (c != moo->_nil); not_found: - if ((stix_oop_t)cls == stix->_class) + if ((moo_oop_t)cls == moo->_class) { /* the object is an instance of Class. find the method * in an instance method dictionary of Class also */ - mthdic = ((stix_oop_class_t)cls)->mthdic[STIX_METHOD_INSTANCE]; - STIX_ASSERT (stix, (stix_oop_t)mthdic != stix->_nil); - STIX_ASSERT (stix, STIX_CLASSOF(stix, mthdic) == stix->_method_dictionary); + mthdic = ((moo_oop_class_t)cls)->mthdic[MOO_METHOD_INSTANCE]; + MOO_ASSERT (moo, (moo_oop_t)mthdic != moo->_nil); + MOO_ASSERT (moo, MOO_CLASSOF(moo, mthdic) == moo->_method_dictionary); - ass = (stix_oop_association_t)stix_lookupdic (stix, mthdic, message); + ass = (moo_oop_association_t)moo_lookupdic (moo, mthdic, message); if (ass) { - STIX_ASSERT (stix, STIX_CLASSOF(stix, ass->value) == stix->_method); - return (stix_oop_method_t)ass->value; + MOO_ASSERT (moo, MOO_CLASSOF(moo, ass->value) == moo->_method); + return (moo_oop_method_t)ass->value; } } - STIX_DEBUG3 (stix, "Method [%.*js] not found for %O\n", message->len, message->ptr, receiver); - stix->errnum = STIX_ENOENT; - return STIX_NULL; + MOO_DEBUG3 (moo, "Method [%.*js] not found for %O\n", message->len, message->ptr, receiver); + moo->errnum = MOO_ENOENT; + return MOO_NULL; } -static int start_initial_process_and_context (stix_t* stix, const stix_oocs_t* objname, const stix_oocs_t* mthname) +static int start_initial_process_and_context (moo_t* moo, const moo_oocs_t* objname, const moo_oocs_t* mthname) { /* the initial context is a fake context. if objname is 'Stix' and * mthname is 'main', this function emulates message sending 'Stix main'. @@ -1093,28 +1093,28 @@ static int start_initial_process_and_context (stix_t* stix, const stix_oocs_t* o * push Stix * send #main */ - stix_oop_context_t ctx; - stix_oop_association_t ass; - stix_oop_method_t mth; - stix_oop_process_t proc; + moo_oop_context_t ctx; + moo_oop_association_t ass; + moo_oop_method_t mth; + moo_oop_process_t proc; /* create a fake initial context. */ - ctx = (stix_oop_context_t)stix_instantiate (stix, stix->_method_context, STIX_NULL, 0); + ctx = (moo_oop_context_t)moo_instantiate (moo, moo->_method_context, MOO_NULL, 0); if (!ctx) return -1; - ass = stix_lookupsysdic (stix, objname); + ass = moo_lookupsysdic (moo, objname); if (!ass) return -1; - mth = find_method (stix, ass->value, mthname, 0); + mth = find_method (moo, ass->value, mthname, 0); if (!mth) return -1; - if (STIX_OOP_TO_SMOOI(mth->tmpr_nargs) > 0) + if (MOO_OOP_TO_SMOOI(mth->tmpr_nargs) > 0) { /* this method expects more than 0 arguments. * i can't use it as a start-up method. TODO: overcome this problem */ - stix->errnum = STIX_EINVAL; + moo->errnum = MOO_EINVAL; return -1; } @@ -1124,79 +1124,79 @@ TODO: overcome this problem * and is not really worked on except that it is used to call the * initial method. so it doesn't really require any extra stack space. */ /* TODO: verify this theory of mine. */ - stix->ip = 0; - stix->sp = -1; + moo->ip = 0; + moo->sp = -1; - ctx->ip = STIX_SMOOI_TO_OOP(0); /* point to the beginning */ - ctx->sp = STIX_SMOOI_TO_OOP(-1); /* pointer to -1 below the bottom */ + ctx->ip = MOO_SMOOI_TO_OOP(0); /* point to the beginning */ + ctx->sp = MOO_SMOOI_TO_OOP(-1); /* pointer to -1 below the bottom */ ctx->origin = ctx; /* point to self */ - ctx->method_or_nargs = (stix_oop_t)mth; /* fake. help SWITCH_ACTIVE_CONTEXT() not fail. TODO: create a static fake method and use it... instead of 'mth' */ + ctx->method_or_nargs = (moo_oop_t)mth; /* fake. help SWITCH_ACTIVE_CONTEXT() not fail. TODO: create a static fake method and use it... instead of 'mth' */ /* [NOTE] * the receiver field and the sender field of ctx are nils. * especially, the fact that the sender field is nil is used by * the main execution loop for breaking out of the loop */ - STIX_ASSERT (stix, stix->active_context == STIX_NULL); - STIX_ASSERT (stix, stix->active_method == STIX_NULL); + MOO_ASSERT (moo, moo->active_context == MOO_NULL); + MOO_ASSERT (moo, moo->active_method == MOO_NULL); - /* stix_gc() uses stix->processor when stix->active_context - * is not NULL. at this poinst, stix->processor should point to + /* moo_gc() uses moo->processor when moo->active_context + * is not NULL. at this poinst, moo->processor should point to * an instance of ProcessScheduler. */ - STIX_ASSERT (stix, (stix_oop_t)stix->processor != stix->_nil); - STIX_ASSERT (stix, stix->processor->tally == STIX_SMOOI_TO_OOP(0)); + MOO_ASSERT (moo, (moo_oop_t)moo->processor != moo->_nil); + MOO_ASSERT (moo, moo->processor->tally == MOO_SMOOI_TO_OOP(0)); /* start_initial_process() calls the SWITCH_ACTIVE_CONTEXT() macro. - * the macro assumes a non-null value in stix->active_context. + * the macro assumes a non-null value in moo->active_context. * let's force set active_context to ctx directly. */ - stix->active_context = ctx; + moo->active_context = ctx; - stix_pushtmp (stix, (stix_oop_t*)&ctx); - stix_pushtmp (stix, (stix_oop_t*)&mth); - stix_pushtmp (stix, (stix_oop_t*)&ass); - proc = start_initial_process (stix, ctx); - stix_poptmps (stix, 3); + moo_pushtmp (moo, (moo_oop_t*)&ctx); + moo_pushtmp (moo, (moo_oop_t*)&mth); + moo_pushtmp (moo, (moo_oop_t*)&ass); + proc = start_initial_process (moo, ctx); + moo_poptmps (moo, 3); if (!proc) return -1; - STIX_STACK_PUSH (stix, ass->value); /* push the receiver - the object referenced by 'objname' */ - STORE_ACTIVE_SP (stix); /* stix->active_context->sp = STIX_SMOOI_TO_OOP(stix->sp) */ + MOO_STACK_PUSH (moo, ass->value); /* push the receiver - the object referenced by 'objname' */ + STORE_ACTIVE_SP (moo); /* moo->active_context->sp = MOO_SMOOI_TO_OOP(moo->sp) */ - STIX_ASSERT (stix, stix->processor->active == proc); - STIX_ASSERT (stix, stix->processor->active->initial_context == ctx); - STIX_ASSERT (stix, stix->processor->active->current_context == ctx); - STIX_ASSERT (stix, stix->active_context == ctx); + MOO_ASSERT (moo, moo->processor->active == proc); + MOO_ASSERT (moo, moo->processor->active->initial_context == ctx); + MOO_ASSERT (moo, moo->processor->active->current_context == ctx); + MOO_ASSERT (moo, moo->active_context == ctx); /* emulate the message sending */ - return activate_new_method (stix, mth, 0); + return activate_new_method (moo, mth, 0); } /* ------------------------------------------------------------------------- */ -static stix_pfrc_t pf_dump (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_dump (moo_t* moo, moo_ooi_t nargs) { - stix_ooi_t i; + moo_ooi_t i; - STIX_ASSERT (stix, nargs >= 0); + MOO_ASSERT (moo, nargs >= 0); - stix_logbfmt (stix, 0, "RECEIVER: %O\n", STIX_STACK_GET(stix, stix->sp - nargs)); + moo_logbfmt (moo, 0, "RECEIVER: %O\n", MOO_STACK_GET(moo, moo->sp - nargs)); for (i = nargs; i > 0; ) { --i; - stix_logbfmt (stix, 0, "ARGUMENT %zd: %O\n", i, STIX_STACK_GET(stix, stix->sp - i)); + moo_logbfmt (moo, 0, "ARGUMENT %zd: %O\n", i, MOO_STACK_GET(moo, moo->sp - i)); } - STIX_STACK_SETRETTORCV (stix, nargs); /* ^self */ - return STIX_PF_SUCCESS; + MOO_STACK_SETRETTORCV (moo, nargs); /* ^self */ + return MOO_PF_SUCCESS; } -static void log_char_object (stix_t* stix, stix_oow_t mask, stix_oop_char_t msg) +static void log_char_object (moo_t* moo, moo_oow_t mask, moo_oop_char_t msg) { - stix_ooi_t n; - stix_oow_t rem; - const stix_ooch_t* ptr; + moo_ooi_t n; + moo_oow_t rem; + const moo_ooch_t* ptr; - STIX_ASSERT (stix, STIX_OBJ_GET_FLAGS_TYPE(msg) == STIX_OBJ_TYPE_CHAR); + MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_TYPE(msg) == MOO_OBJ_TYPE_CHAR); - rem = STIX_OBJ_GET_SIZE(msg); + rem = MOO_OBJ_GET_SIZE(msg); ptr = msg->slot; start_over: @@ -1204,78 +1204,78 @@ start_over: { if (*ptr == '\0') { - n = stix_logbfmt (stix, mask, "%jc", *ptr); - STIX_ASSERT (stix, n == 1); + n = moo_logbfmt (moo, mask, "%jc", *ptr); + MOO_ASSERT (moo, n == 1); rem -= n; ptr += n; goto start_over; } - n = stix_logbfmt (stix, mask, "%.*js", rem, ptr); + n = moo_logbfmt (moo, mask, "%.*js", rem, ptr); if (n <= -1) break; if (n == 0) { /* to skip the unprinted character. * actually, this check is not needed because of '\0' skipped * at the beginning of the loop */ - n = stix_logbfmt (stix, mask, "%jc", *ptr); - STIX_ASSERT (stix, n == 1); + n = moo_logbfmt (moo, mask, "%jc", *ptr); + MOO_ASSERT (moo, n == 1); } rem -= n; ptr += n; } } -static stix_pfrc_t pf_log (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_log (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t msg, level; - stix_oow_t mask; - stix_ooi_t k; + moo_oop_t msg, level; + moo_oow_t mask; + moo_ooi_t k; - STIX_ASSERT (stix, nargs >= 2); + MOO_ASSERT (moo, nargs >= 2); - level = STIX_STACK_GETARG(stix, nargs, 0); - if (!STIX_OOP_IS_SMOOI(level)) mask = STIX_LOG_APP | STIX_LOG_INFO; - else mask = STIX_LOG_APP | STIX_OOP_TO_SMOOI(level); + level = MOO_STACK_GETARG(moo, nargs, 0); + if (!MOO_OOP_IS_SMOOI(level)) mask = MOO_LOG_APP | MOO_LOG_INFO; + else mask = MOO_LOG_APP | MOO_OOP_TO_SMOOI(level); for (k = 1; k < nargs; k++) { - msg = STIX_STACK_GETARG (stix, nargs, k); + msg = MOO_STACK_GETARG (moo, nargs, k); - if (msg == stix->_nil || msg == stix->_true || msg == stix->_false) + if (msg == moo->_nil || msg == moo->_true || msg == moo->_false) { goto dump_object; } - else if (STIX_OOP_IS_POINTER(msg)) + else if (MOO_OOP_IS_POINTER(msg)) { - if (STIX_OBJ_GET_FLAGS_TYPE(msg) == STIX_OBJ_TYPE_CHAR) + if (MOO_OBJ_GET_FLAGS_TYPE(msg) == MOO_OBJ_TYPE_CHAR) { - log_char_object (stix, mask, (stix_oop_char_t)msg); + log_char_object (moo, mask, (moo_oop_char_t)msg); } - else if (STIX_OBJ_GET_FLAGS_TYPE(msg) == STIX_OBJ_TYPE_OOP) + else if (MOO_OBJ_GET_FLAGS_TYPE(msg) == MOO_OBJ_TYPE_OOP) { /* visit only 1-level down into an array-like object */ - stix_oop_t inner, _class; - stix_oow_t i, spec; + moo_oop_t inner, _class; + moo_oow_t i, spec; - _class = STIX_CLASSOF(stix, msg); + _class = MOO_CLASSOF(moo, msg); - spec = STIX_OOP_TO_SMOOI(((stix_oop_class_t)_class)->spec); - if (STIX_CLASS_SPEC_NAMED_INSTVAR(spec) > 0 || !STIX_CLASS_SPEC_IS_INDEXED(spec)) goto dump_object; + spec = MOO_OOP_TO_SMOOI(((moo_oop_class_t)_class)->spec); + if (MOO_CLASS_SPEC_NAMED_INSTVAR(spec) > 0 || !MOO_CLASS_SPEC_IS_INDEXED(spec)) goto dump_object; - for (i = 0; i < STIX_OBJ_GET_SIZE(msg); i++) + for (i = 0; i < MOO_OBJ_GET_SIZE(msg); i++) { - inner = ((stix_oop_oop_t)msg)->slot[i]; + inner = ((moo_oop_oop_t)msg)->slot[i]; - if (i > 0) stix_logbfmt (stix, mask, " "); - if (STIX_OOP_IS_POINTER(inner) && - STIX_OBJ_GET_FLAGS_TYPE(inner) == STIX_OBJ_TYPE_CHAR) + if (i > 0) moo_logbfmt (moo, mask, " "); + if (MOO_OOP_IS_POINTER(inner) && + MOO_OBJ_GET_FLAGS_TYPE(inner) == MOO_OBJ_TYPE_CHAR) { - log_char_object (stix, mask, (stix_oop_char_t)inner); + log_char_object (moo, mask, (moo_oop_char_t)inner); } else { - stix_logbfmt (stix, mask, "%O", inner); + moo_logbfmt (moo, mask, "%O", inner); } } } @@ -1284,542 +1284,542 @@ static stix_pfrc_t pf_log (stix_t* stix, stix_ooi_t nargs) else { dump_object: - stix_logbfmt (stix, mask, "%O", msg); + moo_logbfmt (moo, mask, "%O", msg); } } - STIX_STACK_SETRETTORCV (stix, nargs); /* ^self */ - return STIX_PF_SUCCESS; + MOO_STACK_SETRETTORCV (moo, nargs); /* ^self */ + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_identical (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_identical (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg, b; + moo_oop_t rcv, arg, b; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - b = (rcv == arg)? stix->_true: stix->_false; + b = (rcv == arg)? moo->_true: moo->_false; - STIX_STACK_SETRET (stix, nargs, b); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, b); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_not_identical (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_not_identical (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg, b; + moo_oop_t rcv, arg, b; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - b = (rcv != arg)? stix->_true: stix->_false; + b = (rcv != arg)? moo->_true: moo->_false; - STIX_STACK_SETRET (stix, nargs, b); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, b); + return MOO_PF_SUCCESS; } -static stix_pfrc_t _equal_objects (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t _equal_objects (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg; + moo_oop_t rcv, arg; int rtag; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); if (rcv == arg) return 1; /* identical. so equal */ - rtag = STIX_OOP_GET_TAG(rcv); - if (rtag != STIX_OOP_GET_TAG(arg)) return 0; + rtag = MOO_OOP_GET_TAG(rcv); + if (rtag != MOO_OOP_GET_TAG(arg)) return 0; - switch (STIX_OOP_GET_TAG(rcv)) + switch (MOO_OOP_GET_TAG(rcv)) { - case STIX_OOP_TAG_SMINT: - return STIX_OOP_TO_SMOOI(rcv) == STIX_OOP_TO_SMOOI(arg)? 1: 0; + case MOO_OOP_TAG_SMINT: + return MOO_OOP_TO_SMOOI(rcv) == MOO_OOP_TO_SMOOI(arg)? 1: 0; - case STIX_OOP_TAG_CHAR: - return STIX_OOP_TO_CHAR(rcv) == STIX_OOP_TO_CHAR(arg)? 1: 0; + case MOO_OOP_TAG_CHAR: + return MOO_OOP_TO_CHAR(rcv) == MOO_OOP_TO_CHAR(arg)? 1: 0; - case STIX_OOP_TAG_ERROR: - return STIX_OOP_TO_ERROR(rcv) == STIX_OOP_TO_ERROR(arg)? 1: 0; + case MOO_OOP_TAG_ERROR: + return MOO_OOP_TO_ERROR(rcv) == MOO_OOP_TO_ERROR(arg)? 1: 0; default: { - STIX_ASSERT (stix, STIX_OOP_IS_POINTER(rcv)); + MOO_ASSERT (moo, MOO_OOP_IS_POINTER(rcv)); - if (STIX_OBJ_GET_CLASS(rcv) != STIX_OBJ_GET_CLASS(arg)) return 0; /* different class, not equal */ - STIX_ASSERT (stix, STIX_OBJ_GET_FLAGS_TYPE(rcv) == STIX_OBJ_GET_FLAGS_TYPE(arg)); + if (MOO_OBJ_GET_CLASS(rcv) != MOO_OBJ_GET_CLASS(arg)) return 0; /* different class, not equal */ + MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_TYPE(rcv) == MOO_OBJ_GET_FLAGS_TYPE(arg)); - if (STIX_OBJ_GET_CLASS(rcv) == stix->_class && rcv != arg) + if (MOO_OBJ_GET_CLASS(rcv) == moo->_class && rcv != arg) { /* a class object are supposed to be unique */ return 0; } - if (STIX_OBJ_GET_SIZE(rcv) != STIX_OBJ_GET_SIZE(arg)) return 0; /* different size, not equal */ + if (MOO_OBJ_GET_SIZE(rcv) != MOO_OBJ_GET_SIZE(arg)) return 0; /* different size, not equal */ - switch (STIX_OBJ_GET_FLAGS_TYPE(rcv)) + switch (MOO_OBJ_GET_FLAGS_TYPE(rcv)) { - case STIX_OBJ_TYPE_BYTE: - case STIX_OBJ_TYPE_CHAR: - case STIX_OBJ_TYPE_HALFWORD: - case STIX_OBJ_TYPE_WORD: - return (STIX_MEMCMP (((stix_oop_byte_t)rcv)->slot, ((stix_oop_byte_t)arg)->slot, STIX_BYTESOF(stix,rcv)) == 0)? 1: 0; + case MOO_OBJ_TYPE_BYTE: + case MOO_OBJ_TYPE_CHAR: + case MOO_OBJ_TYPE_HALFWORD: + case MOO_OBJ_TYPE_WORD: + return (MOO_MEMCMP (((moo_oop_byte_t)rcv)->slot, ((moo_oop_byte_t)arg)->slot, MOO_BYTESOF(moo,rcv)) == 0)? 1: 0; default: - if (rcv == stix->_nil) return arg == stix->_nil? 1: 0; - if (rcv == stix->_true) return arg == stix->_true? 1: 0; - if (rcv == stix->_false) return arg == stix->_false? 1: 0; + if (rcv == moo->_nil) return arg == moo->_nil? 1: 0; + if (rcv == moo->_true) return arg == moo->_true? 1: 0; + if (rcv == moo->_false) return arg == moo->_false? 1: 0; - /* STIX_OBJ_TYPE_OOP, ... */ - STIX_DEBUG1 (stix, "<_equal_objects> Cannot compare objects of type %d\n", (int)STIX_OBJ_GET_FLAGS_TYPE(rcv)); + /* MOO_OBJ_TYPE_OOP, ... */ + MOO_DEBUG1 (moo, "<_equal_objects> Cannot compare objects of type %d\n", (int)MOO_OBJ_GET_FLAGS_TYPE(rcv)); return -1; } } } } -static stix_pfrc_t pf_equal (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_equal (moo_t* moo, moo_ooi_t nargs) { int n; - n = _equal_objects (stix, nargs); - if (n <= -1) return STIX_PF_FAILURE; + n = _equal_objects (moo, nargs); + if (n <= -1) return MOO_PF_FAILURE; - STIX_STACK_SETRET (stix, nargs, (n? stix->_true: stix->_false)); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, (n? moo->_true: moo->_false)); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_not_equal (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_not_equal (moo_t* moo, moo_ooi_t nargs) { int n; - n = _equal_objects (stix, nargs); - if (n <= -1) return STIX_PF_FAILURE; + n = _equal_objects (moo, nargs); + if (n <= -1) return MOO_PF_FAILURE; - STIX_STACK_SETRET (stix, nargs, (n? stix->_false: stix->_true)); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, (n? moo->_false: moo->_true)); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_class (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_class (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, c; + moo_oop_t rcv, c; - STIX_ASSERT (stix, nargs == 0); + MOO_ASSERT (moo, nargs == 0); - rcv = STIX_STACK_GETRCV(stix, nargs); - c = STIX_CLASSOF(stix, rcv); + rcv = MOO_STACK_GETRCV(moo, nargs); + c = MOO_CLASSOF(moo, rcv); - STIX_STACK_SETRET (stix, nargs, c); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, c); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_basic_new (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_basic_new (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, obj; + moo_oop_t rcv, obj; - STIX_ASSERT (stix, nargs == 0); + MOO_ASSERT (moo, nargs == 0); - rcv = STIX_STACK_GETRCV (stix, nargs); - if (STIX_CLASSOF(stix, rcv) != stix->_class) + rcv = MOO_STACK_GETRCV (moo, nargs); + if (MOO_CLASSOF(moo, rcv) != moo->_class) { /* the receiver is not a class object */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - obj = stix_instantiate (stix, rcv, STIX_NULL, 0); - if (!obj) return STIX_PF_HARD_FAILURE; + obj = moo_instantiate (moo, rcv, MOO_NULL, 0); + if (!obj) return MOO_PF_HARD_FAILURE; - STIX_STACK_SETRET (stix, nargs, obj); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, obj); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_basic_new_with_size (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_basic_new_with_size (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, szoop, obj; - stix_oow_t size; + moo_oop_t rcv, szoop, obj; + moo_oow_t size; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - if (STIX_CLASSOF(stix, rcv) != stix->_class) + rcv = MOO_STACK_GETRCV(moo, nargs); + if (MOO_CLASSOF(moo, rcv) != moo->_class) { /* the receiver is not a class object */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - szoop = STIX_STACK_GETARG(stix, nargs, 0); - if (stix_inttooow (stix, szoop, &size) <= 0) + szoop = MOO_STACK_GETARG(moo, nargs, 0); + if (moo_inttooow (moo, szoop, &size) <= 0) { /* integer out of range or not integer */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - /* stix_instantiate() ignores size if the instance specification + /* moo_instantiate() ignores size if the instance specification * disallows indexed(variable) parts. */ /* TODO: should i check the specification before calling - * stix_instantiate()? */ - obj = stix_instantiate (stix, rcv, STIX_NULL, size); + * moo_instantiate()? */ + obj = moo_instantiate (moo, rcv, MOO_NULL, size); if (!obj) { - return STIX_PF_HARD_FAILURE; + return MOO_PF_HARD_FAILURE; } - STIX_STACK_SETRET (stix, nargs, obj); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, obj); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_ngc_new (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_ngc_new (moo_t* moo, moo_ooi_t nargs) { /* TODO: implement this. * if NGC is allowed for non-OOP objects, GC issues get very simple. * * also allow NGC code in non-safe mode. in safe mode, ngc_new is same as normal new. * ngc_dispose should not do anything in safe mode. */ - return pf_basic_new (stix, nargs); + return pf_basic_new (moo, nargs); } -static stix_pfrc_t pf_ngc_new_with_size (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_ngc_new_with_size (moo_t* moo, moo_ooi_t nargs) { - return pf_basic_new_with_size (stix, nargs); + return pf_basic_new_with_size (moo, nargs); } -static stix_pfrc_t pf_ngc_dispose (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_ngc_dispose (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv; + moo_oop_t rcv; - STIX_ASSERT (stix, nargs == 0); - rcv = STIX_STACK_GETRCV (stix, nargs); + MOO_ASSERT (moo, nargs == 0); + rcv = MOO_STACK_GETRCV (moo, nargs); - stix_freemem (stix, rcv); + moo_freemem (moo, rcv); - STIX_STACK_SETRET (stix, nargs, stix->_nil); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, moo->_nil); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_shallow_copy (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_shallow_copy (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, obj; + moo_oop_t rcv, obj; - STIX_ASSERT (stix, nargs == 0); - rcv = STIX_STACK_GETRCV (stix, nargs); + MOO_ASSERT (moo, nargs == 0); + rcv = MOO_STACK_GETRCV (moo, nargs); - obj = stix_shallowcopy (stix, rcv); - if (!obj) return STIX_PF_HARD_FAILURE; + obj = moo_shallowcopy (moo, rcv); + if (!obj) return MOO_PF_HARD_FAILURE; - STIX_STACK_SETRET (stix, nargs, obj); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, obj); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_basic_size (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_basic_size (moo_t* moo, moo_ooi_t nargs) { /* return the number of indexable fields */ - stix_oop_t rcv, sz; + moo_oop_t rcv, sz; - STIX_ASSERT (stix, nargs == 0); + MOO_ASSERT (moo, nargs == 0); - rcv = STIX_STACK_GETRCV (stix, nargs); + rcv = MOO_STACK_GETRCV (moo, nargs); - if (!STIX_OOP_IS_POINTER(rcv)) + if (!MOO_OOP_IS_POINTER(rcv)) { - sz = STIX_SMOOI_TO_OOP(0); + sz = MOO_SMOOI_TO_OOP(0); } else { - sz = stix_oowtoint (stix, STIX_OBJ_GET_SIZE(rcv)); - if (!sz) return STIX_PF_HARD_FAILURE; /* hard failure */ + sz = moo_oowtoint (moo, MOO_OBJ_GET_SIZE(rcv)); + if (!sz) return MOO_PF_HARD_FAILURE; /* hard failure */ } - STIX_STACK_SETRET(stix, nargs, sz); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET(moo, nargs, sz); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_basic_at (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_basic_at (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, pos, v; - stix_oow_t idx; + moo_oop_t rcv, pos, v; + moo_oow_t idx; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - if (!STIX_OOP_IS_POINTER(rcv)) + rcv = MOO_STACK_GETRCV(moo, nargs); + if (!MOO_OOP_IS_POINTER(rcv)) { /* the receiver is a special numeric object, not a normal pointer */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - pos = STIX_STACK_GETARG(stix, nargs, 0); - if (stix_inttooow (stix, pos, &idx) <= 0) + pos = MOO_STACK_GETARG(moo, nargs, 0); + if (moo_inttooow (moo, pos, &idx) <= 0) { /* negative integer or not integer */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - if (idx >= STIX_OBJ_GET_SIZE(rcv)) + if (idx >= MOO_OBJ_GET_SIZE(rcv)) { /* index out of range */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - switch (STIX_OBJ_GET_FLAGS_TYPE(rcv)) + switch (MOO_OBJ_GET_FLAGS_TYPE(rcv)) { - case STIX_OBJ_TYPE_BYTE: - v = STIX_SMOOI_TO_OOP(((stix_oop_byte_t)rcv)->slot[idx]); + case MOO_OBJ_TYPE_BYTE: + v = MOO_SMOOI_TO_OOP(((moo_oop_byte_t)rcv)->slot[idx]); break; - case STIX_OBJ_TYPE_CHAR: - v = STIX_CHAR_TO_OOP(((stix_oop_char_t)rcv)->slot[idx]); + case MOO_OBJ_TYPE_CHAR: + v = MOO_CHAR_TO_OOP(((moo_oop_char_t)rcv)->slot[idx]); break; - case STIX_OBJ_TYPE_HALFWORD: + case MOO_OBJ_TYPE_HALFWORD: /* TODO: LargeInteger if the halfword is too large */ - v = STIX_SMOOI_TO_OOP(((stix_oop_halfword_t)rcv)->slot[idx]); + v = MOO_SMOOI_TO_OOP(((moo_oop_halfword_t)rcv)->slot[idx]); break; - case STIX_OBJ_TYPE_WORD: - v = stix_oowtoint (stix, ((stix_oop_word_t)rcv)->slot[idx]); - if (!v) return STIX_PF_HARD_FAILURE; + case MOO_OBJ_TYPE_WORD: + v = moo_oowtoint (moo, ((moo_oop_word_t)rcv)->slot[idx]); + if (!v) return MOO_PF_HARD_FAILURE; break; - case STIX_OBJ_TYPE_OOP: - v = ((stix_oop_oop_t)rcv)->slot[idx]; + case MOO_OBJ_TYPE_OOP: + v = ((moo_oop_oop_t)rcv)->slot[idx]; break; default: - stix->errnum = STIX_EINTERN; - return STIX_PF_HARD_FAILURE; + moo->errnum = MOO_EINTERN; + return MOO_PF_HARD_FAILURE; } - STIX_STACK_SETRET (stix, nargs, v); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, v); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_basic_at_put (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_basic_at_put (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, pos, val; - stix_oow_t idx; + moo_oop_t rcv, pos, val; + moo_oow_t idx; - STIX_ASSERT (stix, nargs == 2); + MOO_ASSERT (moo, nargs == 2); - rcv = STIX_STACK_GETRCV(stix, nargs); - if (!STIX_OOP_IS_POINTER(rcv)) + rcv = MOO_STACK_GETRCV(moo, nargs); + if (!MOO_OOP_IS_POINTER(rcv)) { /* the receiver is a special numeric object, not a normal pointer */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - pos = STIX_STACK_GETARG(stix, nargs, 0); - val = STIX_STACK_GETARG(stix, nargs, 1); + pos = MOO_STACK_GETARG(moo, nargs, 0); + val = MOO_STACK_GETARG(moo, nargs, 1); - if (stix_inttooow (stix, pos, &idx) <= 0) + if (moo_inttooow (moo, pos, &idx) <= 0) { /* negative integer or not integer */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - if (idx >= STIX_OBJ_GET_SIZE(rcv)) + if (idx >= MOO_OBJ_GET_SIZE(rcv)) { /* index out of range */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - if (STIX_OBJ_GET_CLASS(rcv) == stix->_symbol) + if (MOO_OBJ_GET_CLASS(rcv) == moo->_symbol) { /* TODO: disallow change of some key kernel objects???? */ /* TODO: is it better to introduct a read-only mark in the object header instead of this class check??? */ - /* read-only object */ /* TODO: DEVISE A WAY TO PASS a proper error from the primitive handler to STIX */ - return STIX_PF_FAILURE; + /* read-only object */ /* TODO: DEVISE A WAY TO PASS a proper error from the primitive handler to MOO */ + return MOO_PF_FAILURE; } - switch (STIX_OBJ_GET_FLAGS_TYPE(rcv)) + switch (MOO_OBJ_GET_FLAGS_TYPE(rcv)) { - case STIX_OBJ_TYPE_BYTE: - if (!STIX_OOP_IS_SMOOI(val)) + case MOO_OBJ_TYPE_BYTE: + if (!MOO_OOP_IS_SMOOI(val)) { /* the value is not a character */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } /* TOOD: must I check the range of the value? */ - ((stix_oop_char_t)rcv)->slot[idx] = STIX_OOP_TO_SMOOI(val); + ((moo_oop_char_t)rcv)->slot[idx] = MOO_OOP_TO_SMOOI(val); break; - case STIX_OBJ_TYPE_CHAR: - if (!STIX_OOP_IS_CHAR(val)) + case MOO_OBJ_TYPE_CHAR: + if (!MOO_OOP_IS_CHAR(val)) { /* the value is not a character */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - ((stix_oop_char_t)rcv)->slot[idx] = STIX_OOP_TO_CHAR(val); + ((moo_oop_char_t)rcv)->slot[idx] = MOO_OOP_TO_CHAR(val); break; - case STIX_OBJ_TYPE_HALFWORD: - if (!STIX_OOP_IS_SMOOI(val)) + case MOO_OBJ_TYPE_HALFWORD: + if (!MOO_OOP_IS_SMOOI(val)) { /* the value is not a number */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } /* if the small integer is too large, it will get truncated */ - ((stix_oop_halfword_t)rcv)->slot[idx] = STIX_OOP_TO_SMOOI(val); + ((moo_oop_halfword_t)rcv)->slot[idx] = MOO_OOP_TO_SMOOI(val); break; - case STIX_OBJ_TYPE_WORD: + case MOO_OBJ_TYPE_WORD: { - stix_oow_t w; + moo_oow_t w; - if (stix_inttooow (stix, val, &w) <= 0) + if (moo_inttooow (moo, val, &w) <= 0) { /* the value is not a number, out of range, or negative */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - ((stix_oop_word_t)rcv)->slot[idx] = w; + ((moo_oop_word_t)rcv)->slot[idx] = w; break; } - case STIX_OBJ_TYPE_OOP: - ((stix_oop_oop_t)rcv)->slot[idx] = val; + case MOO_OBJ_TYPE_OOP: + ((moo_oop_oop_t)rcv)->slot[idx] = val; break; default: - stix->errnum = STIX_EINTERN; - return STIX_PF_HARD_FAILURE; + moo->errnum = MOO_EINTERN; + return MOO_PF_HARD_FAILURE; } /* TODO: return receiver or value? */ - STIX_STACK_SETRET (stix, nargs, val); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, val); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_hash (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_hash (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv; - stix_oow_t hv; + moo_oop_t rcv; + moo_oow_t hv; - STIX_ASSERT (stix, nargs == 0); - rcv = STIX_STACK_GETRCV(stix, nargs); + MOO_ASSERT (moo, nargs == 0); + rcv = MOO_STACK_GETRCV(moo, nargs); - switch (STIX_OOP_GET_TAG(rcv)) + switch (MOO_OOP_GET_TAG(rcv)) { - case STIX_OOP_TAG_SMINT: - hv = STIX_OOP_TO_SMOOI(rcv); + case MOO_OOP_TAG_SMINT: + hv = MOO_OOP_TO_SMOOI(rcv); break; - case STIX_OOP_TAG_CHAR: - hv = STIX_OOP_TO_CHAR(rcv); + case MOO_OOP_TAG_CHAR: + hv = MOO_OOP_TO_CHAR(rcv); break; - case STIX_OOP_TAG_ERROR: - hv = STIX_OOP_TO_ERROR(rcv); + case MOO_OOP_TAG_ERROR: + hv = MOO_OOP_TO_ERROR(rcv); break; default: { int type; - STIX_ASSERT (stix, STIX_OOP_IS_POINTER(rcv)); - type = STIX_OBJ_GET_FLAGS_TYPE(rcv); + MOO_ASSERT (moo, MOO_OOP_IS_POINTER(rcv)); + type = MOO_OBJ_GET_FLAGS_TYPE(rcv); switch (type) { - case STIX_OBJ_TYPE_BYTE: - hv = stix_hashbytes(((stix_oop_byte_t)rcv)->slot, STIX_OBJ_GET_SIZE(rcv)); + case MOO_OBJ_TYPE_BYTE: + hv = moo_hashbytes(((moo_oop_byte_t)rcv)->slot, MOO_OBJ_GET_SIZE(rcv)); break; - case STIX_OBJ_TYPE_CHAR: - hv = stix_hashoochars (((stix_oop_char_t)rcv)->slot, STIX_OBJ_GET_SIZE(rcv)); + case MOO_OBJ_TYPE_CHAR: + hv = moo_hashoochars (((moo_oop_char_t)rcv)->slot, MOO_OBJ_GET_SIZE(rcv)); break; - case STIX_OBJ_TYPE_HALFWORD: - hv = stix_hashhalfwords(((stix_oop_halfword_t)rcv)->slot, STIX_OBJ_GET_SIZE(rcv)); + case MOO_OBJ_TYPE_HALFWORD: + hv = moo_hashhalfwords(((moo_oop_halfword_t)rcv)->slot, MOO_OBJ_GET_SIZE(rcv)); break; - case STIX_OBJ_TYPE_WORD: - hv = stix_hashwords(((stix_oop_word_t)rcv)->slot, STIX_OBJ_GET_SIZE(rcv)); + case MOO_OBJ_TYPE_WORD: + hv = moo_hashwords(((moo_oop_word_t)rcv)->slot, MOO_OBJ_GET_SIZE(rcv)); break; default: - /* STIX_OBJ_TYPE_OOP, ... */ - STIX_DEBUG1 (stix, " Cannot hash an object of type %d\n", type); - return STIX_PF_FAILURE; + /* MOO_OBJ_TYPE_OOP, ... */ + MOO_DEBUG1 (moo, " Cannot hash an object of type %d\n", type); + return MOO_PF_FAILURE; } break; } } - /* stix_hashxxx() functions should limit the return value to fall - * in the range between 0 and STIX_SMOOI_MAX inclusive */ - STIX_ASSERT (stix, hv >= 0 && hv <= STIX_SMOOI_MAX); + /* moo_hashxxx() functions should limit the return value to fall + * in the range between 0 and MOO_SMOOI_MAX inclusive */ + MOO_ASSERT (moo, hv >= 0 && hv <= MOO_SMOOI_MAX); - STIX_STACK_SETRET (stix, nargs, STIX_SMOOI_TO_OOP(hv)); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(hv)); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_exceptionize_error (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_exceptionize_error (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv; + moo_oop_t rcv; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - if (!STIX_OOP_IS_POINTER(rcv)) + rcv = MOO_STACK_GETRCV(moo, nargs); + if (!MOO_OOP_IS_POINTER(rcv)) { /* the receiver is a special numeric object, not a normal pointer. * excceptionization is not supported for small integers, characters, and errors. * first of all, methods of these classes must not return errors */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } // TODO: ....... -// STIX_OBJ_SET_FLAGS_EXTRA (rcv, xxx); - STIX_STACK_SETRETTORCV (stix, nargs); - return STIX_PF_SUCCESS; +// MOO_OBJ_SET_FLAGS_EXTRA (rcv, xxx); + MOO_STACK_SETRETTORCV (moo, nargs); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_context_goto (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_context_goto (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv; - stix_oop_t pc; + moo_oop_t rcv; + moo_oop_t pc; /* this primivie provides the similar functionality to MethodContext>>pc: * except that it pops the receiver and arguments and doesn't push a * return value. it's useful when you want to change the instruction * pointer while maintaining the stack level before the call */ - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - if (STIX_CLASSOF(stix, rcv) != stix->_method_context) + rcv = MOO_STACK_GETRCV(moo, nargs); + if (MOO_CLASSOF(moo, rcv) != moo->_method_context) { - STIX_LOG2 (stix, STIX_LOG_PRIMITIVE | STIX_LOG_ERROR, + MOO_LOG2 (moo, MOO_LOG_PRIMITIVE | MOO_LOG_ERROR, "Error(%hs) - invalid receiver, not a method context - %O\n", __PRIMITIVE_NAME__, rcv); - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - pc = STIX_STACK_GETARG(stix, nargs, 0); - if (!STIX_OOP_IS_SMOOI(pc) || STIX_OOP_TO_SMOOI(pc) < 0) + pc = MOO_STACK_GETARG(moo, nargs, 0); + if (!MOO_OOP_IS_SMOOI(pc) || MOO_OOP_TO_SMOOI(pc) < 0) { - STIX_LOG1 (stix, STIX_LOG_PRIMITIVE | STIX_LOG_ERROR, + MOO_LOG1 (moo, MOO_LOG_PRIMITIVE | MOO_LOG_ERROR, "Error(%hs) - invalid pc\n", __PRIMITIVE_NAME__); - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - ((stix_oop_context_t)rcv)->ip = pc; - LOAD_ACTIVE_IP (stix); + ((moo_oop_context_t)rcv)->ip = pc; + LOAD_ACTIVE_IP (moo); - STIX_ASSERT (stix, nargs + 1 == 2); - STIX_STACK_POPS (stix, 2); /* pop both the argument and the receiver */ - return STIX_PF_SUCCESS; + MOO_ASSERT (moo, nargs + 1 == 2); + MOO_STACK_POPS (moo, 2); /* pop both the argument and the receiver */ + return MOO_PF_SUCCESS; } -static stix_pfrc_t __block_value (stix_t* stix, stix_oop_context_t rcv_blkctx, stix_ooi_t nargs, stix_ooi_t num_first_arg_elems, stix_oop_context_t* pblkctx) +static moo_pfrc_t __block_value (moo_t* moo, moo_oop_context_t rcv_blkctx, moo_ooi_t nargs, moo_ooi_t num_first_arg_elems, moo_oop_context_t* pblkctx) { /* prepare a new block context for activation. * the receiver must be a block context which becomes the base * for a new block context. */ - stix_oop_context_t blkctx; - stix_ooi_t local_ntmprs, i; - stix_ooi_t actual_arg_count; + moo_oop_context_t blkctx; + moo_ooi_t local_ntmprs, i; + moo_ooi_t actual_arg_count; actual_arg_count = (num_first_arg_elems > 0)? num_first_arg_elems: nargs; @@ -1835,52 +1835,52 @@ static stix_pfrc_t __block_value (stix_t* stix, stix_oop_context_t rcv_blkctx, s */ /* the receiver must be a block context */ - STIX_ASSERT (stix, STIX_CLASSOF(stix, rcv_blkctx) == stix->_block_context); - if (rcv_blkctx->receiver_or_source != stix->_nil) + MOO_ASSERT (moo, MOO_CLASSOF(moo, rcv_blkctx) == moo->_block_context); + if (rcv_blkctx->receiver_or_source != moo->_nil) { /* the 'source' field is not nil. * this block context has already been activated once. * you can't send 'value' again to reactivate it. * For example, [thisContext value] value. */ - STIX_ASSERT (stix, STIX_OBJ_GET_SIZE(rcv_blkctx) > STIX_CONTEXT_NAMED_INSTVARS); - STIX_LOG2 (stix, STIX_LOG_PRIMITIVE | STIX_LOG_ERROR, + MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(rcv_blkctx) > MOO_CONTEXT_NAMED_INSTVARS); + MOO_LOG2 (moo, MOO_LOG_PRIMITIVE | MOO_LOG_ERROR, "Error(%hs) - re-valuing of a block context - %O\n", __PRIMITIVE_NAME__, rcv_blkctx); - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - STIX_ASSERT (stix, STIX_OBJ_GET_SIZE(rcv_blkctx) == STIX_CONTEXT_NAMED_INSTVARS); + MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(rcv_blkctx) == MOO_CONTEXT_NAMED_INSTVARS); - if (STIX_OOP_TO_SMOOI(rcv_blkctx->method_or_nargs) != actual_arg_count /* nargs */) + if (MOO_OOP_TO_SMOOI(rcv_blkctx->method_or_nargs) != actual_arg_count /* nargs */) { - STIX_LOG4 (stix, STIX_LOG_PRIMITIVE | STIX_LOG_ERROR, + MOO_LOG4 (moo, MOO_LOG_PRIMITIVE | MOO_LOG_ERROR, "Error(%hs) - wrong number of arguments to a block context %O - expecting %zd, got %zd\n", - __PRIMITIVE_NAME__, rcv_blkctx, STIX_OOP_TO_SMOOI(rcv_blkctx->method_or_nargs), actual_arg_count); - return STIX_PF_FAILURE; + __PRIMITIVE_NAME__, rcv_blkctx, MOO_OOP_TO_SMOOI(rcv_blkctx->method_or_nargs), actual_arg_count); + return MOO_PF_FAILURE; } /* the number of temporaries stored in the block context * accumulates the number of temporaries starting from the origin. * simple calculation is needed to find the number of local temporaries */ - local_ntmprs = STIX_OOP_TO_SMOOI(rcv_blkctx->ntmprs) - - STIX_OOP_TO_SMOOI(((stix_oop_context_t)rcv_blkctx->home)->ntmprs); - STIX_ASSERT (stix, local_ntmprs >= actual_arg_count); + local_ntmprs = MOO_OOP_TO_SMOOI(rcv_blkctx->ntmprs) - + MOO_OOP_TO_SMOOI(((moo_oop_context_t)rcv_blkctx->home)->ntmprs); + MOO_ASSERT (moo, local_ntmprs >= actual_arg_count); /* create a new block context to clone rcv_blkctx */ - stix_pushtmp (stix, (stix_oop_t*)&rcv_blkctx); - blkctx = (stix_oop_context_t) stix_instantiate (stix, stix->_block_context, STIX_NULL, local_ntmprs); - stix_poptmp (stix); - if (!blkctx) return STIX_PF_HARD_FAILURE; + moo_pushtmp (moo, (moo_oop_t*)&rcv_blkctx); + blkctx = (moo_oop_context_t) moo_instantiate (moo, moo->_block_context, MOO_NULL, local_ntmprs); + moo_poptmp (moo); + if (!blkctx) return MOO_PF_HARD_FAILURE; #if 0 /* shallow-copy the named part including home, origin, etc. */ - for (i = 0; i < STIX_CONTEXT_NAMED_INSTVARS; i++) + for (i = 0; i < MOO_CONTEXT_NAMED_INSTVARS; i++) { - ((stix_oop_oop_t)blkctx)->slot[i] = ((stix_oop_oop_t)rcv_blkctx)->slot[i]; + ((moo_oop_oop_t)blkctx)->slot[i] = ((moo_oop_oop_t)rcv_blkctx)->slot[i]; } #else blkctx->ip = rcv_blkctx->ip; blkctx->ntmprs = rcv_blkctx->ntmprs; blkctx->method_or_nargs = rcv_blkctx->method_or_nargs; - blkctx->receiver_or_source = (stix_oop_t)rcv_blkctx; + blkctx->receiver_or_source = (moo_oop_t)rcv_blkctx; blkctx->home = rcv_blkctx->home; blkctx->origin = rcv_blkctx->origin; #endif @@ -1890,11 +1890,11 @@ static stix_pfrc_t __block_value (stix_t* stix, stix_oop_context_t rcv_blkctx, s { /* the first argument should be an array. this function is ordered * to pass array elements to the new block */ - stix_oop_oop_t xarg; - STIX_ASSERT (stix, nargs == 1); - xarg = (stix_oop_oop_t)STIX_STACK_GETTOP (stix); - STIX_ASSERT (stix, STIX_ISTYPEOF(stix,xarg,STIX_OBJ_TYPE_OOP)); - STIX_ASSERT (stix, STIX_OBJ_GET_SIZE(xarg) == num_first_arg_elems); + moo_oop_oop_t xarg; + MOO_ASSERT (moo, nargs == 1); + xarg = (moo_oop_oop_t)MOO_STACK_GETTOP (moo); + MOO_ASSERT (moo, MOO_ISTYPEOF(moo,xarg,MOO_OBJ_TYPE_OOP)); + MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(xarg) == num_first_arg_elems); for (i = 0; i < num_first_arg_elems; i++) { blkctx->slot[i] = xarg->slot[i]; @@ -1905,41 +1905,41 @@ static stix_pfrc_t __block_value (stix_t* stix, stix_oop_context_t rcv_blkctx, s /* copy the arguments to the stack */ for (i = 0; i < nargs; i++) { - blkctx->slot[i] = STIX_STACK_GETARG(stix, nargs, i); + blkctx->slot[i] = MOO_STACK_GETARG(moo, nargs, i); } } - STIX_STACK_POPS (stix, nargs + 1); /* pop arguments and receiver */ + MOO_STACK_POPS (moo, nargs + 1); /* pop arguments and receiver */ - STIX_ASSERT (stix, blkctx->home != stix->_nil); - blkctx->sp = STIX_SMOOI_TO_OOP(-1); /* not important at all */ - blkctx->sender = stix->active_context; + MOO_ASSERT (moo, blkctx->home != moo->_nil); + blkctx->sp = MOO_SMOOI_TO_OOP(-1); /* not important at all */ + blkctx->sender = moo->active_context; *pblkctx = blkctx; - return STIX_PF_SUCCESS; + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_block_value (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_block_value (moo_t* moo, moo_ooi_t nargs) { - stix_pfrc_t x; - stix_oop_context_t rcv_blkctx, blkctx; + moo_pfrc_t x; + moo_oop_context_t rcv_blkctx, blkctx; - rcv_blkctx = (stix_oop_context_t)STIX_STACK_GETRCV(stix, nargs); - if (STIX_CLASSOF(stix, rcv_blkctx) != stix->_block_context) + rcv_blkctx = (moo_oop_context_t)MOO_STACK_GETRCV(moo, nargs); + if (MOO_CLASSOF(moo, rcv_blkctx) != moo->_block_context) { /* the receiver must be a block context */ - STIX_LOG2 (stix, STIX_LOG_PRIMITIVE | STIX_LOG_ERROR, + MOO_LOG2 (moo, MOO_LOG_PRIMITIVE | MOO_LOG_ERROR, "Error(%hs) - invalid receiver, not a block context - %O\n", __PRIMITIVE_NAME__, rcv_blkctx); - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - x = __block_value (stix, rcv_blkctx, nargs, 0, &blkctx); - if (x <= STIX_PF_FAILURE) return x; /* hard failure and soft failure */ + x = __block_value (moo, rcv_blkctx, nargs, 0, &blkctx); + if (x <= MOO_PF_FAILURE) return x; /* hard failure and soft failure */ - SWITCH_ACTIVE_CONTEXT (stix, (stix_oop_context_t)blkctx); - return STIX_PF_SUCCESS; + SWITCH_ACTIVE_CONTEXT (moo, (moo_oop_context_t)blkctx); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_block_new_process (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_block_new_process (moo_t* moo, moo_ooi_t nargs) { /* create a new process from a block context. * the receiver must be be a block. @@ -1948,198 +1948,198 @@ static stix_pfrc_t pf_block_new_process (stix_t* stix, stix_ooi_t nargs) */ int x; - stix_oop_context_t rcv_blkctx, blkctx; - stix_oop_process_t proc; - stix_ooi_t num_first_arg_elems = 0; + moo_oop_context_t rcv_blkctx, blkctx; + moo_oop_process_t proc; + moo_ooi_t num_first_arg_elems = 0; if (nargs > 1) { /* too many arguments */ /* TODO: proper error handling */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } if (nargs == 1) { - stix_oop_t xarg; + moo_oop_t xarg; - xarg = STIX_STACK_GETARG(stix, nargs, 0); - if (!STIX_ISTYPEOF(stix,xarg,STIX_OBJ_TYPE_OOP)) + xarg = MOO_STACK_GETARG(moo, nargs, 0); + if (!MOO_ISTYPEOF(moo,xarg,MOO_OBJ_TYPE_OOP)) { /* the only optional argument must be an OOP-indexable * object like an array */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - num_first_arg_elems = STIX_OBJ_GET_SIZE(xarg); + num_first_arg_elems = MOO_OBJ_GET_SIZE(xarg); } - rcv_blkctx = (stix_oop_context_t)STIX_STACK_GETRCV(stix, nargs); - if (STIX_CLASSOF(stix, rcv_blkctx) != stix->_block_context) + rcv_blkctx = (moo_oop_context_t)MOO_STACK_GETRCV(moo, nargs); + if (MOO_CLASSOF(moo, rcv_blkctx) != moo->_block_context) { /* the receiver must be a block context */ - STIX_LOG2 (stix, STIX_LOG_PRIMITIVE | STIX_LOG_ERROR, + MOO_LOG2 (moo, MOO_LOG_PRIMITIVE | MOO_LOG_ERROR, "Error(%hs) - invalid receiver, not a block context - %O\n", __PRIMITIVE_NAME__, rcv_blkctx); - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } /* this primitive creates a new process with a block as if the block * is sent the value message */ - x = __block_value (stix, rcv_blkctx, nargs, num_first_arg_elems, &blkctx); + x = __block_value (moo, rcv_blkctx, nargs, num_first_arg_elems, &blkctx); if (x <= 0) return x; /* both hard failure and soft failure */ - /* reset the sender field to stix->_nil because this block context + /* reset the sender field to moo->_nil because this block context * will be the initial context of a new process. you can simply * inspect the sender field to see if a context is an initial * context of a process. */ - blkctx->sender = (stix_oop_context_t)stix->_nil; + blkctx->sender = (moo_oop_context_t)moo->_nil; - proc = make_process (stix, blkctx); - if (!proc) return STIX_PF_HARD_FAILURE; /* hard failure */ /* TOOD: can't this be treated as a soft failure? */ + proc = make_process (moo, blkctx); + if (!proc) return MOO_PF_HARD_FAILURE; /* hard failure */ /* TOOD: can't this be treated as a soft failure? */ /* __block_value() has popped all arguments and the receiver. * PUSH the return value instead of changing the stack top */ - STIX_STACK_PUSH (stix, (stix_oop_t)proc); - return STIX_PF_SUCCESS; + MOO_STACK_PUSH (moo, (moo_oop_t)proc); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_process_resume (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_process_resume (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv; - STIX_ASSERT (stix, nargs == 0); + moo_oop_t rcv; + MOO_ASSERT (moo, nargs == 0); - rcv = STIX_STACK_GETRCV(stix, nargs); - if (STIX_CLASSOF(stix,rcv) != stix->_process) return STIX_PF_FAILURE; + rcv = MOO_STACK_GETRCV(moo, nargs); + if (MOO_CLASSOF(moo,rcv) != moo->_process) return MOO_PF_FAILURE; - resume_process (stix, (stix_oop_process_t)rcv); /* TODO: error check */ + resume_process (moo, (moo_oop_process_t)rcv); /* TODO: error check */ /* keep the receiver in the stack top */ - return STIX_PF_SUCCESS; + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_process_terminate (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_process_terminate (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv; - STIX_ASSERT (stix, nargs == 0); + moo_oop_t rcv; + MOO_ASSERT (moo, nargs == 0); /* TODO: need to run ensure blocks here.. * when it's executed here. it does't have to be in Exception>>handleException when there is no exception handler */ - rcv = STIX_STACK_GETRCV(stix, nargs); - if (STIX_CLASSOF(stix,rcv) != stix->_process) return STIX_PF_FAILURE; + rcv = MOO_STACK_GETRCV(moo, nargs); + if (MOO_CLASSOF(moo,rcv) != moo->_process) return MOO_PF_FAILURE; - terminate_process (stix, (stix_oop_process_t)rcv); + terminate_process (moo, (moo_oop_process_t)rcv); /* keep the receiver in the stack top */ - return STIX_PF_SUCCESS; + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_process_yield (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_process_yield (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv; - STIX_ASSERT (stix, nargs == 0); + moo_oop_t rcv; + MOO_ASSERT (moo, nargs == 0); - rcv = STIX_STACK_GETRCV(stix, nargs); - if (STIX_CLASSOF(stix,rcv) != stix->_process) return STIX_PF_FAILURE; + rcv = MOO_STACK_GETRCV(moo, nargs); + if (MOO_CLASSOF(moo,rcv) != moo->_process) return MOO_PF_FAILURE; - yield_process (stix, (stix_oop_process_t)rcv); + yield_process (moo, (moo_oop_process_t)rcv); /* keep the receiver in the stack top */ - return STIX_PF_SUCCESS; + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_process_suspend (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_process_suspend (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv; - STIX_ASSERT (stix, nargs == 0); + moo_oop_t rcv; + MOO_ASSERT (moo, nargs == 0); - rcv = STIX_STACK_GETRCV(stix, nargs); - if (STIX_CLASSOF(stix,rcv) != stix->_process) return STIX_PF_FAILURE; + rcv = MOO_STACK_GETRCV(moo, nargs); + if (MOO_CLASSOF(moo,rcv) != moo->_process) return MOO_PF_FAILURE; - suspend_process (stix, (stix_oop_process_t)rcv); + suspend_process (moo, (moo_oop_process_t)rcv); /* keep the receiver in the stack top */ - return STIX_PF_SUCCESS; + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_semaphore_signal (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_semaphore_signal (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv; - STIX_ASSERT (stix, nargs == 0); + moo_oop_t rcv; + MOO_ASSERT (moo, nargs == 0); - rcv = STIX_STACK_GETRCV(stix, nargs); - if (STIX_CLASSOF(stix,rcv) != stix->_semaphore) return STIX_PF_FAILURE; + rcv = MOO_STACK_GETRCV(moo, nargs); + if (MOO_CLASSOF(moo,rcv) != moo->_semaphore) return MOO_PF_FAILURE; - signal_semaphore (stix, (stix_oop_semaphore_t)rcv); + signal_semaphore (moo, (moo_oop_semaphore_t)rcv); /* keep the receiver in the stack top */ - return STIX_PF_SUCCESS; + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_semaphore_wait (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_semaphore_wait (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv; - STIX_ASSERT (stix, nargs == 0); + moo_oop_t rcv; + MOO_ASSERT (moo, nargs == 0); - rcv = STIX_STACK_GETRCV(stix, nargs); - if (STIX_CLASSOF(stix,rcv) != stix->_semaphore) return STIX_PF_FAILURE; + rcv = MOO_STACK_GETRCV(moo, nargs); + if (MOO_CLASSOF(moo,rcv) != moo->_semaphore) return MOO_PF_FAILURE; - await_semaphore (stix, (stix_oop_semaphore_t)rcv); + await_semaphore (moo, (moo_oop_semaphore_t)rcv); /* keep the receiver in the stack top */ - return STIX_PF_SUCCESS; + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_processor_schedule (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_processor_schedule (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg; + moo_oop_t rcv, arg; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - if (rcv != (stix_oop_t)stix->processor || STIX_CLASSOF(stix,arg) != stix->_process) + if (rcv != (moo_oop_t)moo->processor || MOO_CLASSOF(moo,arg) != moo->_process) { - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - resume_process (stix, (stix_oop_process_t)arg); /* TODO: error check */ - return STIX_PF_SUCCESS; + resume_process (moo, (moo_oop_process_t)arg); /* TODO: error check */ + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_processor_add_timed_semaphore (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_processor_add_timed_semaphore (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, sec, nsec; - stix_oop_semaphore_t sem; - stix_ntime_t now, ft; + moo_oop_t rcv, sec, nsec; + moo_oop_semaphore_t sem; + moo_ntime_t now, ft; - STIX_ASSERT (stix, nargs >= 2 || nargs <= 3); + MOO_ASSERT (moo, nargs >= 2 || nargs <= 3); if (nargs == 3) { - nsec = STIX_STACK_GETARG (stix, nargs, 2); - if (!STIX_OOP_IS_SMOOI(nsec)) return STIX_PF_FAILURE; + nsec = MOO_STACK_GETARG (moo, nargs, 2); + if (!MOO_OOP_IS_SMOOI(nsec)) return MOO_PF_FAILURE; } - else nsec = STIX_SMOOI_TO_OOP(0); + else nsec = MOO_SMOOI_TO_OOP(0); - sec = STIX_STACK_GETARG(stix, nargs, 1); - sem = (stix_oop_semaphore_t)STIX_STACK_GETARG(stix, nargs, 0); - rcv = STIX_STACK_GETRCV(stix, nargs); + sec = MOO_STACK_GETARG(moo, nargs, 1); + sem = (moo_oop_semaphore_t)MOO_STACK_GETARG(moo, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); - if (rcv != (stix_oop_t)stix->processor) return STIX_PF_FAILURE; - if (STIX_CLASSOF(stix,sem) != stix->_semaphore) return STIX_PF_FAILURE; - if (!STIX_OOP_IS_SMOOI(sec)) return STIX_PF_FAILURE; + if (rcv != (moo_oop_t)moo->processor) return MOO_PF_FAILURE; + if (MOO_CLASSOF(moo,sem) != moo->_semaphore) return MOO_PF_FAILURE; + if (!MOO_OOP_IS_SMOOI(sec)) return MOO_PF_FAILURE; - if (STIX_OOP_IS_SMOOI(sem->heap_index) && - sem->heap_index != STIX_SMOOI_TO_OOP(-1)) + if (MOO_OOP_IS_SMOOI(sem->heap_index) && + sem->heap_index != MOO_SMOOI_TO_OOP(-1)) { - delete_from_sem_heap (stix, STIX_OOP_TO_SMOOI(sem->heap_index)); - STIX_ASSERT (stix, sem->heap_index == STIX_SMOOI_TO_OOP(-1)); + delete_from_sem_heap (moo, MOO_OOP_TO_SMOOI(sem->heap_index)); + MOO_ASSERT (moo, sem->heap_index == MOO_SMOOI_TO_OOP(-1)); /* Is this more desired??? - STIX_STACK_SETRET (stix, nargs, stix->_false); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, moo->_false); + return MOO_PF_SUCCESS; */ } @@ -2147,675 +2147,675 @@ static stix_pfrc_t pf_processor_add_timed_semaphore (stix_t* stix, stix_ooi_t na * * this code assumes that the monotonic clock returns a small value * that can fit into a SmallInteger, even after some additions... */ - vm_gettime (stix, &now); - STIX_ADDNTIMESNS (&ft, &now, STIX_OOP_TO_SMOOI(sec), STIX_OOP_TO_SMOOI(nsec)); - if (ft.sec < 0 || ft.sec > STIX_SMOOI_MAX) + vm_gettime (moo, &now); + MOO_ADDNTIMESNS (&ft, &now, MOO_OOP_TO_SMOOI(sec), MOO_OOP_TO_SMOOI(nsec)); + if (ft.sec < 0 || ft.sec > MOO_SMOOI_MAX) { /* soft error - cannot represent the expiry time in * a small integer. */ - STIX_LOG3 (stix, STIX_LOG_PRIMITIVE | STIX_LOG_ERROR, + MOO_LOG3 (moo, MOO_LOG_PRIMITIVE | MOO_LOG_ERROR, "Error(%hs) - time (%ld) out of range(0 - %zd) when adding a timed semaphore\n", - __PRIMITIVE_NAME__, (unsigned long int)ft.sec, (stix_ooi_t)STIX_SMOOI_MAX); - return STIX_PF_FAILURE; + __PRIMITIVE_NAME__, (unsigned long int)ft.sec, (moo_ooi_t)MOO_SMOOI_MAX); + return MOO_PF_FAILURE; } - sem->heap_ftime_sec = STIX_SMOOI_TO_OOP(ft.sec); - sem->heap_ftime_nsec = STIX_SMOOI_TO_OOP(ft.nsec); + sem->heap_ftime_sec = MOO_SMOOI_TO_OOP(ft.sec); + sem->heap_ftime_nsec = MOO_SMOOI_TO_OOP(ft.nsec); - if (add_to_sem_heap (stix, sem) <= -1) return STIX_PF_HARD_FAILURE; + if (add_to_sem_heap (moo, sem) <= -1) return MOO_PF_HARD_FAILURE; - STIX_STACK_SETRETTORCV (stix, nargs); /* ^self */ - return STIX_PF_SUCCESS; + MOO_STACK_SETRETTORCV (moo, nargs); /* ^self */ + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_processor_remove_semaphore (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_processor_remove_semaphore (moo_t* moo, moo_ooi_t nargs) { /* remove a semaphore from processor's signal scheduling */ - stix_oop_t rcv; - stix_oop_semaphore_t sem; + moo_oop_t rcv; + moo_oop_semaphore_t sem; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - sem = (stix_oop_semaphore_t)STIX_STACK_GETARG(stix, nargs, 0); - rcv = STIX_STACK_GETRCV(stix, nargs); + sem = (moo_oop_semaphore_t)MOO_STACK_GETARG(moo, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); /* TODO: remove a semaphore from IO handler if it's registered... * remove a semaphore from XXXXXXXXXXXXXX */ - if (rcv != (stix_oop_t)stix->processor) return STIX_PF_FAILURE; - if (STIX_CLASSOF(stix,sem) != stix->_semaphore) return STIX_PF_FAILURE; + if (rcv != (moo_oop_t)moo->processor) return MOO_PF_FAILURE; + if (MOO_CLASSOF(moo,sem) != moo->_semaphore) return MOO_PF_FAILURE; - if (STIX_OOP_IS_SMOOI(sem->heap_index) && - sem->heap_index != STIX_SMOOI_TO_OOP(-1)) + if (MOO_OOP_IS_SMOOI(sem->heap_index) && + sem->heap_index != MOO_SMOOI_TO_OOP(-1)) { /* the semaphore is in the timed semaphore heap */ - delete_from_sem_heap (stix, STIX_OOP_TO_SMOOI(sem->heap_index)); - STIX_ASSERT (stix, sem->heap_index == STIX_SMOOI_TO_OOP(-1)); + delete_from_sem_heap (moo, MOO_OOP_TO_SMOOI(sem->heap_index)); + MOO_ASSERT (moo, sem->heap_index == MOO_SMOOI_TO_OOP(-1)); } - STIX_STACK_SETRETTORCV (stix, nargs); /* ^self */ - return STIX_PF_SUCCESS; + MOO_STACK_SETRETTORCV (moo, nargs); /* ^self */ + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_processor_return_to (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_processor_return_to (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, ret, ctx; + moo_oop_t rcv, ret, ctx; - STIX_ASSERT (stix, nargs == 2); + MOO_ASSERT (moo, nargs == 2); - rcv = STIX_STACK_GETRCV(stix, nargs); - ret = STIX_STACK_GETARG(stix, nargs, 0); - ctx = STIX_STACK_GETARG(stix, nargs, 1); + rcv = MOO_STACK_GETRCV(moo, nargs); + ret = MOO_STACK_GETARG(moo, nargs, 0); + ctx = MOO_STACK_GETARG(moo, nargs, 1); - if (rcv != (stix_oop_t)stix->processor) return STIX_PF_FAILURE; + if (rcv != (moo_oop_t)moo->processor) return MOO_PF_FAILURE; - if (STIX_CLASSOF(stix, ctx) != stix->_block_context && - STIX_CLASSOF(stix, ctx) != stix->_method_context) return STIX_PF_FAILURE; + if (MOO_CLASSOF(moo, ctx) != moo->_block_context && + MOO_CLASSOF(moo, ctx) != moo->_method_context) return MOO_PF_FAILURE; - STIX_STACK_POPS (stix, nargs + 1); /* pop arguments and receiver */ + MOO_STACK_POPS (moo, nargs + 1); /* pop arguments and receiver */ /* TODO: verify if this is correct? does't it correct restore the stack pointer? * test complex chains of method contexts and block contexts */ - if (STIX_CLASSOF(stix, ctx) == stix->_method_context) + if (MOO_CLASSOF(moo, ctx) == moo->_method_context) { /* when returning to a method context, load the sp register with * the value stored in the context */ - stix->sp = STIX_OOP_TO_SMOOI(((stix_oop_context_t)ctx)->sp); + moo->sp = MOO_OOP_TO_SMOOI(((moo_oop_context_t)ctx)->sp); } - STIX_STACK_PUSH (stix, ret); + MOO_STACK_PUSH (moo, ret); - SWITCH_ACTIVE_CONTEXT (stix, (stix_oop_context_t)ctx); - return STIX_PF_SUCCESS; + SWITCH_ACTIVE_CONTEXT (moo, (moo_oop_context_t)ctx); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_integer_add (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_integer_add (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg, res; + moo_oop_t rcv, arg, res; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - res = stix_addints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); + res = moo_addints (moo, rcv, arg); + if (!res) return (moo->errnum == MOO_EINVAL? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE); - STIX_STACK_SETRET (stix, nargs, res); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, res); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_integer_sub (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_integer_sub (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg, res; + moo_oop_t rcv, arg, res; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - res = stix_subints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); + res = moo_subints (moo, rcv, arg); + if (!res) return (moo->errnum == MOO_EINVAL? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE); - STIX_STACK_SETRET (stix, nargs, res); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, res); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_integer_mul (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_integer_mul (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg, res; + moo_oop_t rcv, arg, res; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - res = stix_mulints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); + res = moo_mulints (moo, rcv, arg); + if (!res) return (moo->errnum == MOO_EINVAL? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE); - STIX_STACK_SETRET (stix, nargs, res); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, res); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_integer_quo (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_integer_quo (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg, quo; + moo_oop_t rcv, arg, quo; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - quo = stix_divints (stix, rcv, arg, 0, STIX_NULL); - if (!quo) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); -/* TODO: STIX_EDIVBY0 soft or hard failure? */ + quo = moo_divints (moo, rcv, arg, 0, MOO_NULL); + if (!quo) return (moo->errnum == MOO_EINVAL? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE); +/* TODO: MOO_EDIVBY0 soft or hard failure? */ - STIX_STACK_SETRET (stix, nargs, quo); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, quo); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_integer_rem (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_integer_rem (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg, quo, rem; + moo_oop_t rcv, arg, quo, rem; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - quo = stix_divints (stix, rcv, arg, 0, &rem); - if (!quo) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); -/* TODO: STIX_EDIVBY0 soft or hard failure? */ + quo = moo_divints (moo, rcv, arg, 0, &rem); + if (!quo) return (moo->errnum == MOO_EINVAL? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE); +/* TODO: MOO_EDIVBY0 soft or hard failure? */ - STIX_STACK_SETRET (stix, nargs, rem); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, rem); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_integer_quo2 (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_integer_quo2 (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg, quo; + moo_oop_t rcv, arg, quo; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - quo = stix_divints (stix, rcv, arg, 1, STIX_NULL); - if (!quo) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); -/* TODO: STIX_EDIVBY0 soft or hard failure? */ + quo = moo_divints (moo, rcv, arg, 1, MOO_NULL); + if (!quo) return (moo->errnum == MOO_EINVAL? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE); +/* TODO: MOO_EDIVBY0 soft or hard failure? */ - STIX_STACK_SETRET (stix, nargs, quo); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, quo); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_integer_rem2 (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_integer_rem2 (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg, quo, rem; + moo_oop_t rcv, arg, quo, rem; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - quo = stix_divints (stix, rcv, arg, 1, &rem); - if (!quo) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); -/* TODO: STIX_EDIVBY0 soft or hard failure? */ + quo = moo_divints (moo, rcv, arg, 1, &rem); + if (!quo) return (moo->errnum == MOO_EINVAL? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE); +/* TODO: MOO_EDIVBY0 soft or hard failure? */ - STIX_STACK_SETRET (stix, nargs, rem); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, rem); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_integer_negated (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_integer_negated (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, res; + moo_oop_t rcv, res; - STIX_ASSERT (stix, nargs == 0); + MOO_ASSERT (moo, nargs == 0); - rcv = STIX_STACK_GETRCV(stix, nargs); + rcv = MOO_STACK_GETRCV(moo, nargs); - res = stix_negateint (stix, rcv); - if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); + res = moo_negateint (moo, rcv); + if (!res) return (moo->errnum == MOO_EINVAL? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE); - STIX_STACK_SETRET (stix, nargs, res); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, res); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_integer_bitat (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_integer_bitat (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg, res; + moo_oop_t rcv, arg, res; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - res = stix_bitatint (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); + res = moo_bitatint (moo, rcv, arg); + if (!res) return (moo->errnum == MOO_EINVAL? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE); - STIX_STACK_SETRET (stix, nargs, res); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, res); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_integer_bitand (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_integer_bitand (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg, res; + moo_oop_t rcv, arg, res; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - res = stix_bitandints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); + res = moo_bitandints (moo, rcv, arg); + if (!res) return (moo->errnum == MOO_EINVAL? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE); - STIX_STACK_SETRET (stix, nargs, res); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, res); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_integer_bitor (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_integer_bitor (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg, res; + moo_oop_t rcv, arg, res; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - res = stix_bitorints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); + res = moo_bitorints (moo, rcv, arg); + if (!res) return (moo->errnum == MOO_EINVAL? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE); - STIX_STACK_SETRET (stix, nargs, res); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, res); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_integer_bitxor (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_integer_bitxor (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg, res; + moo_oop_t rcv, arg, res; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - res = stix_bitxorints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); + res = moo_bitxorints (moo, rcv, arg); + if (!res) return (moo->errnum == MOO_EINVAL? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE); - STIX_STACK_SETRET (stix, nargs, res); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, res); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_integer_bitinv (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_integer_bitinv (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, res; + moo_oop_t rcv, res; - STIX_ASSERT (stix, nargs == 0); + MOO_ASSERT (moo, nargs == 0); - rcv = STIX_STACK_GETRCV(stix, nargs); + rcv = MOO_STACK_GETRCV(moo, nargs); - res = stix_bitinvint (stix, rcv); - if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); + res = moo_bitinvint (moo, rcv); + if (!res) return (moo->errnum == MOO_EINVAL? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE); - STIX_STACK_SETRET (stix, nargs, res); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, res); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_integer_bitshift (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_integer_bitshift (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg, res; + moo_oop_t rcv, arg, res; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - res = stix_bitshiftint (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); + res = moo_bitshiftint (moo, rcv, arg); + if (!res) return (moo->errnum == MOO_EINVAL? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE); - STIX_STACK_SETRET (stix, nargs, res); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, res); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_integer_eq (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_integer_eq (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg, res; + moo_oop_t rcv, arg, res; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - res = stix_eqints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); + res = moo_eqints (moo, rcv, arg); + if (!res) return (moo->errnum == MOO_EINVAL? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE); - STIX_STACK_SETRET (stix, nargs, res); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, res); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_integer_ne (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_integer_ne (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg, res; + moo_oop_t rcv, arg, res; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - res = stix_neints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); + res = moo_neints (moo, rcv, arg); + if (!res) return (moo->errnum == MOO_EINVAL? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE); - STIX_STACK_SETRET (stix, nargs, res); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, res); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_integer_lt (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_integer_lt (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg, res; + moo_oop_t rcv, arg, res; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - res = stix_ltints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); + res = moo_ltints (moo, rcv, arg); + if (!res) return (moo->errnum == MOO_EINVAL? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE); - STIX_STACK_SETRET (stix, nargs, res); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, res); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_integer_gt (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_integer_gt (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg, res; + moo_oop_t rcv, arg, res; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - res = stix_gtints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); + res = moo_gtints (moo, rcv, arg); + if (!res) return (moo->errnum == MOO_EINVAL? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE); - STIX_STACK_SETRET (stix, nargs, res); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, res); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_integer_le (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_integer_le (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg, res; + moo_oop_t rcv, arg, res; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - res = stix_leints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); + res = moo_leints (moo, rcv, arg); + if (!res) return (moo->errnum == MOO_EINVAL? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE); - STIX_STACK_SETRET (stix, nargs, res); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, res); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_integer_ge (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_integer_ge (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg, res; + moo_oop_t rcv, arg, res; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - res = stix_geints (stix, rcv, arg); - if (!res) return (stix->errnum == STIX_EINVAL? STIX_PF_FAILURE: STIX_PF_HARD_FAILURE); + res = moo_geints (moo, rcv, arg); + if (!res) return (moo->errnum == MOO_EINVAL? MOO_PF_FAILURE: MOO_PF_HARD_FAILURE); - STIX_STACK_SETRET (stix, nargs, res); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, res); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_integer_inttostr (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_integer_inttostr (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg, str; - stix_ooi_t radix; + moo_oop_t rcv, arg, str; + moo_ooi_t radix; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - if (!STIX_OOP_IS_SMOOI(arg)) return STIX_PF_FAILURE; - radix = STIX_OOP_TO_SMOOI(arg); + if (!MOO_OOP_IS_SMOOI(arg)) return MOO_PF_FAILURE; + radix = MOO_OOP_TO_SMOOI(arg); - if (radix < 2 || radix > 36) return STIX_PF_FAILURE; - str = stix_inttostr (stix, rcv, radix); - if (!str) return (stix->errnum == STIX_EINVAL? 0: -1); + if (radix < 2 || radix > 36) return MOO_PF_FAILURE; + str = moo_inttostr (moo, rcv, radix); + if (!str) return (moo->errnum == MOO_EINVAL? 0: -1); - STIX_STACK_SETRET (stix, nargs, str); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, str); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_smooi_as_character (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_smooi_as_character (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv; - stix_ooi_t ec; + moo_oop_t rcv; + moo_ooi_t ec; - STIX_ASSERT (stix, nargs == 0); + MOO_ASSERT (moo, nargs == 0); - rcv = STIX_STACK_GETRCV(stix, nargs); - if (!STIX_OOP_IS_SMOOI(rcv)) return STIX_PF_FAILURE; + rcv = MOO_STACK_GETRCV(moo, nargs); + if (!MOO_OOP_IS_SMOOI(rcv)) return MOO_PF_FAILURE; - ec = STIX_OOP_TO_SMOOI(rcv); + ec = MOO_OOP_TO_SMOOI(rcv); if (ec < 0) ec = 0; - STIX_STACK_SETRET (stix, nargs, STIX_CHAR_TO_OOP(ec)); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, MOO_CHAR_TO_OOP(ec)); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_smooi_as_error (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_smooi_as_error (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv; - stix_ooi_t ec; + moo_oop_t rcv; + moo_ooi_t ec; - STIX_ASSERT (stix, nargs == 0); + MOO_ASSERT (moo, nargs == 0); - rcv = STIX_STACK_GETRCV(stix, nargs); - if (!STIX_OOP_IS_SMOOI(rcv)) return STIX_PF_FAILURE; + rcv = MOO_STACK_GETRCV(moo, nargs); + if (!MOO_OOP_IS_SMOOI(rcv)) return MOO_PF_FAILURE; - ec = STIX_OOP_TO_SMOOI(rcv); + ec = MOO_OOP_TO_SMOOI(rcv); if (ec < 0) ec = 0; - STIX_STACK_SETRET (stix, nargs, STIX_ERROR_TO_OOP(ec)); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, MOO_ERROR_TO_OOP(ec)); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_error_as_character (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_error_as_character (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv; - stix_ooi_t ec; + moo_oop_t rcv; + moo_ooi_t ec; - STIX_ASSERT (stix, nargs == 0); + MOO_ASSERT (moo, nargs == 0); - rcv = STIX_STACK_GETRCV(stix, nargs); - if (!STIX_OOP_IS_ERROR(rcv)) return STIX_PF_FAILURE; + rcv = MOO_STACK_GETRCV(moo, nargs); + if (!MOO_OOP_IS_ERROR(rcv)) return MOO_PF_FAILURE; - ec = STIX_OOP_TO_ERROR(rcv); - STIX_ASSERT (stix, STIX_IN_SMOOI_RANGE(ec)); - STIX_STACK_SETRET (stix, nargs, STIX_CHAR_TO_OOP(ec)); - return STIX_PF_SUCCESS; + ec = MOO_OOP_TO_ERROR(rcv); + MOO_ASSERT (moo, MOO_IN_SMOOI_RANGE(ec)); + MOO_STACK_SETRET (moo, nargs, MOO_CHAR_TO_OOP(ec)); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_error_as_integer (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_error_as_integer (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv; - stix_ooi_t ec; + moo_oop_t rcv; + moo_ooi_t ec; - STIX_ASSERT (stix, nargs == 0); + MOO_ASSERT (moo, nargs == 0); - rcv = STIX_STACK_GETRCV(stix, nargs); - if (!STIX_OOP_IS_ERROR(rcv)) return STIX_PF_FAILURE; + rcv = MOO_STACK_GETRCV(moo, nargs); + if (!MOO_OOP_IS_ERROR(rcv)) return MOO_PF_FAILURE; - ec = STIX_OOP_TO_ERROR(rcv); - STIX_ASSERT (stix, STIX_IN_SMOOI_RANGE(ec)); - STIX_STACK_SETRET (stix, nargs, STIX_SMOOI_TO_OOP(ec)); - return STIX_PF_SUCCESS; + ec = MOO_OOP_TO_ERROR(rcv); + MOO_ASSERT (moo, MOO_IN_SMOOI_RANGE(ec)); + MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(ec)); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_error_as_string (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_error_as_string (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, ss; - stix_ooi_t ec; - const stix_ooch_t* s; + moo_oop_t rcv, ss; + moo_ooi_t ec; + const moo_ooch_t* s; - STIX_ASSERT (stix, nargs == 0); + MOO_ASSERT (moo, nargs == 0); - rcv = STIX_STACK_GETRCV(stix, nargs); - if (!STIX_OOP_IS_ERROR(rcv)) return STIX_PF_FAILURE; + rcv = MOO_STACK_GETRCV(moo, nargs); + if (!MOO_OOP_IS_ERROR(rcv)) return MOO_PF_FAILURE; - ec = STIX_OOP_TO_ERROR(rcv); - STIX_ASSERT (stix, STIX_IN_SMOOI_RANGE(ec)); + ec = MOO_OOP_TO_ERROR(rcv); + MOO_ASSERT (moo, MOO_IN_SMOOI_RANGE(ec)); /* TODO: error string will be mostly the same.. do i really have to call makestring every time? */ - s = stix_errnumtoerrstr (ec); - ss = stix_makestring (stix, s, stix_countoocstr(s)); - if (!ss) return STIX_PF_HARD_FAILURE; + s = moo_errnumtoerrstr (ec); + ss = moo_makestring (moo, s, moo_countoocstr(s)); + if (!ss) return MOO_PF_HARD_FAILURE; - STIX_STACK_SETRET (stix, nargs, ss); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, ss); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_ffi_open (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_ffi_open (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg; + moo_oop_t rcv, arg; void* handle; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - if (!STIX_ISTYPEOF(stix, arg, STIX_OBJ_TYPE_CHAR)) + if (!MOO_ISTYPEOF(moo, arg, MOO_OBJ_TYPE_CHAR)) { /* TODO: more info on error */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - if (!stix->vmprim.dl_open) + if (!moo->vmprim.dl_open) { /* TODO: more info on error */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } /* TODO: check null-termination... */ - handle = stix->vmprim.dl_open (stix, ((stix_oop_char_t)arg)->slot); + handle = moo->vmprim.dl_open (moo, ((moo_oop_char_t)arg)->slot); if (!handle) { /* TODO: more info on error */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - STIX_STACK_POP (stix); + MOO_STACK_POP (moo); /* TODO: how to hold an address? as an integer???? or a byte array? fix this not to loose accuracy*/ - STIX_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(handle)); + MOO_STACK_SETTOP (moo, MOO_SMOOI_TO_OOP(handle)); - return STIX_PF_SUCCESS; + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_ffi_close (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_ffi_close (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, arg; + moo_oop_t rcv, arg; void* handle; - STIX_ASSERT (stix, nargs == 1); + MOO_ASSERT (moo, nargs == 1); - rcv = STIX_STACK_GETRCV(stix, nargs); - arg = STIX_STACK_GETARG(stix, nargs, 0); + rcv = MOO_STACK_GETRCV(moo, nargs); + arg = MOO_STACK_GETARG(moo, nargs, 0); - if (!STIX_OOP_IS_SMOOI(arg)) + if (!MOO_OOP_IS_SMOOI(arg)) { /* TODO: more info on error */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - STIX_STACK_POP (stix); + MOO_STACK_POP (moo); - handle = (void*)STIX_OOP_TO_SMOOI(arg); /* TODO: how to store void* ???. fix this not to loose accuracy */ - if (stix->vmprim.dl_close) stix->vmprim.dl_close (stix, handle); - return STIX_PF_SUCCESS; + handle = (void*)MOO_OOP_TO_SMOOI(arg); /* TODO: how to store void* ???. fix this not to loose accuracy */ + if (moo->vmprim.dl_close) moo->vmprim.dl_close (moo, handle); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_ffi_call (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_ffi_call (moo_t* moo, moo_ooi_t nargs) { #if defined(USE_DYNCALL) - stix_oop_t rcv, fun, sig, args; + moo_oop_t rcv, fun, sig, args; - STIX_ASSERT (stix, nargs == 3); + MOO_ASSERT (moo, nargs == 3); - rcv = STIX_STACK_GET(stix, stix->sp - 3); - fun = STIX_STACK_GET(stix, stix->sp - 2); - sig = STIX_STACK_GET(stix, stix->sp - 1); - args = STIX_STACK_GET(stix, stix->sp); + rcv = MOO_STACK_GET(moo, moo->sp - 3); + fun = MOO_STACK_GET(moo, moo->sp - 2); + sig = MOO_STACK_GET(moo, moo->sp - 1); + args = MOO_STACK_GET(moo, moo->sp); - if (!STIX_OOP_IS_SMOOI(fun)) /* TODO: how to store pointer */ + if (!MOO_OOP_IS_SMOOI(fun)) /* TODO: how to store pointer */ { /* TODO: more info on error */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - if (!STIX_ISTYPEOF(stix, sig, STIX_OBJ_TYPE_CHAR) || STIX_OBJ_GET_SIZE(sig) <= 0) + if (!MOO_ISTYPEOF(moo, sig, MOO_OBJ_TYPE_CHAR) || MOO_OBJ_GET_SIZE(sig) <= 0) { -STIX_DEBUG0 (stix, "FFI: wrong signature...\n"); - return STIX_PF_FAILURE; +MOO_DEBUG0 (moo, "FFI: wrong signature...\n"); + return MOO_PF_FAILURE; } - if (STIX_CLASSOF(stix,args) != stix->_array) /* TODO: check if arr is a kind of array??? or check if it's indexed */ + if (MOO_CLASSOF(moo,args) != moo->_array) /* TODO: check if arr is a kind of array??? or check if it's indexed */ { /* TODO: more info on error */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } { - stix_oow_t i; + moo_oow_t i; DCCallVM* dc; void* f; - stix_oop_oop_t arr; + moo_oop_oop_t arr; int mode_set; - f = STIX_OOP_TO_SMOOI(fun); /* TODO: decode pointer properly */ - arr = (stix_oop_oop_t)args; + f = MOO_OOP_TO_SMOOI(fun); /* TODO: decode pointer properly */ + arr = (moo_oop_oop_t)args; dc = dcNewCallVM (4096); - if (!dc) return STIX_PF_HARD_FAILURE; /* TODO: proper error handling */ + if (!dc) return MOO_PF_HARD_FAILURE; /* TODO: proper error handling */ -STIX_DEBUG1 (stix, "FFI: CALLING............%p\n", f); +MOO_DEBUG1 (moo, "FFI: CALLING............%p\n", f); /*dcMode (dc, DC_CALL_C_DEFAULT); dcReset (dc);*/ - /*for (i = 2; i < STIX_OBJ_GET_SIZE(sig); i++) + /*for (i = 2; i < MOO_OBJ_GET_SIZE(sig); i++) { - if (((stix_oop_char_t)sig)->slot[i] == '|') + if (((moo_oop_char_t)sig)->slot[i] == '|') { dcMode (dc, DC_CALL_C_ELLIPSIS); -STIX_DEBUG0 (stix, "CALL MODE 111 ERROR %d %d\n", dcGetError (dc), DC_ERROR_UNSUPPORTED_MODE); +MOO_DEBUG0 (moo, "CALL MODE 111 ERROR %d %d\n", dcGetError (dc), DC_ERROR_UNSUPPORTED_MODE); mode_set = 1; break; } } if (!mode_set) */ dcMode (dc, DC_CALL_C_DEFAULT); - for (i = 2; i < STIX_OBJ_GET_SIZE(sig); i++) + for (i = 2; i < MOO_OBJ_GET_SIZE(sig); i++) { -STIX_DEBUG1 (stix, "FFI: CALLING ARG %c\n", ((stix_oop_char_t)sig)->slot[i]); - switch (((stix_oop_char_t)sig)->slot[i]) +MOO_DEBUG1 (moo, "FFI: CALLING ARG %c\n", ((moo_oop_char_t)sig)->slot[i]); + switch (((moo_oop_char_t)sig)->slot[i]) { /* TODO: support more types... */ /* case '|': dcMode (dc, DC_CALL_C_ELLIPSIS_VARARGS); -STIX_DEBUG2 (stix, "CALL MODE 222 ERROR %d %d\n", dcGetError (dc), DC_ERROR_UNSUPPORTED_MODE); +MOO_DEBUG2 (moo, "CALL MODE 222 ERROR %d %d\n", dcGetError (dc), DC_ERROR_UNSUPPORTED_MODE); break; */ case 'c': /* TODO: sanity check on the argument type */ - dcArgChar (dc, STIX_OOP_TO_CHAR(arr->slot[i - 2])); + dcArgChar (dc, MOO_OOP_TO_CHAR(arr->slot[i - 2])); break; case 'i': - dcArgInt (dc, STIX_OOP_TO_SMOOI(arr->slot[i - 2])); + dcArgInt (dc, MOO_OOP_TO_SMOOI(arr->slot[i - 2])); break; case 'l': - dcArgLong (dc, STIX_OOP_TO_SMOOI(arr->slot[i - 2])); + dcArgLong (dc, MOO_OOP_TO_SMOOI(arr->slot[i - 2])); break; case 'L': - dcArgLongLong (dc, STIX_OOP_TO_SMOOI(arr->slot[i - 2])); + dcArgLongLong (dc, MOO_OOP_TO_SMOOI(arr->slot[i - 2])); break; case 's': { - stix_oow_t bcslen, ucslen; - stix_bch_t bcs[1024]; + moo_oow_t bcslen, ucslen; + moo_bch_t bcs[1024]; - ucslen = STIX_OBJ_GET_SIZE(arr->slot[i - 2]); - stix_convootobchars (stix, ((stix_oop_char_t)arr->slot[i - 2])->slot, &ucslen, bcs, &bcslen); /* proper string conversion */ + ucslen = MOO_OBJ_GET_SIZE(arr->slot[i - 2]); + moo_convootobchars (moo, ((moo_oop_char_t)arr->slot[i - 2])->slot, &ucslen, bcs, &bcslen); /* proper string conversion */ bcs[bcslen] = '\0'; dcArgPointer (dc, bcs); @@ -2829,60 +2829,60 @@ STIX_DEBUG2 (stix, "CALL MODE 222 ERROR %d %d\n", dcGetError (dc), DC_ERROR_UNSU } - STIX_STACK_POPS (stix, nargs); + MOO_STACK_POPS (moo, nargs); - switch (((stix_oop_char_t)sig)->slot[0]) + switch (((moo_oop_char_t)sig)->slot[0]) { /* TODO: support more types... */ /* TODO: proper return value conversion */ case 'c': { char r = dcCallChar (dc, f); - STIX_STACK_SETTOP (stix, STIX_CHAR_TO_OOP(r)); + MOO_STACK_SETTOP (moo, MOO_CHAR_TO_OOP(r)); break; } case 'i': { int r = dcCallInt (dc, f); -STIX_DEBUG1 (stix, "CALLED... %d\n", r); -STIX_DEBUG2 (stix, "CALL ERROR %d %d\n", dcGetError (dc), DC_ERROR_UNSUPPORTED_MODE); - STIX_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(r)); +MOO_DEBUG1 (moo, "CALLED... %d\n", r); +MOO_DEBUG2 (moo, "CALL ERROR %d %d\n", dcGetError (dc), DC_ERROR_UNSUPPORTED_MODE); + MOO_STACK_SETTOP (moo, MOO_SMOOI_TO_OOP(r)); break; } case 'l': { long r = dcCallLong (dc, f); - STIX_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(r)); + MOO_STACK_SETTOP (moo, MOO_SMOOI_TO_OOP(r)); break; } case 'L': { long long r = dcCallLongLong (dc, f); - STIX_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(r)); + MOO_STACK_SETTOP (moo, MOO_SMOOI_TO_OOP(r)); break; } case 's': { - stix_oow_t bcslen, ucslen; - stix_ooch_t ucs[1024]; - stix_oop_t s; + moo_oow_t bcslen, ucslen; + moo_ooch_t ucs[1024]; + moo_oop_t s; char* r = dcCallPointer (dc, f); bcslen = strlen(r); - stix_convbtooochars (stix, r, &bcslen, ucs, &ucslen); /* proper string conversion */ + moo_convbtooochars (moo, r, &bcslen, ucs, &ucslen); /* proper string conversion */ - s = stix_makestring(stix, ucs, ucslen) + s = moo_makestring(moo, ucs, ucslen) if (!s) { dcFree (dc); - return STIX_PF_HARD_FAILURE; /* TODO: proper error h andling */ + return MOO_PF_HARD_FAILURE; /* TODO: proper error h andling */ } - STIX_STACK_SETTOP (stix, s); + MOO_STACK_SETTOP (moo, s); break; } @@ -2894,58 +2894,58 @@ STIX_DEBUG2 (stix, "CALL ERROR %d %d\n", dcGetError (dc), DC_ERROR_UNSUPPORTED_M dcFree (dc); } - return STIX_PF_SUCCESS; + return MOO_PF_SUCCESS; #else - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; #endif } -static stix_pfrc_t pf_ffi_getsym (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_ffi_getsym (moo_t* moo, moo_ooi_t nargs) { - stix_oop_t rcv, hnd, fun; + moo_oop_t rcv, hnd, fun; void* sym; - STIX_ASSERT (stix, nargs == 2); + MOO_ASSERT (moo, nargs == 2); - rcv = STIX_STACK_GET(stix, stix->sp - 2); - fun = STIX_STACK_GET(stix, stix->sp - 1); - hnd = STIX_STACK_GET(stix, stix->sp); + rcv = MOO_STACK_GET(moo, moo->sp - 2); + fun = MOO_STACK_GET(moo, moo->sp - 1); + hnd = MOO_STACK_GET(moo, moo->sp); - if (!STIX_OOP_IS_SMOOI(hnd)) /* TODO: how to store pointer */ + if (!MOO_OOP_IS_SMOOI(hnd)) /* TODO: how to store pointer */ { /* TODO: more info on error */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - if (!STIX_ISTYPEOF(stix,fun,STIX_OBJ_TYPE_CHAR)) + if (!MOO_ISTYPEOF(moo,fun,MOO_OBJ_TYPE_CHAR)) { -STIX_DEBUG0 (stix, "wrong function name...\n"); - return STIX_PF_FAILURE; +MOO_DEBUG0 (moo, "wrong function name...\n"); + return MOO_PF_FAILURE; } - if (!stix->vmprim.dl_getsym) + if (!moo->vmprim.dl_getsym) { - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - sym = stix->vmprim.dl_getsym (stix, (void*)STIX_OOP_TO_SMOOI(hnd), ((stix_oop_char_t)fun)->slot); + sym = moo->vmprim.dl_getsym (moo, (void*)MOO_OOP_TO_SMOOI(hnd), ((moo_oop_char_t)fun)->slot); if (!sym) { - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } /* TODO: how to hold an address? as an integer???? or a byte array? */ - STIX_STACK_SETRET (stix, nargs, STIX_SMOOI_TO_OOP(sym)); + MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(sym)); - return STIX_PF_SUCCESS; + return MOO_PF_SUCCESS; } -#define MAX_NARGS STIX_TYPE_MAX(stix_ooi_t) +#define MAX_NARGS MOO_TYPE_MAX(moo_ooi_t) struct pf_t { - stix_ooi_t min_nargs; /* expected number of arguments */ - stix_ooi_t max_nargs; /* expected number of arguments */ - stix_pfimpl_t handler; + moo_ooi_t min_nargs; /* expected number of arguments */ + moo_ooi_t max_nargs; /* expected number of arguments */ + moo_pfimpl_t handler; const char* name; /* the name is supposed to be 7-bit ascii only */ }; typedef struct pf_t pf_t; @@ -3028,104 +3028,104 @@ static pf_t pftab[] = }; -int stix_getpfnum (stix_t* stix, const stix_ooch_t* ptr, stix_oow_t len) +int moo_getpfnum (moo_t* moo, const moo_ooch_t* ptr, moo_oow_t len) { int i; - for (i = 0; i < STIX_COUNTOF(pftab); i++) + for (i = 0; i < MOO_COUNTOF(pftab); i++) { - if (stix_compoocharsbcstr(ptr, len, pftab[i].name) == 0) + if (moo_compoocharsbcstr(ptr, len, pftab[i].name) == 0) { return i; } } - stix->errnum = STIX_ENOENT; + moo->errnum = MOO_ENOENT; return -1; } /* ------------------------------------------------------------------------- */ -static int start_method (stix_t* stix, stix_oop_method_t method, stix_oow_t nargs) +static int start_method (moo_t* moo, moo_oop_method_t method, moo_oow_t nargs) { - stix_ooi_t preamble, preamble_code; + moo_ooi_t preamble, preamble_code; -#if defined(STIX_DEBUG_VM_EXEC) - stix_ooi_t fetched_instruction_pointer = 0; /* set it to a fake value */ +#if defined(MOO_DEBUG_VM_EXEC) + moo_ooi_t fetched_instruction_pointer = 0; /* set it to a fake value */ #endif - preamble = STIX_OOP_TO_SMOOI(method->preamble); + preamble = MOO_OOP_TO_SMOOI(method->preamble); - if (nargs != STIX_OOP_TO_SMOOI(method->tmpr_nargs)) + if (nargs != MOO_OOP_TO_SMOOI(method->tmpr_nargs)) { - stix_ooi_t preamble_flags; + moo_ooi_t preamble_flags; - preamble_flags = STIX_METHOD_GET_PREAMBLE_FLAGS(preamble); - if (!(preamble_flags & STIX_METHOD_PREAMBLE_FLAG_VARIADIC)) + preamble_flags = MOO_METHOD_GET_PREAMBLE_FLAGS(preamble); + if (!(preamble_flags & MOO_METHOD_PREAMBLE_FLAG_VARIADIC)) { -/* TODO: better to throw a stix exception so that the caller can catch it??? */ - STIX_LOG3 (stix, STIX_LOG_IC | STIX_LOG_FATAL, +/* TODO: better to throw a moo exception so that the caller can catch it??? */ + MOO_LOG3 (moo, MOO_LOG_IC | MOO_LOG_FATAL, "Fatal error - Argument count mismatch for a non-variadic method [%O] - %zd expected, %zu given\n", - method->name, STIX_OOP_TO_SMOOI(method->tmpr_nargs), nargs); - stix->errnum = STIX_EINVAL; + method->name, MOO_OOP_TO_SMOOI(method->tmpr_nargs), nargs); + moo->errnum = MOO_EINVAL; return -1; } } - preamble_code = STIX_METHOD_GET_PREAMBLE_CODE(preamble); + preamble_code = MOO_METHOD_GET_PREAMBLE_CODE(preamble); switch (preamble_code) { - case STIX_METHOD_PREAMBLE_RETURN_RECEIVER: - LOG_INST_0 (stix, "preamble_return_receiver"); - STIX_STACK_POPS (stix, nargs); /* pop arguments only*/ + case MOO_METHOD_PREAMBLE_RETURN_RECEIVER: + LOG_INST_0 (moo, "preamble_return_receiver"); + MOO_STACK_POPS (moo, nargs); /* pop arguments only*/ break; - case STIX_METHOD_PREAMBLE_RETURN_NIL: - LOG_INST_0 (stix, "preamble_return_nil"); - STIX_STACK_POPS (stix, nargs); - STIX_STACK_SETTOP (stix, stix->_nil); + case MOO_METHOD_PREAMBLE_RETURN_NIL: + LOG_INST_0 (moo, "preamble_return_nil"); + MOO_STACK_POPS (moo, nargs); + MOO_STACK_SETTOP (moo, moo->_nil); break; - case STIX_METHOD_PREAMBLE_RETURN_TRUE: - LOG_INST_0 (stix, "preamble_return_true"); - STIX_STACK_POPS (stix, nargs); - STIX_STACK_SETTOP (stix, stix->_true); + case MOO_METHOD_PREAMBLE_RETURN_TRUE: + LOG_INST_0 (moo, "preamble_return_true"); + MOO_STACK_POPS (moo, nargs); + MOO_STACK_SETTOP (moo, moo->_true); break; - case STIX_METHOD_PREAMBLE_RETURN_FALSE: - LOG_INST_0 (stix, "preamble_return_false"); - STIX_STACK_POPS (stix, nargs); - STIX_STACK_SETTOP (stix, stix->_false); + case MOO_METHOD_PREAMBLE_RETURN_FALSE: + LOG_INST_0 (moo, "preamble_return_false"); + MOO_STACK_POPS (moo, nargs); + MOO_STACK_SETTOP (moo, moo->_false); break; - case STIX_METHOD_PREAMBLE_RETURN_INDEX: + case MOO_METHOD_PREAMBLE_RETURN_INDEX: /* preamble_index field is used to store a positive integer */ - LOG_INST_1 (stix, "preamble_return_index %zd", STIX_METHOD_GET_PREAMBLE_INDEX(preamble)); - STIX_STACK_POPS (stix, nargs); - STIX_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(STIX_METHOD_GET_PREAMBLE_INDEX(preamble))); + LOG_INST_1 (moo, "preamble_return_index %zd", MOO_METHOD_GET_PREAMBLE_INDEX(preamble)); + MOO_STACK_POPS (moo, nargs); + MOO_STACK_SETTOP (moo, MOO_SMOOI_TO_OOP(MOO_METHOD_GET_PREAMBLE_INDEX(preamble))); break; - case STIX_METHOD_PREAMBLE_RETURN_NEGINDEX: + case MOO_METHOD_PREAMBLE_RETURN_NEGINDEX: /* preamble_index field is used to store a negative integer */ - LOG_INST_1 (stix, "preamble_return_negindex %zd", STIX_METHOD_GET_PREAMBLE_INDEX(preamble)); - STIX_STACK_POPS (stix, nargs); - STIX_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(-STIX_METHOD_GET_PREAMBLE_INDEX(preamble))); + LOG_INST_1 (moo, "preamble_return_negindex %zd", MOO_METHOD_GET_PREAMBLE_INDEX(preamble)); + MOO_STACK_POPS (moo, nargs); + MOO_STACK_SETTOP (moo, MOO_SMOOI_TO_OOP(-MOO_METHOD_GET_PREAMBLE_INDEX(preamble))); break; - case STIX_METHOD_PREAMBLE_RETURN_INSTVAR: + case MOO_METHOD_PREAMBLE_RETURN_INSTVAR: { - stix_oop_oop_t rcv; + moo_oop_oop_t rcv; - STIX_STACK_POPS (stix, nargs); /* pop arguments only */ + MOO_STACK_POPS (moo, nargs); /* pop arguments only */ - LOG_INST_1 (stix, "preamble_return_instvar %zd", STIX_METHOD_GET_PREAMBLE_INDEX(preamble)); + LOG_INST_1 (moo, "preamble_return_instvar %zd", MOO_METHOD_GET_PREAMBLE_INDEX(preamble)); /* replace the receiver by an instance variable of the receiver */ - rcv = (stix_oop_oop_t)STIX_STACK_GETTOP(stix); - STIX_ASSERT (stix, STIX_OBJ_GET_FLAGS_TYPE(rcv) == STIX_OBJ_TYPE_OOP); - STIX_ASSERT (stix, STIX_OBJ_GET_SIZE(rcv) > STIX_METHOD_GET_PREAMBLE_INDEX(preamble)); + rcv = (moo_oop_oop_t)MOO_STACK_GETTOP(moo); + MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_TYPE(rcv) == MOO_OBJ_TYPE_OOP); + MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(rcv) > MOO_METHOD_GET_PREAMBLE_INDEX(preamble)); - if (rcv == (stix_oop_oop_t)stix->active_context) + if (rcv == (moo_oop_oop_t)moo->active_context) { /* the active context object doesn't keep * the most up-to-date information in the @@ -3136,68 +3136,68 @@ static int start_method (stix_t* stix, stix_oop_method_t method, stix_oow_t narg * skips activation of a new method context * that would commit these fields. */ - STORE_ACTIVE_IP (stix); - STORE_ACTIVE_SP (stix); + STORE_ACTIVE_IP (moo); + STORE_ACTIVE_SP (moo); } /* this accesses the instance variable of the receiver */ - STIX_STACK_SET (stix, stix->sp, rcv->slot[STIX_METHOD_GET_PREAMBLE_INDEX(preamble)]); + MOO_STACK_SET (moo, moo->sp, rcv->slot[MOO_METHOD_GET_PREAMBLE_INDEX(preamble)]); break; } - case STIX_METHOD_PREAMBLE_PRIMITIVE: + case MOO_METHOD_PREAMBLE_PRIMITIVE: { - stix_ooi_t pfnum; + moo_ooi_t pfnum; - pfnum = STIX_METHOD_GET_PREAMBLE_INDEX(preamble); - LOG_INST_1 (stix, "preamble_primitive %zd", pf_no); + pfnum = MOO_METHOD_GET_PREAMBLE_INDEX(preamble); + LOG_INST_1 (moo, "preamble_primitive %zd", pf_no); - if (pfnum >= 0 && pfnum < STIX_COUNTOF(pftab) && + if (pfnum >= 0 && pfnum < MOO_COUNTOF(pftab) && (nargs >= pftab[pfnum].min_nargs && nargs <= pftab[pfnum].max_nargs)) { int n; - stix_pushtmp (stix, (stix_oop_t*)&method); - n = pftab[pfnum].handler (stix, nargs); - stix_poptmp (stix); - if (n <= STIX_PF_HARD_FAILURE) return -1; - if (n >= STIX_PF_SUCCESS) break; + moo_pushtmp (moo, (moo_oop_t*)&method); + n = pftab[pfnum].handler (moo, nargs); + moo_poptmp (moo); + if (n <= MOO_PF_HARD_FAILURE) return -1; + if (n >= MOO_PF_SUCCESS) break; } /* soft primitive failure */ - if (activate_new_method (stix, method, nargs) <= -1) return -1; + if (activate_new_method (moo, method, nargs) <= -1) return -1; break; } - case STIX_METHOD_PREAMBLE_NAMED_PRIMITIVE: + case MOO_METHOD_PREAMBLE_NAMED_PRIMITIVE: { - stix_ooi_t pf_name_index; - stix_oop_t name; - stix_pfimpl_t handler; - stix_oow_t w; - stix_ooi_t /*sp,*/ sb; + moo_ooi_t pf_name_index; + moo_oop_t name; + moo_pfimpl_t handler; + moo_oow_t w; + moo_ooi_t /*sp,*/ sb; - /*sp = stix->sp;*/ - sb = stix->sp - nargs - 1; /* stack base before receiver and arguments */ + /*sp = moo->sp;*/ + sb = moo->sp - nargs - 1; /* stack base before receiver and arguments */ - pf_name_index = STIX_METHOD_GET_PREAMBLE_INDEX(preamble); - LOG_INST_1 (stix, "preamble_named_primitive %zd", pf_name_index); + pf_name_index = MOO_METHOD_GET_PREAMBLE_INDEX(preamble); + LOG_INST_1 (moo, "preamble_named_primitive %zd", pf_name_index); /* merge two SmallIntegers to get a full pointer */ - w = (stix_oow_t)STIX_OOP_TO_SMOOI(method->preamble_data[0]) << (STIX_OOW_BITS / 2) | - (stix_oow_t)STIX_OOP_TO_SMOOI(method->preamble_data[1]); - handler = (stix_pfimpl_t)w; + w = (moo_oow_t)MOO_OOP_TO_SMOOI(method->preamble_data[0]) << (MOO_OOW_BITS / 2) | + (moo_oow_t)MOO_OOP_TO_SMOOI(method->preamble_data[1]); + handler = (moo_pfimpl_t)w; if (handler) goto exec_handler; else { - STIX_ASSERT (stix, pf_name_index >= 0); + MOO_ASSERT (moo, pf_name_index >= 0); name = method->slot[pf_name_index]; - STIX_ASSERT (stix, STIX_ISTYPEOF(stix,name,STIX_OBJ_TYPE_CHAR)); - STIX_ASSERT (stix, STIX_OBJ_GET_FLAGS_EXTRA(name)); - STIX_ASSERT (stix, STIX_CLASSOF(stix,name) == stix->_symbol); + MOO_ASSERT (moo, MOO_ISTYPEOF(moo,name,MOO_OBJ_TYPE_CHAR)); + MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_EXTRA(name)); + MOO_ASSERT (moo, MOO_CLASSOF(moo,name) == moo->_symbol); - handler = stix_querymod (stix, ((stix_oop_char_t)name)->slot, STIX_OBJ_GET_SIZE(name)); + handler = moo_querymod (moo, ((moo_oop_char_t)name)->slot, MOO_OBJ_GET_SIZE(name)); } if (handler) @@ -3205,11 +3205,11 @@ static int start_method (stix_t* stix, stix_oop_method_t method, stix_oow_t narg int n; /* split a pointer to two OOP fields as SmallIntegers for storing. */ - method->preamble_data[0] = STIX_SMOOI_TO_OOP((stix_oow_t)handler >> (STIX_OOW_BITS / 2)); - method->preamble_data[1] = STIX_SMOOI_TO_OOP((stix_oow_t)handler & STIX_LBMASK(stix_oow_t, STIX_OOW_BITS / 2)); + method->preamble_data[0] = MOO_SMOOI_TO_OOP((moo_oow_t)handler >> (MOO_OOW_BITS / 2)); + method->preamble_data[1] = MOO_SMOOI_TO_OOP((moo_oow_t)handler & MOO_LBMASK(moo_oow_t, MOO_OOW_BITS / 2)); exec_handler: - stix_pushtmp (stix, (stix_oop_t*)&method); + moo_pushtmp (moo, (moo_oop_t*)&method); /* the primitive handler is executed without activating the method itself. * one major difference between the primitive function and the normal method @@ -3217,76 +3217,76 @@ static int start_method (stix_t* stix, stix_oop_method_t method, stix_oow_t narg * directly in the stack unlik a normal activated method context where the * arguments are copied to the back. */ - n = handler (stix, nargs); + n = handler (moo, nargs); - stix_poptmp (stix); - if (n <= STIX_PF_HARD_FAILURE) + moo_poptmp (moo); + if (n <= MOO_PF_HARD_FAILURE) { - STIX_DEBUG2 (stix, "Hard failure indicated by primitive function %p - return code %d\n", handler, n); + MOO_DEBUG2 (moo, "Hard failure indicated by primitive function %p - return code %d\n", handler, n); return -1; /* hard primitive failure */ } - if (n >= STIX_PF_SUCCESS) break; /* primitive ok*/ + if (n >= MOO_PF_SUCCESS) break; /* primitive ok*/ /* soft primitive failure */ - STIX_DEBUG1 (stix, "Soft failure indicated by primitive function %p\n", handler); + MOO_DEBUG1 (moo, "Soft failure indicated by primitive function %p\n", handler); } else { /* no handler found */ - STIX_DEBUG0 (stix, "Soft failure for non-existent primitive function\n"); + MOO_DEBUG0 (moo, "Soft failure for non-existent primitive function\n"); } - #if defined(STIX_USE_OBJECT_TRAILER) - STIX_ASSERT (stix, STIX_OBJ_GET_FLAGS_TRAILER(method)); - if (STIX_METHOD_GET_CODE_SIZE(method) == 0) /* this trailer size field not a small integer */ + #if defined(MOO_USE_OBJECT_TRAILER) + MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_TRAILER(method)); + if (MOO_METHOD_GET_CODE_SIZE(method) == 0) /* this trailer size field not a small integer */ #else - if (method->code == stix->_nil) + if (method->code == moo->_nil) #endif { /* no byte code to execute */ /* TODO: what is the best tactics? emulate "self primitiveFailed"? */ /* force restore stack pointers */ - stix->sp = sb; - STIX_STACK_PUSH (stix, stix->_nil); + moo->sp = sb; + MOO_STACK_PUSH (moo, moo->_nil); return -1; } else { - if (activate_new_method (stix, method, nargs) <= -1) return -1; + if (activate_new_method (moo, method, nargs) <= -1) return -1; } break; } default: - STIX_ASSERT (stix, preamble_code == STIX_METHOD_PREAMBLE_NONE || - preamble_code == STIX_METHOD_PREAMBLE_EXCEPTION || - preamble_code == STIX_METHOD_PREAMBLE_ENSURE); - if (activate_new_method (stix, method, nargs) <= -1) return -1; + MOO_ASSERT (moo, preamble_code == MOO_METHOD_PREAMBLE_NONE || + preamble_code == MOO_METHOD_PREAMBLE_EXCEPTION || + preamble_code == MOO_METHOD_PREAMBLE_ENSURE); + if (activate_new_method (moo, method, nargs) <= -1) return -1; break; } return 0; } -static int send_message (stix_t* stix, stix_oop_char_t selector, int to_super, stix_ooi_t nargs) +static int send_message (moo_t* moo, moo_oop_char_t selector, int to_super, moo_ooi_t nargs) { - stix_oocs_t mthname; - stix_oop_t receiver; - stix_oop_method_t method; + moo_oocs_t mthname; + moo_oop_t receiver; + moo_oop_method_t method; - STIX_ASSERT (stix, STIX_OOP_IS_POINTER(selector)); - STIX_ASSERT (stix, STIX_OBJ_GET_FLAGS_TYPE(selector) == STIX_OBJ_TYPE_CHAR); - STIX_ASSERT (stix, STIX_CLASSOF(stix, selector) == stix->_symbol); + MOO_ASSERT (moo, MOO_OOP_IS_POINTER(selector)); + MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_TYPE(selector) == MOO_OBJ_TYPE_CHAR); + MOO_ASSERT (moo, MOO_CLASSOF(moo, selector) == moo->_symbol); - receiver = STIX_STACK_GET(stix, stix->sp - nargs); + receiver = MOO_STACK_GET(moo, moo->sp - nargs); mthname.ptr = selector->slot; - mthname.len = STIX_OBJ_GET_SIZE(selector); - method = find_method (stix, receiver, &mthname, to_super); + mthname.len = MOO_OBJ_GET_SIZE(selector); + method = find_method (moo, receiver, &mthname, to_super); if (!method) { - static stix_ooch_t fbm[] = { + static moo_ooch_t fbm[] = { 'd', 'o', 'e', 's', 'N', 'o', 't', 'U', 'n', 'd', 'e', 'r', 's', 't', 'a', 'n', 'd', ':' @@ -3294,16 +3294,16 @@ static int send_message (stix_t* stix, stix_oop_char_t selector, int to_super, s mthname.ptr = fbm; mthname.len = 18; - method = find_method (stix, receiver, &mthname, 0); + method = find_method (moo, receiver, &mthname, 0); if (!method) { /* this must not happen as long as doesNotUnderstand: is implemented under Apex. * this check should indicate a very serious internal problem */ - STIX_LOG4 (stix, STIX_LOG_IC | STIX_LOG_FATAL, + MOO_LOG4 (moo, MOO_LOG_IC | MOO_LOG_FATAL, "Fatal error - receiver [%O] of class [%O] does not understand a message [%.*js]\n", - receiver, STIX_CLASSOF(stix, receiver), mthname.len, mthname.ptr); + receiver, MOO_CLASSOF(moo, receiver), mthname.len, mthname.ptr); - stix->errnum = STIX_EMSGSND; + moo->errnum = MOO_EMSGSND; return -1; } else @@ -3312,126 +3312,126 @@ static int send_message (stix_t* stix, stix_oop_char_t selector, int to_super, s * has been called. */ /* TODO: if i manipulate the stack this way here, the stack trace for the last call is kind of lost. * how can i preserve it gracefully? */ - STIX_STACK_POPS (stix, nargs); + MOO_STACK_POPS (moo, nargs); nargs = 1; - STIX_STACK_PUSH (stix, (stix_oop_t)selector); + MOO_STACK_PUSH (moo, (moo_oop_t)selector); } } - return start_method (stix, method, nargs); + return start_method (moo, method, nargs); } -static int send_private_message (stix_t* stix, const stix_ooch_t* nameptr, stix_oow_t namelen, int to_super, stix_ooi_t nargs) +static int send_private_message (moo_t* moo, const moo_ooch_t* nameptr, moo_oow_t namelen, int to_super, moo_ooi_t nargs) { - stix_oocs_t mthname; - stix_oop_t receiver; - stix_oop_method_t method; + moo_oocs_t mthname; + moo_oop_t receiver; + moo_oop_method_t method; - receiver = STIX_STACK_GET(stix, stix->sp - nargs); + receiver = MOO_STACK_GET(moo, moo->sp - nargs); - mthname.ptr = (stix_ooch_t*)nameptr; + mthname.ptr = (moo_ooch_t*)nameptr; mthname.len = namelen; - method = find_method (stix, receiver, &mthname, to_super); + method = find_method (moo, receiver, &mthname, to_super); if (!method) { - STIX_LOG4 (stix, STIX_LOG_IC | STIX_LOG_FATAL, + MOO_LOG4 (moo, MOO_LOG_IC | MOO_LOG_FATAL, "Fatal error - receiver [%O] of class [%O] does not understand a private message [%.*js]\n", - receiver, STIX_CLASSOF(stix, receiver), mthname.len, mthname.ptr); - stix->errnum = STIX_EMSGSND; + receiver, MOO_CLASSOF(moo, receiver), mthname.len, mthname.ptr); + moo->errnum = MOO_EMSGSND; return -1; } - return start_method (stix, method, nargs); + return start_method (moo, method, nargs); } /* ------------------------------------------------------------------------- */ -int stix_execute (stix_t* stix) +int moo_execute (moo_t* moo) { - stix_oob_t bcode; - stix_oow_t b1, b2; - stix_oop_t return_value; + moo_oob_t bcode; + moo_oow_t b1, b2; + moo_oop_t return_value; int unwind_protect; - stix_oop_context_t unwind_start; - stix_oop_context_t unwind_stop; + moo_oop_context_t unwind_start; + moo_oop_context_t unwind_stop; -#if defined(STIX_PROFILE_VM) - stix_uintmax_t inst_counter = 0; +#if defined(MOO_PROFILE_VM) + moo_uintmax_t inst_counter = 0; #endif -#if defined(STIX_DEBUG_VM_EXEC) - stix_ooi_t fetched_instruction_pointer; +#if defined(MOO_DEBUG_VM_EXEC) + moo_ooi_t fetched_instruction_pointer; #endif - STIX_ASSERT (stix, stix->active_context != STIX_NULL); + MOO_ASSERT (moo, moo->active_context != MOO_NULL); - vm_startup (stix); - stix->proc_switched = 0; + vm_startup (moo); + moo->proc_switched = 0; while (1) { - if (stix->sem_heap_count > 0) + if (moo->sem_heap_count > 0) { - stix_ntime_t ft, now; - vm_gettime (stix, &now); + moo_ntime_t ft, now; + vm_gettime (moo, &now); do { - STIX_ASSERT (stix, STIX_OOP_IS_SMOOI(stix->sem_heap[0]->heap_ftime_sec)); - STIX_ASSERT (stix, STIX_OOP_IS_SMOOI(stix->sem_heap[0]->heap_ftime_nsec)); + MOO_ASSERT (moo, MOO_OOP_IS_SMOOI(moo->sem_heap[0]->heap_ftime_sec)); + MOO_ASSERT (moo, MOO_OOP_IS_SMOOI(moo->sem_heap[0]->heap_ftime_nsec)); - STIX_INITNTIME (&ft, - STIX_OOP_TO_SMOOI(stix->sem_heap[0]->heap_ftime_sec), - STIX_OOP_TO_SMOOI(stix->sem_heap[0]->heap_ftime_nsec) + MOO_INITNTIME (&ft, + MOO_OOP_TO_SMOOI(moo->sem_heap[0]->heap_ftime_sec), + MOO_OOP_TO_SMOOI(moo->sem_heap[0]->heap_ftime_nsec) ); - if (STIX_CMPNTIME(&ft, (stix_ntime_t*)&now) <= 0) + if (MOO_CMPNTIME(&ft, (moo_ntime_t*)&now) <= 0) { - stix_oop_process_t proc; + moo_oop_process_t proc; /* waited long enough. signal the semaphore */ - proc = signal_semaphore (stix, stix->sem_heap[0]); - /* [NOTE] no stix_pushtmp() on proc. no GC must occur + proc = signal_semaphore (moo, moo->sem_heap[0]); + /* [NOTE] no moo_pushtmp() on proc. no GC must occur * in the following line until it's used for * wake_new_process() below. */ - delete_from_sem_heap (stix, 0); + delete_from_sem_heap (moo, 0); /* if no process is waiting on the semaphore, - * signal_semaphore() returns stix->_nil. */ + * signal_semaphore() returns moo->_nil. */ - if (stix->processor->active == stix->nil_process && (stix_oop_t)proc != stix->_nil) + if (moo->processor->active == moo->nil_process && (moo_oop_t)proc != moo->_nil) { /* this is the only runnable process. * switch the process to the running state. * it uses wake_new_process() instead of * switch_to_process() as there is no running * process at this moment */ - STIX_ASSERT (stix, proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_RUNNABLE)); - STIX_ASSERT (stix, proc == stix->processor->runnable_head); + MOO_ASSERT (moo, proc->state == MOO_SMOOI_TO_OOP(PROC_STATE_RUNNABLE)); + MOO_ASSERT (moo, proc == moo->processor->runnable_head); - wake_new_process (stix, proc); - stix->proc_switched = 1; + wake_new_process (moo, proc); + moo->proc_switched = 1; } } - else if (stix->processor->active == stix->nil_process) + else if (moo->processor->active == moo->nil_process) { - STIX_SUBNTIME (&ft, &ft, (stix_ntime_t*)&now); - vm_sleep (stix, &ft); /* TODO: change this to i/o multiplexer??? */ - vm_gettime (stix, &now); + MOO_SUBNTIME (&ft, &ft, (moo_ntime_t*)&now); + vm_sleep (moo, &ft); /* TODO: change this to i/o multiplexer??? */ + vm_gettime (moo, &now); } else { break; } } - while (stix->sem_heap_count > 0); + while (moo->sem_heap_count > 0); } - if (stix->processor->active == stix->nil_process) + if (moo->processor->active == moo->nil_process) { /* no more waiting semaphore and no more process */ - STIX_ASSERT (stix, stix->processor->tally = STIX_SMOOI_TO_OOP(0)); - STIX_LOG0 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "No more runnable process\n"); + MOO_ASSERT (moo, moo->processor->tally = MOO_SMOOI_TO_OOP(0)); + MOO_LOG0 (moo, MOO_LOG_IC | MOO_LOG_DEBUG, "No more runnable process\n"); #if 0 if (there is semaphore awaited.... ) @@ -3443,11 +3443,11 @@ int stix_execute (stix_t* stix) break; } - while (stix->sem_list_count > 0) + while (moo->sem_list_count > 0) { /* handle async signals */ - --stix->sem_list_count; - signal_semaphore (stix, stix->sem_list[stix->sem_list_count]); + --moo->sem_list_count; + signal_semaphore (moo, moo->sem_list[moo->sem_list_count]); } /* if (semaphore heap has pending request) @@ -3456,22 +3456,22 @@ int stix_execute (stix_t* stix) }*/ /* TODO: implement different process switching scheme - time-slice or clock based??? */ -#if defined(STIX_EXTERNAL_PROCESS_SWITCH) - if (!stix->proc_switched && stix->switch_proc) { switch_to_next_runnable_process (stix); } - stix->switch_proc = 0; +#if defined(MOO_EXTERNAL_PROCESS_SWITCH) + if (!moo->proc_switched && moo->switch_proc) { switch_to_next_runnable_process (moo); } + moo->switch_proc = 0; #else - if (!stix->proc_switched) { switch_to_next_runnable_process (stix); } + if (!moo->proc_switched) { switch_to_next_runnable_process (moo); } #endif - stix->proc_switched = 0; + moo->proc_switched = 0; -#if defined(STIX_DEBUG_VM_EXEC) - fetched_instruction_pointer = stix->ip; +#if defined(MOO_DEBUG_VM_EXEC) + fetched_instruction_pointer = moo->ip; #endif - FETCH_BYTE_CODE_TO (stix, bcode); - /*while (bcode == BCODE_NOOP) FETCH_BYTE_CODE_TO (stix, bcode);*/ + FETCH_BYTE_CODE_TO (moo, bcode); + /*while (bcode == BCODE_NOOP) FETCH_BYTE_CODE_TO (moo, bcode);*/ -#if defined(STIX_PROFILE_VM) +#if defined(MOO_PROFILE_VM) inst_counter++; #endif @@ -3480,7 +3480,7 @@ int stix_execute (stix_t* stix) /* ------------------------------------------------- */ case BCODE_PUSH_INSTVAR_X: - FETCH_PARAM_CODE_TO (stix, b1); + FETCH_PARAM_CODE_TO (moo, b1); goto push_instvar; case BCODE_PUSH_INSTVAR_0: case BCODE_PUSH_INSTVAR_1: @@ -3492,15 +3492,15 @@ int stix_execute (stix_t* stix) case BCODE_PUSH_INSTVAR_7: b1 = bcode & 0x7; /* low 3 bits */ push_instvar: - LOG_INST_1 (stix, "push_instvar %zu", b1); - STIX_ASSERT (stix, STIX_OBJ_GET_FLAGS_TYPE(stix->active_context->origin->receiver_or_source) == STIX_OBJ_TYPE_OOP); - STIX_STACK_PUSH (stix, ((stix_oop_oop_t)stix->active_context->origin->receiver_or_source)->slot[b1]); + LOG_INST_1 (moo, "push_instvar %zu", b1); + MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_TYPE(moo->active_context->origin->receiver_or_source) == MOO_OBJ_TYPE_OOP); + MOO_STACK_PUSH (moo, ((moo_oop_oop_t)moo->active_context->origin->receiver_or_source)->slot[b1]); break; /* ------------------------------------------------- */ case BCODE_STORE_INTO_INSTVAR_X: - FETCH_PARAM_CODE_TO (stix, b1); + FETCH_PARAM_CODE_TO (moo, b1); goto store_instvar; case BCODE_STORE_INTO_INSTVAR_0: case BCODE_STORE_INTO_INSTVAR_1: @@ -3512,14 +3512,14 @@ int stix_execute (stix_t* stix) case BCODE_STORE_INTO_INSTVAR_7: b1 = bcode & 0x7; /* low 3 bits */ store_instvar: - LOG_INST_1 (stix, "store_into_instvar %zu", b1); - STIX_ASSERT (stix, STIX_OBJ_GET_FLAGS_TYPE(stix->active_context->receiver_or_source) == STIX_OBJ_TYPE_OOP); - ((stix_oop_oop_t)stix->active_context->origin->receiver_or_source)->slot[b1] = STIX_STACK_GETTOP(stix); + LOG_INST_1 (moo, "store_into_instvar %zu", b1); + MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_TYPE(moo->active_context->receiver_or_source) == MOO_OBJ_TYPE_OOP); + ((moo_oop_oop_t)moo->active_context->origin->receiver_or_source)->slot[b1] = MOO_STACK_GETTOP(moo); break; /* ------------------------------------------------- */ case BCODE_POP_INTO_INSTVAR_X: - FETCH_PARAM_CODE_TO (stix, b1); + FETCH_PARAM_CODE_TO (moo, b1); goto pop_into_instvar; case BCODE_POP_INTO_INSTVAR_0: case BCODE_POP_INTO_INSTVAR_1: @@ -3531,17 +3531,17 @@ int stix_execute (stix_t* stix) case BCODE_POP_INTO_INSTVAR_7: b1 = bcode & 0x7; /* low 3 bits */ pop_into_instvar: - LOG_INST_1 (stix, "pop_into_instvar %zu", b1); - STIX_ASSERT (stix, STIX_OBJ_GET_FLAGS_TYPE(stix->active_context->receiver_or_source) == STIX_OBJ_TYPE_OOP); - ((stix_oop_oop_t)stix->active_context->origin->receiver_or_source)->slot[b1] = STIX_STACK_GETTOP(stix); - STIX_STACK_POP (stix); + LOG_INST_1 (moo, "pop_into_instvar %zu", b1); + MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_TYPE(moo->active_context->receiver_or_source) == MOO_OBJ_TYPE_OOP); + ((moo_oop_oop_t)moo->active_context->origin->receiver_or_source)->slot[b1] = MOO_STACK_GETTOP(moo); + MOO_STACK_POP (moo); break; /* ------------------------------------------------- */ case BCODE_PUSH_TEMPVAR_X: case BCODE_STORE_INTO_TEMPVAR_X: case BCODE_POP_INTO_TEMPVAR_X: - FETCH_PARAM_CODE_TO (stix, b1); + FETCH_PARAM_CODE_TO (moo, b1); goto handle_tempvar; case BCODE_PUSH_TEMPVAR_0: @@ -3569,46 +3569,46 @@ int stix_execute (stix_t* stix) case BCODE_POP_INTO_TEMPVAR_6: case BCODE_POP_INTO_TEMPVAR_7: { - stix_oop_context_t ctx; - stix_ooi_t bx; + moo_oop_context_t ctx; + moo_ooi_t bx; b1 = bcode & 0x7; /* low 3 bits */ handle_tempvar: - #if defined(STIX_USE_CTXTEMPVAR) + #if defined(MOO_USE_CTXTEMPVAR) /* when CTXTEMPVAR inststructions are used, the above * instructions are used only for temporary access * outside a block. i can assume that the temporary * variable index is pointing to one of temporaries * in the relevant method context */ - ctx = stix->active_context->origin; + ctx = moo->active_context->origin; bx = b1; - STIX_ASSERT (stix, STIX_CLASSOF(stix, ctx) == stix->_method_context); + MOO_ASSERT (moo, MOO_CLASSOF(moo, ctx) == moo->_method_context); #else /* otherwise, the index may point to a temporaries * declared inside a block */ - if (stix->active_context->home != stix->_nil) + if (moo->active_context->home != moo->_nil) { /* this code assumes that the method context and * the block context place some key fields in the * same offset. such fields include 'home', 'ntmprs' */ - stix_oop_t home; - stix_ooi_t home_ntmprs; + moo_oop_t home; + moo_ooi_t home_ntmprs; - ctx = stix->active_context; + ctx = moo->active_context; home = ctx->home; do { /* ntmprs contains the number of defined temporaries * including those defined in the home context */ - home_ntmprs = STIX_OOP_TO_SMOOI(((stix_oop_context_t)home)->ntmprs); + home_ntmprs = MOO_OOP_TO_SMOOI(((moo_oop_context_t)home)->ntmprs); if (b1 >= home_ntmprs) break; - ctx = (stix_oop_context_t)home; - home = ((stix_oop_context_t)home)->home; - if (home == stix->_nil) + ctx = (moo_oop_context_t)home; + home = ((moo_oop_context_t)home)->home; + if (home == moo->_nil) { home_ntmprs = 0; break; @@ -3622,7 +3622,7 @@ int stix_execute (stix_t* stix) } else { - ctx = stix->active_context; + ctx = moo->active_context; bx = b1; } #endif @@ -3630,23 +3630,23 @@ int stix_execute (stix_t* stix) if ((bcode >> 4) & 1) { /* push - bit 4 on */ - LOG_INST_1 (stix, "push_tempvar %zu", b1); - STIX_STACK_PUSH (stix, ctx->slot[bx]); + LOG_INST_1 (moo, "push_tempvar %zu", b1); + MOO_STACK_PUSH (moo, ctx->slot[bx]); } else { /* store or pop - bit 5 off */ - ctx->slot[bx] = STIX_STACK_GETTOP(stix); + ctx->slot[bx] = MOO_STACK_GETTOP(moo); if ((bcode >> 3) & 1) { /* pop - bit 3 on */ - LOG_INST_1 (stix, "pop_into_tempvar %zu", b1); - STIX_STACK_POP (stix); + LOG_INST_1 (moo, "pop_into_tempvar %zu", b1); + MOO_STACK_POP (moo); } else { - LOG_INST_1 (stix, "store_into_tempvar %zu", b1); + LOG_INST_1 (moo, "store_into_tempvar %zu", b1); } } @@ -3655,7 +3655,7 @@ int stix_execute (stix_t* stix) /* ------------------------------------------------- */ case BCODE_PUSH_LITERAL_X: - FETCH_PARAM_CODE_TO (stix, b1); + FETCH_PARAM_CODE_TO (moo, b1); goto push_literal; case BCODE_PUSH_LITERAL_0: @@ -3668,15 +3668,15 @@ int stix_execute (stix_t* stix) case BCODE_PUSH_LITERAL_7: b1 = bcode & 0x7; /* low 3 bits */ push_literal: - LOG_INST_1 (stix, "push_literal @%zu", b1); - STIX_STACK_PUSH (stix, stix->active_method->slot[b1]); + LOG_INST_1 (moo, "push_literal @%zu", b1); + MOO_STACK_PUSH (moo, moo->active_method->slot[b1]); break; /* ------------------------------------------------- */ case BCODE_PUSH_OBJECT_X: case BCODE_STORE_INTO_OBJECT_X: case BCODE_POP_INTO_OBJECT_X: - FETCH_PARAM_CODE_TO (stix, b1); + FETCH_PARAM_CODE_TO (moo, b1); goto handle_object; case BCODE_PUSH_OBJECT_0: @@ -3692,34 +3692,34 @@ int stix_execute (stix_t* stix) case BCODE_POP_INTO_OBJECT_2: case BCODE_POP_INTO_OBJECT_3: { - stix_oop_association_t ass; + moo_oop_association_t ass; b1 = bcode & 0x3; /* low 2 bits */ handle_object: - ass = (stix_oop_association_t)stix->active_method->slot[b1]; - STIX_ASSERT (stix, STIX_CLASSOF(stix, ass) == stix->_association); + ass = (moo_oop_association_t)moo->active_method->slot[b1]; + MOO_ASSERT (moo, MOO_CLASSOF(moo, ass) == moo->_association); if ((bcode >> 3) & 1) { /* store or pop */ - ass->value = STIX_STACK_GETTOP(stix); + ass->value = MOO_STACK_GETTOP(moo); if ((bcode >> 2) & 1) { /* pop */ - LOG_INST_1 (stix, "pop_into_object @%zu", b1); - STIX_STACK_POP (stix); + LOG_INST_1 (moo, "pop_into_object @%zu", b1); + MOO_STACK_POP (moo); } else { - LOG_INST_1 (stix, "store_into_object @%zu", b1); + LOG_INST_1 (moo, "store_into_object @%zu", b1); } } else { /* push */ - LOG_INST_1 (stix, "push_object @%zu", b1); - STIX_STACK_PUSH (stix, ass->value); + LOG_INST_1 (moo, "push_object @%zu", b1); + MOO_STACK_PUSH (moo, ass->value); } break; } @@ -3727,31 +3727,31 @@ int stix_execute (stix_t* stix) /* -------------------------------------------------------- */ case BCODE_JUMP_FORWARD_X: - FETCH_PARAM_CODE_TO (stix, b1); - LOG_INST_1 (stix, "jump_forward %zu", b1); - stix->ip += b1; + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST_1 (moo, "jump_forward %zu", b1); + moo->ip += b1; break; case BCODE_JUMP_FORWARD_0: case BCODE_JUMP_FORWARD_1: case BCODE_JUMP_FORWARD_2: case BCODE_JUMP_FORWARD_3: - LOG_INST_1 (stix, "jump_forward %zu", (stix_oow_t)(bcode & 0x3)); - stix->ip += (bcode & 0x3); /* low 2 bits */ + LOG_INST_1 (moo, "jump_forward %zu", (moo_oow_t)(bcode & 0x3)); + moo->ip += (bcode & 0x3); /* low 2 bits */ break; case BCODE_JUMP_BACKWARD_X: - FETCH_PARAM_CODE_TO (stix, b1); - LOG_INST_1 (stix, "jump_backward %zu", b1); - stix->ip += b1; + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST_1 (moo, "jump_backward %zu", b1); + moo->ip += b1; break; case BCODE_JUMP_BACKWARD_0: case BCODE_JUMP_BACKWARD_1: case BCODE_JUMP_BACKWARD_2: case BCODE_JUMP_BACKWARD_3: - LOG_INST_1 (stix, "jump_backward %zu", (stix_oow_t)(bcode & 0x3)); - stix->ip -= (bcode & 0x3); /* low 2 bits */ + LOG_INST_1 (moo, "jump_backward %zu", (moo_oow_t)(bcode & 0x3)); + moo->ip -= (bcode & 0x3); /* low 2 bits */ break; case BCODE_JUMP_IF_TRUE_X: @@ -3764,20 +3764,20 @@ int stix_execute (stix_t* stix) case BCODE_JUMP_IF_FALSE_1: case BCODE_JUMP_IF_FALSE_2: case BCODE_JUMP_IF_FALSE_3: -STIX_LOG0 (stix, STIX_LOG_IC | STIX_LOG_FATAL, "<<<<<<<<<<<<<< JUMP NOT IMPLEMENTED YET >>>>>>>>>>>>\n"); -stix->errnum = STIX_ENOIMPL; +MOO_LOG0 (moo, MOO_LOG_IC | MOO_LOG_FATAL, "<<<<<<<<<<<<<< JUMP NOT IMPLEMENTED YET >>>>>>>>>>>>\n"); +moo->errnum = MOO_ENOIMPL; return -1; case BCODE_JUMP2_FORWARD: - FETCH_PARAM_CODE_TO (stix, b1); - LOG_INST_1 (stix, "jump2_forward %zu", b1); - stix->ip += MAX_CODE_JUMP + b1; + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST_1 (moo, "jump2_forward %zu", b1); + moo->ip += MAX_CODE_JUMP + b1; break; case BCODE_JUMP2_BACKWARD: - FETCH_PARAM_CODE_TO (stix, b1); - LOG_INST_1 (stix, "jump2_backward %zu", b1); - stix->ip -= MAX_CODE_JUMP + b1; + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST_1 (moo, "jump2_backward %zu", b1); + moo->ip -= MAX_CODE_JUMP + b1; break; /* -------------------------------------------------------- */ @@ -3785,8 +3785,8 @@ return -1; case BCODE_PUSH_CTXTEMPVAR_X: case BCODE_STORE_INTO_CTXTEMPVAR_X: case BCODE_POP_INTO_CTXTEMPVAR_X: - FETCH_PARAM_CODE_TO (stix, b1); - FETCH_PARAM_CODE_TO (stix, b2); + FETCH_PARAM_CODE_TO (moo, b1); + FETCH_PARAM_CODE_TO (moo, b2); goto handle_ctxtempvar; case BCODE_PUSH_CTXTEMPVAR_0: case BCODE_PUSH_CTXTEMPVAR_1: @@ -3801,42 +3801,42 @@ return -1; case BCODE_POP_INTO_CTXTEMPVAR_2: case BCODE_POP_INTO_CTXTEMPVAR_3: { - stix_ooi_t i; - stix_oop_context_t ctx; + moo_ooi_t i; + moo_oop_context_t ctx; b1 = bcode & 0x3; /* low 2 bits */ - FETCH_BYTE_CODE_TO (stix, b2); + FETCH_BYTE_CODE_TO (moo, b2); handle_ctxtempvar: - ctx = stix->active_context; - STIX_ASSERT (stix, (stix_oop_t)ctx != stix->_nil); + ctx = moo->active_context; + MOO_ASSERT (moo, (moo_oop_t)ctx != moo->_nil); for (i = 0; i < b1; i++) { - ctx = (stix_oop_context_t)ctx->home; + ctx = (moo_oop_context_t)ctx->home; } if ((bcode >> 3) & 1) { /* store or pop */ - ctx->slot[b2] = STIX_STACK_GETTOP(stix); + ctx->slot[b2] = MOO_STACK_GETTOP(moo); if ((bcode >> 2) & 1) { /* pop */ - STIX_STACK_POP (stix); - LOG_INST_2 (stix, "pop_into_ctxtempvar %zu %zu", b1, b2); + MOO_STACK_POP (moo); + LOG_INST_2 (moo, "pop_into_ctxtempvar %zu %zu", b1, b2); } else { - LOG_INST_2 (stix, "store_into_ctxtempvar %zu %zu", b1, b2); + LOG_INST_2 (moo, "store_into_ctxtempvar %zu %zu", b1, b2); } } else { /* push */ - STIX_STACK_PUSH (stix, ctx->slot[b2]); - LOG_INST_2 (stix, "push_ctxtempvar %zu %zu", b1, b2); + MOO_STACK_PUSH (moo, ctx->slot[b2]); + LOG_INST_2 (moo, "push_ctxtempvar %zu %zu", b1, b2); } break; @@ -3846,8 +3846,8 @@ return -1; case BCODE_PUSH_OBJVAR_X: case BCODE_STORE_INTO_OBJVAR_X: case BCODE_POP_INTO_OBJVAR_X: - FETCH_PARAM_CODE_TO (stix, b1); - FETCH_PARAM_CODE_TO (stix, b2); + FETCH_PARAM_CODE_TO (moo, b1); + FETCH_PARAM_CODE_TO (moo, b2); goto handle_objvar; case BCODE_PUSH_OBJVAR_0: @@ -3863,40 +3863,40 @@ return -1; case BCODE_POP_INTO_OBJVAR_2: case BCODE_POP_INTO_OBJVAR_3: { - stix_oop_oop_t t; + moo_oop_oop_t t; /* b1 -> variable index to the object indicated by b2. * b2 -> object index stored in the literal frame. */ b1 = bcode & 0x3; /* low 2 bits */ - FETCH_BYTE_CODE_TO (stix, b2); + FETCH_BYTE_CODE_TO (moo, b2); handle_objvar: - t = (stix_oop_oop_t)stix->active_method->slot[b2]; - STIX_ASSERT (stix, STIX_OBJ_GET_FLAGS_TYPE(t) == STIX_OBJ_TYPE_OOP); - STIX_ASSERT (stix, b1 < STIX_OBJ_GET_SIZE(t)); + t = (moo_oop_oop_t)moo->active_method->slot[b2]; + MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_TYPE(t) == MOO_OBJ_TYPE_OOP); + MOO_ASSERT (moo, b1 < MOO_OBJ_GET_SIZE(t)); if ((bcode >> 3) & 1) { /* store or pop */ - t->slot[b1] = STIX_STACK_GETTOP(stix); + t->slot[b1] = MOO_STACK_GETTOP(moo); if ((bcode >> 2) & 1) { /* pop */ - STIX_STACK_POP (stix); - LOG_INST_2 (stix, "pop_into_objvar %zu %zu", b1, b2); + MOO_STACK_POP (moo); + LOG_INST_2 (moo, "pop_into_objvar %zu %zu", b1, b2); } else { - LOG_INST_2 (stix, "store_into_objvar %zu %zu", b1, b2); + LOG_INST_2 (moo, "store_into_objvar %zu %zu", b1, b2); } } else { /* push */ - LOG_INST_2 (stix, "push_objvar %zu %zu", b1, b2); - STIX_STACK_PUSH (stix, t->slot[b1]); + LOG_INST_2 (moo, "push_objvar %zu %zu", b1, b2); + MOO_STACK_PUSH (moo, t->slot[b1]); } break; } @@ -3906,8 +3906,8 @@ return -1; case BCODE_SEND_MESSAGE_TO_SUPER_X: /* b1 -> number of arguments * b2 -> selector index stored in the literal frame */ - FETCH_PARAM_CODE_TO (stix, b1); - FETCH_PARAM_CODE_TO (stix, b2); + FETCH_PARAM_CODE_TO (moo, b1); + FETCH_PARAM_CODE_TO (moo, b2); goto handle_send_message; case BCODE_SEND_MESSAGE_0: @@ -3919,121 +3919,121 @@ return -1; case BCODE_SEND_MESSAGE_TO_SUPER_2: case BCODE_SEND_MESSAGE_TO_SUPER_3: { - stix_oop_char_t selector; + moo_oop_char_t selector; b1 = bcode & 0x3; /* low 2 bits */ - FETCH_BYTE_CODE_TO (stix, b2); + FETCH_BYTE_CODE_TO (moo, b2); handle_send_message: /* get the selector from the literal frame */ - selector = (stix_oop_char_t)stix->active_method->slot[b2]; + selector = (moo_oop_char_t)moo->active_method->slot[b2]; - LOG_INST_3 (stix, "send_message%hs %zu @%zu", (((bcode >> 2) & 1)? "_to_super": ""), b1, b2); + LOG_INST_3 (moo, "send_message%hs %zu @%zu", (((bcode >> 2) & 1)? "_to_super": ""), b1, b2); - if (send_message (stix, selector, ((bcode >> 2) & 1), b1) <= -1) goto oops; + if (send_message (moo, selector, ((bcode >> 2) & 1), b1) <= -1) goto oops; break; /* CMD_SEND_MESSAGE */ } /* -------------------------------------------------------- */ case BCODE_PUSH_RECEIVER: - LOG_INST_0 (stix, "push_receiver"); - STIX_STACK_PUSH (stix, stix->active_context->origin->receiver_or_source); + LOG_INST_0 (moo, "push_receiver"); + MOO_STACK_PUSH (moo, moo->active_context->origin->receiver_or_source); break; case BCODE_PUSH_NIL: - LOG_INST_0 (stix, "push_nil"); - STIX_STACK_PUSH (stix, stix->_nil); + LOG_INST_0 (moo, "push_nil"); + MOO_STACK_PUSH (moo, moo->_nil); break; case BCODE_PUSH_TRUE: - LOG_INST_0 (stix, "push_true"); - STIX_STACK_PUSH (stix, stix->_true); + LOG_INST_0 (moo, "push_true"); + MOO_STACK_PUSH (moo, moo->_true); break; case BCODE_PUSH_FALSE: - LOG_INST_0 (stix, "push_false"); - STIX_STACK_PUSH (stix, stix->_false); + LOG_INST_0 (moo, "push_false"); + MOO_STACK_PUSH (moo, moo->_false); break; case BCODE_PUSH_CONTEXT: - LOG_INST_0 (stix, "push_context"); - STIX_STACK_PUSH (stix, (stix_oop_t)stix->active_context); + LOG_INST_0 (moo, "push_context"); + MOO_STACK_PUSH (moo, (moo_oop_t)moo->active_context); break; case BCODE_PUSH_PROCESS: - LOG_INST_0 (stix, "push_process"); - STIX_STACK_PUSH (stix, (stix_oop_t)stix->processor->active); + LOG_INST_0 (moo, "push_process"); + MOO_STACK_PUSH (moo, (moo_oop_t)moo->processor->active); break; case BCODE_PUSH_NEGONE: - LOG_INST_0 (stix, "push_negone"); - STIX_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(-1)); + LOG_INST_0 (moo, "push_negone"); + MOO_STACK_PUSH (moo, MOO_SMOOI_TO_OOP(-1)); break; case BCODE_PUSH_ZERO: - LOG_INST_0 (stix, "push_zero"); - STIX_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(0)); + LOG_INST_0 (moo, "push_zero"); + MOO_STACK_PUSH (moo, MOO_SMOOI_TO_OOP(0)); break; case BCODE_PUSH_ONE: - LOG_INST_0 (stix, "push_one"); - STIX_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(1)); + LOG_INST_0 (moo, "push_one"); + MOO_STACK_PUSH (moo, MOO_SMOOI_TO_OOP(1)); break; case BCODE_PUSH_TWO: - LOG_INST_0 (stix, "push_two"); - STIX_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(2)); + LOG_INST_0 (moo, "push_two"); + MOO_STACK_PUSH (moo, MOO_SMOOI_TO_OOP(2)); break; case BCODE_PUSH_INTLIT: - FETCH_PARAM_CODE_TO (stix, b1); - LOG_INST_1 (stix, "push_intlit %zu", b1); - STIX_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(b1)); + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST_1 (moo, "push_intlit %zu", b1); + MOO_STACK_PUSH (moo, MOO_SMOOI_TO_OOP(b1)); break; case BCODE_PUSH_NEGINTLIT: { - stix_ooi_t num; - FETCH_PARAM_CODE_TO (stix, b1); + moo_ooi_t num; + FETCH_PARAM_CODE_TO (moo, b1); num = b1; - LOG_INST_1 (stix, "push_negintlit %zu", b1); - STIX_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(-num)); + LOG_INST_1 (moo, "push_negintlit %zu", b1); + MOO_STACK_PUSH (moo, MOO_SMOOI_TO_OOP(-num)); break; } case BCODE_PUSH_CHARLIT: - FETCH_PARAM_CODE_TO (stix, b1); - LOG_INST_1 (stix, "push_charlit %zu", b1); - STIX_STACK_PUSH (stix, STIX_CHAR_TO_OOP(b1)); + FETCH_PARAM_CODE_TO (moo, b1); + LOG_INST_1 (moo, "push_charlit %zu", b1); + MOO_STACK_PUSH (moo, MOO_CHAR_TO_OOP(b1)); break; /* -------------------------------------------------------- */ case BCODE_DUP_STACKTOP: { - stix_oop_t t; - LOG_INST_0 (stix, "dup_stacktop"); - STIX_ASSERT (stix, !STIX_STACK_ISEMPTY(stix)); - t = STIX_STACK_GETTOP(stix); - STIX_STACK_PUSH (stix, t); + moo_oop_t t; + LOG_INST_0 (moo, "dup_stacktop"); + MOO_ASSERT (moo, !MOO_STACK_ISEMPTY(moo)); + t = MOO_STACK_GETTOP(moo); + MOO_STACK_PUSH (moo, t); break; } case BCODE_POP_STACKTOP: - LOG_INST_0 (stix, "pop_stacktop"); - STIX_ASSERT (stix, !STIX_STACK_ISEMPTY(stix)); - STIX_STACK_POP (stix); + LOG_INST_0 (moo, "pop_stacktop"); + MOO_ASSERT (moo, !MOO_STACK_ISEMPTY(moo)); + MOO_STACK_POP (moo); break; case BCODE_RETURN_STACKTOP: - LOG_INST_0 (stix, "return_stacktop"); - return_value = STIX_STACK_GETTOP(stix); - STIX_STACK_POP (stix); + LOG_INST_0 (moo, "return_stacktop"); + return_value = MOO_STACK_GETTOP(moo); + MOO_STACK_POP (moo); goto handle_return; case BCODE_RETURN_RECEIVER: - LOG_INST_0 (stix, "return_receiver"); - return_value = stix->active_context->origin->receiver_or_source; + LOG_INST_0 (moo, "return_receiver"); + return_value = moo->active_context->origin->receiver_or_source; handle_return: #if 0 @@ -4077,9 +4077,9 @@ return -1; * TODO: verify if this really works * */ - stix->ip--; + moo->ip--; #else - if (stix->active_context->origin == stix->processor->active->initial_context->origin) + if (moo->active_context->origin == moo->processor->active->initial_context->origin) { /* method return from a processified block * @@ -4106,14 +4106,14 @@ return -1; * } */ - STIX_ASSERT (stix, STIX_CLASSOF(stix, stix->active_context) == stix->_block_context); - STIX_ASSERT (stix, STIX_CLASSOF(stix, stix->processor->active->initial_context) == stix->_block_context); + MOO_ASSERT (moo, MOO_CLASSOF(moo, moo->active_context) == moo->_block_context); + MOO_ASSERT (moo, MOO_CLASSOF(moo, moo->processor->active->initial_context) == moo->_block_context); /* decrement the instruction pointer back to the return instruction. * even if the context is reentered, it will just return. - *stix->ip--;*/ + *moo->ip--;*/ - terminate_process (stix, stix->processor->active); + terminate_process (moo, moo->processor->active); } else { @@ -4122,27 +4122,27 @@ return -1; /* set the instruction pointer to an invalid value. * this is stored into the current method context * before context switching and marks a dead context */ - if (stix->active_context->origin == stix->active_context) + if (moo->active_context->origin == moo->active_context) { /* returning from a method */ - STIX_ASSERT (stix, STIX_CLASSOF(stix, stix->active_context) == stix->_method_context); - stix->ip = -1; + MOO_ASSERT (moo, MOO_CLASSOF(moo, moo->active_context) == moo->_method_context); + moo->ip = -1; } else { - stix_oop_context_t ctx; + moo_oop_context_t ctx; /* method return from within a block(including a non-local return) */ - STIX_ASSERT (stix, STIX_CLASSOF(stix, stix->active_context) == stix->_block_context); + MOO_ASSERT (moo, MOO_CLASSOF(moo, moo->active_context) == moo->_block_context); - ctx = stix->active_context; - while ((stix_oop_t)ctx != stix->_nil) + ctx = moo->active_context; + while ((moo_oop_t)ctx != moo->_nil) { - if (STIX_CLASSOF(stix, ctx) == stix->_method_context) + if (MOO_CLASSOF(moo, ctx) == moo->_method_context) { - stix_ooi_t preamble; - preamble = STIX_OOP_TO_SMOOI(((stix_oop_method_t)ctx->method_or_nargs)->preamble); - if (STIX_METHOD_GET_PREAMBLE_CODE(preamble) == STIX_METHOD_PREAMBLE_ENSURE) + moo_ooi_t preamble; + preamble = MOO_OOP_TO_SMOOI(((moo_oop_method_t)ctx->method_or_nargs)->preamble); + if (MOO_METHOD_GET_PREAMBLE_CODE(preamble) == MOO_METHOD_PREAMBLE_ENSURE) { if (!unwind_protect) { @@ -4152,72 +4152,72 @@ return -1; unwind_stop = ctx; } } - if (ctx == stix->active_context->origin) goto non_local_return_ok; + if (ctx == moo->active_context->origin) goto non_local_return_ok; ctx = ctx->sender; } /* cannot return from a method that has returned already */ - STIX_ASSERT (stix, STIX_CLASSOF(stix, stix->active_context->origin) == stix->_method_context); - STIX_ASSERT (stix, stix->active_context->origin->ip == STIX_SMOOI_TO_OOP(-1)); + MOO_ASSERT (moo, MOO_CLASSOF(moo, moo->active_context->origin) == moo->_method_context); + MOO_ASSERT (moo, moo->active_context->origin->ip == MOO_SMOOI_TO_OOP(-1)); - STIX_LOG0 (stix, STIX_LOG_IC | STIX_LOG_ERROR, "Error - cannot return from dead context\n"); - stix->errnum = STIX_EINTERN; /* TODO: can i make this error catchable at the stix level? */ + MOO_LOG0 (moo, MOO_LOG_IC | MOO_LOG_ERROR, "Error - cannot return from dead context\n"); + moo->errnum = MOO_EINTERN; /* TODO: can i make this error catchable at the moo level? */ return -1; non_local_return_ok: -/*STIX_DEBUG2 (stix, "NON_LOCAL RETURN OK TO... %p %p\n", stix->active_context->origin, stix->active_context->origin->sender);*/ - stix->active_context->origin->ip = STIX_SMOOI_TO_OOP(-1); +/*MOO_DEBUG2 (moo, "NON_LOCAL RETURN OK TO... %p %p\n", moo->active_context->origin, moo->active_context->origin->sender);*/ + moo->active_context->origin->ip = MOO_SMOOI_TO_OOP(-1); } - STIX_ASSERT (stix, STIX_CLASSOF(stix, stix->active_context->origin) == stix->_method_context); + MOO_ASSERT (moo, MOO_CLASSOF(moo, moo->active_context->origin) == moo->_method_context); /* restore the stack pointer */ - stix->sp = STIX_OOP_TO_SMOOI(stix->active_context->origin->sp); - SWITCH_ACTIVE_CONTEXT (stix, stix->active_context->origin->sender); + moo->sp = MOO_OOP_TO_SMOOI(moo->active_context->origin->sp); + SWITCH_ACTIVE_CONTEXT (moo, moo->active_context->origin->sender); if (unwind_protect) { - static stix_ooch_t fbm[] = { + static moo_ooch_t fbm[] = { 'u', 'n', 'w', 'i', 'n', 'd', 'T', 'o', ':', 'r', 'e', 't', 'u', 'r', 'n', ':' }; - STIX_STACK_PUSH (stix, (stix_oop_t)unwind_start); - STIX_STACK_PUSH (stix, (stix_oop_t)unwind_stop); - STIX_STACK_PUSH (stix, (stix_oop_t)return_value); + MOO_STACK_PUSH (moo, (moo_oop_t)unwind_start); + MOO_STACK_PUSH (moo, (moo_oop_t)unwind_stop); + MOO_STACK_PUSH (moo, (moo_oop_t)return_value); - if (send_private_message (stix, fbm, 16, 0, 2) <= -1) return -1; + if (send_private_message (moo, fbm, 16, 0, 2) <= -1) return -1; } else { /* push the return value to the stack of the new active context */ - STIX_STACK_PUSH (stix, return_value); + MOO_STACK_PUSH (moo, return_value); - if (stix->active_context == stix->initial_context) + if (moo->active_context == moo->initial_context) { /* the new active context is the fake initial context. * this context can't get executed further. */ - STIX_ASSERT (stix, (stix_oop_t)stix->active_context->sender == stix->_nil); - STIX_ASSERT (stix, STIX_CLASSOF(stix, stix->active_context) == stix->_method_context); - STIX_ASSERT (stix, stix->active_context->receiver_or_source == stix->_nil); - STIX_ASSERT (stix, stix->active_context == stix->processor->active->initial_context); - STIX_ASSERT (stix, stix->active_context->origin == stix->processor->active->initial_context->origin); - STIX_ASSERT (stix, stix->active_context->origin == stix->active_context); + MOO_ASSERT (moo, (moo_oop_t)moo->active_context->sender == moo->_nil); + MOO_ASSERT (moo, MOO_CLASSOF(moo, moo->active_context) == moo->_method_context); + MOO_ASSERT (moo, moo->active_context->receiver_or_source == moo->_nil); + MOO_ASSERT (moo, moo->active_context == moo->processor->active->initial_context); + MOO_ASSERT (moo, moo->active_context->origin == moo->processor->active->initial_context->origin); + MOO_ASSERT (moo, moo->active_context->origin == moo->active_context); /* NOTE: this condition is true for the processified block context also. - * stix->active_context->origin == stix->processor->active->initial_context->origin + * moo->active_context->origin == moo->processor->active->initial_context->origin * however, the check here is done after context switching and the * processified block check has been done against the context before switching */ /* the stack contains the final return value so the stack pointer must be 0. */ - STIX_ASSERT (stix, stix->sp == 0); + MOO_ASSERT (moo, moo->sp == 0); - if (stix->option.trait & STIX_AWAIT_PROCS) - terminate_process (stix, stix->processor->active); + if (moo->option.trait & MOO_AWAIT_PROCS) + terminate_process (moo, moo->processor->active); else goto done; /* TODO: store the return value to the VM register. - * the caller to stix_execute() can fetch it to return it to the system */ + * the caller to moo_execute() can fetch it to return it to the system */ } } } @@ -4227,19 +4227,19 @@ return -1; break; case BCODE_RETURN_FROM_BLOCK: - LOG_INST_0 (stix, "return_from_block"); + LOG_INST_0 (moo, "return_from_block"); - STIX_ASSERT (stix, STIX_CLASSOF(stix, stix->active_context) == stix->_block_context); + MOO_ASSERT (moo, MOO_CLASSOF(moo, moo->active_context) == moo->_block_context); - if (stix->active_context == stix->processor->active->initial_context) + if (moo->active_context == moo->processor->active->initial_context) { /* the active context to return from is an initial context of * the active process. this process must have been created * over a block using the newProcess method. let's terminate * the process. */ - STIX_ASSERT (stix, (stix_oop_t)stix->active_context->sender == stix->_nil); - terminate_process (stix, stix->processor->active); + MOO_ASSERT (moo, (moo_oop_t)moo->active_context->sender == moo->_nil); + terminate_process (moo, moo->processor->active); } else { @@ -4248,80 +4248,80 @@ return -1; /* the process stack is shared. the return value * doesn't need to get moved. */ - SWITCH_ACTIVE_CONTEXT (stix, (stix_oop_context_t)stix->active_context->sender); + SWITCH_ACTIVE_CONTEXT (moo, (moo_oop_context_t)moo->active_context->sender); } break; case BCODE_MAKE_BLOCK: { - stix_oop_context_t blkctx; + moo_oop_context_t blkctx; /* b1 - number of block arguments * b2 - number of block temporaries */ - FETCH_PARAM_CODE_TO (stix, b1); - FETCH_PARAM_CODE_TO (stix, b2); + FETCH_PARAM_CODE_TO (moo, b1); + FETCH_PARAM_CODE_TO (moo, b2); - LOG_INST_2 (stix, "make_block %zu %zu", b1, b2); + LOG_INST_2 (moo, "make_block %zu %zu", b1, b2); - STIX_ASSERT (stix, b1 >= 0); - STIX_ASSERT (stix, b2 >= b1); + MOO_ASSERT (moo, b1 >= 0); + MOO_ASSERT (moo, b2 >= b1); /* the block context object created here is used as a base * object for block context activation. pf_block_value() * clones a block context and activates the cloned context. * this base block context is created with no stack for * this reason */ - blkctx = (stix_oop_context_t)stix_instantiate (stix, stix->_block_context, STIX_NULL, 0); + blkctx = (moo_oop_context_t)moo_instantiate (moo, moo->_block_context, MOO_NULL, 0); if (!blkctx) return -1; /* the long forward jump instruction has the format of * 11000100 KKKKKKKK or 11000100 KKKKKKKK KKKKKKKK - * depending on STIX_BCODE_LONG_PARAM_SIZE. change 'ip' to point to + * depending on MOO_BCODE_LONG_PARAM_SIZE. change 'ip' to point to * the instruction after the jump. */ - blkctx->ip = STIX_SMOOI_TO_OOP(stix->ip + STIX_BCODE_LONG_PARAM_SIZE + 1); + blkctx->ip = MOO_SMOOI_TO_OOP(moo->ip + MOO_BCODE_LONG_PARAM_SIZE + 1); /* stack pointer below the bottom. this base block context * has an empty stack anyway. */ - blkctx->sp = STIX_SMOOI_TO_OOP(-1); + blkctx->sp = MOO_SMOOI_TO_OOP(-1); /* the number of arguments for a block context is local to the block */ - blkctx->method_or_nargs = STIX_SMOOI_TO_OOP(b1); + blkctx->method_or_nargs = MOO_SMOOI_TO_OOP(b1); /* the number of temporaries here is an accumulated count including * the number of temporaries of a home context */ - blkctx->ntmprs = STIX_SMOOI_TO_OOP(b2); + blkctx->ntmprs = MOO_SMOOI_TO_OOP(b2); /* set the home context where it's defined */ - blkctx->home = (stix_oop_t)stix->active_context; + blkctx->home = (moo_oop_t)moo->active_context; /* no source for a base block context. */ - blkctx->receiver_or_source = stix->_nil; + blkctx->receiver_or_source = moo->_nil; - blkctx->origin = stix->active_context->origin; + blkctx->origin = moo->active_context->origin; /* push the new block context to the stack of the active context */ - STIX_STACK_PUSH (stix, (stix_oop_t)blkctx); + MOO_STACK_PUSH (moo, (moo_oop_t)blkctx); break; } case BCODE_SEND_BLOCK_COPY: { - stix_ooi_t nargs, ntmprs; - stix_oop_context_t rctx; - stix_oop_context_t blkctx; + moo_ooi_t nargs, ntmprs; + moo_oop_context_t rctx; + moo_oop_context_t blkctx; - LOG_INST_0 (stix, "send_block_copy"); + LOG_INST_0 (moo, "send_block_copy"); /* it emulates thisContext blockCopy: nargs ofTmprCount: ntmprs */ - STIX_ASSERT (stix, stix->sp >= 2); + MOO_ASSERT (moo, moo->sp >= 2); - STIX_ASSERT (stix, STIX_CLASSOF(stix, STIX_STACK_GETTOP(stix)) == stix->_small_integer); - ntmprs = STIX_OOP_TO_SMOOI(STIX_STACK_GETTOP(stix)); - STIX_STACK_POP (stix); + MOO_ASSERT (moo, MOO_CLASSOF(moo, MOO_STACK_GETTOP(moo)) == moo->_small_integer); + ntmprs = MOO_OOP_TO_SMOOI(MOO_STACK_GETTOP(moo)); + MOO_STACK_POP (moo); - STIX_ASSERT (stix, STIX_CLASSOF(stix, STIX_STACK_GETTOP(stix)) == stix->_small_integer); - nargs = STIX_OOP_TO_SMOOI(STIX_STACK_GETTOP(stix)); - STIX_STACK_POP (stix); + MOO_ASSERT (moo, MOO_CLASSOF(moo, MOO_STACK_GETTOP(moo)) == moo->_small_integer); + nargs = MOO_OOP_TO_SMOOI(MOO_STACK_GETTOP(moo)); + MOO_STACK_POP (moo); - STIX_ASSERT (stix, nargs >= 0); - STIX_ASSERT (stix, ntmprs >= nargs); + MOO_ASSERT (moo, nargs >= 0); + MOO_ASSERT (moo, ntmprs >= nargs); /* the block context object created here is used * as a base object for block context activation. @@ -4329,13 +4329,13 @@ return -1; * context and activates the cloned context. * this base block context is created with no * stack for this reason. */ - blkctx = (stix_oop_context_t)stix_instantiate (stix, stix->_block_context, STIX_NULL, 0); + blkctx = (moo_oop_context_t)moo_instantiate (moo, moo->_block_context, MOO_NULL, 0); if (!blkctx) return -1; /* get the receiver to the block copy message after block context instantiation * not to get affected by potential GC */ - rctx = (stix_oop_context_t)STIX_STACK_GETTOP(stix); - STIX_ASSERT (stix, rctx == stix->active_context); + rctx = (moo_oop_context_t)MOO_STACK_GETTOP(moo); + MOO_ASSERT (moo, rctx == moo->active_context); /* [NOTE] * blkctx->sender is left to nil. it is set to the @@ -4355,32 +4355,32 @@ return -1; /* the extended jump instruction has the format of * 0000XXXX KKKKKKKK or 0000XXXX KKKKKKKK KKKKKKKK - * depending on STIX_BCODE_LONG_PARAM_SIZE. change 'ip' to point to + * depending on MOO_BCODE_LONG_PARAM_SIZE. change 'ip' to point to * the instruction after the jump. */ - blkctx->ip = STIX_SMOOI_TO_OOP(stix->ip + STIX_BCODE_LONG_PARAM_SIZE + 1); - blkctx->sp = STIX_SMOOI_TO_OOP(-1); + blkctx->ip = MOO_SMOOI_TO_OOP(moo->ip + MOO_BCODE_LONG_PARAM_SIZE + 1); + blkctx->sp = MOO_SMOOI_TO_OOP(-1); /* the number of arguments for a block context is local to the block */ - blkctx->method_or_nargs = STIX_SMOOI_TO_OOP(nargs); + blkctx->method_or_nargs = MOO_SMOOI_TO_OOP(nargs); /* the number of temporaries here is an accumulated count including * the number of temporaries of a home context */ - blkctx->ntmprs = STIX_SMOOI_TO_OOP(ntmprs); + blkctx->ntmprs = MOO_SMOOI_TO_OOP(ntmprs); - blkctx->home = (stix_oop_t)rctx; - blkctx->receiver_or_source = stix->_nil; + blkctx->home = (moo_oop_t)rctx; + blkctx->receiver_or_source = moo->_nil; #if 0 - if (rctx->home == stix->_nil) + if (rctx->home == moo->_nil) { /* the context that receives the blockCopy message is a method context */ - STIX_ASSERT (stix, STIX_CLASSOF(stix, rctx) == stix->_method_context); - STIX_ASSERT (stix, rctx == (stix_oop_t)stix->active_context); - blkctx->origin = (stix_oop_context_t)rctx; + MOO_ASSERT (moo, MOO_CLASSOF(moo, rctx) == moo->_method_context); + MOO_ASSERT (moo, rctx == (moo_oop_t)moo->active_context); + blkctx->origin = (moo_oop_context_t)rctx; } else { /* a block context is active */ - STIX_ASSERT (stix, STIX_CLASSOF(stix, rctx) == stix->_block_context); - blkctx->origin = ((stix_oop_block_context_t)rctx)->origin; + MOO_ASSERT (moo, MOO_CLASSOF(moo, rctx) == moo->_block_context); + blkctx->origin = ((moo_oop_block_context_t)rctx)->origin; } #else @@ -4392,28 +4392,28 @@ return -1; blkctx->origin = rctx->origin; #endif - STIX_STACK_SETTOP (stix, (stix_oop_t)blkctx); + MOO_STACK_SETTOP (moo, (moo_oop_t)blkctx); break; } case BCODE_NOOP: /* do nothing */ - LOG_INST_0 (stix, "noop"); + LOG_INST_0 (moo, "noop"); break; default: - STIX_LOG1 (stix, STIX_LOG_IC | STIX_LOG_FATAL, "Fatal error - unknown byte code 0x%zx\n", bcode); - stix->errnum = STIX_EINTERN; + MOO_LOG1 (moo, MOO_LOG_IC | MOO_LOG_FATAL, "Fatal error - unknown byte code 0x%zx\n", bcode); + moo->errnum = MOO_EINTERN; goto oops; } } done: - vm_cleanup (stix); -#if defined(STIX_PROFILE_VM) - STIX_LOG1 (stix, STIX_LOG_IC | STIX_LOG_INFO, "TOTAL_INST_COUTNER = %zu\n", inst_counter); + vm_cleanup (moo); +#if defined(MOO_PROFILE_VM) + MOO_LOG1 (moo, MOO_LOG_IC | MOO_LOG_INFO, "TOTAL_INST_COUTNER = %zu\n", inst_counter); #endif return 0; @@ -4422,23 +4422,23 @@ oops: return -1; } -int stix_invoke (stix_t* stix, const stix_oocs_t* objname, const stix_oocs_t* mthname) +int moo_invoke (moo_t* moo, const moo_oocs_t* objname, const moo_oocs_t* mthname) { int n; - STIX_ASSERT (stix, stix->initial_context == STIX_NULL); - STIX_ASSERT (stix, stix->active_context == STIX_NULL); - STIX_ASSERT (stix, stix->active_method == STIX_NULL); + MOO_ASSERT (moo, moo->initial_context == MOO_NULL); + MOO_ASSERT (moo, moo->active_context == MOO_NULL); + MOO_ASSERT (moo, moo->active_method == MOO_NULL); - if (start_initial_process_and_context (stix, objname, mthname) <= -1) return -1; - stix->initial_context = stix->processor->active->initial_context; + if (start_initial_process_and_context (moo, objname, mthname) <= -1) return -1; + moo->initial_context = moo->processor->active->initial_context; - n = stix_execute (stix); + n = moo_execute (moo); /* TODO: reset processor fields. set processor->tally to zero. processor->active to nil_process... */ - stix->initial_context = STIX_NULL; - stix->active_context = STIX_NULL; - stix->active_method = STIX_NULL; + moo->initial_context = MOO_NULL; + moo->active_context = MOO_NULL; + moo->active_method = MOO_NULL; return n; } diff --git a/stix/lib/gc.c b/stix/lib/gc.c index aa31a24..1f966e1 100644 --- a/stix/lib/gc.c +++ b/stix/lib/gc.c @@ -24,7 +24,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "stix-prv.h" +#include "moo-prv.h" /* @@ -73,87 +73,87 @@ struct kernel_class_info_t { - stix_oow_t len; - stix_ooch_t name[20]; - stix_oow_t offset; + moo_oow_t len; + moo_ooch_t name[20]; + moo_oow_t offset; }; typedef struct kernel_class_info_t kernel_class_info_t; static kernel_class_info_t kernel_classes[] = { - { 4, { 'A','p','e','x' }, STIX_OFFSETOF(stix_t,_apex) }, - { 15, { 'U','n','d','e','f','i','n','e','d','O','b','j','e','c','t' }, STIX_OFFSETOF(stix_t,_undefined_object) }, - { 5, { 'C','l','a','s','s' }, STIX_OFFSETOF(stix_t,_class) }, - { 6, { 'O','b','j','e','c','t' }, STIX_OFFSETOF(stix_t,_object) }, - { 6, { 'S','t','r','i','n','g' }, STIX_OFFSETOF(stix_t,_string) }, + { 4, { 'A','p','e','x' }, MOO_OFFSETOF(moo_t,_apex) }, + { 15, { 'U','n','d','e','f','i','n','e','d','O','b','j','e','c','t' }, MOO_OFFSETOF(moo_t,_undefined_object) }, + { 5, { 'C','l','a','s','s' }, MOO_OFFSETOF(moo_t,_class) }, + { 6, { 'O','b','j','e','c','t' }, MOO_OFFSETOF(moo_t,_object) }, + { 6, { 'S','t','r','i','n','g' }, MOO_OFFSETOF(moo_t,_string) }, - { 6, { 'S','y','m','b','o','l' }, STIX_OFFSETOF(stix_t,_symbol) }, - { 5, { 'A','r','r','a','y' }, STIX_OFFSETOF(stix_t,_array) }, - { 9, { 'B','y','t','e','A','r','r','a','y' }, STIX_OFFSETOF(stix_t,_byte_array) }, - { 9, { 'S','y','m','b','o','l','S','e','t' }, STIX_OFFSETOF(stix_t,_symbol_set) }, - { 16, { 'S','y','s','t','e','m','D','i','c','t','i','o','n','a','r','y' }, STIX_OFFSETOF(stix_t, _system_dictionary) }, + { 6, { 'S','y','m','b','o','l' }, MOO_OFFSETOF(moo_t,_symbol) }, + { 5, { 'A','r','r','a','y' }, MOO_OFFSETOF(moo_t,_array) }, + { 9, { 'B','y','t','e','A','r','r','a','y' }, MOO_OFFSETOF(moo_t,_byte_array) }, + { 9, { 'S','y','m','b','o','l','S','e','t' }, MOO_OFFSETOF(moo_t,_symbol_set) }, + { 16, { 'S','y','s','t','e','m','D','i','c','t','i','o','n','a','r','y' }, MOO_OFFSETOF(moo_t, _system_dictionary) }, - { 9, { 'N','a','m','e','s','p','a','c','e' }, STIX_OFFSETOF(stix_t, _namespace) }, - { 14, { 'P','o','o','l','D','i','c','t','i','o','n','a','r','y' }, STIX_OFFSETOF(stix_t, _pool_dictionary) }, - { 16, { 'M','e','t','h','o','d','D','i','c','t','i','o','n','a','r','y' }, STIX_OFFSETOF(stix_t, _method_dictionary) }, - { 14, { 'C','o','m','p','i','l','e','d','M','e','t','h','o','d' }, STIX_OFFSETOF(stix_t, _method) }, - { 11, { 'A','s','s','o','c','i','a','t','i','o','n' }, STIX_OFFSETOF(stix_t, _association) }, + { 9, { 'N','a','m','e','s','p','a','c','e' }, MOO_OFFSETOF(moo_t, _namespace) }, + { 14, { 'P','o','o','l','D','i','c','t','i','o','n','a','r','y' }, MOO_OFFSETOF(moo_t, _pool_dictionary) }, + { 16, { 'M','e','t','h','o','d','D','i','c','t','i','o','n','a','r','y' }, MOO_OFFSETOF(moo_t, _method_dictionary) }, + { 14, { 'C','o','m','p','i','l','e','d','M','e','t','h','o','d' }, MOO_OFFSETOF(moo_t, _method) }, + { 11, { 'A','s','s','o','c','i','a','t','i','o','n' }, MOO_OFFSETOF(moo_t, _association) }, - { 13, { 'M','e','t','h','o','d','C','o','n','t','e','x','t' }, STIX_OFFSETOF(stix_t, _method_context) }, - { 12, { 'B','l','o','c','k','C','o','n','t','e','x','t' }, STIX_OFFSETOF(stix_t, _block_context) }, - { 7, { 'P','r','o','c','e','s','s' }, STIX_OFFSETOF(stix_t, _process) }, - { 9, { 'S','e','m','a','p','h','o','r','e' }, STIX_OFFSETOF(stix_t, _semaphore) }, - { 16, { 'P','r','o','c','e','s','s','S','c','h','e','d','u','l','e','r' }, STIX_OFFSETOF(stix_t, _process_scheduler) }, + { 13, { 'M','e','t','h','o','d','C','o','n','t','e','x','t' }, MOO_OFFSETOF(moo_t, _method_context) }, + { 12, { 'B','l','o','c','k','C','o','n','t','e','x','t' }, MOO_OFFSETOF(moo_t, _block_context) }, + { 7, { 'P','r','o','c','e','s','s' }, MOO_OFFSETOF(moo_t, _process) }, + { 9, { 'S','e','m','a','p','h','o','r','e' }, MOO_OFFSETOF(moo_t, _semaphore) }, + { 16, { 'P','r','o','c','e','s','s','S','c','h','e','d','u','l','e','r' }, MOO_OFFSETOF(moo_t, _process_scheduler) }, - { 5, { 'E','r','r','o','r' }, STIX_OFFSETOF(stix_t, _error_class) }, - { 4, { 'T','r','u','e' }, STIX_OFFSETOF(stix_t, _true_class) }, - { 5, { 'F','a','l','s','e' }, STIX_OFFSETOF(stix_t, _false_class) }, - { 9, { 'C','h','a','r','a','c','t','e','r' }, STIX_OFFSETOF(stix_t, _character) }, - { 12, { 'S','m','a','l','l','I','n','t','e','g','e','r' }, STIX_OFFSETOF(stix_t, _small_integer) }, + { 5, { 'E','r','r','o','r' }, MOO_OFFSETOF(moo_t, _error_class) }, + { 4, { 'T','r','u','e' }, MOO_OFFSETOF(moo_t, _true_class) }, + { 5, { 'F','a','l','s','e' }, MOO_OFFSETOF(moo_t, _false_class) }, + { 9, { 'C','h','a','r','a','c','t','e','r' }, MOO_OFFSETOF(moo_t, _character) }, + { 12, { 'S','m','a','l','l','I','n','t','e','g','e','r' }, MOO_OFFSETOF(moo_t, _small_integer) }, - { 20, { 'L','a','r','g','e','P','o','s','i','t','i','v','e','I','n','t','e','g','e','r' }, STIX_OFFSETOF(stix_t, _large_positive_integer) }, - { 20, { 'L','a','r','g','e','N','e','g','a','t','i','v','e','I','n','t','e','g','e','r' }, STIX_OFFSETOF(stix_t, _large_negative_integer) } + { 20, { 'L','a','r','g','e','P','o','s','i','t','i','v','e','I','n','t','e','g','e','r' }, MOO_OFFSETOF(moo_t, _large_positive_integer) }, + { 20, { 'L','a','r','g','e','N','e','g','a','t','i','v','e','I','n','t','e','g','e','r' }, MOO_OFFSETOF(moo_t, _large_negative_integer) } }; /* ----------------------------------------------------------------------- * BOOTSTRAPPER * ----------------------------------------------------------------------- */ -static stix_oop_t alloc_kernel_class (stix_t* stix, stix_oow_t indexed_classvars, stix_oow_t spec) +static moo_oop_t alloc_kernel_class (moo_t* moo, moo_oow_t indexed_classvars, moo_oow_t spec) { - stix_oop_class_t c; + moo_oop_class_t c; - c = (stix_oop_class_t)stix_allocoopobj (stix, STIX_CLASS_NAMED_INSTVARS + indexed_classvars); - if (!c) return STIX_NULL; + c = (moo_oop_class_t)moo_allocoopobj (moo, MOO_CLASS_NAMED_INSTVARS + indexed_classvars); + if (!c) return MOO_NULL; - STIX_OBJ_SET_FLAGS_KERNEL (c, 1); - STIX_OBJ_SET_CLASS (c, stix->_class); - c->spec = STIX_SMOOI_TO_OOP(spec); - c->selfspec = STIX_SMOOI_TO_OOP(STIX_CLASS_SELFSPEC_MAKE(indexed_classvars, 0)); + MOO_OBJ_SET_FLAGS_KERNEL (c, 1); + MOO_OBJ_SET_CLASS (c, moo->_class); + c->spec = MOO_SMOOI_TO_OOP(spec); + c->selfspec = MOO_SMOOI_TO_OOP(MOO_CLASS_SELFSPEC_MAKE(indexed_classvars, 0)); - return (stix_oop_t)c; + return (moo_oop_t)c; } -static int ignite_1 (stix_t* stix) +static int ignite_1 (moo_t* moo) { /* * Create fundamental class objects with some fields mis-initialized yet. * Such fields include 'superclass', 'subclasses', 'name', etc. */ - STIX_ASSERT (stix, stix->_nil != STIX_NULL); - STIX_ASSERT (stix, STIX_OBJ_GET_CLASS(stix->_nil) == STIX_NULL); + MOO_ASSERT (moo, moo->_nil != MOO_NULL); + MOO_ASSERT (moo, MOO_OBJ_GET_CLASS(moo->_nil) == MOO_NULL); - STIX_ASSERT (stix, stix->_class == STIX_NULL); + MOO_ASSERT (moo, moo->_class == MOO_NULL); /* -------------------------------------------------------------- * Class * The instance of Class can have indexed instance variables * which are actually class variables. * -------------------------------------------------------------- */ - stix->_class = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_CLASS_NAMED_INSTVARS, 1, STIX_OBJ_TYPE_OOP)); - if (!stix->_class) return -1; + moo->_class = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(MOO_CLASS_NAMED_INSTVARS, 1, MOO_OBJ_TYPE_OOP)); + if (!moo->_class) return -1; - STIX_ASSERT (stix, STIX_OBJ_GET_CLASS(stix->_class) == STIX_NULL); - STIX_OBJ_SET_CLASS (stix->_class, stix->_class); + MOO_ASSERT (moo, MOO_OBJ_GET_CLASS(moo->_class) == MOO_NULL); + MOO_OBJ_SET_CLASS (moo->_class, moo->_class); /* -------------------------------------------------------------- * Apex - proto-object with 1 class variable. @@ -167,155 +167,155 @@ static int ignite_1 (stix_t* stix) * Character * SmallIntger * -------------------------------------------------------------- */ - stix->_apex = alloc_kernel_class (stix, 1, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP)); - stix->_undefined_object = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP)); - stix->_object = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP)); - stix->_string = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 1, STIX_OBJ_TYPE_CHAR)); + moo->_apex = alloc_kernel_class (moo, 1, MOO_CLASS_SPEC_MAKE(0, 0, MOO_OBJ_TYPE_OOP)); + moo->_undefined_object = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(0, 0, MOO_OBJ_TYPE_OOP)); + moo->_object = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(0, 0, MOO_OBJ_TYPE_OOP)); + moo->_string = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(0, 1, MOO_OBJ_TYPE_CHAR)); - stix->_symbol = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 1, STIX_OBJ_TYPE_CHAR)); - stix->_array = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 1, STIX_OBJ_TYPE_OOP)); - stix->_byte_array = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 1, STIX_OBJ_TYPE_BYTE)); - stix->_symbol_set = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_SET_NAMED_INSTVARS, 0, STIX_OBJ_TYPE_OOP)); - stix->_system_dictionary = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_SET_NAMED_INSTVARS, 0, STIX_OBJ_TYPE_OOP)); + moo->_symbol = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(0, 1, MOO_OBJ_TYPE_CHAR)); + moo->_array = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(0, 1, MOO_OBJ_TYPE_OOP)); + moo->_byte_array = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(0, 1, MOO_OBJ_TYPE_BYTE)); + moo->_symbol_set = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(MOO_SET_NAMED_INSTVARS, 0, MOO_OBJ_TYPE_OOP)); + moo->_system_dictionary = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(MOO_SET_NAMED_INSTVARS, 0, MOO_OBJ_TYPE_OOP)); - stix->_namespace = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_SET_NAMED_INSTVARS, 0, STIX_OBJ_TYPE_OOP)); - stix->_pool_dictionary = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_SET_NAMED_INSTVARS, 0, STIX_OBJ_TYPE_OOP)); - stix->_method_dictionary = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_SET_NAMED_INSTVARS, 0, STIX_OBJ_TYPE_OOP)); - stix->_method = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_METHOD_NAMED_INSTVARS, 1, STIX_OBJ_TYPE_OOP)); - stix->_association = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_ASSOCIATION_NAMED_INSTVARS, 0, STIX_OBJ_TYPE_OOP)); + moo->_namespace = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(MOO_SET_NAMED_INSTVARS, 0, MOO_OBJ_TYPE_OOP)); + moo->_pool_dictionary = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(MOO_SET_NAMED_INSTVARS, 0, MOO_OBJ_TYPE_OOP)); + moo->_method_dictionary = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(MOO_SET_NAMED_INSTVARS, 0, MOO_OBJ_TYPE_OOP)); + moo->_method = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(MOO_METHOD_NAMED_INSTVARS, 1, MOO_OBJ_TYPE_OOP)); + moo->_association = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(MOO_ASSOCIATION_NAMED_INSTVARS, 0, MOO_OBJ_TYPE_OOP)); - stix->_method_context = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_CONTEXT_NAMED_INSTVARS, 1, STIX_OBJ_TYPE_OOP)); - stix->_block_context = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_CONTEXT_NAMED_INSTVARS, 1, STIX_OBJ_TYPE_OOP)); - stix->_process = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_PROCESS_NAMED_INSTVARS, 1, STIX_OBJ_TYPE_OOP)); - stix->_semaphore = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_SEMAPHORE_NAMED_INSTVARS, 0, STIX_OBJ_TYPE_OOP)); - stix->_process_scheduler = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(STIX_PROCESS_SCHEDULER_NAMED_INSTVARS, 0, STIX_OBJ_TYPE_OOP)); + moo->_method_context = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(MOO_CONTEXT_NAMED_INSTVARS, 1, MOO_OBJ_TYPE_OOP)); + moo->_block_context = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(MOO_CONTEXT_NAMED_INSTVARS, 1, MOO_OBJ_TYPE_OOP)); + moo->_process = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(MOO_PROCESS_NAMED_INSTVARS, 1, MOO_OBJ_TYPE_OOP)); + moo->_semaphore = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(MOO_SEMAPHORE_NAMED_INSTVARS, 0, MOO_OBJ_TYPE_OOP)); + moo->_process_scheduler = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(MOO_PROCESS_SCHEDULER_NAMED_INSTVARS, 0, MOO_OBJ_TYPE_OOP)); - stix->_error_class = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP)); - stix->_true_class = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP)); - stix->_false_class = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP)); + moo->_error_class = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(0, 0, MOO_OBJ_TYPE_OOP)); + moo->_true_class = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(0, 0, MOO_OBJ_TYPE_OOP)); + moo->_false_class = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(0, 0, MOO_OBJ_TYPE_OOP)); /* TOOD: what is a proper spec for Character and SmallInteger? * If the fixed part is 0, its instance must be an object of 0 payload fields. * Does this make sense? */ - stix->_character = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP)); - stix->_small_integer = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP)); - stix->_large_positive_integer = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 1, STIX_OBJ_TYPE_LIWORD)); - stix->_large_negative_integer = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 1, STIX_OBJ_TYPE_LIWORD)); + moo->_character = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(0, 0, MOO_OBJ_TYPE_OOP)); + moo->_small_integer = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(0, 0, MOO_OBJ_TYPE_OOP)); + moo->_large_positive_integer = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(0, 1, MOO_OBJ_TYPE_LIWORD)); + moo->_large_negative_integer = alloc_kernel_class (moo, 0, MOO_CLASS_SPEC_MAKE(0, 1, MOO_OBJ_TYPE_LIWORD)); - if (!stix->_apex || !stix->_undefined_object || - !stix->_object || !stix->_string || + if (!moo->_apex || !moo->_undefined_object || + !moo->_object || !moo->_string || - !stix->_symbol || !stix->_array || - !stix->_byte_array || !stix->_symbol_set || !stix->_system_dictionary || + !moo->_symbol || !moo->_array || + !moo->_byte_array || !moo->_symbol_set || !moo->_system_dictionary || - !stix->_namespace || !stix->_pool_dictionary || - !stix->_method_dictionary || !stix->_method || !stix->_association || + !moo->_namespace || !moo->_pool_dictionary || + !moo->_method_dictionary || !moo->_method || !moo->_association || - !stix->_method_context || !stix->_block_context || - !stix->_process || !stix->_semaphore || !stix->_process_scheduler || + !moo->_method_context || !moo->_block_context || + !moo->_process || !moo->_semaphore || !moo->_process_scheduler || - !stix->_true_class || !stix->_false_class || - !stix->_character || !stix->_small_integer || - !stix->_large_positive_integer || !stix->_large_negative_integer) return -1; + !moo->_true_class || !moo->_false_class || + !moo->_character || !moo->_small_integer || + !moo->_large_positive_integer || !moo->_large_negative_integer) return -1; - STIX_OBJ_SET_CLASS (stix->_nil, stix->_undefined_object); + MOO_OBJ_SET_CLASS (moo->_nil, moo->_undefined_object); return 0; } -static int ignite_2 (stix_t* stix) +static int ignite_2 (moo_t* moo) { - stix_oop_t tmp; + moo_oop_t tmp; /* Create 'true' and 'false objects */ - stix->_true = stix_instantiate (stix, stix->_true_class, STIX_NULL, 0); - stix->_false = stix_instantiate (stix, stix->_false_class, STIX_NULL, 0); - if (!stix->_true || !stix->_false) return -1; + moo->_true = moo_instantiate (moo, moo->_true_class, MOO_NULL, 0); + moo->_false = moo_instantiate (moo, moo->_false_class, MOO_NULL, 0); + if (!moo->_true || !moo->_false) return -1; /* Create the symbol table */ - tmp = stix_instantiate (stix, stix->_symbol_set, STIX_NULL, 0); + tmp = moo_instantiate (moo, moo->_symbol_set, MOO_NULL, 0); if (!tmp) return -1; - stix->symtab = (stix_oop_set_t)tmp; + moo->symtab = (moo_oop_set_t)tmp; - stix->symtab->tally = STIX_SMOOI_TO_OOP(0); - /* It's important to assign the result of stix_instantiate() to a temporary - * variable first and then assign it to stix->symtab->bucket. - * The pointer 'stix->symtab; can change in stix_instantiate() and the - * target address of assignment may get set before stix_instantiate() + moo->symtab->tally = MOO_SMOOI_TO_OOP(0); + /* It's important to assign the result of moo_instantiate() to a temporary + * variable first and then assign it to moo->symtab->bucket. + * The pointer 'moo->symtab; can change in moo_instantiate() and the + * target address of assignment may get set before moo_instantiate() * is called. */ - tmp = stix_instantiate (stix, stix->_array, STIX_NULL, stix->option.dfl_symtab_size); + tmp = moo_instantiate (moo, moo->_array, MOO_NULL, moo->option.dfl_symtab_size); if (!tmp) return -1; - stix->symtab->bucket = (stix_oop_oop_t)tmp; + moo->symtab->bucket = (moo_oop_oop_t)tmp; /* Create the system dictionary */ - tmp = (stix_oop_t)stix_makedic (stix, stix->_system_dictionary, stix->option.dfl_sysdic_size); + tmp = (moo_oop_t)moo_makedic (moo, moo->_system_dictionary, moo->option.dfl_sysdic_size); if (!tmp) return -1; - stix->sysdic = (stix_oop_set_t)tmp; + moo->sysdic = (moo_oop_set_t)tmp; /* Create a nil process used to simplify nil check in GC. * only accessible by VM. not exported via the global dictionary. */ - tmp = (stix_oop_t)stix_instantiate (stix, stix->_process, STIX_NULL, 0); + tmp = (moo_oop_t)moo_instantiate (moo, moo->_process, MOO_NULL, 0); if (!tmp) return -1; - stix->nil_process = (stix_oop_process_t)tmp; - stix->nil_process->sp = STIX_SMOOI_TO_OOP(-1); + moo->nil_process = (moo_oop_process_t)tmp; + moo->nil_process->sp = MOO_SMOOI_TO_OOP(-1); /* Create a process scheduler */ - tmp = (stix_oop_t)stix_instantiate (stix, stix->_process_scheduler, STIX_NULL, 0); + tmp = (moo_oop_t)moo_instantiate (moo, moo->_process_scheduler, MOO_NULL, 0); if (!tmp) return -1; - stix->processor = (stix_oop_process_scheduler_t)tmp; - stix->processor->tally = STIX_SMOOI_TO_OOP(0); - stix->processor->active = stix->nil_process; + moo->processor = (moo_oop_process_scheduler_t)tmp; + moo->processor->tally = MOO_SMOOI_TO_OOP(0); + moo->processor->active = moo->nil_process; /* Export the system dictionary via the first class variable of the Stix class */ - ((stix_oop_class_t)stix->_apex)->slot[0] = (stix_oop_t)stix->sysdic; + ((moo_oop_class_t)moo->_apex)->slot[0] = (moo_oop_t)moo->sysdic; return 0; } -static int ignite_3 (stix_t* stix) +static int ignite_3 (moo_t* moo) { /* Register kernel classes manually created so far to the system dictionary */ - static stix_ooch_t str_system[] = { 'S','y','s','t','e', 'm' }; - static stix_ooch_t str_processor[] = { 'P', 'r', 'o', 'c', 'e', 's', 's', 'o', 'r' }; + static moo_ooch_t str_system[] = { 'S','y','s','t','e', 'm' }; + static moo_ooch_t str_processor[] = { 'P', 'r', 'o', 'c', 'e', 's', 's', 'o', 'r' }; - stix_oow_t i; - stix_oop_t sym, cls; - stix_oop_t* stix_ptr; + moo_oow_t i; + moo_oop_t sym, cls; + moo_oop_t* moo_ptr; - for (i = 0; i < STIX_COUNTOF(kernel_classes); i++) + for (i = 0; i < MOO_COUNTOF(kernel_classes); i++) { - sym = stix_makesymbol (stix, kernel_classes[i].name, kernel_classes[i].len); + sym = moo_makesymbol (moo, kernel_classes[i].name, kernel_classes[i].len); if (!sym) return -1; - cls = *(stix_oop_t*)((stix_uint8_t*)stix + kernel_classes[i].offset); + cls = *(moo_oop_t*)((moo_uint8_t*)moo + kernel_classes[i].offset); - if (!stix_putatsysdic(stix, sym, cls)) return -1; - stix_ptr++; + if (!moo_putatsysdic(moo, sym, cls)) return -1; + moo_ptr++; } /* Make the system dictionary available as the global name 'Stix' */ - sym = stix_makesymbol (stix, str_system, 6); + sym = moo_makesymbol (moo, str_system, 6); if (!sym) return -1; - if (!stix_putatsysdic(stix, sym, (stix_oop_t)stix->sysdic)) return -1; + if (!moo_putatsysdic(moo, sym, (moo_oop_t)moo->sysdic)) return -1; /* Make the process scheduler avaialble as the global name 'Processor' */ - sym = stix_makesymbol (stix, str_processor, 9); + sym = moo_makesymbol (moo, str_processor, 9); if (!sym) return -1; - if (!stix_putatsysdic(stix, sym, (stix_oop_t)stix->processor)) return -1; + if (!moo_putatsysdic(moo, sym, (moo_oop_t)moo->processor)) return -1; return 0; } -int stix_ignite (stix_t* stix) +int moo_ignite (moo_t* moo) { - STIX_ASSERT (stix, stix->_nil == STIX_NULL); + MOO_ASSERT (moo, moo->_nil == MOO_NULL); - stix->_nil = stix_allocbytes (stix, STIX_SIZEOF(stix_obj_t)); - if (!stix->_nil) return -1; + moo->_nil = moo_allocbytes (moo, MOO_SIZEOF(moo_obj_t)); + if (!moo->_nil) return -1; - stix->_nil->_flags = STIX_OBJ_MAKE_FLAGS (STIX_OBJ_TYPE_OOP, STIX_SIZEOF(stix_oop_t), 0, 1, 0, 0, 0); - stix->_nil->_size = 0; + moo->_nil->_flags = MOO_OBJ_MAKE_FLAGS (MOO_OBJ_TYPE_OOP, MOO_SIZEOF(moo_oop_t), 0, 1, 0, 0, 0); + moo->_nil->_size = 0; - if (ignite_1(stix) <= -1 || ignite_2(stix) <= -1 || ignite_3(stix)) return -1; + if (ignite_1(moo) <= -1 || ignite_2(moo) <= -1 || ignite_3(moo)) return -1; return 0; } @@ -325,80 +325,80 @@ int stix_ignite (stix_t* stix) * ----------------------------------------------------------------------- */ -static void compact_symbol_table (stix_t* stix, stix_oop_t _nil) +static void compact_symbol_table (moo_t* moo, moo_oop_t _nil) { - stix_oop_char_t symbol; - stix_oow_t i, x, y, z; - stix_oow_t bucket_size, index; - stix_ooi_t tally; + moo_oop_char_t symbol; + moo_oow_t i, x, y, z; + moo_oow_t bucket_size, index; + moo_ooi_t tally; -#if defined(STIX_SUPPORT_GC_DURING_IGNITION) - if (!stix->symtab) return; /* symbol table has not been created */ +#if defined(MOO_SUPPORT_GC_DURING_IGNITION) + if (!moo->symtab) return; /* symbol table has not been created */ #endif - /* the symbol table doesn't allow more data items than STIX_SMOOI_MAX. - * so stix->symtab->tally must always be a small integer */ - STIX_ASSERT (stix, STIX_OOP_IS_SMOOI(stix->symtab->tally)); - tally = STIX_OOP_TO_SMOOI(stix->symtab->tally); - STIX_ASSERT (stix, tally >= 0); /* it must not be less than 0 */ + /* the symbol table doesn't allow more data items than MOO_SMOOI_MAX. + * so moo->symtab->tally must always be a small integer */ + MOO_ASSERT (moo, MOO_OOP_IS_SMOOI(moo->symtab->tally)); + tally = MOO_OOP_TO_SMOOI(moo->symtab->tally); + MOO_ASSERT (moo, tally >= 0); /* it must not be less than 0 */ if (tally <= 0) return; - /* NOTE: in theory, the bucket size can be greater than STIX_SMOOI_MAX + /* NOTE: in theory, the bucket size can be greater than MOO_SMOOI_MAX * as it is an internal header field and is of an unsigned type */ - bucket_size = STIX_OBJ_GET_SIZE(stix->symtab->bucket); + bucket_size = MOO_OBJ_GET_SIZE(moo->symtab->bucket); for (index = 0; index < bucket_size; ) { - if (STIX_OBJ_GET_FLAGS_MOVED(stix->symtab->bucket->slot[index])) + if (MOO_OBJ_GET_FLAGS_MOVED(moo->symtab->bucket->slot[index])) { index++; continue; } - STIX_ASSERT (stix, stix->symtab->bucket->slot[index] != _nil); + MOO_ASSERT (moo, moo->symtab->bucket->slot[index] != _nil); for (i = 0, x = index, y = index; i < bucket_size; i++) { y = (y + 1) % bucket_size; /* done if the slot at the current hash index is _nil */ - if (stix->symtab->bucket->slot[y] == _nil) break; + if (moo->symtab->bucket->slot[y] == _nil) break; /* get the natural hash index for the data in the slot * at the current hash index */ - symbol = (stix_oop_char_t)stix->symtab->bucket->slot[y]; + symbol = (moo_oop_char_t)moo->symtab->bucket->slot[y]; - STIX_ASSERT (stix, STIX_CLASSOF(stix,symbol) == stix->_symbol); + MOO_ASSERT (moo, MOO_CLASSOF(moo,symbol) == moo->_symbol); - z = stix_hashoochars(symbol->slot, STIX_OBJ_GET_SIZE(symbol)) % bucket_size; + z = moo_hashoochars(symbol->slot, MOO_OBJ_GET_SIZE(symbol)) % bucket_size; /* move an element if necessary */ if ((y > x && (z <= x || z > y)) || (y < x && (z <= x && z > y))) { - stix->symtab->bucket->slot[x] = stix->symtab->bucket->slot[y]; + moo->symtab->bucket->slot[x] = moo->symtab->bucket->slot[y]; x = y; } } - stix->symtab->bucket->slot[x] = _nil; + moo->symtab->bucket->slot[x] = _nil; tally--; } - STIX_ASSERT (stix, tally >= 0); - STIX_ASSERT (stix, tally <= STIX_SMOOI_MAX); - stix->symtab->tally = STIX_SMOOI_TO_OOP(tally); + MOO_ASSERT (moo, tally >= 0); + MOO_ASSERT (moo, tally <= MOO_SMOOI_MAX); + moo->symtab->tally = MOO_SMOOI_TO_OOP(tally); } -static STIX_INLINE stix_oow_t get_payload_bytes (stix_t* stix, stix_oop_t oop) +static MOO_INLINE moo_oow_t get_payload_bytes (moo_t* moo, moo_oop_t oop) { - stix_oow_t nbytes_aligned; + moo_oow_t nbytes_aligned; -#if defined(STIX_USE_OBJECT_TRAILER) - if (STIX_OBJ_GET_FLAGS_TRAILER(oop)) +#if defined(MOO_USE_OBJECT_TRAILER) + if (MOO_OBJ_GET_FLAGS_TRAILER(oop)) { - stix_oow_t nbytes; + moo_oow_t nbytes; /* only an OOP object can have the trailer. * @@ -412,51 +412,51 @@ static STIX_INLINE stix_oow_t get_payload_bytes (stix_t* stix, stix_oop_t oop) * | Z | <-- if TRAILER is set, it is the number of bytes in the trailer * | | | | | */ - STIX_ASSERT (stix, STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_OOP); - STIX_ASSERT (stix, STIX_OBJ_GET_FLAGS_UNIT(oop) == STIX_SIZEOF(stix_oow_t)); - STIX_ASSERT (stix, STIX_OBJ_GET_FLAGS_EXTRA(oop) == 0); /* no 'extra' for an OOP object */ + MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_TYPE(oop) == MOO_OBJ_TYPE_OOP); + MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_UNIT(oop) == MOO_SIZEOF(moo_oow_t)); + MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_EXTRA(oop) == 0); /* no 'extra' for an OOP object */ - nbytes = STIX_OBJ_BYTESOF(oop) + STIX_SIZEOF(stix_oow_t) + \ - (stix_oow_t)((stix_oop_oop_t)oop)->slot[STIX_OBJ_GET_SIZE(oop)]; - nbytes_aligned = STIX_ALIGN (nbytes, STIX_SIZEOF(stix_oop_t)); + nbytes = MOO_OBJ_BYTESOF(oop) + MOO_SIZEOF(moo_oow_t) + \ + (moo_oow_t)((moo_oop_oop_t)oop)->slot[MOO_OBJ_GET_SIZE(oop)]; + nbytes_aligned = MOO_ALIGN (nbytes, MOO_SIZEOF(moo_oop_t)); } else { #endif /* calculate the payload size in bytes */ - nbytes_aligned = STIX_ALIGN (STIX_OBJ_BYTESOF(oop), STIX_SIZEOF(stix_oop_t)); -#if defined(STIX_USE_OBJECT_TRAILER) + nbytes_aligned = MOO_ALIGN (MOO_OBJ_BYTESOF(oop), MOO_SIZEOF(moo_oop_t)); +#if defined(MOO_USE_OBJECT_TRAILER) } #endif return nbytes_aligned; } -stix_oop_t stix_moveoop (stix_t* stix, stix_oop_t oop) +moo_oop_t moo_moveoop (moo_t* moo, moo_oop_t oop) { -#if defined(STIX_SUPPORT_GC_DURING_IGNITION) +#if defined(MOO_SUPPORT_GC_DURING_IGNITION) if (!oop) return oop; #endif - if (!STIX_OOP_IS_POINTER(oop)) return oop; + if (!MOO_OOP_IS_POINTER(oop)) return oop; - if (STIX_OBJ_GET_FLAGS_MOVED(oop)) + if (MOO_OBJ_GET_FLAGS_MOVED(oop)) { /* this object has migrated to the new heap. * the class field has been updated to the new object * in the 'else' block below. i can simply return it * without further migration. */ - return STIX_OBJ_GET_CLASS(oop); + return MOO_OBJ_GET_CLASS(oop); } else { - stix_oow_t nbytes_aligned; - stix_oop_t tmp; + moo_oow_t nbytes_aligned; + moo_oop_t tmp; - nbytes_aligned = get_payload_bytes (stix, oop); + nbytes_aligned = get_payload_bytes (moo, oop); /* allocate space in the new heap */ - tmp = stix_allocheapmem (stix, stix->newheap, STIX_SIZEOF(stix_obj_t) + nbytes_aligned); + tmp = moo_allocheapmem (moo, moo->newheap, MOO_SIZEOF(moo_obj_t) + nbytes_aligned); /* allocation here must not fail because * i'm allocating the new space in a new heap for @@ -465,91 +465,91 @@ stix_oop_t stix_moveoop (stix_t* stix, stix_oop_t oop) * assuming the new heap is as large as the old heap, * and garbage collection doesn't allocate more objects * than in the old heap, it must not fail. */ - STIX_ASSERT (stix, tmp != STIX_NULL); + MOO_ASSERT (moo, tmp != MOO_NULL); /* copy the payload to the new object */ - STIX_MEMCPY (tmp, oop, STIX_SIZEOF(stix_obj_t) + nbytes_aligned); + MOO_MEMCPY (tmp, oop, MOO_SIZEOF(moo_obj_t) + nbytes_aligned); /* mark the old object that it has migrated to the new heap */ - STIX_OBJ_SET_FLAGS_MOVED(oop, 1); + MOO_OBJ_SET_FLAGS_MOVED(oop, 1); /* let the class field of the old object point to the new * object allocated in the new heap. it is returned in * the 'if' block at the top of this function. */ - STIX_OBJ_SET_CLASS (oop, tmp); + MOO_OBJ_SET_CLASS (oop, tmp); /* return the new object */ return tmp; } } -static stix_uint8_t* scan_new_heap (stix_t* stix, stix_uint8_t* ptr) +static moo_uint8_t* scan_new_heap (moo_t* moo, moo_uint8_t* ptr) { - while (ptr < stix->newheap->ptr) + while (ptr < moo->newheap->ptr) { - stix_oow_t i; - stix_oow_t nbytes_aligned; - stix_oop_t oop; + moo_oow_t i; + moo_oow_t nbytes_aligned; + moo_oop_t oop; - oop = (stix_oop_t)ptr; + oop = (moo_oop_t)ptr; - #if defined(STIX_USE_OBJECT_TRAILER) - if (STIX_OBJ_GET_FLAGS_TRAILER(oop)) + #if defined(MOO_USE_OBJECT_TRAILER) + if (MOO_OBJ_GET_FLAGS_TRAILER(oop)) { - stix_oow_t nbytes; + moo_oow_t nbytes; - STIX_ASSERT (stix, STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_OOP); - STIX_ASSERT (stix, STIX_OBJ_GET_FLAGS_UNIT(oop) == STIX_SIZEOF(stix_oow_t)); - STIX_ASSERT (stix, STIX_OBJ_GET_FLAGS_EXTRA(oop) == 0); /* no 'extra' for an OOP object */ + MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_TYPE(oop) == MOO_OBJ_TYPE_OOP); + MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_UNIT(oop) == MOO_SIZEOF(moo_oow_t)); + MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_EXTRA(oop) == 0); /* no 'extra' for an OOP object */ - nbytes = STIX_OBJ_BYTESOF(oop) + STIX_SIZEOF(stix_oow_t) + \ - (stix_oow_t)((stix_oop_oop_t)oop)->slot[STIX_OBJ_GET_SIZE(oop)]; - nbytes_aligned = STIX_ALIGN (nbytes, STIX_SIZEOF(stix_oop_t)); + nbytes = MOO_OBJ_BYTESOF(oop) + MOO_SIZEOF(moo_oow_t) + \ + (moo_oow_t)((moo_oop_oop_t)oop)->slot[MOO_OBJ_GET_SIZE(oop)]; + nbytes_aligned = MOO_ALIGN (nbytes, MOO_SIZEOF(moo_oop_t)); } else { #endif - nbytes_aligned = STIX_ALIGN (STIX_OBJ_BYTESOF(oop), STIX_SIZEOF(stix_oop_t)); - #if defined(STIX_USE_OBJECT_TRAILER) + nbytes_aligned = MOO_ALIGN (MOO_OBJ_BYTESOF(oop), MOO_SIZEOF(moo_oop_t)); + #if defined(MOO_USE_OBJECT_TRAILER) } #endif - STIX_OBJ_SET_CLASS (oop, stix_moveoop(stix, STIX_OBJ_GET_CLASS(oop))); - if (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_OOP) + MOO_OBJ_SET_CLASS (oop, moo_moveoop(moo, MOO_OBJ_GET_CLASS(oop))); + if (MOO_OBJ_GET_FLAGS_TYPE(oop) == MOO_OBJ_TYPE_OOP) { - stix_oop_oop_t xtmp; - stix_oow_t size; + moo_oop_oop_t xtmp; + moo_oow_t size; - if (stix->_process && STIX_OBJ_GET_CLASS(oop) == stix->_process) + if (moo->_process && MOO_OBJ_GET_CLASS(oop) == moo->_process) { /* the stack in a process object doesn't need to be * scanned in full. the slots above the stack pointer * are garbages. */ - size = STIX_PROCESS_NAMED_INSTVARS + - STIX_OOP_TO_SMOOI(((stix_oop_process_t)oop)->sp) + 1; - STIX_ASSERT (stix, size <= STIX_OBJ_GET_SIZE(oop)); + size = MOO_PROCESS_NAMED_INSTVARS + + MOO_OOP_TO_SMOOI(((moo_oop_process_t)oop)->sp) + 1; + MOO_ASSERT (moo, size <= MOO_OBJ_GET_SIZE(oop)); } else { - size = STIX_OBJ_GET_SIZE(oop); + size = MOO_OBJ_GET_SIZE(oop); } - xtmp = (stix_oop_oop_t)oop; + xtmp = (moo_oop_oop_t)oop; for (i = 0; i < size; i++) { - if (STIX_OOP_IS_POINTER(xtmp->slot[i])) - xtmp->slot[i] = stix_moveoop (stix, xtmp->slot[i]); + if (MOO_OOP_IS_POINTER(xtmp->slot[i])) + xtmp->slot[i] = moo_moveoop (moo, xtmp->slot[i]); } } - ptr = ptr + STIX_SIZEOF(stix_obj_t) + nbytes_aligned; + ptr = ptr + MOO_SIZEOF(moo_obj_t) + nbytes_aligned; } /* return the pointer to the beginning of the free space in the heap */ return ptr; } -void stix_gc (stix_t* stix) +void moo_gc (moo_t* moo) { /* * move a referenced object to the new heap. @@ -557,183 +557,183 @@ void stix_gc (stix_t* stix) * move objects pointed to by the fields to the new heap. * finally perform some tricky symbol table clean-up. */ - stix_uint8_t* ptr; - stix_heap_t* tmp; - stix_oop_t old_nil; - stix_oow_t i; - stix_cb_t* cb; + moo_uint8_t* ptr; + moo_heap_t* tmp; + moo_oop_t old_nil; + moo_oow_t i; + moo_cb_t* cb; - if (stix->active_context) + if (moo->active_context) { /* TODO: verify if this is correct */ - STIX_ASSERT (stix, (stix_oop_t)stix->processor != stix->_nil); - STIX_ASSERT (stix, (stix_oop_t)stix->processor->active != stix->_nil); + MOO_ASSERT (moo, (moo_oop_t)moo->processor != moo->_nil); + MOO_ASSERT (moo, (moo_oop_t)moo->processor->active != moo->_nil); /* store the stack pointer to the active process */ - stix->processor->active->sp = STIX_SMOOI_TO_OOP(stix->sp); + moo->processor->active->sp = MOO_SMOOI_TO_OOP(moo->sp); /* store the instruction pointer to the active context */ - stix->active_context->ip = STIX_SMOOI_TO_OOP(stix->ip); + moo->active_context->ip = MOO_SMOOI_TO_OOP(moo->ip); } - STIX_LOG4 (stix, STIX_LOG_GC | STIX_LOG_INFO, + MOO_LOG4 (moo, MOO_LOG_GC | MOO_LOG_INFO, "Starting GC curheap base %p ptr %p newheap base %p ptr %p\n", - stix->curheap->base, stix->curheap->ptr, stix->newheap->base, stix->newheap->ptr); + moo->curheap->base, moo->curheap->ptr, moo->newheap->base, moo->newheap->ptr); /* TODO: allocate common objects like _nil and the root dictionary * in the permanant heap. minimize moving around */ - old_nil = stix->_nil; + old_nil = moo->_nil; /* move _nil and the root object table */ - stix->_nil = stix_moveoop (stix, stix->_nil); - stix->_true = stix_moveoop (stix, stix->_true); - stix->_false = stix_moveoop (stix, stix->_false); + moo->_nil = moo_moveoop (moo, moo->_nil); + moo->_true = moo_moveoop (moo, moo->_true); + moo->_false = moo_moveoop (moo, moo->_false); - for (i = 0; i < STIX_COUNTOF(kernel_classes); i++) + for (i = 0; i < MOO_COUNTOF(kernel_classes); i++) { - stix_oop_t tmp; - tmp = *(stix_oop_t*)((stix_uint8_t*)stix + kernel_classes[i].offset); - tmp = stix_moveoop (stix, tmp); - *(stix_oop_t*)((stix_uint8_t*)stix + kernel_classes[i].offset) = tmp; + moo_oop_t tmp; + tmp = *(moo_oop_t*)((moo_uint8_t*)moo + kernel_classes[i].offset); + tmp = moo_moveoop (moo, tmp); + *(moo_oop_t*)((moo_uint8_t*)moo + kernel_classes[i].offset) = tmp; } - stix->sysdic = (stix_oop_set_t) stix_moveoop (stix, (stix_oop_t)stix->sysdic); - stix->processor = (stix_oop_process_scheduler_t) stix_moveoop (stix, (stix_oop_t)stix->processor); - stix->nil_process = (stix_oop_process_t) stix_moveoop (stix, (stix_oop_t)stix->nil_process); + moo->sysdic = (moo_oop_set_t) moo_moveoop (moo, (moo_oop_t)moo->sysdic); + moo->processor = (moo_oop_process_scheduler_t) moo_moveoop (moo, (moo_oop_t)moo->processor); + moo->nil_process = (moo_oop_process_t) moo_moveoop (moo, (moo_oop_t)moo->nil_process); - for (i = 0; i < stix->sem_list_count; i++) + for (i = 0; i < moo->sem_list_count; i++) { - stix->sem_list[i] = (stix_oop_semaphore_t)stix_moveoop (stix, (stix_oop_t)stix->sem_list[i]); + moo->sem_list[i] = (moo_oop_semaphore_t)moo_moveoop (moo, (moo_oop_t)moo->sem_list[i]); } - for (i = 0; i < stix->sem_heap_count; i++) + for (i = 0; i < moo->sem_heap_count; i++) { - stix->sem_heap[i] = (stix_oop_semaphore_t)stix_moveoop (stix, (stix_oop_t)stix->sem_heap[i]); + moo->sem_heap[i] = (moo_oop_semaphore_t)moo_moveoop (moo, (moo_oop_t)moo->sem_heap[i]); } - for (i = 0; i < stix->tmp_count; i++) + for (i = 0; i < moo->tmp_count; i++) { - *stix->tmp_stack[i] = stix_moveoop (stix, *stix->tmp_stack[i]); + *moo->tmp_stack[i] = moo_moveoop (moo, *moo->tmp_stack[i]); } - if (stix->initial_context) - stix->initial_context = (stix_oop_context_t)stix_moveoop (stix, (stix_oop_t)stix->initial_context); - if (stix->active_context) - stix->active_context = (stix_oop_context_t)stix_moveoop (stix, (stix_oop_t)stix->active_context); - if (stix->active_method) - stix->active_method = (stix_oop_method_t)stix_moveoop (stix, (stix_oop_t)stix->active_method); + if (moo->initial_context) + moo->initial_context = (moo_oop_context_t)moo_moveoop (moo, (moo_oop_t)moo->initial_context); + if (moo->active_context) + moo->active_context = (moo_oop_context_t)moo_moveoop (moo, (moo_oop_t)moo->active_context); + if (moo->active_method) + moo->active_method = (moo_oop_method_t)moo_moveoop (moo, (moo_oop_t)moo->active_method); - for (cb = stix->cblist; cb; cb = cb->next) + for (cb = moo->cblist; cb; cb = cb->next) { - if (cb->gc) cb->gc (stix); + if (cb->gc) cb->gc (moo); } /* scan the new heap to move referenced objects */ - ptr = (stix_uint8_t*) STIX_ALIGN ((stix_uintptr_t)stix->newheap->base, STIX_SIZEOF(stix_oop_t)); - ptr = scan_new_heap (stix, ptr); + ptr = (moo_uint8_t*) MOO_ALIGN ((moo_uintptr_t)moo->newheap->base, MOO_SIZEOF(moo_oop_t)); + ptr = scan_new_heap (moo, ptr); /* traverse the symbol table for unreferenced symbols. * if the symbol has not moved to the new heap, the symbol * is not referenced by any other objects than the symbol * table itself */ - compact_symbol_table (stix, old_nil); + compact_symbol_table (moo, old_nil); /* move the symbol table itself */ - stix->symtab = (stix_oop_set_t)stix_moveoop (stix, (stix_oop_t)stix->symtab); + moo->symtab = (moo_oop_set_t)moo_moveoop (moo, (moo_oop_t)moo->symtab); /* scan the new heap again from the end position of * the previous scan to move referenced objects by * the symbol table. */ - ptr = scan_new_heap (stix, ptr); + ptr = scan_new_heap (moo, ptr); /* the contents of the current heap is not needed any more. * reset the upper bound to the base. don't forget to align the heap - * pointer to the OOP size. See stix_makeheap() also */ - stix->curheap->ptr = (stix_uint8_t*)STIX_ALIGN(((stix_uintptr_t)stix->curheap->base), STIX_SIZEOF(stix_oop_t)); + * pointer to the OOP size. See moo_makeheap() also */ + moo->curheap->ptr = (moo_uint8_t*)MOO_ALIGN(((moo_uintptr_t)moo->curheap->base), MOO_SIZEOF(moo_oop_t)); /* swap the current heap and old heap */ - tmp = stix->curheap; - stix->curheap = stix->newheap; - stix->newheap = tmp; + tmp = moo->curheap; + moo->curheap = moo->newheap; + moo->newheap = tmp; /* - if (stix->symtab && STIX_LOG_ENABLED(stix, STIX_LOG_GC | STIX_LOG_DEBUG)) + if (moo->symtab && MOO_LOG_ENABLED(moo, MOO_LOG_GC | MOO_LOG_DEBUG)) { - stix_oow_t index; - stix_oop_oop_t buc; - STIX_LOG0 (stix, STIX_LOG_GC | STIX_LOG_DEBUG, "--------- SURVIVING SYMBOLS IN GC ----------\n"); - buc = (stix_oop_oop_t) stix->symtab->bucket; - for (index = 0; index < STIX_OBJ_GET_SIZE(buc); index++) + moo_oow_t index; + moo_oop_oop_t buc; + MOO_LOG0 (moo, MOO_LOG_GC | MOO_LOG_DEBUG, "--------- SURVIVING SYMBOLS IN GC ----------\n"); + buc = (moo_oop_oop_t) moo->symtab->bucket; + for (index = 0; index < MOO_OBJ_GET_SIZE(buc); index++) { - if ((stix_oop_t)buc->slot[index] != stix->_nil) + if ((moo_oop_t)buc->slot[index] != moo->_nil) { - STIX_LOG1 (stix, STIX_LOG_GC | STIX_LOG_DEBUG, "\t%O\n", buc->slot[index]); + MOO_LOG1 (moo, MOO_LOG_GC | MOO_LOG_DEBUG, "\t%O\n", buc->slot[index]); } } - STIX_LOG0 (stix, STIX_LOG_GC | STIX_LOG_DEBUG, "--------------------------------------------\n"); + MOO_LOG0 (moo, MOO_LOG_GC | MOO_LOG_DEBUG, "--------------------------------------------\n"); } */ - if (stix->active_method) SET_ACTIVE_METHOD_CODE (stix); /* update stix->active_code */ + if (moo->active_method) SET_ACTIVE_METHOD_CODE (moo); /* update moo->active_code */ /* TODO: include some gc statstics like number of live objects, gc performance, etc */ - STIX_LOG4 (stix, STIX_LOG_GC | STIX_LOG_INFO, + MOO_LOG4 (moo, MOO_LOG_GC | MOO_LOG_INFO, "Finished GC curheap base %p ptr %p newheap base %p ptr %p\n", - stix->curheap->base, stix->curheap->ptr, stix->newheap->base, stix->newheap->ptr); + moo->curheap->base, moo->curheap->ptr, moo->newheap->base, moo->newheap->ptr); } -void stix_pushtmp (stix_t* stix, stix_oop_t* oop_ptr) +void moo_pushtmp (moo_t* moo, moo_oop_t* oop_ptr) { /* if you have too many temporaries pushed, something must be wrong. * change your code not to exceede the stack limit */ - STIX_ASSERT (stix, stix->tmp_count < STIX_COUNTOF(stix->tmp_stack)); - stix->tmp_stack[stix->tmp_count++] = oop_ptr; + MOO_ASSERT (moo, moo->tmp_count < MOO_COUNTOF(moo->tmp_stack)); + moo->tmp_stack[moo->tmp_count++] = oop_ptr; } -void stix_poptmp (stix_t* stix) +void moo_poptmp (moo_t* moo) { - STIX_ASSERT (stix, stix->tmp_count > 0); - stix->tmp_count--; + MOO_ASSERT (moo, moo->tmp_count > 0); + moo->tmp_count--; } -void stix_poptmps (stix_t* stix, stix_oow_t count) +void moo_poptmps (moo_t* moo, moo_oow_t count) { - STIX_ASSERT (stix, stix->tmp_count >= count); - stix->tmp_count -= count; + MOO_ASSERT (moo, moo->tmp_count >= count); + moo->tmp_count -= count; } -stix_oop_t stix_shallowcopy (stix_t* stix, stix_oop_t oop) +moo_oop_t moo_shallowcopy (moo_t* moo, moo_oop_t oop) { - if (STIX_OOP_IS_POINTER(oop) && STIX_OBJ_GET_CLASS(oop) != stix->_symbol) + if (MOO_OOP_IS_POINTER(oop) && MOO_OBJ_GET_CLASS(oop) != moo->_symbol) { #if 0 - stix_oop_t z; - stix_oop_class_t c; + moo_oop_t z; + moo_oop_class_t c; - c = (stix_oop_class_t)STIX_OBJ_GET_CLASS(oop); - stix_pushtmp (stix, &oop); - z = stix_instantiate (stix, (stix_oop_t)c, STIX_NULL, STIX_OBJ_GET_SIZE(oop) - STIX_CLASS_SPEC_NAMED_INSTVAR(STIX_OOP_TO_SMOOI(c->spec))); - stix_poptmp(stix); + c = (moo_oop_class_t)MOO_OBJ_GET_CLASS(oop); + moo_pushtmp (moo, &oop); + z = moo_instantiate (moo, (moo_oop_t)c, MOO_NULL, MOO_OBJ_GET_SIZE(oop) - MOO_CLASS_SPEC_NAMED_INSTVAR(MOO_OOP_TO_SMOOI(c->spec))); + moo_poptmp(moo); if (!z) return z; /* copy the payload */ - STIX_MEMCPY (z + 1, oop + 1, get_payload_bytes(stix, oop)); + MOO_MEMCPY (z + 1, oop + 1, get_payload_bytes(moo, oop)); return z; #else - stix_oop_t z; - stix_oow_t total_bytes; + moo_oop_t z; + moo_oow_t total_bytes; - total_bytes = STIX_SIZEOF(stix_obj_t) + get_payload_bytes(stix, oop); + total_bytes = MOO_SIZEOF(moo_obj_t) + get_payload_bytes(moo, oop); - stix_pushtmp (stix, &oop); - z = stix_allocbytes (stix, total_bytes); - stix_poptmp(stix); + moo_pushtmp (moo, &oop); + z = moo_allocbytes (moo, total_bytes); + moo_poptmp(moo); - STIX_MEMCPY (z, oop, total_bytes); + MOO_MEMCPY (z, oop, total_bytes); return z; #endif } diff --git a/stix/lib/heap.c b/stix/lib/heap.c index b788fbd..e851fe0 100644 --- a/stix/lib/heap.c +++ b/stix/lib/heap.c @@ -24,53 +24,53 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "stix-prv.h" +#include "moo-prv.h" -stix_heap_t* stix_makeheap (stix_t* stix, stix_oow_t size) +moo_heap_t* moo_makeheap (moo_t* moo, moo_oow_t size) { - stix_heap_t* heap; + moo_heap_t* heap; - heap = (stix_heap_t*)STIX_MMGR_ALLOC(stix->mmgr, STIX_SIZEOF(*heap) + size); + heap = (moo_heap_t*)MOO_MMGR_ALLOC(moo->mmgr, MOO_SIZEOF(*heap) + size); if (!heap) { - stix->errnum = STIX_ESYSMEM; - return STIX_NULL; + moo->errnum = MOO_ESYSMEM; + return MOO_NULL; } - STIX_MEMSET (heap, 0, STIX_SIZEOF(*heap) + size); + MOO_MEMSET (heap, 0, MOO_SIZEOF(*heap) + size); - heap->base = (stix_uint8_t*)(heap + 1); + heap->base = (moo_uint8_t*)(heap + 1); /* adjust the initial allocation pointer to a multiple of the oop size */ - heap->ptr = (stix_uint8_t*)STIX_ALIGN(((stix_uintptr_t)heap->base), STIX_SIZEOF(stix_oop_t)); + heap->ptr = (moo_uint8_t*)MOO_ALIGN(((moo_uintptr_t)heap->base), MOO_SIZEOF(moo_oop_t)); heap->limit = heap->base + size; - STIX_ASSERT (stix, heap->ptr >= heap->base); - STIX_ASSERT (stix, heap->limit >= heap->base ); - STIX_ASSERT (stix, heap->limit - heap->base == size); + MOO_ASSERT (moo, heap->ptr >= heap->base); + MOO_ASSERT (moo, heap->limit >= heap->base ); + MOO_ASSERT (moo, heap->limit - heap->base == size); /* if size is too small, heap->ptr may go past heap->limit even at * this moment depending on the alignment of heap->base. subsequent - * calls to substix_allocheapmem() are bound to fail. Make sure to + * calls to submoo_allocheapmem() are bound to fail. Make sure to * pass a heap size large enough */ return heap; } -void stix_killheap (stix_t* stix, stix_heap_t* heap) +void moo_killheap (moo_t* moo, moo_heap_t* heap) { - STIX_MMGR_FREE (stix->mmgr, heap); + MOO_MMGR_FREE (moo->mmgr, heap); } -void* stix_allocheapmem (stix_t* stix, stix_heap_t* heap, stix_oow_t size) +void* moo_allocheapmem (moo_t* moo, moo_heap_t* heap, moo_oow_t size) { - stix_uint8_t* ptr; + moo_uint8_t* ptr; /* check the heap size limit */ if (heap->ptr >= heap->limit || heap->limit - heap->ptr < size) { - STIX_LOG4 (stix, STIX_LOG_ERROR, "Cannot allocate %zd bytes from heap - ptr %p limit %p size %zd\n", size, heap->ptr, heap->limit, (stix_oow_t)(heap->limit - heap->ptr)); - stix->errnum = STIX_EOOMEM; - return STIX_NULL; + MOO_LOG4 (moo, MOO_LOG_ERROR, "Cannot allocate %zd bytes from heap - ptr %p limit %p size %zd\n", size, heap->ptr, heap->limit, (moo_oow_t)(heap->limit - heap->ptr)); + moo->errnum = MOO_EOOMEM; + return MOO_NULL; } /* allocation is as simple as moving the heap pointer */ diff --git a/stix/lib/logfmt.c b/stix/lib/logfmt.c index 2f5bd0d..d9f49d1 100644 --- a/stix/lib/logfmt.c +++ b/stix/lib/logfmt.c @@ -24,7 +24,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "stix-prv.h" +#include "moo-prv.h" /*#include */ /* for snrintf(). used for floating-point number formatting */ #include @@ -42,8 +42,8 @@ floting-point conversion implementation*/ /* Max number conversion buffer length: - * stix_intmax_t in base 2, plus NUL byte. */ -#define MAXNBUF (STIX_SIZEOF(stix_intmax_t) * 8 + 1) + * moo_intmax_t in base 2, plus NUL byte. */ +#define MAXNBUF (MOO_SIZEOF(moo_intmax_t) * 8 + 1) enum { @@ -64,8 +64,8 @@ enum static struct { - stix_uint8_t flag; /* for single occurrence */ - stix_uint8_t dflag; /* for double occurrence */ + moo_uint8_t flag; /* for single occurrence */ + moo_uint8_t dflag; /* for double occurrence */ } lm_tab[26] = { { 0, 0 }, /* a */ @@ -112,44 +112,44 @@ enum FLAGC_LENMOD = (1 << 10) /* length modifier */ }; -static const stix_bch_t hex2ascii_lower[] = +static const moo_bch_t hex2ascii_lower[] = { '0','1','2','3','4','5','6','7','8','9', 'a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z' }; -static const stix_bch_t hex2ascii_upper[] = +static const moo_bch_t hex2ascii_upper[] = { '0','1','2','3','4','5','6','7','8','9', 'A','B','C','D','E','F','G','H','I','J','K','L','M', 'N','O','P','Q','R','S','T','U','V','W','X','H','Z' }; -static stix_uch_t uch_nullstr[] = { '(','n','u','l','l', ')','\0' }; -static stix_bch_t bch_nullstr[] = { '(','n','u','l','l', ')','\0' }; +static moo_uch_t uch_nullstr[] = { '(','n','u','l','l', ')','\0' }; +static moo_bch_t bch_nullstr[] = { '(','n','u','l','l', ')','\0' }; -typedef int (*stix_fmtout_putch_t) ( - stix_t* stix, - stix_oow_t mask, - stix_ooch_t c, - stix_oow_t len +typedef int (*moo_fmtout_putch_t) ( + moo_t* moo, + moo_oow_t mask, + moo_ooch_t c, + moo_oow_t len ); -typedef int (*stix_fmtout_putcs_t) ( - stix_t* stix, - stix_oow_t mask, - const stix_ooch_t* ptr, - stix_oow_t len +typedef int (*moo_fmtout_putcs_t) ( + moo_t* moo, + moo_oow_t mask, + const moo_ooch_t* ptr, + moo_oow_t len ); -typedef struct stix_fmtout_t stix_fmtout_t; -struct stix_fmtout_t +typedef struct moo_fmtout_t moo_fmtout_t; +struct moo_fmtout_t { - stix_oow_t count; /* out */ - stix_oow_t mask; /* in */ - stix_fmtout_putch_t putch; /* in */ - stix_fmtout_putcs_t putcs; /* in */ + moo_oow_t count; /* out */ + moo_oow_t mask; /* in */ + moo_fmtout_putch_t putch; /* in */ + moo_fmtout_putcs_t putcs; /* in */ }; /* ------------------------------------------------------------------------- */ @@ -160,9 +160,9 @@ struct stix_fmtout_t * The buffer pointed to by `nbuf' must have length >= MAXNBUF. */ -static stix_bch_t* sprintn_lower (stix_bch_t* nbuf, stix_uintmax_t num, int base, stix_ooi_t *lenp) +static moo_bch_t* sprintn_lower (moo_bch_t* nbuf, moo_uintmax_t num, int base, moo_ooi_t *lenp) { - stix_bch_t* p; + moo_bch_t* p; p = nbuf; *p = '\0'; @@ -172,9 +172,9 @@ static stix_bch_t* sprintn_lower (stix_bch_t* nbuf, stix_uintmax_t num, int base return p; /* returns the end */ } -static stix_bch_t* sprintn_upper (stix_bch_t* nbuf, stix_uintmax_t num, int base, stix_ooi_t *lenp) +static moo_bch_t* sprintn_upper (moo_bch_t* nbuf, moo_uintmax_t num, int base, moo_ooi_t *lenp) { - stix_bch_t* p; + moo_bch_t* p; p = nbuf; *p = '\0'; @@ -185,181 +185,181 @@ static stix_bch_t* sprintn_upper (stix_bch_t* nbuf, stix_uintmax_t num, int base } /* ------------------------------------------------------------------------- */ -static int put_ooch (stix_t* stix, stix_oow_t mask, stix_ooch_t ch, stix_oow_t len) +static int put_ooch (moo_t* moo, moo_oow_t mask, moo_ooch_t ch, moo_oow_t len) { if (len <= 0) return 1; - if (stix->log.len > 0 && stix->log.last_mask != mask) + if (moo->log.len > 0 && moo->log.last_mask != mask) { /* the mask has changed. commit the buffered text */ /* TODO: HANDLE LINE ENDING CONVENTION BETTER... */ - if (stix->log.ptr[stix->log.len - 1] != '\n') + if (moo->log.ptr[moo->log.len - 1] != '\n') { /* no line ending - append a line terminator */ - stix->log.ptr[stix->log.len++] = '\n'; + moo->log.ptr[moo->log.len++] = '\n'; } - stix->vmprim.log_write (stix, stix->log.last_mask, stix->log.ptr, stix->log.len); - stix->log.len = 0; + moo->vmprim.log_write (moo, moo->log.last_mask, moo->log.ptr, moo->log.len); + moo->log.len = 0; } redo: - if (len > stix->log.capa - stix->log.len) + if (len > moo->log.capa - moo->log.len) { - stix_oow_t newcapa; - stix_ooch_t* tmp; + moo_oow_t newcapa; + moo_ooch_t* tmp; - if (len > STIX_TYPE_MAX(stix_oow_t) - stix->log.len) + if (len > MOO_TYPE_MAX(moo_oow_t) - moo->log.len) { /* data too big */ - stix->errnum = STIX_ETOOBIG; + moo->errnum = MOO_ETOOBIG; return -1; } - newcapa = STIX_ALIGN(stix->log.len + len, 512); /* TODO: adjust this capacity */ + newcapa = MOO_ALIGN(moo->log.len + len, 512); /* TODO: adjust this capacity */ /* +1 to handle line ending injection more easily */ - tmp = stix_reallocmem (stix, stix->log.ptr, (newcapa + 1) * STIX_SIZEOF(*tmp)); + tmp = moo_reallocmem (moo, moo->log.ptr, (newcapa + 1) * MOO_SIZEOF(*tmp)); if (!tmp) { - if (stix->log.len > 0) + if (moo->log.len > 0) { /* can't expand the buffer. just flush the existing contents */ - stix->vmprim.log_write (stix, stix->log.last_mask, stix->log.ptr, stix->log.len); - stix->log.len = 0; + moo->vmprim.log_write (moo, moo->log.last_mask, moo->log.ptr, moo->log.len); + moo->log.len = 0; goto redo; } return -1; } - stix->log.ptr = tmp; - stix->log.capa = newcapa; + moo->log.ptr = tmp; + moo->log.capa = newcapa; } while (len > 0) { - stix->log.ptr[stix->log.len++] = ch; + moo->log.ptr[moo->log.len++] = ch; len--; } - stix->log.last_mask = mask; + moo->log.last_mask = mask; return 1; /* success */ } -static int put_oocs (stix_t* stix, stix_oow_t mask, const stix_ooch_t* ptr, stix_oow_t len) +static int put_oocs (moo_t* moo, moo_oow_t mask, const moo_ooch_t* ptr, moo_oow_t len) { if (len <= 0) return 1; - if (stix->log.len > 0 && stix->log.last_mask != mask) + if (moo->log.len > 0 && moo->log.last_mask != mask) { /* the mask has changed. commit the buffered text */ /* TODO: HANDLE LINE ENDING CONVENTION BETTER... */ - if (stix->log.ptr[stix->log.len - 1] != '\n') + if (moo->log.ptr[moo->log.len - 1] != '\n') { /* no line ending - append a line terminator */ - stix->log.ptr[stix->log.len++] = '\n'; + moo->log.ptr[moo->log.len++] = '\n'; } - stix->vmprim.log_write (stix, stix->log.last_mask, stix->log.ptr, stix->log.len); - stix->log.len = 0; + moo->vmprim.log_write (moo, moo->log.last_mask, moo->log.ptr, moo->log.len); + moo->log.len = 0; } - if (len > stix->log.capa - stix->log.len) + if (len > moo->log.capa - moo->log.len) { - stix_oow_t newcapa; - stix_ooch_t* tmp; + moo_oow_t newcapa; + moo_ooch_t* tmp; - if (len > STIX_TYPE_MAX(stix_oow_t) - stix->log.len) + if (len > MOO_TYPE_MAX(moo_oow_t) - moo->log.len) { /* data too big */ - stix->errnum = STIX_ETOOBIG; + moo->errnum = MOO_ETOOBIG; return -1; } - newcapa = STIX_ALIGN(stix->log.len + len, 512); /* TODO: adjust this capacity */ + newcapa = MOO_ALIGN(moo->log.len + len, 512); /* TODO: adjust this capacity */ /* +1 to handle line ending injection more easily */ - tmp = stix_reallocmem (stix, stix->log.ptr, (newcapa + 1) * STIX_SIZEOF(*tmp)); + tmp = moo_reallocmem (moo, moo->log.ptr, (newcapa + 1) * MOO_SIZEOF(*tmp)); if (!tmp) return -1; - stix->log.ptr = tmp; - stix->log.capa = newcapa; + moo->log.ptr = tmp; + moo->log.capa = newcapa; } - STIX_MEMCPY (&stix->log.ptr[stix->log.len], ptr, len * STIX_SIZEOF(*ptr)); - stix->log.len += len; + MOO_MEMCPY (&moo->log.ptr[moo->log.len], ptr, len * MOO_SIZEOF(*ptr)); + moo->log.len += len; - stix->log.last_mask = mask; + moo->log.last_mask = mask; return 1; /* success */ } /* ------------------------------------------------------------------------- */ -static void print_object (stix_t* stix, stix_oow_t mask, stix_oop_t oop) +static void print_object (moo_t* moo, moo_oow_t mask, moo_oop_t oop) { - if (oop == stix->_nil) + if (oop == moo->_nil) { - stix_logbfmt (stix, mask, "nil"); + moo_logbfmt (moo, mask, "nil"); } - else if (oop == stix->_true) + else if (oop == moo->_true) { - stix_logbfmt (stix, mask, "true"); + moo_logbfmt (moo, mask, "true"); } - else if (oop == stix->_false) + else if (oop == moo->_false) { - stix_logbfmt (stix, mask, "false"); + moo_logbfmt (moo, mask, "false"); } - else if (STIX_OOP_IS_SMOOI(oop)) + else if (MOO_OOP_IS_SMOOI(oop)) { - stix_logbfmt (stix, mask, "%zd", STIX_OOP_TO_SMOOI(oop)); + moo_logbfmt (moo, mask, "%zd", MOO_OOP_TO_SMOOI(oop)); } - else if (STIX_OOP_IS_CHAR(oop)) + else if (MOO_OOP_IS_CHAR(oop)) { - stix_logbfmt (stix, mask, "$%.1C", STIX_OOP_TO_CHAR(oop)); + moo_logbfmt (moo, mask, "$%.1C", MOO_OOP_TO_CHAR(oop)); } - else if (STIX_OOP_IS_ERROR(oop)) + else if (MOO_OOP_IS_ERROR(oop)) { - stix_logbfmt (stix, mask, "error(%zd)", STIX_OOP_TO_ERROR(oop)); + moo_logbfmt (moo, mask, "error(%zd)", MOO_OOP_TO_ERROR(oop)); } else { - stix_oop_class_t c; - stix_oow_t i; + moo_oop_class_t c; + moo_oow_t i; - STIX_ASSERT (stix, STIX_OOP_IS_POINTER(oop)); - c = (stix_oop_class_t)STIX_OBJ_GET_CLASS(oop); /*STIX_CLASSOF(stix, oop);*/ + MOO_ASSERT (moo, MOO_OOP_IS_POINTER(oop)); + c = (moo_oop_class_t)MOO_OBJ_GET_CLASS(oop); /*MOO_CLASSOF(moo, oop);*/ - if ((stix_oop_t)c == stix->_large_negative_integer) + if ((moo_oop_t)c == moo->_large_negative_integer) { - stix_oow_t i; - stix_logbfmt (stix, mask, "-16r"); - for (i = STIX_OBJ_GET_SIZE(oop); i > 0;) + moo_oow_t i; + moo_logbfmt (moo, mask, "-16r"); + for (i = MOO_OBJ_GET_SIZE(oop); i > 0;) { - stix_logbfmt (stix, mask, "%0*lX", (int)(STIX_SIZEOF(stix_liw_t) * 2), (unsigned long)((stix_oop_liword_t)oop)->slot[--i]); + moo_logbfmt (moo, mask, "%0*lX", (int)(MOO_SIZEOF(moo_liw_t) * 2), (unsigned long)((moo_oop_liword_t)oop)->slot[--i]); } } - else if ((stix_oop_t)c == stix->_large_positive_integer) + else if ((moo_oop_t)c == moo->_large_positive_integer) { - stix_oow_t i; - stix_logbfmt (stix, mask, "16r"); - for (i = STIX_OBJ_GET_SIZE(oop); i > 0;) + moo_oow_t i; + moo_logbfmt (moo, mask, "16r"); + for (i = MOO_OBJ_GET_SIZE(oop); i > 0;) { - stix_logbfmt (stix, mask, "%0*lX", (int)(STIX_SIZEOF(stix_liw_t) * 2), (unsigned long)((stix_oop_liword_t)oop)->slot[--i]); + moo_logbfmt (moo, mask, "%0*lX", (int)(MOO_SIZEOF(moo_liw_t) * 2), (unsigned long)((moo_oop_liword_t)oop)->slot[--i]); } } - else if (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_CHAR) + else if (MOO_OBJ_GET_FLAGS_TYPE(oop) == MOO_OBJ_TYPE_CHAR) { - if ((stix_oop_t)c == stix->_symbol) + if ((moo_oop_t)c == moo->_symbol) { - stix_logbfmt (stix, mask, "#%.*js", STIX_OBJ_GET_SIZE(oop), ((stix_oop_char_t)oop)->slot); + moo_logbfmt (moo, mask, "#%.*js", MOO_OBJ_GET_SIZE(oop), ((moo_oop_char_t)oop)->slot); } - else /*if ((stix_oop_t)c == stix->_string)*/ + else /*if ((moo_oop_t)c == moo->_string)*/ { - stix_ooch_t ch; + moo_ooch_t ch; int escape = 0; - for (i = 0; i < STIX_OBJ_GET_SIZE(oop); i++) + for (i = 0; i < MOO_OBJ_GET_SIZE(oop); i++) { - ch = ((stix_oop_char_t)oop)->slot[i]; + ch = ((moo_oop_char_t)oop)->slot[i]; if (ch < ' ') { escape = 1; @@ -369,12 +369,12 @@ static void print_object (stix_t* stix, stix_oow_t mask, stix_oop_t oop) if (escape) { - stix_ooch_t escaped; + moo_ooch_t escaped; - stix_logbfmt (stix, mask, "S'"); - for (i = 0; i < STIX_OBJ_GET_SIZE(oop); i++) + moo_logbfmt (moo, mask, "S'"); + for (i = 0; i < MOO_OBJ_GET_SIZE(oop); i++) { - ch = ((stix_oop_char_t)oop)->slot[i]; + ch = ((moo_oop_char_t)oop)->slot[i]; if (ch < ' ') { switch (ch) @@ -409,74 +409,74 @@ static void print_object (stix_t* stix, stix_oow_t mask, stix_oop_t oop) } if (escaped == ch) - stix_logbfmt (stix, mask, "\\x%X", ch); + moo_logbfmt (moo, mask, "\\x%X", ch); else - stix_logbfmt (stix, mask, "\\%jc", escaped); + moo_logbfmt (moo, mask, "\\%jc", escaped); } else { - stix_logbfmt (stix, mask, "%jc", ch); + moo_logbfmt (moo, mask, "%jc", ch); } } - stix_logbfmt (stix, mask, "'"); + moo_logbfmt (moo, mask, "'"); } else { - stix_logbfmt (stix, mask, "'%.*js'", STIX_OBJ_GET_SIZE(oop), ((stix_oop_char_t)oop)->slot); + moo_logbfmt (moo, mask, "'%.*js'", MOO_OBJ_GET_SIZE(oop), ((moo_oop_char_t)oop)->slot); } } } - else if (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_BYTE) + else if (MOO_OBJ_GET_FLAGS_TYPE(oop) == MOO_OBJ_TYPE_BYTE) { - stix_logbfmt (stix, mask, "#["); - for (i = 0; i < STIX_OBJ_GET_SIZE(oop); i++) + moo_logbfmt (moo, mask, "#["); + for (i = 0; i < MOO_OBJ_GET_SIZE(oop); i++) { - stix_logbfmt (stix, mask, " %d", ((stix_oop_byte_t)oop)->slot[i]); + moo_logbfmt (moo, mask, " %d", ((moo_oop_byte_t)oop)->slot[i]); } - stix_logbfmt (stix, mask, "]"); + moo_logbfmt (moo, mask, "]"); } - else if (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_HALFWORD) + else if (MOO_OBJ_GET_FLAGS_TYPE(oop) == MOO_OBJ_TYPE_HALFWORD) { - stix_logbfmt (stix, mask, "#[["); /* TODO: fix this symbol/notation */ - for (i = 0; i < STIX_OBJ_GET_SIZE(oop); i++) + moo_logbfmt (moo, mask, "#[["); /* TODO: fix this symbol/notation */ + for (i = 0; i < MOO_OBJ_GET_SIZE(oop); i++) { - stix_logbfmt (stix, mask, " %zX", (stix_oow_t)((stix_oop_halfword_t)oop)->slot[i]); + moo_logbfmt (moo, mask, " %zX", (moo_oow_t)((moo_oop_halfword_t)oop)->slot[i]); } - stix_logbfmt (stix, mask, "]]"); + moo_logbfmt (moo, mask, "]]"); } - else if (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_WORD) + else if (MOO_OBJ_GET_FLAGS_TYPE(oop) == MOO_OBJ_TYPE_WORD) { - stix_logbfmt (stix, mask, "#[[["); /* TODO: fix this symbol/notation */ - for (i = 0; i < STIX_OBJ_GET_SIZE(oop); i++) + moo_logbfmt (moo, mask, "#[[["); /* TODO: fix this symbol/notation */ + for (i = 0; i < MOO_OBJ_GET_SIZE(oop); i++) { - stix_logbfmt (stix, mask, " %zX", ((stix_oop_word_t)oop)->slot[i]); + moo_logbfmt (moo, mask, " %zX", ((moo_oop_word_t)oop)->slot[i]); } - stix_logbfmt (stix, mask, "]]]"); + moo_logbfmt (moo, mask, "]]]"); } - else if ((stix_oop_t)c == stix->_array) + else if ((moo_oop_t)c == moo->_array) { - stix_logbfmt (stix, mask, "#("); - for (i = 0; i < STIX_OBJ_GET_SIZE(oop); i++) + moo_logbfmt (moo, mask, "#("); + for (i = 0; i < MOO_OBJ_GET_SIZE(oop); i++) { - stix_logbfmt (stix, mask, " "); - print_object (stix, mask, ((stix_oop_oop_t)oop)->slot[i]); + moo_logbfmt (moo, mask, " "); + print_object (moo, mask, ((moo_oop_oop_t)oop)->slot[i]); } - stix_logbfmt (stix, mask, ")"); + moo_logbfmt (moo, mask, ")"); } - else if ((stix_oop_t)c == stix->_class) + else if ((moo_oop_t)c == moo->_class) { /* print the class name */ - stix_logbfmt (stix, mask, "%.*js", STIX_OBJ_GET_SIZE(((stix_oop_class_t)oop)->name), ((stix_oop_class_t)oop)->name->slot); + moo_logbfmt (moo, mask, "%.*js", MOO_OBJ_GET_SIZE(((moo_oop_class_t)oop)->name), ((moo_oop_class_t)oop)->name->slot); } - else if ((stix_oop_t)c == stix->_association) + else if ((moo_oop_t)c == moo->_association) { - stix_logbfmt (stix, mask, "%O -> %O", ((stix_oop_association_t)oop)->key, ((stix_oop_association_t)oop)->value); + moo_logbfmt (moo, mask, "%O -> %O", ((moo_oop_association_t)oop)->key, ((moo_oop_association_t)oop)->value); } else { - stix_logbfmt (stix, mask, "instance of %.*js(%p)", STIX_OBJ_GET_SIZE(c->name), ((stix_oop_char_t)c->name)->slot, oop); + moo_logbfmt (moo, mask, "instance of %.*js(%p)", MOO_OBJ_GET_SIZE(c->name), ((moo_oop_char_t)c->name)->slot, oop); } } } @@ -485,65 +485,65 @@ static void print_object (stix_t* stix, stix_oow_t mask, stix_oop_t oop) #undef fmtchar_t #undef logfmtv -#define fmtchar_t stix_bch_t +#define fmtchar_t moo_bch_t #define FMTCHAR_IS_BCH -#if defined(STIX_OOCH_IS_BCH) +#if defined(MOO_OOCH_IS_BCH) # define FMTCHAR_IS_OOCH #endif -#define logfmtv stix_logbfmtv +#define logfmtv moo_logbfmtv #include "logfmtv.h" #undef fmtchar_t #undef logfmtv -#define fmtchar_t stix_uch_t -#define logfmtv stix_logufmtv +#define fmtchar_t moo_uch_t +#define logfmtv moo_logufmtv #define FMTCHAR_IS_UCH -#if defined(STIX_OOCH_IS_UCH) +#if defined(MOO_OOCH_IS_UCH) # define FMTCHAR_IS_OOCH #endif #include "logfmtv.h" -stix_ooi_t stix_logbfmt (stix_t* stix, stix_oow_t mask, const stix_bch_t* fmt, ...) +moo_ooi_t moo_logbfmt (moo_t* moo, moo_oow_t mask, const moo_bch_t* fmt, ...) { int x; va_list ap; - stix_fmtout_t fo; + moo_fmtout_t fo; fo.mask = mask; fo.putch = put_ooch; fo.putcs = put_oocs; va_start (ap, fmt); - x = stix_logbfmtv (stix, fmt, &fo, ap); + x = moo_logbfmtv (moo, fmt, &fo, ap); va_end (ap); - if (stix->log.len > 0 && stix->log.ptr[stix->log.len - 1] == '\n') + if (moo->log.len > 0 && moo->log.ptr[moo->log.len - 1] == '\n') { - stix->vmprim.log_write (stix, stix->log.last_mask, stix->log.ptr, stix->log.len); - stix->log.len = 0; + moo->vmprim.log_write (moo, moo->log.last_mask, moo->log.ptr, moo->log.len); + moo->log.len = 0; } return (x <= -1)? -1: fo.count; } -stix_ooi_t stix_logufmt (stix_t* stix, stix_oow_t mask, const stix_uch_t* fmt, ...) +moo_ooi_t moo_logufmt (moo_t* moo, moo_oow_t mask, const moo_uch_t* fmt, ...) { int x; va_list ap; - stix_fmtout_t fo; + moo_fmtout_t fo; fo.mask = mask; fo.putch = put_ooch; fo.putcs = put_oocs; va_start (ap, fmt); - x = stix_logufmtv (stix, fmt, &fo, ap); + x = moo_logufmtv (moo, fmt, &fo, ap); va_end (ap); - if (stix->log.len > 0 && stix->log.ptr[stix->log.len - 1] == '\n') + if (moo->log.len > 0 && moo->log.ptr[moo->log.len - 1] == '\n') { - stix->vmprim.log_write (stix, stix->log.last_mask, stix->log.ptr, stix->log.len); - stix->log.len = 0; + moo->vmprim.log_write (moo, moo->log.last_mask, moo->log.ptr, moo->log.len); + moo->log.len = 0; } return (x <= -1)? -1: fo.count; diff --git a/stix/lib/logfmtv.h b/stix/lib/logfmtv.h index d2997b8..27c5c58 100644 --- a/stix/lib/logfmtv.h +++ b/stix/lib/logfmtv.h @@ -73,50 +73,50 @@ #define PUT_OOCH(c,n) do { \ int xx; \ - if ((xx = data->putch (stix, data->mask, c, n)) <= -1) goto oops; \ + if ((xx = data->putch (moo, data->mask, c, n)) <= -1) goto oops; \ if (xx == 0) goto done; \ data->count += n; \ } while (0) #define PUT_OOCS(ptr,len) do { \ int xx; \ - if ((xx = data->putcs (stix, data->mask, ptr, len)) <= -1) goto oops; \ + if ((xx = data->putcs (moo, data->mask, ptr, len)) <= -1) goto oops; \ if (xx == 0) goto done; \ data->count += len; \ } while (0) -int logfmtv (stix_t* stix, const fmtchar_t* fmt, stix_fmtout_t* data, va_list ap) +int logfmtv (moo_t* moo, const fmtchar_t* fmt, moo_fmtout_t* data, va_list ap) { const fmtchar_t* percent; #if defined(FMTCHAR_IS_OOCH) const fmtchar_t* checkpoint; #endif - stix_bch_t nbuf[MAXNBUF], bch; - const stix_bch_t* nbufp; + moo_bch_t nbuf[MAXNBUF], bch; + const moo_bch_t* nbufp; int n, base, neg, sign; - stix_ooi_t tmp, width, precision; - stix_ooch_t ch, padc; + moo_ooi_t tmp, width, precision; + moo_ooch_t ch, padc; int lm_flag, lm_dflag, flagc, numlen; - stix_uintmax_t num = 0; + moo_uintmax_t num = 0; int stop = 0; #if 0 - stix_bchbuf_t* fltfmt; - stix_oochbuf_t* fltout; + moo_bchbuf_t* fltfmt; + moo_oochbuf_t* fltout; #endif - stix_bch_t* (*sprintn) (stix_bch_t* nbuf, stix_uintmax_t num, int base, stix_ooi_t* lenp); + moo_bch_t* (*sprintn) (moo_bch_t* nbuf, moo_uintmax_t num, int base, moo_ooi_t* lenp); data->count = 0; #if 0 - fltfmt = &stix->d->fltfmt; - fltout = &stix->d->fltout; + fltfmt = &moo->d->fltfmt; + fltout = &moo->d->fltout; fltfmt->ptr = fltfmt->buf; - fltfmt->capa = STIX_COUNTOF(fltfmt->buf) - 1; + fltfmt->capa = MOO_COUNTOF(fltfmt->buf) - 1; fltout->ptr = fltout->buf; - fltout->capa = STIX_COUNTOF(fltout->buf) - 1; + fltout->capa = MOO_COUNTOF(fltout->buf) - 1; #endif while (1) @@ -200,7 +200,7 @@ reswitch: if (flagc & (FLAGC_STAR2 | FLAGC_PRECISION)) goto invalid_format; flagc |= FLAGC_STAR2; - precision = va_arg(ap, stix_ooi_t); /* this deviates from the standard printf that accepts 'int' */ + precision = va_arg(ap, moo_ooi_t); /* this deviates from the standard printf that accepts 'int' */ if (precision < 0) { /* if precision is less than 0, @@ -214,7 +214,7 @@ reswitch: if (flagc & (FLAGC_STAR1 | FLAGC_WIDTH)) goto invalid_format; flagc |= FLAGC_STAR1; - width = va_arg(ap, stix_ooi_t); /* it deviates from the standard printf that accepts 'int' */ + width = va_arg(ap, moo_ooi_t); /* it deviates from the standard printf that accepts 'int' */ if (width < 0) { /* @@ -264,8 +264,8 @@ reswitch: case 'h': /* short int */ case 'l': /* long int */ case 'q': /* long long int */ - case 'j': /* stix_intmax_t/stix_uintmax_t */ - case 'z': /* stix_ooi_t/stix_oow_t */ + case 'j': /* moo_intmax_t/moo_uintmax_t */ + case 'z': /* moo_ooi_t/moo_oow_t */ case 't': /* ptrdiff_t */ if (lm_flag & (LF_LD | LF_QD)) goto invalid_format; @@ -320,10 +320,10 @@ reswitch: case 'n': if (lm_flag & LF_J) /* j */ - *(va_arg(ap, stix_intmax_t*)) = data->count; + *(va_arg(ap, moo_intmax_t*)) = data->count; else if (lm_flag & LF_Z) /* z */ - *(va_arg(ap, stix_ooi_t*)) = data->count; - #if (STIX_SIZEOF_LONG_LONG > 0) + *(va_arg(ap, moo_ooi_t*)) = data->count; + #if (MOO_SIZEOF_LONG_LONG > 0) else if (lm_flag & LF_Q) /* ll */ *(va_arg(ap, long long int*)) = data->count; #endif @@ -335,7 +335,7 @@ reswitch: *(va_arg(ap, char*)) = data->count; else if (flagc & FLAGC_LENMOD) { - stix->errnum = STIX_EINVAL; + moo->errnum = MOO_EINVAL; goto oops; } else @@ -370,7 +370,7 @@ reswitch: if (width == 0) flagc |= FLAGC_SHARP; else flagc &= ~FLAGC_SHARP; - num = (stix_uintptr_t)va_arg(ap, void*); + num = (moo_uintptr_t)va_arg(ap, void*); goto number; case 'c': @@ -378,11 +378,11 @@ reswitch: /* zeropad must not take effect for 'c' */ if (flagc & FLAGC_ZEROPAD) padc = ' '; if (lm_flag & LF_L) goto uppercase_c; - #if defined(STIX_OOCH_IS_UCH) + #if defined(MOO_OOCH_IS_UCH) if (lm_flag & LF_J) goto uppercase_c; #endif lowercase_c: - bch = STIX_SIZEOF(stix_bch_t) < STIX_SIZEOF(int)? va_arg(ap, int): va_arg(ap, stix_bch_t); + bch = MOO_SIZEOF(moo_bch_t) < MOO_SIZEOF(int)? va_arg(ap, int): va_arg(ap, moo_bch_t); print_lowercase_c: /* precision 0 doesn't kill the letter */ @@ -395,16 +395,16 @@ reswitch: case 'C': { - stix_uch_t ooch; + moo_uch_t ooch; /* zeropad must not take effect for 'C' */ if (flagc & FLAGC_ZEROPAD) padc = ' '; if (lm_flag & LF_H) goto lowercase_c; - #if defined(STIX_OOCH_IS_BCH) + #if defined(MOO_OOCH_IS_BCH) if (lm_flag & LF_J) goto lowercase_c; #endif uppercase_c: - ooch = STIX_SIZEOF(stix_uch_t) < STIX_SIZEOF(int)? va_arg(ap, int): va_arg(ap, stix_uch_t); + ooch = MOO_SIZEOF(moo_uch_t) < MOO_SIZEOF(int)? va_arg(ap, int): va_arg(ap, moo_uch_t); /* precision 0 doesn't kill the letter */ width--; @@ -416,28 +416,28 @@ reswitch: case 's': { - const stix_bch_t* bsp; - stix_oow_t bslen, slen; + const moo_bch_t* bsp; + moo_oow_t bslen, slen; /* zeropad must not take effect for 'S' */ if (flagc & FLAGC_ZEROPAD) padc = ' '; if (lm_flag & LF_L) goto uppercase_s; - #if defined(STIX_OOCH_IS_UCH) + #if defined(MOO_OOCH_IS_UCH) if (lm_flag & LF_J) goto uppercase_s; #endif lowercase_s: - bsp = va_arg (ap, stix_bch_t*); - if (bsp == STIX_NULL) bsp = bch_nullstr; + bsp = va_arg (ap, moo_bch_t*); + if (bsp == MOO_NULL) bsp = bch_nullstr; - #if defined(STIX_OOCH_IS_UCH) + #if defined(MOO_OOCH_IS_UCH) /* get the length */ for (bslen = 0; bsp[bslen]; bslen++); - if (stix_convbtooochars (stix, bsp, &bslen, STIX_NULL, &slen) <= -1) + if (moo_convbtooochars (moo, bsp, &bslen, MOO_NULL, &slen) <= -1) { /* conversion error */ - stix->errnum = STIX_EECERR; + moo->errnum = MOO_EECERR; goto oops; } @@ -449,17 +449,17 @@ reswitch: if (!(flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width); { - stix_ooch_t conv_buf[32]; - stix_oow_t conv_len, src_len, tot_len = 0; + moo_ooch_t conv_buf[32]; + moo_oow_t conv_len, src_len, tot_len = 0; while (n > 0) { - STIX_ASSERT (stix, bslen > tot_len); + MOO_ASSERT (moo, bslen > tot_len); src_len = bslen - tot_len; - conv_len = STIX_COUNTOF(conv_buf); + conv_len = MOO_COUNTOF(conv_buf); /* this must not fail since the dry-run above was successful */ - stix_convbtooochars (stix, &bsp[tot_len], &src_len, conv_buf, &conv_len); + moo_convbtooochars (moo, &bsp[tot_len], &src_len, conv_buf, &conv_len); tot_len += src_len; if (conv_len > n) conv_len = n; @@ -491,27 +491,27 @@ reswitch: case 'S': { - const stix_uch_t* usp; - stix_oow_t uslen, slen; + const moo_uch_t* usp; + moo_oow_t uslen, slen; /* zeropad must not take effect for 's' */ if (flagc & FLAGC_ZEROPAD) padc = ' '; if (lm_flag & LF_H) goto lowercase_s; - #if defined(STIX_OOCH_IS_UCH) + #if defined(MOO_OOCH_IS_UCH) if (lm_flag & LF_J) goto lowercase_s; #endif uppercase_s: - usp = va_arg (ap, stix_uch_t*); - if (usp == STIX_NULL) usp = uch_nullstr; + usp = va_arg (ap, moo_uch_t*); + if (usp == MOO_NULL) usp = uch_nullstr; - #if defined(STIX_OOCH_IS_BCH) + #if defined(MOO_OOCH_IS_BCH) /* get the length */ for (uslen = 0; usp[uslen]; uslen++); - if (stix_convutooochars (stix, usp, &uslen, STIX_NULL, &slen) <= -1) + if (moo_convutooochars (moo, usp, &uslen, MOO_NULL, &slen) <= -1) { /* conversion error */ - stix->errnum = STIX_EECERR; + moo->errnum = MOO_EECERR; goto oops; } @@ -522,17 +522,17 @@ reswitch: if (!(flagc & FLAGC_LEFTADJ) && width > 0) PUT_OOCH (padc, width); { - stix_ooch_t conv_buf[32]; - stix_oow_t conv_len, src_len, tot_len = 0; + moo_ooch_t conv_buf[32]; + moo_oow_t conv_len, src_len, tot_len = 0; while (n > 0) { - STIX_ASSERT (stix, uslen > tot_len); + MOO_ASSERT (moo, uslen > tot_len); src_len = uslen - tot_len; - conv_len = STIX_COUNTOF(conv_buf); + conv_len = MOO_COUNTOF(conv_buf); /* this must not fail since the dry-run above was successful */ - stix_convutooochars (stix, &usp[tot_len], &src_len, conv_buf, &conv_len); + moo_convutooochars (moo, &usp[tot_len], &src_len, conv_buf, &conv_len); tot_len += src_len; if (conv_len > n) conv_len = n; @@ -562,7 +562,7 @@ reswitch: } case 'O': /* object - ignore precision, width, adjustment */ - print_object (stix, data->mask, va_arg (ap, stix_oop_t)); + print_object (moo, data->mask, va_arg (ap, moo_oop_t)); break; #if 0 @@ -579,44 +579,44 @@ reswitch: { /* let me rely on snprintf until i implement float-point to string conversion */ int q; - stix_oow_t fmtlen; - #if (STIX_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF) + moo_oow_t fmtlen; + #if (MOO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF) __float128 v_qd; #endif long double v_ld; double v_d; int dtype = 0; - stix_oow_t newcapa; + moo_oow_t newcapa; if (lm_flag & LF_J) { - #if (STIX_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF) && (STIX_SIZEOF_FLTMAX_T == STIX_SIZEOF___FLOAT128) - v_qd = va_arg (ap, stix_fltmax_t); + #if (MOO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF) && (MOO_SIZEOF_FLTMAX_T == MOO_SIZEOF___FLOAT128) + v_qd = va_arg (ap, moo_fltmax_t); dtype = LF_QD; - #elif STIX_SIZEOF_FLTMAX_T == STIX_SIZEOF_DOUBLE - v_d = va_arg (ap, stix_fltmax_t); - #elif STIX_SIZEOF_FLTMAX_T == STIX_SIZEOF_LONG_DOUBLE - v_ld = va_arg (ap, stix_fltmax_t); + #elif MOO_SIZEOF_FLTMAX_T == MOO_SIZEOF_DOUBLE + v_d = va_arg (ap, moo_fltmax_t); + #elif MOO_SIZEOF_FLTMAX_T == MOO_SIZEOF_LONG_DOUBLE + v_ld = va_arg (ap, moo_fltmax_t); dtype = LF_LD; #else - #error Unsupported stix_flt_t + #error Unsupported moo_flt_t #endif } else if (lm_flag & LF_Z) { - /* stix_flt_t is limited to double or long double */ + /* moo_flt_t is limited to double or long double */ /* precedence goes to double if sizeof(double) == sizeof(long double) * for example, %Lf didn't work on some old platforms. * so i prefer the format specifier with no modifier. */ - #if STIX_SIZEOF_FLT_T == STIX_SIZEOF_DOUBLE - v_d = va_arg (ap, stix_flt_t); - #elif STIX_SIZEOF_FLT_T == STIX_SIZEOF_LONG_DOUBLE - v_ld = va_arg (ap, stix_flt_t); + #if MOO_SIZEOF_FLT_T == MOO_SIZEOF_DOUBLE + v_d = va_arg (ap, moo_flt_t); + #elif MOO_SIZEOF_FLT_T == MOO_SIZEOF_LONG_DOUBLE + v_ld = va_arg (ap, moo_flt_t); dtype = LF_LD; #else - #error Unsupported stix_flt_t + #error Unsupported moo_flt_t #endif } else if (lm_flag & (LF_LD | LF_L)) @@ -624,7 +624,7 @@ reswitch: v_ld = va_arg (ap, long double); dtype = LF_LD; } - #if (STIX_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF) + #if (MOO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF) else if (lm_flag & (LF_QD | LF_Q)) { v_qd = va_arg (ap, __float128); @@ -633,7 +633,7 @@ reswitch: #endif else if (flagc & FLAGC_LENMOD) { - stix->errnum = STIX_EINVAL; + moo->errnum = MOO_EINVAL; goto oops; } else @@ -646,15 +646,15 @@ reswitch: { if (fltfmt->ptr == fltfmt->buf) { - fltfmt->ptr = STIX_MMGR_ALLOC (STIX_MMGR_GETDFL(), STIX_SIZEOF(*fltfmt->ptr) * (fmtlen + 1)); - if (fltfmt->ptr == STIX_NULL) goto oops; + fltfmt->ptr = MOO_MMGR_ALLOC (MOO_MMGR_GETDFL(), MOO_SIZEOF(*fltfmt->ptr) * (fmtlen + 1)); + if (fltfmt->ptr == MOO_NULL) goto oops; } else { - stix_mchar_t* tmpptr; + moo_mchar_t* tmpptr; - tmpptr = STIX_MMGR_REALLOC (STIX_MMGR_GETDFL(), fltfmt->ptr, STIX_SIZEOF(*fltfmt->ptr) * (fmtlen + 1)); - if (tmpptr == STIX_NULL) goto oops; + tmpptr = MOO_MMGR_REALLOC (MOO_MMGR_GETDFL(), fltfmt->ptr, MOO_SIZEOF(*fltfmt->ptr) * (fmtlen + 1)); + if (tmpptr == MOO_NULL) goto oops; fltfmt->ptr = tmpptr; } @@ -673,22 +673,22 @@ reswitch: if (flagc & FLAGC_STAR1) fltfmt->ptr[fmtlen++] = '*'; else if (flagc & FLAGC_WIDTH) { - fmtlen += stix_fmtuintmaxtombs ( + fmtlen += moo_fmtuintmaxtombs ( &fltfmt->ptr[fmtlen], fltfmt->capa - fmtlen, - width, 10, -1, '\0', STIX_NULL); + width, 10, -1, '\0', MOO_NULL); } if (flagc & FLAGC_DOT) fltfmt->ptr[fmtlen++] = '.'; if (flagc & FLAGC_STAR2) fltfmt->ptr[fmtlen++] = '*'; else if (flagc & FLAGC_PRECISION) { - fmtlen += stix_fmtuintmaxtombs ( + fmtlen += moo_fmtuintmaxtombs ( &fltfmt->ptr[fmtlen], fltfmt->capa - fmtlen, - precision, 10, -1, '\0', STIX_NULL); + precision, 10, -1, '\0', MOO_NULL); } if (dtype == LF_LD) fltfmt->ptr[fmtlen++] = 'L'; - #if (STIX_SIZEOF___FLOAT128 > 0) + #if (MOO_SIZEOF___FLOAT128 > 0) else if (dtype == LF_QD) fltfmt->ptr[fmtlen++] = 'Q'; #endif @@ -704,10 +704,10 @@ reswitch: newcapa = precision + width + 32; if (fltout->capa < newcapa) { - STIX_ASSERT (stix, fltout->ptr == fltout->buf); + MOO_ASSERT (moo, fltout->ptr == fltout->buf); - fltout->ptr = STIX_MMGR_ALLOC (STIX_MMGR_GETDFL(), STIX_SIZEOF(char_t) * (newcapa + 1)); - if (fltout->ptr == STIX_NULL) goto oops; + fltout->ptr = MOO_MMGR_ALLOC (MOO_MMGR_GETDFL(), MOO_SIZEOF(char_t) * (newcapa + 1)); + if (fltout->ptr == MOO_NULL) goto oops; fltout->capa = newcapa; } #endif @@ -718,23 +718,23 @@ reswitch: if (dtype == LF_LD) { #if defined(HAVE_SNPRINTF) - q = snprintf ((stix_mchar_t*)fltout->ptr, fltout->capa + 1, fltfmt->ptr, v_ld); + q = snprintf ((moo_mchar_t*)fltout->ptr, fltout->capa + 1, fltfmt->ptr, v_ld); #else - q = sprintf ((stix_mchar_t*)fltout->ptr, fltfmt->ptr, v_ld); + q = sprintf ((moo_mchar_t*)fltout->ptr, fltfmt->ptr, v_ld); #endif } - #if (STIX_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF) + #if (MOO_SIZEOF___FLOAT128 > 0) && defined(HAVE_QUADMATH_SNPRINTF) else if (dtype == LF_QD) { - q = quadmath_snprintf ((stix_mchar_t*)fltout->ptr, fltout->capa + 1, fltfmt->ptr, v_qd); + q = quadmath_snprintf ((moo_mchar_t*)fltout->ptr, fltout->capa + 1, fltfmt->ptr, v_qd); } #endif else { #if defined(HAVE_SNPRINTF) - q = snprintf ((stix_mchar_t*)fltout->ptr, fltout->capa + 1, fltfmt->ptr, v_d); + q = snprintf ((moo_mchar_t*)fltout->ptr, fltout->capa + 1, fltfmt->ptr, v_d); #else - q = sprintf ((stix_mchar_t*)fltout->ptr, fltfmt->ptr, v_d); + q = sprintf ((moo_mchar_t*)fltout->ptr, fltfmt->ptr, v_d); #endif } if (q <= -1) goto oops; @@ -745,27 +745,27 @@ reswitch: if (fltout->ptr == fltout->sbuf) { - fltout->ptr = STIX_MMGR_ALLOC (STIX_MMGR_GETDFL(), STIX_SIZEOF(char_t) * (newcapa + 1)); - if (fltout->ptr == STIX_NULL) goto oops; + fltout->ptr = MOO_MMGR_ALLOC (MOO_MMGR_GETDFL(), MOO_SIZEOF(char_t) * (newcapa + 1)); + if (fltout->ptr == MOO_NULL) goto oops; } else { char_t* tmpptr; - tmpptr = STIX_MMGR_REALLOC (STIX_MMGR_GETDFL(), fltout->ptr, STIX_SIZEOF(char_t) * (newcapa + 1)); - if (tmpptr == STIX_NULL) goto oops; + tmpptr = MOO_MMGR_REALLOC (MOO_MMGR_GETDFL(), fltout->ptr, MOO_SIZEOF(char_t) * (newcapa + 1)); + if (tmpptr == MOO_NULL) goto oops; fltout->ptr = tmpptr; } fltout->capa = newcapa; } - if (STIX_SIZEOF(char_t) != STIX_SIZEOF(stix_mchar_t)) + if (MOO_SIZEOF(char_t) != MOO_SIZEOF(moo_mchar_t)) { fltout->ptr[q] = '\0'; while (q > 0) { q--; - fltout->ptr[q] = ((stix_mchar_t*)fltout->ptr)[q]; + fltout->ptr[q] = ((moo_mchar_t*)fltout->ptr)[q]; } } @@ -783,33 +783,33 @@ handle_nosign: if (lm_flag & LF_J) { #if defined(__GNUC__) && \ - (STIX_SIZEOF_UINTMAX_T > STIX_SIZEOF_OOW_T) && \ - (STIX_SIZEOF_UINTMAX_T != STIX_SIZEOF_LONG_LONG) && \ - (STIX_SIZEOF_UINTMAX_T != STIX_SIZEOF_LONG) - /* GCC-compiled binaries crashed when getting stix_uintmax_t with va_arg. + (MOO_SIZEOF_UINTMAX_T > MOO_SIZEOF_OOW_T) && \ + (MOO_SIZEOF_UINTMAX_T != MOO_SIZEOF_LONG_LONG) && \ + (MOO_SIZEOF_UINTMAX_T != MOO_SIZEOF_LONG) + /* GCC-compiled binaries crashed when getting moo_uintmax_t with va_arg. * This is just a work-around for it */ int i; - for (i = 0, num = 0; i < STIX_SIZEOF(stix_uintmax_t) / STIX_SIZEOF(stix_oow_t); i++) + for (i = 0, num = 0; i < MOO_SIZEOF(moo_uintmax_t) / MOO_SIZEOF(moo_oow_t); i++) { - #if defined(STIX_ENDIAN_BIG) - num = num << (8 * STIX_SIZEOF(stix_oow_t)) | (va_arg (ap, stix_oow_t)); + #if defined(MOO_ENDIAN_BIG) + num = num << (8 * MOO_SIZEOF(moo_oow_t)) | (va_arg (ap, moo_oow_t)); #else - register int shift = i * STIX_SIZEOF(stix_oow_t); - stix_oow_t x = va_arg (ap, stix_oow_t); - num |= (stix_uintmax_t)x << (shift * 8); + register int shift = i * MOO_SIZEOF(moo_oow_t); + moo_oow_t x = va_arg (ap, moo_oow_t); + num |= (moo_uintmax_t)x << (shift * 8); #endif } #else - num = va_arg (ap, stix_uintmax_t); + num = va_arg (ap, moo_uintmax_t); #endif } #if 0 else if (lm_flag & LF_T) - num = va_arg (ap, stix_ptrdiff_t); + num = va_arg (ap, moo_ptrdiff_t); #endif else if (lm_flag & LF_Z) - num = va_arg (ap, stix_oow_t); - #if (STIX_SIZEOF_LONG_LONG > 0) + num = va_arg (ap, moo_oow_t); + #if (MOO_SIZEOF_LONG_LONG > 0) else if (lm_flag & LF_Q) num = va_arg (ap, unsigned long long int); #endif @@ -827,34 +827,34 @@ handle_sign: if (lm_flag & LF_J) { #if defined(__GNUC__) && \ - (STIX_SIZEOF_INTMAX_T > STIX_SIZEOF_OOI_T) && \ - (STIX_SIZEOF_UINTMAX_T != STIX_SIZEOF_LONG_LONG) && \ - (STIX_SIZEOF_UINTMAX_T != STIX_SIZEOF_LONG) - /* GCC-compiled binraries crashed when getting stix_uintmax_t with va_arg. + (MOO_SIZEOF_INTMAX_T > MOO_SIZEOF_OOI_T) && \ + (MOO_SIZEOF_UINTMAX_T != MOO_SIZEOF_LONG_LONG) && \ + (MOO_SIZEOF_UINTMAX_T != MOO_SIZEOF_LONG) + /* GCC-compiled binraries crashed when getting moo_uintmax_t with va_arg. * This is just a work-around for it */ int i; - for (i = 0, num = 0; i < STIX_SIZEOF(stix_intmax_t) / STIX_SIZEOF(stix_oow_t); i++) + for (i = 0, num = 0; i < MOO_SIZEOF(moo_intmax_t) / MOO_SIZEOF(moo_oow_t); i++) { - #if defined(STIX_ENDIAN_BIG) - num = num << (8 * STIX_SIZEOF(stix_oow_t)) | (va_arg (ap, stix_oow_t)); + #if defined(MOO_ENDIAN_BIG) + num = num << (8 * MOO_SIZEOF(moo_oow_t)) | (va_arg (ap, moo_oow_t)); #else - register int shift = i * STIX_SIZEOF(stix_oow_t); - stix_oow_t x = va_arg (ap, stix_oow_t); - num |= (stix_uintmax_t)x << (shift * 8); + register int shift = i * MOO_SIZEOF(moo_oow_t); + moo_oow_t x = va_arg (ap, moo_oow_t); + num |= (moo_uintmax_t)x << (shift * 8); #endif } #else - num = va_arg (ap, stix_intmax_t); + num = va_arg (ap, moo_intmax_t); #endif } #if 0 else if (lm_flag & LF_T) - num = va_arg(ap, stix_ptrdiff_t); + num = va_arg(ap, moo_ptrdiff_t); #endif else if (lm_flag & LF_Z) - num = va_arg (ap, stix_ooi_t); - #if (STIX_SIZEOF_LONG_LONG > 0) + num = va_arg (ap, moo_ooi_t); + #if (MOO_SIZEOF_LONG_LONG > 0) else if (lm_flag & LF_Q) num = va_arg (ap, long long int); #endif @@ -868,10 +868,10 @@ handle_sign: num = va_arg (ap, int); number: - if (sign && (stix_intmax_t)num < 0) + if (sign && (moo_intmax_t)num < 0) { neg = 1; - num = -(stix_intmax_t)num; + num = -(moo_intmax_t)num; } nbufp = sprintn (nbuf, num, base, &tmp); @@ -884,7 +884,7 @@ number: else if (flagc & FLAGC_SIGN) tmp++; else if (flagc & FLAGC_SPACE) tmp++; - numlen = (int)((const stix_bch_t*)nbufp - (const stix_bch_t*)nbuf); + numlen = (int)((const moo_bch_t*)nbufp - (const moo_bch_t*)nbuf); if ((flagc & FLAGC_DOT) && precision > numlen) { /* extra zeros for precision specified */ diff --git a/stix/lib/main.c b/stix/lib/main.c index 4f5b24a..b1a1908 100644 --- a/stix/lib/main.c +++ b/stix/lib/main.c @@ -24,7 +24,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "stix-prv.h" +#include "moo-prv.h" #include #include @@ -36,7 +36,7 @@ #if defined(_WIN32) # include # include -# if defined(STIX_HAVE_CFG_H) +# if defined(MOO_HAVE_CFG_H) # include # define USE_LTDL # endif @@ -65,27 +65,27 @@ # endif #endif -#if !defined(STIX_DEFAULT_MODPREFIX) +#if !defined(MOO_DEFAULT_MODPREFIX) # if defined(_WIN32) -# define STIX_DEFAULT_MODPREFIX "stix-" +# define MOO_DEFAULT_MODPREFIX "moo-" # elif defined(__OS2__) -# define STIX_DEFAULT_MODPREFIX "st-" +# define MOO_DEFAULT_MODPREFIX "st-" # elif defined(__MSDOS__) -# define STIX_DEFAULT_MODPREFIX "st-" +# define MOO_DEFAULT_MODPREFIX "st-" # else -# define STIX_DEFAULT_MODPREFIX "libstix-" +# define MOO_DEFAULT_MODPREFIX "libmoo-" # endif #endif -#if !defined(STIX_DEFAULT_MODPOSTFIX) +#if !defined(MOO_DEFAULT_MODPOSTFIX) # if defined(_WIN32) -# define STIX_DEFAULT_MODPOSTFIX "" +# define MOO_DEFAULT_MODPOSTFIX "" # elif defined(__OS2__) -# define STIX_DEFAULT_MODPOSTFIX "" +# define MOO_DEFAULT_MODPOSTFIX "" # elif defined(__MSDOS__) -# define STIX_DEFAULT_MODPOSTFIX "" +# define MOO_DEFAULT_MODPOSTFIX "" # else -# define STIX_DEFAULT_MODPOSTFIX "" +# define MOO_DEFAULT_MODPOSTFIX "" # endif #endif @@ -93,8 +93,8 @@ typedef struct bb_t bb_t; struct bb_t { char buf[1024]; - stix_oow_t pos; - stix_oow_t len; + moo_oow_t pos; + moo_oow_t len; FILE* fp; }; @@ -106,27 +106,27 @@ struct xtn_t /* ========================================================================= */ -static void* sys_alloc (stix_mmgr_t* mmgr, stix_oow_t size) +static void* sys_alloc (moo_mmgr_t* mmgr, moo_oow_t size) { return malloc (size); } -static void* sys_realloc (stix_mmgr_t* mmgr, void* ptr, stix_oow_t size) +static void* sys_realloc (moo_mmgr_t* mmgr, void* ptr, moo_oow_t size) { return realloc (ptr, size); } -static void sys_free (stix_mmgr_t* mmgr, void* ptr) +static void sys_free (moo_mmgr_t* mmgr, void* ptr) { free (ptr); } -static stix_mmgr_t sys_mmgr = +static moo_mmgr_t sys_mmgr = { sys_alloc, sys_realloc, sys_free, - STIX_NULL + MOO_NULL }; /* ========================================================================= */ @@ -138,21 +138,21 @@ static stix_mmgr_t sys_mmgr = #endif -static const stix_bch_t* get_base_name (const stix_bch_t* path) +static const moo_bch_t* get_base_name (const moo_bch_t* path) { - const stix_bch_t* p, * last = STIX_NULL; + const moo_bch_t* p, * last = MOO_NULL; for (p = path; *p != '\0'; p++) { if (IS_PATH_SEP(*p)) last = p; } - return (last == STIX_NULL)? path: (last + 1); + return (last == MOO_NULL)? path: (last + 1); } -static STIX_INLINE stix_ooi_t open_input (stix_t* stix, stix_ioarg_t* arg) +static MOO_INLINE moo_ooi_t open_input (moo_t* moo, moo_ioarg_t* arg) { - xtn_t* xtn = stix_getxtn(stix); + xtn_t* xtn = moo_getxtn(moo); bb_t* bb; FILE* fp; @@ -160,13 +160,13 @@ static STIX_INLINE stix_ooi_t open_input (stix_t* stix, stix_ioarg_t* arg) { /* includee */ - stix_bch_t bcs[1024]; /* TODO: right buffer size */ - stix_oow_t bcslen = STIX_COUNTOF(bcs); - stix_oow_t ucslen; + moo_bch_t bcs[1024]; /* TODO: right buffer size */ + moo_oow_t bcslen = MOO_COUNTOF(bcs); + moo_oow_t ucslen; - if (stix_convootobcstr (stix, arg->name, &ucslen, bcs, &bcslen) <= -1) + if (moo_convootobcstr (moo, arg->name, &ucslen, bcs, &bcslen) <= -1) { - stix_seterrnum (stix, STIX_EECERR); + moo_seterrnum (moo, MOO_EECERR); return -1; } @@ -190,11 +190,11 @@ static STIX_INLINE stix_ooi_t open_input (stix_t* stix, stix_ioarg_t* arg) if (!fp) { - stix_seterrnum (stix, STIX_EIOERR); + moo_seterrnum (moo, MOO_EIOERR); return -1; } - bb = stix_callocmem (stix, STIX_SIZEOF(*bb)); + bb = moo_callocmem (moo, MOO_SIZEOF(*bb)); if (!bb) { fclose (fp); @@ -206,32 +206,32 @@ static STIX_INLINE stix_ooi_t open_input (stix_t* stix, stix_ioarg_t* arg) return 0; } -static STIX_INLINE stix_ooi_t close_input (stix_t* stix, stix_ioarg_t* arg) +static MOO_INLINE moo_ooi_t close_input (moo_t* moo, moo_ioarg_t* arg) { - xtn_t* xtn = stix_getxtn(stix); + xtn_t* xtn = moo_getxtn(moo); bb_t* bb; bb = (bb_t*)arg->handle; - STIX_ASSERT (stix, bb != STIX_NULL && bb->fp != STIX_NULL); + MOO_ASSERT (moo, bb != MOO_NULL && bb->fp != MOO_NULL); fclose (bb->fp); - stix_freemem (stix, bb); + moo_freemem (moo, bb); - arg->handle = STIX_NULL; + arg->handle = MOO_NULL; return 0; } -static STIX_INLINE stix_ooi_t read_input (stix_t* stix, stix_ioarg_t* arg) +static MOO_INLINE moo_ooi_t read_input (moo_t* moo, moo_ioarg_t* arg) { /*xtn_t* xtn = hcl_getxtn(hcl);*/ bb_t* bb; - stix_oow_t bcslen, ucslen, remlen; + moo_oow_t bcslen, ucslen, remlen; int x; bb = (bb_t*)arg->handle; - STIX_ASSERT (stix, bb != STIX_NULL && bb->fp != STIX_NULL); + MOO_ASSERT (moo, bb != MOO_NULL && bb->fp != MOO_NULL); do { x = fgetc (bb->fp); @@ -239,7 +239,7 @@ static STIX_INLINE stix_ooi_t read_input (stix_t* stix, stix_ioarg_t* arg) { if (ferror((FILE*)bb->fp)) { - stix_seterrnum (stix, STIX_EIOERR); + moo_seterrnum (moo, MOO_EIOERR); return -1; } break; @@ -247,15 +247,15 @@ static STIX_INLINE stix_ooi_t read_input (stix_t* stix, stix_ioarg_t* arg) bb->buf[bb->len++] = x; } - while (bb->len < STIX_COUNTOF(bb->buf) && x != '\r' && x != '\n'); + while (bb->len < MOO_COUNTOF(bb->buf) && x != '\r' && x != '\n'); bcslen = bb->len; - ucslen = STIX_COUNTOF(arg->buf); - x = stix_convbtooochars (stix, bb->buf, &bcslen, arg->buf, &ucslen); - x = stix_convbtooochars (stix, bb->buf, &bcslen, arg->buf, &ucslen); + ucslen = MOO_COUNTOF(arg->buf); + x = moo_convbtooochars (moo, bb->buf, &bcslen, arg->buf, &ucslen); + x = moo_convbtooochars (moo, bb->buf, &bcslen, arg->buf, &ucslen); if (x <= -1 && ucslen <= 0) { - stix_seterrnum (stix, STIX_EECERR); + moo_seterrnum (moo, MOO_EECERR); return -1; } @@ -265,76 +265,76 @@ static STIX_INLINE stix_ooi_t read_input (stix_t* stix, stix_ioarg_t* arg) return ucslen; } -static stix_ooi_t input_handler (stix_t* stix, stix_iocmd_t cmd, stix_ioarg_t* arg) +static moo_ooi_t input_handler (moo_t* moo, moo_iocmd_t cmd, moo_ioarg_t* arg) { switch (cmd) { - case STIX_IO_OPEN: - return open_input (stix, arg); + case MOO_IO_OPEN: + return open_input (moo, arg); - case STIX_IO_CLOSE: - return close_input (stix, arg); + case MOO_IO_CLOSE: + return close_input (moo, arg); - case STIX_IO_READ: - return read_input (stix, arg); + case MOO_IO_READ: + return read_input (moo, arg); default: - stix->errnum = STIX_EINTERN; + moo->errnum = MOO_EINTERN; return -1; } } /* ========================================================================= */ -static void* dl_open (stix_t* stix, const stix_ooch_t* name) +static void* dl_open (moo_t* moo, const moo_ooch_t* name) { #if defined(USE_LTDL) /* TODO: support various platforms */ - stix_bch_t buf[1024]; /* TODO: use a proper path buffer */ - stix_oow_t ucslen, bcslen; - stix_oow_t len; + moo_bch_t buf[1024]; /* TODO: use a proper path buffer */ + moo_oow_t ucslen, bcslen; + moo_oow_t len; void* handle; /* TODO: using MODPREFIX isn't a good idea 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. + * Attempting /home/hyung-hwan/xxx/lib/libmoo-libc.so.6 followed by libc.so.6 is bad. * Need to accept the type or flags? * - * dl_open (stix, "xxxx", STIX_MOD_EXTERNAL); + * dl_open (moo, "xxxx", MOO_MOD_EXTERNAL); * if external, don't use DEFAULT_MODPERFIX and MODPOSTFIX??? */ - len = stix_copybcstr (buf, STIX_COUNTOF(buf), STIX_DEFAULT_MODPREFIX); + len = moo_copybcstr (buf, MOO_COUNTOF(buf), MOO_DEFAULT_MODPREFIX); /* TODO: proper error checking and overflow checking */ - bcslen = STIX_COUNTOF(buf) - len; - stix_convootobcstr (stix, name, &ucslen, &buf[len], &bcslen); + bcslen = MOO_COUNTOF(buf) - len; + moo_convootobcstr (moo, name, &ucslen, &buf[len], &bcslen); - stix_copybcstr (&buf[bcslen + len], STIX_COUNTOF(buf) - bcslen - len, STIX_DEFAULT_MODPOSTFIX); + moo_copybcstr (&buf[bcslen + len], MOO_COUNTOF(buf) - bcslen - len, MOO_DEFAULT_MODPOSTFIX); handle = lt_dlopenext (buf); if (!handle) { buf[bcslen + len] = '\0'; handle = lt_dlopenext (&buf[len]); - if (handle) STIX_DEBUG2 (stix, "Opened module file %s handle %p\n", &buf[len], handle); + if (handle) MOO_DEBUG2 (moo, "Opened module file %s handle %p\n", &buf[len], handle); } else { - STIX_DEBUG2 (stix, "Opened module file %s handle %p\n", buf, handle); + MOO_DEBUG2 (moo, "Opened module file %s handle %p\n", buf, handle); } return handle; #else /* TODO: implemenent this */ - return STIX_NULL; + return MOO_NULL; #endif } -static void dl_close (stix_t* stix, void* handle) +static void dl_close (moo_t* moo, void* handle) { - STIX_DEBUG1 (stix, "Closed module handle %p\n", handle); + MOO_DEBUG1 (moo, "Closed module handle %p\n", handle); #if defined(USE_LTDL) lt_dlclose (handle); #elif defined(_WIN32) @@ -348,18 +348,18 @@ static void dl_close (stix_t* stix, void* handle) #endif } -static void* dl_getsym (stix_t* stix, void* handle, const stix_ooch_t* name) +static void* dl_getsym (moo_t* moo, void* handle, const moo_ooch_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_oow_t ucslen, bcslen; + moo_bch_t buf[1024]; /* TODO: use a proper buffer. dynamically allocated if conversion result in too a large value */ + moo_oow_t ucslen, bcslen; void* sym; const char* symname; buf[0] = '_'; - bcslen = STIX_COUNTOF(buf) - 2; - stix_convootobcstr (stix, name, &ucslen, &buf[1], &bcslen); /* TODO: error check */ + bcslen = MOO_COUNTOF(buf) - 2; + moo_convootobcstr (moo, name, &ucslen, &buf[1], &bcslen); /* TODO: error check */ symname = &buf[1]; sym = lt_dlsym (handle, symname); if (!sym) @@ -381,21 +381,21 @@ static void* dl_getsym (stix_t* stix, void* handle, const stix_ooch_t* name) } } - if (sym) STIX_DEBUG2 (stix, "Loaded module symbol %s from handle %p\n", symname, handle); + if (sym) MOO_DEBUG2 (moo, "Loaded module symbol %s from handle %p\n", symname, handle); return sym; #else /* TODO: IMPLEMENT THIS */ - return STIX_NULL; + return MOO_NULL; #endif } /* ========================================================================= */ -static int write_all (int fd, const char* ptr, stix_oow_t len) +static int write_all (int fd, const char* ptr, moo_oow_t len) { while (len > 0) { - stix_ooi_t wr; + moo_ooi_t wr; wr = write (1, ptr, len); @@ -415,21 +415,21 @@ static int write_all (int fd, const char* ptr, stix_oow_t len) return 0; } -static void log_write (stix_t* stix, stix_oow_t mask, const stix_ooch_t* msg, stix_oow_t len) +static void log_write (moo_t* moo, moo_oow_t mask, const moo_ooch_t* msg, moo_oow_t len) { #if defined(_WIN32) # error NOT IMPLEMENTED #else - stix_bch_t buf[256]; - stix_oow_t ucslen, bcslen, msgidx; + moo_bch_t buf[256]; + moo_oow_t ucslen, bcslen, msgidx; int n; char ts[32]; size_t tslen; struct tm tm, *tmp; time_t now; -if (mask & STIX_LOG_GC) return; /* don't show gc logs */ +if (mask & MOO_LOG_GC) return; /* don't show gc logs */ /* TODO: beautify the log message. * do classification based on mask. */ @@ -452,9 +452,9 @@ if (mask & STIX_LOG_GC) return; /* don't show gc logs */ while (len > 0) { ucslen = len; - bcslen = STIX_COUNTOF(buf); + bcslen = MOO_COUNTOF(buf); - n = stix_convootobchars (stix, &msg[msgidx], &ucslen, buf, &bcslen); + n = moo_convootobchars (moo, &msg[msgidx], &ucslen, buf, &bcslen); if (n == 0 || n == -2) { /* n = 0: @@ -463,7 +463,7 @@ if (mask & STIX_LOG_GC) return; /* don't show gc logs */ * buffer not sufficient. not all got converted yet. * write what have been converted this round. */ - STIX_ASSERT (stix, ucslen > 0); /* if this fails, the buffer size must be increased */ + MOO_ASSERT (moo, ucslen > 0); /* if this fails, the buffer size must be increased */ /* attempt to write all converted characters */ if (write_all (1, buf, bcslen) <= -1) break; @@ -486,9 +486,9 @@ if (mask & STIX_LOG_GC) return; /* don't show gc logs */ /* ========================================================================= */ -static stix_ooch_t str_my_object[] = { 'M', 'y', 'O', 'b','j','e','c','t' }; -static stix_ooch_t str_main[] = { 'm', 'a', 'i', 'n' }; -static stix_t* g_stix = STIX_NULL; +static moo_ooch_t str_my_object[] = { 'M', 'y', 'O', 'b','j','e','c','t' }; +static moo_ooch_t str_main[] = { 'm', 'a', 'i', 'n' }; +static moo_t* g_moo = MOO_NULL; /* ========================================================================= */ @@ -507,7 +507,7 @@ static void timer_intr_handler (void) */ /* The timer interrupt (normally) occurs 18.2 times per second. */ - if (g_stix) stix_switchprocess (g_stix); + if (g_moo) moo_switchprocess (g_moo); _chain_intr(prev_timer_intr_handler); } @@ -520,7 +520,7 @@ static ProcessSerialNumber g_psn; static pascal void timer_intr_handler (TMTask* task) { - if (g_stix) stix_switchprocess (g_stix); + if (g_moo) moo_switchprocess (g_moo); WakeUpProcess (&g_psn); PrimeTime ((QElem*)&g_tmtask, TMTASK_DELAY); } @@ -528,7 +528,7 @@ static pascal void timer_intr_handler (TMTask* task) #else static void arrange_process_switching (int sig) { - if (g_stix) stix_switchprocess (g_stix); + if (g_moo) moo_switchprocess (g_moo); } #endif @@ -542,7 +542,7 @@ static void setup_tick (void) #elif defined(macintosh) GetCurrentProcess (&g_psn); - memset (&g_tmtask, 0, STIX_SIZEOF(g_tmtask)); + memset (&g_tmtask, 0, MOO_SIZEOF(g_tmtask)); g_tmtask.tmAddr = NewTimerProc (timer_intr_handler); InsXTime ((QElem*)&g_tmtask); @@ -555,13 +555,13 @@ static void setup_tick (void) sigemptyset (&act.sa_mask); act.sa_handler = arrange_process_switching; act.sa_flags = 0; - sigaction (SIGVTALRM, &act, STIX_NULL); + sigaction (SIGVTALRM, &act, MOO_NULL); itv.it_interval.tv_sec = 0; itv.it_interval.tv_usec = 100; /* 100 microseconds */ itv.it_value.tv_sec = 0; itv.it_value.tv_usec = 100; - setitimer (ITIMER_VIRTUAL, &itv, STIX_NULL); + setitimer (ITIMER_VIRTUAL, &itv, MOO_NULL); #else # error UNSUPPORTED @@ -586,12 +586,12 @@ static void cancel_tick (void) itv.it_interval.tv_usec = 0; itv.it_value.tv_sec = 0; /* make setitimer() one-shot only */ itv.it_value.tv_usec = 0; - setitimer (ITIMER_VIRTUAL, &itv, STIX_NULL); + setitimer (ITIMER_VIRTUAL, &itv, MOO_NULL); sigemptyset (&act.sa_mask); act.sa_handler = SIG_IGN; /* ignore the signal potentially fired by the one-shot arrange above */ act.sa_flags = 0; - sigaction (SIGVTALRM, &act, STIX_NULL); + sigaction (SIGVTALRM, &act, MOO_NULL); #else # error UNSUPPORTED @@ -602,11 +602,11 @@ static void cancel_tick (void) int main (int argc, char* argv[]) { - stix_t* stix; + moo_t* moo; xtn_t* xtn; - stix_oocs_t objname; - stix_oocs_t mthname; - stix_vmprim_t vmprim; + moo_oocs_t objname; + moo_oocs_t mthname; + moo_vmprim_t vmprim; int i, xret; #if !defined(macintosh) @@ -627,40 +627,40 @@ int main (int argc, char* argv[]) lt_dlinit (); #endif - stix = stix_open (&sys_mmgr, STIX_SIZEOF(xtn_t), 2048000lu, &vmprim, STIX_NULL); - if (!stix) + moo = moo_open (&sys_mmgr, MOO_SIZEOF(xtn_t), 2048000lu, &vmprim, MOO_NULL); + if (!moo) { - printf ("cannot open stix\n"); + printf ("cannot open moo\n"); return -1; } { - stix_oow_t tab_size; + moo_oow_t tab_size; tab_size = 5000; - stix_setoption (stix, STIX_SYMTAB_SIZE, &tab_size); + moo_setoption (moo, MOO_SYMTAB_SIZE, &tab_size); tab_size = 5000; - stix_setoption (stix, STIX_SYSDIC_SIZE, &tab_size); + moo_setoption (moo, MOO_SYSDIC_SIZE, &tab_size); tab_size = 600; - stix_setoption (stix, STIX_PROCSTK_SIZE, &tab_size); + moo_setoption (moo, MOO_PROCSTK_SIZE, &tab_size); } { int trait = 0; - /*trait |= STIX_NOGC;*/ - trait |= STIX_AWAIT_PROCS; - stix_setoption (stix, STIX_TRAIT, &trait); + /*trait |= MOO_NOGC;*/ + trait |= MOO_AWAIT_PROCS; + moo_setoption (moo, MOO_TRAIT, &trait); } - if (stix_ignite(stix) <= -1) + if (moo_ignite(moo) <= -1) { - printf ("cannot ignite stix - %d\n", stix_geterrnum(stix)); - stix_close (stix); + printf ("cannot ignite moo - %d\n", moo_geterrnum(moo)); + moo_close (moo); return -1; } - xtn = stix_getxtn (stix); + xtn = moo_getxtn (moo); #if defined(macintosh) i = 20; @@ -674,21 +674,21 @@ int main (int argc, char* argv[]) compile: - if (stix_compile (stix, input_handler) <= -1) + if (moo_compile (moo, input_handler) <= -1) { - if (stix->errnum == STIX_ESYNTAX) + if (moo->errnum == MOO_ESYNTAX) { - stix_synerr_t synerr; - stix_bch_t bcs[1024]; /* TODO: right buffer size */ - stix_oow_t bcslen, ucslen; + moo_synerr_t synerr; + moo_bch_t bcs[1024]; /* TODO: right buffer size */ + moo_oow_t bcslen, ucslen; - stix_getsynerr (stix, &synerr); + moo_getsynerr (moo, &synerr); printf ("ERROR: "); if (synerr.loc.file) { - bcslen = STIX_COUNTOF(bcs); - if (stix_convootobcstr (stix, synerr.loc.file, &ucslen, bcs, &bcslen) >= 0) + bcslen = MOO_COUNTOF(bcs); + if (moo_convootobcstr (moo, synerr.loc.file, &ucslen, bcs, &bcslen) >= 0) { printf ("%.*s ", (int)bcslen, bcs); } @@ -702,18 +702,18 @@ int main (int argc, char* argv[]) printf ("syntax error at line %lu column %lu - ", (unsigned long int)synerr.loc.line, (unsigned long int)synerr.loc.colm); - bcslen = STIX_COUNTOF(bcs); - if (stix_convootobcstr (stix, stix_synerrnumtoerrstr(synerr.num), &ucslen, bcs, &bcslen) >= 0) + bcslen = MOO_COUNTOF(bcs); + if (moo_convootobcstr (moo, moo_synerrnumtoerrstr(synerr.num), &ucslen, bcs, &bcslen) >= 0) { printf (" [%.*s]", (int)bcslen, bcs); } if (synerr.tgt.len > 0) { - bcslen = STIX_COUNTOF(bcs); + bcslen = MOO_COUNTOF(bcs); ucslen = synerr.tgt.len; - if (stix_convootobchars (stix, synerr.tgt.ptr, &ucslen, bcs, &bcslen) >= 0) + if (moo_convootobchars (moo, synerr.tgt.ptr, &ucslen, bcs, &bcslen) >= 0) { printf (" [%.*s]", (int)bcslen, bcs); } @@ -723,9 +723,9 @@ int main (int argc, char* argv[]) } else { - printf ("ERROR: cannot compile code - %d\n", stix_geterrnum(stix)); + printf ("ERROR: cannot compile code - %d\n", moo_geterrnum(moo)); } - stix_close (stix); + moo_close (moo); #if defined(USE_LTDL) lt_dlexit (); #endif @@ -735,26 +735,26 @@ int main (int argc, char* argv[]) printf ("COMPILE OK. STARTING EXECUTION ...\n"); xret = 0; - g_stix = stix; + g_moo = moo; setup_tick (); objname.ptr = str_my_object; objname.len = 8; mthname.ptr = str_main; mthname.len = 4; - if (stix_invoke (stix, &objname, &mthname) <= -1) + if (moo_invoke (moo, &objname, &mthname) <= -1) { - printf ("ERROR: cannot execute code - %d\n", stix_geterrnum(stix)); + printf ("ERROR: cannot execute code - %d\n", moo_geterrnum(moo)); xret = -1; } cancel_tick (); - g_stix = STIX_NULL; + g_moo = MOO_NULL; - /*stix_dumpsymtab(stix); - *stix_dumpdic(stix, stix->sysdic, "System dictionary");*/ + /*moo_dumpsymtab(moo); + *moo_dumpdic(moo, moo->sysdic, "System dictionary");*/ - stix_close (stix); + moo_close (moo); #if defined(USE_LTDL) lt_dlexit (); diff --git a/stix/lib/memo.txt b/stix/lib/memo.txt index ea28c37..098ec64 100644 --- a/stix/lib/memo.txt +++ b/stix/lib/memo.txt @@ -4,7 +4,7 @@ * How to embed in a single threaded web server * * -* stix_exec +* moo_exec * VM(shceduler) ---> Context1(obj1,method1) * ---> Context2(obj2,method2) * ---> Context3(obj3,method3) @@ -76,7 +76,7 @@ in original smalltalk, a block can't be placed inside the array literal array := "(" { number | string | symbol | array | characterConstant }* ")". So #(1 2 [^20]) is illegal. -if a block is there, treat it as a valid stix expression and evaluate it. +if a block is there, treat it as a valid moo expression and evaluate it. #(1 2 [1 + 2] 5) t = Array new: 4. @@ -92,19 +92,19 @@ Put the right element. ----------------------------------------------- command line -libstix.a +libmoo.a -stix stix.im Class1.st Class2.st Main.st Main +moo moo.im Class1.st Class2.st Main.st Main --> load the image, compile Class1.st, compile Class2.st compile Main.st --> -stix stix.im +moo moo.im --> load the image ------------------------------------------------------------------------- -#!/usr/bin/stix +#!/usr/bin/moo ################################### ## Main.st diff --git a/stix/lib/stix-cfg.h.in b/stix/lib/moo-cfg.h.in similarity index 92% rename from stix/lib/stix-cfg.h.in rename to stix/lib/moo-cfg.h.in index a8067b7..bc55f03 100644 --- a/stix/lib/stix-cfg.h.in +++ b/stix/lib/moo-cfg.h.in @@ -1,4 +1,4 @@ -/* lib/stix-cfg.h.in. Generated from configure.ac by autoheader. */ +/* lib/moo-cfg.h.in. Generated from configure.ac by autoheader. */ /* Define if building universal (internal helper macro) */ #undef AC_APPLE_UNIVERSAL_BUILD @@ -315,6 +315,105 @@ /* Define to the shared library suffix, say, ".dylib". */ #undef LT_SHARED_EXT +/* link modules statically into the main library */ +#undef MOO_ENABLE_STATIC_MODULE + +/* Big Endian */ +#undef MOO_ENDIAN_BIG + +/* Little Endian */ +#undef MOO_ENDIAN_LITTLE + +/* Unknown Endian */ +#undef MOO_ENDIAN_UNKNOWN + +/* MB_LEN_MAX */ +#undef MOO_MBLEN_MAX + +/* Author */ +#undef MOO_PACKAGE_AUTHOR + +/* package name */ +#undef MOO_PACKAGE_NAME + +/* Project URL */ +#undef MOO_PACKAGE_URL + +/* Package version */ +#undef MOO_PACKAGE_VERSION + +/* Major version number */ +#undef MOO_PACKAGE_VERSION_MAJOR + +/* Minor version number */ +#undef MOO_PACKAGE_VERSION_MINOR + +/* Patch level */ +#undef MOO_PACKAGE_VERSION_PATCH + +/* sizeof(char) */ +#undef MOO_SIZEOF_CHAR + +/* sizeof(double) */ +#undef MOO_SIZEOF_DOUBLE + +/* sizeof(float) */ +#undef MOO_SIZEOF_FLOAT + +/* sizeof(int) */ +#undef MOO_SIZEOF_INT + +/* sizeof(long) */ +#undef MOO_SIZEOF_LONG + +/* sizeof(long double) */ +#undef MOO_SIZEOF_LONG_DOUBLE + +/* sizeof(long long) */ +#undef MOO_SIZEOF_LONG_LONG + +/* sizeof(mbstate_t) */ +#undef MOO_SIZEOF_MBSTATE_T + +/* sizeof(off64_t) */ +#undef MOO_SIZEOF_OFF64_T + +/* sizeof(off_t) */ +#undef MOO_SIZEOF_OFF_T + +/* sizeof(short) */ +#undef MOO_SIZEOF_SHORT + +/* sizeof(void*) */ +#undef MOO_SIZEOF_VOID_P + +/* sizeof(wchar_t) */ +#undef MOO_SIZEOF_WCHAR_T + +/* sizeof(__float128) */ +#undef MOO_SIZEOF___FLOAT128 + +/* sizeof(__int128) */ +#undef MOO_SIZEOF___INT128 + +/* sizeof(__int128_t) */ +#undef MOO_SIZEOF___INT128_T + +/* sizeof(__int16) */ +#undef MOO_SIZEOF___INT16 + +/* sizeof(__int32) */ +#undef MOO_SIZEOF___INT32 + +/* sizeof(__int64) */ +#undef MOO_SIZEOF___INT64 + +/* sizeof(__int8) */ +#undef MOO_SIZEOF___INT8 + +/* sizeof(__uint128_t) */ +#undef MOO_SIZEOF___UINT128_T + /* Define if dlsym() requires a leading underscore in symbol names. */ #undef NEED_USCORE @@ -420,105 +519,6 @@ /* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS -/* link modules statically into the main library */ -#undef STIX_ENABLE_STATIC_MODULE - -/* Big Endian */ -#undef STIX_ENDIAN_BIG - -/* Little Endian */ -#undef STIX_ENDIAN_LITTLE - -/* Unknown Endian */ -#undef STIX_ENDIAN_UNKNOWN - -/* MB_LEN_MAX */ -#undef STIX_MBLEN_MAX - -/* Author */ -#undef STIX_PACKAGE_AUTHOR - -/* package name */ -#undef STIX_PACKAGE_NAME - -/* Project URL */ -#undef STIX_PACKAGE_URL - -/* Package version */ -#undef STIX_PACKAGE_VERSION - -/* Major version number */ -#undef STIX_PACKAGE_VERSION_MAJOR - -/* Minor version number */ -#undef STIX_PACKAGE_VERSION_MINOR - -/* Patch level */ -#undef STIX_PACKAGE_VERSION_PATCH - -/* sizeof(char) */ -#undef STIX_SIZEOF_CHAR - -/* sizeof(double) */ -#undef STIX_SIZEOF_DOUBLE - -/* sizeof(float) */ -#undef STIX_SIZEOF_FLOAT - -/* sizeof(int) */ -#undef STIX_SIZEOF_INT - -/* sizeof(long) */ -#undef STIX_SIZEOF_LONG - -/* sizeof(long double) */ -#undef STIX_SIZEOF_LONG_DOUBLE - -/* sizeof(long long) */ -#undef STIX_SIZEOF_LONG_LONG - -/* sizeof(mbstate_t) */ -#undef STIX_SIZEOF_MBSTATE_T - -/* sizeof(off64_t) */ -#undef STIX_SIZEOF_OFF64_T - -/* sizeof(off_t) */ -#undef STIX_SIZEOF_OFF_T - -/* sizeof(short) */ -#undef STIX_SIZEOF_SHORT - -/* sizeof(void*) */ -#undef STIX_SIZEOF_VOID_P - -/* sizeof(wchar_t) */ -#undef STIX_SIZEOF_WCHAR_T - -/* sizeof(__float128) */ -#undef STIX_SIZEOF___FLOAT128 - -/* sizeof(__int128) */ -#undef STIX_SIZEOF___INT128 - -/* sizeof(__int128_t) */ -#undef STIX_SIZEOF___INT128_T - -/* sizeof(__int16) */ -#undef STIX_SIZEOF___INT16 - -/* sizeof(__int32) */ -#undef STIX_SIZEOF___INT32 - -/* sizeof(__int64) */ -#undef STIX_SIZEOF___INT64 - -/* sizeof(__int8) */ -#undef STIX_SIZEOF___INT8 - -/* sizeof(__uint128_t) */ -#undef STIX_SIZEOF___UINT128_T - /* Version number of package */ #undef VERSION diff --git a/stix/lib/moo-cmn.h b/stix/lib/moo-cmn.h new file mode 100644 index 0000000..9e88787 --- /dev/null +++ b/stix/lib/moo-cmn.h @@ -0,0 +1,723 @@ +/* + * $Id$ + * + Copyright (c) 2014-2016 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 _MOO_CMN_H_ +#define _MOO_CMN_H_ + +/* WARNING: NEVER CHANGE/DELETE THE FOLLOWING MOO_HAVE_CFG_H DEFINITION. + * IT IS USED FOR DEPLOYMENT BY MAKEFILE.AM */ +/*#define MOO_HAVE_CFG_H*/ + +#if defined(MOO_HAVE_CFG_H) +# include "moo-cfg.h" +#elif defined(_WIN32) +# include "moo-msw.h" +#elif defined(__OS2__) +# include "moo-os2.h" +#elif defined(__MSDOS__) +# include "moo-dos.h" +#elif defined(macintosh) +# include "moo-mac.h" /* class mac os */ +#else +# error UNSUPPORTED SYSTEM +#endif + +#if defined(EMSCRIPTEN) +# if defined(MOO_SIZEOF___INT128) +# undef MOO_SIZEOF___INT128 +# define MOO_SIZEOF___INT128 0 +# endif +# if defined(MOO_SIZEOF_LONG) && defined(MOO_SIZEOF_INT) && (MOO_SIZEOF_LONG > MOO_SIZEOF_INT) + /* autoconf doesn't seem to match actual emscripten */ +# undef MOO_SIZEOF_LONG +# define MOO_SIZEOF_LONG MOO_SIZEOF_INT +# endif +#endif + + +/* ========================================================================= + * PRIMITIVE TYPE DEFINTIONS + * ========================================================================= */ + +/* moo_int8_t */ +#if defined(MOO_SIZEOF_CHAR) && (MOO_SIZEOF_CHAR == 1) +# define MOO_HAVE_UINT8_T +# define MOO_HAVE_INT8_T + typedef unsigned char moo_uint8_t; + typedef signed char moo_int8_t; +#elif defined(MOO_SIZEOF___INT8) && (MOO_SIZEOF___INT8 == 1) +# define MOO_HAVE_UINT8_T +# define MOO_HAVE_INT8_T + typedef unsigned __int8 moo_uint8_t; + typedef signed __int8 moo_int8_t; +#elif defined(MOO_SIZEOF___INT8_T) && (MOO_SIZEOF___INT8_T == 1) +# define MOO_HAVE_UINT8_T +# define MOO_HAVE_INT8_T + typedef unsigned __int8_t moo_uint8_t; + typedef signed __int8_t moo_int8_t; +#else +# define MOO_HAVE_UINT8_T +# define MOO_HAVE_INT8_T + typedef unsigned char moo_uint8_t; + typedef signed char moo_int8_t; +#endif + + +/* moo_int16_t */ +#if defined(MOO_SIZEOF_SHORT) && (MOO_SIZEOF_SHORT == 2) +# define MOO_HAVE_UINT16_T +# define MOO_HAVE_INT16_T + typedef unsigned short int moo_uint16_t; + typedef signed short int moo_int16_t; +#elif defined(MOO_SIZEOF___INT16) && (MOO_SIZEOF___INT16 == 2) +# define MOO_HAVE_UINT16_T +# define MOO_HAVE_INT16_T + typedef unsigned __int16 moo_uint16_t; + typedef signed __int16 moo_int16_t; +#elif defined(MOO_SIZEOF___INT16_T) && (MOO_SIZEOF___INT16_T == 2) +# define MOO_HAVE_UINT16_T +# define MOO_HAVE_INT16_T + typedef unsigned __int16_t moo_uint16_t; + typedef signed __int16_t moo_int16_t; +#else +# define MOO_HAVE_UINT16_T +# define MOO_HAVE_INT16_T + typedef unsigned short int moo_uint16_t; + typedef signed short int moo_int16_t; +#endif + + +/* moo_int32_t */ +#if defined(MOO_SIZEOF_INT) && (MOO_SIZEOF_INT == 4) +# define MOO_HAVE_UINT32_T +# define MOO_HAVE_INT32_T + typedef unsigned int moo_uint32_t; + typedef signed int moo_int32_t; +#elif defined(MOO_SIZEOF_LONG) && (MOO_SIZEOF_LONG == 4) +# define MOO_HAVE_UINT32_T +# define MOO_HAVE_INT32_T + typedef unsigned long moo_uint32_t; + typedef signed long moo_int32_t; +#elif defined(MOO_SIZEOF___INT32) && (MOO_SIZEOF___INT32 == 4) +# define MOO_HAVE_UINT32_T +# define MOO_HAVE_INT32_T + typedef unsigned __int32 moo_uint32_t; + typedef signed __int32 moo_int32_t; +#elif defined(MOO_SIZEOF___INT32_T) && (MOO_SIZEOF___INT32_T == 4) +# define MOO_HAVE_UINT32_T +# define MOO_HAVE_INT32_T + typedef unsigned __int32_t moo_uint32_t; + typedef signed __int32_t moo_int32_t; +#elif defined(__MSDOS__) +# define MOO_HAVE_UINT32_T +# define MOO_HAVE_INT32_T + typedef unsigned long int moo_uint32_t; + typedef signed long int moo_int32_t; +#else +# define MOO_HAVE_UINT32_T +# define MOO_HAVE_INT32_T + typedef unsigned int moo_uint32_t; + typedef signed int moo_int32_t; +#endif + +/* moo_int64_t */ +#if defined(MOO_SIZEOF_INT) && (MOO_SIZEOF_INT == 8) +# define MOO_HAVE_UINT64_T +# define MOO_HAVE_INT64_T + typedef unsigned int moo_uint64_t; + typedef signed int moo_int64_t; +#elif defined(MOO_SIZEOF_LONG) && (MOO_SIZEOF_LONG == 8) +# define MOO_HAVE_UINT64_T +# define MOO_HAVE_INT64_T + typedef unsigned long moo_uint64_t; + typedef signed long moo_int64_t; +#elif defined(MOO_SIZEOF_LONG_LONG) && (MOO_SIZEOF_LONG_LONG == 8) +# define MOO_HAVE_UINT64_T +# define MOO_HAVE_INT64_T + typedef unsigned long long moo_uint64_t; + typedef signed long long moo_int64_t; +#elif defined(MOO_SIZEOF___INT64) && (MOO_SIZEOF___INT64 == 8) +# define MOO_HAVE_UINT64_T +# define MOO_HAVE_INT64_T + typedef unsigned __int64 moo_uint64_t; + typedef signed __int64 moo_int64_t; +#elif defined(MOO_SIZEOF___INT64_T) && (MOO_SIZEOF___INT64_T == 8) +# define MOO_HAVE_UINT64_T +# define MOO_HAVE_INT64_T + typedef unsigned __int64_t moo_uint64_t; + typedef signed __int64_t moo_int64_t; +#else + /* no 64-bit integer */ +#endif + +/* moo_int128_t */ +#if defined(MOO_SIZEOF_INT) && (MOO_SIZEOF_INT == 16) +# define MOO_HAVE_UINT128_T +# define MOO_HAVE_INT128_T + typedef unsigned int moo_uint128_t; + typedef signed int moo_int128_t; +#elif defined(MOO_SIZEOF_LONG) && (MOO_SIZEOF_LONG == 16) +# define MOO_HAVE_UINT128_T +# define MOO_HAVE_INT128_T + typedef unsigned long moo_uint128_t; + typedef signed long moo_int128_t; +#elif defined(MOO_SIZEOF_LONG_LONG) && (MOO_SIZEOF_LONG_LONG == 16) +# define MOO_HAVE_UINT128_T +# define MOO_HAVE_INT128_T + typedef unsigned long long moo_uint128_t; + typedef signed long long moo_int128_t; +#elif defined(MOO_SIZEOF___INT128) && (MOO_SIZEOF___INT128 == 16) +# define MOO_HAVE_UINT128_T +# define MOO_HAVE_INT128_T + typedef unsigned __int128 moo_uint128_t; + typedef signed __int128 moo_int128_t; +#elif defined(MOO_SIZEOF___INT128_T) && (MOO_SIZEOF___INT128_T == 16) +# define MOO_HAVE_UINT128_T +# define MOO_HAVE_INT128_T + #if defined(MOO_SIZEOF___UINT128_T) && (MOO_SIZEOF___UINT128_T == MOO_SIZEOF___INT128_T) + typedef __uint128_t moo_uint128_t; + typedef __int128_t moo_int128_t; + #elif defined(__clang__) + typedef __uint128_t moo_uint128_t; + typedef __int128_t moo_int128_t; + #else + typedef unsigned __int128_t moo_uint128_t; + typedef signed __int128_t moo_int128_t; + #endif +#else + /* no 128-bit integer */ +#endif + +#if defined(MOO_HAVE_UINT8_T) && (MOO_SIZEOF_VOID_P == 1) +# error UNSUPPORTED POINTER SIZE +#elif defined(MOO_HAVE_UINT16_T) && (MOO_SIZEOF_VOID_P == 2) + typedef moo_uint16_t moo_uintptr_t; + typedef moo_int16_t moo_intptr_t; + typedef moo_uint8_t moo_ushortptr_t; + typedef moo_int8_t moo_shortptr_t; +#elif defined(MOO_HAVE_UINT32_T) && (MOO_SIZEOF_VOID_P == 4) + typedef moo_uint32_t moo_uintptr_t; + typedef moo_int32_t moo_intptr_t; + typedef moo_uint16_t moo_ushortptr_t; + typedef moo_int16_t moo_shortptr_t; +#elif defined(MOO_HAVE_UINT64_T) && (MOO_SIZEOF_VOID_P == 8) + typedef moo_uint64_t moo_uintptr_t; + typedef moo_int64_t moo_intptr_t; + typedef moo_uint32_t moo_ushortptr_t; + typedef moo_int32_t moo_shortptr_t; +#elif defined(MOO_HAVE_UINT128_T) && (MOO_SIZEOF_VOID_P == 16) + typedef moo_uint128_t moo_uintptr_t; + typedef moo_int128_t moo_intptr_t; + typedef moo_uint64_t moo_ushortptr_t; + typedef moo_int64_t moo_shortptr_t; +#else +# error UNKNOWN POINTER SIZE +#endif + +#define MOO_SIZEOF_INTPTR_T MOO_SIZEOF_VOID_P +#define MOO_SIZEOF_UINTPTR_T MOO_SIZEOF_VOID_P +#define MOO_SIZEOF_SHORTPTR_T (MOO_SIZEOF_VOID_P / 2) +#define MOO_SIZEOF_USHORTPTR_T (MOO_SIZEOF_VOID_P / 2) + +#if defined(MOO_HAVE_INT128_T) +# define MOO_SIZEOF_INTMAX_T 16 +# define MOO_SIZEOF_UINTMAX_T 16 + typedef moo_int128_t moo_intmax_t; + typedef moo_uint128_t moo_uintmax_t; +#elif defined(MOO_HAVE_INT64_T) +# define MOO_SIZEOF_INTMAX_T 8 +# define MOO_SIZEOF_UINTMAX_T 8 + typedef moo_int64_t moo_intmax_t; + typedef moo_uint64_t moo_uintmax_t; +#elif defined(MOO_HAVE_INT32_T) +# define MOO_SIZEOF_INTMAX_T 4 +# define MOO_SIZEOF_UINTMAX_T 4 + typedef moo_int32_t moo_intmax_t; + typedef moo_uint32_t moo_uintmax_t; +#elif defined(MOO_HAVE_INT16_T) +# define MOO_SIZEOF_INTMAX_T 2 +# define MOO_SIZEOF_UINTMAX_T 2 + typedef moo_int16_t moo_intmax_t; + typedef moo_uint16_t moo_uintmax_t; +#elif defined(MOO_HAVE_INT8_T) +# define MOO_SIZEOF_INTMAX_T 1 +# define MOO_SIZEOF_UINTMAX_T 1 + typedef moo_int8_t moo_intmax_t; + typedef moo_uint8_t moo_uintmax_t; +#else +# error UNKNOWN INTMAX SIZE +#endif + +/* ========================================================================= + * BASIC MOO TYPES + * =========================================================================*/ + +typedef char moo_bch_t; +typedef int moo_bci_t; + +typedef moo_uint16_t moo_uch_t; /* TODO ... wchar_t??? */ +typedef moo_int32_t moo_uci_t; + +typedef moo_uint8_t moo_oob_t; + +/* NOTE: sizeof(moo_oop_t) must be equal to sizeof(moo_oow_t) */ +typedef moo_uintptr_t moo_oow_t; +typedef moo_intptr_t moo_ooi_t; +#define MOO_SIZEOF_OOW_T MOO_SIZEOF_UINTPTR_T +#define MOO_SIZEOF_OOI_T MOO_SIZEOF_INTPTR_T + +typedef moo_ushortptr_t moo_oohw_t; /* half word - half word */ +typedef moo_shortptr_t moo_oohi_t; /* signed half word */ +#define MOO_SIZEOF_OOHW_T MOO_SIZEOF_USHORTPTR_T +#define MOO_SIZEOF_OOHI_T MOO_SIZEOF_SHORTPTR_T + +struct moo_ucs_t +{ + moo_uch_t* ptr; + moo_oow_t len; +}; +typedef struct moo_ucs_t moo_ucs_t; + +struct moo_bcs_t +{ + moo_bch_t* ptr; + moo_oow_t len; +}; +typedef struct moo_bcs_t moo_bcs_t; + +typedef moo_uch_t moo_ooch_t; +typedef moo_uci_t moo_ooci_t; +typedef moo_ucs_t moo_oocs_t; +#define MOO_OOCH_IS_UCH + + + +/* ========================================================================= + * TIME-RELATED TYPES + * =========================================================================*/ +#define MOO_MSECS_PER_SEC (1000) +#define MOO_MSECS_PER_MIN (MOO_MSECS_PER_SEC * MOO_SECS_PER_MIN) +#define MOO_MSECS_PER_HOUR (MOO_MSECS_PER_SEC * MOO_SECS_PER_HOUR) +#define MOO_MSECS_PER_DAY (MOO_MSECS_PER_SEC * MOO_SECS_PER_DAY) + +#define MOO_USECS_PER_MSEC (1000) +#define MOO_NSECS_PER_USEC (1000) +#define MOO_NSECS_PER_MSEC (MOO_NSECS_PER_USEC * MOO_USECS_PER_MSEC) +#define MOO_USECS_PER_SEC (MOO_USECS_PER_MSEC * MOO_MSECS_PER_SEC) +#define MOO_NSECS_PER_SEC (MOO_NSECS_PER_USEC * MOO_USECS_PER_MSEC * MOO_MSECS_PER_SEC) + +#define MOO_SECNSEC_TO_MSEC(sec,nsec) \ + (((moo_intptr_t)(sec) * MOO_MSECS_PER_SEC) + ((moo_intptr_t)(nsec) / MOO_NSECS_PER_MSEC)) + +#define MOO_SECNSEC_TO_USEC(sec,nsec) \ + (((moo_intptr_t)(sec) * MOO_USECS_PER_SEC) + ((moo_intptr_t)(nsec) / MOO_NSECS_PER_USEC)) + +#define MOO_SECNSEC_TO_NSEC(sec,nsec) \ + (((moo_intptr_t)(sec) * MOO_NSECS_PER_SEC) + (moo_intptr_t)(nsec)) + +#define MOO_SEC_TO_MSEC(sec) ((sec) * MOO_MSECS_PER_SEC) +#define MOO_MSEC_TO_SEC(sec) ((sec) / MOO_MSECS_PER_SEC) + +#define MOO_USEC_TO_NSEC(usec) ((usec) * MOO_NSECS_PER_USEC) +#define MOO_NSEC_TO_USEC(nsec) ((nsec) / MOO_NSECS_PER_USEC) + +#define MOO_MSEC_TO_NSEC(msec) ((msec) * MOO_NSECS_PER_MSEC) +#define MOO_NSEC_TO_MSEC(nsec) ((nsec) / MOO_NSECS_PER_MSEC) + +#define MOO_SEC_TO_NSEC(sec) ((sec) * MOO_NSECS_PER_SEC) +#define MOO_NSEC_TO_SEC(nsec) ((nsec) / MOO_NSECS_PER_SEC) + +#define MOO_SEC_TO_USEC(sec) ((sec) * MOO_USECS_PER_SEC) +#define MOO_USEC_TO_SEC(usec) ((usec) / MOO_USECS_PER_SEC) + +typedef struct moo_ntime_t moo_ntime_t; +struct moo_ntime_t +{ + moo_intptr_t sec; + moo_int32_t nsec; /* nanoseconds */ +}; + +#define MOO_INITNTIME(c,s,ns) (((c)->sec = (s)), ((c)->nsec = (ns))) +#define MOO_CLEARNTIME(c) MOO_INITNTIME(c, 0, 0) + +#define MOO_ADDNTIME(c,a,b) \ + do { \ + (c)->sec = (a)->sec + (b)->sec; \ + (c)->nsec = (a)->nsec + (b)->nsec; \ + while ((c)->nsec >= MOO_NSECS_PER_SEC) { (c)->sec++; (c)->nsec -= MOO_NSECS_PER_SEC; } \ + } while(0) + +#define MOO_ADDNTIMESNS(c,a,s,ns) \ + do { \ + (c)->sec = (a)->sec + (s); \ + (c)->nsec = (a)->nsec + (ns); \ + while ((c)->nsec >= MOO_NSECS_PER_SEC) { (c)->sec++; (c)->nsec -= MOO_NSECS_PER_SEC; } \ + } while(0) + +#define MOO_SUBNTIME(c,a,b) \ + do { \ + (c)->sec = (a)->sec - (b)->sec; \ + (c)->nsec = (a)->nsec - (b)->nsec; \ + while ((c)->nsec < 0) { (c)->sec--; (c)->nsec += MOO_NSECS_PER_SEC; } \ + } while(0) + +#define MOO_SUBNTIMESNS(c,a,s,ns) \ + do { \ + (c)->sec = (a)->sec - s; \ + (c)->nsec = (a)->nsec - ns; \ + while ((c)->nsec < 0) { (c)->sec--; (c)->nsec += MOO_NSECS_PER_SEC; } \ + } while(0) + + +#define MOO_CMPNTIME(a,b) (((a)->sec == (b)->sec)? ((a)->nsec - (b)->nsec): ((a)->sec - (b)->sec)) + +/* ========================================================================= + * PRIMITIVE MACROS + * ========================================================================= */ +#define MOO_UCI_EOF ((moo_ooci_t)-1) + +#define MOO_SIZEOF(x) (sizeof(x)) +#define MOO_COUNTOF(x) (sizeof(x) / sizeof(x[0])) + +/** + * The MOO_OFFSETOF() macro returns the offset of a field from the beginning + * of a structure. + */ +#define MOO_OFFSETOF(type,member) ((moo_uintptr_t)&((type*)0)->member) + +/** + * The MOO_ALIGNOF() macro returns the alignment size of a structure. + * Note that this macro may not work reliably depending on the type given. + */ +#define MOO_ALIGNOF(type) MOO_OFFSETOF(struct { moo_uint8_t d1; type d2; }, d2) + /*(sizeof(struct { moo_uint8_t d1; type d2; }) - sizeof(type))*/ + +#if defined(__cplusplus) +# if (__cplusplus >= 201103L) /* C++11 */ +# define MOO_NULL nullptr +# else +# define MOO_NULL (0) +# endif +#else +# define MOO_NULL ((void*)0) +#endif + +/* make a bit mask that can mask off low n bits */ +#define MOO_LBMASK(type,n) (~(~((type)0) << (n))) +#define MOO_LBMASK_SAFE(type,n) (((n) < MOO_SIZEOF(type) * 8)? MOO_LBMASK(type,n): ~(type)0) + +/* make a bit mask that can mask off hig n bits */ +#define MOO_HBMASK(type,n) (~(~((type)0) >> (n))) +#define MOO_HBMASK_SAFE(type,n) (((n) < MOO_SIZEOF(type) * 8)? MOO_HBMASK(type,n): ~(type)0) + +/* get 'length' bits starting from the bit at the 'offset' */ +#define MOO_GETBITS(type,value,offset,length) \ + ((((type)(value)) >> (offset)) & MOO_LBMASK(type,length)) + +#define MOO_CLEARBITS(type,value,offset,length) \ + (((type)(value)) & ~(MOO_LBMASK(type,length) << (offset))) + +#define MOO_SETBITS(type,value,offset,length,bits) \ + (value = (MOO_CLEARBITS(type,value,offset,length) | (((bits) & MOO_LBMASK(type,length)) << (offset)))) + +#define MOO_FLIPBITS(type,value,offset,length) \ + (((type)(value)) ^ (MOO_LBMASK(type,length) << (offset))) + +#define MOO_ORBITS(type,value,offset,length,bits) \ + (value = (((type)(value)) | (((bits) & MOO_LBMASK(type,length)) << (offset)))) + + +/** + * The MOO_BITS_MAX() macros calculates the maximum value that the 'nbits' + * bits of an unsigned integer of the given 'type' can hold. + * \code + * printf ("%u", MOO_BITS_MAX(unsigned int, 5)); + * \endcode + */ +/*#define MOO_BITS_MAX(type,nbits) ((((type)1) << (nbits)) - 1)*/ +#define MOO_BITS_MAX(type,nbits) ((~(type)0) >> (MOO_SIZEOF(type) * 8 - (nbits))) + +/* ========================================================================= + * MMGR + * ========================================================================= */ +typedef struct moo_mmgr_t moo_mmgr_t; + +/** + * allocate a memory chunk of the size \a n. + * \return pointer to a memory chunk on success, #MOO_NULL on failure. + */ +typedef void* (*moo_mmgr_alloc_t) (moo_mmgr_t* mmgr, moo_oow_t n); +/** + * resize a memory chunk pointed to by \a ptr to the size \a n. + * \return pointer to a memory chunk on success, #MOO_NULL on failure. + */ +typedef void* (*moo_mmgr_realloc_t) (moo_mmgr_t* mmgr, void* ptr, moo_oow_t n); +/** + * free a memory chunk pointed to by \a ptr. + */ +typedef void (*moo_mmgr_free_t) (moo_mmgr_t* mmgr, void* ptr); + +/** + * The moo_mmgr_t type defines the memory management interface. + * As the type is merely a structure, it is just used as a single container + * for memory management functions with a pointer to user-defined data. + * The user-defined data pointer \a ctx is passed to each memory management + * function whenever it is called. You can allocate, reallocate, and free + * a memory chunk. + * + * For example, a moo_xxx_open() function accepts a pointer of the moo_mmgr_t + * type and the xxx object uses it to manage dynamic data within the object. + */ +struct moo_mmgr_t +{ + moo_mmgr_alloc_t alloc; /**< allocation function */ + moo_mmgr_realloc_t realloc; /**< resizing function */ + moo_mmgr_free_t free; /**< disposal function */ + void* ctx; /**< user-defined data pointer */ +}; + +/** + * The MOO_MMGR_ALLOC() macro allocates a memory block of the \a size bytes + * using the \a mmgr memory manager. + */ +#define MOO_MMGR_ALLOC(mmgr,size) ((mmgr)->alloc(mmgr,size)) + +/** + * The MOO_MMGR_REALLOC() macro resizes a memory block pointed to by \a ptr + * to the \a size bytes using the \a mmgr memory manager. + */ +#define MOO_MMGR_REALLOC(mmgr,ptr,size) ((mmgr)->realloc(mmgr,ptr,size)) + +/** + * The MOO_MMGR_FREE() macro deallocates the memory block pointed to by \a ptr. + */ +#define MOO_MMGR_FREE(mmgr,ptr) ((mmgr)->free(mmgr,ptr)) + + +/* ========================================================================= + * CMGR + * =========================================================================*/ + +typedef struct moo_cmgr_t moo_cmgr_t; + +typedef moo_oow_t (*moo_cmgr_bctouc_t) ( + const moo_bch_t* mb, + moo_oow_t size, + moo_uch_t* wc +); + +typedef moo_oow_t (*moo_cmgr_uctobc_t) ( + moo_uch_t wc, + moo_bch_t* mb, + moo_oow_t size +); + +/** + * The moo_cmgr_t type defines the character-level interface to + * multibyte/wide-character conversion. This interface doesn't + * provide any facility to store conversion state in a context + * independent manner. This leads to the limitation that it can + * handle a stateless multibyte encoding only. + */ +struct moo_cmgr_t +{ + moo_cmgr_bctouc_t bctouc; + moo_cmgr_uctobc_t uctobc; +}; + +/* ========================================================================= + * FORWARD DECLARATION FOR MAIN MOO STRUCTURE + * =========================================================================*/ +typedef struct moo_t moo_t; + +/* ========================================================================= + * MACROS THAT CHANGES THE BEHAVIORS OF THE C COMPILER/LINKER + * =========================================================================*/ + +#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500) +# define MOO_IMPORT +# define MOO_EXPORT +# define MOO_PRIVATE +#elif defined(_WIN32) || (defined(__WATCOMC__) && !defined(__WINDOWS_386__)) +# define MOO_IMPORT __declspec(dllimport) +# define MOO_EXPORT __declspec(dllexport) +# define MOO_PRIVATE +#elif defined(__GNUC__) && (__GNUC__>=4) +# define MOO_IMPORT __attribute__((visibility("default"))) +# define MOO_EXPORT __attribute__((visibility("default"))) +# define MOO_PRIVATE __attribute__((visibility("hidden"))) +/*# define MOO_PRIVATE __attribute__((visibility("internal")))*/ +#else +# define MOO_IMPORT +# define MOO_EXPORT +# define MOO_PRIVATE +#endif + +#if defined(__STDC_VERSION__) && (__STDC_VERSION__>=199901L) + /* C99 has inline */ +# define MOO_INLINE inline +# define MOO_HAVE_INLINE +#elif defined(__GNUC__) && defined(__GNUC_GNU_INLINE__) + /* gcc disables inline when -std=c89 or -ansi is used. + * so use __inline__ supported by gcc regardless of the options */ +# define MOO_INLINE /*extern*/ __inline__ +# define MOO_HAVE_INLINE +#else +# define MOO_INLINE +# undef MOO_HAVE_INLINE +#endif + +/** + * The MOO_TYPE_IS_SIGNED() macro determines if a type is signed. + * \code + * printf ("%d\n", (int)MOO_TYPE_IS_SIGNED(int)); + * printf ("%d\n", (int)MOO_TYPE_IS_SIGNED(unsigned int)); + * \endcode + */ +#define MOO_TYPE_IS_SIGNED(type) (((type)0) > ((type)-1)) + +/** + * The MOO_TYPE_IS_SIGNED() macro determines if a type is unsigned. + * \code + * printf ("%d\n", MOO_TYPE_IS_UNSIGNED(int)); + * printf ("%d\n", MOO_TYPE_IS_UNSIGNED(unsigned int)); + * \endcode + */ +#define MOO_TYPE_IS_UNSIGNED(type) (((type)0) < ((type)-1)) + +#define MOO_TYPE_SIGNED_MAX(type) \ + ((type)~((type)1 << ((type)MOO_SIZEOF(type) * 8 - 1))) +#define MOO_TYPE_UNSIGNED_MAX(type) ((type)(~(type)0)) + +#define MOO_TYPE_SIGNED_MIN(type) \ + ((type)((type)1 << ((type)MOO_SIZEOF(type) * 8 - 1))) +#define MOO_TYPE_UNSIGNED_MIN(type) ((type)0) + +#define MOO_TYPE_MAX(type) \ + ((MOO_TYPE_IS_SIGNED(type)? MOO_TYPE_SIGNED_MAX(type): MOO_TYPE_UNSIGNED_MAX(type))) +#define MOO_TYPE_MIN(type) \ + ((MOO_TYPE_IS_SIGNED(type)? MOO_TYPE_SIGNED_MIN(type): MOO_TYPE_UNSIGNED_MIN(type))) + + +/* ========================================================================= + * COMPILER FEATURE TEST MACROS + * =========================================================================*/ +#if !defined(__has_builtin) && defined(_INTELC32_) + /* intel c code builder 1.0 ended up with an error without this override */ + #define __has_builtin(x) 0 +#endif + +/* +#if !defined(__is_identifier) + #define __is_identifier(x) 0 +#endif + +#if !defined(__has_attribute) + #define __has_attribute(x) 0 +#endif +*/ + + +#if defined(__has_builtin) + #if __has_builtin(__builtin_ctz) + #define MOO_HAVE_BUILTIN_CTZ + #endif + + #if __has_builtin(__builtin_uadd_overflow) + #define MOO_HAVE_BUILTIN_UADD_OVERFLOW + #endif + #if __has_builtin(__builtin_uaddl_overflow) + #define MOO_HAVE_BUILTIN_UADDL_OVERFLOW + #endif + #if __has_builtin(__builtin_uaddll_overflow) + #define MOO_HAVE_BUILTIN_UADDLL_OVERFLOW + #endif + #if __has_builtin(__builtin_umul_overflow) + #define MOO_HAVE_BUILTIN_UMUL_OVERFLOW + #endif + #if __has_builtin(__builtin_umull_overflow) + #define MOO_HAVE_BUILTIN_UMULL_OVERFLOW + #endif + #if __has_builtin(__builtin_umulll_overflow) + #define MOO_HAVE_BUILTIN_UMULLL_OVERFLOW + #endif + + #if __has_builtin(__builtin_sadd_overflow) + #define MOO_HAVE_BUILTIN_SADD_OVERFLOW + #endif + #if __has_builtin(__builtin_saddl_overflow) + #define MOO_HAVE_BUILTIN_SADDL_OVERFLOW + #endif + #if __has_builtin(__builtin_saddll_overflow) + #define MOO_HAVE_BUILTIN_SADDLL_OVERFLOW + #endif + #if __has_builtin(__builtin_smul_overflow) + #define MOO_HAVE_BUILTIN_SMUL_OVERFLOW + #endif + #if __has_builtin(__builtin_smull_overflow) + #define MOO_HAVE_BUILTIN_SMULL_OVERFLOW + #endif + #if __has_builtin(__builtin_smulll_overflow) + #define MOO_HAVE_BUILTIN_SMULLL_OVERFLOW + #endif + + #if __has_builtin(__builtin_expect) + #define MOO_HAVE_BUILTIN_EXPECT + #endif +#elif defined(__GNUC__) && defined(__GNUC_MINOR__) + + #if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) + #define MOO_HAVE_BUILTIN_CTZ + #define MOO_HAVE_BUILTIN_EXPECT + #endif + + #if (__GNUC__ >= 5) + #define MOO_HAVE_BUILTIN_UADD_OVERFLOW + #define MOO_HAVE_BUILTIN_UADDL_OVERFLOW + #define MOO_HAVE_BUILTIN_UADDLL_OVERFLOW + #define MOO_HAVE_BUILTIN_UMUL_OVERFLOW + #define MOO_HAVE_BUILTIN_UMULL_OVERFLOW + #define MOO_HAVE_BUILTIN_UMULLL_OVERFLOW + + #define MOO_HAVE_BUILTIN_SADD_OVERFLOW + #define MOO_HAVE_BUILTIN_SADDL_OVERFLOW + #define MOO_HAVE_BUILTIN_SADDLL_OVERFLOW + #define MOO_HAVE_BUILTIN_SMUL_OVERFLOW + #define MOO_HAVE_BUILTIN_SMULL_OVERFLOW + #define MOO_HAVE_BUILTIN_SMULLL_OVERFLOW + #endif + +#endif + +#if defined(MOO_HAVE_BUILTIN_EXPECT) +# define MOO_LIKELY(x) (__builtin_expect(!!x,1)) +# define MOO_UNLIKELY(x) (__builtin_expect(!!x,0)) +#else +# define MOO_LIKELY(x) (x) +# define MOO_UNLIKELY(x) (x) +#endif + +#endif diff --git a/stix/lib/moo-dos.h b/stix/lib/moo-dos.h new file mode 100644 index 0000000..8262239 --- /dev/null +++ b/stix/lib/moo-dos.h @@ -0,0 +1,167 @@ +/* + * $Id$ + * + Copyright (c) 2014-2016 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. + */ +/* DOS for other platforms than x86? + * If so, the endian should be defined selectively + */ +#define MOO_ENDIAN_LITTLE + +#if defined(__WATCOMC__) && defined(__386__) +# define MOO_SIZEOF_CHAR 1 +# define MOO_SIZEOF_SHORT 2 +# define MOO_SIZEOF_INT 4 +# define MOO_SIZEOF_LONG 4 +# if (__WATCOMC__ < 1200) +# define MOO_SIZEOF_LONG_LONG 0 +# else +# define MOO_SIZEOF_LONG_LONG 8 +# endif +# define MOO_SIZEOF_VOID_P 4 +# define MOO_SIZEOF_FLOAT 4 +# define MOO_SIZEOF_DOUBLE 8 +# define MOO_SIZEOF_LONG_DOUBLE 8 +# define MOO_SIZEOF_WCHAR_T 2 + +# define MOO_SIZEOF___INT8 1 +# define MOO_SIZEOF___INT16 2 +# define MOO_SIZEOF___INT32 4 +# define MOO_SIZEOF___INT64 8 +# define MOO_SIZEOF___INT128 0 + +# define MOO_SIZEOF_OFF64_T 0 +# define MOO_SIZEOF_OFF_T 4 + +# define MOO_SIZEOF_MBSTATE_T MOO_SIZEOF_LONG +# define MOO_MBLEN_MAX 8 + +#elif defined(__WATCOMC__) && !defined(__386__) +# define MOO_SIZEOF_CHAR 1 +# define MOO_SIZEOF_SHORT 2 +# define MOO_SIZEOF_INT 2 +# define MOO_SIZEOF_LONG 4 +# define MOO_SIZEOF_LONG_LONG 8 + +# define MOO_SIZEOF_VOID_P 4 +# define MOO_SIZEOF_FLOAT 4 +# define MOO_SIZEOF_DOUBLE 8 +# define MOO_SIZEOF_LONG_DOUBLE 8 +# define MOO_SIZEOF_WCHAR_T 2 + +# define MOO_SIZEOF___INT8 1 +# define MOO_SIZEOF___INT16 2 +# define MOO_SIZEOF___INT32 4 +# define MOO_SIZEOF___INT64 8 +# define MOO_SIZEOF___INT128 0 + +# define MOO_SIZEOF_OFF64_T 0 +# define MOO_SIZEOF_OFF_T 4 + +# define MOO_SIZEOF_MBSTATE_T MOO_SIZEOF_LONG +# define MOO_MBLEN_MAX 8 + +#elif defined(__TURBOC__) +/* TODO: be more version specific wchar_t may be available in newer BCC */ +# define MOO_SIZEOF_CHAR 1 +# define MOO_SIZEOF_SHORT 2 +# define MOO_SIZEOF_INT 2 +# define MOO_SIZEOF_LONG 4 +# define MOO_SIZEOF_LONG_LONG 0 + +# define MOO_SIZEOF_VOID_P 4 +# define MOO_SIZEOF_FLOAT 4 +# define MOO_SIZEOF_DOUBLE 8 +# define MOO_SIZEOF_LONG_DOUBLE 10 +# define MOO_SIZEOF_WCHAR_T 0 + +# define MOO_SIZEOF___INT8 0 +# define MOO_SIZEOF___INT16 0 +# define MOO_SIZEOF___INT32 0 +# define MOO_SIZEOF___INT64 0 +# define MOO_SIZEOF___INT128 0 + +# define MOO_SIZEOF_OFF64_T 0 +# define MOO_SIZEOF_OFF_T 4 + +# define MOO_SIZEOF_MBSTATE_T MOO_SIZEOF_LONG +# define MOO_MBLEN_MAX 8 + +#elif defined(__ZTC__) && defined(DOS386) + + /* Zortech in DOSX 386 mode (ztc -mx) */ +# define MOO_SIZEOF_CHAR 1 +# define MOO_SIZEOF_SHORT 2 +# define MOO_SIZEOF_INT 4 +# define MOO_SIZEOF_LONG 4 +# define MOO_SIZEOF_LONG_LONG 0 + +# define MOO_SIZEOF_VOID_P 4 +# define MOO_SIZEOF_FLOAT 4 +# define MOO_SIZEOF_DOUBLE 8 +# define MOO_SIZEOF_LONG_DOUBLE 8 +# define MOO_SIZEOF_WCHAR_T 1 + +# define MOO_SIZEOF___INT8 0 +# define MOO_SIZEOF___INT16 0 +# define MOO_SIZEOF___INT32 0 +# define MOO_SIZEOF___INT64 0 +# define MOO_SIZEOF___INT128 0 + +# define MOO_SIZEOF_OFF64_T 0 +# define MOO_SIZEOF_OFF_T 4 + +# define MOO_SIZEOF_MBSTATE_T MOO_SIZEOF_LONG +# define MOO_MBLEN_MAX 8 + +#elif defined(_INTELC32_) + + /* Intel C Code Builder 1.0 */ +# define MOO_SIZEOF_CHAR 1 +# define MOO_SIZEOF_SHORT 2 +# define MOO_SIZEOF_INT 4 +# define MOO_SIZEOF_LONG 4 +# define MOO_SIZEOF_LONG_LONG 0 + +# define MOO_SIZEOF_VOID_P 4 +# define MOO_SIZEOF_FLOAT 4 +# define MOO_SIZEOF_DOUBLE 8 +# define MOO_SIZEOF_LONG_DOUBLE 8 +# define MOO_SIZEOF_WCHAR_T 1 + +# define MOO_SIZEOF___INT8 0 +# define MOO_SIZEOF___INT16 0 +# define MOO_SIZEOF___INT32 0 +# define MOO_SIZEOF___INT64 0 +# define MOO_SIZEOF___INT128 0 + +# define MOO_SIZEOF_OFF64_T 0 +# define MOO_SIZEOF_OFF_T 4 + +# define MOO_SIZEOF_MBSTATE_T MOO_SIZEOF_LONG +# define MOO_MBLEN_MAX 8 + +#else +# error Define the size of various data types. +#endif + diff --git a/stix/lib/stix-mac.h b/stix/lib/moo-mac.h similarity index 68% rename from stix/lib/stix-mac.h rename to stix/lib/moo-mac.h index 176f2e0..734a441 100644 --- a/stix/lib/stix-mac.h +++ b/stix/lib/moo-mac.h @@ -26,31 +26,31 @@ /* This file is for class Mac OS */ /* Mac OS on PPC and m68k uses the big endian mode */ -#define STIX_ENDIAN_BIG +#define MOO_ENDIAN_BIG #if defined(__MWERKS__) -# define STIX_SIZEOF_CHAR 1 -# define STIX_SIZEOF_SHORT 2 -# define STIX_SIZEOF_INT 4 -# define STIX_SIZEOF_LONG 4 -# define STIX_SIZEOF_LONG_LONG 8 -# define STIX_SIZEOF_VOID_P 4 -# define STIX_SIZEOF_FLOAT 4 -# define STIX_SIZEOF_DOUBLE 8 -# define STIX_SIZEOF_LONG_DOUBLE 8 -# define STIX_SIZEOF_WCHAR_T 2 +# define MOO_SIZEOF_CHAR 1 +# define MOO_SIZEOF_SHORT 2 +# define MOO_SIZEOF_INT 4 +# define MOO_SIZEOF_LONG 4 +# define MOO_SIZEOF_LONG_LONG 8 +# define MOO_SIZEOF_VOID_P 4 +# define MOO_SIZEOF_FLOAT 4 +# define MOO_SIZEOF_DOUBLE 8 +# define MOO_SIZEOF_LONG_DOUBLE 8 +# define MOO_SIZEOF_WCHAR_T 2 -# define STIX_SIZEOF___INT8 1 -# define STIX_SIZEOF___INT16 2 -# define STIX_SIZEOF___INT32 4 -# define STIX_SIZEOF___INT64 8 -# define STIX_SIZEOF___INT128 0 +# define MOO_SIZEOF___INT8 1 +# define MOO_SIZEOF___INT16 2 +# define MOO_SIZEOF___INT32 4 +# define MOO_SIZEOF___INT64 8 +# define MOO_SIZEOF___INT128 0 -# define STIX_SIZEOF_OFF64_T 0 -# define STIX_SIZEOF_OFF_T 8 +# define MOO_SIZEOF_OFF64_T 0 +# define MOO_SIZEOF_OFF_T 8 -# define STIX_SIZEOF_MBSTATE_T STIX_SIZEOF_LONG -# define STIX_MBLEN_MAX 16 +# define MOO_SIZEOF_MBSTATE_T MOO_SIZEOF_LONG +# define MOO_MBLEN_MAX 16 #else # error Define the size of various data types. diff --git a/stix/lib/moo-msw.h b/stix/lib/moo-msw.h new file mode 100644 index 0000000..fdbf041 --- /dev/null +++ b/stix/lib/moo-msw.h @@ -0,0 +1,174 @@ +/* + * $Id$ + * + Copyright (c) 2014-2016 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. + */ + +/* +Macro Meaning +_WIN64 A 64-bit platform. +_WIN32 A 32-bit platform. This value is also defined by the 64-bit + compiler for backward compatibility. +_WIN16 A 16-bit platform + +The following macros are specific to the architecture. + +Macro Meaning +_M_IA64 Intel Itanium Processor Family +_M_IX86 x86 platform +_M_X64 x64 platform +*/ + +/* windows for most of non-x86 platforms dropped. + * make it selective to support old non-x86 windows platforms. */ +#define MOO_ENDIAN_LITTLE + +#if defined(__WATCOMC__) +# define MOO_SIZEOF_CHAR 1 +# define MOO_SIZEOF_SHORT 2 +# define MOO_SIZEOF_INT 4 +# define MOO_SIZEOF_LONG 4 +# if (__WATCOMC__ < 1200) +# define MOO_SIZEOF_LONG_LONG 0 +# else +# define MOO_SIZEOF_LONG_LONG 8 +# endif + +# if defined(_WIN64) +# define MOO_SIZEOF_VOID_P 8 +# else +# define MOO_SIZEOF_VOID_P 4 +# endif +# define MOO_SIZEOF_FLOAT 4 +# define MOO_SIZEOF_DOUBLE 8 +# define MOO_SIZEOF_LONG_DOUBLE 8 +# define MOO_SIZEOF_WCHAR_T 2 + +# define MOO_SIZEOF___INT8 1 +# define MOO_SIZEOF___INT16 2 +# define MOO_SIZEOF___INT32 4 +# define MOO_SIZEOF___INT64 8 +# define MOO_SIZEOF___INT128 0 + +# define MOO_SIZEOF_OFF64_T 0 +# define MOO_SIZEOF_OFF_T 8 + +# define MOO_SIZEOF_MBSTATE_T MOO_SIZEOF_LONG +# define MOO_MBLEN_MAX 16 + +#elif defined(__GNUC__) || defined(__DMC__) || defined(__POCC__) +# define MOO_SIZEOF_CHAR 1 +# define MOO_SIZEOF_SHORT 2 +# define MOO_SIZEOF_INT 4 +# define MOO_SIZEOF_LONG 4 +# define MOO_SIZEOF_LONG_LONG 8 + +# if defined(_WIN64) +# define MOO_SIZEOF_VOID_P 8 +# else +# define MOO_SIZEOF_VOID_P 4 +# endif +# define MOO_SIZEOF_FLOAT 4 +# define MOO_SIZEOF_DOUBLE 8 +# define MOO_SIZEOF_LONG_DOUBLE 16 +# define MOO_SIZEOF_WCHAR_T 2 + +# define MOO_SIZEOF___INT8 0 +# define MOO_SIZEOF___INT16 0 +# define MOO_SIZEOF___INT32 0 +# define MOO_SIZEOF___INT64 0 +# define MOO_SIZEOF___INT128 0 + +# define MOO_SIZEOF_OFF64_T 0 +# define MOO_SIZEOF_OFF_T 8 + +# define MOO_SIZEOF_MBSTATE_T MOO_SIZEOF_LONG +# define MOO_MBLEN_MAX 16 + +#elif defined(_MSC_VER) +# define MOO_SIZEOF_CHAR 1 +# define MOO_SIZEOF_SHORT 2 +# define MOO_SIZEOF_INT 4 +# define MOO_SIZEOF_LONG 4 +# if (_MSC_VER>=1310) +# define MOO_SIZEOF_LONG_LONG 8 +# else +# define MOO_SIZEOF_LONG_LONG 0 +# endif + +# if defined(_WIN64) +# define MOO_SIZEOF_VOID_P 8 +# else +# define MOO_SIZEOF_VOID_P 4 +# endif +# define MOO_SIZEOF_FLOAT 4 +# define MOO_SIZEOF_DOUBLE 8 +# define MOO_SIZEOF_LONG_DOUBLE 8 +# define MOO_SIZEOF_WCHAR_T 2 + +# define MOO_SIZEOF___INT8 1 +# define MOO_SIZEOF___INT16 2 +# define MOO_SIZEOF___INT32 4 +# define MOO_SIZEOF___INT64 8 +# define MOO_SIZEOF___INT128 0 + +# define MOO_SIZEOF_OFF64_T 0 +# define MOO_SIZEOF_OFF_T 8 + +# define MOO_SIZEOF_MBSTATE_T MOO_SIZEOF_LONG +# define MOO_MBLEN_MAX 8 + +#elif defined(__BORLANDC__) + +# define MOO_SIZEOF_CHAR 1 +# define MOO_SIZEOF_SHORT 2 +# define MOO_SIZEOF_INT 4 +# define MOO_SIZEOF_LONG 4 +# define MOO_SIZEOF_LONG_LONG 0 + +# if defined(_WIN64) +# define MOO_SIZEOF_VOID_P 8 +# else +# define MOO_SIZEOF_VOID_P 4 +# endif +# define MOO_SIZEOF_FLOAT 4 +# define MOO_SIZEOF_DOUBLE 8 +# define MOO_SIZEOF_LONG_DOUBLE 8 +# define MOO_SIZEOF_WCHAR_T 2 + +# define MOO_SIZEOF___INT8 1 +# define MOO_SIZEOF___INT16 2 +# define MOO_SIZEOF___INT32 4 +# define MOO_SIZEOF___INT64 8 +# define MOO_SIZEOF___INT128 0 + +# define MOO_SIZEOF_OFF64_T 0 +# define MOO_SIZEOF_OFF_T 8 + +# define MOO_SIZEOF_MBSTATE_T MOO_SIZEOF_LONG +# define MOO_MBLEN_MAX 8 + +#else +# error Define the size of various data types. +#endif + diff --git a/stix/lib/stix-os2.h b/stix/lib/moo-os2.h similarity index 54% rename from stix/lib/stix-os2.h rename to stix/lib/moo-os2.h index 9e1bea5..ffc3476 100644 --- a/stix/lib/stix-os2.h +++ b/stix/lib/moo-os2.h @@ -26,62 +26,62 @@ /* OS/2 for other platforms than x86? * If so, the endian should be defined selectively */ -#define STIX_ENDIAN_LITTLE +#define MOO_ENDIAN_LITTLE #if defined(__WATCOMC__) -# define STIX_SIZEOF_CHAR 1 -# define STIX_SIZEOF_SHORT 2 -# define STIX_SIZEOF_INT 4 -# define STIX_SIZEOF_LONG 4 +# define MOO_SIZEOF_CHAR 1 +# define MOO_SIZEOF_SHORT 2 +# define MOO_SIZEOF_INT 4 +# define MOO_SIZEOF_LONG 4 # if (__WATCOMC__ < 1200) -# define STIX_SIZEOF_LONG_LONG 0 +# define MOO_SIZEOF_LONG_LONG 0 # else -# define STIX_SIZEOF_LONG_LONG 8 +# define MOO_SIZEOF_LONG_LONG 8 # endif -# define STIX_SIZEOF_VOID_P 4 -# define STIX_SIZEOF_FLOAT 4 -# define STIX_SIZEOF_DOUBLE 8 -# define STIX_SIZEOF_LONG_DOUBLE 8 -# define STIX_SIZEOF_WCHAR_T 2 +# define MOO_SIZEOF_VOID_P 4 +# define MOO_SIZEOF_FLOAT 4 +# define MOO_SIZEOF_DOUBLE 8 +# define MOO_SIZEOF_LONG_DOUBLE 8 +# define MOO_SIZEOF_WCHAR_T 2 -# define STIX_SIZEOF___INT8 1 -# define STIX_SIZEOF___INT16 2 -# define STIX_SIZEOF___INT32 4 -# define STIX_SIZEOF___INT64 8 -# define STIX_SIZEOF___INT128 0 +# define MOO_SIZEOF___INT8 1 +# define MOO_SIZEOF___INT16 2 +# define MOO_SIZEOF___INT32 4 +# define MOO_SIZEOF___INT64 8 +# define MOO_SIZEOF___INT128 0 -# define STIX_SIZEOF_OFF64_T 0 -# define STIX_SIZEOF_OFF_T 8 +# define MOO_SIZEOF_OFF64_T 0 +# define MOO_SIZEOF_OFF_T 8 /* I don't know the exact mbstate size. * but this should be large enough */ -# define STIX_SIZEOF_MBSTATE_T STIX_SIZEOF_LONG +# define MOO_SIZEOF_MBSTATE_T MOO_SIZEOF_LONG /* TODO: check the exact value */ -# define STIX_MBLEN_MAX 8 +# define MOO_MBLEN_MAX 8 #elif defined(__BORLANDC__) -# define STIX_SIZEOF_CHAR 1 -# define STIX_SIZEOF_SHORT 2 -# define STIX_SIZEOF_INT 4 -# define STIX_SIZEOF_LONG 4 -# define STIX_SIZEOF_LONG_LONG 0 -# define STIX_SIZEOF_VOID_P 4 -# define STIX_SIZEOF_FLOAT 4 -# define STIX_SIZEOF_DOUBLE 8 -# define STIX_SIZEOF_LONG_DOUBLE 8 -# define STIX_SIZEOF_WCHAR_T 2 +# define MOO_SIZEOF_CHAR 1 +# define MOO_SIZEOF_SHORT 2 +# define MOO_SIZEOF_INT 4 +# define MOO_SIZEOF_LONG 4 +# define MOO_SIZEOF_LONG_LONG 0 +# define MOO_SIZEOF_VOID_P 4 +# define MOO_SIZEOF_FLOAT 4 +# define MOO_SIZEOF_DOUBLE 8 +# define MOO_SIZEOF_LONG_DOUBLE 8 +# define MOO_SIZEOF_WCHAR_T 2 -# define STIX_SIZEOF___INT8 0 -# define STIX_SIZEOF___INT16 0 -# define STIX_SIZEOF___INT32 0 -# define STIX_SIZEOF___INT64 0 -# define STIX_SIZEOF___INT128 0 +# define MOO_SIZEOF___INT8 0 +# define MOO_SIZEOF___INT16 0 +# define MOO_SIZEOF___INT32 0 +# define MOO_SIZEOF___INT64 0 +# define MOO_SIZEOF___INT128 0 -# define STIX_SIZEOF_OFF64_T 0 -# define STIX_SIZEOF_OFF_T 4 +# define MOO_SIZEOF_OFF64_T 0 +# define MOO_SIZEOF_OFF_T 4 -# define STIX_SIZEOF_MBSTATE_T STIX_SIZEOF_LONG -# define STIX_MBLEN_MAX 8 +# define MOO_SIZEOF_MBSTATE_T MOO_SIZEOF_LONG +# define MOO_MBLEN_MAX 8 #else # error Define the size of various data types. diff --git a/stix/lib/stix-prv.h b/stix/lib/moo-prv.h similarity index 62% rename from stix/lib/stix-prv.h rename to stix/lib/moo-prv.h index c60b35a..4e3ed51 100644 --- a/stix/lib/stix-prv.h +++ b/stix/lib/moo-prv.h @@ -24,83 +24,83 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _STIX_PRV_H_ -#define _STIX_PRV_H_ +#ifndef _MOO_PRV_H_ +#define _MOO_PRV_H_ -#include "stix.h" -#include "stix-utl.h" +#include "moo.h" +#include "moo-utl.h" /* you can define this to either 1 or 2 */ -#define STIX_BCODE_LONG_PARAM_SIZE 2 +#define MOO_BCODE_LONG_PARAM_SIZE 2 -/* this is useful for debugging. stix_gc() can be called - * while stix has not been fully initialized when this is defined*/ -#define STIX_SUPPORT_GC_DURING_IGNITION +/* this is useful for debugging. moo_gc() can be called + * while moo has not been fully initialized when this is defined*/ +#define MOO_SUPPORT_GC_DURING_IGNITION /* define this to generate XXXX_CTXTEMVAR instructions */ -#define STIX_USE_CTXTEMPVAR +#define MOO_USE_CTXTEMPVAR /* define this to use the MAKE_BLOCK instruction instead of * PUSH_CONTEXT, PUSH_INTLIT, PUSH_INTLIT, SEND_BLOCK_COPY */ -#define STIX_USE_MAKE_BLOCK +#define MOO_USE_MAKE_BLOCK /* this is for gc debugging */ -#define STIX_DEBUG_GC -#define STIX_DEBUG_COMPILER -/*#define STIX_DEBUG_VM_PROCESSOR*/ -/*#define STIX_DEBUG_VM_EXEC*/ -#define STIX_DEBUG_BIGINT -#define STIX_PROFILE_VM +#define MOO_DEBUG_GC +#define MOO_DEBUG_COMPILER +/*#define MOO_DEBUG_VM_PROCESSOR*/ +/*#define MOO_DEBUG_VM_EXEC*/ +#define MOO_DEBUG_BIGINT +#define MOO_PROFILE_VM /* allow the caller to drive process switching by calling - * stix_switchprocess(). */ -#define STIX_EXTERNAL_PROCESS_SWITCH + * moo_switchprocess(). */ +#define MOO_EXTERNAL_PROCESS_SWITCH /* limit the maximum object size such that: * 1. an index to an object field can be represented in a small integer. * 2. the maximum number of bits including bit-shifts can be represented - * in the stix_oow_t type. + * in the moo_oow_t type. */ -#define STIX_LIMIT_OBJ_SIZE +#define MOO_LIMIT_OBJ_SIZE /* TODO: delete these header inclusion lines */ #include #if defined(__has_builtin) # if __has_builtin(__builtin_memset) -# define STIX_MEMSET(dst,src,size) __builtin_memset(dst,src,size) +# define MOO_MEMSET(dst,src,size) __builtin_memset(dst,src,size) # else -# define STIX_MEMSET(dst,src,size) memset(dst,src,size) +# define MOO_MEMSET(dst,src,size) memset(dst,src,size) # endif # if __has_builtin(__builtin_memcpy) -# define STIX_MEMCPY(dst,src,size) __builtin_memcpy(dst,src,size) +# define MOO_MEMCPY(dst,src,size) __builtin_memcpy(dst,src,size) # else -# define STIX_MEMCPY(dst,src,size) memcpy(dst,src,size) +# define MOO_MEMCPY(dst,src,size) memcpy(dst,src,size) # endif # if __has_builtin(__builtin_memmove) -# define STIX_MEMMOVE(dst,src,size) __builtin_memmove(dst,src,size) +# define MOO_MEMMOVE(dst,src,size) __builtin_memmove(dst,src,size) # else -# define STIX_MEMMOVE(dst,src,size) memmove(dst,src,size) +# define MOO_MEMMOVE(dst,src,size) memmove(dst,src,size) # endif # if __has_builtin(__builtin_memcmp) -# define STIX_MEMCMP(dst,src,size) __builtin_memcmp(dst,src,size) +# define MOO_MEMCMP(dst,src,size) __builtin_memcmp(dst,src,size) # else -# define STIX_MEMCMP(dst,src,size) memcmp(dst,src,size) +# define MOO_MEMCMP(dst,src,size) memcmp(dst,src,size) # endif #elif defined(__GNUC__) && (__GNUC__ >= 3 || (defined(__GNUC_MINOR) && __GNUC__ == 2 && __GNUC_MINOR__ >= 91)) /* gcc 2.91 or higher */ -# define STIX_MEMSET(dst,src,size) __builtin_memset(dst,src,size) -# define STIX_MEMCPY(dst,src,size) __builtin_memcpy(dst,src,size) -# define STIX_MEMMOVE(dst,src,size) __builtin_memmove(dst,src,size) -# define STIX_MEMCMP(dst,src,size) __builtin_memcmp(dst,src,size) +# define MOO_MEMSET(dst,src,size) __builtin_memset(dst,src,size) +# define MOO_MEMCPY(dst,src,size) __builtin_memcpy(dst,src,size) +# define MOO_MEMMOVE(dst,src,size) __builtin_memmove(dst,src,size) +# define MOO_MEMCMP(dst,src,size) __builtin_memcmp(dst,src,size) #else -# define STIX_MEMSET(dst,src,size) memset(dst,src,size) -# define STIX_MEMCPY(dst,src,size) memcpy(dst,src,size) -# define STIX_MEMMOVE(dst,src,size) memmove(dst,src,size) -# define STIX_MEMCMP(dst,src,size) memcmp(dst,src,size) +# define MOO_MEMSET(dst,src,size) memset(dst,src,size) +# define MOO_MEMCPY(dst,src,size) memcpy(dst,src,size) +# define MOO_MEMMOVE(dst,src,size) memmove(dst,src,size) +# define MOO_MEMCMP(dst,src,size) memcmp(dst,src,size) #endif -#define STIX_ALIGN(x,y) ((((x) + (y) - 1) / (y)) * (y)) +#define MOO_ALIGN(x,y) ((((x) + (y) - 1) / (y)) * (y)) /* ========================================================================= */ @@ -113,54 +113,54 @@ * named instance variables. If the spec of a class is indexed, the object * of the class can be i nstantiated with the size of the indexed part. * - * For example, on a platform where sizeof(stix_oow_t) is 4, + * For example, on a platform where sizeof(moo_oow_t) is 4, * the layout of the spec field of a class as an OOP value looks like this: * * 31 10 9 8 7 6 5 4 3 2 1 0 * |number of named instance variables|indexed-type|indexability|oop-tag| * * the number of named instance variables is stored in high 23 bits. - * the indexed type takes up bit 3 to bit 8 (assuming STIX_OBJ_TYPE_BITS is 6. - * STIX_OBJ_TYPE_XXX enumerators are used to represent actual values). + * the indexed type takes up bit 3 to bit 8 (assuming MOO_OBJ_TYPE_BITS is 6. + * MOO_OBJ_TYPE_XXX enumerators are used to represent actual values). * and the indexability is stored in bit 2. * * The maximum number of named(fixed) instance variables for a class is: - * 2 ^ ((BITS-IN-OOW - STIX_OOP_TAG_BITS) - STIX_OBJ_TYPE_BITS - 1) - 1 + * 2 ^ ((BITS-IN-OOW - MOO_OOP_TAG_BITS) - MOO_OBJ_TYPE_BITS - 1) - 1 * - * STIX_OOP_TAG_BITS are decremented from the number of bits in OOW because + * MOO_OOP_TAG_BITS are decremented from the number of bits in OOW because * the spec field is always encoded as a small integer. * * The number of named instance variables can be greater than 0 if the * class spec is not indexed or if it's a pointer indexed class - * (indexed_type == STIX_OBJ_TYPE_OOP) + * (indexed_type == MOO_OBJ_TYPE_OOP) * - * indexed_type is one of the #stix_obj_type_t enumerators. + * indexed_type is one of the #moo_obj_type_t enumerators. */ /* - * The STIX_CLASS_SPEC_MAKE() macro creates a class spec value. - * _class->spec = STIX_SMOOI_TO_OOP(STIX_CLASS_SPEC_MAKE(0, 1, STIX_OBJ_TYPE_CHAR)); + * The MOO_CLASS_SPEC_MAKE() macro creates a class spec value. + * _class->spec = MOO_SMOOI_TO_OOP(MOO_CLASS_SPEC_MAKE(0, 1, MOO_OBJ_TYPE_CHAR)); */ -#define STIX_CLASS_SPEC_MAKE(named_instvar,is_indexed,indexed_type) ( \ - (((stix_oow_t)(named_instvar)) << (STIX_OBJ_FLAGS_TYPE_BITS + 1)) | \ - (((stix_oow_t)(indexed_type)) << 1) | (((stix_oow_t)is_indexed) & 1) ) +#define MOO_CLASS_SPEC_MAKE(named_instvar,is_indexed,indexed_type) ( \ + (((moo_oow_t)(named_instvar)) << (MOO_OBJ_FLAGS_TYPE_BITS + 1)) | \ + (((moo_oow_t)(indexed_type)) << 1) | (((moo_oow_t)is_indexed) & 1) ) /* what is the number of named instance variables? - * STIX_CLASS_SPEC_NAMED_INSTVAR(STIX_OOP_TO_SMOOI(_class->spec)) + * MOO_CLASS_SPEC_NAMED_INSTVAR(MOO_OOP_TO_SMOOI(_class->spec)) */ -#define STIX_CLASS_SPEC_NAMED_INSTVAR(spec) \ - (((stix_oow_t)(spec)) >> (STIX_OBJ_FLAGS_TYPE_BITS + 1)) +#define MOO_CLASS_SPEC_NAMED_INSTVAR(spec) \ + (((moo_oow_t)(spec)) >> (MOO_OBJ_FLAGS_TYPE_BITS + 1)) /* is it a user-indexable class? * all objects can be indexed with basicAt:. * this indicates if an object can be instantiated with a dynamic size * (new: size) and and can be indexed with at:. */ -#define STIX_CLASS_SPEC_IS_INDEXED(spec) (((stix_oow_t)(spec)) & 1) +#define MOO_CLASS_SPEC_IS_INDEXED(spec) (((moo_oow_t)(spec)) & 1) /* if so, what is the indexing type? character? pointer? etc? */ -#define STIX_CLASS_SPEC_INDEXED_TYPE(spec) \ - ((((stix_oow_t)(spec)) >> 1) & STIX_LBMASK(stix_oow_t, STIX_OBJ_FLAGS_TYPE_BITS)) +#define MOO_CLASS_SPEC_INDEXED_TYPE(spec) \ + ((((moo_oow_t)(spec)) >> 1) & MOO_LBMASK(moo_oow_t, MOO_OBJ_FLAGS_TYPE_BITS)) /* What is the maximum number of named instance variables? * This limit is set so because the number must be encoded into the spec field @@ -170,11 +170,11 @@ * type of the spec field in the class object. */ /* -#define STIX_MAX_NAMED_INSTVARS \ - STIX_BITS_MAX(stix_oow_t, STIX_OOW_BITS - STIX_OOP_TAG_BITS - (STIX_OBJ_FLAGS_TYPE_BITS + 1) - 1) +#define MOO_MAX_NAMED_INSTVARS \ + MOO_BITS_MAX(moo_oow_t, MOO_OOW_BITS - MOO_OOP_TAG_BITS - (MOO_OBJ_FLAGS_TYPE_BITS + 1) - 1) */ -#define STIX_MAX_NAMED_INSTVARS \ - STIX_BITS_MAX(stix_oow_t, STIX_SMOOI_ABS_BITS - (STIX_OBJ_FLAGS_TYPE_BITS + 1)) +#define MOO_MAX_NAMED_INSTVARS \ + MOO_BITS_MAX(moo_oow_t, MOO_SMOOI_ABS_BITS - (MOO_OBJ_FLAGS_TYPE_BITS + 1)) /* Given the number of named instance variables, what is the maximum number * of indexed instance variables? The number of indexed instance variables @@ -183,74 +183,74 @@ * named instance variables. So it's the maximum value of obj->_size minus * the number of named instance variables. */ -#define STIX_MAX_INDEXED_INSTVARS(named_instvar) (STIX_OBJ_SIZE_MAX - named_instvar) +#define MOO_MAX_INDEXED_INSTVARS(named_instvar) (MOO_OBJ_SIZE_MAX - named_instvar) /* -#define STIX_CLASS_SELFSPEC_MAKE(class_var,classinst_var) \ - (((stix_oow_t)class_var) << ((STIX_OOW_BITS - STIX_OOP_TAG_BITS) / 2)) | ((stix_oow_t)classinst_var) +#define MOO_CLASS_SELFSPEC_MAKE(class_var,classinst_var) \ + (((moo_oow_t)class_var) << ((MOO_OOW_BITS - MOO_OOP_TAG_BITS) / 2)) | ((moo_oow_t)classinst_var) */ -#define STIX_CLASS_SELFSPEC_MAKE(class_var,classinst_var) \ - (((stix_oow_t)class_var) << (STIX_SMOOI_BITS / 2)) | ((stix_oow_t)classinst_var) +#define MOO_CLASS_SELFSPEC_MAKE(class_var,classinst_var) \ + (((moo_oow_t)class_var) << (MOO_SMOOI_BITS / 2)) | ((moo_oow_t)classinst_var) /* -#define STIX_CLASS_SELFSPEC_CLASSVAR(spec) ((stix_oow_t)spec >> ((STIX_OOW_BITS - STIX_OOP_TAG_BITS) / 2)) -#define STIX_CLASS_SELFSPEC_CLASSINSTVAR(spec) (((stix_oow_t)spec) & STIX_LBMASK(stix_oow_t, (STIX_OOW_BITS - STIX_OOP_TAG_BITS) / 2)) +#define MOO_CLASS_SELFSPEC_CLASSVAR(spec) ((moo_oow_t)spec >> ((MOO_OOW_BITS - MOO_OOP_TAG_BITS) / 2)) +#define MOO_CLASS_SELFSPEC_CLASSINSTVAR(spec) (((moo_oow_t)spec) & MOO_LBMASK(moo_oow_t, (MOO_OOW_BITS - MOO_OOP_TAG_BITS) / 2)) */ -#define STIX_CLASS_SELFSPEC_CLASSVAR(spec) ((stix_oow_t)spec >> (STIX_SMOOI_BITS / 2)) -#define STIX_CLASS_SELFSPEC_CLASSINSTVAR(spec) (((stix_oow_t)spec) & STIX_LBMASK(stix_oow_t, (STIX_SMOOI_BITS / 2))) +#define MOO_CLASS_SELFSPEC_CLASSVAR(spec) ((moo_oow_t)spec >> (MOO_SMOOI_BITS / 2)) +#define MOO_CLASS_SELFSPEC_CLASSINSTVAR(spec) (((moo_oow_t)spec) & MOO_LBMASK(moo_oow_t, (MOO_SMOOI_BITS / 2))) /* * yet another -1 in the calculation of the bit numbers for signed nature of * a small-integer */ /* -#define STIX_MAX_CLASSVARS STIX_BITS_MAX(stix_oow_t, (STIX_OOW_BITS - STIX_OOP_TAG_BITS - 1) / 2) -#define STIX_MAX_CLASSINSTVARS STIX_BITS_MAX(stix_oow_t, (STIX_OOW_BITS - STIX_OOP_TAG_BITS - 1) / 2) +#define MOO_MAX_CLASSVARS MOO_BITS_MAX(moo_oow_t, (MOO_OOW_BITS - MOO_OOP_TAG_BITS - 1) / 2) +#define MOO_MAX_CLASSINSTVARS MOO_BITS_MAX(moo_oow_t, (MOO_OOW_BITS - MOO_OOP_TAG_BITS - 1) / 2) */ -#define STIX_MAX_CLASSVARS STIX_BITS_MAX(stix_oow_t, STIX_SMOOI_ABS_BITS / 2) -#define STIX_MAX_CLASSINSTVARS STIX_BITS_MAX(stix_oow_t, STIX_SMOOI_ABS_BITS / 2) +#define MOO_MAX_CLASSVARS MOO_BITS_MAX(moo_oow_t, MOO_SMOOI_ABS_BITS / 2) +#define MOO_MAX_CLASSINSTVARS MOO_BITS_MAX(moo_oow_t, MOO_SMOOI_ABS_BITS / 2) -#if defined(STIX_LIMIT_OBJ_SIZE) +#if defined(MOO_LIMIT_OBJ_SIZE) /* limit the maximum object size such that: * 1. an index to an object field can be represented in a small integer. - * 2. the maximum number of bit shifts can be represented in the stix_oow_t type. + * 2. the maximum number of bit shifts can be represented in the moo_oow_t type. */ -# define STIX_OBJ_SIZE_MAX ((stix_oow_t)STIX_SMOOI_MAX) -# define STIX_OBJ_SIZE_BITS_MAX (STIX_OBJ_SIZE_MAX * 8) +# define MOO_OBJ_SIZE_MAX ((moo_oow_t)MOO_SMOOI_MAX) +# define MOO_OBJ_SIZE_BITS_MAX (MOO_OBJ_SIZE_MAX * 8) #else -# define STIX_OBJ_SIZE_MAX ((stix_oow_t)STIX_TYPE_MAX(stix_oow_t)) -# define STIX_OBJ_SIZE_BITS_MAX (STIX_OBJ_SIZE_MAX * 8) +# define MOO_OBJ_SIZE_MAX ((moo_oow_t)MOO_TYPE_MAX(moo_oow_t)) +# define MOO_OBJ_SIZE_BITS_MAX (MOO_OBJ_SIZE_MAX * 8) #endif -#if defined(STIX_INCLUDE_COMPILER) +#if defined(MOO_INCLUDE_COMPILER) /* ========================================================================= */ /* SOURCE CODE I/O FOR COMPILER */ /* ========================================================================= */ -struct stix_iolxc_t +struct moo_iolxc_t { - stix_ooci_t c; /**< character */ - stix_ioloc_t l; /**< location */ + moo_ooci_t c; /**< character */ + moo_ioloc_t l; /**< location */ }; -typedef struct stix_iolxc_t stix_iolxc_t; +typedef struct moo_iolxc_t moo_iolxc_t; /* -enum stix_ioarg_flag_t +enum moo_ioarg_flag_t { - STIX_IO_INCLUDED = (1 << 0) + MOO_IO_INCLUDED = (1 << 0) }; -typedef enum stix_ioarg_flag_t stix_ioarg_flag_t; */ +typedef enum moo_ioarg_flag_t moo_ioarg_flag_t; */ -struct stix_ioarg_t +struct moo_ioarg_t { /** * [IN] I/O object name. - * It is #STIX_NULL for the main stream and points to a non-NULL string + * It is #MOO_NULL for the main stream and points to a non-NULL string * for an included stream. */ - const stix_ooch_t* name; + const moo_ooch_t* name; /** * [OUT] I/O handle set by an open handler. @@ -264,13 +264,13 @@ struct stix_ioarg_t /** * [OUT] place data here */ - stix_ooch_t buf[1024]; + moo_ooch_t buf[1024]; /** - * [IN] points to the data of the includer. It is #STIX_NULL for the + * [IN] points to the data of the includer. It is #MOO_NULL for the * main stream. */ - stix_ioarg_t* includer; + moo_ioarg_t* includer; /*-----------------------------------------------------------------*/ /*----------- from here down, internal use only -------------------*/ @@ -281,104 +281,105 @@ struct stix_ioarg_t unsigned long int line; unsigned long int colm; - stix_ooci_t nl; + moo_ooci_t nl; - stix_iolxc_t lxc; + moo_iolxc_t lxc; /*-----------------------------------------------------------------*/ }; -struct stix_iotok_t +struct moo_iotok_t { enum { - STIX_IOTOK_EOF, + MOO_IOTOK_EOF, - STIX_IOTOK_CHARLIT, - STIX_IOTOK_STRLIT, - STIX_IOTOK_SYMLIT, - STIX_IOTOK_NUMLIT, - STIX_IOTOK_RADNUMLIT, - STIX_IOTOK_ERRLIT, /* error(NN) */ - STIX_IOTOK_ERROR, /* error */ - STIX_IOTOK_NIL, - STIX_IOTOK_SELF, - STIX_IOTOK_SUPER, - STIX_IOTOK_TRUE, - STIX_IOTOK_FALSE, - STIX_IOTOK_THIS_CONTEXT, - STIX_IOTOK_THIS_PROCESS, - STIX_IOTOK_IDENT, - STIX_IOTOK_IDENT_DOTTED, - STIX_IOTOK_BINSEL, - STIX_IOTOK_KEYWORD, - STIX_IOTOK_ASSIGN, - STIX_IOTOK_COLON, - STIX_IOTOK_RETURN, - STIX_IOTOK_LBRACE, - STIX_IOTOK_RBRACE, - STIX_IOTOK_LBRACK, - STIX_IOTOK_RBRACK, - STIX_IOTOK_LPAREN, - STIX_IOTOK_RPAREN, - STIX_IOTOK_ARPAREN, /* #( */ - STIX_IOTOK_BAPAREN, /* #[ */ - STIX_IOTOK_PERIOD, - STIX_IOTOK_COMMA, - STIX_IOTOK_SEMICOLON + MOO_IOTOK_CHARLIT, + MOO_IOTOK_STRLIT, + MOO_IOTOK_SYMLIT, + MOO_IOTOK_NUMLIT, + MOO_IOTOK_RADNUMLIT, + MOO_IOTOK_ERRLIT, /* error(NN) */ + MOO_IOTOK_ERROR, /* error */ + MOO_IOTOK_NIL, + MOO_IOTOK_SELF, + MOO_IOTOK_SUPER, + MOO_IOTOK_TRUE, + MOO_IOTOK_FALSE, + MOO_IOTOK_THIS_CONTEXT, + MOO_IOTOK_THIS_PROCESS, + MOO_IOTOK_IF, + MOO_IOTOK_IDENT, + MOO_IOTOK_IDENT_DOTTED, + MOO_IOTOK_BINSEL, + MOO_IOTOK_KEYWORD, + MOO_IOTOK_ASSIGN, + MOO_IOTOK_COLON, + MOO_IOTOK_RETURN, + MOO_IOTOK_LBRACE, + MOO_IOTOK_RBRACE, + MOO_IOTOK_LBRACK, + MOO_IOTOK_RBRACK, + MOO_IOTOK_LPAREN, + MOO_IOTOK_RPAREN, + MOO_IOTOK_ARPAREN, /* #( */ + MOO_IOTOK_BAPAREN, /* #[ */ + MOO_IOTOK_PERIOD, + MOO_IOTOK_COMMA, + MOO_IOTOK_SEMICOLON } type; - stix_oocs_t name; - stix_oow_t name_capa; + moo_oocs_t name; + moo_oow_t name_capa; - stix_ioloc_t loc; + moo_ioloc_t loc; }; -typedef struct stix_iotok_t stix_iotok_t; +typedef struct moo_iotok_t moo_iotok_t; -typedef struct stix_iolink_t stix_iolink_t; -struct stix_iolink_t +typedef struct moo_iolink_t moo_iolink_t; +struct moo_iolink_t { - stix_iolink_t* link; + moo_iolink_t* link; }; -struct stix_code_t +struct moo_code_t { - stix_uint8_t* ptr; - stix_oow_t len; + moo_uint8_t* ptr; + moo_oow_t len; }; -typedef struct stix_code_t stix_code_t; +typedef struct moo_code_t moo_code_t; -struct stix_compiler_t +struct moo_compiler_t { /* input handler */ - stix_ioimpl_t impl; + moo_ioimpl_t impl; /* information about the last meaningful character read. * this is a copy of curinp->lxc if no ungetting is performed. * if there is something in the unget buffer, this is overwritten * by a value from the buffer when the request to read a character * is served */ - stix_iolxc_t lxc; + moo_iolxc_t lxc; /* unget buffer */ - stix_iolxc_t ungot[10]; + moo_iolxc_t ungot[10]; int nungots; /* static input data buffer */ - stix_ioarg_t arg; + moo_ioarg_t arg; /* pointer to the current input data. initially, it points to &arg */ - stix_ioarg_t* curinp; + moo_ioarg_t* curinp; /* the last token read */ - stix_iotok_t tok; - stix_iolink_t* io_names; + moo_iotok_t tok; + moo_iolink_t* io_names; int in_array; - stix_synerr_t synerr; + moo_synerr_t synerr; /* temporary space to handle an illegal character */ - stix_ooch_t ilchr; - stix_oocs_t ilchr_ucs; + moo_ooch_t ilchr; + moo_oocs_t ilchr_ucs; /* information about a class being compiled */ struct @@ -386,141 +387,141 @@ struct stix_compiler_t int flags; int indexed_type; - stix_oop_class_t self_oop; - stix_oop_t super_oop; /* this may be nil. so the type is stix_oop_t */ + moo_oop_class_t self_oop; + moo_oop_t super_oop; /* this may be nil. so the type is moo_oop_t */ #ifdef MTHDIC - stix_oop_set_t mthdic_oop[2]; /* used when compiling a method definition */ + moo_oop_set_t mthdic_oop[2]; /* used when compiling a method definition */ #endif - stix_oop_set_t pooldic_oop; /* used when compiling a pooldic definition */ - stix_oop_set_t ns_oop; - stix_oocs_t fqn; - stix_oocs_t name; - stix_oow_t fqn_capa; - stix_ioloc_t fqn_loc; + moo_oop_set_t pooldic_oop; /* used when compiling a pooldic definition */ + moo_oop_set_t ns_oop; + moo_oocs_t fqn; + moo_oocs_t name; + moo_oow_t fqn_capa; + moo_ioloc_t fqn_loc; - stix_oop_set_t superns_oop; - stix_oocs_t superfqn; - stix_oocs_t supername; - stix_oow_t superfqn_capa; - stix_ioloc_t superfqn_loc; + moo_oop_set_t superns_oop; + moo_oocs_t superfqn; + moo_oocs_t supername; + moo_oow_t superfqn_capa; + moo_ioloc_t superfqn_loc; /* instance variable, class variable, class instance variable */ - stix_oocs_t vars[3]; - stix_oow_t vars_capa[3]; + moo_oocs_t vars[3]; + moo_oow_t vars_capa[3]; /* var_count, unlike vars above, includes superclass counts as well. * var_count[0] - number of named instance variables * var_count[1] - number of class variables * var_count[2] - number of class instance variables */ - stix_oow_t var_count[3]; + moo_oow_t var_count[3]; /* buffer to hold pooldic import declaration */ - stix_oocs_t pooldic; - stix_oow_t pooldic_capa; - stix_oow_t pooldic_count; + moo_oocs_t pooldic; + moo_oow_t pooldic_capa; + moo_oow_t pooldic_count; /* used to hold imported pool dictionarie objects */ - stix_oop_set_t* pooldic_imp_oops; - stix_oow_t pooldic_imp_oops_capa; + moo_oop_set_t* pooldic_imp_oops; + moo_oow_t pooldic_imp_oops_capa; } cls; /* information about a method being comipled */ struct { - stix_method_type_t type; + moo_method_type_t type; /* method source text */ - stix_oocs_t text; - stix_oow_t text_capa; + moo_oocs_t text; + moo_oow_t text_capa; /* buffer to store identifier names to be assigned */ - stix_oocs_t assignees; - stix_oow_t assignees_capa; + moo_oocs_t assignees; + moo_oow_t assignees_capa; /* buffer to store binary selectors being worked on */ - stix_oocs_t binsels; - stix_oow_t binsels_capa; + moo_oocs_t binsels; + moo_oow_t binsels_capa; /* buffer to store keyword selectors being worked on */ - stix_oocs_t kwsels; - stix_oow_t kwsels_capa; + moo_oocs_t kwsels; + moo_oow_t kwsels_capa; /* method name */ - stix_oocs_t name; - stix_oow_t name_capa; - stix_ioloc_t name_loc; + moo_oocs_t name; + moo_oow_t name_capa; + moo_ioloc_t name_loc; /* is the unary method followed by parameter list? */ int variadic; /* single string containing a space separated list of temporaries */ - stix_oocs_t tmprs; - stix_oow_t tmprs_capa; - stix_oow_t tmpr_count; /* total number of temporaries including arguments */ - stix_oow_t tmpr_nargs; + moo_oocs_t tmprs; + moo_oow_t tmprs_capa; + moo_oow_t tmpr_count; /* total number of temporaries including arguments */ + moo_oow_t tmpr_nargs; /* literals */ - stix_oop_t* literals; - stix_oow_t literal_count; - stix_oow_t literal_capa; + moo_oop_t* literals; + moo_oow_t literal_count; + moo_oow_t literal_capa; /* byte array elements */ - stix_oob_t* balit; - stix_oow_t balit_count; - stix_oow_t balit_capa; + moo_oob_t* balit; + moo_oow_t balit_count; + moo_oow_t balit_capa; /* array elements */ - stix_oop_t* arlit; - stix_oow_t arlit_count; - stix_oow_t arlit_capa; + moo_oop_t* arlit; + moo_oow_t arlit_count; + moo_oow_t arlit_capa; /* 0 for no primitive, 1 for a normal primitive, 2 for a named primitive */ int pftype; /* primitive function number */ - stix_ooi_t pfnum; + moo_ooi_t pfnum; /* block depth */ - stix_oow_t blk_depth; - stix_oow_t* blk_tmprcnt; - stix_oow_t blk_tmprcnt_capa; + moo_oow_t blk_depth; + moo_oow_t* blk_tmprcnt; + moo_oow_t blk_tmprcnt_capa; /* byte code */ - stix_code_t code; - stix_oow_t code_capa; + moo_code_t code; + moo_oow_t code_capa; } mth; }; /* -typedef struct stix_bchbuf_t stix_bchbuf_t; -struct stix_bchbuf_t +typedef struct moo_bchbuf_t moo_bchbuf_t; +struct moo_bchbuf_t { - stix_bch_t buf[128]; - stix_bch_t* ptr; - stix_oow_t capa; + moo_bch_t buf[128]; + moo_bch_t* ptr; + moo_oow_t capa; }; -typedef struct stix_oochbuf_t stix_oochbuf_t; -struct stix_oochbuf_t +typedef struct moo_oochbuf_t moo_oochbuf_t; +struct moo_oochbuf_t { - stix_ooch_t buf[128]; - stix_ooch_t* ptr; - stix_oow_t capa; + moo_ooch_t buf[128]; + moo_ooch_t* ptr; + moo_oow_t capa; }; */ #endif -#if defined(STIX_USE_OBJECT_TRAILER) +#if defined(MOO_USE_OBJECT_TRAILER) /* let it point to the trailer of the method */ -# define SET_ACTIVE_METHOD_CODE(stix) ((stix)->active_code = (stix_oob_t*)&(stix)->active_method->slot[STIX_OBJ_GET_SIZE((stix)->active_method) + 1 - STIX_METHOD_NAMED_INSTVARS]) +# define SET_ACTIVE_METHOD_CODE(moo) ((moo)->active_code = (moo_oob_t*)&(moo)->active_method->slot[MOO_OBJ_GET_SIZE((moo)->active_method) + 1 - MOO_METHOD_NAMED_INSTVARS]) #else /* let it point to the payload of the code byte array */ -# define SET_ACTIVE_METHOD_CODE(stix) ((stix)->active_code = (stix)->active_method->code->slot) +# define SET_ACTIVE_METHOD_CODE(moo) ((moo)->active_code = (moo)->active_method->code->slot) #endif -#if defined(STIX_BCODE_LONG_PARAM_SIZE) && (STIX_BCODE_LONG_PARAM_SIZE == 1) +#if defined(MOO_BCODE_LONG_PARAM_SIZE) && (MOO_BCODE_LONG_PARAM_SIZE == 1) # define MAX_CODE_INDEX (0xFFu) # define MAX_CODE_NTMPRS (0xFFu) # define MAX_CODE_NARGS (0xFFu) @@ -528,7 +529,7 @@ struct stix_oochbuf_t # define MAX_CODE_NBLKTMPRS (0xFFu) # define MAX_CODE_JUMP (0xFFu) # define MAX_CODE_PARAM (0xFFu) -#elif defined(STIX_BCODE_LONG_PARAM_SIZE) && (STIX_BCODE_LONG_PARAM_SIZE == 2) +#elif defined(MOO_BCODE_LONG_PARAM_SIZE) && (MOO_BCODE_LONG_PARAM_SIZE == 2) # define MAX_CODE_INDEX (0xFFFFu) # define MAX_CODE_NTMPRS (0xFFFFu) # define MAX_CODE_NARGS (0xFFFFu) @@ -537,7 +538,7 @@ struct stix_oochbuf_t # define MAX_CODE_JUMP (0xFFFFu) # define MAX_CODE_PARAM (0xFFFFu) #else -# error Unsupported STIX_BCODE_LONG_PARAM_SIZE +# error Unsupported MOO_BCODE_LONG_PARAM_SIZE #endif @@ -602,7 +603,7 @@ SHORT INSTRUCTION CODE LONG INSTRUCTION C ## */ -enum stix_bcode_t +enum moo_bcode_t { BCODE_STORE_INTO_INSTVAR_0 = 0x00, BCODE_STORE_INTO_INSTVAR_1 = 0x01, @@ -827,315 +828,315 @@ extern "C" { /* ========================================================================= */ /** - * The stix_makeheap() function creates a new heap of the \a size bytes. + * The moo_makeheap() function creates a new heap of the \a size bytes. * - * \return heap pointer on success and #STIX_NULL on failure. + * \return heap pointer on success and #MOO_NULL on failure. */ -stix_heap_t* stix_makeheap ( - stix_t* stix, - stix_oow_t size +moo_heap_t* moo_makeheap ( + moo_t* moo, + moo_oow_t size ); /** - * The stix_killheap() function destroys the heap pointed to by \a heap. + * The moo_killheap() function destroys the heap pointed to by \a heap. */ -void stix_killheap ( - stix_t* stix, - stix_heap_t* heap +void moo_killheap ( + moo_t* moo, + moo_heap_t* heap ); /** - * The stix_allocheapmem() function allocates \a size bytes in the heap pointed + * The moo_allocheapmem() function allocates \a size bytes in the heap pointed * to by \a heap. * - * \return memory pointer on success and #STIX_NULL on failure. + * \return memory pointer on success and #MOO_NULL on failure. */ -void* stix_allocheapmem ( - stix_t* stix, - stix_heap_t* heap, - stix_oow_t size +void* moo_allocheapmem ( + moo_t* moo, + moo_heap_t* heap, + moo_oow_t size ); /* ========================================================================= */ /* gc.c */ /* ========================================================================= */ -stix_oop_t stix_moveoop ( - stix_t* stix, - stix_oop_t oop +moo_oop_t moo_moveoop ( + moo_t* moo, + moo_oop_t oop ); /* ========================================================================= */ /* obj.c */ /* ========================================================================= */ -void* stix_allocbytes ( - stix_t* stix, - stix_oow_t size +void* moo_allocbytes ( + moo_t* moo, + moo_oow_t size ); /** - * The stix_allocoopobj() function allocates a raw object composed of \a size + * The moo_allocoopobj() function allocates a raw object composed of \a size * pointer fields excluding the header. */ -stix_oop_t stix_allocoopobj ( - stix_t* stix, - stix_oow_t size +moo_oop_t moo_allocoopobj ( + moo_t* moo, + moo_oow_t size ); -#if defined(STIX_USE_OBJECT_TRAILER) -stix_oop_t stix_allocoopobjwithtrailer ( - stix_t* stix, - stix_oow_t size, - const stix_oob_t* tptr, - stix_oow_t tlen +#if defined(MOO_USE_OBJECT_TRAILER) +moo_oop_t moo_allocoopobjwithtrailer ( + moo_t* moo, + moo_oow_t size, + const moo_oob_t* tptr, + moo_oow_t tlen ); #endif -stix_oop_t stix_alloccharobj ( - stix_t* stix, - const stix_ooch_t* ptr, - stix_oow_t len +moo_oop_t moo_alloccharobj ( + moo_t* moo, + const moo_ooch_t* ptr, + moo_oow_t len ); -stix_oop_t stix_allocbyteobj ( - stix_t* stix, - const stix_oob_t* ptr, - stix_oow_t len +moo_oop_t moo_allocbyteobj ( + moo_t* moo, + const moo_oob_t* ptr, + moo_oow_t len ); -stix_oop_t stix_allochalfwordobj ( - stix_t* stix, - const stix_oohw_t* ptr, - stix_oow_t len +moo_oop_t moo_allochalfwordobj ( + moo_t* moo, + const moo_oohw_t* ptr, + moo_oow_t len ); -stix_oop_t stix_allocwordobj ( - stix_t* stix, - const stix_oow_t* ptr, - stix_oow_t len +moo_oop_t moo_allocwordobj ( + moo_t* moo, + const moo_oow_t* ptr, + moo_oow_t len ); -#if defined(STIX_USE_OBJECT_TRAILER) -stix_oop_t stix_instantiatewithtrailer ( - stix_t* stix, - stix_oop_t _class, - stix_oow_t vlen, - const stix_oob_t* tptr, - stix_oow_t tlen +#if defined(MOO_USE_OBJECT_TRAILER) +moo_oop_t moo_instantiatewithtrailer ( + moo_t* moo, + moo_oop_t _class, + moo_oow_t vlen, + const moo_oob_t* tptr, + moo_oow_t tlen ); #endif /* ========================================================================= */ /* sym.c */ /* ========================================================================= */ -stix_oop_t stix_makesymbol ( - stix_t* stix, - const stix_ooch_t* ptr, - stix_oow_t len +moo_oop_t moo_makesymbol ( + moo_t* moo, + const moo_ooch_t* ptr, + moo_oow_t len ); -stix_oop_t stix_findsymbol ( - stix_t* stix, - const stix_ooch_t* ptr, - stix_oow_t len +moo_oop_t moo_findsymbol ( + moo_t* moo, + const moo_ooch_t* ptr, + moo_oow_t len ); -stix_oop_t stix_makestring ( - stix_t* stix, - const stix_ooch_t* ptr, - stix_oow_t len +moo_oop_t moo_makestring ( + moo_t* moo, + const moo_ooch_t* ptr, + moo_oow_t len ); /* ========================================================================= */ /* dic.c */ /* ========================================================================= */ -stix_oop_association_t stix_putatsysdic ( - stix_t* stix, - stix_oop_t key, - stix_oop_t value +moo_oop_association_t moo_putatsysdic ( + moo_t* moo, + moo_oop_t key, + moo_oop_t value ); -stix_oop_association_t stix_getatsysdic ( - stix_t* stix, - stix_oop_t key +moo_oop_association_t moo_getatsysdic ( + moo_t* moo, + moo_oop_t key ); -stix_oop_association_t stix_lookupsysdic ( - stix_t* stix, - const stix_oocs_t* name +moo_oop_association_t moo_lookupsysdic ( + moo_t* moo, + const moo_oocs_t* name ); -stix_oop_association_t stix_putatdic ( - stix_t* stix, - stix_oop_set_t dic, - stix_oop_t key, - stix_oop_t value +moo_oop_association_t moo_putatdic ( + moo_t* moo, + moo_oop_set_t dic, + moo_oop_t key, + moo_oop_t value ); -stix_oop_association_t stix_getatdic ( - stix_t* stix, - stix_oop_set_t dic, - stix_oop_t key +moo_oop_association_t moo_getatdic ( + moo_t* moo, + moo_oop_set_t dic, + moo_oop_t key ); -stix_oop_association_t stix_lookupdic ( - stix_t* stix, - stix_oop_set_t dic, - const stix_oocs_t* name +moo_oop_association_t moo_lookupdic ( + moo_t* moo, + moo_oop_set_t dic, + const moo_oocs_t* name ); -int stix_deletedic ( - stix_t* stix, - stix_oop_set_t dic, - const stix_oocs_t* name +int moo_deletedic ( + moo_t* moo, + moo_oop_set_t dic, + const moo_oocs_t* name ); -stix_oop_set_t stix_makedic ( - stix_t* stix, - stix_oop_t cls, - stix_oow_t size +moo_oop_set_t moo_makedic ( + moo_t* moo, + moo_oop_t cls, + moo_oow_t size ); /* ========================================================================= */ /* proc.c */ /* ========================================================================= */ -stix_oop_process_t stix_makeproc ( - stix_t* stix +moo_oop_process_t moo_makeproc ( + moo_t* moo ); /* ========================================================================= */ /* bigint.c */ /* ========================================================================= */ -int stix_isint ( - stix_t* stix, - stix_oop_t x +int moo_isint ( + moo_t* moo, + moo_oop_t x ); -int stix_inttooow ( - stix_t* stix, - stix_oop_t x, - stix_oow_t* w +int moo_inttooow ( + moo_t* moo, + moo_oop_t x, + moo_oow_t* w ); -stix_oop_t stix_oowtoint ( - stix_t* stix, - stix_oow_t w +moo_oop_t moo_oowtoint ( + moo_t* moo, + moo_oow_t w ); -stix_oop_t stix_addints ( - stix_t* stix, - stix_oop_t x, - stix_oop_t y +moo_oop_t moo_addints ( + moo_t* moo, + moo_oop_t x, + moo_oop_t y ); -stix_oop_t stix_subints ( - stix_t* stix, - stix_oop_t x, - stix_oop_t y +moo_oop_t moo_subints ( + moo_t* moo, + moo_oop_t x, + moo_oop_t y ); -stix_oop_t stix_mulints ( - stix_t* stix, - stix_oop_t x, - stix_oop_t y +moo_oop_t moo_mulints ( + moo_t* moo, + moo_oop_t x, + moo_oop_t y ); -stix_oop_t stix_divints ( - stix_t* stix, - stix_oop_t x, - stix_oop_t y, +moo_oop_t moo_divints ( + moo_t* moo, + moo_oop_t x, + moo_oop_t y, int modulo, - stix_oop_t* rem + moo_oop_t* rem ); -stix_oop_t stix_negateint ( - stix_t* stix, - stix_oop_t x +moo_oop_t moo_negateint ( + moo_t* moo, + moo_oop_t x ); -stix_oop_t stix_bitatint ( - stix_t* stix, - stix_oop_t x, - stix_oop_t y +moo_oop_t moo_bitatint ( + moo_t* moo, + moo_oop_t x, + moo_oop_t y ); -stix_oop_t stix_bitandints ( - stix_t* stix, - stix_oop_t x, - stix_oop_t y +moo_oop_t moo_bitandints ( + moo_t* moo, + moo_oop_t x, + moo_oop_t y ); -stix_oop_t stix_bitorints ( - stix_t* stix, - stix_oop_t x, - stix_oop_t y +moo_oop_t moo_bitorints ( + moo_t* moo, + moo_oop_t x, + moo_oop_t y ); -stix_oop_t stix_bitxorints ( - stix_t* stix, - stix_oop_t x, - stix_oop_t y +moo_oop_t moo_bitxorints ( + moo_t* moo, + moo_oop_t x, + moo_oop_t y ); -stix_oop_t stix_bitinvint ( - stix_t* stix, - stix_oop_t x +moo_oop_t moo_bitinvint ( + moo_t* moo, + moo_oop_t x ); -stix_oop_t stix_bitshiftint ( - stix_t* stix, - stix_oop_t x, - stix_oop_t y +moo_oop_t moo_bitshiftint ( + moo_t* moo, + moo_oop_t x, + moo_oop_t y ); -stix_oop_t stix_eqints ( - stix_t* stix, - stix_oop_t x, - stix_oop_t y +moo_oop_t moo_eqints ( + moo_t* moo, + moo_oop_t x, + moo_oop_t y ); -stix_oop_t stix_neints ( - stix_t* stix, - stix_oop_t x, - stix_oop_t y +moo_oop_t moo_neints ( + moo_t* moo, + moo_oop_t x, + moo_oop_t y ); -stix_oop_t stix_gtints ( - stix_t* stix, - stix_oop_t x, - stix_oop_t y +moo_oop_t moo_gtints ( + moo_t* moo, + moo_oop_t x, + moo_oop_t y ); -stix_oop_t stix_geints ( - stix_t* stix, - stix_oop_t x, - stix_oop_t y +moo_oop_t moo_geints ( + moo_t* moo, + moo_oop_t x, + moo_oop_t y ); -stix_oop_t stix_ltints ( - stix_t* stix, - stix_oop_t x, - stix_oop_t y +moo_oop_t moo_ltints ( + moo_t* moo, + moo_oop_t x, + moo_oop_t y ); -stix_oop_t stix_leints ( - stix_t* stix, - stix_oop_t x, - stix_oop_t y +moo_oop_t moo_leints ( + moo_t* moo, + moo_oop_t x, + moo_oop_t y ); -stix_oop_t stix_strtoint ( - stix_t* stix, - const stix_ooch_t* str, - stix_oow_t len, +moo_oop_t moo_strtoint ( + moo_t* moo, + const moo_ooch_t* str, + moo_oow_t len, int radix ); -stix_oop_t stix_inttostr ( - stix_t* stix, - stix_oop_t num, +moo_oop_t moo_inttostr ( + moo_t* moo, + moo_oop_t num, int radix ); @@ -1143,43 +1144,43 @@ stix_oop_t stix_inttostr ( /* exec.c */ /* ========================================================================= */ -int stix_getpfnum ( - stix_t* stix, - const stix_ooch_t* ptr, - stix_oow_t len +int moo_getpfnum ( + moo_t* moo, + const moo_ooch_t* ptr, + moo_oow_t len ); /* ========================================================================= */ -/* stix.c */ +/* moo.c */ /* ========================================================================= */ -stix_mod_data_t* stix_openmod ( - stix_t* stix, - const stix_ooch_t* name, - stix_oow_t namelen +moo_mod_data_t* moo_openmod ( + moo_t* moo, + const moo_ooch_t* name, + moo_oow_t namelen ); -void stix_closemod ( - stix_t* stix, - stix_mod_data_t* mdp +void moo_closemod ( + moo_t* moo, + moo_mod_data_t* mdp ); -int stix_importmod ( - stix_t* stix, - stix_oop_t _class, - const stix_ooch_t* name, - stix_oow_t len +int moo_importmod ( + moo_t* moo, + moo_oop_t _class, + const moo_ooch_t* name, + moo_oow_t len ); /* - * The stix_querymod() function finds a primitive function in modules + * The moo_querymod() function finds a primitive function in modules * with a full primitive identifier. */ -stix_pfimpl_t stix_querymod ( - stix_t* stix, - const stix_ooch_t* pfid, - stix_oow_t pfidlen +moo_pfimpl_t moo_querymod ( + moo_t* moo, + const moo_ooch_t* pfid, + moo_oow_t pfidlen ); @@ -1187,8 +1188,8 @@ stix_pfimpl_t stix_querymod ( /* ========================================================================= */ /* debug.c */ /* ========================================================================= */ -void stix_dumpsymtab (stix_t* stix); -void stix_dumpdic (stix_t* stix, stix_oop_set_t dic, const stix_bch_t* title); +void moo_dumpsymtab (moo_t* moo); +void moo_dumpdic (moo_t* moo, moo_oop_set_t dic, const moo_bch_t* title); #if defined(__cplusplus) diff --git a/stix/lib/moo-rbt.h b/stix/lib/moo-rbt.h new file mode 100644 index 0000000..0956876 --- /dev/null +++ b/stix/lib/moo-rbt.h @@ -0,0 +1,603 @@ +/* + * $Id$ + * + Copyright (c) 2014-2016 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 _MOO_RBT_H_ +#define _MOO_RBT_H_ + +#include "moo-cmn.h" + +/**@file + * This file provides a red-black tree encapsulated in the #moo_rbt_t type that + * implements a self-balancing binary search tree.Its interface is very close + * to #moo_htb_t. + * + * This sample code adds a series of keys and values and print them + * in descending key order. + * @code + * #include + * #include + * #include + * + * static moo_rbt_walk_t walk (moo_rbt_t* rbt, moo_rbt_pair_t* pair, void* ctx) + * { + * moo_printf (MOO_T("key = %d, value = %d\n"), + * *(int*)MOO_RBT_KPTR(pair), *(int*)MOO_RBT_VPTR(pair)); + * return MOO_RBT_WALK_FORWARD; + * } + * + * int main () + * { + * moo_rbt_t* s1; + * int i; + * + * s1 = moo_rbt_open (MOO_MMGR_GETDFL(), 0, 1, 1); // error handling skipped + * moo_rbt_setstyle (s1, moo_getrbtstyle(MOO_RBT_STYLE_INLINE_COPIERS)); + * + * for (i = 0; i < 20; i++) + * { + * int x = i * 20; + * moo_rbt_insert (s1, &i, MOO_SIZEOF(i), &x, MOO_SIZEOF(x)); // eror handling skipped + * } + * + * moo_rbt_rwalk (s1, walk, MOO_NULL); + * + * moo_rbt_close (s1); + * return 0; + * } + * @endcode + */ + +typedef struct moo_rbt_t moo_rbt_t; +typedef struct moo_rbt_pair_t moo_rbt_pair_t; + +/** + * The moo_rbt_walk_t type defines values that the callback function can + * return to control moo_rbt_walk() and moo_rbt_rwalk(). + */ +enum moo_rbt_walk_t +{ + MOO_RBT_WALK_STOP = 0, + MOO_RBT_WALK_FORWARD = 1 +}; +typedef enum moo_rbt_walk_t moo_rbt_walk_t; + +/** + * The moo_rbt_id_t type defines IDs to indicate a key or a value in various + * functions + */ +enum moo_rbt_id_t +{ + MOO_RBT_KEY = 0, /**< indicate a key */ + MOO_RBT_VAL = 1 /**< indicate a value */ +}; +typedef enum moo_rbt_id_t moo_rbt_id_t; + +/** + * The moo_rbt_copier_t type defines a pair contruction callback. + */ +typedef void* (*moo_rbt_copier_t) ( + moo_rbt_t* rbt /* red-black tree */, + void* dptr /* pointer to a key or a value */, + moo_oow_t dlen /* length of a key or a value */ +); + +/** + * The moo_rbt_freeer_t defines a key/value destruction callback. + */ +typedef void (*moo_rbt_freeer_t) ( + moo_rbt_t* rbt, /**< red-black tree */ + void* dptr, /**< pointer to a key or a value */ + moo_oow_t dlen /**< length of a key or a value */ +); + +/** + * The moo_rbt_comper_t type defines a key comparator that is called when + * the rbt needs to compare keys. A red-black tree is created with a default + * comparator which performs bitwise comparison of two keys. + * The comparator should return 0 if the keys are the same, 1 if the first + * key is greater than the second key, -1 otherwise. + */ +typedef int (*moo_rbt_comper_t) ( + const moo_rbt_t* rbt, /**< red-black tree */ + const void* kptr1, /**< key pointer */ + moo_oow_t klen1, /**< key length */ + const void* kptr2, /**< key pointer */ + moo_oow_t klen2 /**< key length */ +); + +/** + * The moo_rbt_keeper_t type defines a value keeper that is called when + * a value is retained in the context that it should be destroyed because + * it is identical to a new value. Two values are identical if their + * pointers and lengths are equal. + */ +typedef void (*moo_rbt_keeper_t) ( + moo_rbt_t* rbt, /**< red-black tree */ + void* vptr, /**< value pointer */ + moo_oow_t vlen /**< value length */ +); + +/** + * The moo_rbt_walker_t defines a pair visitor. + */ +typedef moo_rbt_walk_t (*moo_rbt_walker_t) ( + moo_rbt_t* rbt, /**< red-black tree */ + moo_rbt_pair_t* pair, /**< pointer to a key/value pair */ + void* ctx /**< pointer to user-defined data */ +); + +/** + * The moo_rbt_cbserter_t type defines a callback function for moo_rbt_cbsert(). + * The moo_rbt_cbserter() function calls it to allocate a new pair for the + * key pointed to by @a kptr of the length @a klen and the callback context + * @a ctx. The second parameter @a pair is passed the pointer to the existing + * pair for the key or #MOO_NULL in case of no existing key. The callback + * must return a pointer to a new or a reallocated pair. When reallocating the + * existing pair, this callback must destroy the existing pair and return the + * newly reallocated pair. It must return #MOO_NULL for failure. + */ +typedef moo_rbt_pair_t* (*moo_rbt_cbserter_t) ( + moo_rbt_t* rbt, /**< red-black tree */ + moo_rbt_pair_t* pair, /**< pair pointer */ + void* kptr, /**< key pointer */ + moo_oow_t klen, /**< key length */ + void* ctx /**< callback context */ +); + +/** + * The moo_rbt_pair_t type defines red-black tree pair. A pair is composed + * of a key and a value. It maintains pointers to the beginning of a key and + * a value plus their length. The length is scaled down with the scale factor + * specified in an owning tree. Use macros defined in the + */ +struct moo_rbt_pair_t +{ + struct + { + void* ptr; + moo_oow_t len; + } key; + + struct + { + void* ptr; + moo_oow_t len; + } val; + + /* management information below */ + enum + { + MOO_RBT_RED, + MOO_RBT_BLACK + } color; + moo_rbt_pair_t* parent; + moo_rbt_pair_t* child[2]; /* left and right */ +}; + +typedef struct moo_rbt_style_t moo_rbt_style_t; + +/** + * The moo_rbt_style_t type defines callback function sets for key/value + * pair manipulation. + */ +struct moo_rbt_style_t +{ + moo_rbt_copier_t copier[2]; /**< key and value copier */ + moo_rbt_freeer_t freeer[2]; /**< key and value freeer */ + moo_rbt_comper_t comper; /**< key comparator */ + moo_rbt_keeper_t keeper; /**< value keeper */ +}; + +/** + * The moo_rbt_style_kind_t type defines the type of predefined + * callback set for pair manipulation. + */ +enum moo_rbt_style_kind_t +{ + /** store the key and the value pointer */ + MOO_RBT_STYLE_DEFAULT, + /** copy both key and value into the pair */ + MOO_RBT_STYLE_INLINE_COPIERS, + /** copy the key into the pair but store the value pointer */ + MOO_RBT_STYLE_INLINE_KEY_COPIER, + /** copy the value into the pair but store the key pointer */ + MOO_RBT_STYLE_INLINE_VALUE_COPIER +}; + +typedef enum moo_rbt_style_kind_t moo_rbt_style_kind_t; + +/** + * The moo_rbt_t type defines a red-black tree. + */ +struct moo_rbt_t +{ + moo_t* moo; + const moo_rbt_style_t* style; + moo_oob_t scale[2]; /**< length scale */ + moo_rbt_pair_t xnil; /**< internal nil node */ + moo_oow_t size; /**< number of pairs */ + moo_rbt_pair_t* root; /**< root pair */ +}; + +/** + * The MOO_RBT_COPIER_SIMPLE macros defines a copier that remembers the + * pointer and length of data in a pair. + */ +#define MOO_RBT_COPIER_SIMPLE ((moo_rbt_copier_t)1) + +/** + * The MOO_RBT_COPIER_INLINE macros defines a copier that copies data into + * a pair. + */ +#define MOO_RBT_COPIER_INLINE ((moo_rbt_copier_t)2) + +#define MOO_RBT_COPIER_DEFAULT (MOO_RBT_COPIER_SIMPLE) +#define MOO_RBT_FREEER_DEFAULT (MOO_NULL) +#define MOO_RBT_COMPER_DEFAULT (moo_rbt_dflcomp) +#define MOO_RBT_KEEPER_DEFAULT (MOO_NULL) + +/** + * The MOO_RBT_SIZE() macro returns the number of pairs in red-black tree. + */ +#define MOO_RBT_SIZE(m) ((const moo_oow_t)(m)->size) +#define MOO_RBT_KSCALE(m) ((const int)(m)->scale[MOO_RBT_KEY]) +#define MOO_RBT_VSCALE(m) ((const int)(m)->scale[MOO_RBT_VAL]) + +#define MOO_RBT_KPTL(p) (&(p)->key) +#define MOO_RBT_VPTL(p) (&(p)->val) + +#define MOO_RBT_KPTR(p) ((p)->key.ptr) +#define MOO_RBT_KLEN(p) ((p)->key.len) +#define MOO_RBT_VPTR(p) ((p)->val.ptr) +#define MOO_RBT_VLEN(p) ((p)->val.len) + +#define MOO_RBT_NEXT(p) ((p)->next) + +#if defined(__cplusplus) +extern "C" { +#endif + +/** + * The moo_getrbtstyle() functions returns a predefined callback set for + * pair manipulation. + */ +MOO_EXPORT const moo_rbt_style_t* moo_getrbtstyle ( + moo_rbt_style_kind_t kind +); + +/** + * The moo_rbt_open() function creates a red-black tree. + * @return moo_rbt_t pointer on success, MOO_NULL on failure. + */ +MOO_EXPORT moo_rbt_t* moo_rbt_open ( + moo_t* moo, + moo_oow_t xtnsize, /**< extension size in bytes */ + int kscale, /**< key scale */ + int vscale /**< value scale */ +); + +/** + * The moo_rbt_close() function destroys a red-black tree. + */ +MOO_EXPORT void moo_rbt_close ( + moo_rbt_t* rbt /**< red-black tree */ +); + +/** + * The moo_rbt_init() function initializes a red-black tree + */ +MOO_EXPORT int moo_rbt_init ( + moo_rbt_t* rbt, /**< red-black tree */ + moo_t* moo, + int kscale, /**< key scale */ + int vscale /**< value scale */ +); + +/** + * The moo_rbt_fini() funtion finalizes a red-black tree + */ +MOO_EXPORT void moo_rbt_fini ( + moo_rbt_t* rbt /**< red-black tree */ +); + +MOO_EXPORT void* moo_rbt_getxtn ( + moo_rbt_t* rbt +); + +/** + * The moo_rbt_getstyle() function gets manipulation callback function set. + */ +MOO_EXPORT const moo_rbt_style_t* moo_rbt_getstyle ( + const moo_rbt_t* rbt /**< red-black tree */ +); + +/** + * The moo_rbt_setstyle() function sets internal manipulation callback + * functions for data construction, destruction, comparison, etc. + * The callback structure pointed to by \a style must outlive the tree + * pointed to by \a htb as the tree doesn't copy the contents of the + * structure. + */ +MOO_EXPORT void moo_rbt_setstyle ( + moo_rbt_t* rbt, /**< red-black tree */ + const moo_rbt_style_t* style /**< callback function set */ +); + +/** + * The moo_rbt_getsize() function gets the number of pairs in red-black tree. + */ +MOO_EXPORT moo_oow_t moo_rbt_getsize ( + const moo_rbt_t* rbt /**< red-black tree */ +); + +/** + * The moo_rbt_search() function searches red-black tree to find a pair with a + * matching key. It returns the pointer to the pair found. If it fails + * to find one, it returns MOO_NULL. + * @return pointer to the pair with a maching key, + * or MOO_NULL if no match is found. + */ +MOO_EXPORT moo_rbt_pair_t* moo_rbt_search ( + const moo_rbt_t* rbt, /**< red-black tree */ + const void* kptr, /**< key pointer */ + moo_oow_t klen /**< the size of the key */ +); + +/** + * The moo_rbt_upsert() function searches red-black tree for the pair with a + * matching key. If one is found, it updates the pair. Otherwise, it inserts + * a new pair with the key and the value given. It returns the pointer to the + * pair updated or inserted. + * @return a pointer to the updated or inserted pair on success, + * MOO_NULL on failure. + */ +MOO_EXPORT moo_rbt_pair_t* moo_rbt_upsert ( + moo_rbt_t* rbt, /**< red-black tree */ + void* kptr, /**< key pointer */ + moo_oow_t klen, /**< key length */ + void* vptr, /**< value pointer */ + moo_oow_t vlen /**< value length */ +); + +/** + * The moo_rbt_ensert() function inserts a new pair with the key and the value + * given. If there exists a pair with the key given, the function returns + * the pair containing the key. + * @return pointer to a pair on success, MOO_NULL on failure. + */ +MOO_EXPORT moo_rbt_pair_t* moo_rbt_ensert ( + moo_rbt_t* rbt, /**< red-black tree */ + void* kptr, /**< key pointer */ + moo_oow_t klen, /**< key length */ + void* vptr, /**< value pointer */ + moo_oow_t vlen /**< value length */ +); + +/** + * The moo_rbt_insert() function inserts a new pair with the key and the value + * given. If there exists a pair with the key given, the function returns + * MOO_NULL without channging the value. + * @return pointer to the pair created on success, MOO_NULL on failure. + */ +MOO_EXPORT moo_rbt_pair_t* moo_rbt_insert ( + moo_rbt_t* rbt, /**< red-black tree */ + void* kptr, /**< key pointer */ + moo_oow_t klen, /**< key length */ + void* vptr, /**< value pointer */ + moo_oow_t vlen /**< value length */ +); + +/** + * The moo_rbt_update() function updates the value of an existing pair + * with a matching key. + * @return pointer to the pair on success, MOO_NULL on no matching pair + */ +MOO_EXPORT moo_rbt_pair_t* moo_rbt_update ( + moo_rbt_t* rbt, /**< red-black tree */ + void* kptr, /**< key pointer */ + moo_oow_t klen, /**< key length */ + void* vptr, /**< value pointer */ + moo_oow_t vlen /**< value length */ +); + +/** + * The moo_rbt_cbsert() function inserts a key/value pair by delegating pair + * allocation to a callback function. Depending on the callback function, + * it may behave like moo_rbt_insert(), moo_rbt_upsert(), moo_rbt_update(), + * moo_rbt_ensert(), or totally differently. The sample code below inserts + * a new pair if the key is not found and appends the new value to the + * existing value delimited by a comma if the key is found. + * + * @code + * moo_rbt_walk_t print_map_pair (moo_rbt_t* map, moo_rbt_pair_t* pair, void* ctx) + * { + * moo_printf (MOO_T("%.*s[%d] => %.*s[%d]\n"), + * (int)MOO_RBT_KLEN(pair), MOO_RBT_KPTR(pair), (int)MOO_RBT_KLEN(pair), + * (int)MOO_RBT_VLEN(pair), MOO_RBT_VPTR(pair), (int)MOO_RBT_VLEN(pair)); + * return MOO_RBT_WALK_FORWARD; + * } + * + * moo_rbt_pair_t* cbserter ( + * moo_rbt_t* rbt, moo_rbt_pair_t* pair, + * void* kptr, moo_oow_t klen, void* ctx) + * { + * moo_cstr_t* v = (moo_cstr_t*)ctx; + * if (pair == MOO_NULL) + * { + * // no existing key for the key + * return moo_rbt_allocpair (rbt, kptr, klen, v->ptr, v->len); + * } + * else + * { + * // a pair with the key exists. + * // in this sample, i will append the new value to the old value + * // separated by a comma + * moo_rbt_pair_t* new_pair; + * moo_char_t comma = MOO_T(','); + * moo_oob_t* vptr; + * + * // allocate a new pair, but without filling the actual value. + * // note vptr is given MOO_NULL for that purpose + * new_pair = moo_rbt_allocpair ( + * rbt, kptr, klen, MOO_NULL, pair->vlen + 1 + v->len); + * if (new_pair == MOO_NULL) return MOO_NULL; + * + * // fill in the value space + * vptr = new_pair->vptr; + * moo_memcpy (vptr, pair->vptr, pair->vlen*MOO_SIZEOF(moo_char_t)); + * vptr += pair->vlen*MOO_SIZEOF(moo_char_t); + * moo_memcpy (vptr, &comma, MOO_SIZEOF(moo_char_t)); + * vptr += MOO_SIZEOF(moo_char_t); + * moo_memcpy (vptr, v->ptr, v->len*MOO_SIZEOF(moo_char_t)); + * + * // this callback requires the old pair to be destroyed + * moo_rbt_freepair (rbt, pair); + * + * // return the new pair + * return new_pair; + * } + * } + * + * int main () + * { + * moo_rbt_t* s1; + * int i; + * moo_char_t* keys[] = { MOO_T("one"), MOO_T("two"), MOO_T("three") }; + * moo_char_t* vals[] = { MOO_T("1"), MOO_T("2"), MOO_T("3"), MOO_T("4"), MOO_T("5") }; + * + * s1 = moo_rbt_open ( + * MOO_MMGR_GETDFL(), 0, + * MOO_SIZEOF(moo_char_t), MOO_SIZEOF(moo_char_t) + * ); // note error check is skipped + * moo_rbt_setstyle (s1, &style1); + * + * for (i = 0; i < MOO_COUNTOF(vals); i++) + * { + * moo_cstr_t ctx; + * ctx.ptr = vals[i]; ctx.len = moo_strlen(vals[i]); + * moo_rbt_cbsert (s1, + * keys[i%MOO_COUNTOF(keys)], moo_strlen(keys[i%MOO_COUNTOF(keys)]), + * cbserter, &ctx + * ); // note error check is skipped + * } + * moo_rbt_walk (s1, print_map_pair, MOO_NULL); + * + * moo_rbt_close (s1); + * return 0; + * } + * @endcode + */ +MOO_EXPORT moo_rbt_pair_t* moo_rbt_cbsert ( + moo_rbt_t* rbt, /**< red-black tree */ + void* kptr, /**< key pointer */ + moo_oow_t klen, /**< key length */ + moo_rbt_cbserter_t cbserter, /**< callback function */ + void* ctx /**< callback context */ +); + +/** + * The moo_rbt_delete() function deletes a pair with a matching key + * @return 0 on success, -1 on failure + */ +MOO_EXPORT int moo_rbt_delete ( + moo_rbt_t* rbt, /**< red-black tree */ + const void* kptr, /**< key pointer */ + moo_oow_t klen /**< key size */ +); + +/** + * The moo_rbt_clear() function empties a red-black tree. + */ +MOO_EXPORT void moo_rbt_clear ( + moo_rbt_t* rbt /**< red-black tree */ +); + +/** + * The moo_rbt_walk() function traverses a red-black tree in preorder + * from the leftmost child. + */ +MOO_EXPORT void moo_rbt_walk ( + moo_rbt_t* rbt, /**< red-black tree */ + moo_rbt_walker_t walker, /**< callback function for each pair */ + void* ctx /**< pointer to user-specific data */ +); + +/** + * The moo_rbt_walk() function traverses a red-black tree in preorder + * from the rightmost child. + */ +MOO_EXPORT void moo_rbt_rwalk ( + moo_rbt_t* rbt, /**< red-black tree */ + moo_rbt_walker_t walker, /**< callback function for each pair */ + void* ctx /**< pointer to user-specific data */ +); + +/** + * The moo_rbt_allocpair() function allocates a pair for a key and a value + * given. But it does not chain the pair allocated into the red-black tree @a rbt. + * Use this function at your own risk. + * + * Take note of he following special behavior when the copier is + * #MOO_RBT_COPIER_INLINE. + * - If @a kptr is #MOO_NULL, the key space of the size @a klen is reserved but + * not propagated with any data. + * - If @a vptr is #MOO_NULL, the value space of the size @a vlen is reserved + * but not propagated with any data. + */ +MOO_EXPORT moo_rbt_pair_t* moo_rbt_allocpair ( + moo_rbt_t* rbt, + void* kptr, + moo_oow_t klen, + void* vptr, + moo_oow_t vlen +); + +/** + * The moo_rbt_freepair() function destroys a pair. But it does not detach + * the pair destroyed from the red-black tree @a rbt. Use this function at your + * own risk. + */ +MOO_EXPORT void moo_rbt_freepair ( + moo_rbt_t* rbt, + moo_rbt_pair_t* pair +); + +/** + * The moo_rbt_dflcomp() function defines the default key comparator. + */ +MOO_EXPORT int moo_rbt_dflcomp ( + const moo_rbt_t* rbt, + const void* kptr1, + moo_oow_t klen1, + const void* kptr2, + moo_oow_t klen2 +); + +#if defined(__cplusplus) +} +#endif + +#endif diff --git a/stix/lib/moo-utl.h b/stix/lib/moo-utl.h new file mode 100644 index 0000000..fe26890 --- /dev/null +++ b/stix/lib/moo-utl.h @@ -0,0 +1,331 @@ +/* + * $Id$ + * + Copyright (c) 2014-2016 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 _MOO_UTL_H_ +#define _MOO_UTL_H_ + +#include "moo-cmn.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +MOO_EXPORT moo_oow_t moo_hashbytes ( + const moo_oob_t* ptr, + moo_oow_t len +); + +#if defined(MOO_HAVE_INLINE) + static MOO_INLINE moo_oow_t moo_hashbchars (const moo_bch_t* ptr, moo_oow_t len) + { + return moo_hashbytes((const moo_oob_t*)ptr,len * MOO_SIZEOF(moo_bch_t)); + } + + static MOO_INLINE moo_oow_t moo_hashuchars (const moo_uch_t* ptr, moo_oow_t len) + { + return moo_hashbytes((const moo_oob_t*)ptr,len * MOO_SIZEOF(moo_uch_t)); + } + + static MOO_INLINE moo_oow_t moo_hashwords (const moo_oow_t* ptr, moo_oow_t len) + { + return moo_hashbytes((const moo_oob_t*)ptr, len * MOO_SIZEOF(moo_oow_t)); + } + + static MOO_INLINE moo_oow_t moo_hashhalfwords (const moo_oohw_t* ptr, moo_oow_t len) + { + return moo_hashbytes((const moo_oob_t*)ptr, len * MOO_SIZEOF(moo_oohw_t)); + } +#else +# define moo_hashbchars(ptr,len) moo_hashbytes((const moo_oob_t*)ptr,len * MOO_SIZEOF(moo_bch_t)) +# define moo_hashuchars(ptr,len) moo_hashbytes((const moo_oob_t*)ptr,len * MOO_SIZEOF(moo_uch_t)) +# define moo_hashwords(ptr,len) moo_hashbytes((const moo_oob_t*)ptr, len * MOO_SIZEOF(moo_oow_t)) +# define moo_hashhalfwords(ptr,len) moo_hashbytes((const moo_oob_t*)ptr, len * MOO_SIZEOF(moo_oohw_t)) +#endif + +#if defined(MOO_OOCH_IS_UCH) +# define moo_hashoochars(ptr,len) moo_hashuchars(ptr,len) +#else +# define moo_hashoochars(ptr,len) moo_hashbchars(ptr,len) +#endif + + +MOO_EXPORT moo_oow_t moo_hashwords ( + const moo_oow_t* ptr, + moo_oow_t len +); + +/** + * The moo_equaluchars() function determines equality of two strings + * of the same length \a len. + */ +MOO_EXPORT int moo_equaluchars ( + const moo_uch_t* str1, + const moo_uch_t* str2, + moo_oow_t len +); + +MOO_EXPORT int moo_equalbchars ( + const moo_bch_t* str1, + const moo_bch_t* str2, + moo_oow_t len +); + +MOO_EXPORT int moo_compucstr ( + const moo_uch_t* str1, + const moo_uch_t* str2 +); + +MOO_EXPORT int moo_compbcstr ( + const moo_bch_t* str1, + const moo_bch_t* str2 +); + +MOO_EXPORT int moo_compucbcstr ( + const moo_uch_t* str1, + const moo_bch_t* str2 +); + +MOO_EXPORT int moo_compucharsbcstr ( + const moo_uch_t* str1, + moo_oow_t len, + const moo_bch_t* str2 +); + +MOO_EXPORT int moo_compbcharsbcstr ( + const moo_bch_t* str1, + moo_oow_t len, + const moo_bch_t* str2 +); + +MOO_EXPORT void moo_copyuchars ( + moo_uch_t* dst, + const moo_uch_t* src, + moo_oow_t len +); + +MOO_EXPORT void moo_copybchars ( + moo_bch_t* dst, + const moo_bch_t* src, + moo_oow_t len +); + +MOO_EXPORT void moo_copybtouchars ( + moo_uch_t* dst, + const moo_bch_t* src, + moo_oow_t len +); + +MOO_EXPORT moo_oow_t moo_copyucstr ( + moo_uch_t* dst, + moo_oow_t len, + const moo_uch_t* src +); + +MOO_EXPORT moo_oow_t moo_copybcstr ( + moo_bch_t* dst, + moo_oow_t len, + const moo_bch_t* src +); + +MOO_EXPORT moo_uch_t* moo_finduchar ( + const moo_uch_t* ptr, + moo_oow_t len, + moo_uch_t c +); + +MOO_EXPORT moo_bch_t* moo_findbchar ( + const moo_bch_t* ptr, + moo_oow_t len, + moo_bch_t c +); + +MOO_EXPORT moo_uch_t* moo_rfinduchar ( + const moo_uch_t* ptr, + moo_oow_t len, + moo_uch_t c +); + +MOO_EXPORT moo_bch_t* moo_rfindbchar ( + const moo_bch_t* ptr, + moo_oow_t len, + moo_bch_t c +); + + +MOO_EXPORT moo_oow_t moo_countucstr ( + const moo_uch_t* str +); + +MOO_EXPORT moo_oow_t moo_countbcstr ( + const moo_bch_t* str +); + +#if defined(MOO_OOCH_IS_UCH) +# define moo_equaloochars(str1,str2,len) moo_equaluchars(str1,str2,len) +# define moo_compoocbcstr(str1,str2) moo_compucbcstr(str1,str2) +# define moo_compoocharsbcstr(str1,len1,str2) moo_compucharsbcstr(str1,len1,str2) +# define moo_compoocstr(str1,str2) moo_compucstr(str1,str2) +# define moo_copyoochars(dst,src,len) moo_copyuchars(dst,src,len) +# define moo_copybctooochars(dst,src,len) moo_copybtouchars(dst,src,len) +# define moo_copyoocstr(dst,len,src) moo_copyucstr(dst,len,src) +# define moo_findoochar(ptr,len,c) moo_finduchar(ptr,len,c) +# define moo_rfindoochar(ptr,len,c) moo_rfinduchar(ptr,len,c) +# define moo_countoocstr(str) moo_countucstr(str) +#else + +# define moo_equaloochars(str1,str2,len) moo_equalbchars(str1,str2,len) +# define moo_compoocbcstr(str1,str2) moo_compbcstr(str1,str2) +# define moo_compoocharsbcstr(str1,len1,str2) moo_compbcharsbcstr(str1,len1,str2) +# define moo_compoocstr(str1,str2) moo_compbcstr(str1,str2) +# define moo_copyoochars(dst,src,len) moo_copybchars(dst,src,len) +# define moo_copybctooochars(dst,src,len) moo_copybchars(dst,src,len) +# define moo_copyoocstr(dst,len,src) moo_copybcstr(dst,len,src) +# define moo_findoochar(ptr,len,c) moo_findbchar(ptr,len,c) +# define moo_rfindoochar(ptr,len,c) moo_rfindbchar(ptr,len,c) +# define moo_countoocstr(str) moo_countbcstr(str) +#endif + + + +MOO_EXPORT int moo_copyoocstrtosbuf ( + moo_t* moo, + const moo_ooch_t* str, + int id +); + +MOO_EXPORT int moo_concatoocstrtosbuf ( + moo_t* moo, + const moo_ooch_t* str, + int id +); + +MOO_EXPORT moo_cmgr_t* moo_getutf8cmgr ( + void +); + +/** + * The moo_convutoutf8chars() function converts a unicode character string \a ucs + * to a UTF8 string and writes it into the buffer pointed to by \a bcs, but + * not more than \a bcslen bytes including the terminating null. + * + * Upon return, \a bcslen is modified to the actual number of bytes written to + * \a bcs excluding the terminating null; \a ucslen is modified to the number of + * wide characters converted. + * + * You may pass #MOO_NULL for \a bcs to dry-run conversion or to get the + * required buffer size for conversion. -2 is never returned in this case. + * + * \return + * - 0 on full conversion, + * - -1 on no or partial conversion for an illegal character encountered, + * - -2 on no or partial conversion for a small buffer. + * + * \code + * const moo_uch_t ucs[] = { 'H', 'e', 'l', 'l', 'o' }; + * moo_bch_t bcs[10]; + * moo_oow_t ucslen = 5; + * moo_oow_t bcslen = MOO_COUNTOF(bcs); + * n = moo_convutoutf8chars (ucs, &ucslen, bcs, &bcslen); + * if (n <= -1) + * { + * // conversion error + * } + * \endcode + */ +MOO_EXPORT int moo_convutoutf8chars ( + const moo_uch_t* ucs, + moo_oow_t* ucslen, + moo_bch_t* bcs, + moo_oow_t* bcslen +); + +/** + * The moo_convutf8touchars() function converts a UTF8 string to a uncide string. + * + * It never returns -2 if \a ucs is #MOO_NULL. + * + * \code + * const moo_bch_t* bcs = "test string"; + * moo_uch_t ucs[100]; + * moo_oow_t ucslen = MOO_COUNTOF(buf), n; + * moo_oow_t bcslen = 11; + * int n; + * n = moo_convutf8touchars (bcs, &bcslen, ucs, &ucslen); + * if (n <= -1) { invalid/incomplenete sequence or buffer to small } + * \endcode + * + * The resulting \a ucslen can still be greater than 0 even if the return + * value is negative. The value indiates the number of characters converted + * before the error has occurred. + * + * \return 0 on success. + * -1 if \a bcs contains an illegal character. + * -2 if the wide-character string buffer is too small. + * -3 if \a bcs is not a complete sequence. + */ +MOO_EXPORT int moo_convutf8touchars ( + const moo_bch_t* bcs, + moo_oow_t* bcslen, + moo_uch_t* ucs, + moo_oow_t* ucslen +); + + +MOO_EXPORT int moo_convutoutf8cstr ( + const moo_uch_t* ucs, + moo_oow_t* ucslen, + moo_bch_t* bcs, + moo_oow_t* bcslen +); + +MOO_EXPORT int moo_convutf8toucstr ( + const moo_bch_t* bcs, + moo_oow_t* bcslen, + moo_uch_t* ucs, + moo_oow_t* ucslen +); + + + +MOO_EXPORT moo_oow_t moo_uctoutf8 ( + moo_uch_t uc, + moo_bch_t* utf8, + moo_oow_t size +); + +MOO_EXPORT moo_oow_t moo_utf8touc ( + const moo_bch_t* utf8, + moo_oow_t size, + moo_uch_t* uc +); + + +#if defined(__cplusplus) +} +#endif + + +#endif diff --git a/stix/lib/moo.c b/stix/lib/moo.c new file mode 100644 index 0000000..9a6e627 --- /dev/null +++ b/stix/lib/moo.c @@ -0,0 +1,740 @@ +/* + * $Id$ + * + Copyright (c) 2014-2016 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 "moo-prv.h" + +moo_t* moo_open (moo_mmgr_t* mmgr, moo_oow_t xtnsize, moo_oow_t heapsize, const moo_vmprim_t* vmprim, moo_errnum_t* errnum) +{ + moo_t* moo; + + /* if this assertion fails, correct the type definition in moo.h */ + MOO_ASSERT (moo, MOO_SIZEOF(moo_oow_t) == MOO_SIZEOF(moo_oop_t)); + + moo = MOO_MMGR_ALLOC (mmgr, MOO_SIZEOF(*moo) + xtnsize); + if (moo) + { + if (moo_init(moo, mmgr, heapsize, vmprim) <= -1) + { + if (errnum) *errnum = moo->errnum; + MOO_MMGR_FREE (mmgr, moo); + moo = MOO_NULL; + } + else MOO_MEMSET (moo + 1, 0, xtnsize); + } + else if (errnum) *errnum = MOO_ESYSMEM; + + return moo; +} + +void moo_close (moo_t* moo) +{ + moo_fini (moo); + MOO_MMGR_FREE (moo->mmgr, moo); +} + +static void fill_bigint_tables (moo_t* moo) +{ + int radix, safe_ndigits; + moo_oow_t ub, w; + moo_oow_t multiplier; + + for (radix = 2; radix <= 36; radix++) + { + w = 0; + ub = (moo_oow_t)MOO_TYPE_MAX(moo_liw_t) / radix - (radix - 1); + multiplier = 1; + safe_ndigits = 0; + + while (w <= ub) + { + w = w * radix + (radix - 1); + multiplier *= radix; + safe_ndigits++; + } + + /* safe_ndigits contains the number of digits that never + * cause overflow when computed normally with a native type. */ + moo->bigint[radix].safe_ndigits = safe_ndigits; + moo->bigint[radix].multiplier = multiplier; + } +} + +int moo_init (moo_t* moo, moo_mmgr_t* mmgr, moo_oow_t heapsz, const moo_vmprim_t* vmprim) +{ + int modtab_inited = 0; + + MOO_MEMSET (moo, 0, MOO_SIZEOF(*moo)); + moo->mmgr = mmgr; + moo->cmgr = moo_getutf8cmgr (); + moo->vmprim = *vmprim; + + moo->option.log_mask = ~0u; + moo->option.dfl_symtab_size = MOO_DFL_SYMTAB_SIZE; + moo->option.dfl_sysdic_size = MOO_DFL_SYSDIC_SIZE; + moo->option.dfl_procstk_size = MOO_DFL_PROCSTK_SIZE; + +/* TODO: intoduct a permanent heap */ + /*moo->permheap = moo_makeheap (moo, what is the best size???); + if (!moo->permheap) goto oops; */ + moo->curheap = moo_makeheap (moo, heapsz); + if (!moo->curheap) goto oops; + moo->newheap = moo_makeheap (moo, heapsz); + if (!moo->newheap) goto oops; + + if (moo_rbt_init (&moo->modtab, moo, MOO_SIZEOF(moo_ooch_t), 1) <= -1) goto oops; + modtab_inited = 1; + moo_rbt_setstyle (&moo->modtab, moo_getrbtstyle(MOO_RBT_STYLE_INLINE_COPIERS)); + + fill_bigint_tables (moo); + + moo->tagged_classes[MOO_OOP_TAG_SMINT] = &moo->_small_integer; + moo->tagged_classes[MOO_OOP_TAG_CHAR] = &moo->_character; + moo->tagged_classes[MOO_OOP_TAG_ERROR] = &moo->_error_class; + + return 0; + +oops: + if (modtab_inited) moo_rbt_fini (&moo->modtab); + if (moo->newheap) moo_killheap (moo, moo->newheap); + if (moo->curheap) moo_killheap (moo, moo->curheap); + if (moo->permheap) moo_killheap (moo, moo->permheap); + return -1; +} + +static moo_rbt_walk_t unload_module (moo_rbt_t* rbt, moo_rbt_pair_t* pair, void* ctx) +{ + moo_t* moo = (moo_t*)ctx; + moo_mod_data_t* mdp; + + mdp = MOO_RBT_VPTR(pair); + MOO_ASSERT (moo, mdp != MOO_NULL); + + mdp->pair = MOO_NULL; /* to prevent moo_closemod() from calling moo_rbt_delete() */ + moo_closemod (moo, mdp); + + return MOO_RBT_WALK_FORWARD; +} + +void moo_fini (moo_t* moo) +{ + moo_cb_t* cb; + moo_oow_t i; + + if (moo->sem_list) + { + moo_freemem (moo, moo->sem_list); + moo->sem_list_capa = 0; + moo->sem_list_count = 0; + } + + if (moo->sem_heap) + { + moo_freemem (moo, moo->sem_heap); + moo->sem_heap_capa = 0; + moo->sem_heap_count = 0; + } + + for (cb = moo->cblist; cb; cb = cb->next) + { + if (cb->fini) cb->fini (moo); + } + + moo_rbt_walk (&moo->modtab, unload_module, moo); /* unload all modules */ + moo_rbt_fini (&moo->modtab); + +/* TOOD: persistency? storing objects to image file? */ + moo_killheap (moo, moo->newheap); + moo_killheap (moo, moo->curheap); + moo_killheap (moo, moo->permheap); + + /* deregister all callbacks */ + while (moo->cblist) moo_deregcb (moo, moo->cblist); + + for (i = 0; i < MOO_COUNTOF(moo->sbuf); i++) + { + if (moo->sbuf[i].ptr) + { + moo_freemem (moo, moo->sbuf[i].ptr); + moo->sbuf[i].ptr = MOO_NULL; + moo->sbuf[i].len = 0; + moo->sbuf[i].capa = 0; + } + } + + if (moo->log.ptr) + { + /* make sure to flush your log message */ +/* TODO: flush unwritten message */ + + moo_freemem (moo, moo->log.ptr); + moo->log.capa = 0; + moo->log.len = 0; + } +} + +const moo_ooch_t* moo_geterrstr (moo_t* moo) +{ + return moo_errnumtoerrstr (moo->errnum); +} + +int moo_setoption (moo_t* moo, moo_option_t id, const void* value) +{ + switch (id) + { + case MOO_TRAIT: + moo->option.trait = *(const unsigned int*)value; + return 0; + + case MOO_LOG_MASK: + moo->option.log_mask = *(const unsigned int*)value; + return 0; + + case MOO_SYMTAB_SIZE: + { + moo_oow_t w; + + w = *(moo_oow_t*)value; + if (w <= 0 || w > MOO_SMOOI_MAX) goto einval; + + moo->option.dfl_symtab_size = *(moo_oow_t*)value; + return 0; + } + + case MOO_SYSDIC_SIZE: + { + moo_oow_t w; + + w = *(moo_oow_t*)value; + if (w <= 0 || w > MOO_SMOOI_MAX) goto einval; + + moo->option.dfl_sysdic_size = *(moo_oow_t*)value; + return 0; + } + + case MOO_PROCSTK_SIZE: + { + moo_oow_t w; + + w = *(moo_oow_t*)value; + if (w <= 0 || w > MOO_SMOOI_MAX) goto einval; + + moo->option.dfl_procstk_size = *(moo_oow_t*)value; + return 0; + } + } + +einval: + moo->errnum = MOO_EINVAL; + return -1; +} + +int moo_getoption (moo_t* moo, moo_option_t id, void* value) +{ + switch (id) + { + case MOO_TRAIT: + *(unsigned int*)value = moo->option.trait; + return 0; + + case MOO_LOG_MASK: + *(unsigned int*)value = moo->option.log_mask; + return 0; + + case MOO_SYMTAB_SIZE: + *(moo_oow_t*)value = moo->option.dfl_symtab_size; + return 0; + + case MOO_SYSDIC_SIZE: + *(moo_oow_t*)value = moo->option.dfl_sysdic_size; + return 0; + + case MOO_PROCSTK_SIZE: + *(moo_oow_t*)value = moo->option.dfl_procstk_size; + return 0; + }; + + moo->errnum = MOO_EINVAL; + return -1; +} + +moo_cb_t* moo_regcb (moo_t* moo, moo_cb_t* tmpl) +{ + moo_cb_t* actual; + + actual = moo_allocmem (moo, MOO_SIZEOF(*actual)); + if (!actual) return MOO_NULL; + + *actual = *tmpl; + actual->next = moo->cblist; + actual->prev = MOO_NULL; + moo->cblist = actual; + + return actual; +} + +void moo_deregcb (moo_t* moo, moo_cb_t* cb) +{ + if (cb == moo->cblist) + { + moo->cblist = moo->cblist->next; + if (moo->cblist) moo->cblist->prev = MOO_NULL; + } + else + { + if (cb->next) cb->next->prev = cb->prev; + if (cb->prev) cb->prev->next = cb->next; + } + + moo_freemem (moo, cb); +} + +void* moo_allocmem (moo_t* moo, moo_oow_t size) +{ + void* ptr; + + ptr = MOO_MMGR_ALLOC (moo->mmgr, size); + if (!ptr) moo->errnum = MOO_ESYSMEM; + return ptr; +} + +void* moo_callocmem (moo_t* moo, moo_oow_t size) +{ + void* ptr; + + ptr = MOO_MMGR_ALLOC (moo->mmgr, size); + if (!ptr) moo->errnum = MOO_ESYSMEM; + else MOO_MEMSET (ptr, 0, size); + return ptr; +} + +void* moo_reallocmem (moo_t* moo, void* ptr, moo_oow_t size) +{ + ptr = MOO_MMGR_REALLOC (moo->mmgr, ptr, size); + if (!ptr) moo->errnum = MOO_ESYSMEM; + return ptr; +} + +void moo_freemem (moo_t* moo, void* ptr) +{ + MOO_MMGR_FREE (moo->mmgr, ptr); +} + +/* -------------------------------------------------------------------------- */ + +#define MOD_PREFIX "moo_mod_" +#define MOD_PREFIX_LEN 9 + +#if defined(MOO_ENABLE_STATIC_MODULE) + +#include "../mod/console.h" +#include "../mod/_stdio.h" + +static struct +{ + moo_bch_t* modname; + int (*modload) (moo_t* moo, moo_mod_t* mod); +} +static_modtab[] = +{ + { "console", moo_mod_console }, + { "stdio", moo_mod_stdio }, +}; +#endif + +moo_mod_data_t* moo_openmod (moo_t* moo, const moo_ooch_t* name, moo_oow_t namelen) +{ + moo_rbt_pair_t* pair; + moo_mod_data_t* mdp; + moo_mod_data_t md; + moo_mod_load_t load = MOO_NULL; +#if defined(MOO_ENABLE_STATIC_MODULE) + int n; +#endif + + /* maximum module name length is MOO_MOD_NAME_LEN_MAX. + * MOD_PREFIX_LEN for MOD_PREFIX + * 1 for _ at the end when moo_mod_xxx_ is attempted. + * 1 for the terminating '\0'. + */ + moo_ooch_t buf[MOD_PREFIX_LEN + MOO_MOD_NAME_LEN_MAX + 1 + 1]; + + /* copy instead of encoding conversion. MOD_PREFIX must not + * include a character that requires encoding conversion. + * note the terminating null isn't needed in buf here. */ + moo_copybctooochars (buf, MOD_PREFIX, MOD_PREFIX_LEN); + + if (namelen > MOO_COUNTOF(buf) - (MOD_PREFIX_LEN + 1 + 1)) + { + /* module name too long */ + moo->errnum = MOO_EINVAL; /* TODO: change the error number to something more specific */ + return MOO_NULL; + } + + moo_copyoochars (&buf[MOD_PREFIX_LEN], name, namelen); + buf[MOD_PREFIX_LEN + namelen] = '\0'; + +#if defined(MOO_ENABLE_STATIC_MODULE) + /* attempt to find a statically linked module */ + +/*TODO: CHANGE THIS PART */ + + /* TODO: binary search ... */ + for (n = 0; n < MOO_COUNTOF(static_modtab); n++) + { + if (moo_compoocharsbcstr (name, namelen, static_modtab[n].modname) == 0) + { + load = static_modtab[n].modload; + break; + } + } + + if (n >= MOO_COUNTOF(static_modtab)) + { + moo->errnum = MOO_ENOENT; + return MOO_NULL; + } + + if (load) + { + /* found the module in the staic module table */ + + MOO_MEMSET (&md, 0, MOO_SIZEOF(md)); + moo_copyoochars ((moo_ooch_t*)md.mod.name, name, namelen); + /* Note md.handle is MOO_NULL for a static module */ + + /* i copy-insert 'md' into the table before calling 'load'. + * to pass the same address to load(), query(), etc */ + pair = moo_rbt_insert (&moo->modtab, (moo_ooch_t*)name, namelen, &md, MOO_SIZEOF(md)); + if (pair == MOO_NULL) + { + moo->errnum = MOO_ESYSMEM; + return MOO_NULL; + } + + mdp = (moo_mod_data_t*)MOO_RBT_VPTR(pair); + if (load (moo, &mdp->mod) <= -1) + { + moo_rbt_delete (&moo->modtab, (moo_ooch_t*)name, namelen); + return MOO_NULL; + } + + return mdp; + } +#endif + + /* attempt to find an external module */ + MOO_MEMSET (&md, 0, MOO_SIZEOF(md)); + moo_copyoochars ((moo_ooch_t*)md.mod.name, name, namelen); + if (moo->vmprim.dl_open && moo->vmprim.dl_getsym && moo->vmprim.dl_close) + { + md.handle = moo->vmprim.dl_open (moo, &buf[MOD_PREFIX_LEN]); + } + + if (md.handle == MOO_NULL) + { + MOO_DEBUG2 (moo, "Cannot open a module [%.*js]\n", namelen, name); + moo->errnum = MOO_ENOENT; /* TODO: be more descriptive about the error */ + return MOO_NULL; + } + + /* attempt to get moo_mod_xxx where xxx is the module name*/ + load = moo->vmprim.dl_getsym (moo, md.handle, buf); + if (!load) + { + MOO_DEBUG3 (moo, "Cannot get a module symbol [%js] in [%.*js]\n", buf, namelen, name); + moo->errnum = MOO_ENOENT; /* TODO: be more descriptive about the error */ + moo->vmprim.dl_close (moo, md.handle); + return MOO_NULL; + } + + /* i copy-insert 'md' into the table before calling 'load'. + * to pass the same address to load(), query(), etc */ + pair = moo_rbt_insert (&moo->modtab, (void*)name, namelen, &md, MOO_SIZEOF(md)); + if (pair == MOO_NULL) + { + MOO_DEBUG2 (moo, "Cannot register a module [%.*js]\n", namelen, name); + moo->errnum = MOO_ESYSMEM; + moo->vmprim.dl_close (moo, md.handle); + return MOO_NULL; + } + + mdp = (moo_mod_data_t*)MOO_RBT_VPTR(pair); + if (load (moo, &mdp->mod) <= -1) + { + MOO_DEBUG3 (moo, "Module function [%js] returned failure in [%.*js]\n", buf, namelen, name); + moo->errnum = MOO_ENOENT; /* TODO: proper error code and handling */ + moo_rbt_delete (&moo->modtab, name, namelen); + moo->vmprim.dl_close (moo, mdp->handle); + return MOO_NULL; + } + + mdp->pair = pair; + + MOO_DEBUG2 (moo, "Opened a module [%js] - %p\n", mdp->mod.name, mdp->handle); + + /* the module loader must ensure to set a proper query handler */ + MOO_ASSERT (moo, mdp->mod.query != MOO_NULL); + + return mdp; +} + +void moo_closemod (moo_t* moo, moo_mod_data_t* mdp) +{ + if (mdp->mod.unload) mdp->mod.unload (moo, &mdp->mod); + + if (mdp->handle) + { + moo->vmprim.dl_close (moo, mdp->handle); + MOO_DEBUG2 (moo, "Closed a module [%js] - %p\n", mdp->mod.name, mdp->handle); + mdp->handle = MOO_NULL; + } + + if (mdp->pair) + { + /*mdp->pair = MOO_NULL;*/ /* this reset isn't needed as the area will get freed by moo_rbt_delete()) */ + moo_rbt_delete (&moo->modtab, mdp->mod.name, moo_countoocstr(mdp->mod.name)); + } +} + +int moo_importmod (moo_t* moo, moo_oop_t _class, const moo_ooch_t* name, moo_oow_t len) +{ + moo_rbt_pair_t* pair; + moo_mod_data_t* mdp; + int r = 0; + + /* moo_openmod(), moo_closemod(), etc calls a user-defined callback. + * i need to protect _class in case the user-defined callback allocates + * a OOP memory chunk and GC occurs */ + moo_pushtmp (moo, &_class); + + pair = moo_rbt_search (&moo->modtab, name, len); + if (pair) + { + mdp = (moo_mod_data_t*)MOO_RBT_VPTR(pair); + MOO_ASSERT (moo, mdp != MOO_NULL); + } + else + { + mdp = moo_openmod (moo, name, len); + if (!mdp) + { + r = -1; + goto done2; + } + } + + if (!mdp->mod.import) + { + MOO_DEBUG1 (moo, "Cannot import module [%js] - importing not supported by the module\n", mdp->mod.name); + moo->errnum = MOO_ENOIMPL; + r = -1; + goto done; + } + + if (mdp->mod.import (moo, &mdp->mod, _class) <= -1) + { + MOO_DEBUG1 (moo, "Cannot import module [%js] - module's import() returned failure\n", mdp->mod.name); + r = -1; + goto done; + } + +done: + if (!pair) + { + /* close the module if it has been opened in this function. */ + moo_closemod (moo, mdp); + } + +done2: + moo_poptmp (moo); + return r; +} + +moo_pfimpl_t moo_querymod (moo_t* moo, const moo_ooch_t* pfid, moo_oow_t pfidlen) +{ + /* primitive function identifier + * _funcname + * modname_funcname + */ + moo_rbt_pair_t* pair; + moo_mod_data_t* mdp; + const moo_ooch_t* sep; + + moo_oow_t mod_name_len; + moo_pfimpl_t handler; + + sep = moo_findoochar (pfid, pfidlen, '.'); + if (!sep) + { + /* i'm writing a conservative code here. the compiler should + * guarantee that an underscore is included in an primitive identifer. + * what if the compiler is broken? imagine a buggy compiler rewritten + * in moo itself? */ + MOO_DEBUG2 (moo, "Internal error - no period in a primitive function identifier [%.*js] - buggy compiler?\n", pfidlen, pfid); + moo->errnum = MOO_EINTERN; + return MOO_NULL; + } + + mod_name_len = sep - pfid; + + pair = moo_rbt_search (&moo->modtab, pfid, mod_name_len); + if (pair) + { + mdp = (moo_mod_data_t*)MOO_RBT_VPTR(pair); + MOO_ASSERT (moo, mdp != MOO_NULL); + } + else + { + mdp = moo_openmod (moo, pfid, mod_name_len); + if (!mdp) return MOO_NULL; + } + + if ((handler = mdp->mod.query (moo, &mdp->mod, sep + 1)) == MOO_NULL) + { + /* the primitive function is not found. keep the module open */ + MOO_DEBUG2 (moo, "Cannot find a primitive function [%js] in a module [%js]\n", sep + 1, mdp->mod.name); + moo->errnum = MOO_ENOENT; /* TODO: proper error code and handling */ + return MOO_NULL; + } + + MOO_DEBUG3 (moo, "Found a primitive function [%js] in a module [%js] - %p\n", sep + 1, mdp->mod.name, handler); + return handler; +} + +/* -------------------------------------------------------------------------- */ + +/* add a new primitive method */ +int moo_genpfmethod (moo_t* moo, moo_mod_t* mod, moo_oop_t _class, moo_method_type_t type, const moo_ooch_t* mthname, int variadic, const moo_ooch_t* pfname) +{ + /* NOTE: this function is a subset of add_compiled_method() in comp.c */ + + moo_oop_char_t mnsym, pfidsym; + moo_oop_method_t mth; + moo_oop_class_t cls; + moo_oow_t tmp_count = 0, i; + moo_ooi_t arg_count = 0; + moo_oocs_t cs; + moo_ooi_t preamble_flags = 0; + static moo_ooch_t dot[] = { '.', '\0' }; + + MOO_ASSERT (moo, MOO_CLASSOF(moo, _class) == moo->_class); + + if (!pfname) pfname = mthname; + + cls = (moo_oop_class_t)_class; + moo_pushtmp (moo, (moo_oop_t*)&cls); tmp_count++; + MOO_ASSERT (moo, MOO_CLASSOF(moo, (moo_oop_t)cls->mthdic[type]) == moo->_method_dictionary); + + for (i = 0; mthname[i]; i++) + { + if (mthname[i] == ':') + { + if (variadic) goto oops_inval; + arg_count++; + } + } +/* TODO: check if name is a valid method name - more checks... */ +/* TOOD: if the method name is a binary selector, it can still have an argument.. so the check below is invalid... */ + if (arg_count > 0 && mthname[i - 1] != ':') + { + oops_inval: + MOO_DEBUG2 (moo, "Cannot generate primitive function method [%js] in [%O] - invalid name\n", mthname, cls->name); + moo->errnum = MOO_EINVAL; + goto oops; + } + + cs.ptr = (moo_ooch_t*)mthname; + cs.len = i; + if (moo_lookupdic (moo, cls->mthdic[type], &cs) != MOO_NULL) + { + MOO_DEBUG2 (moo, "Cannot generate primitive function method [%js] in [%O] - duplicate\n", mthname, cls->name); + moo->errnum = MOO_EEXIST; + goto oops; + } + + mnsym = (moo_oop_char_t)moo_makesymbol (moo, mthname, i); + if (!mnsym) goto oops; + moo_pushtmp (moo, (moo_oop_t*)&mnsym); tmp_count++; + + /* compose a full primitive function identifier to VM's string buffer. + * pfid => mod->name + '.' + pfname */ + if (moo_copyoocstrtosbuf(moo, mod->name, 0) <= -1 || + moo_concatoocstrtosbuf(moo, dot, 0) <= -1 || + moo_concatoocstrtosbuf(moo, pfname, 0) <= -1) + { + MOO_DEBUG2 (moo, "Cannot generate primitive function method [%js] in [%O] - VM memory shortage\n", mthname, cls->name); + return -1; + } + + pfidsym = (moo_oop_char_t)moo_makesymbol (moo, moo->sbuf[0].ptr, moo->sbuf[0].len); + if (!pfidsym) + { + MOO_DEBUG2 (moo, "Cannot generate primitive function method [%js] in [%O] - symbol instantiation failure\n", mthname, cls->name); + goto oops; + } + moo_pushtmp (moo, (moo_oop_t*)&pfidsym); tmp_count++; + +#if defined(MOO_USE_OBJECT_TRAILER) + mth = (moo_oop_method_t)moo_instantiatewithtrailer (moo, moo->_method, 1, MOO_NULL, 0); +#else + mth = (moo_oop_method_t)moo_instantiate (moo, moo->_method, MOO_NULL, 1); +#endif + if (!mth) + { + MOO_DEBUG2 (moo, "Cannot generate primitive function method [%js] in [%O] - method instantiation failure\n", mthname, cls->name); + goto oops; + } + + /* store the primitive function name symbol to the literal frame */ + mth->slot[0] = (moo_oop_t)pfidsym; + + /* premable should contain the index to the literal frame which is always 0 */ + mth->owner = cls; + mth->name = mnsym; + if (variadic) preamble_flags |= MOO_METHOD_PREAMBLE_FLAG_VARIADIC; + mth->preamble = MOO_SMOOI_TO_OOP(MOO_METHOD_MAKE_PREAMBLE(MOO_METHOD_PREAMBLE_NAMED_PRIMITIVE, 0, preamble_flags)); + mth->preamble_data[0] = MOO_SMOOI_TO_OOP(0); + mth->preamble_data[1] = MOO_SMOOI_TO_OOP(0); + mth->tmpr_count = MOO_SMOOI_TO_OOP(arg_count); + mth->tmpr_nargs = MOO_SMOOI_TO_OOP(arg_count); + +/* TODO: emit BCODE_RETURN_NIL ? */ + + if (!moo_putatdic (moo, cls->mthdic[type], (moo_oop_t)mnsym, (moo_oop_t)mth)) + { + MOO_DEBUG2 (moo, "Cannot generate primitive function method [%js] in [%O] - failed to add to method dictionary\n", mthname, cls->name); + goto oops; + } + + MOO_DEBUG2 (moo, "Generated primitive function method [%js] in [%O]\n", mthname, cls->name); + + moo_poptmps (moo, tmp_count); tmp_count = 0; + return 0; + +oops: + moo_poptmps (moo, tmp_count); + return -1; +} diff --git a/stix/lib/moo.h b/stix/lib/moo.h new file mode 100644 index 0000000..0503997 --- /dev/null +++ b/stix/lib/moo.h @@ -0,0 +1,1463 @@ +/* + * $Id$ + * + Copyright (c) 2014-2016 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 _MOO_H_ +#define _MOO_H_ + +#include "moo-cmn.h" +#include "moo-rbt.h" + +/* TODO: move this macro out to the build files.... */ +#define MOO_INCLUDE_COMPILER + +/* define this to allow an pointer(OOP) object to have trailing bytes + * this is used to embed bytes codes into the back of a compile method + * object instead of putting in in a separate byte array. */ +#define MOO_USE_OBJECT_TRAILER +/* ========================================================================== */ + +/** + * The moo_errnum_t type defines the error codes. + */ +enum moo_errnum_t +{ + MOO_ENOERR, /**< no error */ + MOO_EGENERIC, /**< generic error */ + + MOO_ENOIMPL, /**< not implemented */ + MOO_ESYSERR, /**< subsystem error */ + MOO_EINTERN, /**< internal error */ + MOO_ESYSMEM, /**< insufficient system memory */ + MOO_EOOMEM, /**< insufficient object memory */ + + MOO_EINVAL, /**< invalid parameter or data */ + MOO_ENOENT, /**< data not found */ + MOO_EEXIST, /**< existing/duplicate data */ + MOO_EBUSY, + MOO_EACCES, + MOO_EPERM, + MOO_ENOTDIR, + MOO_EINTR, + MOO_EPIPE, + MOO_EAGAIN, + + MOO_ETOOBIG, /**< data too large */ + MOO_EMSGSND, /**< message sending error. even doesNotUnderstand: is not found */ + MOO_ERANGE, /**< range error. overflow and underflow */ + MOO_EBCFULL, /**< byte-code full */ + MOO_EDFULL, /**< dictionary full */ + MOO_EPFULL, /**< processor full */ + MOO_ESHFULL, /**< semaphore heap full */ + MOO_ESLFULL, /**< semaphore list full */ + MOO_EDIVBY0, /**< divide by zero */ + MOO_EIOERR, /**< I/O error */ + MOO_EECERR, /**< encoding conversion error */ + +#if defined(MOO_INCLUDE_COMPILER) + MOO_ESYNTAX /** < syntax error */ +#endif +}; +typedef enum moo_errnum_t moo_errnum_t; + +enum moo_option_t +{ + MOO_TRAIT, + MOO_LOG_MASK, + MOO_SYMTAB_SIZE, /* default system table size */ + MOO_SYSDIC_SIZE, /* default system dictionary size */ + MOO_PROCSTK_SIZE /* default process stack size */ +}; +typedef enum moo_option_t moo_option_t; + +enum moo_option_dflval_t +{ + MOO_DFL_SYMTAB_SIZE = 5000, + MOO_DFL_SYSDIC_SIZE = 5000, + MOO_DFL_PROCSTK_SIZE = 5000 +}; +typedef enum moo_option_dflval_t moo_option_dflval_t; + +enum moo_trait_t +{ + /* perform no garbage collection when the heap is full. + * you still can use moo_gc() explicitly. */ + MOO_NOGC = (1 << 0), + + /* wait for running process when exiting from the main method */ + MOO_AWAIT_PROCS = (1 << 1) +}; +typedef enum moo_trait_t moo_trait_t; + +typedef struct moo_obj_t moo_obj_t; +typedef struct moo_obj_t* moo_oop_t; + +/* these are more specialized types for moo_obj_t */ +typedef struct moo_obj_oop_t moo_obj_oop_t; +typedef struct moo_obj_char_t moo_obj_char_t; +typedef struct moo_obj_byte_t moo_obj_byte_t; +typedef struct moo_obj_halfword_t moo_obj_halfword_t; +typedef struct moo_obj_word_t moo_obj_word_t; + +/* these are more specialized types for moo_oop_t */ +typedef struct moo_obj_oop_t* moo_oop_oop_t; +typedef struct moo_obj_char_t* moo_oop_char_t; +typedef struct moo_obj_byte_t* moo_oop_byte_t; +typedef struct moo_obj_halfword_t* moo_oop_halfword_t; +typedef struct moo_obj_word_t* moo_oop_word_t; + +#define MOO_OOW_BITS (MOO_SIZEOF_OOW_T * 8) +#define MOO_OOI_BITS (MOO_SIZEOF_OOI_T * 8) +#define MOO_OOP_BITS (MOO_SIZEOF_OOP_T * 8) +#define MOO_OOHW_BITS (MOO_SIZEOF_OOHW_T * 8) + + +/* ========================================================================= */ +/* BIGINT TYPES AND MACROS */ +/* ========================================================================= */ +#if (MOO_SIZEOF_UINTMAX_T > MOO_SIZEOF_OOW_T) +# define MOO_USE_FULL_WORD +#endif + +#if defined(MOO_USE_FULL_WORD) + typedef moo_oow_t moo_liw_t; /* large integer word */ + typedef moo_ooi_t moo_lii_t; + typedef moo_uintmax_t moo_lidw_t; /* large integer double word */ + typedef moo_intmax_t moo_lidi_t; +# define MOO_SIZEOF_LIW_T MOO_SIZEOF_OOW_T +# define MOO_SIZEOF_LIDW_T MOO_SIZEOF_UINTMAX_T +# define MOO_LIW_BITS MOO_OOW_BITS +# define MOO_LIDW_BITS (MOO_SIZEOF_UINTMAX_T * 8) + + typedef moo_oop_word_t moo_oop_liword_t; +# define MOO_OBJ_TYPE_LIWORD MOO_OBJ_TYPE_WORD + +#else + typedef moo_oohw_t moo_liw_t; + typedef moo_oohi_t moo_lii_t; + typedef moo_oow_t moo_lidw_t; + typedef moo_ooi_t moo_lidi_t; +# define MOO_SIZEOF_LIW_T MOO_SIZEOF_OOHW_T +# define MOO_SIZEOF_LIDW_T MOO_SIZEOF_OOW_T +# define MOO_LIW_BITS MOO_OOHW_BITS +# define MOO_LIDW_BITS MOO_OOW_BITS + + typedef moo_oop_halfword_t moo_oop_liword_t; +# define MOO_OBJ_TYPE_LIWORD MOO_OBJ_TYPE_HALFWORD + +#endif + + +enum moo_method_type_t +{ + MOO_METHOD_INSTANCE, + MOO_METHOD_CLASS, + + /* --------------------------- */ + MOO_METHOD_TYPE_COUNT +}; +typedef enum moo_method_type_t moo_method_type_t; + +/* + * OOP encoding + * An object pointer(OOP) is an ordinary pointer value to an object. + * but some simple numeric values are also encoded into OOP using a simple + * bit-shifting and masking. + * + * A real OOP is stored without any bit-shifting while a non-OOP value encoded + * in an OOP is bit-shifted to the left by 2 and the 2 least-significant bits + * are set to 1 or 2. + * + * This scheme works because the object allocators aligns the object size to + * a multiple of sizeof(moo_oop_t). This way, the 2 least-significant bits + * of a real OOP are always 0s. + */ + +#define MOO_OOP_TAG_BITS 2 +#define MOO_OOP_TAG_SMINT 1 +#define MOO_OOP_TAG_CHAR 2 +#define MOO_OOP_TAG_ERROR 3 + +#define MOO_OOP_GET_TAG(oop) (((moo_oow_t)oop) & MOO_LBMASK(moo_oow_t, MOO_OOP_TAG_BITS)) +#define MOO_OOP_IS_NUMERIC(oop) (MOO_OOP_GET_TAG(oop) != 0) +#define MOO_OOP_IS_POINTER(oop) (MOO_OOP_GET_TAG(oop) == 0) + +#define MOO_OOP_IS_SMOOI(oop) (MOO_OOP_GET_TAG(oop) == MOO_OOP_TAG_SMINT) +#define MOO_OOP_IS_CHAR(oop) (MOO_OOP_GET_TAG(oop) == MOO_OOP_TAG_CHAR) +#define MOO_OOP_IS_ERROR(oop) (MOO_OOP_GET_TAG(oop) == MOO_OOP_TAG_ERROR) + +#define MOO_SMOOI_TO_OOP(num) ((moo_oop_t)((((moo_ooi_t)(num)) << MOO_OOP_TAG_BITS) | MOO_OOP_TAG_SMINT)) +#define MOO_OOP_TO_SMOOI(oop) (((moo_ooi_t)oop) >> MOO_OOP_TAG_BITS) +#define MOO_CHAR_TO_OOP(num) ((moo_oop_t)((((moo_oow_t)(num)) << MOO_OOP_TAG_BITS) | MOO_OOP_TAG_CHAR)) +#define MOO_OOP_TO_CHAR(oop) (((moo_oow_t)oop) >> MOO_OOP_TAG_BITS) +#define MOO_ERROR_TO_OOP(num) ((moo_oop_t)((((moo_oow_t)(num)) << MOO_OOP_TAG_BITS) | MOO_OOP_TAG_ERROR)) +#define MOO_OOP_TO_ERROR(oop) (((moo_oow_t)oop) >> MOO_OOP_TAG_BITS) + +/* SMOOI takes up 62 bits on a 64-bit architecture and 30 bits + * on a 32-bit architecture. The absolute value takes up 61 bits and 29 bits + * respectively for the sign bit. */ +#define MOO_SMOOI_BITS (MOO_OOI_BITS - MOO_OOP_TAG_BITS) +#define MOO_SMOOI_ABS_BITS (MOO_SMOOI_BITS - 1) +#define MOO_SMOOI_MAX ((moo_ooi_t)(~((moo_oow_t)0) >> (MOO_OOP_TAG_BITS + 1))) +/* Sacrificing 1 bit pattern for a negative SMOOI makes + * implementation a lot eaisier in many aspects. */ +/*#define MOO_SMOOI_MIN (-MOO_SMOOI_MAX - 1)*/ +#define MOO_SMOOI_MIN (-MOO_SMOOI_MAX) +#define MOO_IN_SMOOI_RANGE(ooi) ((ooi) >= MOO_SMOOI_MIN && (ooi) <= MOO_SMOOI_MAX) + +/* TODO: There are untested code where a small integer is converted to moo_oow_t. + * for example, the spec making macro treats the number as moo_oow_t instead of moo_ooi_t. + * as of this writing, i skip testing that part with the spec value exceeding MOO_SMOOI_MAX. + * later, please verify it works, probably by limiting the value ranges in such macros + */ + +/* + * Object structure + */ +enum moo_obj_type_t +{ + MOO_OBJ_TYPE_OOP, + MOO_OBJ_TYPE_CHAR, + MOO_OBJ_TYPE_BYTE, + MOO_OBJ_TYPE_HALFWORD, + MOO_OBJ_TYPE_WORD + +/* + MOO_OBJ_TYPE_UINT8, + MOO_OBJ_TYPE_UINT16, + MOO_OBJ_TYPE_UINT32, +*/ + +/* NOTE: you can have MOO_OBJ_SHORT, MOO_OBJ_INT + * MOO_OBJ_LONG, MOO_OBJ_FLOAT, MOO_OBJ_DOUBLE, etc + * type type field being 6 bits long, you can have up to 64 different types. + + MOO_OBJ_TYPE_SHORT, + MOO_OBJ_TYPE_INT, + MOO_OBJ_TYPE_LONG, + MOO_OBJ_TYPE_FLOAT, + MOO_OBJ_TYPE_DOUBLE */ +}; +typedef enum moo_obj_type_t moo_obj_type_t; + +/* ========================================================================= + * Object header structure + * + * _flags: + * type: the type of a payload item. + * one of MOO_OBJ_TYPE_OOP, MOO_OBJ_TYPE_CHAR, + * MOO_OBJ_TYPE_BYTE, MOO_OBJ_TYPE_HALFWORD, MOO_OBJ_TYPE_WORD + * unit: the size of a payload item in bytes. + * extra: 0 or 1. 1 indicates that the payload contains 1 more + * item than the value of the size field. used for a + * terminating null in a variable-char object. internel + * use only. + * kernel: 0 or 1. indicates that the object is a kernel object. + * VM disallows layout changes of a kernel object. + * internal use only. + * moved: 0 or 1. used by GC. internal use only. + * ngc: 0 or 1, used by GC. internal use only. + * trailer: 0 or 1. indicates that there are trailing bytes + * after the object payload. internal use only. + * + * _size: the number of payload items in an object. + * it doesn't include the header size. + * + * The total number of bytes occupied by an object can be calculated + * with this fomula: + * sizeof(moo_obj_t) + ALIGN((size + extra) * unit), sizeof(moo_oop_t)) + * + * If the type is known to be not MOO_OBJ_TYPE_CHAR, you can assume that + * 'extra' is 0. So you can simplify the fomula in such a context. + * sizeof(moo_obj_t) + ALIGN(size * unit), sizeof(moo_oop_t)) + * + * The ALIGN() macro is used above since allocation adjusts the payload + * size to a multiple of sizeof(moo_oop_t). it assumes that sizeof(moo_obj_t) + * is a multiple of sizeof(moo_oop_t). See the MOO_BYTESOF() macro. + * + * Due to the header structure, an object can only contain items of + * homogeneous data types in the payload. + * + * It's actually possible to split the size field into 2. For example, + * the upper half contains the number of oops and the lower half contains + * the number of bytes/chars. This way, a variable-byte class or a variable-char + * class can have normal instance variables. On the contrary, the actual byte + * size calculation and the access to the payload fields become more complex. + * Therefore, i've dropped the idea. + * ========================================================================= */ +#define MOO_OBJ_FLAGS_TYPE_BITS 6 +#define MOO_OBJ_FLAGS_UNIT_BITS 5 +#define MOO_OBJ_FLAGS_EXTRA_BITS 1 +#define MOO_OBJ_FLAGS_KERNEL_BITS 2 +#define MOO_OBJ_FLAGS_MOVED_BITS 1 +#define MOO_OBJ_FLAGS_NGC_BITS 1 +#define MOO_OBJ_FLAGS_TRAILER_BITS 1 + +#define MOO_OBJ_FLAGS_TYPE_SHIFT (MOO_OBJ_FLAGS_UNIT_BITS + MOO_OBJ_FLAGS_UNIT_SHIFT) +#define MOO_OBJ_FLAGS_UNIT_SHIFT (MOO_OBJ_FLAGS_EXTRA_BITS + MOO_OBJ_FLAGS_EXTRA_SHIFT) +#define MOO_OBJ_FLAGS_EXTRA_SHIFT (MOO_OBJ_FLAGS_KERNEL_BITS + MOO_OBJ_FLAGS_KERNEL_SHIFT) +#define MOO_OBJ_FLAGS_KERNEL_SHIFT (MOO_OBJ_FLAGS_MOVED_BITS + MOO_OBJ_FLAGS_MOVED_SHIFT) +#define MOO_OBJ_FLAGS_MOVED_SHIFT (MOO_OBJ_FLAGS_NGC_BITS + MOO_OBJ_FLAGS_NGC_SHIFT) +#define MOO_OBJ_FLAGS_NGC_SHIFT (MOO_OBJ_FLAGS_TRAILER_BITS + MOO_OBJ_FLAGS_TRAILER_SHIFT) +#define MOO_OBJ_FLAGS_TRAILER_SHIFT (0) + +#define MOO_OBJ_GET_FLAGS_TYPE(oop) MOO_GETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_TYPE_SHIFT, MOO_OBJ_FLAGS_TYPE_BITS) +#define MOO_OBJ_GET_FLAGS_UNIT(oop) MOO_GETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_UNIT_SHIFT, MOO_OBJ_FLAGS_UNIT_BITS) +#define MOO_OBJ_GET_FLAGS_EXTRA(oop) MOO_GETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_EXTRA_SHIFT, MOO_OBJ_FLAGS_EXTRA_BITS) +#define MOO_OBJ_GET_FLAGS_KERNEL(oop) MOO_GETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_KERNEL_SHIFT, MOO_OBJ_FLAGS_KERNEL_BITS) +#define MOO_OBJ_GET_FLAGS_MOVED(oop) MOO_GETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_MOVED_SHIFT, MOO_OBJ_FLAGS_MOVED_BITS) +#define MOO_OBJ_GET_FLAGS_NGC(oop) MOO_GETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_NGC_SHIFT, MOO_OBJ_FLAGS_NGC_BITS) +#define MOO_OBJ_GET_FLAGS_TRAILER(oop) MOO_GETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_TRAILER_SHIFT, MOO_OBJ_FLAGS_TRAILER_BITS) + +#define MOO_OBJ_SET_FLAGS_TYPE(oop,v) MOO_SETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_TYPE_SHIFT, MOO_OBJ_FLAGS_TYPE_BITS, v) +#define MOO_OBJ_SET_FLAGS_UNIT(oop,v) MOO_SETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_UNIT_SHIFT, MOO_OBJ_FLAGS_UNIT_BITS, v) +#define MOO_OBJ_SET_FLAGS_EXTRA(oop,v) MOO_SETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_EXTRA_SHIFT, MOO_OBJ_FLAGS_EXTRA_BITS, v) +#define MOO_OBJ_SET_FLAGS_KERNEL(oop,v) MOO_SETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_KERNEL_SHIFT, MOO_OBJ_FLAGS_KERNEL_BITS, v) +#define MOO_OBJ_SET_FLAGS_MOVED(oop,v) MOO_SETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_MOVED_SHIFT, MOO_OBJ_FLAGS_MOVED_BITS, v) +#define MOO_OBJ_SET_FLAGS_NGC(oop,v) MOO_SETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_NGC_SHIFT, MOO_OBJ_FLAGS_NGC_BITS, v) +#define MOO_OBJ_SET_FLAGS_TRAILER(oop,v) MOO_SETBITS(moo_oow_t, (oop)->_flags, MOO_OBJ_FLAGS_TRAILER_SHIFT, MOO_OBJ_FLAGS_TRAILER_BITS, v) + +#define MOO_OBJ_GET_SIZE(oop) ((oop)->_size) +#define MOO_OBJ_GET_CLASS(oop) ((oop)->_class) + +#define MOO_OBJ_SET_SIZE(oop,v) ((oop)->_size = (v)) +#define MOO_OBJ_SET_CLASS(oop,c) ((oop)->_class = (c)) + +/* [NOTE] this macro doesn't include the size of the trailer */ +#define MOO_OBJ_BYTESOF(oop) ((MOO_OBJ_GET_SIZE(oop) + MOO_OBJ_GET_FLAGS_EXTRA(oop)) * MOO_OBJ_GET_FLAGS_UNIT(oop)) + +/* [NOTE] this macro doesn't check the range of the actual value. + * make sure that the value of each bit fields given falls within the + * possible range of the defined bits */ +#define MOO_OBJ_MAKE_FLAGS(t,u,e,k,m,g,r) ( \ + (((moo_oow_t)(t)) << MOO_OBJ_FLAGS_TYPE_SHIFT) | \ + (((moo_oow_t)(u)) << MOO_OBJ_FLAGS_UNIT_SHIFT) | \ + (((moo_oow_t)(e)) << MOO_OBJ_FLAGS_EXTRA_SHIFT) | \ + (((moo_oow_t)(k)) << MOO_OBJ_FLAGS_KERNEL_SHIFT) | \ + (((moo_oow_t)(m)) << MOO_OBJ_FLAGS_MOVED_SHIFT) | \ + (((moo_oow_t)(g)) << MOO_OBJ_FLAGS_NGC_SHIFT) | \ + (((moo_oow_t)(r)) << MOO_OBJ_FLAGS_TRAILER_SHIFT) \ +) + +#define MOO_OBJ_HEADER \ + moo_oow_t _flags; \ + moo_oow_t _size; \ + moo_oop_t _class + +struct moo_obj_t +{ + MOO_OBJ_HEADER; +}; + +struct moo_obj_oop_t +{ + MOO_OBJ_HEADER; + moo_oop_t slot[1]; +}; + +struct moo_obj_char_t +{ + MOO_OBJ_HEADER; + moo_ooch_t slot[1]; +}; + +struct moo_obj_byte_t +{ + MOO_OBJ_HEADER; + moo_oob_t slot[1]; +}; + +struct moo_obj_halfword_t +{ + MOO_OBJ_HEADER; + moo_oohw_t slot[1]; +}; + +struct moo_obj_word_t +{ + MOO_OBJ_HEADER; + moo_oow_t slot[1]; +}; + +typedef struct moo_trailer_t moo_trailer_t; +struct moo_trailer_t +{ + moo_oow_t size; + moo_oob_t slot[1]; +}; + +#define MOO_SET_NAMED_INSTVARS 2 +typedef struct moo_set_t moo_set_t; +typedef struct moo_set_t* moo_oop_set_t; +struct moo_set_t +{ + MOO_OBJ_HEADER; + moo_oop_t tally; /* SmallInteger */ + moo_oop_oop_t bucket; /* Array */ +}; + +#define MOO_CLASS_NAMED_INSTVARS 11 +typedef struct moo_class_t moo_class_t; +typedef struct moo_class_t* moo_oop_class_t; +struct moo_class_t +{ + MOO_OBJ_HEADER; + + moo_oop_t spec; /* SmallInteger. instance specification */ + moo_oop_t selfspec; /* SmallInteger. specification of the class object itself */ + + moo_oop_t superclass; /* Another class */ + moo_oop_t subclasses; /* Array of subclasses */ + + moo_oop_char_t name; /* Symbol */ + + /* == NEVER CHANGE THIS ORDER OF 3 ITEMS BELOW == */ + moo_oop_char_t instvars; /* String */ + moo_oop_char_t classvars; /* String */ + moo_oop_char_t classinstvars; /* String */ + /* == NEVER CHANGE THE ORDER OF 3 ITEMS ABOVE == */ + + moo_oop_char_t pooldics; /* String - pool dictionaries imported */ + + /* [0] - instance methods, MethodDictionary + * [1] - class methods, MethodDictionary */ + moo_oop_set_t mthdic[MOO_METHOD_TYPE_COUNT]; + + /* indexed part afterwards */ + moo_oop_t slot[1]; /* class instance variables and class variables. */ +}; + +#define MOO_ASSOCIATION_NAMED_INSTVARS 2 +typedef struct moo_association_t moo_association_t; +typedef struct moo_association_t* moo_oop_association_t; +struct moo_association_t +{ + MOO_OBJ_HEADER; + moo_oop_t key; + moo_oop_t value; +}; + +#if defined(MOO_USE_OBJECT_TRAILER) +# define MOO_METHOD_NAMED_INSTVARS 8 +#else +# define MOO_METHOD_NAMED_INSTVARS 9 +#endif +typedef struct moo_method_t moo_method_t; +typedef struct moo_method_t* moo_oop_method_t; +struct moo_method_t +{ + MOO_OBJ_HEADER; + + moo_oop_class_t owner; /* Class */ + + moo_oop_char_t name; /* Symbol, method name */ + + /* primitive number */ + moo_oop_t preamble; /* SmallInteger */ + moo_oop_t preamble_data[2]; /* SmallInteger */ + + /* number of temporaries including arguments */ + moo_oop_t tmpr_count; /* SmallInteger */ + + /* number of arguments in temporaries */ + moo_oop_t tmpr_nargs; /* SmallInteger */ + +#if defined(MOO_USE_OBJECT_TRAILER) + /* no code field is used */ +#else + moo_oop_byte_t code; /* ByteArray */ +#endif + + moo_oop_t source; /* TODO: what should I put? */ + + /* == variable indexed part == */ + moo_oop_t slot[1]; /* it stores literals */ +}; + +#if defined(MOO_USE_OBJECT_TRAILER) + + /* if m is to be type-cast to moo_oop_method_t, the macro must be + * redefined to this: + * (&((moo_oop_method_t)m)>slot[MOO_OBJ_GET_SIZE(m) + 1 - MOO_METHOD_NAMED_INSTVARS]) + */ +# define MOO_METHOD_GET_CODE_BYTE(m) ((moo_oob_t*)&((moo_oop_oop_t)m)->slot[MOO_OBJ_GET_SIZE(m) + 1]) +# define MOO_METHOD_GET_CODE_SIZE(m) ((moo_oow_t)((moo_oop_oop_t)m)->slot[MOO_OBJ_GET_SIZE(m)]) +#else +# define MOO_METHOD_GET_CODE_BYTE(m) ((m)->code->slot) +# define MOO_METHOD_GET_CODE_SIZE(m) MOO_OBJ_GET_SIZE((m)->code) +#endif + +/* The preamble field is composed of: + * 2-bit flag + * 6-bit code + * 16-bit index + * + * The code can be one of the following values: + * 0 - no special action + * 1 - return self + * 2 - return nil + * 3 - return true + * 4 - return false + * 5 - return index. + * 6 - return -index. + * 7 - return instvar[index] + * 8 - do primitive[index] + * 9 - do named primitive[index] + * 10 - exception handler + * 11 - ensure block + */ + +/* NOTE: changing preamble code bit structure requires changes to CompiledMethod>>preambleCode */ +#define MOO_METHOD_MAKE_PREAMBLE(code,index,flags) ((((moo_ooi_t)index) << 8) | ((moo_ooi_t)code << 2) | flags) +#define MOO_METHOD_GET_PREAMBLE_CODE(preamble) ((((moo_ooi_t)preamble) & 0xFF) >> 2) +#define MOO_METHOD_GET_PREAMBLE_INDEX(preamble) (((moo_ooi_t)preamble) >> 8) +#define MOO_METHOD_GET_PREAMBLE_FLAGS(preamble) (((moo_ooi_t)preamble) & 0x3) + +/* preamble codes */ +#define MOO_METHOD_PREAMBLE_NONE 0 +#define MOO_METHOD_PREAMBLE_RETURN_RECEIVER 1 +#define MOO_METHOD_PREAMBLE_RETURN_NIL 2 +#define MOO_METHOD_PREAMBLE_RETURN_TRUE 3 +#define MOO_METHOD_PREAMBLE_RETURN_FALSE 4 +#define MOO_METHOD_PREAMBLE_RETURN_INDEX 5 +#define MOO_METHOD_PREAMBLE_RETURN_NEGINDEX 6 +#define MOO_METHOD_PREAMBLE_RETURN_INSTVAR 7 +#define MOO_METHOD_PREAMBLE_PRIMITIVE 8 +#define MOO_METHOD_PREAMBLE_NAMED_PRIMITIVE 9 /* index is an index to the symbol table */ + +#define MOO_METHOD_PREAMBLE_EXCEPTION 10 /* NOTE changing this requires changes in Except.st */ +#define MOO_METHOD_PREAMBLE_ENSURE 11 /* NOTE changing this requires changes in Except.st */ + +/* the index is an 16-bit unsigned integer. */ +#define MOO_METHOD_PREAMBLE_INDEX_MIN 0x0000 +#define MOO_METHOD_PREAMBLE_INDEX_MAX 0xFFFF +#define MOO_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(num) ((num) >= MOO_METHOD_PREAMBLE_INDEX_MIN && (num) <= MOO_METHOD_PREAMBLE_INDEX_MAX) + +/* preamble flags */ +#define MOO_METHOD_PREAMBLE_FLAG_VARIADIC (1 << 0) + +/* NOTE: if you change the number of instance variables for moo_context_t, + * you need to change the defintion of BlockContext and MethodContext. + * plus, you need to update various exception handling code in MethodContext */ +#define MOO_CONTEXT_NAMED_INSTVARS 8 +typedef struct moo_context_t moo_context_t; +typedef struct moo_context_t* moo_oop_context_t; +struct moo_context_t +{ + MOO_OBJ_HEADER; + + /* it points to the active context at the moment when + * this context object has been activated. a new method context + * is activated as a result of normal message sending and a block + * context is activated when it is sent 'value'. it's set to + * nil if a block context created hasn't received 'value'. */ + moo_oop_context_t sender; + + /* SmallInteger, instruction pointer */ + moo_oop_t ip; + + /* SmallInteger, stack pointer. the actual stack pointer is in the active + * process. For a method context, it stores the stack pointer of the active + * process before it gets activated. the stack pointer of the active + * process is restored using this value upon returning. This field is + * almost useless for a block context. */ + moo_oop_t sp; + + /* SmallInteger. Number of temporaries. + * For a block context, it's inclusive of the temporaries + * defined its 'home'. */ + moo_oop_t ntmprs; + + /* CompiledMethod for a method context, + * SmallInteger for a block context */ + moo_oop_t method_or_nargs; + + /* it points to the receiver of the message for a method context. + * a base block context(created but not yet activated) has nil in this + * field. if a block context is activated by 'value', it points + * to the block context object used as a base for shallow-copy. */ + moo_oop_t receiver_or_source; + + /* it is set to nil for a method context. + * for a block context, it points to the active context at the + * moment the block context was created. that is, it points to + * a method context where the base block has been defined. + * an activated block context copies this field from the source. */ + moo_oop_t home; + + /* when a method context is created, it is set to itself. no change is + * made when the method context is activated. when a block context is + * created (when MAKE_BLOCK or BLOCK_COPY is executed), it is set to the + * origin of the active context. when the block context is shallow-copied + * for activation (when it is sent 'value'), it is set to the origin of + * the source block context. */ + moo_oop_context_t origin; + + /* variable indexed part - actual arguments and temporaries are placed here */ + moo_oop_t slot[1]; /* stack */ +}; + + +#define MOO_PROCESS_NAMED_INSTVARS 7 +typedef struct moo_process_t moo_process_t; +typedef struct moo_process_t* moo_oop_process_t; + +#define MOO_SEMAPHORE_NAMED_INSTVARS 6 +typedef struct moo_semaphore_t moo_semaphore_t; +typedef struct moo_semaphore_t* moo_oop_semaphore_t; + +struct moo_process_t +{ + MOO_OBJ_HEADER; + moo_oop_context_t initial_context; + moo_oop_context_t current_context; + + moo_oop_t state; /* SmallInteger */ + moo_oop_t sp; /* stack pointer. SmallInteger */ + + moo_oop_process_t prev; + moo_oop_process_t next; + + moo_oop_semaphore_t sem; + + /* == variable indexed part == */ + moo_oop_t slot[1]; /* process stack */ +}; + +struct moo_semaphore_t +{ + MOO_OBJ_HEADER; + moo_oop_t count; /* SmallInteger */ + moo_oop_process_t waiting_head; + moo_oop_process_t waiting_tail; + moo_oop_t heap_index; /* index to the heap */ + moo_oop_t heap_ftime_sec; /* firing time */ + moo_oop_t heap_ftime_nsec; /* firing time */ +}; + +#define MOO_PROCESS_SCHEDULER_NAMED_INSTVARS 5 +typedef struct moo_process_scheduler_t moo_process_scheduler_t; +typedef struct moo_process_scheduler_t* moo_oop_process_scheduler_t; +struct moo_process_scheduler_t +{ + MOO_OBJ_HEADER; + moo_oop_t tally; /* SmallInteger, the number of runnable processes */ + moo_oop_process_t active; /* pointer to an active process in the runnable process list */ + moo_oop_process_t runnable_head; /* runnable process list */ + moo_oop_process_t runnable_tail; /* runnable process list */ + moo_oop_t sempq; /* SemaphoreHeap */ +}; + +/** + * The MOO_CLASSOF() macro return the class of an object including a numeric + * object encoded into a pointer. + */ +#define MOO_CLASSOF(moo,oop) \ + (MOO_OOP_GET_TAG(oop)? (*moo->tagged_classes[MOO_OOP_GET_TAG(oop)]): MOO_OBJ_GET_CLASS(oop)) + +/** + * The MOO_BYTESOF() macro returns the size of the payload of + * an object in bytes. If the pointer given encodes a numeric value, + * it returns the size of #moo_oow_t in bytes. + */ +#define MOO_BYTESOF(moo,oop) \ + (MOO_OOP_IS_NUMERIC(oop)? MOO_SIZEOF(moo_oow_t): MOO_OBJ_BYTESOF(oop)) + +/** + * The MOO_ISTYPEOF() macro is a safe replacement for MOO_OBJ_GET_FLAGS_TYPE() + */ +#define MOO_ISTYPEOF(moo,oop,type) \ + (!MOO_OOP_IS_NUMERIC(oop) && MOO_OBJ_GET_FLAGS_TYPE(oop) == (type)) + +typedef struct moo_heap_t moo_heap_t; + +struct moo_heap_t +{ + moo_uint8_t* base; /* start of a heap */ + moo_uint8_t* limit; /* end of a heap */ + moo_uint8_t* ptr; /* next allocation pointer */ +}; + +/* ========================================================================= + * VIRTUAL MACHINE PRIMITIVES + * ========================================================================= */ +typedef void* (*moo_vmprim_opendl_t) (moo_t* moo, const moo_ooch_t* name); +typedef void (*moo_vmprim_closedl_t) (moo_t* moo, void* handle); +typedef void* (*moo_vmprim_getdlsym_t) (moo_t* moo, void* handle, const moo_ooch_t* name); + +typedef void (*moo_log_write_t) (moo_t* moo, moo_oow_t mask, const moo_ooch_t* msg, moo_oow_t len); + +struct moo_vmprim_t +{ + moo_vmprim_opendl_t dl_open; + moo_vmprim_closedl_t dl_close; + moo_vmprim_getdlsym_t dl_getsym; + moo_log_write_t log_write; +}; + +typedef struct moo_vmprim_t moo_vmprim_t; + +/* ========================================================================= + * IO MANIPULATION + * ========================================================================= */ + +/* TODO: MOVE moo_ioimpl_t HERE */ + +/* ========================================================================= + * CALLBACK MANIPULATION + * ========================================================================= */ +typedef void (*moo_cbimpl_t) (moo_t* moo); + +typedef struct moo_cb_t moo_cb_t; +struct moo_cb_t +{ + moo_cbimpl_t gc; + moo_cbimpl_t fini; + + /* private below */ + moo_cb_t* prev; + moo_cb_t* next; +}; + + +/* ========================================================================= + * MODULE MANIPULATION + * ========================================================================= */ +#define MOO_MOD_NAME_LEN_MAX 120 + +enum moo_pfrc_t +{ + MOO_PF_HARD_FAILURE = -1, + MOO_PF_FAILURE = 0, + MOO_PF_SUCCESS = 1 +}; +typedef enum moo_pfrc_t moo_pfrc_t; + +/* primitive function implementation type */ +typedef moo_pfrc_t (*moo_pfimpl_t) ( + moo_t* moo, + moo_ooi_t nargs +); + +typedef struct moo_mod_t moo_mod_t; + +typedef int (*moo_mod_load_t) ( + moo_t* moo, + moo_mod_t* mod +); + +typedef int (*moo_mod_import_t) ( + moo_t* moo, + moo_mod_t* mod, + moo_oop_t _class +); + +typedef moo_pfimpl_t (*moo_mod_query_t) ( + moo_t* moo, + moo_mod_t* mod, + const moo_uch_t* name +); + +typedef void (*moo_mod_unload_t) ( + moo_t* moo, + moo_mod_t* mod +); + +struct moo_mod_t +{ + const moo_ooch_t name[MOO_MOD_NAME_LEN_MAX + 1]; + moo_mod_import_t import; + moo_mod_query_t query; + moo_mod_unload_t unload; + void* ctx; +}; + +struct moo_mod_data_t +{ + void* handle; + moo_rbt_pair_t* pair; /* internal backreference to moo->modtab */ + moo_mod_t mod; +}; +typedef struct moo_mod_data_t moo_mod_data_t; + + + +struct moo_sbuf_t +{ + moo_ooch_t* ptr; + moo_oow_t len; + moo_oow_t capa; +}; +typedef struct moo_sbuf_t moo_sbuf_t; + +/* ========================================================================= + * MOO VM + * ========================================================================= */ +#if defined(MOO_INCLUDE_COMPILER) +typedef struct moo_compiler_t moo_compiler_t; +#endif + +struct moo_t +{ + moo_mmgr_t* mmgr; + moo_cmgr_t* cmgr; + moo_errnum_t errnum; + + struct + { + unsigned int trait; + unsigned int log_mask; + moo_oow_t dfl_symtab_size; + moo_oow_t dfl_sysdic_size; + moo_oow_t dfl_procstk_size; + } option; + + moo_vmprim_t vmprim; + + moo_cb_t* cblist; + moo_rbt_t modtab; /* primitive module table */ + + struct + { + moo_ooch_t* ptr; + moo_oow_t len; + moo_oow_t capa; + int last_mask; + } log; + + /* ========================= */ + + moo_heap_t* permheap; /* TODO: put kernel objects to here */ + moo_heap_t* curheap; + moo_heap_t* newheap; + + /* ============================================================= + * nil, true, false + * ============================================================= */ + moo_oop_t _nil; /* pointer to the nil object */ + moo_oop_t _true; + moo_oop_t _false; + + /* ============================================================= + * KERNEL CLASSES + * Be sure to Keep these kernel class pointers registered in the + * kernel_classes table in gc.c + * ============================================================= */ + moo_oop_t _apex; /* Apex */ + moo_oop_t _undefined_object; /* UndefinedObject */ + moo_oop_t _class; /* Class */ + moo_oop_t _object; /* Object */ + moo_oop_t _string; /* String */ + + moo_oop_t _symbol; /* Symbol */ + moo_oop_t _array; /* Array */ + moo_oop_t _byte_array; /* ByteArray */ + moo_oop_t _symbol_set; /* SymbolSet */ + moo_oop_t _system_dictionary; /* SystemDictionary */ + + moo_oop_t _namespace; /* Namespace */ + moo_oop_t _pool_dictionary; /* PoolDictionary */ + moo_oop_t _method_dictionary; /* MethodDictionary */ + moo_oop_t _method; /* CompiledMethod */ + moo_oop_t _association; /* Association */ + + moo_oop_t _method_context; /* MethodContext */ + moo_oop_t _block_context; /* BlockContext */ + moo_oop_t _process; /* Process */ + moo_oop_t _semaphore; /* Semaphore */ + moo_oop_t _process_scheduler; /* ProcessScheduler */ + + moo_oop_t _error_class; /* Error */ + moo_oop_t _true_class; /* True */ + moo_oop_t _false_class; /* False */ + moo_oop_t _character; /* Character */ + moo_oop_t _small_integer; /* SmallInteger */ + + moo_oop_t _large_positive_integer; /* LargePositiveInteger */ + moo_oop_t _large_negative_integer; /* LargeNegativeInteger */ + /* ============================================================= + * END KERNEL CLASSES + * ============================================================= */ + + /* ============================================================= + * KEY SYSTEM DICTIONARIES + * ============================================================= */ + moo_oop_t* tagged_classes[4]; + moo_oop_set_t symtab; /* system-wide symbol table. instance of SymbolSet */ + moo_oop_set_t sysdic; /* system dictionary. instance of SystemDictionary */ + moo_oop_process_scheduler_t processor; /* instance of ProcessScheduler */ + moo_oop_process_t nil_process; /* instance of Process */ + + /* pending asynchronous semaphores */ + moo_oop_semaphore_t* sem_list; + moo_oow_t sem_list_count; + moo_oow_t sem_list_capa; + + /* semaphores sorted according to time-out */ + moo_oop_semaphore_t* sem_heap; + moo_oow_t sem_heap_count; + moo_oow_t sem_heap_capa; + + moo_oop_t* tmp_stack[256]; /* stack for temporaries */ + moo_oow_t tmp_count; + + /* ============================================================= + * EXECUTION REGISTERS + * ============================================================= */ + moo_oop_context_t initial_context; /* fake initial context */ + moo_oop_context_t active_context; + moo_oop_method_t active_method; + moo_oob_t* active_code; + moo_ooi_t sp; + moo_ooi_t ip; + int proc_switched; /* TODO: this is temporary. implement something else to skip immediate context switching */ + int switch_proc; + moo_ntime_t vm_time_offset; + /* ============================================================= + * END EXECUTION REGISTERS + * ============================================================= */ + + /* == BIGINT CONVERSION == */ + struct + { + int safe_ndigits; + moo_oow_t multiplier; + } bigint[37]; + /* == END BIGINT CONVERSION == */ + + moo_sbuf_t sbuf[64]; + +#if defined(MOO_INCLUDE_COMPILER) + moo_compiler_t* c; +#endif +}; + + +/* TODO: stack bound check when pushing */ +#define MOO_STACK_PUSH(moo,v) \ + do { \ + (moo)->sp = (moo)->sp + 1; \ + (moo)->processor->active->slot[(moo)->sp] = v; \ + } while (0) + +#define MOO_STACK_GET(moo,v_sp) ((moo)->processor->active->slot[v_sp]) +#define MOO_STACK_SET(moo,v_sp,v_obj) ((moo)->processor->active->slot[v_sp] = v_obj) + +#define MOO_STACK_GETTOP(moo) MOO_STACK_GET(moo, (moo)->sp) +#define MOO_STACK_SETTOP(moo,v_obj) MOO_STACK_SET(moo, (moo)->sp, v_obj) + +#define MOO_STACK_POP(moo) ((moo)->sp = (moo)->sp - 1) +#define MOO_STACK_POPS(moo,count) ((moo)->sp = (moo)->sp - (count)) +#define MOO_STACK_ISEMPTY(moo) ((moo)->sp <= -1) + +#define MOO_STACK_GETARG(moo,nargs,idx) MOO_STACK_GET(moo, (moo)->sp - ((nargs) - (idx) - 1)) +#define MOO_STACK_GETRCV(moo,nargs) MOO_STACK_GET(moo, (moo)->sp - nargs); + +/* you can't access arguments and receiver after this macro. + * also you must not call this macro more than once */ +#define MOO_STACK_SETRET(moo,nargs,retv) (MOO_STACK_POPS(moo, nargs), MOO_STACK_SETTOP(moo, (retv))) +#define MOO_STACK_SETRETTORCV(moo,nargs) (MOO_STACK_POPS(moo, nargs)) +#define MOO_STACK_SETRETTOERROR(moo,nargs) MOO_STACK_SETRET(moo, nargs, MOO_ERROR_TO_OOP(moo->errnum)) +/*#define MOO_STACK_SETRETTOERROR(moo,nargs,ec) MOO_STACK_SETRET(moo, nargs, MOO_ERROR_TO_OOP(ec))*/ + +/* ========================================================================= + * MOO VM LOGGING + * ========================================================================= */ + +enum moo_log_mask_t +{ + MOO_LOG_DEBUG = (1 << 0), + MOO_LOG_INFO = (1 << 1), + MOO_LOG_WARN = (1 << 2), + MOO_LOG_ERROR = (1 << 3), + MOO_LOG_FATAL = (1 << 4), + + MOO_LOG_MNEMONIC = (1 << 8), /* bytecode mnemonic */ + MOO_LOG_GC = (1 << 9), + MOO_LOG_IC = (1 << 10), /* instruction cycle, fetch-decode-execute */ + MOO_LOG_PRIMITIVE = (1 << 11), + MOO_LOG_APP = (1 << 12) /* moo applications, set by moo logging primitive */ +}; +typedef enum moo_log_mask_t moo_log_mask_t; + +#define MOO_LOG_ENABLED(moo,mask) ((moo)->option.log_mask & (mask)) + +#define MOO_LOG0(moo,mask,fmt) do { if (MOO_LOG_ENABLED(moo,mask)) moo_logbfmt(moo, mask, fmt); } while(0) +#define MOO_LOG1(moo,mask,fmt,a1) do { if (MOO_LOG_ENABLED(moo,mask)) moo_logbfmt(moo, mask, fmt, a1); } while(0) +#define MOO_LOG2(moo,mask,fmt,a1,a2) do { if (MOO_LOG_ENABLED(moo,mask)) moo_logbfmt(moo, mask, fmt, a1, a2); } while(0) +#define MOO_LOG3(moo,mask,fmt,a1,a2,a3) do { if (MOO_LOG_ENABLED(moo,mask)) moo_logbfmt(moo, mask, fmt, a1, a2, a3); } while(0) +#define MOO_LOG4(moo,mask,fmt,a1,a2,a3,a4) do { if (MOO_LOG_ENABLED(moo,mask)) moo_logbfmt(moo, mask, fmt, a1, a2, a3, a4); } while(0) +#define MOO_LOG5(moo,mask,fmt,a1,a2,a3,a4,a5) do { if (MOO_LOG_ENABLED(moo,mask)) moo_logbfmt(moo, mask, fmt, a1, a2, a3, a4, a5); } while(0) +#define MOO_LOG6(moo,mask,fmt,a1,a2,a3,a4,a5,a6) do { if (MOO_LOG_ENABLED(moo,mask)) moo_logbfmt(moo, mask, fmt, a1, a2, a3, a4, a5, a6); } while(0) + +#define MOO_DEBUG0(moo,fmt) MOO_LOG0(moo, MOO_LOG_DEBUG, fmt) +#define MOO_DEBUG1(moo,fmt,a1) MOO_LOG1(moo, MOO_LOG_DEBUG, fmt, a1) +#define MOO_DEBUG2(moo,fmt,a1,a2) MOO_LOG2(moo, MOO_LOG_DEBUG, fmt, a1, a2) +#define MOO_DEBUG3(moo,fmt,a1,a2,a3) MOO_LOG3(moo, MOO_LOG_DEBUG, fmt, a1, a2, a3) +#define MOO_DEBUG4(moo,fmt,a1,a2,a3,a4) MOO_LOG4(moo, MOO_LOG_DEBUG, fmt, a1, a2, a3, a4) +#define MOO_DEBUG5(moo,fmt,a1,a2,a3,a4,a5) MOO_LOG5(moo, MOO_LOG_DEBUG, fmt, a1, a2, a3, a4, a5) +#define MOO_DEBUG6(moo,fmt,a1,a2,a3,a4,a5,a6) MOO_LOG6(moo, MOO_LOG_DEBUG, fmt, a1, a2, a3, a4, a5, a6) + +#define MOO_INFO0(moo,fmt) MOO_LOG0(moo, MOO_LOG_INFO, fmt) +#define MOO_INFO1(moo,fmt,a1) MOO_LOG1(moo, MOO_LOG_INFO, fmt, a1) +#define MOO_INFO2(moo,fmt,a1,a2) MOO_LOG2(moo, MOO_LOG_INFO, fmt, a1, a2) +#define MOO_INFO3(moo,fmt,a1,a2,a3) MOO_LOG3(moo, MOO_LOG_INFO, fmt, a1, a2, a3) +#define MOO_INFO4(moo,fmt,a1,a2,a3,a4) MOO_LOG4(moo, MOO_LOG_INFO, fmt, a1, a2, a3, a4) +#define MOO_INFO5(moo,fmt,a1,a2,a3,a4,a5) MOO_LOG5(moo, MOO_LOG_INFO, fmt, a1, a2, a3, a4, a5) +#define MOO_INFO6(moo,fmt,a1,a2,a3,a4,a5,a6) MOO_LOG6(moo, MOO_LOG_INFO, fmt, a1, a2, a3, a4, a5, a6) + + +/* ========================================================================= + * MOO ASSERTION + * ========================================================================= */ +#if defined(NDEBUG) +# define MOO_ASSERT(moo,expr) ((void)0) +#else +# define MOO_ASSERT(moo,expr) ((void)((expr) || (moo_assertfailed (moo, #expr, __FILE__, __LINE__), 0))) +#endif + + +#if defined(MOO_INCLUDE_COMPILER) +enum moo_iocmd_t +{ + MOO_IO_OPEN, + MOO_IO_CLOSE, + MOO_IO_READ +}; +typedef enum moo_iocmd_t moo_iocmd_t; + +struct moo_ioloc_t +{ + unsigned long int line; /**< line */ + unsigned long int colm; /**< column */ + const moo_ooch_t* file; /**< file specified in #include */ +}; +typedef struct moo_ioloc_t moo_ioloc_t; + +typedef struct moo_ioarg_t moo_ioarg_t; + +typedef moo_ooi_t (*moo_ioimpl_t) ( + moo_t* moo, + moo_iocmd_t cmd, + moo_ioarg_t* arg +); + +enum moo_synerrnum_t +{ + MOO_SYNERR_NOERR, + MOO_SYNERR_ILCHR, /* illegal character */ + MOO_SYNERR_CMTNC, /* comment not closed */ + MOO_SYNERR_STRNC, /* string not closed */ + MOO_SYNERR_CLTNT, /* character literal not terminated */ + MOO_SYNERR_HLTNT, /* hased literal not terminated */ + MOO_SYNERR_CHARLIT, /* wrong character literal */ + MOO_SYNERR_COLON, /* : expected */ + MOO_SYNERR_STRING, /* string expected */ + MOO_SYNERR_RADIX, /* invalid radix */ + MOO_SYNERR_RADNUMLIT, /* invalid numeric literal with radix */ + MOO_SYNERR_BYTERANGE, /* byte too small or too large */ + MOO_SYNERR_ERRLIT, /* wrong error literal */ + MOO_SYNERR_LBRACE, /* { expected */ + MOO_SYNERR_RBRACE, /* } expected */ + MOO_SYNERR_LPAREN, /* ( expected */ + MOO_SYNERR_RPAREN, /* ) expected */ + MOO_SYNERR_RBRACK, /* ] expected */ + MOO_SYNERR_PERIOD, /* . expected */ + MOO_SYNERR_COMMA, /* , expected */ + MOO_SYNERR_VBAR, /* | expected */ + MOO_SYNERR_GT, /* > expected */ + MOO_SYNERR_ASSIGN, /* := expected */ + MOO_SYNERR_IDENT, /* identifier expected */ + MOO_SYNERR_INTEGER, /* integer expected */ + MOO_SYNERR_PRIMITIVE, /* primitive: expected */ + MOO_SYNERR_DIRECTIVE, /* wrong directive */ + MOO_SYNERR_CLASSUNDEF, /* undefined class */ + MOO_SYNERR_CLASSDUP, /* duplicate class */ + MOO_SYNERR_CLASSCONTRA, /* contradictory class */ + MOO_SYNERR_CLASSNAME, /* wrong class name */ + MOO_SYNERR_DCLBANNED, /* #dcl not allowed */ + MOO_SYNERR_MTHNAME, /* wrong method name */ + MOO_SYNERR_MTHNAMEDUP, /* duplicate method name */ + MOO_SYNERR_ARGNAMEDUP, /* duplicate argument name */ + MOO_SYNERR_TMPRNAMEDUP, /* duplicate temporary variable name */ + MOO_SYNERR_VARNAMEDUP, /* duplicate variable name */ + MOO_SYNERR_BLKARGNAMEDUP, /* duplicate block argument name */ + MOO_SYNERR_VARARG, /* cannot assign to argument */ + MOO_SYNERR_VARUNDCL, /* undeclared variable */ + MOO_SYNERR_VARUNUSE, /* unsuable variable in compiled code */ + MOO_SYNERR_VARINACC, /* inaccessible variable - e.g. accessing an instance variable from a class method is not allowed. */ + MOO_SYNERR_VARAMBIG, /* ambiguious variable - e.g. the variable is found in multiple pool dictionaries imported */ + MOO_SYNERR_PRIMARY, /* wrong expression primary */ + MOO_SYNERR_TMPRFLOOD, /* too many temporaries */ + MOO_SYNERR_ARGFLOOD, /* too many arguments */ + MOO_SYNERR_BLKTMPRFLOOD, /* too many block temporaries */ + MOO_SYNERR_BLKARGFLOOD, /* too many block arguments */ + MOO_SYNERR_BLKFLOOD, /* too large block */ + MOO_SYNERR_PFNUM, /* wrong primitive number */ + MOO_SYNERR_PFID, /* wrong primitive identifier */ + MOO_SYNERR_MODNAME, /* wrong module name */ + MOO_SYNERR_INCLUDE, /* #include error */ + MOO_SYNERR_NAMESPACE, /* wrong namespace name */ + MOO_SYNERR_POOLDIC, /* wrong pool dictionary */ + MOO_SYNERR_POOLDICDUP, /* duplicate pool dictionary */ + MOO_SYNERR_LITERAL /* literal expected */ +}; +typedef enum moo_synerrnum_t moo_synerrnum_t; + +struct moo_synerr_t +{ + moo_synerrnum_t num; + moo_ioloc_t loc; + moo_oocs_t tgt; +}; +typedef struct moo_synerr_t moo_synerr_t; +#endif + +#if defined(__cplusplus) +extern "C" { +#endif + +#define moo_switchprocess(moo) ((moo)->switch_proc = 1) + + +MOO_EXPORT moo_t* moo_open ( + moo_mmgr_t* mmgr, + moo_oow_t xtnsize, + moo_oow_t heapsize, + const moo_vmprim_t* vmprim, + moo_errnum_t* errnum +); + +MOO_EXPORT void moo_close ( + moo_t* moo +); + +MOO_EXPORT int moo_init ( + moo_t* moo, + moo_mmgr_t* mmgr, + moo_oow_t heapsize, + const moo_vmprim_t* vmprim +); + +MOO_EXPORT void moo_fini ( + moo_t* moo +); + +#if defined(MOO_HAVE_INLINE) + static MOO_INLINE moo_mmgr_t* moo_getmmgr (moo_t* moo) { return moo->mmgr; } + static MOO_INLINE void* moo_getxtn (moo_t* moo) { return (void*)(moo + 1); } + + static MOO_INLINE moo_cmgr_t* moo_getcmgr (moo_t* moo) { return moo->cmgr; } + static MOO_INLINE void moo_setcmgr (moo_t* moo, moo_cmgr_t* cmgr) { moo->cmgr = cmgr; } + + static MOO_INLINE moo_errnum_t moo_geterrnum (moo_t* moo) { return moo->errnum; } + static MOO_INLINE void moo_seterrnum (moo_t* moo, moo_errnum_t errnum) { moo->errnum = errnum; } +#else +# define moo_getmmgr(moo) ((moo)->mmgr) +# define moo_getxtn(moo) ((void*)((moo) + 1)) + +# define moo_getcmgr(moo) ((moo)->cmgr) +# define moo_setcmgr(moo,mgr) ((moo)->cmgr = (mgr)) + +# define moo_geterrnum(moo) ((moo)->errnum) +# define moo_seterrnum(moo,num) ((moo)->errnum = (num)) +#endif + +MOO_EXPORT const moo_ooch_t* moo_geterrstr ( + moo_t* moo +); + +/** + * The moo_getoption() function gets the value of an option + * specified by \a id into the buffer pointed to by \a value. + * + * \return 0 on success, -1 on failure + */ +MOO_EXPORT int moo_getoption ( + moo_t* moo, + moo_option_t id, + void* value +); + +/** + * The moo_setoption() function sets the value of an option + * specified by \a id to the value pointed to by \a value. + * + * \return 0 on success, -1 on failure + */ +MOO_EXPORT int moo_setoption ( + moo_t* moo, + moo_option_t id, + const void* value +); + + +MOO_EXPORT moo_cb_t* moo_regcb ( + moo_t* moo, + moo_cb_t* tmpl +); + +MOO_EXPORT void moo_deregcb ( + moo_t* moo, + moo_cb_t* cb +); + +/** + * The moo_gc() function performs garbage collection. + * It is not affected by #MOO_NOGC. + */ +MOO_EXPORT void moo_gc ( + moo_t* moo +); + + +/** + * The moo_instantiate() function creates a new object of the class + * \a _class. The size of the fixed part is taken from the information + * contained in the class defintion. The \a vlen parameter specifies + * the length of the variable part. The \a vptr parameter points to + * the memory area to copy into the variable part of the new object. + * If \a vptr is #MOO_NULL, the variable part is initialized to 0 or + * an equivalent value depending on the type. + */ +MOO_EXPORT moo_oop_t moo_instantiate ( + moo_t* moo, + moo_oop_t _class, + const void* vptr, + moo_oow_t vlen +); + +MOO_EXPORT moo_oop_t moo_shallowcopy ( + moo_t* moo, + moo_oop_t oop +); + +/** + * The moo_ignite() function creates key initial objects. + */ +MOO_EXPORT int moo_ignite ( + moo_t* moo +); + +/** + * The moo_execute() function executes an activated context. + */ +MOO_EXPORT int moo_execute ( + moo_t* moo +); + +/** + * The moo_invoke() function sends a message named \a mthname to an object + * named \a objname. + */ +MOO_EXPORT int moo_invoke ( + moo_t* moo, + const moo_oocs_t* objname, + const moo_oocs_t* mthname +); + +/* Temporary OOP management */ +MOO_EXPORT void moo_pushtmp ( + moo_t* moo, + moo_oop_t* oop_ptr +); + +MOO_EXPORT void moo_poptmp ( + moo_t* moo +); + +MOO_EXPORT void moo_poptmps ( + moo_t* moo, + moo_oow_t count +); + +/* ========================================================================= + * SYSTEM MEMORY MANAGEMENT FUCNTIONS VIA MMGR + * ========================================================================= */ +MOO_EXPORT void* moo_allocmem ( + moo_t* moo, + moo_oow_t size +); + +MOO_EXPORT void* moo_callocmem ( + moo_t* moo, + moo_oow_t size +); + +MOO_EXPORT void* moo_reallocmem ( + moo_t* moo, + void* ptr, + moo_oow_t size +); + +MOO_EXPORT void moo_freemem ( + moo_t* moo, + void* ptr +); + + +/* ========================================================================= + * PRIMITIVE METHOD MANIPULATION + * ========================================================================= */ +MOO_EXPORT int moo_genpfmethod ( + moo_t* moo, + moo_mod_t* mod, + moo_oop_t _class, + moo_method_type_t type, + const moo_ooch_t* mthname, + int variadic, + const moo_ooch_t* name +); + +/* ========================================================================= + * STRING ENCODING CONVERSION + * ========================================================================= */ + +#if defined(MOO_OOCH_IS_UCH) +# define moo_convootobchars(moo,oocs,oocslen,bcs,bcslen) moo_convutobchars(moo,oocs,oocslen,bcs,bcslen) +# define moo_convbtooochars(moo,bcs,bcslen,oocs,oocslen) moo_convbtouchars(moo,bcs,bcslen,oocs,oocslen) +# define moo_convootobcstr(moo,oocs,oocslen,bcs,bcslen) moo_convutobcstr(moo,oocs,oocslen,bcs,bcslen) +# define moo_convbtooocstr(moo,bcs,bcslen,oocs,oocslen) moo_convbtoucstr(moo,bcs,bcslen,oocs,oocslen) +#else +# define moo_convootouchars(moo,oocs,oocslen,bcs,bcslen) moo_convbtouchars(moo,oocs,oocslen,bcs,bcslen) +# define moo_convutooochars(moo,bcs,bcslen,oocs,oocslen) moo_convutobchars(moo,bcs,bcslen,oocs,oocslen) +# define moo_convootoucstr(moo,oocs,oocslen,bcs,bcslen) moo_convbtoucstr(moo,oocs,oocslen,bcs,bcslen) +# define moo_convutooocstr(moo,bcs,bcslen,oocs,oocslen) moo_convutobcstr(moo,bcs,bcslen,oocs,oocslen) +#endif + +MOO_EXPORT int moo_convbtouchars ( + moo_t* moo, + const moo_bch_t* bcs, + moo_oow_t* bcslen, + moo_uch_t* ucs, + moo_oow_t* ucslen +); + +MOO_EXPORT int moo_convutobchars ( + moo_t* moo, + const moo_uch_t* ucs, + moo_oow_t* ucslen, + moo_bch_t* bcs, + moo_oow_t* bcslen +); + + +/** + * The moo_convbtoucstr() function converts a null-terminated byte string + * to a wide string. + */ +MOO_EXPORT int moo_convbtoucstr ( + moo_t* moo, + const moo_bch_t* bcs, + moo_oow_t* bcslen, + moo_uch_t* ucs, + moo_oow_t* ucslen +); + + +/** + * The moo_convutobcstr() function converts a null-terminated wide string + * to a byte string. + */ +int moo_convutobcstr ( + moo_t* moo, + const moo_uch_t* ucs, + moo_oow_t* ucslen, + moo_bch_t* bcs, + moo_oow_t* bcslen +); + +/* ========================================================================= + * MOO VM LOGGING + * ========================================================================= */ + +MOO_EXPORT moo_ooi_t moo_logbfmt ( + moo_t* moo, + moo_oow_t mask, + const moo_bch_t* fmt, + ... +); + +MOO_EXPORT moo_ooi_t moo_logufmt ( + moo_t* moo, + moo_oow_t mask, + const moo_uch_t* fmt, + ... +); + +#if defined(MOO_OOCH_IS_UCH) +# define moo_logoofmt moo_logufmt +#else +# define moo_logoofmt moo_logbfmt +#endif + +/* ========================================================================= + * MISCELLANEOUS HELPER FUNCTIONS + * ========================================================================= */ + +MOO_EXPORT int moo_decode ( + moo_t* moo, + moo_oop_method_t mth, + const moo_oocs_t* classfqn +); + +MOO_EXPORT void moo_assertfailed ( + moo_t* moo, + const moo_bch_t* expr, + const moo_bch_t* file, + moo_oow_t line +); + +MOO_EXPORT moo_errnum_t moo_syserrtoerrnum ( + int syserr +); + +MOO_EXPORT const moo_ooch_t* moo_errnumtoerrstr ( + moo_errnum_t errnum +); + +#if defined(MOO_INCLUDE_COMPILER) + +MOO_EXPORT int moo_compile ( + moo_t* moo, + moo_ioimpl_t io +); + +MOO_EXPORT void moo_getsynerr ( + moo_t* moo, + moo_synerr_t* synerr +); + +MOO_EXPORT const moo_ooch_t* moo_synerrnumtoerrstr ( + moo_synerrnum_t errnum +); +#endif + +#if defined(__cplusplus) +} +#endif + + +#endif diff --git a/stix/lib/obj.c b/stix/lib/obj.c index c22b563..8162fda 100644 --- a/stix/lib/obj.c +++ b/stix/lib/obj.c @@ -24,195 +24,195 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "stix-prv.h" +#include "moo-prv.h" -void* stix_allocbytes (stix_t* stix, stix_oow_t size) +void* moo_allocbytes (moo_t* moo, moo_oow_t size) { - stix_uint8_t* ptr; + moo_uint8_t* ptr; -#if defined(STIX_DEBUG_GC) - if (!(stix->option.trait & STIX_NOGC)) stix_gc (stix); +#if defined(MOO_DEBUG_GC) + if (!(moo->option.trait & MOO_NOGC)) moo_gc (moo); #endif - ptr = stix_allocheapmem (stix, stix->curheap, size); - if (!ptr && stix->errnum == STIX_EOOMEM && !(stix->option.trait & STIX_NOGC)) + ptr = moo_allocheapmem (moo, moo->curheap, size); + if (!ptr && moo->errnum == MOO_EOOMEM && !(moo->option.trait & MOO_NOGC)) { - stix_gc (stix); - ptr = stix_allocheapmem (stix, stix->curheap, size); + moo_gc (moo); + ptr = moo_allocheapmem (moo, moo->curheap, size); /* TODO: grow heap if ptr is still null. */ } return ptr; } -stix_oop_t stix_allocoopobj (stix_t* stix, stix_oow_t size) +moo_oop_t moo_allocoopobj (moo_t* moo, moo_oow_t size) { - stix_oop_oop_t hdr; - stix_oow_t nbytes, nbytes_aligned; + moo_oop_oop_t hdr; + moo_oow_t nbytes, nbytes_aligned; - nbytes = size * STIX_SIZEOF(stix_oop_t); + nbytes = size * MOO_SIZEOF(moo_oop_t); /* this isn't really necessary since nbytes must be * aligned already. */ - nbytes_aligned = STIX_ALIGN(nbytes, STIX_SIZEOF(stix_oop_t)); + nbytes_aligned = MOO_ALIGN(nbytes, MOO_SIZEOF(moo_oop_t)); /* making the number of bytes to allocate a multiple of - * STIX_SIZEOF(stix_oop_t) will guarantee the starting address + * MOO_SIZEOF(moo_oop_t) will guarantee the starting address * of the allocated space to be an even number. - * see STIX_OOP_IS_NUMERIC() and STIX_OOP_IS_POINTER() */ - hdr = stix_allocbytes (stix, STIX_SIZEOF(stix_obj_t) + nbytes_aligned); - if (!hdr) return STIX_NULL; + * see MOO_OOP_IS_NUMERIC() and MOO_OOP_IS_POINTER() */ + hdr = moo_allocbytes (moo, MOO_SIZEOF(moo_obj_t) + nbytes_aligned); + if (!hdr) return MOO_NULL; - hdr->_flags = STIX_OBJ_MAKE_FLAGS(STIX_OBJ_TYPE_OOP, STIX_SIZEOF(stix_oop_t), 0, 0, 0, 0, 0); - STIX_OBJ_SET_SIZE (hdr, size); - STIX_OBJ_SET_CLASS (hdr, stix->_nil); + hdr->_flags = MOO_OBJ_MAKE_FLAGS(MOO_OBJ_TYPE_OOP, MOO_SIZEOF(moo_oop_t), 0, 0, 0, 0, 0); + MOO_OBJ_SET_SIZE (hdr, size); + MOO_OBJ_SET_CLASS (hdr, moo->_nil); - while (size > 0) hdr->slot[--size] = stix->_nil; + while (size > 0) hdr->slot[--size] = moo->_nil; - return (stix_oop_t)hdr; + return (moo_oop_t)hdr; } -#if defined(STIX_USE_OBJECT_TRAILER) -stix_oop_t stix_allocoopobjwithtrailer (stix_t* stix, stix_oow_t size, const stix_oob_t* bptr, stix_oow_t blen) +#if defined(MOO_USE_OBJECT_TRAILER) +moo_oop_t moo_allocoopobjwithtrailer (moo_t* moo, moo_oow_t size, const moo_oob_t* bptr, moo_oow_t blen) { - stix_oop_oop_t hdr; - stix_oow_t nbytes, nbytes_aligned; - stix_oow_t i; + moo_oop_oop_t hdr; + moo_oow_t nbytes, nbytes_aligned; + moo_oow_t i; - /* +1 for the trailer size of the stix_oow_t type */ - nbytes = (size + 1) * STIX_SIZEOF(stix_oop_t) + blen; - nbytes_aligned = STIX_ALIGN(nbytes, STIX_SIZEOF(stix_oop_t)); + /* +1 for the trailer size of the moo_oow_t type */ + nbytes = (size + 1) * MOO_SIZEOF(moo_oop_t) + blen; + nbytes_aligned = MOO_ALIGN(nbytes, MOO_SIZEOF(moo_oop_t)); - hdr = stix_allocbytes (stix, STIX_SIZEOF(stix_obj_t) + nbytes_aligned); - if (!hdr) return STIX_NULL; + hdr = moo_allocbytes (moo, MOO_SIZEOF(moo_obj_t) + nbytes_aligned); + if (!hdr) return MOO_NULL; - hdr->_flags = STIX_OBJ_MAKE_FLAGS(STIX_OBJ_TYPE_OOP, STIX_SIZEOF(stix_oop_t), 0, 0, 0, 0, 1); - STIX_OBJ_SET_SIZE (hdr, size); - STIX_OBJ_SET_CLASS (hdr, stix->_nil); + hdr->_flags = MOO_OBJ_MAKE_FLAGS(MOO_OBJ_TYPE_OOP, MOO_SIZEOF(moo_oop_t), 0, 0, 0, 0, 1); + MOO_OBJ_SET_SIZE (hdr, size); + MOO_OBJ_SET_CLASS (hdr, moo->_nil); - for (i = 0; i < size; i++) hdr->slot[i] = stix->_nil; + for (i = 0; i < size; i++) hdr->slot[i] = moo->_nil; /* [NOTE] this is not converted to a SmallInteger object */ - hdr->slot[size] = (stix_oop_t)blen; + hdr->slot[size] = (moo_oop_t)blen; if (bptr) { - STIX_MEMCPY (&hdr->slot[size + 1], bptr, blen); + MOO_MEMCPY (&hdr->slot[size + 1], bptr, blen); } else { - STIX_MEMSET (&hdr->slot[size + 1], 0, blen); + MOO_MEMSET (&hdr->slot[size + 1], 0, blen); } - return (stix_oop_t)hdr; + return (moo_oop_t)hdr; } #endif -static STIX_INLINE stix_oop_t alloc_numeric_array (stix_t* stix, const void* ptr, stix_oow_t len, stix_obj_type_t type, stix_oow_t unit, int extra) +static MOO_INLINE moo_oop_t alloc_numeric_array (moo_t* moo, const void* ptr, moo_oow_t len, moo_obj_type_t type, moo_oow_t unit, int extra) { /* allocate a variable object */ - stix_oop_t hdr; - stix_oow_t xbytes, nbytes, nbytes_aligned; + moo_oop_t hdr; + moo_oow_t xbytes, nbytes, nbytes_aligned; xbytes = len * unit; /* 'extra' indicates an extra unit to append at the end. * it's useful to store a string with a terminating null */ nbytes = extra? xbytes + len: xbytes; - nbytes_aligned = STIX_ALIGN(nbytes, STIX_SIZEOF(stix_oop_t)); + nbytes_aligned = MOO_ALIGN(nbytes, MOO_SIZEOF(moo_oop_t)); /* TODO: check overflow in size calculation*/ /* making the number of bytes to allocate a multiple of - * STIX_SIZEOF(stix_oop_t) will guarantee the starting address + * MOO_SIZEOF(moo_oop_t) will guarantee the starting address * of the allocated space to be an even number. - * see STIX_OOP_IS_NUMERIC() and STIX_OOP_IS_POINTER() */ - hdr = stix_allocbytes (stix, STIX_SIZEOF(stix_obj_t) + nbytes_aligned); - if (!hdr) return STIX_NULL; + * see MOO_OOP_IS_NUMERIC() and MOO_OOP_IS_POINTER() */ + hdr = moo_allocbytes (moo, MOO_SIZEOF(moo_obj_t) + nbytes_aligned); + if (!hdr) return MOO_NULL; - hdr->_flags = STIX_OBJ_MAKE_FLAGS(type, unit, extra, 0, 0, 0, 0); + hdr->_flags = MOO_OBJ_MAKE_FLAGS(type, unit, extra, 0, 0, 0, 0); hdr->_size = len; - STIX_OBJ_SET_SIZE (hdr, len); - STIX_OBJ_SET_CLASS (hdr, stix->_nil); + MOO_OBJ_SET_SIZE (hdr, len); + MOO_OBJ_SET_CLASS (hdr, moo->_nil); if (ptr) { /* copy data */ - STIX_MEMCPY (hdr + 1, ptr, xbytes); - STIX_MEMSET ((stix_uint8_t*)(hdr + 1) + xbytes, 0, nbytes_aligned - xbytes); + MOO_MEMCPY (hdr + 1, ptr, xbytes); + MOO_MEMSET ((moo_uint8_t*)(hdr + 1) + xbytes, 0, nbytes_aligned - xbytes); } else { /* initialize with zeros when the string pointer is not given */ - STIX_MEMSET ((hdr + 1), 0, nbytes_aligned); + MOO_MEMSET ((hdr + 1), 0, nbytes_aligned); } return hdr; } -stix_oop_t stix_alloccharobj (stix_t* stix, const stix_ooch_t* ptr, stix_oow_t len) +moo_oop_t moo_alloccharobj (moo_t* moo, const moo_ooch_t* ptr, moo_oow_t len) { - return alloc_numeric_array (stix, ptr, len, STIX_OBJ_TYPE_CHAR, STIX_SIZEOF(stix_ooch_t), 1); + return alloc_numeric_array (moo, ptr, len, MOO_OBJ_TYPE_CHAR, MOO_SIZEOF(moo_ooch_t), 1); } -stix_oop_t stix_allocbyteobj (stix_t* stix, const stix_oob_t* ptr, stix_oow_t len) +moo_oop_t moo_allocbyteobj (moo_t* moo, const moo_oob_t* ptr, moo_oow_t len) { - return alloc_numeric_array (stix, ptr, len, STIX_OBJ_TYPE_BYTE, STIX_SIZEOF(stix_oob_t), 0); + return alloc_numeric_array (moo, ptr, len, MOO_OBJ_TYPE_BYTE, MOO_SIZEOF(moo_oob_t), 0); } -stix_oop_t stix_allochalfwordobj (stix_t* stix, const stix_oohw_t* ptr, stix_oow_t len) +moo_oop_t moo_allochalfwordobj (moo_t* moo, const moo_oohw_t* ptr, moo_oow_t len) { - return alloc_numeric_array (stix, ptr, len, STIX_OBJ_TYPE_HALFWORD, STIX_SIZEOF(stix_oohw_t), 0); + return alloc_numeric_array (moo, ptr, len, MOO_OBJ_TYPE_HALFWORD, MOO_SIZEOF(moo_oohw_t), 0); } -stix_oop_t stix_allocwordobj (stix_t* stix, const stix_oow_t* ptr, stix_oow_t len) +moo_oop_t moo_allocwordobj (moo_t* moo, const moo_oow_t* ptr, moo_oow_t len) { - return alloc_numeric_array (stix, ptr, len, STIX_OBJ_TYPE_WORD, STIX_SIZEOF(stix_oow_t), 0); + return alloc_numeric_array (moo, ptr, len, MOO_OBJ_TYPE_WORD, MOO_SIZEOF(moo_oow_t), 0); } -static STIX_INLINE int decode_spec (stix_t* stix, stix_oop_t _class, stix_oow_t vlen, stix_obj_type_t* type, stix_oow_t* outlen) +static MOO_INLINE int decode_spec (moo_t* moo, moo_oop_t _class, moo_oow_t vlen, moo_obj_type_t* type, moo_oow_t* outlen) { - stix_oow_t spec; - stix_oow_t named_instvar; - stix_obj_type_t indexed_type; + moo_oow_t spec; + moo_oow_t named_instvar; + moo_obj_type_t indexed_type; - STIX_ASSERT (stix, STIX_OOP_IS_POINTER(_class)); - STIX_ASSERT (stix, STIX_CLASSOF(stix, _class) == stix->_class); + MOO_ASSERT (moo, MOO_OOP_IS_POINTER(_class)); + MOO_ASSERT (moo, MOO_CLASSOF(moo, _class) == moo->_class); - STIX_ASSERT (stix, STIX_OOP_IS_SMOOI(((stix_oop_class_t)_class)->spec)); - spec = STIX_OOP_TO_SMOOI(((stix_oop_class_t)_class)->spec); + MOO_ASSERT (moo, MOO_OOP_IS_SMOOI(((moo_oop_class_t)_class)->spec)); + spec = MOO_OOP_TO_SMOOI(((moo_oop_class_t)_class)->spec); - named_instvar = STIX_CLASS_SPEC_NAMED_INSTVAR(spec); /* size of the named_instvar part */ + named_instvar = MOO_CLASS_SPEC_NAMED_INSTVAR(spec); /* size of the named_instvar part */ - if (STIX_CLASS_SPEC_IS_INDEXED(spec)) + if (MOO_CLASS_SPEC_IS_INDEXED(spec)) { - indexed_type = STIX_CLASS_SPEC_INDEXED_TYPE(spec); + indexed_type = MOO_CLASS_SPEC_INDEXED_TYPE(spec); - if (indexed_type == STIX_OBJ_TYPE_OOP) + if (indexed_type == MOO_OBJ_TYPE_OOP) { - if (named_instvar > STIX_MAX_NAMED_INSTVARS) + if (named_instvar > MOO_MAX_NAMED_INSTVARS) { - STIX_DEBUG3 (stix, "Too many named instance variables for a variable-pointer class %O - %zu/%zu\n", _class, named_instvar, (stix_oow_t)STIX_MAX_NAMED_INSTVARS); + MOO_DEBUG3 (moo, "Too many named instance variables for a variable-pointer class %O - %zu/%zu\n", _class, named_instvar, (moo_oow_t)MOO_MAX_NAMED_INSTVARS); return -1; } - if (vlen > STIX_MAX_INDEXED_INSTVARS(named_instvar)) + if (vlen > MOO_MAX_INDEXED_INSTVARS(named_instvar)) { - STIX_DEBUG3 (stix, "Too many unnamed instance variables for a variable-pointer class %O - %zu/%zu\n", _class, vlen, (stix_oow_t)STIX_MAX_INDEXED_INSTVARS(named_instvar)); + MOO_DEBUG3 (moo, "Too many unnamed instance variables for a variable-pointer class %O - %zu/%zu\n", _class, vlen, (moo_oow_t)MOO_MAX_INDEXED_INSTVARS(named_instvar)); return -1; } - STIX_ASSERT (stix, named_instvar + vlen <= STIX_OBJ_SIZE_MAX); + MOO_ASSERT (moo, named_instvar + vlen <= MOO_OBJ_SIZE_MAX); } else { /* a non-pointer indexed class can't have named instance variables */ if (named_instvar > 0) { - STIX_DEBUG1 (stix, "Named instance variables in a variable-nonpointer class %O\n", _class); + MOO_DEBUG1 (moo, "Named instance variables in a variable-nonpointer class %O\n", _class); return -1; } - if (vlen > STIX_OBJ_SIZE_MAX) + if (vlen > MOO_OBJ_SIZE_MAX) { - STIX_DEBUG3 (stix, "Too many unnamed instance variables for a variable-nonpointer class %O - %zu/%zu\n", _class, vlen, (stix_oow_t)STIX_OBJ_SIZE_MAX); + MOO_DEBUG3 (moo, "Too many unnamed instance variables for a variable-nonpointer class %O - %zu/%zu\n", _class, vlen, (moo_oow_t)MOO_OBJ_SIZE_MAX); return -1; } } @@ -221,21 +221,21 @@ static STIX_INLINE int decode_spec (stix_t* stix, stix_oop_t _class, stix_oow_t { /* named instance variables only. treat it as if it is an * indexable class with no variable data */ - indexed_type = STIX_OBJ_TYPE_OOP; + indexed_type = MOO_OBJ_TYPE_OOP; if (vlen > 0) { - STIX_DEBUG2 (stix, "Unamed instance variables for a fixed class %O - %zu\n", _class, vlen); + MOO_DEBUG2 (moo, "Unamed instance variables for a fixed class %O - %zu\n", _class, vlen); return -1; } /*vlen = 0;*/ /* vlen is not used */ - if (named_instvar > STIX_MAX_NAMED_INSTVARS) + if (named_instvar > MOO_MAX_NAMED_INSTVARS) { - STIX_DEBUG3 (stix, "Too many named instance variables for a fixed class %O - %zu/%zu\n", _class, named_instvar, (stix_oow_t)STIX_MAX_NAMED_INSTVARS); + MOO_DEBUG3 (moo, "Too many named instance variables for a fixed class %O - %zu/%zu\n", _class, named_instvar, (moo_oow_t)MOO_MAX_NAMED_INSTVARS); return -1; } - STIX_ASSERT (stix, named_instvar <= STIX_OBJ_SIZE_MAX); + MOO_ASSERT (moo, named_instvar <= MOO_OBJ_SIZE_MAX); } *type = indexed_type; @@ -243,162 +243,162 @@ static STIX_INLINE int decode_spec (stix_t* stix, stix_oop_t _class, stix_oow_t return 0; } -stix_oop_t stix_instantiate (stix_t* stix, stix_oop_t _class, const void* vptr, stix_oow_t vlen) +moo_oop_t moo_instantiate (moo_t* moo, moo_oop_t _class, const void* vptr, moo_oow_t vlen) { - stix_oop_t oop; - stix_obj_type_t type; - stix_oow_t alloclen; - stix_oow_t tmp_count = 0; + moo_oop_t oop; + moo_obj_type_t type; + moo_oow_t alloclen; + moo_oow_t tmp_count = 0; - STIX_ASSERT (stix, stix->_nil != STIX_NULL); + MOO_ASSERT (moo, moo->_nil != MOO_NULL); - if (decode_spec (stix, _class, vlen, &type, &alloclen) <= -1) + if (decode_spec (moo, _class, vlen, &type, &alloclen) <= -1) { - stix->errnum = STIX_EINVAL; - return STIX_NULL; + moo->errnum = MOO_EINVAL; + return MOO_NULL; } - stix_pushtmp (stix, &_class); tmp_count++; + moo_pushtmp (moo, &_class); tmp_count++; switch (type) { - case STIX_OBJ_TYPE_OOP: + case MOO_OBJ_TYPE_OOP: /* both the fixed part(named instance variables) and * the variable part(indexed instance variables) are allowed. */ - oop = stix_allocoopobj (stix, alloclen); + oop = moo_allocoopobj (moo, alloclen); - STIX_ASSERT (stix, vptr == STIX_NULL); + MOO_ASSERT (moo, vptr == MOO_NULL); /* This function is not GC-safe. so i don't want to initialize the payload of a pointer object. The caller can call this function and initialize payloads then. if (oop && vptr && vlen > 0) { - stix_oop_oop_t hdr = (stix_oop_oop_t)oop; - STIX_MEMCPY (&hdr->slot[named_instvar], vptr, vlen * STIX_SIZEOF(stix_oop_t)); + moo_oop_oop_t hdr = (moo_oop_oop_t)oop; + MOO_MEMCPY (&hdr->slot[named_instvar], vptr, vlen * MOO_SIZEOF(moo_oop_t)); } For the above code to work, it should protect the elements of - the vptr array with stix_pushtmp(). So it might be better + the vptr array with moo_pushtmp(). So it might be better to disallow a non-NULL vptr when indexed_type is OOP. See the assertion above this comment block. */ break; - case STIX_OBJ_TYPE_CHAR: - oop = stix_alloccharobj (stix, vptr, alloclen); + case MOO_OBJ_TYPE_CHAR: + oop = moo_alloccharobj (moo, vptr, alloclen); break; - case STIX_OBJ_TYPE_BYTE: - oop = stix_allocbyteobj (stix, vptr, alloclen); + case MOO_OBJ_TYPE_BYTE: + oop = moo_allocbyteobj (moo, vptr, alloclen); break; - case STIX_OBJ_TYPE_HALFWORD: - oop = stix_allochalfwordobj (stix, vptr, alloclen); + case MOO_OBJ_TYPE_HALFWORD: + oop = moo_allochalfwordobj (moo, vptr, alloclen); break; - case STIX_OBJ_TYPE_WORD: - oop = stix_allocwordobj (stix, vptr, alloclen); + case MOO_OBJ_TYPE_WORD: + oop = moo_allocwordobj (moo, vptr, alloclen); break; default: - stix->errnum = STIX_EINTERN; - oop = STIX_NULL; + moo->errnum = MOO_EINTERN; + oop = MOO_NULL; break; } - if (oop) STIX_OBJ_SET_CLASS (oop, _class); - stix_poptmps (stix, tmp_count); + if (oop) MOO_OBJ_SET_CLASS (oop, _class); + moo_poptmps (moo, tmp_count); return oop; } -stix_oop_t stix_instantiate2 (stix_t* stix, stix_oop_t _class, const void* vptr, stix_oow_t vlen, int ngc) +moo_oop_t moo_instantiate2 (moo_t* moo, moo_oop_t _class, const void* vptr, moo_oow_t vlen, int ngc) { - stix_oop_t oop; - stix_obj_type_t type; - stix_oow_t alloclen; - stix_oow_t tmp_count = 0; + moo_oop_t oop; + moo_obj_type_t type; + moo_oow_t alloclen; + moo_oow_t tmp_count = 0; - STIX_ASSERT (stix, stix->_nil != STIX_NULL); + MOO_ASSERT (moo, moo->_nil != MOO_NULL); - if (decode_spec (stix, _class, vlen, &type, &alloclen) <= -1) + if (decode_spec (moo, _class, vlen, &type, &alloclen) <= -1) { - stix->errnum = STIX_EINVAL; - return STIX_NULL; + moo->errnum = MOO_EINVAL; + return MOO_NULL; } - stix_pushtmp (stix, &_class); tmp_count++; + moo_pushtmp (moo, &_class); tmp_count++; /* TODO: support NGC */ switch (type) { - case STIX_OBJ_TYPE_OOP: + case MOO_OBJ_TYPE_OOP: /* NOTE: vptr is not used for GC unsafety */ - oop = stix_allocoopobj (stix, alloclen); + oop = moo_allocoopobj (moo, alloclen); break; - case STIX_OBJ_TYPE_CHAR: - oop = stix_alloccharobj (stix, vptr, alloclen); + case MOO_OBJ_TYPE_CHAR: + oop = moo_alloccharobj (moo, vptr, alloclen); break; - case STIX_OBJ_TYPE_BYTE: - oop = stix_allocbyteobj (stix, vptr, alloclen); + case MOO_OBJ_TYPE_BYTE: + oop = moo_allocbyteobj (moo, vptr, alloclen); break; - case STIX_OBJ_TYPE_HALFWORD: - oop = stix_allochalfwordobj (stix, vptr, alloclen); + case MOO_OBJ_TYPE_HALFWORD: + oop = moo_allochalfwordobj (moo, vptr, alloclen); break; - case STIX_OBJ_TYPE_WORD: - oop = stix_allocwordobj (stix, vptr, alloclen); + case MOO_OBJ_TYPE_WORD: + oop = moo_allocwordobj (moo, vptr, alloclen); break; default: - stix->errnum = STIX_EINTERN; - oop = STIX_NULL; + moo->errnum = MOO_EINTERN; + oop = MOO_NULL; break; } - if (oop) STIX_OBJ_SET_CLASS (oop, _class); - stix_poptmps (stix, tmp_count); + if (oop) MOO_OBJ_SET_CLASS (oop, _class); + moo_poptmps (moo, tmp_count); return oop; } -#if defined(STIX_USE_OBJECT_TRAILER) +#if defined(MOO_USE_OBJECT_TRAILER) -stix_oop_t stix_instantiatewithtrailer (stix_t* stix, stix_oop_t _class, stix_oow_t vlen, const stix_oob_t* tptr, stix_oow_t tlen) +moo_oop_t moo_instantiatewithtrailer (moo_t* moo, moo_oop_t _class, moo_oow_t vlen, const moo_oob_t* tptr, moo_oow_t tlen) { - stix_oop_t oop; - stix_obj_type_t type; - stix_oow_t alloclen; - stix_oow_t tmp_count = 0; + moo_oop_t oop; + moo_obj_type_t type; + moo_oow_t alloclen; + moo_oow_t tmp_count = 0; - STIX_ASSERT (stix, stix->_nil != STIX_NULL); + MOO_ASSERT (moo, moo->_nil != MOO_NULL); - if (decode_spec (stix, _class, vlen, &type, &alloclen) <= -1) + if (decode_spec (moo, _class, vlen, &type, &alloclen) <= -1) { - stix->errnum = STIX_EINVAL; - return STIX_NULL; + moo->errnum = MOO_EINVAL; + return MOO_NULL; } - stix_pushtmp (stix, &_class); tmp_count++; + moo_pushtmp (moo, &_class); tmp_count++; switch (type) { - case STIX_OBJ_TYPE_OOP: + case MOO_OBJ_TYPE_OOP: /* NOTE: vptr is not used for GC unsafety */ - oop = stix_allocoopobjwithtrailer(stix, alloclen, tptr, tlen); + oop = moo_allocoopobjwithtrailer(moo, alloclen, tptr, tlen); break; default: - stix->errnum = STIX_EINTERN; - oop = STIX_NULL; + moo->errnum = MOO_EINTERN; + oop = MOO_NULL; break; } - if (oop) STIX_OBJ_SET_CLASS (oop, _class); - stix_poptmps (stix, tmp_count); + if (oop) MOO_OBJ_SET_CLASS (oop, _class); + moo_poptmps (moo, tmp_count); return oop; } #endif diff --git a/stix/lib/proc.c b/stix/lib/proc.c index 32c265e..a56d0af 100644 --- a/stix/lib/proc.c +++ b/stix/lib/proc.c @@ -24,28 +24,28 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "stix-prv.h" +#include "moo-prv.h" -stix_oop_process_t stix_addnewproc (stix_t* stix) +moo_oop_process_t moo_addnewproc (moo_t* moo) { - stix_oop_process_t proc; + moo_oop_process_t proc; - proc = (stix_oop_process_t)stix_instantiate (stix, stix->_process, STIX_NULL, stix->option.dfl_procstk_size); - if (!proc) return STIX_NULL; + proc = (moo_oop_process_t)moo_instantiate (moo, moo->_process, MOO_NULL, moo->option.dfl_procstk_size); + if (!proc) return MOO_NULL; - proc->state = STIX_SMOOI_TO_OOP(0); + proc->state = MOO_SMOOI_TO_OOP(0); - STIX_ASSERT (stix, STIX_OBJ_GET_SIZE(proc) == STIX_PROCESS_NAMED_INSTVARS + stix->option.dfl_procstk_size); + MOO_ASSERT (moo, MOO_OBJ_GET_SIZE(proc) == MOO_PROCESS_NAMED_INSTVARS + moo->option.dfl_procstk_size); return proc; } -void stix_schedproc (stix_t* stix, stix_oop_process_t proc) +void moo_schedproc (moo_t* moo, moo_oop_process_t proc) { /* TODO: if scheduled, don't add */ - /*proc->next = stix->_active_process; + /*proc->next = moo->_active_process; proc->_active_process = proc;*/ } -void stix_unschedproc (stix_t* stix, stix_oop_process_t proc) +void moo_unschedproc (moo_t* moo, moo_oop_process_t proc) { } diff --git a/stix/lib/rbt.c b/stix/lib/rbt.c index 60784de..df00410 100644 --- a/stix/lib/rbt.c +++ b/stix/lib/rbt.c @@ -24,23 +24,23 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "stix-rbt.h" -#include "stix-prv.h" +#include "moo-rbt.h" +#include "moo-prv.h" -#define copier_t stix_rbt_copier_t -#define freeer_t stix_rbt_freeer_t -#define comper_t stix_rbt_comper_t -#define keeper_t stix_rbt_keeper_t -#define walker_t stix_rbt_walker_t -#define cbserter_t stix_rbt_cbserter_t +#define copier_t moo_rbt_copier_t +#define freeer_t moo_rbt_freeer_t +#define comper_t moo_rbt_comper_t +#define keeper_t moo_rbt_keeper_t +#define walker_t moo_rbt_walker_t +#define cbserter_t moo_rbt_cbserter_t -#define KPTR(p) STIX_RBT_KPTR(p) -#define KLEN(p) STIX_RBT_KLEN(p) -#define VPTR(p) STIX_RBT_VPTR(p) -#define VLEN(p) STIX_RBT_VLEN(p) +#define KPTR(p) MOO_RBT_KPTR(p) +#define KLEN(p) MOO_RBT_KLEN(p) +#define VPTR(p) MOO_RBT_VPTR(p) +#define VLEN(p) MOO_RBT_VLEN(p) -#define KTOB(rbt,len) ((len)*(rbt)->scale[STIX_RBT_KEY]) -#define VTOB(rbt,len) ((len)*(rbt)->scale[STIX_RBT_VAL]) +#define KTOB(rbt,len) ((len)*(rbt)->scale[MOO_RBT_KEY]) +#define VTOB(rbt,len) ((len)*(rbt)->scale[MOO_RBT_VAL]) #define UPSERT 1 #define UPDATE 2 @@ -55,180 +55,180 @@ #define rotate_left(rbt,pivot) rotate(rbt,pivot,1); #define rotate_right(rbt,pivot) rotate(rbt,pivot,0); -STIX_INLINE stix_rbt_pair_t* stix_rbt_allocpair ( - stix_rbt_t* rbt, void* kptr, stix_oow_t klen, void* vptr, stix_oow_t vlen) +MOO_INLINE moo_rbt_pair_t* moo_rbt_allocpair ( + moo_rbt_t* rbt, void* kptr, moo_oow_t klen, void* vptr, moo_oow_t vlen) { - stix_rbt_pair_t* n; + moo_rbt_pair_t* n; - copier_t kcop = rbt->style->copier[STIX_RBT_KEY]; - copier_t vcop = rbt->style->copier[STIX_RBT_VAL]; + copier_t kcop = rbt->style->copier[MOO_RBT_KEY]; + copier_t vcop = rbt->style->copier[MOO_RBT_VAL]; - stix_oow_t as = STIX_SIZEOF(stix_rbt_pair_t); - if (kcop == STIX_RBT_COPIER_INLINE) as += KTOB(rbt,klen); - if (vcop == STIX_RBT_COPIER_INLINE) as += VTOB(rbt,vlen); + moo_oow_t as = MOO_SIZEOF(moo_rbt_pair_t); + if (kcop == MOO_RBT_COPIER_INLINE) as += KTOB(rbt,klen); + if (vcop == MOO_RBT_COPIER_INLINE) as += VTOB(rbt,vlen); - n = (stix_rbt_pair_t*) STIX_MMGR_ALLOC (rbt->stix->mmgr, as); - if (n == STIX_NULL) return STIX_NULL; + n = (moo_rbt_pair_t*) MOO_MMGR_ALLOC (rbt->moo->mmgr, as); + if (n == MOO_NULL) return MOO_NULL; - n->color = STIX_RBT_RED; - n->parent = STIX_NULL; + n->color = MOO_RBT_RED; + n->parent = MOO_NULL; n->child[LEFT] = &rbt->xnil; n->child[RIGHT] = &rbt->xnil; KLEN(n) = klen; - if (kcop == STIX_RBT_COPIER_SIMPLE) + if (kcop == MOO_RBT_COPIER_SIMPLE) { KPTR(n) = kptr; } - else if (kcop == STIX_RBT_COPIER_INLINE) + else if (kcop == MOO_RBT_COPIER_INLINE) { KPTR(n) = n + 1; - if (kptr) STIX_MEMCPY (KPTR(n), kptr, KTOB(rbt,klen)); + if (kptr) MOO_MEMCPY (KPTR(n), kptr, KTOB(rbt,klen)); } else { KPTR(n) = kcop (rbt, kptr, klen); - if (KPTR(n) == STIX_NULL) + if (KPTR(n) == MOO_NULL) { - STIX_MMGR_FREE (rbt->stix->mmgr, n); - return STIX_NULL; + MOO_MMGR_FREE (rbt->moo->mmgr, n); + return MOO_NULL; } } VLEN(n) = vlen; - if (vcop == STIX_RBT_COPIER_SIMPLE) + if (vcop == MOO_RBT_COPIER_SIMPLE) { VPTR(n) = vptr; } - else if (vcop == STIX_RBT_COPIER_INLINE) + else if (vcop == MOO_RBT_COPIER_INLINE) { VPTR(n) = n + 1; - if (kcop == STIX_RBT_COPIER_INLINE) - VPTR(n) = (stix_oob_t*)VPTR(n) + KTOB(rbt,klen); - if (vptr) STIX_MEMCPY (VPTR(n), vptr, VTOB(rbt,vlen)); + if (kcop == MOO_RBT_COPIER_INLINE) + VPTR(n) = (moo_oob_t*)VPTR(n) + KTOB(rbt,klen); + if (vptr) MOO_MEMCPY (VPTR(n), vptr, VTOB(rbt,vlen)); } else { VPTR(n) = vcop (rbt, vptr, vlen); - if (VPTR(n) != STIX_NULL) + if (VPTR(n) != MOO_NULL) { - if (rbt->style->freeer[STIX_RBT_KEY] != STIX_NULL) - rbt->style->freeer[STIX_RBT_KEY] (rbt, KPTR(n), KLEN(n)); - STIX_MMGR_FREE (rbt->stix->mmgr, n); - return STIX_NULL; + if (rbt->style->freeer[MOO_RBT_KEY] != MOO_NULL) + rbt->style->freeer[MOO_RBT_KEY] (rbt, KPTR(n), KLEN(n)); + MOO_MMGR_FREE (rbt->moo->mmgr, n); + return MOO_NULL; } } return n; } -STIX_INLINE void stix_rbt_freepair (stix_rbt_t* rbt, stix_rbt_pair_t* pair) +MOO_INLINE void moo_rbt_freepair (moo_rbt_t* rbt, moo_rbt_pair_t* pair) { - if (rbt->style->freeer[STIX_RBT_KEY] != STIX_NULL) - rbt->style->freeer[STIX_RBT_KEY] (rbt, KPTR(pair), KLEN(pair)); - if (rbt->style->freeer[STIX_RBT_VAL] != STIX_NULL) - rbt->style->freeer[STIX_RBT_VAL] (rbt, VPTR(pair), VLEN(pair)); - STIX_MMGR_FREE (rbt->stix->mmgr, pair); + if (rbt->style->freeer[MOO_RBT_KEY] != MOO_NULL) + rbt->style->freeer[MOO_RBT_KEY] (rbt, KPTR(pair), KLEN(pair)); + if (rbt->style->freeer[MOO_RBT_VAL] != MOO_NULL) + rbt->style->freeer[MOO_RBT_VAL] (rbt, VPTR(pair), VLEN(pair)); + MOO_MMGR_FREE (rbt->moo->mmgr, pair); } -static stix_rbt_style_t style[] = +static moo_rbt_style_t style[] = { { { - STIX_RBT_COPIER_DEFAULT, - STIX_RBT_COPIER_DEFAULT + MOO_RBT_COPIER_DEFAULT, + MOO_RBT_COPIER_DEFAULT }, { - STIX_RBT_FREEER_DEFAULT, - STIX_RBT_FREEER_DEFAULT + MOO_RBT_FREEER_DEFAULT, + MOO_RBT_FREEER_DEFAULT }, - STIX_RBT_COMPER_DEFAULT, - STIX_RBT_KEEPER_DEFAULT + MOO_RBT_COMPER_DEFAULT, + MOO_RBT_KEEPER_DEFAULT }, { { - STIX_RBT_COPIER_INLINE, - STIX_RBT_COPIER_INLINE + MOO_RBT_COPIER_INLINE, + MOO_RBT_COPIER_INLINE }, { - STIX_RBT_FREEER_DEFAULT, - STIX_RBT_FREEER_DEFAULT + MOO_RBT_FREEER_DEFAULT, + MOO_RBT_FREEER_DEFAULT }, - STIX_RBT_COMPER_DEFAULT, - STIX_RBT_KEEPER_DEFAULT + MOO_RBT_COMPER_DEFAULT, + MOO_RBT_KEEPER_DEFAULT }, { { - STIX_RBT_COPIER_INLINE, - STIX_RBT_COPIER_DEFAULT + MOO_RBT_COPIER_INLINE, + MOO_RBT_COPIER_DEFAULT }, { - STIX_RBT_FREEER_DEFAULT, - STIX_RBT_FREEER_DEFAULT + MOO_RBT_FREEER_DEFAULT, + MOO_RBT_FREEER_DEFAULT }, - STIX_RBT_COMPER_DEFAULT, - STIX_RBT_KEEPER_DEFAULT + MOO_RBT_COMPER_DEFAULT, + MOO_RBT_KEEPER_DEFAULT }, { { - STIX_RBT_COPIER_DEFAULT, - STIX_RBT_COPIER_INLINE + MOO_RBT_COPIER_DEFAULT, + MOO_RBT_COPIER_INLINE }, { - STIX_RBT_FREEER_DEFAULT, - STIX_RBT_FREEER_DEFAULT + MOO_RBT_FREEER_DEFAULT, + MOO_RBT_FREEER_DEFAULT }, - STIX_RBT_COMPER_DEFAULT, - STIX_RBT_KEEPER_DEFAULT + MOO_RBT_COMPER_DEFAULT, + MOO_RBT_KEEPER_DEFAULT } }; -const stix_rbt_style_t* stix_getrbtstyle (stix_rbt_style_kind_t kind) +const moo_rbt_style_t* moo_getrbtstyle (moo_rbt_style_kind_t kind) { return &style[kind]; } -stix_rbt_t* stix_rbt_open (stix_t* stix, stix_oow_t xtnsize, int kscale, int vscale) +moo_rbt_t* moo_rbt_open (moo_t* moo, moo_oow_t xtnsize, int kscale, int vscale) { - stix_rbt_t* rbt; + moo_rbt_t* rbt; - rbt = (stix_rbt_t*) STIX_MMGR_ALLOC (stix->mmgr, STIX_SIZEOF(stix_rbt_t) + xtnsize); - if (rbt == STIX_NULL) return STIX_NULL; + rbt = (moo_rbt_t*) MOO_MMGR_ALLOC (moo->mmgr, MOO_SIZEOF(moo_rbt_t) + xtnsize); + if (rbt == MOO_NULL) return MOO_NULL; - if (stix_rbt_init (rbt, stix, kscale, vscale) <= -1) + if (moo_rbt_init (rbt, moo, kscale, vscale) <= -1) { - STIX_MMGR_FREE (stix->mmgr, rbt); - return STIX_NULL; + MOO_MMGR_FREE (moo->mmgr, rbt); + return MOO_NULL; } - STIX_MEMSET (rbt + 1, 0, xtnsize); + MOO_MEMSET (rbt + 1, 0, xtnsize); return rbt; } -void stix_rbt_close (stix_rbt_t* rbt) +void moo_rbt_close (moo_rbt_t* rbt) { - stix_rbt_fini (rbt); - STIX_MMGR_FREE (rbt->stix->mmgr, rbt); + moo_rbt_fini (rbt); + MOO_MMGR_FREE (rbt->moo->mmgr, rbt); } -int stix_rbt_init (stix_rbt_t* rbt, stix_t* stix, int kscale, int vscale) +int moo_rbt_init (moo_rbt_t* rbt, moo_t* moo, int kscale, int vscale) { /* do not zero out the extension */ - STIX_MEMSET (rbt, 0, STIX_SIZEOF(*rbt)); - rbt->stix = stix; + MOO_MEMSET (rbt, 0, MOO_SIZEOF(*rbt)); + rbt->moo = moo; - rbt->scale[STIX_RBT_KEY] = (kscale < 1)? 1: kscale; - rbt->scale[STIX_RBT_VAL] = (vscale < 1)? 1: vscale; + rbt->scale[MOO_RBT_KEY] = (kscale < 1)? 1: kscale; + rbt->scale[MOO_RBT_VAL] = (vscale < 1)? 1: vscale; rbt->size = 0; rbt->style = &style[0]; /* self-initializing nil */ - STIX_MEMSET(&rbt->xnil, 0, STIX_SIZEOF(rbt->xnil)); - rbt->xnil.color = STIX_RBT_BLACK; + MOO_MEMSET(&rbt->xnil, 0, MOO_SIZEOF(rbt->xnil)); + rbt->xnil.color = MOO_RBT_BLACK; rbt->xnil.left = &rbt->xnil; rbt->xnil.right = &rbt->xnil; @@ -238,35 +238,35 @@ int stix_rbt_init (stix_rbt_t* rbt, stix_t* stix, int kscale, int vscale) return 0; } -void stix_rbt_fini (stix_rbt_t* rbt) +void moo_rbt_fini (moo_rbt_t* rbt) { - stix_rbt_clear (rbt); + moo_rbt_clear (rbt); } -void* stix_rbt_getxtn (stix_rbt_t* rbt) +void* moo_rbt_getxtn (moo_rbt_t* rbt) { return (void*)(rbt + 1); } -const stix_rbt_style_t* stix_rbt_getstyle (const stix_rbt_t* rbt) +const moo_rbt_style_t* moo_rbt_getstyle (const moo_rbt_t* rbt) { return rbt->style; } -void stix_rbt_setstyle (stix_rbt_t* rbt, const stix_rbt_style_t* style) +void moo_rbt_setstyle (moo_rbt_t* rbt, const moo_rbt_style_t* style) { - STIX_ASSERT (rbt->stix, style != STIX_NULL); + MOO_ASSERT (rbt->moo, style != MOO_NULL); rbt->style = style; } -stix_oow_t stix_rbt_getsize (const stix_rbt_t* rbt) +moo_oow_t moo_rbt_getsize (const moo_rbt_t* rbt) { return rbt->size; } -stix_rbt_pair_t* stix_rbt_search (const stix_rbt_t* rbt, const void* kptr, stix_oow_t klen) +moo_rbt_pair_t* moo_rbt_search (const moo_rbt_t* rbt, const void* kptr, moo_oow_t klen) { - stix_rbt_pair_t* pair = rbt->root; + moo_rbt_pair_t* pair = rbt->root; while (!IS_NIL(rbt,pair)) { @@ -277,10 +277,10 @@ stix_rbt_pair_t* stix_rbt_search (const stix_rbt_t* rbt, const void* kptr, stix_ else /* if (n < 0) */ pair = pair->left; } - return STIX_NULL; + return MOO_NULL; } -static void rotate (stix_rbt_t* rbt, stix_rbt_pair_t* pivot, int leftwise) +static void rotate (moo_rbt_t* rbt, moo_rbt_pair_t* pivot, int leftwise) { /* * == leftwise rotation @@ -316,10 +316,10 @@ static void rotate (stix_rbt_t* rbt, stix_rbt_pair_t* pivot, int leftwise) * is the left child or the right child of its parent, */ - stix_rbt_pair_t* parent, * z, * c; + moo_rbt_pair_t* parent, * z, * c; int cid1, cid2; - STIX_ASSERT (rbt->stix, pivot != STIX_NULL); + MOO_ASSERT (rbt->moo, pivot != MOO_NULL); if (leftwise) { @@ -347,13 +347,13 @@ static void rotate (stix_rbt_t* rbt, stix_rbt_pair_t* pivot, int leftwise) } else { - STIX_ASSERT (rbt->stix, parent->right == pivot); + MOO_ASSERT (rbt->moo, parent->right == pivot); parent->right = z; } } else { - STIX_ASSERT (rbt->stix, rbt->root == pivot); + MOO_ASSERT (rbt->moo, rbt->root == pivot); rbt->root = z; } @@ -364,17 +364,17 @@ static void rotate (stix_rbt_t* rbt, stix_rbt_pair_t* pivot, int leftwise) if (!IS_NIL(rbt,c)) c->parent = pivot; } -static void adjust (stix_rbt_t* rbt, stix_rbt_pair_t* pair) +static void adjust (moo_rbt_t* rbt, moo_rbt_pair_t* pair) { while (pair != rbt->root) { - stix_rbt_pair_t* tmp, * tmp2, * x_par; + moo_rbt_pair_t* tmp, * tmp2, * x_par; int leftwise; x_par = pair->parent; - if (x_par->color == STIX_RBT_BLACK) break; + if (x_par->color == MOO_RBT_BLACK) break; - STIX_ASSERT (rbt->stix, x_par->parent != STIX_NULL); + MOO_ASSERT (rbt->moo, x_par->parent != MOO_NULL); if (x_par == x_par->parent->child[LEFT]) { @@ -389,11 +389,11 @@ static void adjust (stix_rbt_t* rbt, stix_rbt_pair_t* pair) leftwise = 0; } - if (tmp->color == STIX_RBT_RED) + if (tmp->color == MOO_RBT_RED) { - x_par->color = STIX_RBT_BLACK; - tmp->color = STIX_RBT_BLACK; - x_par->parent->color = STIX_RBT_RED; + x_par->color = MOO_RBT_BLACK; + tmp->color = MOO_RBT_BLACK; + x_par->parent->color = MOO_RBT_RED; pair = x_par->parent; } else @@ -405,51 +405,51 @@ static void adjust (stix_rbt_t* rbt, stix_rbt_pair_t* pair) x_par = pair->parent; } - x_par->color = STIX_RBT_BLACK; - x_par->parent->color = STIX_RBT_RED; + x_par->color = MOO_RBT_BLACK; + x_par->parent->color = MOO_RBT_RED; rotate (rbt, x_par->parent, !leftwise); } } } -static stix_rbt_pair_t* change_pair_val ( - stix_rbt_t* rbt, stix_rbt_pair_t* pair, void* vptr, stix_oow_t vlen) +static moo_rbt_pair_t* change_pair_val ( + moo_rbt_t* rbt, moo_rbt_pair_t* pair, void* vptr, moo_oow_t vlen) { if (VPTR(pair) == vptr && VLEN(pair) == vlen) { /* if the old value and the new value are the same, * it just calls the handler for this condition. * No value replacement occurs. */ - if (rbt->style->keeper != STIX_NULL) + if (rbt->style->keeper != MOO_NULL) { rbt->style->keeper (rbt, vptr, vlen); } } else { - copier_t vcop = rbt->style->copier[STIX_RBT_VAL]; + copier_t vcop = rbt->style->copier[MOO_RBT_VAL]; void* ovptr = VPTR(pair); - stix_oow_t ovlen = VLEN(pair); + moo_oow_t ovlen = VLEN(pair); /* place the new value according to the copier */ - if (vcop == STIX_RBT_COPIER_SIMPLE) + if (vcop == MOO_RBT_COPIER_SIMPLE) { VPTR(pair) = vptr; VLEN(pair) = vlen; } - else if (vcop == STIX_RBT_COPIER_INLINE) + else if (vcop == MOO_RBT_COPIER_INLINE) { if (ovlen == vlen) { - if (vptr) STIX_MEMCPY (VPTR(pair), vptr, VTOB(rbt,vlen)); + if (vptr) MOO_MEMCPY (VPTR(pair), vptr, VTOB(rbt,vlen)); } else { /* need to reconstruct the pair */ - stix_rbt_pair_t* p = stix_rbt_allocpair (rbt, + moo_rbt_pair_t* p = moo_rbt_allocpair (rbt, KPTR(pair), KLEN(pair), vptr, vlen); - if (p == STIX_NULL) return STIX_NULL; + if (p == MOO_NULL) return MOO_NULL; p->color = pair->color; p->left = pair->left; @@ -464,7 +464,7 @@ static stix_rbt_pair_t* change_pair_val ( } else { - STIX_ASSERT (rbt->stix, pair->parent->right == pair); + MOO_ASSERT (rbt->moo, pair->parent->right == pair); pair->parent->right = p; } } @@ -473,34 +473,34 @@ static stix_rbt_pair_t* change_pair_val ( if (pair == rbt->root) rbt->root = p; - stix_rbt_freepair (rbt, pair); + moo_rbt_freepair (rbt, pair); return p; } } else { void* nvptr = vcop (rbt, vptr, vlen); - if (nvptr == STIX_NULL) return STIX_NULL; + if (nvptr == MOO_NULL) return MOO_NULL; VPTR(pair) = nvptr; VLEN(pair) = vlen; } /* free up the old value */ - if (rbt->style->freeer[STIX_RBT_VAL] != STIX_NULL) + if (rbt->style->freeer[MOO_RBT_VAL] != MOO_NULL) { - rbt->style->freeer[STIX_RBT_VAL] (rbt, ovptr, ovlen); + rbt->style->freeer[MOO_RBT_VAL] (rbt, ovptr, ovlen); } } return pair; } -static stix_rbt_pair_t* insert ( - stix_rbt_t* rbt, void* kptr, stix_oow_t klen, void* vptr, stix_oow_t vlen, int opt) +static moo_rbt_pair_t* insert ( + moo_rbt_t* rbt, void* kptr, moo_oow_t klen, void* vptr, moo_oow_t vlen, int opt) { - stix_rbt_pair_t* x_cur = rbt->root; - stix_rbt_pair_t* x_par = STIX_NULL; - stix_rbt_pair_t* x_new; + moo_rbt_pair_t* x_cur = rbt->root; + moo_rbt_pair_t* x_par = MOO_NULL; + moo_rbt_pair_t* x_new; while (!IS_NIL(rbt,x_cur)) { @@ -519,7 +519,7 @@ static stix_rbt_pair_t* insert ( case INSERT: /* return failure */ - return STIX_NULL; + return MOO_NULL; } } @@ -529,15 +529,15 @@ static stix_rbt_pair_t* insert ( else /* if (n < 0) */ x_cur = x_cur->left; } - if (opt == UPDATE) return STIX_NULL; + if (opt == UPDATE) return MOO_NULL; - x_new = stix_rbt_allocpair (rbt, kptr, klen, vptr, vlen); - if (x_new == STIX_NULL) return STIX_NULL; + x_new = moo_rbt_allocpair (rbt, kptr, klen, vptr, vlen); + if (x_new == MOO_NULL) return MOO_NULL; - if (x_par == STIX_NULL) + if (x_par == MOO_NULL) { /* the tree contains no pair */ - STIX_ASSERT (rbt->stix, rbt->root == &rbt->xnil); + MOO_ASSERT (rbt->moo, rbt->root == &rbt->xnil); rbt->root = x_new; } else @@ -546,12 +546,12 @@ static stix_rbt_pair_t* insert ( int n = rbt->style->comper (rbt, kptr, klen, KPTR(x_par), KLEN(x_par)); if (n > 0) { - STIX_ASSERT (rbt->stix, x_par->right == &rbt->xnil); + MOO_ASSERT (rbt->moo, x_par->right == &rbt->xnil); x_par->right = x_new; } else { - STIX_ASSERT (rbt->stix, x_par->left == &rbt->xnil); + MOO_ASSERT (rbt->moo, x_par->left == &rbt->xnil); x_par->left = x_new; } @@ -559,42 +559,42 @@ static stix_rbt_pair_t* insert ( adjust (rbt, x_new); } - rbt->root->color = STIX_RBT_BLACK; + rbt->root->color = MOO_RBT_BLACK; rbt->size++; return x_new; } -stix_rbt_pair_t* stix_rbt_upsert ( - stix_rbt_t* rbt, void* kptr, stix_oow_t klen, void* vptr, stix_oow_t vlen) +moo_rbt_pair_t* moo_rbt_upsert ( + moo_rbt_t* rbt, void* kptr, moo_oow_t klen, void* vptr, moo_oow_t vlen) { return insert (rbt, kptr, klen, vptr, vlen, UPSERT); } -stix_rbt_pair_t* stix_rbt_ensert ( - stix_rbt_t* rbt, void* kptr, stix_oow_t klen, void* vptr, stix_oow_t vlen) +moo_rbt_pair_t* moo_rbt_ensert ( + moo_rbt_t* rbt, void* kptr, moo_oow_t klen, void* vptr, moo_oow_t vlen) { return insert (rbt, kptr, klen, vptr, vlen, ENSERT); } -stix_rbt_pair_t* stix_rbt_insert ( - stix_rbt_t* rbt, void* kptr, stix_oow_t klen, void* vptr, stix_oow_t vlen) +moo_rbt_pair_t* moo_rbt_insert ( + moo_rbt_t* rbt, void* kptr, moo_oow_t klen, void* vptr, moo_oow_t vlen) { return insert (rbt, kptr, klen, vptr, vlen, INSERT); } -stix_rbt_pair_t* stix_rbt_update ( - stix_rbt_t* rbt, void* kptr, stix_oow_t klen, void* vptr, stix_oow_t vlen) +moo_rbt_pair_t* moo_rbt_update ( + moo_rbt_t* rbt, void* kptr, moo_oow_t klen, void* vptr, moo_oow_t vlen) { return insert (rbt, kptr, klen, vptr, vlen, UPDATE); } -stix_rbt_pair_t* stix_rbt_cbsert ( - stix_rbt_t* rbt, void* kptr, stix_oow_t klen, cbserter_t cbserter, void* ctx) +moo_rbt_pair_t* moo_rbt_cbsert ( + moo_rbt_t* rbt, void* kptr, moo_oow_t klen, cbserter_t cbserter, void* ctx) { - stix_rbt_pair_t* x_cur = rbt->root; - stix_rbt_pair_t* x_par = STIX_NULL; - stix_rbt_pair_t* x_new; + moo_rbt_pair_t* x_cur = rbt->root; + moo_rbt_pair_t* x_par = MOO_NULL; + moo_rbt_pair_t* x_new; while (!IS_NIL(rbt,x_cur)) { @@ -603,16 +603,16 @@ stix_rbt_pair_t* stix_rbt_cbsert ( { /* back up the contents of the current pair * in case it is reallocated */ - stix_rbt_pair_t tmp; + moo_rbt_pair_t tmp; tmp = *x_cur; /* call the callback function to manipulate the pair */ x_new = cbserter (rbt, x_cur, kptr, klen, ctx); - if (x_new == STIX_NULL) + if (x_new == MOO_NULL) { /* error returned by the callback function */ - return STIX_NULL; + return MOO_NULL; } if (x_new != x_cur) @@ -634,7 +634,7 @@ stix_rbt_pair_t* stix_rbt_cbsert ( } else { - STIX_ASSERT (rbt->stix, tmp.parent->right == x_cur); + MOO_ASSERT (rbt->moo, tmp.parent->right == x_cur); tmp.parent->right = x_new; } } @@ -653,13 +653,13 @@ stix_rbt_pair_t* stix_rbt_cbsert ( else /* if (n < 0) */ x_cur = x_cur->left; } - x_new = cbserter (rbt, STIX_NULL, kptr, klen, ctx); - if (x_new == STIX_NULL) return STIX_NULL; + x_new = cbserter (rbt, MOO_NULL, kptr, klen, ctx); + if (x_new == MOO_NULL) return MOO_NULL; - if (x_par == STIX_NULL) + if (x_par == MOO_NULL) { /* the tree contains no pair */ - STIX_ASSERT (rbt->stix, rbt->root == &rbt->xnil); + MOO_ASSERT (rbt->moo, rbt->root == &rbt->xnil); rbt->root = x_new; } else @@ -668,12 +668,12 @@ stix_rbt_pair_t* stix_rbt_cbsert ( int n = rbt->style->comper (rbt, kptr, klen, KPTR(x_par), KLEN(x_par)); if (n > 0) { - STIX_ASSERT (rbt->stix, x_par->right == &rbt->xnil); + MOO_ASSERT (rbt->moo, x_par->right == &rbt->xnil); x_par->right = x_new; } else { - STIX_ASSERT (rbt->stix, x_par->left == &rbt->xnil); + MOO_ASSERT (rbt->moo, x_par->left == &rbt->xnil); x_par->left = x_new; } @@ -681,51 +681,51 @@ stix_rbt_pair_t* stix_rbt_cbsert ( adjust (rbt, x_new); } - rbt->root->color = STIX_RBT_BLACK; + rbt->root->color = MOO_RBT_BLACK; rbt->size++; return x_new; } -static void adjust_for_delete (stix_rbt_t* rbt, stix_rbt_pair_t* pair, stix_rbt_pair_t* par) +static void adjust_for_delete (moo_rbt_t* rbt, moo_rbt_pair_t* pair, moo_rbt_pair_t* par) { - while (pair != rbt->root && pair->color == STIX_RBT_BLACK) + while (pair != rbt->root && pair->color == MOO_RBT_BLACK) { - stix_rbt_pair_t* tmp; + moo_rbt_pair_t* tmp; if (pair == par->left) { tmp = par->right; - if (tmp->color == STIX_RBT_RED) + if (tmp->color == MOO_RBT_RED) { - tmp->color = STIX_RBT_BLACK; - par->color = STIX_RBT_RED; + tmp->color = MOO_RBT_BLACK; + par->color = MOO_RBT_RED; rotate_left (rbt, par); tmp = par->right; } - if (tmp->left->color == STIX_RBT_BLACK && - tmp->right->color == STIX_RBT_BLACK) + if (tmp->left->color == MOO_RBT_BLACK && + tmp->right->color == MOO_RBT_BLACK) { - if (!IS_NIL(rbt,tmp)) tmp->color = STIX_RBT_RED; + if (!IS_NIL(rbt,tmp)) tmp->color = MOO_RBT_RED; pair = par; par = pair->parent; } else { - if (tmp->right->color == STIX_RBT_BLACK) + if (tmp->right->color == MOO_RBT_BLACK) { if (!IS_NIL(rbt,tmp->left)) - tmp->left->color = STIX_RBT_BLACK; - tmp->color = STIX_RBT_RED; + tmp->left->color = MOO_RBT_BLACK; + tmp->color = MOO_RBT_RED; rotate_right (rbt, tmp); tmp = par->right; } tmp->color = par->color; - if (!IS_NIL(rbt,par)) par->color = STIX_RBT_BLACK; - if (tmp->right->color == STIX_RBT_RED) - tmp->right->color = STIX_RBT_BLACK; + if (!IS_NIL(rbt,par)) par->color = MOO_RBT_BLACK; + if (tmp->right->color == MOO_RBT_RED) + tmp->right->color = MOO_RBT_BLACK; rotate_left (rbt, par); pair = rbt->root; @@ -733,37 +733,37 @@ static void adjust_for_delete (stix_rbt_t* rbt, stix_rbt_pair_t* pair, stix_rbt_ } else { - STIX_ASSERT (rbt->stix, pair == par->right); + MOO_ASSERT (rbt->moo, pair == par->right); tmp = par->left; - if (tmp->color == STIX_RBT_RED) + if (tmp->color == MOO_RBT_RED) { - tmp->color = STIX_RBT_BLACK; - par->color = STIX_RBT_RED; + tmp->color = MOO_RBT_BLACK; + par->color = MOO_RBT_RED; rotate_right (rbt, par); tmp = par->left; } - if (tmp->left->color == STIX_RBT_BLACK && - tmp->right->color == STIX_RBT_BLACK) + if (tmp->left->color == MOO_RBT_BLACK && + tmp->right->color == MOO_RBT_BLACK) { - if (!IS_NIL(rbt,tmp)) tmp->color = STIX_RBT_RED; + if (!IS_NIL(rbt,tmp)) tmp->color = MOO_RBT_RED; pair = par; par = pair->parent; } else { - if (tmp->left->color == STIX_RBT_BLACK) + if (tmp->left->color == MOO_RBT_BLACK) { if (!IS_NIL(rbt,tmp->right)) - tmp->right->color = STIX_RBT_BLACK; - tmp->color = STIX_RBT_RED; + tmp->right->color = MOO_RBT_BLACK; + tmp->color = MOO_RBT_RED; rotate_left (rbt, tmp); tmp = par->left; } tmp->color = par->color; - if (!IS_NIL(rbt,par)) par->color = STIX_RBT_BLACK; - if (tmp->left->color == STIX_RBT_RED) - tmp->left->color = STIX_RBT_BLACK; + if (!IS_NIL(rbt,par)) par->color = MOO_RBT_BLACK; + if (tmp->left->color == MOO_RBT_RED) + tmp->left->color = MOO_RBT_BLACK; rotate_right (rbt, par); pair = rbt->root; @@ -771,14 +771,14 @@ static void adjust_for_delete (stix_rbt_t* rbt, stix_rbt_pair_t* pair, stix_rbt_ } } - pair->color = STIX_RBT_BLACK; + pair->color = MOO_RBT_BLACK; } -static void delete_pair (stix_rbt_t* rbt, stix_rbt_pair_t* pair) +static void delete_pair (moo_rbt_t* rbt, moo_rbt_pair_t* pair) { - stix_rbt_pair_t* x, * y, * par; + moo_rbt_pair_t* x, * y, * par; - STIX_ASSERT (rbt->stix, pair && !IS_NIL(rbt,pair)); + MOO_ASSERT (rbt->moo, pair && !IS_NIL(rbt,pair)); if (IS_NIL(rbt,pair->left) || IS_NIL(rbt,pair->right)) { @@ -810,14 +810,14 @@ static void delete_pair (stix_rbt_t* rbt, stix_rbt_pair_t* pair) if (y == pair) { - if (y->color == STIX_RBT_BLACK && !IS_NIL(rbt,x)) + if (y->color == MOO_RBT_BLACK && !IS_NIL(rbt,x)) adjust_for_delete (rbt, x, par); - stix_rbt_freepair (rbt, y); + moo_rbt_freepair (rbt, y); } else { - if (y->color == STIX_RBT_BLACK && !IS_NIL(rbt,x)) + if (y->color == MOO_RBT_BLACK && !IS_NIL(rbt,x)) adjust_for_delete (rbt, x, par); #if 1 @@ -854,55 +854,55 @@ static void delete_pair (stix_rbt_t* rbt, stix_rbt_pair_t* pair) if (y->right->parent == pair) y->right->parent = y; #endif - stix_rbt_freepair (rbt, pair); + moo_rbt_freepair (rbt, pair); } rbt->size--; } -int stix_rbt_delete (stix_rbt_t* rbt, const void* kptr, stix_oow_t klen) +int moo_rbt_delete (moo_rbt_t* rbt, const void* kptr, moo_oow_t klen) { - stix_rbt_pair_t* pair; + moo_rbt_pair_t* pair; - pair = stix_rbt_search (rbt, kptr, klen); - if (pair == STIX_NULL) return -1; + pair = moo_rbt_search (rbt, kptr, klen); + if (pair == MOO_NULL) return -1; delete_pair (rbt, pair); return 0; } -void stix_rbt_clear (stix_rbt_t* rbt) +void moo_rbt_clear (moo_rbt_t* rbt) { /* TODO: improve this */ while (!IS_NIL(rbt,rbt->root)) delete_pair (rbt, rbt->root); } #if 0 -static STIX_INLINE stix_rbt_walk_t walk_recursively ( - stix_rbt_t* rbt, walker_t walker, void* ctx, stix_rbt_pair_t* pair) +static MOO_INLINE moo_rbt_walk_t walk_recursively ( + moo_rbt_t* rbt, walker_t walker, void* ctx, moo_rbt_pair_t* pair) { if (!IS_NIL(rbt,pair->left)) { - if (walk_recursively (rbt, walker, ctx, pair->left) == STIX_RBT_WALK_STOP) - return STIX_RBT_WALK_STOP; + if (walk_recursively (rbt, walker, ctx, pair->left) == MOO_RBT_WALK_STOP) + return MOO_RBT_WALK_STOP; } - if (walker (rbt, pair, ctx) == STIX_RBT_WALK_STOP) return STIX_RBT_WALK_STOP; + if (walker (rbt, pair, ctx) == MOO_RBT_WALK_STOP) return MOO_RBT_WALK_STOP; if (!IS_NIL(rbt,pair->right)) { - if (walk_recursively (rbt, walker, ctx, pair->right) == STIX_RBT_WALK_STOP) - return STIX_RBT_WALK_STOP; + if (walk_recursively (rbt, walker, ctx, pair->right) == MOO_RBT_WALK_STOP) + return MOO_RBT_WALK_STOP; } - return STIX_RBT_WALK_FORWARD; + return MOO_RBT_WALK_FORWARD; } #endif -static STIX_INLINE void walk (stix_rbt_t* rbt, walker_t walker, void* ctx, int l, int r) +static MOO_INLINE void walk (moo_rbt_t* rbt, walker_t walker, void* ctx, int l, int r) { - stix_rbt_pair_t* x_cur = rbt->root; - stix_rbt_pair_t* prev = rbt->root->parent; + moo_rbt_pair_t* x_cur = rbt->root; + moo_rbt_pair_t* prev = rbt->root->parent; while (x_cur && !IS_NIL(rbt,x_cur)) { @@ -918,7 +918,7 @@ static STIX_INLINE void walk (stix_rbt_t* rbt, walker_t walker, void* ctx, int l } else { - if (walker (rbt, x_cur, ctx) == STIX_RBT_WALK_STOP) break; + if (walker (rbt, x_cur, ctx) == MOO_RBT_WALK_STOP) break; if (!IS_NIL(rbt,x_cur->child[r])) { @@ -938,7 +938,7 @@ static STIX_INLINE void walk (stix_rbt_t* rbt, walker_t walker, void* ctx, int l { /* the left child has been already traversed */ - if (walker (rbt, x_cur, ctx) == STIX_RBT_WALK_STOP) break; + if (walker (rbt, x_cur, ctx) == MOO_RBT_WALK_STOP) break; if (!IS_NIL(rbt,x_cur->child[r])) { @@ -956,7 +956,7 @@ static STIX_INLINE void walk (stix_rbt_t* rbt, walker_t walker, void* ctx, int l else { /* both the left child and the right child have been traversed */ - STIX_ASSERT (rbt->stix, prev == x_cur->child[r]); + MOO_ASSERT (rbt->moo, prev == x_cur->child[r]); /* just move up to the parent */ prev = x_cur; x_cur = x_cur->parent; @@ -964,19 +964,19 @@ static STIX_INLINE void walk (stix_rbt_t* rbt, walker_t walker, void* ctx, int l } } -void stix_rbt_walk (stix_rbt_t* rbt, walker_t walker, void* ctx) +void moo_rbt_walk (moo_rbt_t* rbt, walker_t walker, void* ctx) { walk (rbt, walker, ctx, LEFT, RIGHT); } -void stix_rbt_rwalk (stix_rbt_t* rbt, walker_t walker, void* ctx) +void moo_rbt_rwalk (moo_rbt_t* rbt, walker_t walker, void* ctx) { walk (rbt, walker, ctx, RIGHT, LEFT); } -int stix_rbt_dflcomp (const stix_rbt_t* rbt, const void* kptr1, stix_oow_t klen1, const void* kptr2, stix_oow_t klen2) +int moo_rbt_dflcomp (const moo_rbt_t* rbt, const void* kptr1, moo_oow_t klen1, const void* kptr2, moo_oow_t klen2) { - stix_oow_t min; + moo_oow_t min; int n, nn; if (klen1 < klen2) @@ -990,7 +990,7 @@ int stix_rbt_dflcomp (const stix_rbt_t* rbt, const void* kptr1, stix_oow_t klen1 nn = (klen1 == klen2)? 0: 1; } - n = STIX_MEMCMP (kptr1, kptr2, KTOB(rbt,min)); + n = MOO_MEMCMP (kptr1, kptr2, KTOB(rbt,min)); if (n == 0) n = nn; return n; } diff --git a/stix/lib/stix-cmn.h b/stix/lib/stix-cmn.h deleted file mode 100644 index 41eb912..0000000 --- a/stix/lib/stix-cmn.h +++ /dev/null @@ -1,723 +0,0 @@ -/* - * $Id$ - * - Copyright (c) 2014-2016 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_CMN_H_ -#define _STIX_CMN_H_ - -/* WARNING: NEVER CHANGE/DELETE THE FOLLOWING STIX_HAVE_CFG_H DEFINITION. - * IT IS USED FOR DEPLOYMENT BY MAKEFILE.AM */ -/*#define STIX_HAVE_CFG_H*/ - -#if defined(STIX_HAVE_CFG_H) -# include "stix-cfg.h" -#elif defined(_WIN32) -# include "stix-msw.h" -#elif defined(__OS2__) -# include "stix-os2.h" -#elif defined(__MSDOS__) -# include "stix-dos.h" -#elif defined(macintosh) -# include "stix-mac.h" /* class mac os */ -#else -# error UNSUPPORTED SYSTEM -#endif - -#if defined(EMSCRIPTEN) -# if defined(STIX_SIZEOF___INT128) -# undef STIX_SIZEOF___INT128 -# define STIX_SIZEOF___INT128 0 -# endif -# if defined(STIX_SIZEOF_LONG) && defined(STIX_SIZEOF_INT) && (STIX_SIZEOF_LONG > STIX_SIZEOF_INT) - /* autoconf doesn't seem to match actual emscripten */ -# undef STIX_SIZEOF_LONG -# define STIX_SIZEOF_LONG STIX_SIZEOF_INT -# endif -#endif - - -/* ========================================================================= - * PRIMITIVE TYPE DEFINTIONS - * ========================================================================= */ - -/* stix_int8_t */ -#if defined(STIX_SIZEOF_CHAR) && (STIX_SIZEOF_CHAR == 1) -# define STIX_HAVE_UINT8_T -# define STIX_HAVE_INT8_T - typedef unsigned char stix_uint8_t; - typedef signed char stix_int8_t; -#elif defined(STIX_SIZEOF___INT8) && (STIX_SIZEOF___INT8 == 1) -# define STIX_HAVE_UINT8_T -# define STIX_HAVE_INT8_T - typedef unsigned __int8 stix_uint8_t; - typedef signed __int8 stix_int8_t; -#elif defined(STIX_SIZEOF___INT8_T) && (STIX_SIZEOF___INT8_T == 1) -# define STIX_HAVE_UINT8_T -# define STIX_HAVE_INT8_T - typedef unsigned __int8_t stix_uint8_t; - typedef signed __int8_t stix_int8_t; -#else -# define STIX_HAVE_UINT8_T -# define STIX_HAVE_INT8_T - typedef unsigned char stix_uint8_t; - typedef signed char stix_int8_t; -#endif - - -/* stix_int16_t */ -#if defined(STIX_SIZEOF_SHORT) && (STIX_SIZEOF_SHORT == 2) -# define STIX_HAVE_UINT16_T -# define STIX_HAVE_INT16_T - typedef unsigned short int stix_uint16_t; - typedef signed short int stix_int16_t; -#elif defined(STIX_SIZEOF___INT16) && (STIX_SIZEOF___INT16 == 2) -# define STIX_HAVE_UINT16_T -# define STIX_HAVE_INT16_T - typedef unsigned __int16 stix_uint16_t; - typedef signed __int16 stix_int16_t; -#elif defined(STIX_SIZEOF___INT16_T) && (STIX_SIZEOF___INT16_T == 2) -# define STIX_HAVE_UINT16_T -# define STIX_HAVE_INT16_T - typedef unsigned __int16_t stix_uint16_t; - typedef signed __int16_t stix_int16_t; -#else -# define STIX_HAVE_UINT16_T -# define STIX_HAVE_INT16_T - typedef unsigned short int stix_uint16_t; - typedef signed short int stix_int16_t; -#endif - - -/* stix_int32_t */ -#if defined(STIX_SIZEOF_INT) && (STIX_SIZEOF_INT == 4) -# define STIX_HAVE_UINT32_T -# define STIX_HAVE_INT32_T - typedef unsigned int stix_uint32_t; - typedef signed int stix_int32_t; -#elif defined(STIX_SIZEOF_LONG) && (STIX_SIZEOF_LONG == 4) -# define STIX_HAVE_UINT32_T -# define STIX_HAVE_INT32_T - typedef unsigned long stix_uint32_t; - typedef signed long stix_int32_t; -#elif defined(STIX_SIZEOF___INT32) && (STIX_SIZEOF___INT32 == 4) -# define STIX_HAVE_UINT32_T -# define STIX_HAVE_INT32_T - typedef unsigned __int32 stix_uint32_t; - typedef signed __int32 stix_int32_t; -#elif defined(STIX_SIZEOF___INT32_T) && (STIX_SIZEOF___INT32_T == 4) -# define STIX_HAVE_UINT32_T -# define STIX_HAVE_INT32_T - typedef unsigned __int32_t stix_uint32_t; - typedef signed __int32_t stix_int32_t; -#elif defined(__MSDOS__) -# define STIX_HAVE_UINT32_T -# define STIX_HAVE_INT32_T - typedef unsigned long int stix_uint32_t; - typedef signed long int stix_int32_t; -#else -# define STIX_HAVE_UINT32_T -# define STIX_HAVE_INT32_T - typedef unsigned int stix_uint32_t; - typedef signed int stix_int32_t; -#endif - -/* stix_int64_t */ -#if defined(STIX_SIZEOF_INT) && (STIX_SIZEOF_INT == 8) -# define STIX_HAVE_UINT64_T -# define STIX_HAVE_INT64_T - typedef unsigned int stix_uint64_t; - typedef signed int stix_int64_t; -#elif defined(STIX_SIZEOF_LONG) && (STIX_SIZEOF_LONG == 8) -# define STIX_HAVE_UINT64_T -# define STIX_HAVE_INT64_T - typedef unsigned long stix_uint64_t; - typedef signed long stix_int64_t; -#elif defined(STIX_SIZEOF_LONG_LONG) && (STIX_SIZEOF_LONG_LONG == 8) -# define STIX_HAVE_UINT64_T -# define STIX_HAVE_INT64_T - typedef unsigned long long stix_uint64_t; - typedef signed long long stix_int64_t; -#elif defined(STIX_SIZEOF___INT64) && (STIX_SIZEOF___INT64 == 8) -# define STIX_HAVE_UINT64_T -# define STIX_HAVE_INT64_T - typedef unsigned __int64 stix_uint64_t; - typedef signed __int64 stix_int64_t; -#elif defined(STIX_SIZEOF___INT64_T) && (STIX_SIZEOF___INT64_T == 8) -# define STIX_HAVE_UINT64_T -# define STIX_HAVE_INT64_T - typedef unsigned __int64_t stix_uint64_t; - typedef signed __int64_t stix_int64_t; -#else - /* no 64-bit integer */ -#endif - -/* stix_int128_t */ -#if defined(STIX_SIZEOF_INT) && (STIX_SIZEOF_INT == 16) -# define STIX_HAVE_UINT128_T -# define STIX_HAVE_INT128_T - typedef unsigned int stix_uint128_t; - typedef signed int stix_int128_t; -#elif defined(STIX_SIZEOF_LONG) && (STIX_SIZEOF_LONG == 16) -# define STIX_HAVE_UINT128_T -# define STIX_HAVE_INT128_T - typedef unsigned long stix_uint128_t; - typedef signed long stix_int128_t; -#elif defined(STIX_SIZEOF_LONG_LONG) && (STIX_SIZEOF_LONG_LONG == 16) -# define STIX_HAVE_UINT128_T -# define STIX_HAVE_INT128_T - typedef unsigned long long stix_uint128_t; - typedef signed long long stix_int128_t; -#elif defined(STIX_SIZEOF___INT128) && (STIX_SIZEOF___INT128 == 16) -# define STIX_HAVE_UINT128_T -# define STIX_HAVE_INT128_T - typedef unsigned __int128 stix_uint128_t; - typedef signed __int128 stix_int128_t; -#elif defined(STIX_SIZEOF___INT128_T) && (STIX_SIZEOF___INT128_T == 16) -# define STIX_HAVE_UINT128_T -# define STIX_HAVE_INT128_T - #if defined(STIX_SIZEOF___UINT128_T) && (STIX_SIZEOF___UINT128_T == STIX_SIZEOF___INT128_T) - typedef __uint128_t stix_uint128_t; - typedef __int128_t stix_int128_t; - #elif defined(__clang__) - typedef __uint128_t stix_uint128_t; - typedef __int128_t stix_int128_t; - #else - typedef unsigned __int128_t stix_uint128_t; - typedef signed __int128_t stix_int128_t; - #endif -#else - /* no 128-bit integer */ -#endif - -#if defined(STIX_HAVE_UINT8_T) && (STIX_SIZEOF_VOID_P == 1) -# error UNSUPPORTED POINTER SIZE -#elif defined(STIX_HAVE_UINT16_T) && (STIX_SIZEOF_VOID_P == 2) - typedef stix_uint16_t stix_uintptr_t; - typedef stix_int16_t stix_intptr_t; - typedef stix_uint8_t stix_ushortptr_t; - typedef stix_int8_t stix_shortptr_t; -#elif defined(STIX_HAVE_UINT32_T) && (STIX_SIZEOF_VOID_P == 4) - typedef stix_uint32_t stix_uintptr_t; - typedef stix_int32_t stix_intptr_t; - typedef stix_uint16_t stix_ushortptr_t; - typedef stix_int16_t stix_shortptr_t; -#elif defined(STIX_HAVE_UINT64_T) && (STIX_SIZEOF_VOID_P == 8) - typedef stix_uint64_t stix_uintptr_t; - typedef stix_int64_t stix_intptr_t; - typedef stix_uint32_t stix_ushortptr_t; - typedef stix_int32_t stix_shortptr_t; -#elif defined(STIX_HAVE_UINT128_T) && (STIX_SIZEOF_VOID_P == 16) - typedef stix_uint128_t stix_uintptr_t; - typedef stix_int128_t stix_intptr_t; - typedef stix_uint64_t stix_ushortptr_t; - typedef stix_int64_t stix_shortptr_t; -#else -# error UNKNOWN POINTER SIZE -#endif - -#define STIX_SIZEOF_INTPTR_T STIX_SIZEOF_VOID_P -#define STIX_SIZEOF_UINTPTR_T STIX_SIZEOF_VOID_P -#define STIX_SIZEOF_SHORTPTR_T (STIX_SIZEOF_VOID_P / 2) -#define STIX_SIZEOF_USHORTPTR_T (STIX_SIZEOF_VOID_P / 2) - -#if defined(STIX_HAVE_INT128_T) -# define STIX_SIZEOF_INTMAX_T 16 -# define STIX_SIZEOF_UINTMAX_T 16 - typedef stix_int128_t stix_intmax_t; - typedef stix_uint128_t stix_uintmax_t; -#elif defined(STIX_HAVE_INT64_T) -# define STIX_SIZEOF_INTMAX_T 8 -# define STIX_SIZEOF_UINTMAX_T 8 - typedef stix_int64_t stix_intmax_t; - typedef stix_uint64_t stix_uintmax_t; -#elif defined(STIX_HAVE_INT32_T) -# define STIX_SIZEOF_INTMAX_T 4 -# define STIX_SIZEOF_UINTMAX_T 4 - typedef stix_int32_t stix_intmax_t; - typedef stix_uint32_t stix_uintmax_t; -#elif defined(STIX_HAVE_INT16_T) -# define STIX_SIZEOF_INTMAX_T 2 -# define STIX_SIZEOF_UINTMAX_T 2 - typedef stix_int16_t stix_intmax_t; - typedef stix_uint16_t stix_uintmax_t; -#elif defined(STIX_HAVE_INT8_T) -# define STIX_SIZEOF_INTMAX_T 1 -# define STIX_SIZEOF_UINTMAX_T 1 - typedef stix_int8_t stix_intmax_t; - typedef stix_uint8_t stix_uintmax_t; -#else -# error UNKNOWN INTMAX SIZE -#endif - -/* ========================================================================= - * BASIC STIX TYPES - * =========================================================================*/ - -typedef char stix_bch_t; -typedef int stix_bci_t; - -typedef stix_uint16_t stix_uch_t; /* TODO ... wchar_t??? */ -typedef stix_int32_t stix_uci_t; - -typedef stix_uint8_t stix_oob_t; - -/* NOTE: sizeof(stix_oop_t) must be equal to sizeof(stix_oow_t) */ -typedef stix_uintptr_t stix_oow_t; -typedef stix_intptr_t stix_ooi_t; -#define STIX_SIZEOF_OOW_T STIX_SIZEOF_UINTPTR_T -#define STIX_SIZEOF_OOI_T STIX_SIZEOF_INTPTR_T - -typedef stix_ushortptr_t stix_oohw_t; /* half word - half word */ -typedef stix_shortptr_t stix_oohi_t; /* signed half word */ -#define STIX_SIZEOF_OOHW_T STIX_SIZEOF_USHORTPTR_T -#define STIX_SIZEOF_OOHI_T STIX_SIZEOF_SHORTPTR_T - -struct stix_ucs_t -{ - stix_uch_t* ptr; - stix_oow_t len; -}; -typedef struct stix_ucs_t stix_ucs_t; - -struct stix_bcs_t -{ - stix_bch_t* ptr; - stix_oow_t len; -}; -typedef struct stix_bcs_t stix_bcs_t; - -typedef stix_uch_t stix_ooch_t; -typedef stix_uci_t stix_ooci_t; -typedef stix_ucs_t stix_oocs_t; -#define STIX_OOCH_IS_UCH - - - -/* ========================================================================= - * TIME-RELATED TYPES - * =========================================================================*/ -#define STIX_MSECS_PER_SEC (1000) -#define STIX_MSECS_PER_MIN (STIX_MSECS_PER_SEC * STIX_SECS_PER_MIN) -#define STIX_MSECS_PER_HOUR (STIX_MSECS_PER_SEC * STIX_SECS_PER_HOUR) -#define STIX_MSECS_PER_DAY (STIX_MSECS_PER_SEC * STIX_SECS_PER_DAY) - -#define STIX_USECS_PER_MSEC (1000) -#define STIX_NSECS_PER_USEC (1000) -#define STIX_NSECS_PER_MSEC (STIX_NSECS_PER_USEC * STIX_USECS_PER_MSEC) -#define STIX_USECS_PER_SEC (STIX_USECS_PER_MSEC * STIX_MSECS_PER_SEC) -#define STIX_NSECS_PER_SEC (STIX_NSECS_PER_USEC * STIX_USECS_PER_MSEC * STIX_MSECS_PER_SEC) - -#define STIX_SECNSEC_TO_MSEC(sec,nsec) \ - (((stix_intptr_t)(sec) * STIX_MSECS_PER_SEC) + ((stix_intptr_t)(nsec) / STIX_NSECS_PER_MSEC)) - -#define STIX_SECNSEC_TO_USEC(sec,nsec) \ - (((stix_intptr_t)(sec) * STIX_USECS_PER_SEC) + ((stix_intptr_t)(nsec) / STIX_NSECS_PER_USEC)) - -#define STIX_SECNSEC_TO_NSEC(sec,nsec) \ - (((stix_intptr_t)(sec) * STIX_NSECS_PER_SEC) + (stix_intptr_t)(nsec)) - -#define STIX_SEC_TO_MSEC(sec) ((sec) * STIX_MSECS_PER_SEC) -#define STIX_MSEC_TO_SEC(sec) ((sec) / STIX_MSECS_PER_SEC) - -#define STIX_USEC_TO_NSEC(usec) ((usec) * STIX_NSECS_PER_USEC) -#define STIX_NSEC_TO_USEC(nsec) ((nsec) / STIX_NSECS_PER_USEC) - -#define STIX_MSEC_TO_NSEC(msec) ((msec) * STIX_NSECS_PER_MSEC) -#define STIX_NSEC_TO_MSEC(nsec) ((nsec) / STIX_NSECS_PER_MSEC) - -#define STIX_SEC_TO_NSEC(sec) ((sec) * STIX_NSECS_PER_SEC) -#define STIX_NSEC_TO_SEC(nsec) ((nsec) / STIX_NSECS_PER_SEC) - -#define STIX_SEC_TO_USEC(sec) ((sec) * STIX_USECS_PER_SEC) -#define STIX_USEC_TO_SEC(usec) ((usec) / STIX_USECS_PER_SEC) - -typedef struct stix_ntime_t stix_ntime_t; -struct stix_ntime_t -{ - stix_intptr_t sec; - stix_int32_t nsec; /* nanoseconds */ -}; - -#define STIX_INITNTIME(c,s,ns) (((c)->sec = (s)), ((c)->nsec = (ns))) -#define STIX_CLEARNTIME(c) STIX_INITNTIME(c, 0, 0) - -#define STIX_ADDNTIME(c,a,b) \ - do { \ - (c)->sec = (a)->sec + (b)->sec; \ - (c)->nsec = (a)->nsec + (b)->nsec; \ - while ((c)->nsec >= STIX_NSECS_PER_SEC) { (c)->sec++; (c)->nsec -= STIX_NSECS_PER_SEC; } \ - } while(0) - -#define STIX_ADDNTIMESNS(c,a,s,ns) \ - do { \ - (c)->sec = (a)->sec + (s); \ - (c)->nsec = (a)->nsec + (ns); \ - while ((c)->nsec >= STIX_NSECS_PER_SEC) { (c)->sec++; (c)->nsec -= STIX_NSECS_PER_SEC; } \ - } while(0) - -#define STIX_SUBNTIME(c,a,b) \ - do { \ - (c)->sec = (a)->sec - (b)->sec; \ - (c)->nsec = (a)->nsec - (b)->nsec; \ - while ((c)->nsec < 0) { (c)->sec--; (c)->nsec += STIX_NSECS_PER_SEC; } \ - } while(0) - -#define STIX_SUBNTIMESNS(c,a,s,ns) \ - do { \ - (c)->sec = (a)->sec - s; \ - (c)->nsec = (a)->nsec - ns; \ - while ((c)->nsec < 0) { (c)->sec--; (c)->nsec += STIX_NSECS_PER_SEC; } \ - } while(0) - - -#define STIX_CMPNTIME(a,b) (((a)->sec == (b)->sec)? ((a)->nsec - (b)->nsec): ((a)->sec - (b)->sec)) - -/* ========================================================================= - * PRIMITIVE MACROS - * ========================================================================= */ -#define STIX_UCI_EOF ((stix_ooci_t)-1) - -#define STIX_SIZEOF(x) (sizeof(x)) -#define STIX_COUNTOF(x) (sizeof(x) / sizeof(x[0])) - -/** - * The STIX_OFFSETOF() macro returns the offset of a field from the beginning - * of a structure. - */ -#define STIX_OFFSETOF(type,member) ((stix_uintptr_t)&((type*)0)->member) - -/** - * The STIX_ALIGNOF() macro returns the alignment size of a structure. - * Note that this macro may not work reliably depending on the type given. - */ -#define STIX_ALIGNOF(type) STIX_OFFSETOF(struct { stix_uint8_t d1; type d2; }, d2) - /*(sizeof(struct { stix_uint8_t d1; type d2; }) - sizeof(type))*/ - -#if defined(__cplusplus) -# if (__cplusplus >= 201103L) /* C++11 */ -# define STIX_NULL nullptr -# else -# define STIX_NULL (0) -# endif -#else -# define STIX_NULL ((void*)0) -#endif - -/* make a bit mask that can mask off low n bits */ -#define STIX_LBMASK(type,n) (~(~((type)0) << (n))) -#define STIX_LBMASK_SAFE(type,n) (((n) < STIX_SIZEOF(type) * 8)? STIX_LBMASK(type,n): ~(type)0) - -/* make a bit mask that can mask off hig n bits */ -#define STIX_HBMASK(type,n) (~(~((type)0) >> (n))) -#define STIX_HBMASK_SAFE(type,n) (((n) < STIX_SIZEOF(type) * 8)? STIX_HBMASK(type,n): ~(type)0) - -/* get 'length' bits starting from the bit at the 'offset' */ -#define STIX_GETBITS(type,value,offset,length) \ - ((((type)(value)) >> (offset)) & STIX_LBMASK(type,length)) - -#define STIX_CLEARBITS(type,value,offset,length) \ - (((type)(value)) & ~(STIX_LBMASK(type,length) << (offset))) - -#define STIX_SETBITS(type,value,offset,length,bits) \ - (value = (STIX_CLEARBITS(type,value,offset,length) | (((bits) & STIX_LBMASK(type,length)) << (offset)))) - -#define STIX_FLIPBITS(type,value,offset,length) \ - (((type)(value)) ^ (STIX_LBMASK(type,length) << (offset))) - -#define STIX_ORBITS(type,value,offset,length,bits) \ - (value = (((type)(value)) | (((bits) & STIX_LBMASK(type,length)) << (offset)))) - - -/** - * The STIX_BITS_MAX() macros calculates the maximum value that the 'nbits' - * bits of an unsigned integer of the given 'type' can hold. - * \code - * printf ("%u", STIX_BITS_MAX(unsigned int, 5)); - * \endcode - */ -/*#define STIX_BITS_MAX(type,nbits) ((((type)1) << (nbits)) - 1)*/ -#define STIX_BITS_MAX(type,nbits) ((~(type)0) >> (STIX_SIZEOF(type) * 8 - (nbits))) - -/* ========================================================================= - * MMGR - * ========================================================================= */ -typedef struct stix_mmgr_t stix_mmgr_t; - -/** - * allocate a memory chunk of the size \a n. - * \return pointer to a memory chunk on success, #STIX_NULL on failure. - */ -typedef void* (*stix_mmgr_alloc_t) (stix_mmgr_t* mmgr, stix_oow_t n); -/** - * resize a memory chunk pointed to by \a ptr to the size \a n. - * \return pointer to a memory chunk on success, #STIX_NULL on failure. - */ -typedef void* (*stix_mmgr_realloc_t) (stix_mmgr_t* mmgr, void* ptr, stix_oow_t n); -/** - * free a memory chunk pointed to by \a ptr. - */ -typedef void (*stix_mmgr_free_t) (stix_mmgr_t* mmgr, void* ptr); - -/** - * The stix_mmgr_t type defines the memory management interface. - * As the type is merely a structure, it is just used as a single container - * for memory management functions with a pointer to user-defined data. - * The user-defined data pointer \a ctx is passed to each memory management - * function whenever it is called. You can allocate, reallocate, and free - * a memory chunk. - * - * For example, a stix_xxx_open() function accepts a pointer of the stix_mmgr_t - * type and the xxx object uses it to manage dynamic data within the object. - */ -struct stix_mmgr_t -{ - stix_mmgr_alloc_t alloc; /**< allocation function */ - stix_mmgr_realloc_t realloc; /**< resizing function */ - stix_mmgr_free_t free; /**< disposal function */ - void* ctx; /**< user-defined data pointer */ -}; - -/** - * The STIX_MMGR_ALLOC() macro allocates a memory block of the \a size bytes - * using the \a mmgr memory manager. - */ -#define STIX_MMGR_ALLOC(mmgr,size) ((mmgr)->alloc(mmgr,size)) - -/** - * The STIX_MMGR_REALLOC() macro resizes a memory block pointed to by \a ptr - * to the \a size bytes using the \a mmgr memory manager. - */ -#define STIX_MMGR_REALLOC(mmgr,ptr,size) ((mmgr)->realloc(mmgr,ptr,size)) - -/** - * The STIX_MMGR_FREE() macro deallocates the memory block pointed to by \a ptr. - */ -#define STIX_MMGR_FREE(mmgr,ptr) ((mmgr)->free(mmgr,ptr)) - - -/* ========================================================================= - * CMGR - * =========================================================================*/ - -typedef struct stix_cmgr_t stix_cmgr_t; - -typedef stix_oow_t (*stix_cmgr_bctouc_t) ( - const stix_bch_t* mb, - stix_oow_t size, - stix_uch_t* wc -); - -typedef stix_oow_t (*stix_cmgr_uctobc_t) ( - stix_uch_t wc, - stix_bch_t* mb, - stix_oow_t size -); - -/** - * The stix_cmgr_t type defines the character-level interface to - * multibyte/wide-character conversion. This interface doesn't - * provide any facility to store conversion state in a context - * independent manner. This leads to the limitation that it can - * handle a stateless multibyte encoding only. - */ -struct stix_cmgr_t -{ - stix_cmgr_bctouc_t bctouc; - stix_cmgr_uctobc_t uctobc; -}; - -/* ========================================================================= - * FORWARD DECLARATION FOR MAIN STIX STRUCTURE - * =========================================================================*/ -typedef struct stix_t stix_t; - -/* ========================================================================= - * MACROS THAT CHANGES THE BEHAVIORS OF THE C COMPILER/LINKER - * =========================================================================*/ - -#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500) -# define STIX_IMPORT -# define STIX_EXPORT -# define STIX_PRIVATE -#elif defined(_WIN32) || (defined(__WATCOMC__) && !defined(__WINDOWS_386__)) -# define STIX_IMPORT __declspec(dllimport) -# define STIX_EXPORT __declspec(dllexport) -# define STIX_PRIVATE -#elif defined(__GNUC__) && (__GNUC__>=4) -# define STIX_IMPORT __attribute__((visibility("default"))) -# define STIX_EXPORT __attribute__((visibility("default"))) -# define STIX_PRIVATE __attribute__((visibility("hidden"))) -/*# define STIX_PRIVATE __attribute__((visibility("internal")))*/ -#else -# define STIX_IMPORT -# define STIX_EXPORT -# define STIX_PRIVATE -#endif - -#if defined(__STDC_VERSION__) && (__STDC_VERSION__>=199901L) - /* C99 has inline */ -# define STIX_INLINE inline -# define STIX_HAVE_INLINE -#elif defined(__GNUC__) && defined(__GNUC_GNU_INLINE__) - /* gcc disables inline when -std=c89 or -ansi is used. - * so use __inline__ supported by gcc regardless of the options */ -# define STIX_INLINE /*extern*/ __inline__ -# define STIX_HAVE_INLINE -#else -# define STIX_INLINE -# undef STIX_HAVE_INLINE -#endif - -/** - * The STIX_TYPE_IS_SIGNED() macro determines if a type is signed. - * \code - * printf ("%d\n", (int)STIX_TYPE_IS_SIGNED(int)); - * printf ("%d\n", (int)STIX_TYPE_IS_SIGNED(unsigned int)); - * \endcode - */ -#define STIX_TYPE_IS_SIGNED(type) (((type)0) > ((type)-1)) - -/** - * The STIX_TYPE_IS_SIGNED() macro determines if a type is unsigned. - * \code - * printf ("%d\n", STIX_TYPE_IS_UNSIGNED(int)); - * printf ("%d\n", STIX_TYPE_IS_UNSIGNED(unsigned int)); - * \endcode - */ -#define STIX_TYPE_IS_UNSIGNED(type) (((type)0) < ((type)-1)) - -#define STIX_TYPE_SIGNED_MAX(type) \ - ((type)~((type)1 << ((type)STIX_SIZEOF(type) * 8 - 1))) -#define STIX_TYPE_UNSIGNED_MAX(type) ((type)(~(type)0)) - -#define STIX_TYPE_SIGNED_MIN(type) \ - ((type)((type)1 << ((type)STIX_SIZEOF(type) * 8 - 1))) -#define STIX_TYPE_UNSIGNED_MIN(type) ((type)0) - -#define STIX_TYPE_MAX(type) \ - ((STIX_TYPE_IS_SIGNED(type)? STIX_TYPE_SIGNED_MAX(type): STIX_TYPE_UNSIGNED_MAX(type))) -#define STIX_TYPE_MIN(type) \ - ((STIX_TYPE_IS_SIGNED(type)? STIX_TYPE_SIGNED_MIN(type): STIX_TYPE_UNSIGNED_MIN(type))) - - -/* ========================================================================= - * COMPILER FEATURE TEST MACROS - * =========================================================================*/ -#if !defined(__has_builtin) && defined(_INTELC32_) - /* intel c code builder 1.0 ended up with an error without this override */ - #define __has_builtin(x) 0 -#endif - -/* -#if !defined(__is_identifier) - #define __is_identifier(x) 0 -#endif - -#if !defined(__has_attribute) - #define __has_attribute(x) 0 -#endif -*/ - - -#if defined(__has_builtin) - #if __has_builtin(__builtin_ctz) - #define STIX_HAVE_BUILTIN_CTZ - #endif - - #if __has_builtin(__builtin_uadd_overflow) - #define STIX_HAVE_BUILTIN_UADD_OVERFLOW - #endif - #if __has_builtin(__builtin_uaddl_overflow) - #define STIX_HAVE_BUILTIN_UADDL_OVERFLOW - #endif - #if __has_builtin(__builtin_uaddll_overflow) - #define STIX_HAVE_BUILTIN_UADDLL_OVERFLOW - #endif - #if __has_builtin(__builtin_umul_overflow) - #define STIX_HAVE_BUILTIN_UMUL_OVERFLOW - #endif - #if __has_builtin(__builtin_umull_overflow) - #define STIX_HAVE_BUILTIN_UMULL_OVERFLOW - #endif - #if __has_builtin(__builtin_umulll_overflow) - #define STIX_HAVE_BUILTIN_UMULLL_OVERFLOW - #endif - - #if __has_builtin(__builtin_sadd_overflow) - #define STIX_HAVE_BUILTIN_SADD_OVERFLOW - #endif - #if __has_builtin(__builtin_saddl_overflow) - #define STIX_HAVE_BUILTIN_SADDL_OVERFLOW - #endif - #if __has_builtin(__builtin_saddll_overflow) - #define STIX_HAVE_BUILTIN_SADDLL_OVERFLOW - #endif - #if __has_builtin(__builtin_smul_overflow) - #define STIX_HAVE_BUILTIN_SMUL_OVERFLOW - #endif - #if __has_builtin(__builtin_smull_overflow) - #define STIX_HAVE_BUILTIN_SMULL_OVERFLOW - #endif - #if __has_builtin(__builtin_smulll_overflow) - #define STIX_HAVE_BUILTIN_SMULLL_OVERFLOW - #endif - - #if __has_builtin(__builtin_expect) - #define STIX_HAVE_BUILTIN_EXPECT - #endif -#elif defined(__GNUC__) && defined(__GNUC_MINOR__) - - #if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) - #define STIX_HAVE_BUILTIN_CTZ - #define STIX_HAVE_BUILTIN_EXPECT - #endif - - #if (__GNUC__ >= 5) - #define STIX_HAVE_BUILTIN_UADD_OVERFLOW - #define STIX_HAVE_BUILTIN_UADDL_OVERFLOW - #define STIX_HAVE_BUILTIN_UADDLL_OVERFLOW - #define STIX_HAVE_BUILTIN_UMUL_OVERFLOW - #define STIX_HAVE_BUILTIN_UMULL_OVERFLOW - #define STIX_HAVE_BUILTIN_UMULLL_OVERFLOW - - #define STIX_HAVE_BUILTIN_SADD_OVERFLOW - #define STIX_HAVE_BUILTIN_SADDL_OVERFLOW - #define STIX_HAVE_BUILTIN_SADDLL_OVERFLOW - #define STIX_HAVE_BUILTIN_SMUL_OVERFLOW - #define STIX_HAVE_BUILTIN_SMULL_OVERFLOW - #define STIX_HAVE_BUILTIN_SMULLL_OVERFLOW - #endif - -#endif - -#if defined(STIX_HAVE_BUILTIN_EXPECT) -# define STIX_LIKELY(x) (__builtin_expect(!!x,1)) -# define STIX_UNLIKELY(x) (__builtin_expect(!!x,0)) -#else -# define STIX_LIKELY(x) (x) -# define STIX_UNLIKELY(x) (x) -#endif - -#endif diff --git a/stix/lib/stix-dos.h b/stix/lib/stix-dos.h deleted file mode 100644 index 626f377..0000000 --- a/stix/lib/stix-dos.h +++ /dev/null @@ -1,167 +0,0 @@ -/* - * $Id$ - * - Copyright (c) 2014-2016 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. - */ -/* DOS for other platforms than x86? - * If so, the endian should be defined selectively - */ -#define STIX_ENDIAN_LITTLE - -#if defined(__WATCOMC__) && defined(__386__) -# define STIX_SIZEOF_CHAR 1 -# define STIX_SIZEOF_SHORT 2 -# define STIX_SIZEOF_INT 4 -# define STIX_SIZEOF_LONG 4 -# if (__WATCOMC__ < 1200) -# define STIX_SIZEOF_LONG_LONG 0 -# else -# define STIX_SIZEOF_LONG_LONG 8 -# endif -# define STIX_SIZEOF_VOID_P 4 -# define STIX_SIZEOF_FLOAT 4 -# define STIX_SIZEOF_DOUBLE 8 -# define STIX_SIZEOF_LONG_DOUBLE 8 -# define STIX_SIZEOF_WCHAR_T 2 - -# define STIX_SIZEOF___INT8 1 -# define STIX_SIZEOF___INT16 2 -# define STIX_SIZEOF___INT32 4 -# define STIX_SIZEOF___INT64 8 -# define STIX_SIZEOF___INT128 0 - -# define STIX_SIZEOF_OFF64_T 0 -# define STIX_SIZEOF_OFF_T 4 - -# define STIX_SIZEOF_MBSTATE_T STIX_SIZEOF_LONG -# define STIX_MBLEN_MAX 8 - -#elif defined(__WATCOMC__) && !defined(__386__) -# define STIX_SIZEOF_CHAR 1 -# define STIX_SIZEOF_SHORT 2 -# define STIX_SIZEOF_INT 2 -# define STIX_SIZEOF_LONG 4 -# define STIX_SIZEOF_LONG_LONG 8 - -# define STIX_SIZEOF_VOID_P 4 -# define STIX_SIZEOF_FLOAT 4 -# define STIX_SIZEOF_DOUBLE 8 -# define STIX_SIZEOF_LONG_DOUBLE 8 -# define STIX_SIZEOF_WCHAR_T 2 - -# define STIX_SIZEOF___INT8 1 -# define STIX_SIZEOF___INT16 2 -# define STIX_SIZEOF___INT32 4 -# define STIX_SIZEOF___INT64 8 -# define STIX_SIZEOF___INT128 0 - -# define STIX_SIZEOF_OFF64_T 0 -# define STIX_SIZEOF_OFF_T 4 - -# define STIX_SIZEOF_MBSTATE_T STIX_SIZEOF_LONG -# define STIX_MBLEN_MAX 8 - -#elif defined(__TURBOC__) -/* TODO: be more version specific wchar_t may be available in newer BCC */ -# define STIX_SIZEOF_CHAR 1 -# define STIX_SIZEOF_SHORT 2 -# define STIX_SIZEOF_INT 2 -# define STIX_SIZEOF_LONG 4 -# define STIX_SIZEOF_LONG_LONG 0 - -# define STIX_SIZEOF_VOID_P 4 -# define STIX_SIZEOF_FLOAT 4 -# define STIX_SIZEOF_DOUBLE 8 -# define STIX_SIZEOF_LONG_DOUBLE 10 -# define STIX_SIZEOF_WCHAR_T 0 - -# define STIX_SIZEOF___INT8 0 -# define STIX_SIZEOF___INT16 0 -# define STIX_SIZEOF___INT32 0 -# define STIX_SIZEOF___INT64 0 -# define STIX_SIZEOF___INT128 0 - -# define STIX_SIZEOF_OFF64_T 0 -# define STIX_SIZEOF_OFF_T 4 - -# define STIX_SIZEOF_MBSTATE_T STIX_SIZEOF_LONG -# define STIX_MBLEN_MAX 8 - -#elif defined(__ZTC__) && defined(DOS386) - - /* Zortech in DOSX 386 mode (ztc -mx) */ -# define STIX_SIZEOF_CHAR 1 -# define STIX_SIZEOF_SHORT 2 -# define STIX_SIZEOF_INT 4 -# define STIX_SIZEOF_LONG 4 -# define STIX_SIZEOF_LONG_LONG 0 - -# define STIX_SIZEOF_VOID_P 4 -# define STIX_SIZEOF_FLOAT 4 -# define STIX_SIZEOF_DOUBLE 8 -# define STIX_SIZEOF_LONG_DOUBLE 8 -# define STIX_SIZEOF_WCHAR_T 1 - -# define STIX_SIZEOF___INT8 0 -# define STIX_SIZEOF___INT16 0 -# define STIX_SIZEOF___INT32 0 -# define STIX_SIZEOF___INT64 0 -# define STIX_SIZEOF___INT128 0 - -# define STIX_SIZEOF_OFF64_T 0 -# define STIX_SIZEOF_OFF_T 4 - -# define STIX_SIZEOF_MBSTATE_T STIX_SIZEOF_LONG -# define STIX_MBLEN_MAX 8 - -#elif defined(_INTELC32_) - - /* Intel C Code Builder 1.0 */ -# define STIX_SIZEOF_CHAR 1 -# define STIX_SIZEOF_SHORT 2 -# define STIX_SIZEOF_INT 4 -# define STIX_SIZEOF_LONG 4 -# define STIX_SIZEOF_LONG_LONG 0 - -# define STIX_SIZEOF_VOID_P 4 -# define STIX_SIZEOF_FLOAT 4 -# define STIX_SIZEOF_DOUBLE 8 -# define STIX_SIZEOF_LONG_DOUBLE 8 -# define STIX_SIZEOF_WCHAR_T 1 - -# define STIX_SIZEOF___INT8 0 -# define STIX_SIZEOF___INT16 0 -# define STIX_SIZEOF___INT32 0 -# define STIX_SIZEOF___INT64 0 -# define STIX_SIZEOF___INT128 0 - -# define STIX_SIZEOF_OFF64_T 0 -# define STIX_SIZEOF_OFF_T 4 - -# define STIX_SIZEOF_MBSTATE_T STIX_SIZEOF_LONG -# define STIX_MBLEN_MAX 8 - -#else -# error Define the size of various data types. -#endif - diff --git a/stix/lib/stix-msw.h b/stix/lib/stix-msw.h deleted file mode 100644 index 7c5b86f..0000000 --- a/stix/lib/stix-msw.h +++ /dev/null @@ -1,174 +0,0 @@ -/* - * $Id$ - * - Copyright (c) 2014-2016 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. - */ - -/* -Macro Meaning -_WIN64 A 64-bit platform. -_WIN32 A 32-bit platform. This value is also defined by the 64-bit - compiler for backward compatibility. -_WIN16 A 16-bit platform - -The following macros are specific to the architecture. - -Macro Meaning -_M_IA64 Intel Itanium Processor Family -_M_IX86 x86 platform -_M_X64 x64 platform -*/ - -/* windows for most of non-x86 platforms dropped. - * make it selective to support old non-x86 windows platforms. */ -#define STIX_ENDIAN_LITTLE - -#if defined(__WATCOMC__) -# define STIX_SIZEOF_CHAR 1 -# define STIX_SIZEOF_SHORT 2 -# define STIX_SIZEOF_INT 4 -# define STIX_SIZEOF_LONG 4 -# if (__WATCOMC__ < 1200) -# define STIX_SIZEOF_LONG_LONG 0 -# else -# define STIX_SIZEOF_LONG_LONG 8 -# endif - -# if defined(_WIN64) -# define STIX_SIZEOF_VOID_P 8 -# else -# define STIX_SIZEOF_VOID_P 4 -# endif -# define STIX_SIZEOF_FLOAT 4 -# define STIX_SIZEOF_DOUBLE 8 -# define STIX_SIZEOF_LONG_DOUBLE 8 -# define STIX_SIZEOF_WCHAR_T 2 - -# define STIX_SIZEOF___INT8 1 -# define STIX_SIZEOF___INT16 2 -# define STIX_SIZEOF___INT32 4 -# define STIX_SIZEOF___INT64 8 -# define STIX_SIZEOF___INT128 0 - -# define STIX_SIZEOF_OFF64_T 0 -# define STIX_SIZEOF_OFF_T 8 - -# define STIX_SIZEOF_MBSTATE_T STIX_SIZEOF_LONG -# define STIX_MBLEN_MAX 16 - -#elif defined(__GNUC__) || defined(__DMC__) || defined(__POCC__) -# define STIX_SIZEOF_CHAR 1 -# define STIX_SIZEOF_SHORT 2 -# define STIX_SIZEOF_INT 4 -# define STIX_SIZEOF_LONG 4 -# define STIX_SIZEOF_LONG_LONG 8 - -# if defined(_WIN64) -# define STIX_SIZEOF_VOID_P 8 -# else -# define STIX_SIZEOF_VOID_P 4 -# endif -# define STIX_SIZEOF_FLOAT 4 -# define STIX_SIZEOF_DOUBLE 8 -# define STIX_SIZEOF_LONG_DOUBLE 16 -# define STIX_SIZEOF_WCHAR_T 2 - -# define STIX_SIZEOF___INT8 0 -# define STIX_SIZEOF___INT16 0 -# define STIX_SIZEOF___INT32 0 -# define STIX_SIZEOF___INT64 0 -# define STIX_SIZEOF___INT128 0 - -# define STIX_SIZEOF_OFF64_T 0 -# define STIX_SIZEOF_OFF_T 8 - -# define STIX_SIZEOF_MBSTATE_T STIX_SIZEOF_LONG -# define STIX_MBLEN_MAX 16 - -#elif defined(_MSC_VER) -# define STIX_SIZEOF_CHAR 1 -# define STIX_SIZEOF_SHORT 2 -# define STIX_SIZEOF_INT 4 -# define STIX_SIZEOF_LONG 4 -# if (_MSC_VER>=1310) -# define STIX_SIZEOF_LONG_LONG 8 -# else -# define STIX_SIZEOF_LONG_LONG 0 -# endif - -# if defined(_WIN64) -# define STIX_SIZEOF_VOID_P 8 -# else -# define STIX_SIZEOF_VOID_P 4 -# endif -# define STIX_SIZEOF_FLOAT 4 -# define STIX_SIZEOF_DOUBLE 8 -# define STIX_SIZEOF_LONG_DOUBLE 8 -# define STIX_SIZEOF_WCHAR_T 2 - -# define STIX_SIZEOF___INT8 1 -# define STIX_SIZEOF___INT16 2 -# define STIX_SIZEOF___INT32 4 -# define STIX_SIZEOF___INT64 8 -# define STIX_SIZEOF___INT128 0 - -# define STIX_SIZEOF_OFF64_T 0 -# define STIX_SIZEOF_OFF_T 8 - -# define STIX_SIZEOF_MBSTATE_T STIX_SIZEOF_LONG -# define STIX_MBLEN_MAX 8 - -#elif defined(__BORLANDC__) - -# define STIX_SIZEOF_CHAR 1 -# define STIX_SIZEOF_SHORT 2 -# define STIX_SIZEOF_INT 4 -# define STIX_SIZEOF_LONG 4 -# define STIX_SIZEOF_LONG_LONG 0 - -# if defined(_WIN64) -# define STIX_SIZEOF_VOID_P 8 -# else -# define STIX_SIZEOF_VOID_P 4 -# endif -# define STIX_SIZEOF_FLOAT 4 -# define STIX_SIZEOF_DOUBLE 8 -# define STIX_SIZEOF_LONG_DOUBLE 8 -# define STIX_SIZEOF_WCHAR_T 2 - -# define STIX_SIZEOF___INT8 1 -# define STIX_SIZEOF___INT16 2 -# define STIX_SIZEOF___INT32 4 -# define STIX_SIZEOF___INT64 8 -# define STIX_SIZEOF___INT128 0 - -# define STIX_SIZEOF_OFF64_T 0 -# define STIX_SIZEOF_OFF_T 8 - -# define STIX_SIZEOF_MBSTATE_T STIX_SIZEOF_LONG -# define STIX_MBLEN_MAX 8 - -#else -# error Define the size of various data types. -#endif - diff --git a/stix/lib/stix-rbt.h b/stix/lib/stix-rbt.h deleted file mode 100644 index 69fc209..0000000 --- a/stix/lib/stix-rbt.h +++ /dev/null @@ -1,603 +0,0 @@ -/* - * $Id$ - * - Copyright (c) 2014-2016 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_RBT_H_ -#define _STIX_RBT_H_ - -#include "stix-cmn.h" - -/**@file - * This file provides a red-black tree encapsulated in the #stix_rbt_t type that - * implements a self-balancing binary search tree.Its interface is very close - * to #stix_htb_t. - * - * This sample code adds a series of keys and values and print them - * in descending key order. - * @code - * #include - * #include - * #include - * - * static stix_rbt_walk_t walk (stix_rbt_t* rbt, stix_rbt_pair_t* pair, void* ctx) - * { - * stix_printf (STIX_T("key = %d, value = %d\n"), - * *(int*)STIX_RBT_KPTR(pair), *(int*)STIX_RBT_VPTR(pair)); - * return STIX_RBT_WALK_FORWARD; - * } - * - * int main () - * { - * stix_rbt_t* s1; - * int i; - * - * s1 = stix_rbt_open (STIX_MMGR_GETDFL(), 0, 1, 1); // error handling skipped - * stix_rbt_setstyle (s1, stix_getrbtstyle(STIX_RBT_STYLE_INLINE_COPIERS)); - * - * for (i = 0; i < 20; i++) - * { - * int x = i * 20; - * stix_rbt_insert (s1, &i, STIX_SIZEOF(i), &x, STIX_SIZEOF(x)); // eror handling skipped - * } - * - * stix_rbt_rwalk (s1, walk, STIX_NULL); - * - * stix_rbt_close (s1); - * return 0; - * } - * @endcode - */ - -typedef struct stix_rbt_t stix_rbt_t; -typedef struct stix_rbt_pair_t stix_rbt_pair_t; - -/** - * The stix_rbt_walk_t type defines values that the callback function can - * return to control stix_rbt_walk() and stix_rbt_rwalk(). - */ -enum stix_rbt_walk_t -{ - STIX_RBT_WALK_STOP = 0, - STIX_RBT_WALK_FORWARD = 1 -}; -typedef enum stix_rbt_walk_t stix_rbt_walk_t; - -/** - * The stix_rbt_id_t type defines IDs to indicate a key or a value in various - * functions - */ -enum stix_rbt_id_t -{ - STIX_RBT_KEY = 0, /**< indicate a key */ - STIX_RBT_VAL = 1 /**< indicate a value */ -}; -typedef enum stix_rbt_id_t stix_rbt_id_t; - -/** - * The stix_rbt_copier_t type defines a pair contruction callback. - */ -typedef void* (*stix_rbt_copier_t) ( - stix_rbt_t* rbt /* red-black tree */, - void* dptr /* pointer to a key or a value */, - stix_oow_t dlen /* length of a key or a value */ -); - -/** - * The stix_rbt_freeer_t defines a key/value destruction callback. - */ -typedef void (*stix_rbt_freeer_t) ( - stix_rbt_t* rbt, /**< red-black tree */ - void* dptr, /**< pointer to a key or a value */ - stix_oow_t dlen /**< length of a key or a value */ -); - -/** - * The stix_rbt_comper_t type defines a key comparator that is called when - * the rbt needs to compare keys. A red-black tree is created with a default - * comparator which performs bitwise comparison of two keys. - * The comparator should return 0 if the keys are the same, 1 if the first - * key is greater than the second key, -1 otherwise. - */ -typedef int (*stix_rbt_comper_t) ( - const stix_rbt_t* rbt, /**< red-black tree */ - const void* kptr1, /**< key pointer */ - stix_oow_t klen1, /**< key length */ - const void* kptr2, /**< key pointer */ - stix_oow_t klen2 /**< key length */ -); - -/** - * The stix_rbt_keeper_t type defines a value keeper that is called when - * a value is retained in the context that it should be destroyed because - * it is identical to a new value. Two values are identical if their - * pointers and lengths are equal. - */ -typedef void (*stix_rbt_keeper_t) ( - stix_rbt_t* rbt, /**< red-black tree */ - void* vptr, /**< value pointer */ - stix_oow_t vlen /**< value length */ -); - -/** - * The stix_rbt_walker_t defines a pair visitor. - */ -typedef stix_rbt_walk_t (*stix_rbt_walker_t) ( - stix_rbt_t* rbt, /**< red-black tree */ - stix_rbt_pair_t* pair, /**< pointer to a key/value pair */ - void* ctx /**< pointer to user-defined data */ -); - -/** - * The stix_rbt_cbserter_t type defines a callback function for stix_rbt_cbsert(). - * The stix_rbt_cbserter() function calls it to allocate a new pair for the - * key pointed to by @a kptr of the length @a klen and the callback context - * @a ctx. The second parameter @a pair is passed the pointer to the existing - * pair for the key or #STIX_NULL in case of no existing key. The callback - * must return a pointer to a new or a reallocated pair. When reallocating the - * existing pair, this callback must destroy the existing pair and return the - * newly reallocated pair. It must return #STIX_NULL for failure. - */ -typedef stix_rbt_pair_t* (*stix_rbt_cbserter_t) ( - stix_rbt_t* rbt, /**< red-black tree */ - stix_rbt_pair_t* pair, /**< pair pointer */ - void* kptr, /**< key pointer */ - stix_oow_t klen, /**< key length */ - void* ctx /**< callback context */ -); - -/** - * The stix_rbt_pair_t type defines red-black tree pair. A pair is composed - * of a key and a value. It maintains pointers to the beginning of a key and - * a value plus their length. The length is scaled down with the scale factor - * specified in an owning tree. Use macros defined in the - */ -struct stix_rbt_pair_t -{ - struct - { - void* ptr; - stix_oow_t len; - } key; - - struct - { - void* ptr; - stix_oow_t len; - } val; - - /* management information below */ - enum - { - STIX_RBT_RED, - STIX_RBT_BLACK - } color; - stix_rbt_pair_t* parent; - stix_rbt_pair_t* child[2]; /* left and right */ -}; - -typedef struct stix_rbt_style_t stix_rbt_style_t; - -/** - * The stix_rbt_style_t type defines callback function sets for key/value - * pair manipulation. - */ -struct stix_rbt_style_t -{ - stix_rbt_copier_t copier[2]; /**< key and value copier */ - stix_rbt_freeer_t freeer[2]; /**< key and value freeer */ - stix_rbt_comper_t comper; /**< key comparator */ - stix_rbt_keeper_t keeper; /**< value keeper */ -}; - -/** - * The stix_rbt_style_kind_t type defines the type of predefined - * callback set for pair manipulation. - */ -enum stix_rbt_style_kind_t -{ - /** store the key and the value pointer */ - STIX_RBT_STYLE_DEFAULT, - /** copy both key and value into the pair */ - STIX_RBT_STYLE_INLINE_COPIERS, - /** copy the key into the pair but store the value pointer */ - STIX_RBT_STYLE_INLINE_KEY_COPIER, - /** copy the value into the pair but store the key pointer */ - STIX_RBT_STYLE_INLINE_VALUE_COPIER -}; - -typedef enum stix_rbt_style_kind_t stix_rbt_style_kind_t; - -/** - * The stix_rbt_t type defines a red-black tree. - */ -struct stix_rbt_t -{ - stix_t* stix; - const stix_rbt_style_t* style; - stix_oob_t scale[2]; /**< length scale */ - stix_rbt_pair_t xnil; /**< internal nil node */ - stix_oow_t size; /**< number of pairs */ - stix_rbt_pair_t* root; /**< root pair */ -}; - -/** - * The STIX_RBT_COPIER_SIMPLE macros defines a copier that remembers the - * pointer and length of data in a pair. - */ -#define STIX_RBT_COPIER_SIMPLE ((stix_rbt_copier_t)1) - -/** - * The STIX_RBT_COPIER_INLINE macros defines a copier that copies data into - * a pair. - */ -#define STIX_RBT_COPIER_INLINE ((stix_rbt_copier_t)2) - -#define STIX_RBT_COPIER_DEFAULT (STIX_RBT_COPIER_SIMPLE) -#define STIX_RBT_FREEER_DEFAULT (STIX_NULL) -#define STIX_RBT_COMPER_DEFAULT (stix_rbt_dflcomp) -#define STIX_RBT_KEEPER_DEFAULT (STIX_NULL) - -/** - * The STIX_RBT_SIZE() macro returns the number of pairs in red-black tree. - */ -#define STIX_RBT_SIZE(m) ((const stix_oow_t)(m)->size) -#define STIX_RBT_KSCALE(m) ((const int)(m)->scale[STIX_RBT_KEY]) -#define STIX_RBT_VSCALE(m) ((const int)(m)->scale[STIX_RBT_VAL]) - -#define STIX_RBT_KPTL(p) (&(p)->key) -#define STIX_RBT_VPTL(p) (&(p)->val) - -#define STIX_RBT_KPTR(p) ((p)->key.ptr) -#define STIX_RBT_KLEN(p) ((p)->key.len) -#define STIX_RBT_VPTR(p) ((p)->val.ptr) -#define STIX_RBT_VLEN(p) ((p)->val.len) - -#define STIX_RBT_NEXT(p) ((p)->next) - -#if defined(__cplusplus) -extern "C" { -#endif - -/** - * The stix_getrbtstyle() functions returns a predefined callback set for - * pair manipulation. - */ -STIX_EXPORT const stix_rbt_style_t* stix_getrbtstyle ( - stix_rbt_style_kind_t kind -); - -/** - * The stix_rbt_open() function creates a red-black tree. - * @return stix_rbt_t pointer on success, STIX_NULL on failure. - */ -STIX_EXPORT stix_rbt_t* stix_rbt_open ( - stix_t* stix, - stix_oow_t xtnsize, /**< extension size in bytes */ - int kscale, /**< key scale */ - int vscale /**< value scale */ -); - -/** - * The stix_rbt_close() function destroys a red-black tree. - */ -STIX_EXPORT void stix_rbt_close ( - stix_rbt_t* rbt /**< red-black tree */ -); - -/** - * The stix_rbt_init() function initializes a red-black tree - */ -STIX_EXPORT int stix_rbt_init ( - stix_rbt_t* rbt, /**< red-black tree */ - stix_t* stix, - int kscale, /**< key scale */ - int vscale /**< value scale */ -); - -/** - * The stix_rbt_fini() funtion finalizes a red-black tree - */ -STIX_EXPORT void stix_rbt_fini ( - stix_rbt_t* rbt /**< red-black tree */ -); - -STIX_EXPORT void* stix_rbt_getxtn ( - stix_rbt_t* rbt -); - -/** - * The stix_rbt_getstyle() function gets manipulation callback function set. - */ -STIX_EXPORT const stix_rbt_style_t* stix_rbt_getstyle ( - const stix_rbt_t* rbt /**< red-black tree */ -); - -/** - * The stix_rbt_setstyle() function sets internal manipulation callback - * functions for data construction, destruction, comparison, etc. - * The callback structure pointed to by \a style must outlive the tree - * pointed to by \a htb as the tree doesn't copy the contents of the - * structure. - */ -STIX_EXPORT void stix_rbt_setstyle ( - stix_rbt_t* rbt, /**< red-black tree */ - const stix_rbt_style_t* style /**< callback function set */ -); - -/** - * The stix_rbt_getsize() function gets the number of pairs in red-black tree. - */ -STIX_EXPORT stix_oow_t stix_rbt_getsize ( - const stix_rbt_t* rbt /**< red-black tree */ -); - -/** - * The stix_rbt_search() function searches red-black tree to find a pair with a - * matching key. It returns the pointer to the pair found. If it fails - * to find one, it returns STIX_NULL. - * @return pointer to the pair with a maching key, - * or STIX_NULL if no match is found. - */ -STIX_EXPORT stix_rbt_pair_t* stix_rbt_search ( - const stix_rbt_t* rbt, /**< red-black tree */ - const void* kptr, /**< key pointer */ - stix_oow_t klen /**< the size of the key */ -); - -/** - * The stix_rbt_upsert() function searches red-black tree for the pair with a - * matching key. If one is found, it updates the pair. Otherwise, it inserts - * a new pair with the key and the value given. It returns the pointer to the - * pair updated or inserted. - * @return a pointer to the updated or inserted pair on success, - * STIX_NULL on failure. - */ -STIX_EXPORT stix_rbt_pair_t* stix_rbt_upsert ( - stix_rbt_t* rbt, /**< red-black tree */ - void* kptr, /**< key pointer */ - stix_oow_t klen, /**< key length */ - void* vptr, /**< value pointer */ - stix_oow_t vlen /**< value length */ -); - -/** - * The stix_rbt_ensert() function inserts a new pair with the key and the value - * given. If there exists a pair with the key given, the function returns - * the pair containing the key. - * @return pointer to a pair on success, STIX_NULL on failure. - */ -STIX_EXPORT stix_rbt_pair_t* stix_rbt_ensert ( - stix_rbt_t* rbt, /**< red-black tree */ - void* kptr, /**< key pointer */ - stix_oow_t klen, /**< key length */ - void* vptr, /**< value pointer */ - stix_oow_t vlen /**< value length */ -); - -/** - * The stix_rbt_insert() function inserts a new pair with the key and the value - * given. If there exists a pair with the key given, the function returns - * STIX_NULL without channging the value. - * @return pointer to the pair created on success, STIX_NULL on failure. - */ -STIX_EXPORT stix_rbt_pair_t* stix_rbt_insert ( - stix_rbt_t* rbt, /**< red-black tree */ - void* kptr, /**< key pointer */ - stix_oow_t klen, /**< key length */ - void* vptr, /**< value pointer */ - stix_oow_t vlen /**< value length */ -); - -/** - * The stix_rbt_update() function updates the value of an existing pair - * with a matching key. - * @return pointer to the pair on success, STIX_NULL on no matching pair - */ -STIX_EXPORT stix_rbt_pair_t* stix_rbt_update ( - stix_rbt_t* rbt, /**< red-black tree */ - void* kptr, /**< key pointer */ - stix_oow_t klen, /**< key length */ - void* vptr, /**< value pointer */ - stix_oow_t vlen /**< value length */ -); - -/** - * The stix_rbt_cbsert() function inserts a key/value pair by delegating pair - * allocation to a callback function. Depending on the callback function, - * it may behave like stix_rbt_insert(), stix_rbt_upsert(), stix_rbt_update(), - * stix_rbt_ensert(), or totally differently. The sample code below inserts - * a new pair if the key is not found and appends the new value to the - * existing value delimited by a comma if the key is found. - * - * @code - * stix_rbt_walk_t print_map_pair (stix_rbt_t* map, stix_rbt_pair_t* pair, void* ctx) - * { - * stix_printf (STIX_T("%.*s[%d] => %.*s[%d]\n"), - * (int)STIX_RBT_KLEN(pair), STIX_RBT_KPTR(pair), (int)STIX_RBT_KLEN(pair), - * (int)STIX_RBT_VLEN(pair), STIX_RBT_VPTR(pair), (int)STIX_RBT_VLEN(pair)); - * return STIX_RBT_WALK_FORWARD; - * } - * - * stix_rbt_pair_t* cbserter ( - * stix_rbt_t* rbt, stix_rbt_pair_t* pair, - * void* kptr, stix_oow_t klen, void* ctx) - * { - * stix_cstr_t* v = (stix_cstr_t*)ctx; - * if (pair == STIX_NULL) - * { - * // no existing key for the key - * return stix_rbt_allocpair (rbt, kptr, klen, v->ptr, v->len); - * } - * else - * { - * // a pair with the key exists. - * // in this sample, i will append the new value to the old value - * // separated by a comma - * stix_rbt_pair_t* new_pair; - * stix_char_t comma = STIX_T(','); - * stix_oob_t* vptr; - * - * // allocate a new pair, but without filling the actual value. - * // note vptr is given STIX_NULL for that purpose - * new_pair = stix_rbt_allocpair ( - * rbt, kptr, klen, STIX_NULL, pair->vlen + 1 + v->len); - * if (new_pair == STIX_NULL) return STIX_NULL; - * - * // fill in the value space - * vptr = new_pair->vptr; - * stix_memcpy (vptr, pair->vptr, pair->vlen*STIX_SIZEOF(stix_char_t)); - * vptr += pair->vlen*STIX_SIZEOF(stix_char_t); - * stix_memcpy (vptr, &comma, STIX_SIZEOF(stix_char_t)); - * vptr += STIX_SIZEOF(stix_char_t); - * stix_memcpy (vptr, v->ptr, v->len*STIX_SIZEOF(stix_char_t)); - * - * // this callback requires the old pair to be destroyed - * stix_rbt_freepair (rbt, pair); - * - * // return the new pair - * return new_pair; - * } - * } - * - * int main () - * { - * stix_rbt_t* s1; - * int i; - * stix_char_t* keys[] = { STIX_T("one"), STIX_T("two"), STIX_T("three") }; - * stix_char_t* vals[] = { STIX_T("1"), STIX_T("2"), STIX_T("3"), STIX_T("4"), STIX_T("5") }; - * - * s1 = stix_rbt_open ( - * STIX_MMGR_GETDFL(), 0, - * STIX_SIZEOF(stix_char_t), STIX_SIZEOF(stix_char_t) - * ); // note error check is skipped - * stix_rbt_setstyle (s1, &style1); - * - * for (i = 0; i < STIX_COUNTOF(vals); i++) - * { - * stix_cstr_t ctx; - * ctx.ptr = vals[i]; ctx.len = stix_strlen(vals[i]); - * stix_rbt_cbsert (s1, - * keys[i%STIX_COUNTOF(keys)], stix_strlen(keys[i%STIX_COUNTOF(keys)]), - * cbserter, &ctx - * ); // note error check is skipped - * } - * stix_rbt_walk (s1, print_map_pair, STIX_NULL); - * - * stix_rbt_close (s1); - * return 0; - * } - * @endcode - */ -STIX_EXPORT stix_rbt_pair_t* stix_rbt_cbsert ( - stix_rbt_t* rbt, /**< red-black tree */ - void* kptr, /**< key pointer */ - stix_oow_t klen, /**< key length */ - stix_rbt_cbserter_t cbserter, /**< callback function */ - void* ctx /**< callback context */ -); - -/** - * The stix_rbt_delete() function deletes a pair with a matching key - * @return 0 on success, -1 on failure - */ -STIX_EXPORT int stix_rbt_delete ( - stix_rbt_t* rbt, /**< red-black tree */ - const void* kptr, /**< key pointer */ - stix_oow_t klen /**< key size */ -); - -/** - * The stix_rbt_clear() function empties a red-black tree. - */ -STIX_EXPORT void stix_rbt_clear ( - stix_rbt_t* rbt /**< red-black tree */ -); - -/** - * The stix_rbt_walk() function traverses a red-black tree in preorder - * from the leftmost child. - */ -STIX_EXPORT void stix_rbt_walk ( - stix_rbt_t* rbt, /**< red-black tree */ - stix_rbt_walker_t walker, /**< callback function for each pair */ - void* ctx /**< pointer to user-specific data */ -); - -/** - * The stix_rbt_walk() function traverses a red-black tree in preorder - * from the rightmost child. - */ -STIX_EXPORT void stix_rbt_rwalk ( - stix_rbt_t* rbt, /**< red-black tree */ - stix_rbt_walker_t walker, /**< callback function for each pair */ - void* ctx /**< pointer to user-specific data */ -); - -/** - * The stix_rbt_allocpair() function allocates a pair for a key and a value - * given. But it does not chain the pair allocated into the red-black tree @a rbt. - * Use this function at your own risk. - * - * Take note of he following special behavior when the copier is - * #STIX_RBT_COPIER_INLINE. - * - If @a kptr is #STIX_NULL, the key space of the size @a klen is reserved but - * not propagated with any data. - * - If @a vptr is #STIX_NULL, the value space of the size @a vlen is reserved - * but not propagated with any data. - */ -STIX_EXPORT stix_rbt_pair_t* stix_rbt_allocpair ( - stix_rbt_t* rbt, - void* kptr, - stix_oow_t klen, - void* vptr, - stix_oow_t vlen -); - -/** - * The stix_rbt_freepair() function destroys a pair. But it does not detach - * the pair destroyed from the red-black tree @a rbt. Use this function at your - * own risk. - */ -STIX_EXPORT void stix_rbt_freepair ( - stix_rbt_t* rbt, - stix_rbt_pair_t* pair -); - -/** - * The stix_rbt_dflcomp() function defines the default key comparator. - */ -STIX_EXPORT int stix_rbt_dflcomp ( - const stix_rbt_t* rbt, - const void* kptr1, - stix_oow_t klen1, - const void* kptr2, - stix_oow_t klen2 -); - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/stix/lib/stix-utl.h b/stix/lib/stix-utl.h deleted file mode 100644 index 8a8a35a..0000000 --- a/stix/lib/stix-utl.h +++ /dev/null @@ -1,331 +0,0 @@ -/* - * $Id$ - * - Copyright (c) 2014-2016 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_EXPORT stix_oow_t stix_hashbytes ( - const stix_oob_t* ptr, - stix_oow_t len -); - -#if defined(STIX_HAVE_INLINE) - static STIX_INLINE stix_oow_t stix_hashbchars (const stix_bch_t* ptr, stix_oow_t len) - { - return stix_hashbytes((const stix_oob_t*)ptr,len * STIX_SIZEOF(stix_bch_t)); - } - - static STIX_INLINE stix_oow_t stix_hashuchars (const stix_uch_t* ptr, stix_oow_t len) - { - return stix_hashbytes((const stix_oob_t*)ptr,len * STIX_SIZEOF(stix_uch_t)); - } - - static STIX_INLINE stix_oow_t stix_hashwords (const stix_oow_t* ptr, stix_oow_t len) - { - return stix_hashbytes((const stix_oob_t*)ptr, len * STIX_SIZEOF(stix_oow_t)); - } - - static STIX_INLINE stix_oow_t stix_hashhalfwords (const stix_oohw_t* ptr, stix_oow_t len) - { - return stix_hashbytes((const stix_oob_t*)ptr, len * STIX_SIZEOF(stix_oohw_t)); - } -#else -# define stix_hashbchars(ptr,len) stix_hashbytes((const stix_oob_t*)ptr,len * STIX_SIZEOF(stix_bch_t)) -# define stix_hashuchars(ptr,len) stix_hashbytes((const stix_oob_t*)ptr,len * STIX_SIZEOF(stix_uch_t)) -# define stix_hashwords(ptr,len) stix_hashbytes((const stix_oob_t*)ptr, len * STIX_SIZEOF(stix_oow_t)) -# define stix_hashhalfwords(ptr,len) stix_hashbytes((const stix_oob_t*)ptr, len * STIX_SIZEOF(stix_oohw_t)) -#endif - -#if defined(STIX_OOCH_IS_UCH) -# define stix_hashoochars(ptr,len) stix_hashuchars(ptr,len) -#else -# define stix_hashoochars(ptr,len) stix_hashbchars(ptr,len) -#endif - - -STIX_EXPORT stix_oow_t stix_hashwords ( - const stix_oow_t* ptr, - stix_oow_t len -); - -/** - * The stix_equaluchars() function determines equality of two strings - * of the same length \a len. - */ -STIX_EXPORT int stix_equaluchars ( - const stix_uch_t* str1, - const stix_uch_t* str2, - stix_oow_t len -); - -STIX_EXPORT int stix_equalbchars ( - const stix_bch_t* str1, - const stix_bch_t* str2, - stix_oow_t len -); - -STIX_EXPORT int stix_compucstr ( - const stix_uch_t* str1, - const stix_uch_t* str2 -); - -STIX_EXPORT int stix_compbcstr ( - const stix_bch_t* str1, - const stix_bch_t* str2 -); - -STIX_EXPORT int stix_compucbcstr ( - const stix_uch_t* str1, - const stix_bch_t* str2 -); - -STIX_EXPORT int stix_compucharsbcstr ( - const stix_uch_t* str1, - stix_oow_t len, - const stix_bch_t* str2 -); - -STIX_EXPORT int stix_compbcharsbcstr ( - const stix_bch_t* str1, - stix_oow_t len, - const stix_bch_t* str2 -); - -STIX_EXPORT void stix_copyuchars ( - stix_uch_t* dst, - const stix_uch_t* src, - stix_oow_t len -); - -STIX_EXPORT void stix_copybchars ( - stix_bch_t* dst, - const stix_bch_t* src, - stix_oow_t len -); - -STIX_EXPORT void stix_copybtouchars ( - stix_uch_t* dst, - const stix_bch_t* src, - stix_oow_t len -); - -STIX_EXPORT stix_oow_t stix_copyucstr ( - stix_uch_t* dst, - stix_oow_t len, - const stix_uch_t* src -); - -STIX_EXPORT stix_oow_t stix_copybcstr ( - stix_bch_t* dst, - stix_oow_t len, - const stix_bch_t* src -); - -STIX_EXPORT stix_uch_t* stix_finduchar ( - const stix_uch_t* ptr, - stix_oow_t len, - stix_uch_t c -); - -STIX_EXPORT stix_bch_t* stix_findbchar ( - const stix_bch_t* ptr, - stix_oow_t len, - stix_bch_t c -); - -STIX_EXPORT stix_uch_t* stix_rfinduchar ( - const stix_uch_t* ptr, - stix_oow_t len, - stix_uch_t c -); - -STIX_EXPORT stix_bch_t* stix_rfindbchar ( - const stix_bch_t* ptr, - stix_oow_t len, - stix_bch_t c -); - - -STIX_EXPORT stix_oow_t stix_countucstr ( - const stix_uch_t* str -); - -STIX_EXPORT stix_oow_t stix_countbcstr ( - const stix_bch_t* str -); - -#if defined(STIX_OOCH_IS_UCH) -# define stix_equaloochars(str1,str2,len) stix_equaluchars(str1,str2,len) -# define stix_compoocbcstr(str1,str2) stix_compucbcstr(str1,str2) -# define stix_compoocharsbcstr(str1,len1,str2) stix_compucharsbcstr(str1,len1,str2) -# define stix_compoocstr(str1,str2) stix_compucstr(str1,str2) -# define stix_copyoochars(dst,src,len) stix_copyuchars(dst,src,len) -# define stix_copybctooochars(dst,src,len) stix_copybtouchars(dst,src,len) -# define stix_copyoocstr(dst,len,src) stix_copyucstr(dst,len,src) -# define stix_findoochar(ptr,len,c) stix_finduchar(ptr,len,c) -# define stix_rfindoochar(ptr,len,c) stix_rfinduchar(ptr,len,c) -# define stix_countoocstr(str) stix_countucstr(str) -#else - -# define stix_equaloochars(str1,str2,len) stix_equalbchars(str1,str2,len) -# define stix_compoocbcstr(str1,str2) stix_compbcstr(str1,str2) -# define stix_compoocharsbcstr(str1,len1,str2) stix_compbcharsbcstr(str1,len1,str2) -# define stix_compoocstr(str1,str2) stix_compbcstr(str1,str2) -# define stix_copyoochars(dst,src,len) stix_copybchars(dst,src,len) -# define stix_copybctooochars(dst,src,len) stix_copybchars(dst,src,len) -# define stix_copyoocstr(dst,len,src) stix_copybcstr(dst,len,src) -# define stix_findoochar(ptr,len,c) stix_findbchar(ptr,len,c) -# define stix_rfindoochar(ptr,len,c) stix_rfindbchar(ptr,len,c) -# define stix_countoocstr(str) stix_countbcstr(str) -#endif - - - -STIX_EXPORT int stix_copyoocstrtosbuf ( - stix_t* stix, - const stix_ooch_t* str, - int id -); - -STIX_EXPORT int stix_concatoocstrtosbuf ( - stix_t* stix, - const stix_ooch_t* str, - int id -); - -STIX_EXPORT stix_cmgr_t* stix_getutf8cmgr ( - void -); - -/** - * The stix_convutoutf8chars() function converts a unicode character string \a ucs - * to a UTF8 string and writes it into the buffer pointed to by \a bcs, but - * not more than \a bcslen bytes including the terminating null. - * - * Upon return, \a bcslen is modified to the actual number of bytes written to - * \a bcs excluding the terminating null; \a ucslen is modified to the number of - * wide characters converted. - * - * You may pass #STIX_NULL for \a bcs to dry-run conversion or to get the - * required buffer size for conversion. -2 is never returned in this case. - * - * \return - * - 0 on full conversion, - * - -1 on no or partial conversion for an illegal character encountered, - * - -2 on no or partial conversion for a small buffer. - * - * \code - * const stix_uch_t ucs[] = { 'H', 'e', 'l', 'l', 'o' }; - * stix_bch_t bcs[10]; - * stix_oow_t ucslen = 5; - * stix_oow_t bcslen = STIX_COUNTOF(bcs); - * n = stix_convutoutf8chars (ucs, &ucslen, bcs, &bcslen); - * if (n <= -1) - * { - * // conversion error - * } - * \endcode - */ -STIX_EXPORT int stix_convutoutf8chars ( - const stix_uch_t* ucs, - stix_oow_t* ucslen, - stix_bch_t* bcs, - stix_oow_t* bcslen -); - -/** - * The stix_convutf8touchars() function converts a UTF8 string to a uncide string. - * - * It never returns -2 if \a ucs is #STIX_NULL. - * - * \code - * const stix_bch_t* bcs = "test string"; - * stix_uch_t ucs[100]; - * stix_oow_t ucslen = STIX_COUNTOF(buf), n; - * stix_oow_t bcslen = 11; - * int n; - * n = stix_convutf8touchars (bcs, &bcslen, ucs, &ucslen); - * if (n <= -1) { invalid/incomplenete sequence or buffer to small } - * \endcode - * - * The resulting \a ucslen can still be greater than 0 even if the return - * value is negative. The value indiates the number of characters converted - * before the error has occurred. - * - * \return 0 on success. - * -1 if \a bcs contains an illegal character. - * -2 if the wide-character string buffer is too small. - * -3 if \a bcs is not a complete sequence. - */ -STIX_EXPORT int stix_convutf8touchars ( - const stix_bch_t* bcs, - stix_oow_t* bcslen, - stix_uch_t* ucs, - stix_oow_t* ucslen -); - - -STIX_EXPORT int stix_convutoutf8cstr ( - const stix_uch_t* ucs, - stix_oow_t* ucslen, - stix_bch_t* bcs, - stix_oow_t* bcslen -); - -STIX_EXPORT int stix_convutf8toucstr ( - const stix_bch_t* bcs, - stix_oow_t* bcslen, - stix_uch_t* ucs, - stix_oow_t* ucslen -); - - - -STIX_EXPORT stix_oow_t stix_uctoutf8 ( - stix_uch_t uc, - stix_bch_t* utf8, - stix_oow_t size -); - -STIX_EXPORT stix_oow_t stix_utf8touc ( - const stix_bch_t* utf8, - stix_oow_t size, - stix_uch_t* uc -); - - -#if defined(__cplusplus) -} -#endif - - -#endif diff --git a/stix/lib/stix.c b/stix/lib/stix.c deleted file mode 100644 index b1dbf52..0000000 --- a/stix/lib/stix.c +++ /dev/null @@ -1,740 +0,0 @@ -/* - * $Id$ - * - Copyright (c) 2014-2016 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-prv.h" - -stix_t* stix_open (stix_mmgr_t* mmgr, stix_oow_t xtnsize, stix_oow_t heapsize, const stix_vmprim_t* vmprim, stix_errnum_t* errnum) -{ - stix_t* stix; - - /* if this assertion fails, correct the type definition in stix.h */ - STIX_ASSERT (stix, STIX_SIZEOF(stix_oow_t) == STIX_SIZEOF(stix_oop_t)); - - stix = STIX_MMGR_ALLOC (mmgr, STIX_SIZEOF(*stix) + xtnsize); - if (stix) - { - if (stix_init(stix, mmgr, heapsize, vmprim) <= -1) - { - if (errnum) *errnum = stix->errnum; - STIX_MMGR_FREE (mmgr, stix); - stix = STIX_NULL; - } - else STIX_MEMSET (stix + 1, 0, xtnsize); - } - else if (errnum) *errnum = STIX_ESYSMEM; - - return stix; -} - -void stix_close (stix_t* stix) -{ - stix_fini (stix); - STIX_MMGR_FREE (stix->mmgr, stix); -} - -static void fill_bigint_tables (stix_t* stix) -{ - int radix, safe_ndigits; - stix_oow_t ub, w; - stix_oow_t multiplier; - - for (radix = 2; radix <= 36; radix++) - { - w = 0; - ub = (stix_oow_t)STIX_TYPE_MAX(stix_liw_t) / radix - (radix - 1); - multiplier = 1; - safe_ndigits = 0; - - while (w <= ub) - { - w = w * radix + (radix - 1); - multiplier *= radix; - safe_ndigits++; - } - - /* safe_ndigits contains the number of digits that never - * cause overflow when computed normally with a native type. */ - stix->bigint[radix].safe_ndigits = safe_ndigits; - stix->bigint[radix].multiplier = multiplier; - } -} - -int stix_init (stix_t* stix, stix_mmgr_t* mmgr, stix_oow_t heapsz, const stix_vmprim_t* vmprim) -{ - int modtab_inited = 0; - - STIX_MEMSET (stix, 0, STIX_SIZEOF(*stix)); - stix->mmgr = mmgr; - stix->cmgr = stix_getutf8cmgr (); - stix->vmprim = *vmprim; - - stix->option.log_mask = ~0u; - stix->option.dfl_symtab_size = STIX_DFL_SYMTAB_SIZE; - stix->option.dfl_sysdic_size = STIX_DFL_SYSDIC_SIZE; - stix->option.dfl_procstk_size = STIX_DFL_PROCSTK_SIZE; - -/* TODO: intoduct a permanent heap */ - /*stix->permheap = stix_makeheap (stix, what is the best size???); - if (!stix->permheap) goto oops; */ - stix->curheap = stix_makeheap (stix, heapsz); - if (!stix->curheap) goto oops; - stix->newheap = stix_makeheap (stix, heapsz); - if (!stix->newheap) goto oops; - - if (stix_rbt_init (&stix->modtab, stix, STIX_SIZEOF(stix_ooch_t), 1) <= -1) goto oops; - modtab_inited = 1; - stix_rbt_setstyle (&stix->modtab, stix_getrbtstyle(STIX_RBT_STYLE_INLINE_COPIERS)); - - fill_bigint_tables (stix); - - stix->tagged_classes[STIX_OOP_TAG_SMINT] = &stix->_small_integer; - stix->tagged_classes[STIX_OOP_TAG_CHAR] = &stix->_character; - stix->tagged_classes[STIX_OOP_TAG_ERROR] = &stix->_error_class; - - return 0; - -oops: - if (modtab_inited) stix_rbt_fini (&stix->modtab); - if (stix->newheap) stix_killheap (stix, stix->newheap); - if (stix->curheap) stix_killheap (stix, stix->curheap); - if (stix->permheap) stix_killheap (stix, stix->permheap); - return -1; -} - -static stix_rbt_walk_t unload_module (stix_rbt_t* rbt, stix_rbt_pair_t* pair, void* ctx) -{ - stix_t* stix = (stix_t*)ctx; - stix_mod_data_t* mdp; - - mdp = STIX_RBT_VPTR(pair); - STIX_ASSERT (stix, mdp != STIX_NULL); - - mdp->pair = STIX_NULL; /* to prevent stix_closemod() from calling stix_rbt_delete() */ - stix_closemod (stix, mdp); - - return STIX_RBT_WALK_FORWARD; -} - -void stix_fini (stix_t* stix) -{ - stix_cb_t* cb; - stix_oow_t i; - - if (stix->sem_list) - { - stix_freemem (stix, stix->sem_list); - stix->sem_list_capa = 0; - stix->sem_list_count = 0; - } - - if (stix->sem_heap) - { - stix_freemem (stix, stix->sem_heap); - stix->sem_heap_capa = 0; - stix->sem_heap_count = 0; - } - - for (cb = stix->cblist; cb; cb = cb->next) - { - if (cb->fini) cb->fini (stix); - } - - stix_rbt_walk (&stix->modtab, unload_module, stix); /* unload all modules */ - stix_rbt_fini (&stix->modtab); - -/* TOOD: persistency? storing objects to image file? */ - stix_killheap (stix, stix->newheap); - stix_killheap (stix, stix->curheap); - stix_killheap (stix, stix->permheap); - - /* deregister all callbacks */ - while (stix->cblist) stix_deregcb (stix, stix->cblist); - - for (i = 0; i < STIX_COUNTOF(stix->sbuf); i++) - { - if (stix->sbuf[i].ptr) - { - stix_freemem (stix, stix->sbuf[i].ptr); - stix->sbuf[i].ptr = STIX_NULL; - stix->sbuf[i].len = 0; - stix->sbuf[i].capa = 0; - } - } - - if (stix->log.ptr) - { - /* make sure to flush your log message */ -/* TODO: flush unwritten message */ - - stix_freemem (stix, stix->log.ptr); - stix->log.capa = 0; - stix->log.len = 0; - } -} - -const stix_ooch_t* stix_geterrstr (stix_t* stix) -{ - return stix_errnumtoerrstr (stix->errnum); -} - -int stix_setoption (stix_t* stix, stix_option_t id, const void* value) -{ - switch (id) - { - case STIX_TRAIT: - stix->option.trait = *(const unsigned int*)value; - return 0; - - case STIX_LOG_MASK: - stix->option.log_mask = *(const unsigned int*)value; - return 0; - - case STIX_SYMTAB_SIZE: - { - stix_oow_t w; - - w = *(stix_oow_t*)value; - if (w <= 0 || w > STIX_SMOOI_MAX) goto einval; - - stix->option.dfl_symtab_size = *(stix_oow_t*)value; - return 0; - } - - case STIX_SYSDIC_SIZE: - { - stix_oow_t w; - - w = *(stix_oow_t*)value; - if (w <= 0 || w > STIX_SMOOI_MAX) goto einval; - - stix->option.dfl_sysdic_size = *(stix_oow_t*)value; - return 0; - } - - case STIX_PROCSTK_SIZE: - { - stix_oow_t w; - - w = *(stix_oow_t*)value; - if (w <= 0 || w > STIX_SMOOI_MAX) goto einval; - - stix->option.dfl_procstk_size = *(stix_oow_t*)value; - return 0; - } - } - -einval: - stix->errnum = STIX_EINVAL; - return -1; -} - -int stix_getoption (stix_t* stix, stix_option_t id, void* value) -{ - switch (id) - { - case STIX_TRAIT: - *(unsigned int*)value = stix->option.trait; - return 0; - - case STIX_LOG_MASK: - *(unsigned int*)value = stix->option.log_mask; - return 0; - - case STIX_SYMTAB_SIZE: - *(stix_oow_t*)value = stix->option.dfl_symtab_size; - return 0; - - case STIX_SYSDIC_SIZE: - *(stix_oow_t*)value = stix->option.dfl_sysdic_size; - return 0; - - case STIX_PROCSTK_SIZE: - *(stix_oow_t*)value = stix->option.dfl_procstk_size; - return 0; - }; - - stix->errnum = STIX_EINVAL; - return -1; -} - -stix_cb_t* stix_regcb (stix_t* stix, stix_cb_t* tmpl) -{ - stix_cb_t* actual; - - actual = stix_allocmem (stix, STIX_SIZEOF(*actual)); - if (!actual) return STIX_NULL; - - *actual = *tmpl; - actual->next = stix->cblist; - actual->prev = STIX_NULL; - stix->cblist = actual; - - return actual; -} - -void stix_deregcb (stix_t* stix, stix_cb_t* cb) -{ - if (cb == stix->cblist) - { - stix->cblist = stix->cblist->next; - if (stix->cblist) stix->cblist->prev = STIX_NULL; - } - else - { - if (cb->next) cb->next->prev = cb->prev; - if (cb->prev) cb->prev->next = cb->next; - } - - stix_freemem (stix, cb); -} - -void* stix_allocmem (stix_t* stix, stix_oow_t size) -{ - void* ptr; - - ptr = STIX_MMGR_ALLOC (stix->mmgr, size); - if (!ptr) stix->errnum = STIX_ESYSMEM; - return ptr; -} - -void* stix_callocmem (stix_t* stix, stix_oow_t size) -{ - void* ptr; - - ptr = STIX_MMGR_ALLOC (stix->mmgr, size); - if (!ptr) stix->errnum = STIX_ESYSMEM; - else STIX_MEMSET (ptr, 0, size); - return ptr; -} - -void* stix_reallocmem (stix_t* stix, void* ptr, stix_oow_t size) -{ - ptr = STIX_MMGR_REALLOC (stix->mmgr, ptr, size); - if (!ptr) stix->errnum = STIX_ESYSMEM; - return ptr; -} - -void stix_freemem (stix_t* stix, void* ptr) -{ - STIX_MMGR_FREE (stix->mmgr, ptr); -} - -/* -------------------------------------------------------------------------- */ - -#define MOD_PREFIX "stix_mod_" -#define MOD_PREFIX_LEN 9 - -#if defined(STIX_ENABLE_STATIC_MODULE) - -#include "../mod/console.h" -#include "../mod/_stdio.h" - -static struct -{ - stix_bch_t* modname; - int (*modload) (stix_t* stix, stix_mod_t* mod); -} -static_modtab[] = -{ - { "console", stix_mod_console }, - { "stdio", stix_mod_stdio }, -}; -#endif - -stix_mod_data_t* stix_openmod (stix_t* stix, const stix_ooch_t* name, stix_oow_t namelen) -{ - stix_rbt_pair_t* pair; - stix_mod_data_t* mdp; - stix_mod_data_t md; - stix_mod_load_t load = STIX_NULL; -#if defined(STIX_ENABLE_STATIC_MODULE) - int n; -#endif - - /* maximum module name length is STIX_MOD_NAME_LEN_MAX. - * MOD_PREFIX_LEN for MOD_PREFIX - * 1 for _ at the end when stix_mod_xxx_ is attempted. - * 1 for the terminating '\0'. - */ - stix_ooch_t buf[MOD_PREFIX_LEN + STIX_MOD_NAME_LEN_MAX + 1 + 1]; - - /* copy instead of encoding conversion. MOD_PREFIX must not - * include a character that requires encoding conversion. - * note the terminating null isn't needed in buf here. */ - stix_copybctooochars (buf, MOD_PREFIX, MOD_PREFIX_LEN); - - if (namelen > STIX_COUNTOF(buf) - (MOD_PREFIX_LEN + 1 + 1)) - { - /* module name too long */ - stix->errnum = STIX_EINVAL; /* TODO: change the error number to something more specific */ - return STIX_NULL; - } - - stix_copyoochars (&buf[MOD_PREFIX_LEN], name, namelen); - buf[MOD_PREFIX_LEN + namelen] = '\0'; - -#if defined(STIX_ENABLE_STATIC_MODULE) - /* attempt to find a statically linked module */ - -/*TODO: CHANGE THIS PART */ - - /* TODO: binary search ... */ - for (n = 0; n < STIX_COUNTOF(static_modtab); n++) - { - if (stix_compoocharsbcstr (name, namelen, static_modtab[n].modname) == 0) - { - load = static_modtab[n].modload; - break; - } - } - - if (n >= STIX_COUNTOF(static_modtab)) - { - stix->errnum = STIX_ENOENT; - return STIX_NULL; - } - - if (load) - { - /* found the module in the staic module table */ - - STIX_MEMSET (&md, 0, STIX_SIZEOF(md)); - stix_copyoochars ((stix_ooch_t*)md.mod.name, name, namelen); - /* Note md.handle is STIX_NULL for a static module */ - - /* i copy-insert 'md' into the table before calling 'load'. - * to pass the same address to load(), query(), etc */ - pair = stix_rbt_insert (&stix->modtab, (stix_ooch_t*)name, namelen, &md, STIX_SIZEOF(md)); - if (pair == STIX_NULL) - { - stix->errnum = STIX_ESYSMEM; - return STIX_NULL; - } - - mdp = (stix_mod_data_t*)STIX_RBT_VPTR(pair); - if (load (stix, &mdp->mod) <= -1) - { - stix_rbt_delete (&stix->modtab, (stix_ooch_t*)name, namelen); - return STIX_NULL; - } - - return mdp; - } -#endif - - /* attempt to find an external module */ - STIX_MEMSET (&md, 0, STIX_SIZEOF(md)); - stix_copyoochars ((stix_ooch_t*)md.mod.name, name, namelen); - if (stix->vmprim.dl_open && stix->vmprim.dl_getsym && stix->vmprim.dl_close) - { - md.handle = stix->vmprim.dl_open (stix, &buf[MOD_PREFIX_LEN]); - } - - if (md.handle == STIX_NULL) - { - STIX_DEBUG2 (stix, "Cannot open a module [%.*js]\n", namelen, name); - stix->errnum = STIX_ENOENT; /* TODO: be more descriptive about the error */ - return STIX_NULL; - } - - /* attempt to get stix_mod_xxx where xxx is the module name*/ - load = stix->vmprim.dl_getsym (stix, md.handle, buf); - if (!load) - { - STIX_DEBUG3 (stix, "Cannot get a module symbol [%js] in [%.*js]\n", buf, namelen, name); - stix->errnum = STIX_ENOENT; /* TODO: be more descriptive about the error */ - stix->vmprim.dl_close (stix, md.handle); - return STIX_NULL; - } - - /* i copy-insert 'md' into the table before calling 'load'. - * to pass the same address to load(), query(), etc */ - pair = stix_rbt_insert (&stix->modtab, (void*)name, namelen, &md, STIX_SIZEOF(md)); - if (pair == STIX_NULL) - { - STIX_DEBUG2 (stix, "Cannot register a module [%.*js]\n", namelen, name); - stix->errnum = STIX_ESYSMEM; - stix->vmprim.dl_close (stix, md.handle); - return STIX_NULL; - } - - mdp = (stix_mod_data_t*)STIX_RBT_VPTR(pair); - if (load (stix, &mdp->mod) <= -1) - { - STIX_DEBUG3 (stix, "Module function [%js] returned failure in [%.*js]\n", buf, namelen, name); - stix->errnum = STIX_ENOENT; /* TODO: proper error code and handling */ - stix_rbt_delete (&stix->modtab, name, namelen); - stix->vmprim.dl_close (stix, mdp->handle); - return STIX_NULL; - } - - mdp->pair = pair; - - STIX_DEBUG2 (stix, "Opened a module [%js] - %p\n", mdp->mod.name, mdp->handle); - - /* the module loader must ensure to set a proper query handler */ - STIX_ASSERT (stix, mdp->mod.query != STIX_NULL); - - return mdp; -} - -void stix_closemod (stix_t* stix, stix_mod_data_t* mdp) -{ - if (mdp->mod.unload) mdp->mod.unload (stix, &mdp->mod); - - if (mdp->handle) - { - stix->vmprim.dl_close (stix, mdp->handle); - STIX_DEBUG2 (stix, "Closed a module [%js] - %p\n", mdp->mod.name, mdp->handle); - mdp->handle = STIX_NULL; - } - - if (mdp->pair) - { - /*mdp->pair = STIX_NULL;*/ /* this reset isn't needed as the area will get freed by stix_rbt_delete()) */ - stix_rbt_delete (&stix->modtab, mdp->mod.name, stix_countoocstr(mdp->mod.name)); - } -} - -int stix_importmod (stix_t* stix, stix_oop_t _class, const stix_ooch_t* name, stix_oow_t len) -{ - stix_rbt_pair_t* pair; - stix_mod_data_t* mdp; - int r = 0; - - /* stix_openmod(), stix_closemod(), etc calls a user-defined callback. - * i need to protect _class in case the user-defined callback allocates - * a OOP memory chunk and GC occurs */ - stix_pushtmp (stix, &_class); - - pair = stix_rbt_search (&stix->modtab, name, len); - if (pair) - { - mdp = (stix_mod_data_t*)STIX_RBT_VPTR(pair); - STIX_ASSERT (stix, mdp != STIX_NULL); - } - else - { - mdp = stix_openmod (stix, name, len); - if (!mdp) - { - r = -1; - goto done2; - } - } - - if (!mdp->mod.import) - { - STIX_DEBUG1 (stix, "Cannot import module [%js] - importing not supported by the module\n", mdp->mod.name); - stix->errnum = STIX_ENOIMPL; - r = -1; - goto done; - } - - if (mdp->mod.import (stix, &mdp->mod, _class) <= -1) - { - STIX_DEBUG1 (stix, "Cannot import module [%js] - module's import() returned failure\n", mdp->mod.name); - r = -1; - goto done; - } - -done: - if (!pair) - { - /* close the module if it has been opened in this function. */ - stix_closemod (stix, mdp); - } - -done2: - stix_poptmp (stix); - return r; -} - -stix_pfimpl_t stix_querymod (stix_t* stix, const stix_ooch_t* pfid, stix_oow_t pfidlen) -{ - /* primitive function identifier - * _funcname - * modname_funcname - */ - stix_rbt_pair_t* pair; - stix_mod_data_t* mdp; - const stix_ooch_t* sep; - - stix_oow_t mod_name_len; - stix_pfimpl_t handler; - - sep = stix_findoochar (pfid, pfidlen, '.'); - if (!sep) - { - /* i'm writing a conservative code here. the compiler should - * guarantee that an underscore is included in an primitive identifer. - * what if the compiler is broken? imagine a buggy compiler rewritten - * in stix itself? */ - STIX_DEBUG2 (stix, "Internal error - no period in a primitive function identifier [%.*js] - buggy compiler?\n", pfidlen, pfid); - stix->errnum = STIX_EINTERN; - return STIX_NULL; - } - - mod_name_len = sep - pfid; - - pair = stix_rbt_search (&stix->modtab, pfid, mod_name_len); - if (pair) - { - mdp = (stix_mod_data_t*)STIX_RBT_VPTR(pair); - STIX_ASSERT (stix, mdp != STIX_NULL); - } - else - { - mdp = stix_openmod (stix, pfid, mod_name_len); - if (!mdp) return STIX_NULL; - } - - if ((handler = mdp->mod.query (stix, &mdp->mod, sep + 1)) == STIX_NULL) - { - /* the primitive function is not found. keep the module open */ - STIX_DEBUG2 (stix, "Cannot find a primitive function [%js] in a module [%js]\n", sep + 1, mdp->mod.name); - stix->errnum = STIX_ENOENT; /* TODO: proper error code and handling */ - return STIX_NULL; - } - - STIX_DEBUG3 (stix, "Found a primitive function [%js] in a module [%js] - %p\n", sep + 1, mdp->mod.name, handler); - return handler; -} - -/* -------------------------------------------------------------------------- */ - -/* add a new primitive method */ -int stix_genpfmethod (stix_t* stix, stix_mod_t* mod, stix_oop_t _class, stix_method_type_t type, const stix_ooch_t* mthname, int variadic, const stix_ooch_t* pfname) -{ - /* NOTE: this function is a subset of add_compiled_method() in comp.c */ - - stix_oop_char_t mnsym, pfidsym; - stix_oop_method_t mth; - stix_oop_class_t cls; - stix_oow_t tmp_count = 0, i; - stix_ooi_t arg_count = 0; - stix_oocs_t cs; - stix_ooi_t preamble_flags = 0; - static stix_ooch_t dot[] = { '.', '\0' }; - - STIX_ASSERT (stix, STIX_CLASSOF(stix, _class) == stix->_class); - - if (!pfname) pfname = mthname; - - cls = (stix_oop_class_t)_class; - stix_pushtmp (stix, (stix_oop_t*)&cls); tmp_count++; - STIX_ASSERT (stix, STIX_CLASSOF(stix, (stix_oop_t)cls->mthdic[type]) == stix->_method_dictionary); - - for (i = 0; mthname[i]; i++) - { - if (mthname[i] == ':') - { - if (variadic) goto oops_inval; - arg_count++; - } - } -/* TODO: check if name is a valid method name - more checks... */ -/* TOOD: if the method name is a binary selector, it can still have an argument.. so the check below is invalid... */ - if (arg_count > 0 && mthname[i - 1] != ':') - { - oops_inval: - STIX_DEBUG2 (stix, "Cannot generate primitive function method [%js] in [%O] - invalid name\n", mthname, cls->name); - stix->errnum = STIX_EINVAL; - goto oops; - } - - cs.ptr = (stix_ooch_t*)mthname; - cs.len = i; - if (stix_lookupdic (stix, cls->mthdic[type], &cs) != STIX_NULL) - { - STIX_DEBUG2 (stix, "Cannot generate primitive function method [%js] in [%O] - duplicate\n", mthname, cls->name); - stix->errnum = STIX_EEXIST; - goto oops; - } - - mnsym = (stix_oop_char_t)stix_makesymbol (stix, mthname, i); - if (!mnsym) goto oops; - stix_pushtmp (stix, (stix_oop_t*)&mnsym); tmp_count++; - - /* compose a full primitive function identifier to VM's string buffer. - * pfid => mod->name + '.' + pfname */ - if (stix_copyoocstrtosbuf(stix, mod->name, 0) <= -1 || - stix_concatoocstrtosbuf(stix, dot, 0) <= -1 || - stix_concatoocstrtosbuf(stix, pfname, 0) <= -1) - { - STIX_DEBUG2 (stix, "Cannot generate primitive function method [%js] in [%O] - VM memory shortage\n", mthname, cls->name); - return -1; - } - - pfidsym = (stix_oop_char_t)stix_makesymbol (stix, stix->sbuf[0].ptr, stix->sbuf[0].len); - if (!pfidsym) - { - STIX_DEBUG2 (stix, "Cannot generate primitive function method [%js] in [%O] - symbol instantiation failure\n", mthname, cls->name); - goto oops; - } - stix_pushtmp (stix, (stix_oop_t*)&pfidsym); tmp_count++; - -#if defined(STIX_USE_OBJECT_TRAILER) - mth = (stix_oop_method_t)stix_instantiatewithtrailer (stix, stix->_method, 1, STIX_NULL, 0); -#else - mth = (stix_oop_method_t)stix_instantiate (stix, stix->_method, STIX_NULL, 1); -#endif - if (!mth) - { - STIX_DEBUG2 (stix, "Cannot generate primitive function method [%js] in [%O] - method instantiation failure\n", mthname, cls->name); - goto oops; - } - - /* store the primitive function name symbol to the literal frame */ - mth->slot[0] = (stix_oop_t)pfidsym; - - /* premable should contain the index to the literal frame which is always 0 */ - mth->owner = cls; - mth->name = mnsym; - if (variadic) preamble_flags |= STIX_METHOD_PREAMBLE_FLAG_VARIADIC; - mth->preamble = STIX_SMOOI_TO_OOP(STIX_METHOD_MAKE_PREAMBLE(STIX_METHOD_PREAMBLE_NAMED_PRIMITIVE, 0, preamble_flags)); - mth->preamble_data[0] = STIX_SMOOI_TO_OOP(0); - mth->preamble_data[1] = STIX_SMOOI_TO_OOP(0); - mth->tmpr_count = STIX_SMOOI_TO_OOP(arg_count); - mth->tmpr_nargs = STIX_SMOOI_TO_OOP(arg_count); - -/* TODO: emit BCODE_RETURN_NIL ? */ - - if (!stix_putatdic (stix, cls->mthdic[type], (stix_oop_t)mnsym, (stix_oop_t)mth)) - { - STIX_DEBUG2 (stix, "Cannot generate primitive function method [%js] in [%O] - failed to add to method dictionary\n", mthname, cls->name); - goto oops; - } - - STIX_DEBUG2 (stix, "Generated primitive function method [%js] in [%O]\n", mthname, cls->name); - - stix_poptmps (stix, tmp_count); tmp_count = 0; - return 0; - -oops: - stix_poptmps (stix, tmp_count); - return -1; -} diff --git a/stix/lib/stix.h b/stix/lib/stix.h deleted file mode 100644 index 63236d8..0000000 --- a/stix/lib/stix.h +++ /dev/null @@ -1,1463 +0,0 @@ -/* - * $Id$ - * - Copyright (c) 2014-2016 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_H_ -#define _STIX_H_ - -#include "stix-cmn.h" -#include "stix-rbt.h" - -/* TODO: move this macro out to the build files.... */ -#define STIX_INCLUDE_COMPILER - -/* define this to allow an pointer(OOP) object to have trailing bytes - * this is used to embed bytes codes into the back of a compile method - * object instead of putting in in a separate byte array. */ -#define STIX_USE_OBJECT_TRAILER -/* ========================================================================== */ - -/** - * The stix_errnum_t type defines the error codes. - */ -enum stix_errnum_t -{ - STIX_ENOERR, /**< no error */ - STIX_EGENERIC, /**< generic error */ - - STIX_ENOIMPL, /**< not implemented */ - STIX_ESYSERR, /**< subsystem error */ - STIX_EINTERN, /**< internal error */ - STIX_ESYSMEM, /**< insufficient system memory */ - STIX_EOOMEM, /**< insufficient object memory */ - - STIX_EINVAL, /**< invalid parameter or data */ - STIX_ENOENT, /**< data not found */ - STIX_EEXIST, /**< existing/duplicate data */ - STIX_EBUSY, - STIX_EACCES, - STIX_EPERM, - STIX_ENOTDIR, - STIX_EINTR, - STIX_EPIPE, - STIX_EAGAIN, - - STIX_ETOOBIG, /**< data too large */ - STIX_EMSGSND, /**< message sending error. even doesNotUnderstand: is not found */ - STIX_ERANGE, /**< range error. overflow and underflow */ - STIX_EBCFULL, /**< byte-code full */ - STIX_EDFULL, /**< dictionary full */ - STIX_EPFULL, /**< processor full */ - STIX_ESHFULL, /**< semaphore heap full */ - STIX_ESLFULL, /**< semaphore list full */ - STIX_EDIVBY0, /**< divide by zero */ - STIX_EIOERR, /**< I/O error */ - STIX_EECERR, /**< encoding conversion error */ - -#if defined(STIX_INCLUDE_COMPILER) - STIX_ESYNTAX /** < syntax error */ -#endif -}; -typedef enum stix_errnum_t stix_errnum_t; - -enum stix_option_t -{ - STIX_TRAIT, - STIX_LOG_MASK, - STIX_SYMTAB_SIZE, /* default system table size */ - STIX_SYSDIC_SIZE, /* default system dictionary size */ - STIX_PROCSTK_SIZE /* default process stack size */ -}; -typedef enum stix_option_t stix_option_t; - -enum stix_option_dflval_t -{ - STIX_DFL_SYMTAB_SIZE = 5000, - STIX_DFL_SYSDIC_SIZE = 5000, - STIX_DFL_PROCSTK_SIZE = 5000 -}; -typedef enum stix_option_dflval_t stix_option_dflval_t; - -enum stix_trait_t -{ - /* perform no garbage collection when the heap is full. - * you still can use stix_gc() explicitly. */ - STIX_NOGC = (1 << 0), - - /* wait for running process when exiting from the main method */ - STIX_AWAIT_PROCS = (1 << 1) -}; -typedef enum stix_trait_t stix_trait_t; - -typedef struct stix_obj_t stix_obj_t; -typedef struct stix_obj_t* stix_oop_t; - -/* these are more specialized types for stix_obj_t */ -typedef struct stix_obj_oop_t stix_obj_oop_t; -typedef struct stix_obj_char_t stix_obj_char_t; -typedef struct stix_obj_byte_t stix_obj_byte_t; -typedef struct stix_obj_halfword_t stix_obj_halfword_t; -typedef struct stix_obj_word_t stix_obj_word_t; - -/* these are more specialized types for stix_oop_t */ -typedef struct stix_obj_oop_t* stix_oop_oop_t; -typedef struct stix_obj_char_t* stix_oop_char_t; -typedef struct stix_obj_byte_t* stix_oop_byte_t; -typedef struct stix_obj_halfword_t* stix_oop_halfword_t; -typedef struct stix_obj_word_t* stix_oop_word_t; - -#define STIX_OOW_BITS (STIX_SIZEOF_OOW_T * 8) -#define STIX_OOI_BITS (STIX_SIZEOF_OOI_T * 8) -#define STIX_OOP_BITS (STIX_SIZEOF_OOP_T * 8) -#define STIX_OOHW_BITS (STIX_SIZEOF_OOHW_T * 8) - - -/* ========================================================================= */ -/* BIGINT TYPES AND MACROS */ -/* ========================================================================= */ -#if (STIX_SIZEOF_UINTMAX_T > STIX_SIZEOF_OOW_T) -# define STIX_USE_FULL_WORD -#endif - -#if defined(STIX_USE_FULL_WORD) - typedef stix_oow_t stix_liw_t; /* large integer word */ - typedef stix_ooi_t stix_lii_t; - typedef stix_uintmax_t stix_lidw_t; /* large integer double word */ - typedef stix_intmax_t stix_lidi_t; -# define STIX_SIZEOF_LIW_T STIX_SIZEOF_OOW_T -# define STIX_SIZEOF_LIDW_T STIX_SIZEOF_UINTMAX_T -# define STIX_LIW_BITS STIX_OOW_BITS -# define STIX_LIDW_BITS (STIX_SIZEOF_UINTMAX_T * 8) - - typedef stix_oop_word_t stix_oop_liword_t; -# define STIX_OBJ_TYPE_LIWORD STIX_OBJ_TYPE_WORD - -#else - typedef stix_oohw_t stix_liw_t; - typedef stix_oohi_t stix_lii_t; - typedef stix_oow_t stix_lidw_t; - typedef stix_ooi_t stix_lidi_t; -# define STIX_SIZEOF_LIW_T STIX_SIZEOF_OOHW_T -# define STIX_SIZEOF_LIDW_T STIX_SIZEOF_OOW_T -# define STIX_LIW_BITS STIX_OOHW_BITS -# define STIX_LIDW_BITS STIX_OOW_BITS - - typedef stix_oop_halfword_t stix_oop_liword_t; -# define STIX_OBJ_TYPE_LIWORD STIX_OBJ_TYPE_HALFWORD - -#endif - - -enum stix_method_type_t -{ - STIX_METHOD_INSTANCE, - STIX_METHOD_CLASS, - - /* --------------------------- */ - STIX_METHOD_TYPE_COUNT -}; -typedef enum stix_method_type_t stix_method_type_t; - -/* - * OOP encoding - * An object pointer(OOP) is an ordinary pointer value to an object. - * but some simple numeric values are also encoded into OOP using a simple - * bit-shifting and masking. - * - * A real OOP is stored without any bit-shifting while a non-OOP value encoded - * in an OOP is bit-shifted to the left by 2 and the 2 least-significant bits - * are set to 1 or 2. - * - * This scheme works because the object allocators aligns the object size to - * a multiple of sizeof(stix_oop_t). This way, the 2 least-significant bits - * of a real OOP are always 0s. - */ - -#define STIX_OOP_TAG_BITS 2 -#define STIX_OOP_TAG_SMINT 1 -#define STIX_OOP_TAG_CHAR 2 -#define STIX_OOP_TAG_ERROR 3 - -#define STIX_OOP_GET_TAG(oop) (((stix_oow_t)oop) & STIX_LBMASK(stix_oow_t, STIX_OOP_TAG_BITS)) -#define STIX_OOP_IS_NUMERIC(oop) (STIX_OOP_GET_TAG(oop) != 0) -#define STIX_OOP_IS_POINTER(oop) (STIX_OOP_GET_TAG(oop) == 0) - -#define STIX_OOP_IS_SMOOI(oop) (STIX_OOP_GET_TAG(oop) == STIX_OOP_TAG_SMINT) -#define STIX_OOP_IS_CHAR(oop) (STIX_OOP_GET_TAG(oop) == STIX_OOP_TAG_CHAR) -#define STIX_OOP_IS_ERROR(oop) (STIX_OOP_GET_TAG(oop) == STIX_OOP_TAG_ERROR) - -#define STIX_SMOOI_TO_OOP(num) ((stix_oop_t)((((stix_ooi_t)(num)) << STIX_OOP_TAG_BITS) | STIX_OOP_TAG_SMINT)) -#define STIX_OOP_TO_SMOOI(oop) (((stix_ooi_t)oop) >> STIX_OOP_TAG_BITS) -#define STIX_CHAR_TO_OOP(num) ((stix_oop_t)((((stix_oow_t)(num)) << STIX_OOP_TAG_BITS) | STIX_OOP_TAG_CHAR)) -#define STIX_OOP_TO_CHAR(oop) (((stix_oow_t)oop) >> STIX_OOP_TAG_BITS) -#define STIX_ERROR_TO_OOP(num) ((stix_oop_t)((((stix_oow_t)(num)) << STIX_OOP_TAG_BITS) | STIX_OOP_TAG_ERROR)) -#define STIX_OOP_TO_ERROR(oop) (((stix_oow_t)oop) >> STIX_OOP_TAG_BITS) - -/* SMOOI takes up 62 bits on a 64-bit architecture and 30 bits - * on a 32-bit architecture. The absolute value takes up 61 bits and 29 bits - * respectively for the sign bit. */ -#define STIX_SMOOI_BITS (STIX_OOI_BITS - STIX_OOP_TAG_BITS) -#define STIX_SMOOI_ABS_BITS (STIX_SMOOI_BITS - 1) -#define STIX_SMOOI_MAX ((stix_ooi_t)(~((stix_oow_t)0) >> (STIX_OOP_TAG_BITS + 1))) -/* Sacrificing 1 bit pattern for a negative SMOOI makes - * implementation a lot eaisier in many aspects. */ -/*#define STIX_SMOOI_MIN (-STIX_SMOOI_MAX - 1)*/ -#define STIX_SMOOI_MIN (-STIX_SMOOI_MAX) -#define STIX_IN_SMOOI_RANGE(ooi) ((ooi) >= STIX_SMOOI_MIN && (ooi) <= STIX_SMOOI_MAX) - -/* TODO: There are untested code where a small integer is converted to stix_oow_t. - * for example, the spec making macro treats the number as stix_oow_t instead of stix_ooi_t. - * as of this writing, i skip testing that part with the spec value exceeding STIX_SMOOI_MAX. - * later, please verify it works, probably by limiting the value ranges in such macros - */ - -/* - * Object structure - */ -enum stix_obj_type_t -{ - STIX_OBJ_TYPE_OOP, - STIX_OBJ_TYPE_CHAR, - STIX_OBJ_TYPE_BYTE, - STIX_OBJ_TYPE_HALFWORD, - STIX_OBJ_TYPE_WORD - -/* - STIX_OBJ_TYPE_UINT8, - STIX_OBJ_TYPE_UINT16, - STIX_OBJ_TYPE_UINT32, -*/ - -/* NOTE: you can have STIX_OBJ_SHORT, STIX_OBJ_INT - * STIX_OBJ_LONG, STIX_OBJ_FLOAT, STIX_OBJ_DOUBLE, etc - * type type field being 6 bits long, you can have up to 64 different types. - - STIX_OBJ_TYPE_SHORT, - STIX_OBJ_TYPE_INT, - STIX_OBJ_TYPE_LONG, - STIX_OBJ_TYPE_FLOAT, - STIX_OBJ_TYPE_DOUBLE */ -}; -typedef enum stix_obj_type_t stix_obj_type_t; - -/* ========================================================================= - * Object header structure - * - * _flags: - * type: the type of a payload item. - * one of STIX_OBJ_TYPE_OOP, STIX_OBJ_TYPE_CHAR, - * STIX_OBJ_TYPE_BYTE, STIX_OBJ_TYPE_HALFWORD, STIX_OBJ_TYPE_WORD - * unit: the size of a payload item in bytes. - * extra: 0 or 1. 1 indicates that the payload contains 1 more - * item than the value of the size field. used for a - * terminating null in a variable-char object. internel - * use only. - * kernel: 0 or 1. indicates that the object is a kernel object. - * VM disallows layout changes of a kernel object. - * internal use only. - * moved: 0 or 1. used by GC. internal use only. - * ngc: 0 or 1, used by GC. internal use only. - * trailer: 0 or 1. indicates that there are trailing bytes - * after the object payload. internal use only. - * - * _size: the number of payload items in an object. - * it doesn't include the header size. - * - * The total number of bytes occupied by an object can be calculated - * with this fomula: - * sizeof(stix_obj_t) + ALIGN((size + extra) * unit), sizeof(stix_oop_t)) - * - * If the type is known to be not STIX_OBJ_TYPE_CHAR, you can assume that - * 'extra' is 0. So you can simplify the fomula in such a context. - * sizeof(stix_obj_t) + ALIGN(size * unit), sizeof(stix_oop_t)) - * - * The ALIGN() macro is used above since allocation adjusts the payload - * size to a multiple of sizeof(stix_oop_t). it assumes that sizeof(stix_obj_t) - * is a multiple of sizeof(stix_oop_t). See the STIX_BYTESOF() macro. - * - * Due to the header structure, an object can only contain items of - * homogeneous data types in the payload. - * - * It's actually possible to split the size field into 2. For example, - * the upper half contains the number of oops and the lower half contains - * the number of bytes/chars. This way, a variable-byte class or a variable-char - * class can have normal instance variables. On the contrary, the actual byte - * size calculation and the access to the payload fields become more complex. - * Therefore, i've dropped the idea. - * ========================================================================= */ -#define STIX_OBJ_FLAGS_TYPE_BITS 6 -#define STIX_OBJ_FLAGS_UNIT_BITS 5 -#define STIX_OBJ_FLAGS_EXTRA_BITS 1 -#define STIX_OBJ_FLAGS_KERNEL_BITS 2 -#define STIX_OBJ_FLAGS_MOVED_BITS 1 -#define STIX_OBJ_FLAGS_NGC_BITS 1 -#define STIX_OBJ_FLAGS_TRAILER_BITS 1 - -#define STIX_OBJ_FLAGS_TYPE_SHIFT (STIX_OBJ_FLAGS_UNIT_BITS + STIX_OBJ_FLAGS_UNIT_SHIFT) -#define STIX_OBJ_FLAGS_UNIT_SHIFT (STIX_OBJ_FLAGS_EXTRA_BITS + STIX_OBJ_FLAGS_EXTRA_SHIFT) -#define STIX_OBJ_FLAGS_EXTRA_SHIFT (STIX_OBJ_FLAGS_KERNEL_BITS + STIX_OBJ_FLAGS_KERNEL_SHIFT) -#define STIX_OBJ_FLAGS_KERNEL_SHIFT (STIX_OBJ_FLAGS_MOVED_BITS + STIX_OBJ_FLAGS_MOVED_SHIFT) -#define STIX_OBJ_FLAGS_MOVED_SHIFT (STIX_OBJ_FLAGS_NGC_BITS + STIX_OBJ_FLAGS_NGC_SHIFT) -#define STIX_OBJ_FLAGS_NGC_SHIFT (STIX_OBJ_FLAGS_TRAILER_BITS + STIX_OBJ_FLAGS_TRAILER_SHIFT) -#define STIX_OBJ_FLAGS_TRAILER_SHIFT (0) - -#define STIX_OBJ_GET_FLAGS_TYPE(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_TYPE_SHIFT, STIX_OBJ_FLAGS_TYPE_BITS) -#define STIX_OBJ_GET_FLAGS_UNIT(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_UNIT_SHIFT, STIX_OBJ_FLAGS_UNIT_BITS) -#define STIX_OBJ_GET_FLAGS_EXTRA(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_EXTRA_SHIFT, STIX_OBJ_FLAGS_EXTRA_BITS) -#define STIX_OBJ_GET_FLAGS_KERNEL(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_KERNEL_SHIFT, STIX_OBJ_FLAGS_KERNEL_BITS) -#define STIX_OBJ_GET_FLAGS_MOVED(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_MOVED_SHIFT, STIX_OBJ_FLAGS_MOVED_BITS) -#define STIX_OBJ_GET_FLAGS_NGC(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_NGC_SHIFT, STIX_OBJ_FLAGS_NGC_BITS) -#define STIX_OBJ_GET_FLAGS_TRAILER(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_TRAILER_SHIFT, STIX_OBJ_FLAGS_TRAILER_BITS) - -#define STIX_OBJ_SET_FLAGS_TYPE(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_TYPE_SHIFT, STIX_OBJ_FLAGS_TYPE_BITS, v) -#define STIX_OBJ_SET_FLAGS_UNIT(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_UNIT_SHIFT, STIX_OBJ_FLAGS_UNIT_BITS, v) -#define STIX_OBJ_SET_FLAGS_EXTRA(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_EXTRA_SHIFT, STIX_OBJ_FLAGS_EXTRA_BITS, v) -#define STIX_OBJ_SET_FLAGS_KERNEL(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_KERNEL_SHIFT, STIX_OBJ_FLAGS_KERNEL_BITS, v) -#define STIX_OBJ_SET_FLAGS_MOVED(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_MOVED_SHIFT, STIX_OBJ_FLAGS_MOVED_BITS, v) -#define STIX_OBJ_SET_FLAGS_NGC(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_NGC_SHIFT, STIX_OBJ_FLAGS_NGC_BITS, v) -#define STIX_OBJ_SET_FLAGS_TRAILER(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_TRAILER_SHIFT, STIX_OBJ_FLAGS_TRAILER_BITS, v) - -#define STIX_OBJ_GET_SIZE(oop) ((oop)->_size) -#define STIX_OBJ_GET_CLASS(oop) ((oop)->_class) - -#define STIX_OBJ_SET_SIZE(oop,v) ((oop)->_size = (v)) -#define STIX_OBJ_SET_CLASS(oop,c) ((oop)->_class = (c)) - -/* [NOTE] this macro doesn't include the size of the trailer */ -#define STIX_OBJ_BYTESOF(oop) ((STIX_OBJ_GET_SIZE(oop) + STIX_OBJ_GET_FLAGS_EXTRA(oop)) * STIX_OBJ_GET_FLAGS_UNIT(oop)) - -/* [NOTE] this macro doesn't check the range of the actual value. - * make sure that the value of each bit fields given falls within the - * possible range of the defined bits */ -#define STIX_OBJ_MAKE_FLAGS(t,u,e,k,m,g,r) ( \ - (((stix_oow_t)(t)) << STIX_OBJ_FLAGS_TYPE_SHIFT) | \ - (((stix_oow_t)(u)) << STIX_OBJ_FLAGS_UNIT_SHIFT) | \ - (((stix_oow_t)(e)) << STIX_OBJ_FLAGS_EXTRA_SHIFT) | \ - (((stix_oow_t)(k)) << STIX_OBJ_FLAGS_KERNEL_SHIFT) | \ - (((stix_oow_t)(m)) << STIX_OBJ_FLAGS_MOVED_SHIFT) | \ - (((stix_oow_t)(g)) << STIX_OBJ_FLAGS_NGC_SHIFT) | \ - (((stix_oow_t)(r)) << STIX_OBJ_FLAGS_TRAILER_SHIFT) \ -) - -#define STIX_OBJ_HEADER \ - stix_oow_t _flags; \ - stix_oow_t _size; \ - stix_oop_t _class - -struct stix_obj_t -{ - STIX_OBJ_HEADER; -}; - -struct stix_obj_oop_t -{ - STIX_OBJ_HEADER; - stix_oop_t slot[1]; -}; - -struct stix_obj_char_t -{ - STIX_OBJ_HEADER; - stix_ooch_t slot[1]; -}; - -struct stix_obj_byte_t -{ - STIX_OBJ_HEADER; - stix_oob_t slot[1]; -}; - -struct stix_obj_halfword_t -{ - STIX_OBJ_HEADER; - stix_oohw_t slot[1]; -}; - -struct stix_obj_word_t -{ - STIX_OBJ_HEADER; - stix_oow_t slot[1]; -}; - -typedef struct stix_trailer_t stix_trailer_t; -struct stix_trailer_t -{ - stix_oow_t size; - stix_oob_t slot[1]; -}; - -#define STIX_SET_NAMED_INSTVARS 2 -typedef struct stix_set_t stix_set_t; -typedef struct stix_set_t* stix_oop_set_t; -struct stix_set_t -{ - STIX_OBJ_HEADER; - stix_oop_t tally; /* SmallInteger */ - stix_oop_oop_t bucket; /* Array */ -}; - -#define STIX_CLASS_NAMED_INSTVARS 11 -typedef struct stix_class_t stix_class_t; -typedef struct stix_class_t* stix_oop_class_t; -struct stix_class_t -{ - STIX_OBJ_HEADER; - - stix_oop_t spec; /* SmallInteger. instance specification */ - stix_oop_t selfspec; /* SmallInteger. specification of the class object itself */ - - stix_oop_t superclass; /* Another class */ - stix_oop_t subclasses; /* Array of subclasses */ - - stix_oop_char_t name; /* Symbol */ - - /* == NEVER CHANGE THIS ORDER OF 3 ITEMS BELOW == */ - stix_oop_char_t instvars; /* String */ - stix_oop_char_t classvars; /* String */ - stix_oop_char_t classinstvars; /* String */ - /* == NEVER CHANGE THE ORDER OF 3 ITEMS ABOVE == */ - - stix_oop_char_t pooldics; /* String - pool dictionaries imported */ - - /* [0] - instance methods, MethodDictionary - * [1] - class methods, MethodDictionary */ - stix_oop_set_t mthdic[STIX_METHOD_TYPE_COUNT]; - - /* indexed part afterwards */ - stix_oop_t slot[1]; /* class instance variables and class variables. */ -}; - -#define STIX_ASSOCIATION_NAMED_INSTVARS 2 -typedef struct stix_association_t stix_association_t; -typedef struct stix_association_t* stix_oop_association_t; -struct stix_association_t -{ - STIX_OBJ_HEADER; - stix_oop_t key; - stix_oop_t value; -}; - -#if defined(STIX_USE_OBJECT_TRAILER) -# define STIX_METHOD_NAMED_INSTVARS 8 -#else -# define STIX_METHOD_NAMED_INSTVARS 9 -#endif -typedef struct stix_method_t stix_method_t; -typedef struct stix_method_t* stix_oop_method_t; -struct stix_method_t -{ - STIX_OBJ_HEADER; - - stix_oop_class_t owner; /* Class */ - - stix_oop_char_t name; /* Symbol, method name */ - - /* primitive number */ - stix_oop_t preamble; /* SmallInteger */ - stix_oop_t preamble_data[2]; /* SmallInteger */ - - /* number of temporaries including arguments */ - stix_oop_t tmpr_count; /* SmallInteger */ - - /* number of arguments in temporaries */ - stix_oop_t tmpr_nargs; /* SmallInteger */ - -#if defined(STIX_USE_OBJECT_TRAILER) - /* no code field is used */ -#else - stix_oop_byte_t code; /* ByteArray */ -#endif - - stix_oop_t source; /* TODO: what should I put? */ - - /* == variable indexed part == */ - stix_oop_t slot[1]; /* it stores literals */ -}; - -#if defined(STIX_USE_OBJECT_TRAILER) - - /* if m is to be type-cast to stix_oop_method_t, the macro must be - * redefined to this: - * (&((stix_oop_method_t)m)>slot[STIX_OBJ_GET_SIZE(m) + 1 - STIX_METHOD_NAMED_INSTVARS]) - */ -# define STIX_METHOD_GET_CODE_BYTE(m) ((stix_oob_t*)&((stix_oop_oop_t)m)->slot[STIX_OBJ_GET_SIZE(m) + 1]) -# define STIX_METHOD_GET_CODE_SIZE(m) ((stix_oow_t)((stix_oop_oop_t)m)->slot[STIX_OBJ_GET_SIZE(m)]) -#else -# define STIX_METHOD_GET_CODE_BYTE(m) ((m)->code->slot) -# define STIX_METHOD_GET_CODE_SIZE(m) STIX_OBJ_GET_SIZE((m)->code) -#endif - -/* The preamble field is composed of: - * 2-bit flag - * 6-bit code - * 16-bit index - * - * The code can be one of the following values: - * 0 - no special action - * 1 - return self - * 2 - return nil - * 3 - return true - * 4 - return false - * 5 - return index. - * 6 - return -index. - * 7 - return instvar[index] - * 8 - do primitive[index] - * 9 - do named primitive[index] - * 10 - exception handler - * 11 - ensure block - */ - -/* NOTE: changing preamble code bit structure requires changes to CompiledMethod>>preambleCode */ -#define STIX_METHOD_MAKE_PREAMBLE(code,index,flags) ((((stix_ooi_t)index) << 8) | ((stix_ooi_t)code << 2) | flags) -#define STIX_METHOD_GET_PREAMBLE_CODE(preamble) ((((stix_ooi_t)preamble) & 0xFF) >> 2) -#define STIX_METHOD_GET_PREAMBLE_INDEX(preamble) (((stix_ooi_t)preamble) >> 8) -#define STIX_METHOD_GET_PREAMBLE_FLAGS(preamble) (((stix_ooi_t)preamble) & 0x3) - -/* preamble codes */ -#define STIX_METHOD_PREAMBLE_NONE 0 -#define STIX_METHOD_PREAMBLE_RETURN_RECEIVER 1 -#define STIX_METHOD_PREAMBLE_RETURN_NIL 2 -#define STIX_METHOD_PREAMBLE_RETURN_TRUE 3 -#define STIX_METHOD_PREAMBLE_RETURN_FALSE 4 -#define STIX_METHOD_PREAMBLE_RETURN_INDEX 5 -#define STIX_METHOD_PREAMBLE_RETURN_NEGINDEX 6 -#define STIX_METHOD_PREAMBLE_RETURN_INSTVAR 7 -#define STIX_METHOD_PREAMBLE_PRIMITIVE 8 -#define STIX_METHOD_PREAMBLE_NAMED_PRIMITIVE 9 /* index is an index to the symbol table */ - -#define STIX_METHOD_PREAMBLE_EXCEPTION 10 /* NOTE changing this requires changes in Except.st */ -#define STIX_METHOD_PREAMBLE_ENSURE 11 /* NOTE changing this requires changes in Except.st */ - -/* the index is an 16-bit unsigned integer. */ -#define STIX_METHOD_PREAMBLE_INDEX_MIN 0x0000 -#define STIX_METHOD_PREAMBLE_INDEX_MAX 0xFFFF -#define STIX_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(num) ((num) >= STIX_METHOD_PREAMBLE_INDEX_MIN && (num) <= STIX_METHOD_PREAMBLE_INDEX_MAX) - -/* preamble flags */ -#define STIX_METHOD_PREAMBLE_FLAG_VARIADIC (1 << 0) - -/* NOTE: if you change the number of instance variables for stix_context_t, - * you need to change the defintion of BlockContext and MethodContext. - * plus, you need to update various exception handling code in MethodContext */ -#define STIX_CONTEXT_NAMED_INSTVARS 8 -typedef struct stix_context_t stix_context_t; -typedef struct stix_context_t* stix_oop_context_t; -struct stix_context_t -{ - STIX_OBJ_HEADER; - - /* it points to the active context at the moment when - * this context object has been activated. a new method context - * is activated as a result of normal message sending and a block - * context is activated when it is sent 'value'. it's set to - * nil if a block context created hasn't received 'value'. */ - stix_oop_context_t sender; - - /* SmallInteger, instruction pointer */ - stix_oop_t ip; - - /* SmallInteger, stack pointer. the actual stack pointer is in the active - * process. For a method context, it stores the stack pointer of the active - * process before it gets activated. the stack pointer of the active - * process is restored using this value upon returning. This field is - * almost useless for a block context. */ - stix_oop_t sp; - - /* SmallInteger. Number of temporaries. - * For a block context, it's inclusive of the temporaries - * defined its 'home'. */ - stix_oop_t ntmprs; - - /* CompiledMethod for a method context, - * SmallInteger for a block context */ - stix_oop_t method_or_nargs; - - /* it points to the receiver of the message for a method context. - * a base block context(created but not yet activated) has nil in this - * field. if a block context is activated by 'value', it points - * to the block context object used as a base for shallow-copy. */ - stix_oop_t receiver_or_source; - - /* it is set to nil for a method context. - * for a block context, it points to the active context at the - * moment the block context was created. that is, it points to - * a method context where the base block has been defined. - * an activated block context copies this field from the source. */ - stix_oop_t home; - - /* when a method context is created, it is set to itself. no change is - * made when the method context is activated. when a block context is - * created (when MAKE_BLOCK or BLOCK_COPY is executed), it is set to the - * origin of the active context. when the block context is shallow-copied - * for activation (when it is sent 'value'), it is set to the origin of - * the source block context. */ - stix_oop_context_t origin; - - /* variable indexed part - actual arguments and temporaries are placed here */ - stix_oop_t slot[1]; /* stack */ -}; - - -#define STIX_PROCESS_NAMED_INSTVARS 7 -typedef struct stix_process_t stix_process_t; -typedef struct stix_process_t* stix_oop_process_t; - -#define STIX_SEMAPHORE_NAMED_INSTVARS 6 -typedef struct stix_semaphore_t stix_semaphore_t; -typedef struct stix_semaphore_t* stix_oop_semaphore_t; - -struct stix_process_t -{ - STIX_OBJ_HEADER; - stix_oop_context_t initial_context; - stix_oop_context_t current_context; - - stix_oop_t state; /* SmallInteger */ - stix_oop_t sp; /* stack pointer. SmallInteger */ - - stix_oop_process_t prev; - stix_oop_process_t next; - - stix_oop_semaphore_t sem; - - /* == variable indexed part == */ - stix_oop_t slot[1]; /* process stack */ -}; - -struct stix_semaphore_t -{ - STIX_OBJ_HEADER; - stix_oop_t count; /* SmallInteger */ - stix_oop_process_t waiting_head; - stix_oop_process_t waiting_tail; - stix_oop_t heap_index; /* index to the heap */ - stix_oop_t heap_ftime_sec; /* firing time */ - stix_oop_t heap_ftime_nsec; /* firing time */ -}; - -#define STIX_PROCESS_SCHEDULER_NAMED_INSTVARS 5 -typedef struct stix_process_scheduler_t stix_process_scheduler_t; -typedef struct stix_process_scheduler_t* stix_oop_process_scheduler_t; -struct stix_process_scheduler_t -{ - STIX_OBJ_HEADER; - stix_oop_t tally; /* SmallInteger, the number of runnable processes */ - stix_oop_process_t active; /* pointer to an active process in the runnable process list */ - stix_oop_process_t runnable_head; /* runnable process list */ - stix_oop_process_t runnable_tail; /* runnable process list */ - stix_oop_t sempq; /* SemaphoreHeap */ -}; - -/** - * The STIX_CLASSOF() macro return the class of an object including a numeric - * object encoded into a pointer. - */ -#define STIX_CLASSOF(stix,oop) \ - (STIX_OOP_GET_TAG(oop)? (*stix->tagged_classes[STIX_OOP_GET_TAG(oop)]): STIX_OBJ_GET_CLASS(oop)) - -/** - * The STIX_BYTESOF() macro returns the size of the payload of - * an object in bytes. If the pointer given encodes a numeric value, - * it returns the size of #stix_oow_t in bytes. - */ -#define STIX_BYTESOF(stix,oop) \ - (STIX_OOP_IS_NUMERIC(oop)? STIX_SIZEOF(stix_oow_t): STIX_OBJ_BYTESOF(oop)) - -/** - * The STIX_ISTYPEOF() macro is a safe replacement for STIX_OBJ_GET_FLAGS_TYPE() - */ -#define STIX_ISTYPEOF(stix,oop,type) \ - (!STIX_OOP_IS_NUMERIC(oop) && STIX_OBJ_GET_FLAGS_TYPE(oop) == (type)) - -typedef struct stix_heap_t stix_heap_t; - -struct stix_heap_t -{ - stix_uint8_t* base; /* start of a heap */ - stix_uint8_t* limit; /* end of a heap */ - stix_uint8_t* ptr; /* next allocation pointer */ -}; - -/* ========================================================================= - * VIRTUAL MACHINE PRIMITIVES - * ========================================================================= */ -typedef void* (*stix_vmprim_opendl_t) (stix_t* stix, const stix_ooch_t* name); -typedef void (*stix_vmprim_closedl_t) (stix_t* stix, void* handle); -typedef void* (*stix_vmprim_getdlsym_t) (stix_t* stix, void* handle, const stix_ooch_t* name); - -typedef void (*stix_log_write_t) (stix_t* stix, stix_oow_t mask, const stix_ooch_t* msg, stix_oow_t len); - -struct stix_vmprim_t -{ - stix_vmprim_opendl_t dl_open; - stix_vmprim_closedl_t dl_close; - stix_vmprim_getdlsym_t dl_getsym; - stix_log_write_t log_write; -}; - -typedef struct stix_vmprim_t stix_vmprim_t; - -/* ========================================================================= - * IO MANIPULATION - * ========================================================================= */ - -/* TODO: MOVE stix_ioimpl_t HERE */ - -/* ========================================================================= - * CALLBACK MANIPULATION - * ========================================================================= */ -typedef void (*stix_cbimpl_t) (stix_t* stix); - -typedef struct stix_cb_t stix_cb_t; -struct stix_cb_t -{ - stix_cbimpl_t gc; - stix_cbimpl_t fini; - - /* private below */ - stix_cb_t* prev; - stix_cb_t* next; -}; - - -/* ========================================================================= - * MODULE MANIPULATION - * ========================================================================= */ -#define STIX_MOD_NAME_LEN_MAX 120 - -enum stix_pfrc_t -{ - STIX_PF_HARD_FAILURE = -1, - STIX_PF_FAILURE = 0, - STIX_PF_SUCCESS = 1 -}; -typedef enum stix_pfrc_t stix_pfrc_t; - -/* primitive function implementation type */ -typedef stix_pfrc_t (*stix_pfimpl_t) ( - stix_t* stix, - stix_ooi_t nargs -); - -typedef struct stix_mod_t stix_mod_t; - -typedef int (*stix_mod_load_t) ( - stix_t* stix, - stix_mod_t* mod -); - -typedef int (*stix_mod_import_t) ( - stix_t* stix, - stix_mod_t* mod, - stix_oop_t _class -); - -typedef stix_pfimpl_t (*stix_mod_query_t) ( - stix_t* stix, - stix_mod_t* mod, - const stix_uch_t* name -); - -typedef void (*stix_mod_unload_t) ( - stix_t* stix, - stix_mod_t* mod -); - -struct stix_mod_t -{ - const stix_ooch_t name[STIX_MOD_NAME_LEN_MAX + 1]; - stix_mod_import_t import; - stix_mod_query_t query; - stix_mod_unload_t unload; - void* ctx; -}; - -struct stix_mod_data_t -{ - void* handle; - stix_rbt_pair_t* pair; /* internal backreference to stix->modtab */ - stix_mod_t mod; -}; -typedef struct stix_mod_data_t stix_mod_data_t; - - - -struct stix_sbuf_t -{ - stix_ooch_t* ptr; - stix_oow_t len; - stix_oow_t capa; -}; -typedef struct stix_sbuf_t stix_sbuf_t; - -/* ========================================================================= - * STIX VM - * ========================================================================= */ -#if defined(STIX_INCLUDE_COMPILER) -typedef struct stix_compiler_t stix_compiler_t; -#endif - -struct stix_t -{ - stix_mmgr_t* mmgr; - stix_cmgr_t* cmgr; - stix_errnum_t errnum; - - struct - { - unsigned int trait; - unsigned int log_mask; - stix_oow_t dfl_symtab_size; - stix_oow_t dfl_sysdic_size; - stix_oow_t dfl_procstk_size; - } option; - - stix_vmprim_t vmprim; - - stix_cb_t* cblist; - stix_rbt_t modtab; /* primitive module table */ - - struct - { - stix_ooch_t* ptr; - stix_oow_t len; - stix_oow_t capa; - int last_mask; - } log; - - /* ========================= */ - - stix_heap_t* permheap; /* TODO: put kernel objects to here */ - stix_heap_t* curheap; - stix_heap_t* newheap; - - /* ============================================================= - * nil, true, false - * ============================================================= */ - stix_oop_t _nil; /* pointer to the nil object */ - stix_oop_t _true; - stix_oop_t _false; - - /* ============================================================= - * KERNEL CLASSES - * Be sure to Keep these kernel class pointers registered in the - * kernel_classes table in gc.c - * ============================================================= */ - stix_oop_t _apex; /* Apex */ - stix_oop_t _undefined_object; /* UndefinedObject */ - stix_oop_t _class; /* Class */ - stix_oop_t _object; /* Object */ - stix_oop_t _string; /* String */ - - stix_oop_t _symbol; /* Symbol */ - stix_oop_t _array; /* Array */ - stix_oop_t _byte_array; /* ByteArray */ - stix_oop_t _symbol_set; /* SymbolSet */ - stix_oop_t _system_dictionary; /* SystemDictionary */ - - stix_oop_t _namespace; /* Namespace */ - stix_oop_t _pool_dictionary; /* PoolDictionary */ - stix_oop_t _method_dictionary; /* MethodDictionary */ - stix_oop_t _method; /* CompiledMethod */ - stix_oop_t _association; /* Association */ - - stix_oop_t _method_context; /* MethodContext */ - stix_oop_t _block_context; /* BlockContext */ - stix_oop_t _process; /* Process */ - stix_oop_t _semaphore; /* Semaphore */ - stix_oop_t _process_scheduler; /* ProcessScheduler */ - - stix_oop_t _error_class; /* Error */ - stix_oop_t _true_class; /* True */ - stix_oop_t _false_class; /* False */ - stix_oop_t _character; /* Character */ - stix_oop_t _small_integer; /* SmallInteger */ - - stix_oop_t _large_positive_integer; /* LargePositiveInteger */ - stix_oop_t _large_negative_integer; /* LargeNegativeInteger */ - /* ============================================================= - * END KERNEL CLASSES - * ============================================================= */ - - /* ============================================================= - * KEY SYSTEM DICTIONARIES - * ============================================================= */ - stix_oop_t* tagged_classes[4]; - stix_oop_set_t symtab; /* system-wide symbol table. instance of SymbolSet */ - stix_oop_set_t sysdic; /* system dictionary. instance of SystemDictionary */ - stix_oop_process_scheduler_t processor; /* instance of ProcessScheduler */ - stix_oop_process_t nil_process; /* instance of Process */ - - /* pending asynchronous semaphores */ - stix_oop_semaphore_t* sem_list; - stix_oow_t sem_list_count; - stix_oow_t sem_list_capa; - - /* semaphores sorted according to time-out */ - stix_oop_semaphore_t* sem_heap; - stix_oow_t sem_heap_count; - stix_oow_t sem_heap_capa; - - stix_oop_t* tmp_stack[256]; /* stack for temporaries */ - stix_oow_t tmp_count; - - /* ============================================================= - * EXECUTION REGISTERS - * ============================================================= */ - stix_oop_context_t initial_context; /* fake initial context */ - stix_oop_context_t active_context; - stix_oop_method_t active_method; - stix_oob_t* active_code; - stix_ooi_t sp; - stix_ooi_t ip; - int proc_switched; /* TODO: this is temporary. implement something else to skip immediate context switching */ - int switch_proc; - stix_ntime_t vm_time_offset; - /* ============================================================= - * END EXECUTION REGISTERS - * ============================================================= */ - - /* == BIGINT CONVERSION == */ - struct - { - int safe_ndigits; - stix_oow_t multiplier; - } bigint[37]; - /* == END BIGINT CONVERSION == */ - - stix_sbuf_t sbuf[64]; - -#if defined(STIX_INCLUDE_COMPILER) - stix_compiler_t* c; -#endif -}; - - -/* TODO: stack bound check when pushing */ -#define STIX_STACK_PUSH(stix,v) \ - do { \ - (stix)->sp = (stix)->sp + 1; \ - (stix)->processor->active->slot[(stix)->sp] = v; \ - } while (0) - -#define STIX_STACK_GET(stix,v_sp) ((stix)->processor->active->slot[v_sp]) -#define STIX_STACK_SET(stix,v_sp,v_obj) ((stix)->processor->active->slot[v_sp] = v_obj) - -#define STIX_STACK_GETTOP(stix) STIX_STACK_GET(stix, (stix)->sp) -#define STIX_STACK_SETTOP(stix,v_obj) STIX_STACK_SET(stix, (stix)->sp, v_obj) - -#define STIX_STACK_POP(stix) ((stix)->sp = (stix)->sp - 1) -#define STIX_STACK_POPS(stix,count) ((stix)->sp = (stix)->sp - (count)) -#define STIX_STACK_ISEMPTY(stix) ((stix)->sp <= -1) - -#define STIX_STACK_GETARG(stix,nargs,idx) STIX_STACK_GET(stix, (stix)->sp - ((nargs) - (idx) - 1)) -#define STIX_STACK_GETRCV(stix,nargs) STIX_STACK_GET(stix, (stix)->sp - nargs); - -/* you can't access arguments and receiver after this macro. - * also you must not call this macro more than once */ -#define STIX_STACK_SETRET(stix,nargs,retv) (STIX_STACK_POPS(stix, nargs), STIX_STACK_SETTOP(stix, (retv))) -#define STIX_STACK_SETRETTORCV(stix,nargs) (STIX_STACK_POPS(stix, nargs)) -#define STIX_STACK_SETRETTOERROR(stix,nargs) STIX_STACK_SETRET(stix, nargs, STIX_ERROR_TO_OOP(stix->errnum)) -/*#define STIX_STACK_SETRETTOERROR(stix,nargs,ec) STIX_STACK_SETRET(stix, nargs, STIX_ERROR_TO_OOP(ec))*/ - -/* ========================================================================= - * STIX VM LOGGING - * ========================================================================= */ - -enum stix_log_mask_t -{ - STIX_LOG_DEBUG = (1 << 0), - STIX_LOG_INFO = (1 << 1), - STIX_LOG_WARN = (1 << 2), - STIX_LOG_ERROR = (1 << 3), - STIX_LOG_FATAL = (1 << 4), - - STIX_LOG_MNEMONIC = (1 << 8), /* bytecode mnemonic */ - STIX_LOG_GC = (1 << 9), - STIX_LOG_IC = (1 << 10), /* instruction cycle, fetch-decode-execute */ - STIX_LOG_PRIMITIVE = (1 << 11), - STIX_LOG_APP = (1 << 12) /* stix applications, set by stix logging primitive */ -}; -typedef enum stix_log_mask_t stix_log_mask_t; - -#define STIX_LOG_ENABLED(stix,mask) ((stix)->option.log_mask & (mask)) - -#define STIX_LOG0(stix,mask,fmt) do { if (STIX_LOG_ENABLED(stix,mask)) stix_logbfmt(stix, mask, fmt); } while(0) -#define STIX_LOG1(stix,mask,fmt,a1) do { if (STIX_LOG_ENABLED(stix,mask)) stix_logbfmt(stix, mask, fmt, a1); } while(0) -#define STIX_LOG2(stix,mask,fmt,a1,a2) do { if (STIX_LOG_ENABLED(stix,mask)) stix_logbfmt(stix, mask, fmt, a1, a2); } while(0) -#define STIX_LOG3(stix,mask,fmt,a1,a2,a3) do { if (STIX_LOG_ENABLED(stix,mask)) stix_logbfmt(stix, mask, fmt, a1, a2, a3); } while(0) -#define STIX_LOG4(stix,mask,fmt,a1,a2,a3,a4) do { if (STIX_LOG_ENABLED(stix,mask)) stix_logbfmt(stix, mask, fmt, a1, a2, a3, a4); } while(0) -#define STIX_LOG5(stix,mask,fmt,a1,a2,a3,a4,a5) do { if (STIX_LOG_ENABLED(stix,mask)) stix_logbfmt(stix, mask, fmt, a1, a2, a3, a4, a5); } while(0) -#define STIX_LOG6(stix,mask,fmt,a1,a2,a3,a4,a5,a6) do { if (STIX_LOG_ENABLED(stix,mask)) stix_logbfmt(stix, mask, fmt, a1, a2, a3, a4, a5, a6); } while(0) - -#define STIX_DEBUG0(stix,fmt) STIX_LOG0(stix, STIX_LOG_DEBUG, fmt) -#define STIX_DEBUG1(stix,fmt,a1) STIX_LOG1(stix, STIX_LOG_DEBUG, fmt, a1) -#define STIX_DEBUG2(stix,fmt,a1,a2) STIX_LOG2(stix, STIX_LOG_DEBUG, fmt, a1, a2) -#define STIX_DEBUG3(stix,fmt,a1,a2,a3) STIX_LOG3(stix, STIX_LOG_DEBUG, fmt, a1, a2, a3) -#define STIX_DEBUG4(stix,fmt,a1,a2,a3,a4) STIX_LOG4(stix, STIX_LOG_DEBUG, fmt, a1, a2, a3, a4) -#define STIX_DEBUG5(stix,fmt,a1,a2,a3,a4,a5) STIX_LOG5(stix, STIX_LOG_DEBUG, fmt, a1, a2, a3, a4, a5) -#define STIX_DEBUG6(stix,fmt,a1,a2,a3,a4,a5,a6) STIX_LOG6(stix, STIX_LOG_DEBUG, fmt, a1, a2, a3, a4, a5, a6) - -#define STIX_INFO0(stix,fmt) STIX_LOG0(stix, STIX_LOG_INFO, fmt) -#define STIX_INFO1(stix,fmt,a1) STIX_LOG1(stix, STIX_LOG_INFO, fmt, a1) -#define STIX_INFO2(stix,fmt,a1,a2) STIX_LOG2(stix, STIX_LOG_INFO, fmt, a1, a2) -#define STIX_INFO3(stix,fmt,a1,a2,a3) STIX_LOG3(stix, STIX_LOG_INFO, fmt, a1, a2, a3) -#define STIX_INFO4(stix,fmt,a1,a2,a3,a4) STIX_LOG4(stix, STIX_LOG_INFO, fmt, a1, a2, a3, a4) -#define STIX_INFO5(stix,fmt,a1,a2,a3,a4,a5) STIX_LOG5(stix, STIX_LOG_INFO, fmt, a1, a2, a3, a4, a5) -#define STIX_INFO6(stix,fmt,a1,a2,a3,a4,a5,a6) STIX_LOG6(stix, STIX_LOG_INFO, fmt, a1, a2, a3, a4, a5, a6) - - -/* ========================================================================= - * STIX ASSERTION - * ========================================================================= */ -#if defined(NDEBUG) -# define STIX_ASSERT(stix,expr) ((void)0) -#else -# define STIX_ASSERT(stix,expr) ((void)((expr) || (stix_assertfailed (stix, #expr, __FILE__, __LINE__), 0))) -#endif - - -#if defined(STIX_INCLUDE_COMPILER) -enum stix_iocmd_t -{ - STIX_IO_OPEN, - STIX_IO_CLOSE, - STIX_IO_READ -}; -typedef enum stix_iocmd_t stix_iocmd_t; - -struct stix_ioloc_t -{ - unsigned long int line; /**< line */ - unsigned long int colm; /**< column */ - const stix_ooch_t* file; /**< file specified in #include */ -}; -typedef struct stix_ioloc_t stix_ioloc_t; - -typedef struct stix_ioarg_t stix_ioarg_t; - -typedef stix_ooi_t (*stix_ioimpl_t) ( - stix_t* stix, - stix_iocmd_t cmd, - stix_ioarg_t* arg -); - -enum stix_synerrnum_t -{ - STIX_SYNERR_NOERR, - STIX_SYNERR_ILCHR, /* illegal character */ - STIX_SYNERR_CMTNC, /* comment not closed */ - STIX_SYNERR_STRNC, /* string not closed */ - STIX_SYNERR_CLTNT, /* character literal not terminated */ - STIX_SYNERR_HLTNT, /* hased literal not terminated */ - STIX_SYNERR_CHARLIT, /* wrong character literal */ - STIX_SYNERR_COLON, /* : expected */ - STIX_SYNERR_STRING, /* string expected */ - STIX_SYNERR_RADIX, /* invalid radix */ - STIX_SYNERR_RADNUMLIT, /* invalid numeric literal with radix */ - STIX_SYNERR_BYTERANGE, /* byte too small or too large */ - STIX_SYNERR_ERRLIT, /* wrong error literal */ - STIX_SYNERR_LBRACE, /* { expected */ - STIX_SYNERR_RBRACE, /* } expected */ - STIX_SYNERR_LPAREN, /* ( expected */ - STIX_SYNERR_RPAREN, /* ) expected */ - STIX_SYNERR_RBRACK, /* ] expected */ - STIX_SYNERR_PERIOD, /* . expected */ - STIX_SYNERR_COMMA, /* , expected */ - STIX_SYNERR_VBAR, /* | expected */ - STIX_SYNERR_GT, /* > expected */ - STIX_SYNERR_ASSIGN, /* := expected */ - STIX_SYNERR_IDENT, /* identifier expected */ - STIX_SYNERR_INTEGER, /* integer expected */ - STIX_SYNERR_PRIMITIVE, /* primitive: expected */ - STIX_SYNERR_DIRECTIVE, /* wrong directive */ - STIX_SYNERR_CLASSUNDEF, /* undefined class */ - STIX_SYNERR_CLASSDUP, /* duplicate class */ - STIX_SYNERR_CLASSCONTRA, /* contradictory class */ - STIX_SYNERR_CLASSNAME, /* wrong class name */ - STIX_SYNERR_DCLBANNED, /* #dcl not allowed */ - STIX_SYNERR_MTHNAME, /* wrong method name */ - STIX_SYNERR_MTHNAMEDUP, /* duplicate method name */ - STIX_SYNERR_ARGNAMEDUP, /* duplicate argument name */ - STIX_SYNERR_TMPRNAMEDUP, /* duplicate temporary variable name */ - STIX_SYNERR_VARNAMEDUP, /* duplicate variable name */ - STIX_SYNERR_BLKARGNAMEDUP, /* duplicate block argument name */ - STIX_SYNERR_VARARG, /* cannot assign to argument */ - STIX_SYNERR_VARUNDCL, /* undeclared variable */ - STIX_SYNERR_VARUNUSE, /* unsuable variable in compiled code */ - STIX_SYNERR_VARINACC, /* inaccessible variable - e.g. accessing an instance variable from a class method is not allowed. */ - STIX_SYNERR_VARAMBIG, /* ambiguious variable - e.g. the variable is found in multiple pool dictionaries imported */ - STIX_SYNERR_PRIMARY, /* wrong expression primary */ - STIX_SYNERR_TMPRFLOOD, /* too many temporaries */ - STIX_SYNERR_ARGFLOOD, /* too many arguments */ - STIX_SYNERR_BLKTMPRFLOOD, /* too many block temporaries */ - STIX_SYNERR_BLKARGFLOOD, /* too many block arguments */ - STIX_SYNERR_BLKFLOOD, /* too large block */ - STIX_SYNERR_PFNUM, /* wrong primitive number */ - STIX_SYNERR_PFID, /* wrong primitive identifier */ - STIX_SYNERR_MODNAME, /* wrong module name */ - STIX_SYNERR_INCLUDE, /* #include error */ - STIX_SYNERR_NAMESPACE, /* wrong namespace name */ - STIX_SYNERR_POOLDIC, /* wrong pool dictionary */ - STIX_SYNERR_POOLDICDUP, /* duplicate pool dictionary */ - STIX_SYNERR_LITERAL /* literal expected */ -}; -typedef enum stix_synerrnum_t stix_synerrnum_t; - -struct stix_synerr_t -{ - stix_synerrnum_t num; - stix_ioloc_t loc; - stix_oocs_t tgt; -}; -typedef struct stix_synerr_t stix_synerr_t; -#endif - -#if defined(__cplusplus) -extern "C" { -#endif - -#define stix_switchprocess(stix) ((stix)->switch_proc = 1) - - -STIX_EXPORT stix_t* stix_open ( - stix_mmgr_t* mmgr, - stix_oow_t xtnsize, - stix_oow_t heapsize, - const stix_vmprim_t* vmprim, - stix_errnum_t* errnum -); - -STIX_EXPORT void stix_close ( - stix_t* stix -); - -STIX_EXPORT int stix_init ( - stix_t* stix, - stix_mmgr_t* mmgr, - stix_oow_t heapsize, - const stix_vmprim_t* vmprim -); - -STIX_EXPORT void stix_fini ( - stix_t* stix -); - -#if defined(STIX_HAVE_INLINE) - static STIX_INLINE stix_mmgr_t* stix_getmmgr (stix_t* stix) { return stix->mmgr; } - static STIX_INLINE void* stix_getxtn (stix_t* stix) { return (void*)(stix + 1); } - - static STIX_INLINE stix_cmgr_t* stix_getcmgr (stix_t* stix) { return stix->cmgr; } - static STIX_INLINE void stix_setcmgr (stix_t* stix, stix_cmgr_t* cmgr) { stix->cmgr = cmgr; } - - static STIX_INLINE stix_errnum_t stix_geterrnum (stix_t* stix) { return stix->errnum; } - static STIX_INLINE void stix_seterrnum (stix_t* stix, stix_errnum_t errnum) { stix->errnum = errnum; } -#else -# define stix_getmmgr(stix) ((stix)->mmgr) -# define stix_getxtn(stix) ((void*)((stix) + 1)) - -# define stix_getcmgr(stix) ((stix)->cmgr) -# define stix_setcmgr(stix,mgr) ((stix)->cmgr = (mgr)) - -# define stix_geterrnum(stix) ((stix)->errnum) -# define stix_seterrnum(stix,num) ((stix)->errnum = (num)) -#endif - -STIX_EXPORT const stix_ooch_t* stix_geterrstr ( - stix_t* stix -); - -/** - * The stix_getoption() function gets the value of an option - * specified by \a id into the buffer pointed to by \a value. - * - * \return 0 on success, -1 on failure - */ -STIX_EXPORT int stix_getoption ( - stix_t* stix, - stix_option_t id, - void* value -); - -/** - * The stix_setoption() function sets the value of an option - * specified by \a id to the value pointed to by \a value. - * - * \return 0 on success, -1 on failure - */ -STIX_EXPORT int stix_setoption ( - stix_t* stix, - stix_option_t id, - const void* value -); - - -STIX_EXPORT stix_cb_t* stix_regcb ( - stix_t* stix, - stix_cb_t* tmpl -); - -STIX_EXPORT void stix_deregcb ( - stix_t* stix, - stix_cb_t* cb -); - -/** - * The stix_gc() function performs garbage collection. - * It is not affected by #STIX_NOGC. - */ -STIX_EXPORT void stix_gc ( - stix_t* stix -); - - -/** - * The stix_instantiate() function creates a new object of the class - * \a _class. The size of the fixed part is taken from the information - * contained in the class defintion. The \a vlen parameter specifies - * the length of the variable part. The \a vptr parameter points to - * the memory area to copy into the variable part of the new object. - * If \a vptr is #STIX_NULL, the variable part is initialized to 0 or - * an equivalent value depending on the type. - */ -STIX_EXPORT stix_oop_t stix_instantiate ( - stix_t* stix, - stix_oop_t _class, - const void* vptr, - stix_oow_t vlen -); - -STIX_EXPORT stix_oop_t stix_shallowcopy ( - stix_t* stix, - stix_oop_t oop -); - -/** - * The stix_ignite() function creates key initial objects. - */ -STIX_EXPORT int stix_ignite ( - stix_t* stix -); - -/** - * The stix_execute() function executes an activated context. - */ -STIX_EXPORT int stix_execute ( - stix_t* stix -); - -/** - * The stix_invoke() function sends a message named \a mthname to an object - * named \a objname. - */ -STIX_EXPORT int stix_invoke ( - stix_t* stix, - const stix_oocs_t* objname, - const stix_oocs_t* mthname -); - -/* Temporary OOP management */ -STIX_EXPORT void stix_pushtmp ( - stix_t* stix, - stix_oop_t* oop_ptr -); - -STIX_EXPORT void stix_poptmp ( - stix_t* stix -); - -STIX_EXPORT void stix_poptmps ( - stix_t* stix, - stix_oow_t count -); - -/* ========================================================================= - * SYSTEM MEMORY MANAGEMENT FUCNTIONS VIA MMGR - * ========================================================================= */ -STIX_EXPORT void* stix_allocmem ( - stix_t* stix, - stix_oow_t size -); - -STIX_EXPORT void* stix_callocmem ( - stix_t* stix, - stix_oow_t size -); - -STIX_EXPORT void* stix_reallocmem ( - stix_t* stix, - void* ptr, - stix_oow_t size -); - -STIX_EXPORT void stix_freemem ( - stix_t* stix, - void* ptr -); - - -/* ========================================================================= - * PRIMITIVE METHOD MANIPULATION - * ========================================================================= */ -STIX_EXPORT int stix_genpfmethod ( - stix_t* stix, - stix_mod_t* mod, - stix_oop_t _class, - stix_method_type_t type, - const stix_ooch_t* mthname, - int variadic, - const stix_ooch_t* name -); - -/* ========================================================================= - * STRING ENCODING CONVERSION - * ========================================================================= */ - -#if defined(STIX_OOCH_IS_UCH) -# define stix_convootobchars(stix,oocs,oocslen,bcs,bcslen) stix_convutobchars(stix,oocs,oocslen,bcs,bcslen) -# define stix_convbtooochars(stix,bcs,bcslen,oocs,oocslen) stix_convbtouchars(stix,bcs,bcslen,oocs,oocslen) -# define stix_convootobcstr(stix,oocs,oocslen,bcs,bcslen) stix_convutobcstr(stix,oocs,oocslen,bcs,bcslen) -# define stix_convbtooocstr(stix,bcs,bcslen,oocs,oocslen) stix_convbtoucstr(stix,bcs,bcslen,oocs,oocslen) -#else -# define stix_convootouchars(stix,oocs,oocslen,bcs,bcslen) stix_convbtouchars(stix,oocs,oocslen,bcs,bcslen) -# define stix_convutooochars(stix,bcs,bcslen,oocs,oocslen) stix_convutobchars(stix,bcs,bcslen,oocs,oocslen) -# define stix_convootoucstr(stix,oocs,oocslen,bcs,bcslen) stix_convbtoucstr(stix,oocs,oocslen,bcs,bcslen) -# define stix_convutooocstr(stix,bcs,bcslen,oocs,oocslen) stix_convutobcstr(stix,bcs,bcslen,oocs,oocslen) -#endif - -STIX_EXPORT int stix_convbtouchars ( - stix_t* stix, - const stix_bch_t* bcs, - stix_oow_t* bcslen, - stix_uch_t* ucs, - stix_oow_t* ucslen -); - -STIX_EXPORT int stix_convutobchars ( - stix_t* stix, - const stix_uch_t* ucs, - stix_oow_t* ucslen, - stix_bch_t* bcs, - stix_oow_t* bcslen -); - - -/** - * The stix_convbtoucstr() function converts a null-terminated byte string - * to a wide string. - */ -STIX_EXPORT int stix_convbtoucstr ( - stix_t* stix, - const stix_bch_t* bcs, - stix_oow_t* bcslen, - stix_uch_t* ucs, - stix_oow_t* ucslen -); - - -/** - * The stix_convutobcstr() function converts a null-terminated wide string - * to a byte string. - */ -int stix_convutobcstr ( - stix_t* stix, - const stix_uch_t* ucs, - stix_oow_t* ucslen, - stix_bch_t* bcs, - stix_oow_t* bcslen -); - -/* ========================================================================= - * STIX VM LOGGING - * ========================================================================= */ - -STIX_EXPORT stix_ooi_t stix_logbfmt ( - stix_t* stix, - stix_oow_t mask, - const stix_bch_t* fmt, - ... -); - -STIX_EXPORT stix_ooi_t stix_logufmt ( - stix_t* stix, - stix_oow_t mask, - const stix_uch_t* fmt, - ... -); - -#if defined(STIX_OOCH_IS_UCH) -# define stix_logoofmt stix_logufmt -#else -# define stix_logoofmt stix_logbfmt -#endif - -/* ========================================================================= - * MISCELLANEOUS HELPER FUNCTIONS - * ========================================================================= */ - -STIX_EXPORT int stix_decode ( - stix_t* stix, - stix_oop_method_t mth, - const stix_oocs_t* classfqn -); - -STIX_EXPORT void stix_assertfailed ( - stix_t* stix, - const stix_bch_t* expr, - const stix_bch_t* file, - stix_oow_t line -); - -STIX_EXPORT stix_errnum_t stix_syserrtoerrnum ( - int syserr -); - -STIX_EXPORT const stix_ooch_t* stix_errnumtoerrstr ( - stix_errnum_t errnum -); - -#if defined(STIX_INCLUDE_COMPILER) - -STIX_EXPORT int stix_compile ( - stix_t* stix, - stix_ioimpl_t io -); - -STIX_EXPORT void stix_getsynerr ( - stix_t* stix, - stix_synerr_t* synerr -); - -STIX_EXPORT const stix_ooch_t* stix_synerrnumtoerrstr ( - stix_synerrnum_t errnum -); -#endif - -#if defined(__cplusplus) -} -#endif - - -#endif diff --git a/stix/lib/sym.c b/stix/lib/sym.c index b06649b..8a49371 100644 --- a/stix/lib/sym.c +++ b/stix/lib/sym.c @@ -24,15 +24,15 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "stix-prv.h" +#include "moo-prv.h" -static stix_oop_oop_t expand_bucket (stix_t* stix, stix_oop_oop_t oldbuc) +static moo_oop_oop_t expand_bucket (moo_t* moo, moo_oop_oop_t oldbuc) { - stix_oop_oop_t newbuc; - stix_oow_t oldsz, newsz, index; - stix_oop_char_t symbol; + moo_oop_oop_t newbuc; + moo_oow_t oldsz, newsz, index; + moo_oop_char_t symbol; - oldsz = STIX_OBJ_GET_SIZE(oldbuc); + oldsz = MOO_OBJ_GET_SIZE(oldbuc); /* TODO: better growth policy? */ if (oldsz < 5000) newsz = oldsz + oldsz; @@ -44,100 +44,100 @@ static stix_oop_oop_t expand_bucket (stix_t* stix, stix_oop_oop_t oldbuc) else if (oldsz < 1600000) newsz = oldsz + (oldsz / 64); else { - stix_oow_t inc, inc_max; + moo_oow_t inc, inc_max; inc = oldsz / 128; - inc_max = STIX_OBJ_SIZE_MAX - oldsz; + inc_max = MOO_OBJ_SIZE_MAX - oldsz; if (inc > inc_max) { if (inc_max > 0) inc = inc_max; else { - stix->errnum = STIX_EOOMEM; - return STIX_NULL; + moo->errnum = MOO_EOOMEM; + return MOO_NULL; } } newsz = oldsz + inc; } - stix_pushtmp (stix, (stix_oop_t*)&oldbuc); - newbuc = (stix_oop_oop_t)stix_instantiate (stix, stix->_array, STIX_NULL, newsz); - stix_poptmp (stix); - if (!newbuc) return STIX_NULL; + moo_pushtmp (moo, (moo_oop_t*)&oldbuc); + newbuc = (moo_oop_oop_t)moo_instantiate (moo, moo->_array, MOO_NULL, newsz); + moo_poptmp (moo); + if (!newbuc) return MOO_NULL; while (oldsz > 0) { - symbol = (stix_oop_char_t)oldbuc->slot[--oldsz]; - if ((stix_oop_t)symbol != stix->_nil) + symbol = (moo_oop_char_t)oldbuc->slot[--oldsz]; + if ((moo_oop_t)symbol != moo->_nil) { - STIX_ASSERT (stix, STIX_CLASSOF(stix,symbol) == stix->_symbol); - /*STIX_ASSERT (stix, sym->size > 0);*/ + MOO_ASSERT (moo, MOO_CLASSOF(moo,symbol) == moo->_symbol); + /*MOO_ASSERT (moo, sym->size > 0);*/ - index = stix_hashoochars(symbol->slot, STIX_OBJ_GET_SIZE(symbol)) % newsz; - while (newbuc->slot[index] != stix->_nil) index = (index + 1) % newsz; - newbuc->slot[index] = (stix_oop_t)symbol; + index = moo_hashoochars(symbol->slot, MOO_OBJ_GET_SIZE(symbol)) % newsz; + while (newbuc->slot[index] != moo->_nil) index = (index + 1) % newsz; + newbuc->slot[index] = (moo_oop_t)symbol; } } return newbuc; } -static stix_oop_t find_or_make_symbol (stix_t* stix, const stix_ooch_t* ptr, stix_oow_t len, int create) +static moo_oop_t find_or_make_symbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow_t len, int create) { - stix_ooi_t tally; - stix_oow_t index; - stix_oop_char_t symbol; + moo_ooi_t tally; + moo_oow_t index; + moo_oop_char_t symbol; - STIX_ASSERT (stix, len > 0); + MOO_ASSERT (moo, len > 0); if (len <= 0) { /* i don't allow an empty symbol name */ - stix->errnum = STIX_EINVAL; - return STIX_NULL; + moo->errnum = MOO_EINVAL; + return MOO_NULL; } - STIX_ASSERT (stix, STIX_CLASSOF(stix,stix->symtab->bucket) == stix->_array); - index = stix_hashoochars(ptr, len) % STIX_OBJ_GET_SIZE(stix->symtab->bucket); + MOO_ASSERT (moo, MOO_CLASSOF(moo,moo->symtab->bucket) == moo->_array); + index = moo_hashoochars(ptr, len) % MOO_OBJ_GET_SIZE(moo->symtab->bucket); /* find a matching symbol in the open-addressed symbol table */ - while (stix->symtab->bucket->slot[index] != stix->_nil) + while (moo->symtab->bucket->slot[index] != moo->_nil) { - symbol = (stix_oop_char_t)stix->symtab->bucket->slot[index]; - STIX_ASSERT (stix, STIX_CLASSOF(stix,symbol) == (stix_oop_t)stix->_symbol); + symbol = (moo_oop_char_t)moo->symtab->bucket->slot[index]; + MOO_ASSERT (moo, MOO_CLASSOF(moo,symbol) == (moo_oop_t)moo->_symbol); - if (len == STIX_OBJ_GET_SIZE(symbol) && - stix_equaloochars (ptr, symbol->slot, len)) + if (len == MOO_OBJ_GET_SIZE(symbol) && + moo_equaloochars (ptr, symbol->slot, len)) { - return (stix_oop_t)symbol; + return (moo_oop_t)symbol; } - index = (index + 1) % STIX_OBJ_GET_SIZE(stix->symtab->bucket); + index = (index + 1) % MOO_OBJ_GET_SIZE(moo->symtab->bucket); } if (!create) { - stix->errnum = STIX_ENOENT; - return STIX_NULL; + moo->errnum = MOO_ENOENT; + return MOO_NULL; } /* make a new symbol and insert it */ - STIX_ASSERT (stix, STIX_OOP_IS_SMOOI(stix->symtab->tally)); - tally = STIX_OOP_TO_SMOOI(stix->symtab->tally); - if (tally >= STIX_SMOOI_MAX) + MOO_ASSERT (moo, MOO_OOP_IS_SMOOI(moo->symtab->tally)); + tally = MOO_OOP_TO_SMOOI(moo->symtab->tally); + if (tally >= MOO_SMOOI_MAX) { /* this built-in table is not allowed to hold more than - * STIX_SMOOI_MAX items for efficiency sake */ - stix->errnum = STIX_EDFULL; - return STIX_NULL; + * MOO_SMOOI_MAX items for efficiency sake */ + moo->errnum = MOO_EDFULL; + return MOO_NULL; } - /* no conversion to stix_oow_t is necessary for tally + 1. - * the maximum value of tally is checked to be STIX_SMOOI_MAX - 1. - * tally + 1 can produce at most STIX_SMOOI_MAX. above all, - * STIX_SMOOI_MAX is way smaller than STIX_TYPE_MAX(stix_ooi_t). */ - if (tally + 1 >= STIX_OBJ_GET_SIZE(stix->symtab->bucket)) + /* no conversion to moo_oow_t is necessary for tally + 1. + * the maximum value of tally is checked to be MOO_SMOOI_MAX - 1. + * tally + 1 can produce at most MOO_SMOOI_MAX. above all, + * MOO_SMOOI_MAX is way smaller than MOO_TYPE_MAX(moo_ooi_t). */ + if (tally + 1 >= MOO_OBJ_GET_SIZE(moo->symtab->bucket)) { - stix_oop_oop_t bucket; + moo_oop_oop_t bucket; /* TODO: make the growth policy configurable instead of growing it just before it gets full. The polcy can be grow it @@ -147,40 +147,40 @@ static stix_oop_t find_or_make_symbol (stix_t* stix, const stix_ooch_t* ptr, sti * make sure that it has at least one free slot left * after having added a new symbol. this is to help * traversal end at a _nil slot if no entry is found. */ - bucket = expand_bucket(stix, stix->symtab->bucket); - if (!bucket) return STIX_NULL; + bucket = expand_bucket(moo, moo->symtab->bucket); + if (!bucket) return MOO_NULL; - stix->symtab->bucket = bucket; + moo->symtab->bucket = bucket; /* recalculate the index for the expanded bucket */ - index = stix_hashoochars(ptr, len) % STIX_OBJ_GET_SIZE(stix->symtab->bucket); + index = moo_hashoochars(ptr, len) % MOO_OBJ_GET_SIZE(moo->symtab->bucket); - while (stix->symtab->bucket->slot[index] != stix->_nil) - index = (index + 1) % STIX_OBJ_GET_SIZE(stix->symtab->bucket); + while (moo->symtab->bucket->slot[index] != moo->_nil) + index = (index + 1) % MOO_OBJ_GET_SIZE(moo->symtab->bucket); } /* create a new symbol since it isn't found in the symbol table */ - symbol = (stix_oop_char_t)stix_instantiate(stix, stix->_symbol, ptr, len); + symbol = (moo_oop_char_t)moo_instantiate(moo, moo->_symbol, ptr, len); if (symbol) { - STIX_ASSERT (stix, tally < STIX_SMOOI_MAX); - stix->symtab->tally = STIX_SMOOI_TO_OOP(tally + 1); - stix->symtab->bucket->slot[index] = (stix_oop_t)symbol; + MOO_ASSERT (moo, tally < MOO_SMOOI_MAX); + moo->symtab->tally = MOO_SMOOI_TO_OOP(tally + 1); + moo->symtab->bucket->slot[index] = (moo_oop_t)symbol; } - return (stix_oop_t)symbol; + return (moo_oop_t)symbol; } -stix_oop_t stix_makesymbol (stix_t* stix, const stix_ooch_t* ptr, stix_oow_t len) +moo_oop_t moo_makesymbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow_t len) { - return find_or_make_symbol (stix, ptr, len, 1); + return find_or_make_symbol (moo, ptr, len, 1); } -stix_oop_t stix_findsymbol (stix_t* stix, const stix_ooch_t* ptr, stix_oow_t len) +moo_oop_t moo_findsymbol (moo_t* moo, const moo_ooch_t* ptr, moo_oow_t len) { - return find_or_make_symbol (stix, ptr, len, 0); + return find_or_make_symbol (moo, ptr, len, 0); } -stix_oop_t stix_makestring (stix_t* stix, const stix_ooch_t* ptr, stix_oow_t len) +moo_oop_t moo_makestring (moo_t* moo, const moo_ooch_t* ptr, moo_oow_t len) { - return stix_instantiate (stix, stix->_string, ptr, len); + return moo_instantiate (moo, moo->_string, ptr, len); } diff --git a/stix/lib/utf8.c b/stix/lib/utf8.c index 5e491a5..fad7ab1 100644 --- a/stix/lib/utf8.c +++ b/stix/lib/utf8.c @@ -24,7 +24,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "stix-prv.h" +#include "moo-prv.h" /* * from RFC 2279 UTF-8, a transformation format of ISO 10646 @@ -40,11 +40,11 @@ struct __utf8_t { - stix_uint32_t lower; - stix_uint32_t upper; - stix_uint8_t fbyte; /* mask to the first utf8 byte */ - stix_uint8_t mask; - stix_uint8_t fmask; + moo_uint32_t lower; + moo_uint32_t upper; + moo_uint8_t fbyte; /* mask to the first utf8 byte */ + moo_uint8_t mask; + moo_uint8_t fmask; int length; /* number of bytes */ }; @@ -60,14 +60,14 @@ static __utf8_t utf8_table[] = {0x04000000ul, 0x7FFFFFFFul, 0xFC, 0xFE, 0x01, 6} }; -static STIX_INLINE __utf8_t* get_utf8_slot (stix_uch_t uc) +static MOO_INLINE __utf8_t* get_utf8_slot (moo_uch_t uc) { __utf8_t* cur, * end; - /*STIX_ASSERT (stix, STIX_SIZEOF(stix_bch_t) == 1); - STIX_ASSERT (stix, STIX_SIZEOF(stix_uch_t) >= 2);*/ + /*MOO_ASSERT (moo, MOO_SIZEOF(moo_bch_t) == 1); + MOO_ASSERT (moo, MOO_SIZEOF(moo_uch_t) >= 2);*/ - end = utf8_table + STIX_COUNTOF(utf8_table); + end = utf8_table + MOO_COUNTOF(utf8_table); cur = utf8_table; while (cur < end) @@ -76,14 +76,14 @@ static STIX_INLINE __utf8_t* get_utf8_slot (stix_uch_t uc) cur++; } - return STIX_NULL; /* invalid character */ + return MOO_NULL; /* invalid character */ } -stix_oow_t stix_uctoutf8 (stix_uch_t uc, stix_bch_t* utf8, stix_oow_t size) +moo_oow_t moo_uctoutf8 (moo_uch_t uc, moo_bch_t* utf8, moo_oow_t size) { __utf8_t* cur = get_utf8_slot (uc); - if (cur == STIX_NULL) return 0; /* illegal character */ + if (cur == MOO_NULL) return 0; /* illegal character */ if (utf8 && cur->length <= size) { @@ -103,19 +103,19 @@ stix_oow_t stix_uctoutf8 (stix_uch_t uc, stix_bch_t* utf8, stix_oow_t size) /* small buffer is also indicated by this return value * greater than 'size'. */ - return (stix_oow_t)cur->length; + return (moo_oow_t)cur->length; } -stix_oow_t stix_utf8touc (const stix_bch_t* utf8, stix_oow_t size, stix_uch_t* uc) +moo_oow_t moo_utf8touc (const moo_bch_t* utf8, moo_oow_t size, moo_uch_t* uc) { __utf8_t* cur, * end; - /*STIX_ASSERT (stix, utf8 != STIX_NULL); - STIX_ASSERT (stix, size > 0); - STIX_ASSERT (stix, STIX_SIZEOF(stix_bch_t) == 1); - STIX_ASSERT (stix, STIX_SIZEOF(stix_uch_t) >= 2);*/ + /*MOO_ASSERT (moo, utf8 != MOO_NULL); + MOO_ASSERT (moo, size > 0); + MOO_ASSERT (moo, MOO_SIZEOF(moo_bch_t) == 1); + MOO_ASSERT (moo, MOO_SIZEOF(moo_uch_t) >= 2);*/ - end = utf8_table + STIX_COUNTOF(utf8_table); + end = utf8_table + MOO_COUNTOF(utf8_table); cur = utf8_table; while (cur < end) @@ -133,7 +133,7 @@ stix_oow_t stix_utf8touc (const stix_bch_t* utf8, stix_oow_t size, stix_uch_t* u if (uc) { - stix_uch_t w; + moo_uch_t w; w = utf8[0] & cur->fmask; for (i = 1; i < cur->length; i++) @@ -169,7 +169,7 @@ stix_oow_t stix_utf8touc (const stix_bch_t* utf8, stix_oow_t size, stix_uch_t* u * and * the incomplete seqeunce error (size < cur->length). */ - return (stix_oow_t)cur->length; + return (moo_oow_t)cur->length; } cur++; } diff --git a/stix/lib/utl.c b/stix/lib/utl.c index 3d5ebab..27d3e8f 100644 --- a/stix/lib/utl.c +++ b/stix/lib/utl.c @@ -24,9 +24,9 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "stix-prv.h" +#include "moo-prv.h" -#define STIX_BCLEN_MAX 6 +#define MOO_BCLEN_MAX 6 /* some naming conventions * bchars, uchars -> pointer and length @@ -37,22 +37,22 @@ * utobcstr -> ucstr to bcstr */ -stix_oow_t stix_hashbytes (const stix_oob_t* ptr, stix_oow_t len) +moo_oow_t moo_hashbytes (const moo_oob_t* ptr, moo_oow_t len) { - stix_oow_t h = 0; - const stix_uint8_t* bp, * be; + moo_oow_t h = 0; + const moo_uint8_t* bp, * be; bp = ptr; be = bp + len; while (bp < be) h = h * 31 + *bp++; /* constrain the hash value to be representable in a small integer * for convenience sake */ - return h % ((stix_oow_t)STIX_SMOOI_MAX + 1); + return h % ((moo_oow_t)MOO_SMOOI_MAX + 1); } -int stix_equaluchars (const stix_uch_t* str1, const stix_uch_t* str2, stix_oow_t len) +int moo_equaluchars (const moo_uch_t* str1, const moo_uch_t* str2, moo_oow_t len) { - stix_oow_t i; + moo_oow_t i; for (i = 0; i < len; i++) { @@ -62,9 +62,9 @@ int stix_equaluchars (const stix_uch_t* str1, const stix_uch_t* str2, stix_oow_t return 1; } -int stix_equalbchars (const stix_bch_t* str1, const stix_bch_t* str2, stix_oow_t len) +int moo_equalbchars (const moo_bch_t* str1, const moo_bch_t* str2, moo_oow_t len) { - stix_oow_t i; + moo_oow_t i; for (i = 0; i < len; i++) { @@ -74,7 +74,7 @@ int stix_equalbchars (const stix_bch_t* str1, const stix_bch_t* str2, stix_oow_t return 1; } -int stix_compucstr (const stix_uch_t* str1, const stix_uch_t* str2) +int moo_compucstr (const moo_uch_t* str1, const moo_uch_t* str2) { while (*str1 == *str2) { @@ -85,7 +85,7 @@ int stix_compucstr (const stix_uch_t* str1, const stix_uch_t* str2) return (*str1 > *str2)? 1: -1; } -int stix_compbcstr (const stix_bch_t* str1, const stix_bch_t* str2) +int moo_compbcstr (const moo_bch_t* str1, const moo_bch_t* str2) { while (*str1 == *str2) { @@ -96,7 +96,7 @@ int stix_compbcstr (const stix_bch_t* str1, const stix_bch_t* str2) return (*str1 > *str2)? 1: -1; } -int stix_compucbcstr (const stix_uch_t* str1, const stix_bch_t* str2) +int moo_compucbcstr (const moo_uch_t* str1, const moo_bch_t* str2) { while (*str1 == *str2) { @@ -107,47 +107,47 @@ int stix_compucbcstr (const stix_uch_t* str1, const stix_bch_t* str2) return (*str1 > *str2)? 1: -1; } -int stix_compucharsbcstr (const stix_uch_t* str1, stix_oow_t len, const stix_bch_t* str2) +int moo_compucharsbcstr (const moo_uch_t* str1, moo_oow_t len, const moo_bch_t* str2) { - const stix_uch_t* end = str1 + len; + const moo_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; } -int stix_compbcharsbcstr (const stix_bch_t* str1, stix_oow_t len, const stix_bch_t* str2) +int moo_compbcharsbcstr (const moo_bch_t* str1, moo_oow_t len, const moo_bch_t* str2) { - const stix_bch_t* end = str1 + len; + const moo_bch_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_oow_t len) +void moo_copyuchars (moo_uch_t* dst, const moo_uch_t* src, moo_oow_t len) { - stix_oow_t i; + moo_oow_t i; for (i = 0; i < len; i++) dst[i] = src[i]; } -void stix_copybchars (stix_bch_t* dst, const stix_bch_t* src, stix_oow_t len) +void moo_copybchars (moo_bch_t* dst, const moo_bch_t* src, moo_oow_t len) { - stix_oow_t i; + moo_oow_t i; for (i = 0; i < len; i++) dst[i] = src[i]; } -void stix_copybtouchars (stix_uch_t* dst, const stix_bch_t* src, stix_oow_t len) +void moo_copybtouchars (moo_uch_t* dst, const moo_bch_t* src, moo_oow_t len) { /* copy without conversions. - * use stix_bctouchars() for conversion encoding */ - stix_oow_t i; + * use moo_bctouchars() for conversion encoding */ + moo_oow_t i; for (i = 0; i < len; i++) dst[i] = src[i]; } -stix_oow_t stix_copyucstr (stix_uch_t* dst, stix_oow_t len, const stix_uch_t* src) +moo_oow_t moo_copyucstr (moo_uch_t* dst, moo_oow_t len, const moo_uch_t* src) { - stix_uch_t* p, * p2; + moo_uch_t* p, * p2; p = dst; p2 = dst + len - 1; @@ -161,9 +161,9 @@ stix_oow_t stix_copyucstr (stix_uch_t* dst, stix_oow_t len, const stix_uch_t* sr return p - dst; } -stix_oow_t stix_copybcstr (stix_bch_t* dst, stix_oow_t len, const stix_bch_t* src) +moo_oow_t moo_copybcstr (moo_bch_t* dst, moo_oow_t len, const moo_bch_t* src) { - stix_bch_t* p, * p2; + moo_bch_t* p, * p2; p = dst; p2 = dst + len - 1; @@ -177,131 +177,131 @@ stix_oow_t stix_copybcstr (stix_bch_t* dst, stix_oow_t len, const stix_bch_t* sr return p - dst; } -stix_oow_t stix_countucstr (const stix_uch_t* str) +moo_oow_t moo_countucstr (const moo_uch_t* str) { - const stix_uch_t* ptr = str; + const moo_uch_t* ptr = str; while (*ptr != '\0') ptr++; return ptr - str; } -stix_oow_t stix_countbcstr (const stix_bch_t* str) +moo_oow_t moo_countbcstr (const moo_bch_t* str) { - const stix_bch_t* ptr = str; + const moo_bch_t* ptr = str; while (*ptr != '\0') ptr++; return ptr - str; } -stix_uch_t* stix_finduchar (const stix_uch_t* ptr, stix_oow_t len, stix_uch_t c) +moo_uch_t* moo_finduchar (const moo_uch_t* ptr, moo_oow_t len, moo_uch_t c) { - const stix_uch_t* end; + const moo_uch_t* end; end = ptr + len; while (ptr < end) { - if (*ptr == c) return (stix_uch_t*)ptr; + if (*ptr == c) return (moo_uch_t*)ptr; ptr++; } - return STIX_NULL; + return MOO_NULL; } -stix_bch_t* stix_findbchar (const stix_bch_t* ptr, stix_oow_t len, stix_bch_t c) +moo_bch_t* moo_findbchar (const moo_bch_t* ptr, moo_oow_t len, moo_bch_t c) { - const stix_bch_t* end; + const moo_bch_t* end; end = ptr + len; while (ptr < end) { - if (*ptr == c) return (stix_bch_t*)ptr; + if (*ptr == c) return (moo_bch_t*)ptr; ptr++; } - return STIX_NULL; + return MOO_NULL; } -stix_uch_t* stix_rfinduchar (const stix_uch_t* ptr, stix_oow_t len, stix_uch_t c) +moo_uch_t* moo_rfinduchar (const moo_uch_t* ptr, moo_oow_t len, moo_uch_t c) { - const stix_uch_t* cur; + const moo_uch_t* cur; cur = ptr + len; while (cur > ptr) { --cur; - if (*cur == c) return (stix_uch_t*)cur; + if (*cur == c) return (moo_uch_t*)cur; } - return STIX_NULL; + return MOO_NULL; } -stix_bch_t* stix_rfindbchar (const stix_bch_t* ptr, stix_oow_t len, stix_bch_t c) +moo_bch_t* moo_rfindbchar (const moo_bch_t* ptr, moo_oow_t len, moo_bch_t c) { - const stix_bch_t* cur; + const moo_bch_t* cur; cur = ptr + len; while (cur > ptr) { --cur; - if (*cur == c) return (stix_bch_t*)cur; + if (*cur == c) return (moo_bch_t*)cur; } - return STIX_NULL; + return MOO_NULL; } /* ----------------------------------------------------------------------- */ -int stix_concatoocstrtosbuf (stix_t* stix, const stix_ooch_t* str, int id) +int moo_concatoocstrtosbuf (moo_t* moo, const moo_ooch_t* str, int id) { - stix_sbuf_t* p; - stix_oow_t len; + moo_sbuf_t* p; + moo_oow_t len; - p = &stix->sbuf[id]; - len = stix_countoocstr (str); + p = &moo->sbuf[id]; + len = moo_countoocstr (str); if (len > p->capa - p->len) { - stix_oow_t newcapa; - stix_ooch_t* tmp; + moo_oow_t newcapa; + moo_ooch_t* tmp; - newcapa = STIX_ALIGN(p->len + len, 512); /* TODO: adjust this capacity */ + newcapa = MOO_ALIGN(p->len + len, 512); /* TODO: adjust this capacity */ /* +1 to handle line ending injection more easily */ - tmp = stix_reallocmem (stix, p->ptr, (newcapa + 1) * STIX_SIZEOF(*tmp)); + tmp = moo_reallocmem (moo, p->ptr, (newcapa + 1) * MOO_SIZEOF(*tmp)); if (!tmp) return -1; p->ptr = tmp; p->capa = newcapa; } - stix_copyoochars (&p->ptr[p->len], str, len); + moo_copyoochars (&p->ptr[p->len], str, len); p->len += len; p->ptr[p->len] = '\0'; return 0; } -int stix_copyoocstrtosbuf (stix_t* stix, const stix_ooch_t* str, int id) +int moo_copyoocstrtosbuf (moo_t* moo, const moo_ooch_t* str, int id) { - stix->sbuf[id].len = 0;; - return stix_concatoocstrtosbuf (stix, str, id); + moo->sbuf[id].len = 0;; + return moo_concatoocstrtosbuf (moo, str, id); } /* ----------------------------------------------------------------------- */ -static STIX_INLINE int bcsn_to_ucsn_with_cmgr ( - const stix_bch_t* bcs, stix_oow_t* bcslen, - stix_uch_t* ucs, stix_oow_t* ucslen, stix_cmgr_t* cmgr, int all) +static MOO_INLINE int bcsn_to_ucsn_with_cmgr ( + const moo_bch_t* bcs, moo_oow_t* bcslen, + moo_uch_t* ucs, moo_oow_t* ucslen, moo_cmgr_t* cmgr, int all) { - const stix_bch_t* p; + const moo_bch_t* p; int ret = 0; - stix_oow_t mlen; + moo_oow_t mlen; if (ucs) { /* destination buffer is specified. * copy the conversion result to the buffer */ - stix_uch_t* q, * qend; + moo_uch_t* q, * qend; p = bcs; q = ucs; @@ -310,7 +310,7 @@ static STIX_INLINE int bcsn_to_ucsn_with_cmgr ( while (mlen > 0) { - stix_oow_t n; + moo_oow_t n; if (q >= qend) { @@ -365,15 +365,15 @@ static STIX_INLINE int bcsn_to_ucsn_with_cmgr ( * a buffer with the size and call this function again with * the buffer. */ - stix_uch_t w; - stix_oow_t wlen = 0; + moo_uch_t w; + moo_oow_t wlen = 0; p = bcs; mlen = *bcslen; while (mlen > 0) { - stix_oow_t n; + moo_oow_t n; n = cmgr->bctouc (p, mlen, &w); if (n == 0) @@ -409,12 +409,12 @@ static STIX_INLINE int bcsn_to_ucsn_with_cmgr ( return ret; } -static STIX_INLINE int bcs_to_ucs_with_cmgr ( - const stix_bch_t* bcs, stix_oow_t* bcslen, - stix_uch_t* ucs, stix_oow_t* ucslen, stix_cmgr_t* cmgr, int all) +static MOO_INLINE int bcs_to_ucs_with_cmgr ( + const moo_bch_t* bcs, moo_oow_t* bcslen, + moo_uch_t* ucs, moo_oow_t* ucslen, moo_cmgr_t* cmgr, int all) { - const stix_bch_t* bp; - stix_oow_t mlen, wlen; + const moo_bch_t* bp; + moo_oow_t mlen, wlen; int n; for (bp = bcs; *bp != '\0'; bp++) /* nothing */ ; @@ -432,21 +432,21 @@ static STIX_INLINE int bcs_to_ucs_with_cmgr ( return n; } -static STIX_INLINE int ucsn_to_bcsn_with_cmgr ( - const stix_uch_t* ucs, stix_oow_t* ucslen, - stix_bch_t* bcs, stix_oow_t* bcslen, stix_cmgr_t* cmgr) +static MOO_INLINE int ucsn_to_bcsn_with_cmgr ( + const moo_uch_t* ucs, moo_oow_t* ucslen, + moo_bch_t* bcs, moo_oow_t* bcslen, moo_cmgr_t* cmgr) { - const stix_uch_t* p = ucs; - const stix_uch_t* end = ucs + *ucslen; + const moo_uch_t* p = ucs; + const moo_uch_t* end = ucs + *ucslen; int ret = 0; if (bcs) { - stix_oow_t rem = *bcslen; + moo_oow_t rem = *bcslen; while (p < end) { - stix_oow_t n; + moo_oow_t n; if (rem <= 0) { @@ -472,14 +472,14 @@ static STIX_INLINE int ucsn_to_bcsn_with_cmgr ( } else { - stix_bch_t bcsbuf[STIX_BCLEN_MAX]; - stix_oow_t mlen = 0; + moo_bch_t bcsbuf[MOO_BCLEN_MAX]; + moo_oow_t mlen = 0; while (p < end) { - stix_oow_t n; + moo_oow_t n; - n = cmgr->uctobc (*p, bcsbuf, STIX_COUNTOF(bcsbuf)); + n = cmgr->uctobc (*p, bcsbuf, MOO_COUNTOF(bcsbuf)); if (n == 0) { ret = -1; @@ -487,7 +487,7 @@ static STIX_INLINE int ucsn_to_bcsn_with_cmgr ( } /* it assumes that bcsbuf is large enough to hold a character */ - /*STIX_ASSERT (stix, n <= STIX_COUNTOF(bcsbuf));*/ + /*MOO_ASSERT (moo, n <= MOO_COUNTOF(bcsbuf));*/ p++; mlen += n; } @@ -503,19 +503,19 @@ static STIX_INLINE int ucsn_to_bcsn_with_cmgr ( static int ucs_to_bcs_with_cmgr ( - const stix_uch_t* ucs, stix_oow_t* ucslen, - stix_bch_t* bcs, stix_oow_t* bcslen, stix_cmgr_t* cmgr) + const moo_uch_t* ucs, moo_oow_t* ucslen, + moo_bch_t* bcs, moo_oow_t* bcslen, moo_cmgr_t* cmgr) { - const stix_uch_t* p = ucs; + const moo_uch_t* p = ucs; int ret = 0; if (bcs) { - stix_oow_t rem = *bcslen; + moo_oow_t rem = *bcslen; while (*p != '\0') { - stix_oow_t n; + moo_oow_t n; if (rem <= 0) { @@ -554,14 +554,14 @@ static int ucs_to_bcs_with_cmgr ( } else { - stix_bch_t bcsbuf[STIX_BCLEN_MAX]; - stix_oow_t mlen = 0; + moo_bch_t bcsbuf[MOO_BCLEN_MAX]; + moo_oow_t mlen = 0; while (*p != '\0') { - stix_oow_t n; + moo_oow_t n; - n = cmgr->uctobc (*p, bcsbuf, STIX_COUNTOF(bcsbuf)); + n = cmgr->uctobc (*p, bcsbuf, MOO_COUNTOF(bcsbuf)); if (n == 0) { ret = -1; @@ -569,7 +569,7 @@ static int ucs_to_bcs_with_cmgr ( } /* it assumes that bcs is large enough to hold a character */ - /*STIX_ASSERT (stix, n <= STIX_COUNTOF(bcs));*/ + /*MOO_ASSERT (moo, n <= MOO_COUNTOF(bcs));*/ p++; mlen += n; } @@ -585,36 +585,36 @@ static int ucs_to_bcs_with_cmgr ( /* ----------------------------------------------------------------------- */ -static stix_cmgr_t utf8_cmgr = +static moo_cmgr_t utf8_cmgr = { - stix_utf8touc, - stix_uctoutf8 + moo_utf8touc, + moo_uctoutf8 }; -stix_cmgr_t* stix_getutf8cmgr (void) +moo_cmgr_t* moo_getutf8cmgr (void) { return &utf8_cmgr; } -int stix_convutf8touchars (const stix_bch_t* bcs, stix_oow_t* bcslen, stix_uch_t* ucs, stix_oow_t* ucslen) +int moo_convutf8touchars (const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen) { /* the source is length bound */ return bcsn_to_ucsn_with_cmgr (bcs, bcslen, ucs, ucslen, &utf8_cmgr, 0); } -int stix_convutoutf8chars (const stix_uch_t* ucs, stix_oow_t* ucslen, stix_bch_t* bcs, stix_oow_t* bcslen) +int moo_convutoutf8chars (const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen) { /* length bound */ return ucsn_to_bcsn_with_cmgr (ucs, ucslen, bcs, bcslen, &utf8_cmgr); } -int stix_convutf8toucstr (const stix_bch_t* bcs, stix_oow_t* bcslen, stix_uch_t* ucs, stix_oow_t* ucslen) +int moo_convutf8toucstr (const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen) { /* null-terminated. */ return bcs_to_ucs_with_cmgr (bcs, bcslen, ucs, ucslen, &utf8_cmgr, 0); } -int stix_convutoutf8cstr (const stix_uch_t* ucs, stix_oow_t* ucslen, stix_bch_t* bcs, stix_oow_t* bcslen) +int moo_convutoutf8cstr (const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen) { /* null-terminated */ return ucs_to_bcs_with_cmgr (ucs, ucslen, bcs, bcslen, &utf8_cmgr); @@ -622,26 +622,26 @@ int stix_convutoutf8cstr (const stix_uch_t* ucs, stix_oow_t* ucslen, stix_bch_t* /* ----------------------------------------------------------------------- */ -int stix_convbtouchars (stix_t* stix, const stix_bch_t* bcs, stix_oow_t* bcslen, stix_uch_t* ucs, stix_oow_t* ucslen) +int moo_convbtouchars (moo_t* moo, const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen) { /* length bound */ - return bcsn_to_ucsn_with_cmgr (bcs, bcslen, ucs, ucslen, stix->cmgr, 0); + return bcsn_to_ucsn_with_cmgr (bcs, bcslen, ucs, ucslen, moo->cmgr, 0); } -int stix_convutobchars (stix_t* stix, const stix_uch_t* ucs, stix_oow_t* ucslen, stix_bch_t* bcs, stix_oow_t* bcslen) +int moo_convutobchars (moo_t* moo, const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen) { /* length bound */ - return ucsn_to_bcsn_with_cmgr (ucs, ucslen, bcs, bcslen, stix->cmgr); + return ucsn_to_bcsn_with_cmgr (ucs, ucslen, bcs, bcslen, moo->cmgr); } -int stix_convbtoucstr (stix_t* stix, const stix_bch_t* bcs, stix_oow_t* bcslen, stix_uch_t* ucs, stix_oow_t* ucslen) +int moo_convbtoucstr (moo_t* moo, const moo_bch_t* bcs, moo_oow_t* bcslen, moo_uch_t* ucs, moo_oow_t* ucslen) { /* null-terminated. */ - return bcs_to_ucs_with_cmgr (bcs, bcslen, ucs, ucslen, stix->cmgr, 0); + return bcs_to_ucs_with_cmgr (bcs, bcslen, ucs, ucslen, moo->cmgr, 0); } -int stix_convutobcstr (stix_t* stix, const stix_uch_t* ucs, stix_oow_t* ucslen, stix_bch_t* bcs, stix_oow_t* bcslen) +int moo_convutobcstr (moo_t* moo, const moo_uch_t* ucs, moo_oow_t* ucslen, moo_bch_t* bcs, moo_oow_t* bcslen) { /* null-terminated */ - return ucs_to_bcs_with_cmgr (ucs, ucslen, bcs, bcslen, stix->cmgr); + return ucs_to_bcs_with_cmgr (ucs, ucslen, bcs, bcslen, moo->cmgr); } diff --git a/stix/mod/Makefile.am b/stix/mod/Makefile.am index e4a58ef..bc0fcda 100644 --- a/stix/mod/Makefile.am +++ b/stix/mod/Makefile.am @@ -10,9 +10,9 @@ CPPFLAGS_COMMON = \ if WIN32 # you must adjust the value of DEFAULT_MODPOSTFIX according # to the first number in -version-info above -CPPFLAGS_COMMON += -DSTIX_DEFAULT_MODPREFIX=\"libstix-\" -DSTIX_DEFAULT_MODPOSTFIX=\"-1\" +CPPFLAGS_COMMON += -DMOO_DEFAULT_MODPREFIX=\"libmoo-\" -DMOO_DEFAULT_MODPOSTFIX=\"-1\" else -CPPFLAGS_COMMON += -DSTIX_DEFAULT_MODPREFIX=\"$(libdir)/libstix-\" -DSTIX_DEFAULT_MODPOSTFIX=\"\" +CPPFLAGS_COMMON += -DMOO_DEFAULT_MODPREFIX=\"$(libdir)/libmoo-\" -DMOO_DEFAULT_MODPOSTFIX=\"\" endif if ENABLE_STATIC_MODULE @@ -21,13 +21,13 @@ if ENABLE_STATIC_MODULE # STATIC MODULES BUILT INTO MAIN LIBRARY ################################################## -noinst_LTLIBRARIES = libstix-console.la libstix-stdio.la +noinst_LTLIBRARIES = libmoo-console.la libmoo-stdio.la -libstix_console_la_SOURCES = console.c -libstix_console_la_CPPFLAGS = $(CPPFLAGS_COMMON) +libmoo_console_la_SOURCES = console.c +libmoo_console_la_CPPFLAGS = $(CPPFLAGS_COMMON) -libstix_stdio_la_SOURCES = stdio.c -libstix_stdio_la_CPPFLAGS = $(CPPFLAGS_COMMON) +libmoo_stdio_la_SOURCES = stdio.c +libmoo_stdio_la_CPPFLAGS = $(CPPFLAGS_COMMON) else @@ -35,21 +35,21 @@ else # DYNAMIC MODULES ################################################## LDFLAGS_COMMON = -L$(abs_builddir)/../lib -L$(libdir) -version-info 1:0:0 -no-undefined -LIBADD_COMMON = -lstix +LIBADD_COMMON = -lmoo pkgmodexecdir = $(libdir) -pkgmodexec_LTLIBRARIES = libstix-stdio.la libstix-console.la +pkgmodexec_LTLIBRARIES = libmoo-stdio.la libmoo-console.la -libstix_stdio_la_SOURCES = stdio.c m-stdio.h -libstix_stdio_la_CPPFLAGS = $(CPPFLAGS_COMMON) -libstix_stdio_la_LDFLAGS = $(LDFLAGS_COMMON) -libstix_stdio_la_LIBADD = $(LIBADD_COMMON) +libmoo_stdio_la_SOURCES = stdio.c m-stdio.h +libmoo_stdio_la_CPPFLAGS = $(CPPFLAGS_COMMON) +libmoo_stdio_la_LDFLAGS = $(LDFLAGS_COMMON) +libmoo_stdio_la_LIBADD = $(LIBADD_COMMON) -libstix_console_la_SOURCES = console.c console.h -libstix_console_la_CPPFLAGS = $(CPPFLAGS_COMMON) -libstix_console_la_LDFLAGS = $(LDFLAGS_COMMON) -libstix_console_la_LIBADD = $(LIBADD_COMMON) -ltermcap +libmoo_console_la_SOURCES = console.c console.h +libmoo_console_la_CPPFLAGS = $(CPPFLAGS_COMMON) +libmoo_console_la_LDFLAGS = $(LDFLAGS_COMMON) +libmoo_console_la_LIBADD = $(LIBADD_COMMON) -ltermcap endif diff --git a/stix/mod/Makefile.in b/stix/mod/Makefile.in index 60cce88..0e6672f 100644 --- a/stix/mod/Makefile.in +++ b/stix/mod/Makefile.in @@ -81,8 +81,8 @@ host_triplet = @host@ # you must adjust the value of DEFAULT_MODPOSTFIX according # to the first number in -version-info above -@WIN32_TRUE@am__append_1 = -DSTIX_DEFAULT_MODPREFIX=\"libstix-\" -DSTIX_DEFAULT_MODPOSTFIX=\"-1\" -@WIN32_FALSE@am__append_2 = -DSTIX_DEFAULT_MODPREFIX=\"$(libdir)/libstix-\" -DSTIX_DEFAULT_MODPOSTFIX=\"\" +@WIN32_TRUE@am__append_1 = -DMOO_DEFAULT_MODPREFIX=\"libmoo-\" -DMOO_DEFAULT_MODPOSTFIX=\"-1\" +@WIN32_FALSE@am__append_2 = -DMOO_DEFAULT_MODPREFIX=\"$(libdir)/libmoo-\" -DMOO_DEFAULT_MODPOSTFIX=\"\" subdir = mod DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ $(top_srcdir)/ac/depcomp @@ -96,7 +96,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/argz.m4 \ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d -CONFIG_HEADER = $(top_builddir)/lib/stix-cfg.h +CONFIG_HEADER = $(top_builddir)/lib/moo-cfg.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; @@ -129,40 +129,40 @@ am__uninstall_files_from_dir = { \ am__installdirs = "$(DESTDIR)$(pkgmodexecdir)" LTLIBRARIES = $(noinst_LTLIBRARIES) $(pkgmodexec_LTLIBRARIES) am__DEPENDENCIES_1 = -@ENABLE_STATIC_MODULE_FALSE@libstix_console_la_DEPENDENCIES = \ +@ENABLE_STATIC_MODULE_FALSE@libmoo_console_la_DEPENDENCIES = \ @ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_1) -am__libstix_console_la_SOURCES_DIST = console.c console.h -@ENABLE_STATIC_MODULE_FALSE@am_libstix_console_la_OBJECTS = \ -@ENABLE_STATIC_MODULE_FALSE@ libstix_console_la-console.lo -@ENABLE_STATIC_MODULE_TRUE@am_libstix_console_la_OBJECTS = \ -@ENABLE_STATIC_MODULE_TRUE@ libstix_console_la-console.lo -libstix_console_la_OBJECTS = $(am_libstix_console_la_OBJECTS) +am__libmoo_console_la_SOURCES_DIST = console.c console.h +@ENABLE_STATIC_MODULE_FALSE@am_libmoo_console_la_OBJECTS = \ +@ENABLE_STATIC_MODULE_FALSE@ libmoo_console_la-console.lo +@ENABLE_STATIC_MODULE_TRUE@am_libmoo_console_la_OBJECTS = \ +@ENABLE_STATIC_MODULE_TRUE@ libmoo_console_la-console.lo +libmoo_console_la_OBJECTS = $(am_libmoo_console_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = -libstix_console_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ +libmoo_console_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ - $(AM_CFLAGS) $(CFLAGS) $(libstix_console_la_LDFLAGS) \ - $(LDFLAGS) -o $@ -@ENABLE_STATIC_MODULE_FALSE@am_libstix_console_la_rpath = -rpath \ -@ENABLE_STATIC_MODULE_FALSE@ $(pkgmodexecdir) -@ENABLE_STATIC_MODULE_TRUE@am_libstix_console_la_rpath = -@ENABLE_STATIC_MODULE_FALSE@libstix_stdio_la_DEPENDENCIES = \ -@ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_1) -am__libstix_stdio_la_SOURCES_DIST = stdio.c m-stdio.h -@ENABLE_STATIC_MODULE_FALSE@am_libstix_stdio_la_OBJECTS = \ -@ENABLE_STATIC_MODULE_FALSE@ libstix_stdio_la-stdio.lo -@ENABLE_STATIC_MODULE_TRUE@am_libstix_stdio_la_OBJECTS = \ -@ENABLE_STATIC_MODULE_TRUE@ libstix_stdio_la-stdio.lo -libstix_stdio_la_OBJECTS = $(am_libstix_stdio_la_OBJECTS) -libstix_stdio_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ - $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ - $(AM_CFLAGS) $(CFLAGS) $(libstix_stdio_la_LDFLAGS) $(LDFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) $(libmoo_console_la_LDFLAGS) $(LDFLAGS) \ -o $@ -@ENABLE_STATIC_MODULE_FALSE@am_libstix_stdio_la_rpath = -rpath \ +@ENABLE_STATIC_MODULE_FALSE@am_libmoo_console_la_rpath = -rpath \ @ENABLE_STATIC_MODULE_FALSE@ $(pkgmodexecdir) -@ENABLE_STATIC_MODULE_TRUE@am_libstix_stdio_la_rpath = +@ENABLE_STATIC_MODULE_TRUE@am_libmoo_console_la_rpath = +@ENABLE_STATIC_MODULE_FALSE@libmoo_stdio_la_DEPENDENCIES = \ +@ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_1) +am__libmoo_stdio_la_SOURCES_DIST = stdio.c m-stdio.h +@ENABLE_STATIC_MODULE_FALSE@am_libmoo_stdio_la_OBJECTS = \ +@ENABLE_STATIC_MODULE_FALSE@ libmoo_stdio_la-stdio.lo +@ENABLE_STATIC_MODULE_TRUE@am_libmoo_stdio_la_OBJECTS = \ +@ENABLE_STATIC_MODULE_TRUE@ libmoo_stdio_la-stdio.lo +libmoo_stdio_la_OBJECTS = $(am_libmoo_stdio_la_OBJECTS) +libmoo_stdio_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ + $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ + $(AM_CFLAGS) $(CFLAGS) $(libmoo_stdio_la_LDFLAGS) $(LDFLAGS) \ + -o $@ +@ENABLE_STATIC_MODULE_FALSE@am_libmoo_stdio_la_rpath = -rpath \ +@ENABLE_STATIC_MODULE_FALSE@ $(pkgmodexecdir) +@ENABLE_STATIC_MODULE_TRUE@am_libmoo_stdio_la_rpath = AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false @@ -197,9 +197,9 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = -SOURCES = $(libstix_console_la_SOURCES) $(libstix_stdio_la_SOURCES) -DIST_SOURCES = $(am__libstix_console_la_SOURCES_DIST) \ - $(am__libstix_stdio_la_SOURCES_DIST) +SOURCES = $(libmoo_console_la_SOURCES) $(libmoo_stdio_la_SOURCES) +DIST_SOURCES = $(am__libmoo_console_la_SOURCES_DIST) \ + $(am__libmoo_stdio_la_SOURCES_DIST) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -288,6 +288,20 @@ LT_DLPREOPEN = @LT_DLPREOPEN@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ +MOO_PROJECT_AUTHOR = @MOO_PROJECT_AUTHOR@ +MOO_PROJECT_URL = @MOO_PROJECT_URL@ +MOO_SIZEOF_CHAR = @MOO_SIZEOF_CHAR@ +MOO_SIZEOF_DOUBLE = @MOO_SIZEOF_DOUBLE@ +MOO_SIZEOF_FLOAT = @MOO_SIZEOF_FLOAT@ +MOO_SIZEOF_INT = @MOO_SIZEOF_INT@ +MOO_SIZEOF_LONG = @MOO_SIZEOF_LONG@ +MOO_SIZEOF_LONG_DOUBLE = @MOO_SIZEOF_LONG_DOUBLE@ +MOO_SIZEOF_LONG_LONG = @MOO_SIZEOF_LONG_LONG@ +MOO_SIZEOF_OFF64_T = @MOO_SIZEOF_OFF64_T@ +MOO_SIZEOF_OFF_T = @MOO_SIZEOF_OFF_T@ +MOO_SIZEOF_SHORT = @MOO_SIZEOF_SHORT@ +MOO_SIZEOF_VOID_P = @MOO_SIZEOF_VOID_P@ +MOO_SIZEOF_WCHAR_T = @MOO_SIZEOF_WCHAR_T@ NM = @NM@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ @@ -310,20 +324,6 @@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ -STIX_PROJECT_AUTHOR = @STIX_PROJECT_AUTHOR@ -STIX_PROJECT_URL = @STIX_PROJECT_URL@ -STIX_SIZEOF_CHAR = @STIX_SIZEOF_CHAR@ -STIX_SIZEOF_DOUBLE = @STIX_SIZEOF_DOUBLE@ -STIX_SIZEOF_FLOAT = @STIX_SIZEOF_FLOAT@ -STIX_SIZEOF_INT = @STIX_SIZEOF_INT@ -STIX_SIZEOF_LONG = @STIX_SIZEOF_LONG@ -STIX_SIZEOF_LONG_DOUBLE = @STIX_SIZEOF_LONG_DOUBLE@ -STIX_SIZEOF_LONG_LONG = @STIX_SIZEOF_LONG_LONG@ -STIX_SIZEOF_OFF64_T = @STIX_SIZEOF_OFF64_T@ -STIX_SIZEOF_OFF_T = @STIX_SIZEOF_OFF_T@ -STIX_SIZEOF_SHORT = @STIX_SIZEOF_SHORT@ -STIX_SIZEOF_VOID_P = @STIX_SIZEOF_VOID_P@ -STIX_SIZEOF_WCHAR_T = @STIX_SIZEOF_WCHAR_T@ STRIP = @STRIP@ UNICOWS_LIBS = @UNICOWS_LIBS@ VERSION = @VERSION@ @@ -392,27 +392,27 @@ CPPFLAGS_COMMON = -I$(abs_builddir) -I$(abs_builddir)/../lib \ ################################################## # STATIC MODULES BUILT INTO MAIN LIBRARY ################################################## -@ENABLE_STATIC_MODULE_TRUE@noinst_LTLIBRARIES = libstix-console.la libstix-stdio.la -@ENABLE_STATIC_MODULE_FALSE@libstix_console_la_SOURCES = console.c console.h -@ENABLE_STATIC_MODULE_TRUE@libstix_console_la_SOURCES = console.c -@ENABLE_STATIC_MODULE_FALSE@libstix_console_la_CPPFLAGS = $(CPPFLAGS_COMMON) -@ENABLE_STATIC_MODULE_TRUE@libstix_console_la_CPPFLAGS = $(CPPFLAGS_COMMON) -@ENABLE_STATIC_MODULE_FALSE@libstix_stdio_la_SOURCES = stdio.c m-stdio.h -@ENABLE_STATIC_MODULE_TRUE@libstix_stdio_la_SOURCES = stdio.c -@ENABLE_STATIC_MODULE_FALSE@libstix_stdio_la_CPPFLAGS = $(CPPFLAGS_COMMON) -@ENABLE_STATIC_MODULE_TRUE@libstix_stdio_la_CPPFLAGS = $(CPPFLAGS_COMMON) +@ENABLE_STATIC_MODULE_TRUE@noinst_LTLIBRARIES = libmoo-console.la libmoo-stdio.la +@ENABLE_STATIC_MODULE_FALSE@libmoo_console_la_SOURCES = console.c console.h +@ENABLE_STATIC_MODULE_TRUE@libmoo_console_la_SOURCES = console.c +@ENABLE_STATIC_MODULE_FALSE@libmoo_console_la_CPPFLAGS = $(CPPFLAGS_COMMON) +@ENABLE_STATIC_MODULE_TRUE@libmoo_console_la_CPPFLAGS = $(CPPFLAGS_COMMON) +@ENABLE_STATIC_MODULE_FALSE@libmoo_stdio_la_SOURCES = stdio.c m-stdio.h +@ENABLE_STATIC_MODULE_TRUE@libmoo_stdio_la_SOURCES = stdio.c +@ENABLE_STATIC_MODULE_FALSE@libmoo_stdio_la_CPPFLAGS = $(CPPFLAGS_COMMON) +@ENABLE_STATIC_MODULE_TRUE@libmoo_stdio_la_CPPFLAGS = $(CPPFLAGS_COMMON) ################################################## # DYNAMIC MODULES ################################################## @ENABLE_STATIC_MODULE_FALSE@LDFLAGS_COMMON = -L$(abs_builddir)/../lib -L$(libdir) -version-info 1:0:0 -no-undefined -@ENABLE_STATIC_MODULE_FALSE@LIBADD_COMMON = -lstix +@ENABLE_STATIC_MODULE_FALSE@LIBADD_COMMON = -lmoo @ENABLE_STATIC_MODULE_FALSE@pkgmodexecdir = $(libdir) -@ENABLE_STATIC_MODULE_FALSE@pkgmodexec_LTLIBRARIES = libstix-stdio.la libstix-console.la -@ENABLE_STATIC_MODULE_FALSE@libstix_stdio_la_LDFLAGS = $(LDFLAGS_COMMON) -@ENABLE_STATIC_MODULE_FALSE@libstix_stdio_la_LIBADD = $(LIBADD_COMMON) -@ENABLE_STATIC_MODULE_FALSE@libstix_console_la_LDFLAGS = $(LDFLAGS_COMMON) -@ENABLE_STATIC_MODULE_FALSE@libstix_console_la_LIBADD = $(LIBADD_COMMON) -ltermcap +@ENABLE_STATIC_MODULE_FALSE@pkgmodexec_LTLIBRARIES = libmoo-stdio.la libmoo-console.la +@ENABLE_STATIC_MODULE_FALSE@libmoo_stdio_la_LDFLAGS = $(LDFLAGS_COMMON) +@ENABLE_STATIC_MODULE_FALSE@libmoo_stdio_la_LIBADD = $(LIBADD_COMMON) +@ENABLE_STATIC_MODULE_FALSE@libmoo_console_la_LDFLAGS = $(LDFLAGS_COMMON) +@ENABLE_STATIC_MODULE_FALSE@libmoo_console_la_LIBADD = $(LIBADD_COMMON) -ltermcap all: all-am .SUFFIXES: @@ -494,11 +494,11 @@ clean-pkgmodexecLTLIBRARIES: rm -f $${locs}; \ } -libstix-console.la: $(libstix_console_la_OBJECTS) $(libstix_console_la_DEPENDENCIES) $(EXTRA_libstix_console_la_DEPENDENCIES) - $(AM_V_CCLD)$(libstix_console_la_LINK) $(am_libstix_console_la_rpath) $(libstix_console_la_OBJECTS) $(libstix_console_la_LIBADD) $(LIBS) +libmoo-console.la: $(libmoo_console_la_OBJECTS) $(libmoo_console_la_DEPENDENCIES) $(EXTRA_libmoo_console_la_DEPENDENCIES) + $(AM_V_CCLD)$(libmoo_console_la_LINK) $(am_libmoo_console_la_rpath) $(libmoo_console_la_OBJECTS) $(libmoo_console_la_LIBADD) $(LIBS) -libstix-stdio.la: $(libstix_stdio_la_OBJECTS) $(libstix_stdio_la_DEPENDENCIES) $(EXTRA_libstix_stdio_la_DEPENDENCIES) - $(AM_V_CCLD)$(libstix_stdio_la_LINK) $(am_libstix_stdio_la_rpath) $(libstix_stdio_la_OBJECTS) $(libstix_stdio_la_LIBADD) $(LIBS) +libmoo-stdio.la: $(libmoo_stdio_la_OBJECTS) $(libmoo_stdio_la_DEPENDENCIES) $(EXTRA_libmoo_stdio_la_DEPENDENCIES) + $(AM_V_CCLD)$(libmoo_stdio_la_LINK) $(am_libmoo_stdio_la_rpath) $(libmoo_stdio_la_OBJECTS) $(libmoo_stdio_la_LIBADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -506,8 +506,8 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_console_la-console.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_stdio_la-stdio.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_console_la-console.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmoo_stdio_la-stdio.Plo@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ @@ -533,19 +533,19 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< -libstix_console_la-console.lo: console.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstix_console_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libstix_console_la-console.lo -MD -MP -MF $(DEPDIR)/libstix_console_la-console.Tpo -c -o libstix_console_la-console.lo `test -f 'console.c' || echo '$(srcdir)/'`console.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_console_la-console.Tpo $(DEPDIR)/libstix_console_la-console.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='console.c' object='libstix_console_la-console.lo' libtool=yes @AMDEPBACKSLASH@ +libmoo_console_la-console.lo: console.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_console_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_console_la-console.lo -MD -MP -MF $(DEPDIR)/libmoo_console_la-console.Tpo -c -o libmoo_console_la-console.lo `test -f 'console.c' || echo '$(srcdir)/'`console.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_console_la-console.Tpo $(DEPDIR)/libmoo_console_la-console.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='console.c' object='libmoo_console_la-console.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_console_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libstix_console_la-console.lo `test -f 'console.c' || echo '$(srcdir)/'`console.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_console_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_console_la-console.lo `test -f 'console.c' || echo '$(srcdir)/'`console.c -libstix_stdio_la-stdio.lo: stdio.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstix_stdio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libstix_stdio_la-stdio.lo -MD -MP -MF $(DEPDIR)/libstix_stdio_la-stdio.Tpo -c -o libstix_stdio_la-stdio.lo `test -f 'stdio.c' || echo '$(srcdir)/'`stdio.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_stdio_la-stdio.Tpo $(DEPDIR)/libstix_stdio_la-stdio.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='stdio.c' object='libstix_stdio_la-stdio.lo' libtool=yes @AMDEPBACKSLASH@ +libmoo_stdio_la-stdio.lo: stdio.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_stdio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmoo_stdio_la-stdio.lo -MD -MP -MF $(DEPDIR)/libmoo_stdio_la-stdio.Tpo -c -o libmoo_stdio_la-stdio.lo `test -f 'stdio.c' || echo '$(srcdir)/'`stdio.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmoo_stdio_la-stdio.Tpo $(DEPDIR)/libmoo_stdio_la-stdio.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='stdio.c' object='libmoo_stdio_la-stdio.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_stdio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libstix_stdio_la-stdio.lo `test -f 'stdio.c' || echo '$(srcdir)/'`stdio.c +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmoo_stdio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmoo_stdio_la-stdio.lo `test -f 'stdio.c' || echo '$(srcdir)/'`stdio.c mostlyclean-libtool: -rm -f *.lo diff --git a/stix/mod/_stdio.h b/stix/mod/_stdio.h index fad1f80..8de5e82 100644 --- a/stix/mod/_stdio.h +++ b/stix/mod/_stdio.h @@ -24,16 +24,16 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _STIX_LIB_MOD_STDIO_H_ -#define _STIX_LIB_MOD_STDIO_H_ +#ifndef _MOO_LIB_MOD_STDIO_H_ +#define _MOO_LIB_MOD_STDIO_H_ -#include +#include #if defined(__cplusplus) extern "C" { #endif -STIX_EXPORT int stix_mod_stdio (stix_t* stix, stix_mod_t* mod); +MOO_EXPORT int moo_mod_stdio (moo_t* moo, moo_mod_t* mod); #if defined(__cplusplus) } diff --git a/stix/mod/console.c b/stix/mod/console.c index f9574f2..b0c4a34 100644 --- a/stix/mod/console.c +++ b/stix/mod/console.c @@ -26,7 +26,7 @@ #include "console.h" -#include +#include #include #include @@ -48,11 +48,11 @@ struct console_t }; /* ------------------------------------------------------------------------ */ -static stix_pfrc_t pf_open (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_open (moo_t* moo, moo_ooi_t nargs) { #if defined(_WIN32) HANDLE h; - stix_ooi_t immv; + moo_ooi_t immv; h = GetStdHandle(STD_INPUT_HANDLE); if (h == INVALID_HANDLE_VALUE) return 0; @@ -60,7 +60,7 @@ static stix_pfrc_t pf_open (stix_t* stix, stix_ooi_t nargs) { } - imm = stix_makeimm (stix, h); + imm = moo_makeimm (moo, h); if (imm <= -1) { /* error */ @@ -73,7 +73,7 @@ static stix_pfrc_t pf_open (stix_t* stix, stix_ooi_t nargs) int err; char* term; - con = stix_callocmem (stix, STIX_SIZEOF(*con)); + con = moo_callocmem (moo, MOO_SIZEOF(*con)); if (!con) return 0; if (isatty(1)) @@ -86,7 +86,7 @@ static stix_pfrc_t pf_open (stix_t* stix, stix_ooi_t nargs) if (con->fd == -1) { /* TODO: failed to open /dev/stdout */ - stix_freemem (stix, con); + moo_freemem (moo, con); return 0; } @@ -118,60 +118,60 @@ static stix_pfrc_t pf_open (stix_t* stix, stix_ooi_t nargs) #endif - STIX_STACK_SETRET (stix, nargs, STIX_SMOOI_TO_OOP((stix_oow_t)con)); - return STIX_PF_SUCCESS; + MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP((moo_oow_t)con)); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_close (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_close (moo_t* moo, moo_ooi_t nargs) { #if defined(_WIN32) HANDLE h; - h = STIX_STACK_GETARG (stix, nargs, 0); + h = MOO_STACK_GETARG (moo, nargs, 0); #else #endif console_t* con; - con = STIX_OOP_TO_SMOOI(STIX_STACK_GETARG (stix, nargs, 0)); + con = MOO_OOP_TO_SMOOI(MOO_STACK_GETARG (moo, nargs, 0)); /* TODO: sanity check */ if (con->fd_opened) close (con->fd); - stix_freemem (stix, con); - STIX_STACK_SETRETTORCV (stix, nargs); - return STIX_PF_SUCCESS; + moo_freemem (moo, con); + MOO_STACK_SETRETTORCV (moo, nargs); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_write (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_write (moo_t* moo, moo_ooi_t nargs) { console_t* con; - stix_oop_char_t oomsg; + moo_oop_char_t oomsg; - stix_oow_t ucspos, ucsrem, ucslen, bcslen; - stix_bch_t bcs[1024]; + moo_oow_t ucspos, ucsrem, ucslen, bcslen; + moo_bch_t bcs[1024]; int n; - con = STIX_OOP_TO_SMOOI(STIX_STACK_GETARG (stix, nargs, 0)); - oomsg = (stix_oop_char_t)STIX_STACK_GETARG (stix, nargs, 1); + con = MOO_OOP_TO_SMOOI(MOO_STACK_GETARG (moo, nargs, 0)); + oomsg = (moo_oop_char_t)MOO_STACK_GETARG (moo, nargs, 1); - if (STIX_CLASSOF(stix,oomsg) != stix->_string) + if (MOO_CLASSOF(moo,oomsg) != moo->_string) { /* TODO: invalid message */ - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } ucspos = 0; - ucsrem = STIX_OBJ_GET_SIZE(oomsg); + ucsrem = MOO_OBJ_GET_SIZE(oomsg); while (ucsrem > 0) { ucslen = ucsrem; - bcslen = STIX_COUNTOF(bcs); - if ((n = stix_convootobchars (stix, &oomsg->slot[ucspos], &ucslen, bcs, &bcslen)) <= -1) + bcslen = MOO_COUNTOF(bcs); + if ((n = moo_convootobchars (moo, &oomsg->slot[ucspos], &ucslen, bcs, &bcslen)) <= -1) { if (n != -2 || ucslen <= 0) { - stix_seterrnum (stix, STIX_EECERR); - return STIX_PF_HARD_FAILURE; + moo_seterrnum (moo, MOO_EECERR); + return MOO_PF_HARD_FAILURE; } } @@ -181,42 +181,42 @@ static stix_pfrc_t pf_write (stix_t* stix, stix_ooi_t nargs) ucsrem -= ucslen; } - STIX_STACK_SETRETTORCV (stix, nargs); /* TODO: change return code */ - return STIX_PF_SUCCESS; + MOO_STACK_SETRETTORCV (moo, nargs); /* TODO: change return code */ + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_clear (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_clear (moo_t* moo, moo_ooi_t nargs) { console_t* con; - con = STIX_OOP_TO_SMOOI(STIX_STACK_GETARG(stix, nargs, 0)); + con = MOO_OOP_TO_SMOOI(MOO_STACK_GETARG(moo, nargs, 0)); write (con->fd, con->clear, strlen(con->clear)); - STIX_STACK_SETRETTORCV (stix, nargs); - return STIX_PF_SUCCESS; + MOO_STACK_SETRETTORCV (moo, nargs); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_setcursor (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_setcursor (moo_t* moo, moo_ooi_t nargs) { console_t* con; - stix_oop_oop_t point; + moo_oop_oop_t point; char* cup; - con = STIX_OOP_TO_SMOOI(STIX_STACK_GETARG(stix, nargs, 0)); - point = STIX_STACK_GETARG(stix, nargs, 1); + con = MOO_OOP_TO_SMOOI(MOO_STACK_GETARG(moo, nargs, 0)); + point = MOO_STACK_GETARG(moo, nargs, 1); /* TODO: error check, class check, size check.. */ - if (STIX_OBJ_GET_SIZE(point) != 2) + if (MOO_OBJ_GET_SIZE(point) != 2) { - return STIX_PF_FAILURE; + return MOO_PF_FAILURE; } - cup = tiparm (con->cup, STIX_OOP_TO_SMOOI(point->slot[1]), STIX_OOP_TO_SMOOI(point->slot[0])); + cup = tiparm (con->cup, MOO_OOP_TO_SMOOI(point->slot[1]), MOO_OOP_TO_SMOOI(point->slot[0])); write (con->fd, cup, strlen(cup)); /* TODO: error check */ - STIX_STACK_SETRETTORCV (stix, nargs); - return STIX_PF_SUCCESS; + MOO_STACK_SETRETTORCV (moo, nargs); + return MOO_PF_SUCCESS; } /* ------------------------------------------------------------------------ */ @@ -224,8 +224,8 @@ static stix_pfrc_t pf_setcursor (stix_t* stix, stix_ooi_t nargs) typedef struct fnctab_t fnctab_t; struct fnctab_t { - const stix_bch_t* name; - stix_pfimpl_t handler; + const moo_bch_t* name; + moo_pfimpl_t handler; }; static fnctab_t fnctab[] = @@ -239,17 +239,17 @@ static fnctab_t fnctab[] = /* ------------------------------------------------------------------------ */ -static stix_pfimpl_t query (stix_t* stix, stix_mod_t* mod, const stix_ooch_t* name) +static moo_pfimpl_t query (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name) { int left, right, mid, n; - left = 0; right = STIX_COUNTOF(fnctab) - 1; + left = 0; right = MOO_COUNTOF(fnctab) - 1; while (left <= right) { mid = (left + right) / 2; - n = stix_compoocbcstr (name, fnctab[mid].name); + n = moo_compoocbcstr (name, fnctab[mid].name); if (n < 0) right = mid - 1; else if (n > 0) left = mid + 1; else @@ -258,21 +258,21 @@ static stix_pfimpl_t query (stix_t* stix, stix_mod_t* mod, const stix_ooch_t* na } } - stix->errnum = STIX_ENOENT; - return STIX_NULL; + moo->errnum = MOO_ENOENT; + return MOO_NULL; } -static void unload (stix_t* stix, stix_mod_t* mod) +static void unload (moo_t* moo, moo_mod_t* mod) { /* TODO: close all open handle?? */ } -int stix_mod_console (stix_t* stix, stix_mod_t* mod) +int moo_mod_console (moo_t* moo, moo_mod_t* mod) { mod->query = query; mod->unload = unload; - mod->ctx = STIX_NULL; + mod->ctx = MOO_NULL; return 0; } diff --git a/stix/mod/console.h b/stix/mod/console.h index a617fc8..430f811 100644 --- a/stix/mod/console.h +++ b/stix/mod/console.h @@ -24,16 +24,16 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _STIX_LIB_MOD_CONSOLE_H_ -#define _STIX_LIB_MOD_CONSOLE_H_ +#ifndef _MOO_LIB_MOD_CONSOLE_H_ +#define _MOO_LIB_MOD_CONSOLE_H_ -#include +#include #if defined(__cplusplus) extern "C" { #endif -STIX_EXPORT int stix_mod_console (stix_t* stix, stix_mod_t* mod); +MOO_EXPORT int moo_mod_console (moo_t* moo, moo_mod_t* mod); #if defined(__cplusplus) } diff --git a/stix/mod/stdio.c b/stix/mod/stdio.c index 82766fe..8b5cf7d 100644 --- a/stix/mod/stdio.c +++ b/stix/mod/stdio.c @@ -26,7 +26,7 @@ #include "_stdio.h" -#include +#include #include #include @@ -35,42 +35,42 @@ typedef struct stdio_t stdio_t; struct stdio_t { - STIX_OBJ_HEADER; + MOO_OBJ_HEADER; FILE* fp; }; -static stix_pfrc_t pf_newinstsize (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_newinstsize (moo_t* moo, moo_ooi_t nargs) { - stix_ooi_t newinstsize = STIX_SIZEOF(stdio_t) - STIX_SIZEOF(stix_obj_t); - STIX_STACK_SETRET (stix, nargs, STIX_SMOOI_TO_OOP(newinstsize)); - return STIX_PF_SUCCESS; + moo_ooi_t newinstsize = MOO_SIZEOF(stdio_t) - MOO_SIZEOF(moo_obj_t); + MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(newinstsize)); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_open (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_open (moo_t* moo, moo_ooi_t nargs) { - stix_oop_char_t name; - stix_oop_char_t mode; + moo_oop_char_t name; + moo_oop_char_t mode; stdio_t* rcv; -#if defined(STIX_OOCH_IS_UCH) - stix_oow_t ucslen, bcslen; - stix_bch_t namebuf[PATH_MAX]; - stix_bch_t modebuf[32]; /* TODO: dynamic-sized conversion?? */ +#if defined(MOO_OOCH_IS_UCH) + moo_oow_t ucslen, bcslen; + moo_bch_t namebuf[PATH_MAX]; + moo_bch_t modebuf[32]; /* TODO: dynamic-sized conversion?? */ #endif - rcv = (stdio_t*)STIX_STACK_GETRCV(stix, nargs); - name = (stix_oop_char_t)STIX_STACK_GETARG(stix, nargs, 0); - mode = (stix_oop_char_t)STIX_STACK_GETARG(stix, nargs, 1); + rcv = (stdio_t*)MOO_STACK_GETRCV(moo, nargs); + name = (moo_oop_char_t)MOO_STACK_GETARG(moo, nargs, 0); + mode = (moo_oop_char_t)MOO_STACK_GETARG(moo, nargs, 1); -#if defined(STIX_OOCH_IS_UCH) - ucslen = STIX_OBJ_GET_SIZE(name); - bcslen = STIX_COUNTOF(namebuf) - 1; - if (stix_convootobchars (stix, name->slot, &ucslen, namebuf, &bcslen) <= -1) goto reterr; +#if defined(MOO_OOCH_IS_UCH) + ucslen = MOO_OBJ_GET_SIZE(name); + bcslen = MOO_COUNTOF(namebuf) - 1; + if (moo_convootobchars (moo, name->slot, &ucslen, namebuf, &bcslen) <= -1) goto reterr; namebuf[bcslen] = '\0'; - ucslen = STIX_OBJ_GET_SIZE(mode); - bcslen = STIX_COUNTOF(modebuf) - 1; - if (stix_convootobchars (stix, mode->slot, &ucslen, modebuf, &bcslen) <= -1) goto reterr; + ucslen = MOO_OBJ_GET_SIZE(mode); + bcslen = MOO_COUNTOF(modebuf) - 1; + if (moo_convootobchars (moo, mode->slot, &ucslen, modebuf, &bcslen) <= -1) goto reterr; modebuf[bcslen] = '\0'; rcv->fp = fopen (namebuf, modebuf); @@ -79,92 +79,92 @@ static stix_pfrc_t pf_open (stix_t* stix, stix_ooi_t nargs) #endif if (!rcv->fp) { - stix_seterrnum (stix, stix_syserrtoerrnum(errno)); + moo_seterrnum (moo, moo_syserrtoerrnum(errno)); goto reterr; } - STIX_STACK_SETRETTORCV (stix, nargs); - return STIX_PF_SUCCESS; + MOO_STACK_SETRETTORCV (moo, nargs); + return MOO_PF_SUCCESS; reterr: - STIX_STACK_SETRETTOERROR (stix, nargs); - return STIX_PF_SUCCESS; + MOO_STACK_SETRETTOERROR (moo, nargs); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_close (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_close (moo_t* moo, moo_ooi_t nargs) { stdio_t* rcv; - rcv = (stdio_t*)STIX_STACK_GETRCV(stix, nargs); + rcv = (stdio_t*)MOO_STACK_GETRCV(moo, nargs); if (rcv->fp) { fclose (rcv->fp); rcv->fp = NULL; } - STIX_STACK_SETRETTORCV (stix, nargs); - return STIX_PF_SUCCESS; + MOO_STACK_SETRETTORCV (moo, nargs); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_gets (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_gets (moo_t* moo, moo_ooi_t nargs) { /* return how many bytes have been written.. */ - STIX_STACK_SETRETTORCV (stix, nargs); - return STIX_PF_SUCCESS; + MOO_STACK_SETRETTORCV (moo, nargs); + return MOO_PF_SUCCESS; } -static stix_pfrc_t __pf_puts (stix_t* stix, stix_ooi_t nargs, stix_oow_t limit) +static moo_pfrc_t __pf_puts (moo_t* moo, moo_ooi_t nargs, moo_oow_t limit) { stdio_t* rcv; - stix_ooi_t i; + moo_ooi_t i; - rcv = (stdio_t*)STIX_STACK_GETRCV(stix, nargs); + rcv = (stdio_t*)MOO_STACK_GETRCV(moo, nargs); for (i = 0; i < nargs; i++) { - stix_oop_char_t x; - stix_obj_char_t tmpc; + moo_oop_char_t x; + moo_obj_char_t tmpc; - x = (stix_oop_char_t)STIX_STACK_GETARG(stix, nargs, i); - if (STIX_OOP_IS_CHAR(x)) + x = (moo_oop_char_t)MOO_STACK_GETARG(moo, nargs, i); + if (MOO_OOP_IS_CHAR(x)) { /* do some faking. */ - STIX_ASSERT (stix, STIX_SIZEOF(tmpc) >= STIX_SIZEOF(stix_obj_t) + STIX_SIZEOF(stix_ooch_t)); + MOO_ASSERT (moo, MOO_SIZEOF(tmpc) >= MOO_SIZEOF(moo_obj_t) + MOO_SIZEOF(moo_ooch_t)); - tmpc.slot[0] = STIX_OOP_TO_CHAR(x); - x = (stix_oop_char_t)&tmpc; - STIX_OBJ_SET_SIZE(x, 1); + tmpc.slot[0] = MOO_OOP_TO_CHAR(x); + x = (moo_oop_char_t)&tmpc; + MOO_OBJ_SET_SIZE(x, 1); goto puts_string; } - else if (STIX_OOP_IS_POINTER(x) && STIX_OBJ_GET_FLAGS_TYPE(x) == STIX_OBJ_TYPE_CHAR) + else if (MOO_OOP_IS_POINTER(x) && MOO_OBJ_GET_FLAGS_TYPE(x) == MOO_OBJ_TYPE_CHAR) { int n; - stix_oow_t ucspos, ucsrem, ucslen, bcslen; - stix_bch_t bcs[1024]; /* TODO: choose a better buffer size */ + moo_oow_t ucspos, ucsrem, ucslen, bcslen; + moo_bch_t bcs[1024]; /* TODO: choose a better buffer size */ puts_string: ucspos = 0; - ucsrem = STIX_OBJ_GET_SIZE(x); + ucsrem = MOO_OBJ_GET_SIZE(x); if (ucsrem > limit) ucsrem = limit; while (ucsrem > 0) { ucslen = ucsrem; - bcslen = STIX_COUNTOF(bcs); + bcslen = MOO_COUNTOF(bcs); /* TODO: implement character conversion into stdio and use it instead of vm's conversion facility. */ - if ((n = stix_convootobchars (stix, &x->slot[ucspos], &ucslen, bcs, &bcslen)) <= -1) + if ((n = moo_convootobchars (moo, &x->slot[ucspos], &ucslen, bcs, &bcslen)) <= -1) { if (n != -2 || ucslen <= 0) { - stix_seterrnum (stix, STIX_EECERR); + moo_seterrnum (moo, MOO_EECERR); goto reterr; } } if (fwrite (bcs, 1, bcslen, rcv->fp) < bcslen) { - stix_seterrnum (stix, stix_syserrtoerrnum(errno)); + moo_seterrnum (moo, moo_syserrtoerrnum(errno)); goto reterr; } @@ -175,27 +175,27 @@ static stix_pfrc_t __pf_puts (stix_t* stix, stix_ooi_t nargs, stix_oow_t limit) } else { - stix_seterrnum (stix, STIX_EINVAL); + moo_seterrnum (moo, MOO_EINVAL); goto reterr; } } - STIX_STACK_SETRETTORCV (stix, nargs); - return STIX_PF_SUCCESS; + MOO_STACK_SETRETTORCV (moo, nargs); + return MOO_PF_SUCCESS; reterr: - STIX_STACK_SETRETTOERROR (stix, nargs); - return STIX_PF_SUCCESS; + MOO_STACK_SETRETTOERROR (moo, nargs); + return MOO_PF_SUCCESS; } -static stix_pfrc_t pf_putc (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_putc (moo_t* moo, moo_ooi_t nargs) { - return __pf_puts (stix, nargs, 1); + return __pf_puts (moo, nargs, 1); } -static stix_pfrc_t pf_puts (stix_t* stix, stix_ooi_t nargs) +static moo_pfrc_t pf_puts (moo_t* moo, moo_ooi_t nargs) { - return __pf_puts (stix, nargs, STIX_TYPE_MAX(stix_oow_t)); + return __pf_puts (moo, nargs, MOO_TYPE_MAX(moo_oow_t)); } /*TODO: add print function that can accept ByteArray @@ -207,14 +207,14 @@ static stix_pfrc_t pf_puts (stix_t* stix, stix_ooi_t nargs) typedef struct fnctab_t fnctab_t; struct fnctab_t { - stix_method_type_t type; - stix_ooch_t mthname[15]; + moo_method_type_t type; + moo_ooch_t mthname[15]; int variadic; - stix_pfimpl_t handler; + moo_pfimpl_t handler; }; -#define C STIX_METHOD_CLASS -#define I STIX_METHOD_INSTANCE +#define C MOO_METHOD_CLASS +#define I MOO_METHOD_INSTANCE static fnctab_t fnctab[] = { @@ -230,15 +230,15 @@ static fnctab_t fnctab[] = /* ------------------------------------------------------------------------ */ -static int import (stix_t* stix, stix_mod_t* mod, stix_oop_t _class) +static int import (moo_t* moo, moo_mod_t* mod, moo_oop_t _class) { int ret = 0; - stix_oow_t i; + moo_oow_t i; - stix_pushtmp (stix, &_class); - for (i = 0; i < STIX_COUNTOF(fnctab); i++) + moo_pushtmp (moo, &_class); + for (i = 0; i < MOO_COUNTOF(fnctab); i++) { - if (stix_genpfmethod (stix, mod, _class, fnctab[i].type, fnctab[i].mthname, fnctab[i].variadic, STIX_NULL) <= -1) + if (moo_genpfmethod (moo, mod, _class, fnctab[i].type, fnctab[i].mthname, fnctab[i].variadic, MOO_NULL) <= -1) { /* TODO: delete pfmethod generated??? */ ret = -1; @@ -246,21 +246,21 @@ static int import (stix_t* stix, stix_mod_t* mod, stix_oop_t _class) } } - stix_poptmp (stix); + moo_poptmp (moo); return ret; } -static stix_pfimpl_t query (stix_t* stix, stix_mod_t* mod, const stix_ooch_t* name) +static moo_pfimpl_t query (moo_t* moo, moo_mod_t* mod, const moo_ooch_t* name) { int left, right, mid, n; - left = 0; right = STIX_COUNTOF(fnctab) - 1; + left = 0; right = MOO_COUNTOF(fnctab) - 1; while (left <= right) { mid = (left + right) / 2; - n = stix_compoocstr (name, fnctab[mid].mthname); + n = moo_compoocstr (name, fnctab[mid].mthname); if (n < 0) right = mid - 1; else if (n > 0) left = mid + 1; else @@ -269,8 +269,8 @@ static stix_pfimpl_t query (stix_t* stix, stix_mod_t* mod, const stix_ooch_t* na } } - stix->errnum = STIX_ENOENT; - return STIX_NULL; + moo->errnum = MOO_ENOENT; + return MOO_NULL; } #if 0 @@ -279,22 +279,22 @@ static stix_pfimpl_t query (stix_t* stix, stix_mod_t* mod, const stix_ooch_t* na * check if receiver is at a certain size? * etc... */ -static int sanity_check (stix_t* stix) +static int sanity_check (moo_t* moo) { } #endif -static void unload (stix_t* stix, stix_mod_t* mod) +static void unload (moo_t* moo, moo_mod_t* mod) { /* TODO: close all open handle?? */ } -int stix_mod_stdio (stix_t* stix, stix_mod_t* mod) +int moo_mod_stdio (moo_t* moo, moo_mod_t* mod) { mod->import = import; mod->query = query; mod->unload = unload; - mod->ctx = STIX_NULL; + mod->ctx = MOO_NULL; return 0; }