diff --git a/stix/kernel/Stix.st b/stix/kernel/Stix.st index 915a768..a5bb3b4 100644 --- a/stix/kernel/Stix.st +++ b/stix/kernel/Stix.st @@ -250,7 +250,8 @@ #class(#pointer) CompiledMethod(Object) { - #dcl owner name preamble preamble_data_1 preamble_data_2 ntmprs nargs code source. + ## #dcl owner name preamble preamble_data_1 preamble_data_2 ntmprs nargs code source. + #dcl owner name preamble preamble_data_1 preamble_data_2 ntmprs nargs source. #method preamble { diff --git a/stix/lib/Makefile.am b/stix/lib/Makefile.am index abaf6ca..d4bc79e 100644 --- a/stix/lib/Makefile.am +++ b/stix/lib/Makefile.am @@ -40,6 +40,7 @@ libstix_la_SOURCES = \ bigint.c \ comp.c \ debug.c \ + decode.c \ dic.c \ exec.c \ gc.c \ @@ -82,12 +83,18 @@ LIBADD_MOD_COMMON = -lstix pkgmodexecdir = $(libdir) -pkgmodexec_LTLIBRARIES = libstix-snd.la +pkgmodexec_LTLIBRARIES = libstix-snd.la libstix-con.la + libstix_snd_la_SOURCES = mod-snd.c mod-snd.h libstix_snd_la_CPPFLAGS = $(CPPFLAGS_MOD_COMMON) libstix_snd_la_LDFLAGS = $(LDFLAGS_MOD_COMMON) libstix_snd_la_LIBADD = $(LIBADD_MOD_COMMON) +libstix_con_la_SOURCES = mod-con.c mod-con.h +libstix_con_la_CPPFLAGS = $(CPPFLAGS_MOD_COMMON) +libstix_con_la_LDFLAGS = $(LDFLAGS_MOD_COMMON) +libstix_con_la_LIBADD = $(LIBADD_MOD_COMMON) + endif diff --git a/stix/lib/Makefile.in b/stix/lib/Makefile.in index d27a336..6a37ef1 100644 --- a/stix/lib/Makefile.in +++ b/stix/lib/Makefile.in @@ -133,16 +133,28 @@ am__installdirs = "$(DESTDIR)$(pkglibdir)" \ "$(DESTDIR)$(pkgincludedir)" LTLIBRARIES = $(pkglib_LTLIBRARIES) $(pkgmodexec_LTLIBRARIES) am__DEPENDENCIES_1 = +@ENABLE_STATIC_MODULE_FALSE@libstix_con_la_DEPENDENCIES = \ +@ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_1) +am__libstix_con_la_SOURCES_DIST = mod-con.c mod-con.h +@ENABLE_STATIC_MODULE_FALSE@am_libstix_con_la_OBJECTS = \ +@ENABLE_STATIC_MODULE_FALSE@ libstix_con_la-mod-con.lo +libstix_con_la_OBJECTS = $(am_libstix_con_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_con_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ + $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ + $(AM_CFLAGS) $(CFLAGS) $(libstix_con_la_LDFLAGS) $(LDFLAGS) -o \ + $@ +@ENABLE_STATIC_MODULE_FALSE@am_libstix_con_la_rpath = -rpath \ +@ENABLE_STATIC_MODULE_FALSE@ $(pkgmodexecdir) @ENABLE_STATIC_MODULE_FALSE@libstix_snd_la_DEPENDENCIES = \ @ENABLE_STATIC_MODULE_FALSE@ $(am__DEPENDENCIES_1) am__libstix_snd_la_SOURCES_DIST = mod-snd.c mod-snd.h @ENABLE_STATIC_MODULE_FALSE@am_libstix_snd_la_OBJECTS = \ @ENABLE_STATIC_MODULE_FALSE@ libstix_snd_la-mod-snd.lo libstix_snd_la_OBJECTS = $(am_libstix_snd_la_OBJECTS) -AM_V_lt = $(am__v_lt_@AM_V@) -am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) -am__v_lt_0 = --silent -am__v_lt_1 = libstix_snd_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(libstix_snd_la_LDFLAGS) $(LDFLAGS) -o \ @@ -152,11 +164,11 @@ libstix_snd_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) libstix_la_DEPENDENCIES = $(am__DEPENDENCIES_2) am_libstix_la_OBJECTS = libstix_la-bigint.lo libstix_la-comp.lo \ - libstix_la-debug.lo libstix_la-dic.lo libstix_la-exec.lo \ - libstix_la-gc.lo libstix_la-heap.lo libstix_la-ignite.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-debug.lo libstix_la-decode.lo libstix_la-dic.lo \ + libstix_la-exec.lo libstix_la-gc.lo libstix_la-heap.lo \ + libstix_la-ignite.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) libstix_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ @@ -202,10 +214,11 @@ 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_snd_la_SOURCES) $(libstix_la_SOURCES) \ - $(stix_SOURCES) -DIST_SOURCES = $(am__libstix_snd_la_SOURCES_DIST) \ +SOURCES = $(libstix_con_la_SOURCES) $(libstix_snd_la_SOURCES) \ $(libstix_la_SOURCES) $(stix_SOURCES) +DIST_SOURCES = $(am__libstix_con_la_SOURCES_DIST) \ + $(am__libstix_snd_la_SOURCES_DIST) $(libstix_la_SOURCES) \ + $(stix_SOURCES) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -422,6 +435,7 @@ libstix_la_SOURCES = \ bigint.c \ comp.c \ debug.c \ + decode.c \ dic.c \ exec.c \ gc.c \ @@ -457,11 +471,15 @@ stix_LDADD = $(LIBADD_LIB_COMMON) -lstix #-ldyncall_s @ENABLE_STATIC_MODULE_FALSE@LDFLAGS_MOD_COMMON = $(LDFLAGS_LIB_COMMON) @ENABLE_STATIC_MODULE_FALSE@LIBADD_MOD_COMMON = -lstix @ENABLE_STATIC_MODULE_FALSE@pkgmodexecdir = $(libdir) -@ENABLE_STATIC_MODULE_FALSE@pkgmodexec_LTLIBRARIES = libstix-snd.la +@ENABLE_STATIC_MODULE_FALSE@pkgmodexec_LTLIBRARIES = libstix-snd.la libstix-con.la @ENABLE_STATIC_MODULE_FALSE@libstix_snd_la_SOURCES = mod-snd.c mod-snd.h @ENABLE_STATIC_MODULE_FALSE@libstix_snd_la_CPPFLAGS = $(CPPFLAGS_MOD_COMMON) @ENABLE_STATIC_MODULE_FALSE@libstix_snd_la_LDFLAGS = $(LDFLAGS_MOD_COMMON) @ENABLE_STATIC_MODULE_FALSE@libstix_snd_la_LIBADD = $(LIBADD_MOD_COMMON) +@ENABLE_STATIC_MODULE_FALSE@libstix_con_la_SOURCES = mod-con.c mod-con.h +@ENABLE_STATIC_MODULE_FALSE@libstix_con_la_CPPFLAGS = $(CPPFLAGS_MOD_COMMON) +@ENABLE_STATIC_MODULE_FALSE@libstix_con_la_LDFLAGS = $(LDFLAGS_MOD_COMMON) +@ENABLE_STATIC_MODULE_FALSE@libstix_con_la_LIBADD = $(LIBADD_MOD_COMMON) all: stix-cfg.h $(MAKE) $(AM_MAKEFLAGS) all-am @@ -583,6 +601,9 @@ clean-pkgmodexecLTLIBRARIES: rm -f $${locs}; \ } +libstix-con.la: $(libstix_con_la_OBJECTS) $(libstix_con_la_DEPENDENCIES) $(EXTRA_libstix_con_la_DEPENDENCIES) + $(AM_V_CCLD)$(libstix_con_la_LINK) $(am_libstix_con_la_rpath) $(libstix_con_la_OBJECTS) $(libstix_con_la_LIBADD) $(LIBS) + libstix-snd.la: $(libstix_snd_la_OBJECTS) $(libstix_snd_la_DEPENDENCIES) $(EXTRA_libstix_snd_la_DEPENDENCIES) $(AM_V_CCLD)$(libstix_snd_la_LINK) $(am_libstix_snd_la_rpath) $(libstix_snd_la_OBJECTS) $(libstix_snd_la_LIBADD) $(LIBS) @@ -648,9 +669,11 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_con_la-mod-con.Plo@am__quote@ @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-exec.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-gc.Plo@am__quote@ @@ -690,6 +713,13 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< +libstix_con_la-mod-con.lo: mod-con.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstix_con_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libstix_con_la-mod-con.lo -MD -MP -MF $(DEPDIR)/libstix_con_la-mod-con.Tpo -c -o libstix_con_la-mod-con.lo `test -f 'mod-con.c' || echo '$(srcdir)/'`mod-con.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_con_la-mod-con.Tpo $(DEPDIR)/libstix_con_la-mod-con.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mod-con.c' object='libstix_con_la-mod-con.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_con_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libstix_con_la-mod-con.lo `test -f 'mod-con.c' || echo '$(srcdir)/'`mod-con.c + libstix_snd_la-mod-snd.lo: mod-snd.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstix_snd_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libstix_snd_la-mod-snd.lo -MD -MP -MF $(DEPDIR)/libstix_snd_la-mod-snd.Tpo -c -o libstix_snd_la-mod-snd.lo `test -f 'mod-snd.c' || echo '$(srcdir)/'`mod-snd.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_snd_la-mod-snd.Tpo $(DEPDIR)/libstix_snd_la-mod-snd.Plo @@ -718,6 +748,13 @@ libstix_la-debug.lo: debug.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstix_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libstix_la-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@ +@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 + 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 diff --git a/stix/lib/comp.c b/stix/lib/comp.c index f46d7e3..07e62a9 100644 --- a/stix/lib/comp.c +++ b/stix/lib/comp.c @@ -159,7 +159,6 @@ typedef enum voca_id_t voca_id_t; # define DBGOUT_COMP_3(fmt,a1,a2,a3) #endif - 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); @@ -1547,13 +1546,13 @@ static const stix_ooch_t* add_io_name (stix_t* stix, const stix_oocs_t* name) static int begin_include (stix_t* stix) { - stix_io_arg_t* arg; + stix_ioarg_t* arg; const stix_ooch_t* io_name; io_name = add_io_name (stix, &stix->c->tok.name); if (!io_name) return -1; - arg = (stix_io_arg_t*) stix_callocmem (stix, STIX_SIZEOF(*arg)); + arg = (stix_ioarg_t*) stix_callocmem (stix, STIX_SIZEOF(*arg)); if (!arg) goto oops; arg->name = io_name; @@ -1600,7 +1599,7 @@ oops: static int end_include (stix_t* stix) { int x; - stix_io_arg_t* cur; + stix_ioarg_t* cur; if (stix->c->curinp == &stix->c->arg) return 0; /* no include */ @@ -2633,7 +2632,7 @@ static int compile_method_primitive (stix_t* stix) while (ptr < end && is_digitchar(*ptr)) { prim_no = prim_no * 10 + (*ptr - '0'); - if (!STIX_OOI_IN_PREAMBLE_INDEX_RANGE(prim_no)) + if (!STIX_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(prim_no)) { set_syntax_error (stix, STIX_SYNERR_PRIMNO, &stix->c->tok.loc, &stix->c->tok.name); return -1; @@ -2658,7 +2657,7 @@ static int compile_method_primitive (stix_t* stix) /* the symbol literal contains an underscore. * and it is none of the first of the last character */ if (add_symbol_literal(stix, &stix->c->tok.name, &lit_idx) >= 0 && - STIX_OOI_IN_PREAMBLE_INDEX_RANGE(lit_idx)) + STIX_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(lit_idx)) { stix->c->mth.prim_type = 2; /* named primitive */ stix->c->mth.prim_no = lit_idx; @@ -2669,7 +2668,7 @@ static int compile_method_primitive (stix_t* stix) set_syntax_error (stix, STIX_SYNERR_PRIMNO, &stix->c->tok.loc, &stix->c->tok.name); return -1; } - else if (!STIX_OOI_IN_PREAMBLE_INDEX_RANGE(prim_no)) + else if (!STIX_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(prim_no)) { set_syntax_error (stix, STIX_SYNERR_PRIMNO, &stix->c->tok.loc, &stix->c->tok.name); return -1; @@ -4263,7 +4262,7 @@ static int add_compiled_method (stix_t* stix) preamble_index = (preamble_index << 8) | stix->c->mth.code.ptr[i]; } - if (!STIX_OOI_IN_PREAMBLE_INDEX_RANGE(preamble_index)) + if (!STIX_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(preamble_index)) { /* the index got out of the range */ preamble_code = STIX_METHOD_PREAMBLE_NONE; @@ -4290,7 +4289,7 @@ static int add_compiled_method (stix_t* stix) preamble_index = 0; } - STIX_ASSERT (STIX_OOI_IN_PREAMBLE_INDEX_RANGE(preamble_index)); + STIX_ASSERT (STIX_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(preamble_index)); mth->owner = stix->c->cls.self_oop; mth->name = name; @@ -4311,9 +4310,15 @@ the compiler must collect all source method string collected so far. need to write code to collect string. */ + /* TODO: if (decoding is enabled... */ +printf (">>>> BYTE CODE.....\n"); + stix_decode (stix, mth); + + stix_poptmps (stix, tmp_count); tmp_count = 0; if (!stix_putatdic(stix, stix->c->cls.mthdic_oop[stix->c->mth.type], (stix_oop_t)name, (stix_oop_t)mth)) goto oops; + return 0; oops: @@ -5190,7 +5195,7 @@ static void fini_compiler (stix_t* stix) } } -int stix_compile (stix_t* stix, stix_io_impl_t io) +int stix_compile (stix_t* stix, stix_ioimpl_t io) { int n; @@ -5259,7 +5264,7 @@ oops: * closed. close them */ while (stix->c->curinp != &stix->c->arg) { - stix_io_arg_t* prev; + stix_ioarg_t* prev; /* nothing much to do about a close error */ stix->c->impl (stix, STIX_IO_CLOSE, stix->c->curinp); @@ -5279,3 +5284,5 @@ void stix_getsynerr (stix_t* stix, stix_synerr_t* synerr) STIX_ASSERT (stix->c != STIX_NULL); if (synerr) *synerr = stix->c->synerr; } + + diff --git a/stix/lib/decode.c b/stix/lib/decode.c new file mode 100644 index 0000000..e44811f --- /dev/null +++ b/stix/lib/decode.c @@ -0,0 +1,503 @@ +/* + * $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 WAfRRANTIES + 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" + +# define DECODE_OUT_0(fmt) printf("\t" fmt "\n") +# define DECODE_OUT_1(fmt,a1) printf("\t" fmt "\n",a1) +# define DECODE_OUT_2(fmt,a1,a2) printf("\t" fmt "\n", a1, a2) +# define DECODE_OUT_3(fmt,a1,a2,a3) printf("\t" fmt "\n", a1, a2, a3) + + +#define FETCH_BYTE_CODE(stix) (cdptr[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) \ + do { \ + v_ooi = FETCH_BYTE_CODE(stix); \ + v_ooi = (v_ooi << 8) | FETCH_BYTE_CODE(stix); \ + } while (0) +#else +# define FETCH_PARAM_CODE_TO(stix,v_ooi) (v_ooi = FETCH_BYTE_CODE(stix)) +#endif + +/* TODO: check if ip shoots beyond the maximum length in fetching code and parameters */ +static int decode (stix_t* stix, stix_oop_method_t mth) +{ + stix_oob_t bcode, * cdptr; + stix_oow_t ip = 0, cdlen; + stix_ooi_t b1, b2; + + cdptr = STIX_METHOD_GET_CODE_BYTE(mth); + cdlen = STIX_METHOD_GET_CODE_SIZE(mth); + +/* TODO: check if ip increases beyon bcode when fetching parameters too */ + while (ip < cdlen) + { + FETCH_BYTE_CODE_TO(stix, bcode); + + switch (bcode) + { + case BCODE_PUSH_INSTVAR_X: + FETCH_PARAM_CODE_TO (stix, b1); + goto push_instvar; + case BCODE_PUSH_INSTVAR_0: + case BCODE_PUSH_INSTVAR_1: + case BCODE_PUSH_INSTVAR_2: + case BCODE_PUSH_INSTVAR_3: + case BCODE_PUSH_INSTVAR_4: + case BCODE_PUSH_INSTVAR_5: + case BCODE_PUSH_INSTVAR_6: + case BCODE_PUSH_INSTVAR_7: + b1 = bcode & 0x7; /* low 3 bits */ + push_instvar: + DECODE_OUT_1 ("push_instvar %lu", (unsigned long int)b1); + break; + + /* ------------------------------------------------- */ + + case BCODE_STORE_INTO_INSTVAR_X: + FETCH_PARAM_CODE_TO (stix, b1); + goto store_instvar; + case BCODE_STORE_INTO_INSTVAR_0: + case BCODE_STORE_INTO_INSTVAR_1: + case BCODE_STORE_INTO_INSTVAR_2: + case BCODE_STORE_INTO_INSTVAR_3: + case BCODE_STORE_INTO_INSTVAR_4: + case BCODE_STORE_INTO_INSTVAR_5: + case BCODE_STORE_INTO_INSTVAR_6: + case BCODE_STORE_INTO_INSTVAR_7: + b1 = bcode & 0x7; /* low 3 bits */ + store_instvar: + DECODE_OUT_1 ("store_into_instvar %lu", (unsigned long int)b1); + break; + + case BCODE_POP_INTO_INSTVAR_X: + FETCH_PARAM_CODE_TO (stix, b1); + goto pop_into_instvar; + case BCODE_POP_INTO_INSTVAR_0: + case BCODE_POP_INTO_INSTVAR_1: + case BCODE_POP_INTO_INSTVAR_2: + case BCODE_POP_INTO_INSTVAR_3: + case BCODE_POP_INTO_INSTVAR_4: + case BCODE_POP_INTO_INSTVAR_5: + case BCODE_POP_INTO_INSTVAR_6: + case BCODE_POP_INTO_INSTVAR_7: + b1 = bcode & 0x7; /* low 3 bits */ + pop_into_instvar: + DECODE_OUT_1 ("pop_into_instvar %lu", (unsigned long int)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); + goto handle_tempvar; + + case BCODE_PUSH_TEMPVAR_0: + case BCODE_PUSH_TEMPVAR_1: + case BCODE_PUSH_TEMPVAR_2: + case BCODE_PUSH_TEMPVAR_3: + case BCODE_PUSH_TEMPVAR_4: + case BCODE_PUSH_TEMPVAR_5: + case BCODE_PUSH_TEMPVAR_6: + case BCODE_PUSH_TEMPVAR_7: + case BCODE_STORE_INTO_TEMPVAR_0: + case BCODE_STORE_INTO_TEMPVAR_1: + case BCODE_STORE_INTO_TEMPVAR_2: + case BCODE_STORE_INTO_TEMPVAR_3: + case BCODE_STORE_INTO_TEMPVAR_4: + case BCODE_STORE_INTO_TEMPVAR_5: + case BCODE_STORE_INTO_TEMPVAR_6: + case BCODE_STORE_INTO_TEMPVAR_7: + case BCODE_POP_INTO_TEMPVAR_0: + case BCODE_POP_INTO_TEMPVAR_1: + case BCODE_POP_INTO_TEMPVAR_2: + case BCODE_POP_INTO_TEMPVAR_3: + case BCODE_POP_INTO_TEMPVAR_4: + case BCODE_POP_INTO_TEMPVAR_5: + case BCODE_POP_INTO_TEMPVAR_6: + case BCODE_POP_INTO_TEMPVAR_7: + b1 = bcode & 0x7; /* low 3 bits */ + handle_tempvar: + + if ((bcode >> 4) & 1) + { + /* push - bit 4 on */ + DECODE_OUT_1 ("push_tempvar %d", (int)b1); + } + else + { + /* store or pop - bit 5 off */ + if ((bcode >> 3) & 1) + { + /* pop - bit 3 on */ + DECODE_OUT_1 ("pop_into_tempvar %d", (int)b1); + } + else + { + DECODE_OUT_1 ("store_into_tempvar %d", (int)b1); + } + } + break; + + /* ------------------------------------------------- */ + case BCODE_PUSH_LITERAL_X: + FETCH_PARAM_CODE_TO (stix, b1); + goto push_literal; + + case BCODE_PUSH_LITERAL_0: + case BCODE_PUSH_LITERAL_1: + case BCODE_PUSH_LITERAL_2: + case BCODE_PUSH_LITERAL_3: + case BCODE_PUSH_LITERAL_4: + case BCODE_PUSH_LITERAL_5: + case BCODE_PUSH_LITERAL_6: + case BCODE_PUSH_LITERAL_7: + b1 = bcode & 0x7; /* low 3 bits */ + push_literal: + DECODE_OUT_1 ("push_literal %d", (int)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); + goto handle_object; + + case BCODE_PUSH_OBJECT_0: + case BCODE_PUSH_OBJECT_1: + case BCODE_PUSH_OBJECT_2: + case BCODE_PUSH_OBJECT_3: + case BCODE_STORE_INTO_OBJECT_0: + case BCODE_STORE_INTO_OBJECT_1: + case BCODE_STORE_INTO_OBJECT_2: + case BCODE_STORE_INTO_OBJECT_3: + case BCODE_POP_INTO_OBJECT_0: + case BCODE_POP_INTO_OBJECT_1: + case BCODE_POP_INTO_OBJECT_2: + case BCODE_POP_INTO_OBJECT_3: + b1 = bcode & 0x3; /* low 2 bits */ + handle_object: + if ((bcode >> 3) & 1) + { + if ((bcode >> 2) & 1) + { + DECODE_OUT_1("pop_into_object %d", (int)b1); + } + else + { + DECODE_OUT_1("store_into_object %d", (int)b1); + } + } + else + { + DECODE_OUT_1("push_object %d", (int)b1); + } + break; + + /* -------------------------------------------------------- */ + + case BCODE_JUMP_FORWARD_X: + FETCH_PARAM_CODE_TO (stix, b1); + DECODE_OUT_1 ("jump_forward %d", (int)b1); + break; + + case BCODE_JUMP_FORWARD_0: + case BCODE_JUMP_FORWARD_1: + case BCODE_JUMP_FORWARD_2: + case BCODE_JUMP_FORWARD_3: + DECODE_OUT_1 ("jump_forward %d", (int)(bcode & 0x3)); /* low 2 bits */ + break; + + case BCODE_JUMP_BACKWARD_X: + FETCH_PARAM_CODE_TO (stix, b1); + DECODE_OUT_1 ("jump_backward %d", (int)b1); + stix->ip += b1; + break; + + case BCODE_JUMP_BACKWARD_0: + case BCODE_JUMP_BACKWARD_1: + case BCODE_JUMP_BACKWARD_2: + case BCODE_JUMP_BACKWARD_3: + DECODE_OUT_1 ("jump_backward %d", (int)(bcode & 0x3)); /* low 2 bits */ + break; + + case BCODE_JUMP_IF_TRUE_X: + case BCODE_JUMP_IF_FALSE_X: + case BCODE_JUMP_IF_TRUE_0: + case BCODE_JUMP_IF_TRUE_1: + case BCODE_JUMP_IF_TRUE_2: + case BCODE_JUMP_IF_TRUE_3: + case BCODE_JUMP_IF_FALSE_0: + case BCODE_JUMP_IF_FALSE_1: + case BCODE_JUMP_IF_FALSE_2: + case BCODE_JUMP_IF_FALSE_3: +printf ("<<<<<<<<<<<<<< JUMP NOT IMPLEMENTED YET >>>>>>>>>>>> \n"); +stix->errnum = STIX_ENOIMPL; +return -1; + + case BCODE_JUMP2_FORWARD: + FETCH_PARAM_CODE_TO (stix, b1); + DECODE_OUT_1 ("jump2_forward %d", (int)b1); + break; + + case BCODE_JUMP2_BACKWARD: + FETCH_PARAM_CODE_TO (stix, b1); + DECODE_OUT_1 ("jump2_backward %d", (int)b1); + break; + + /* -------------------------------------------------------- */ + + 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); + goto handle_ctxtempvar; + case BCODE_PUSH_CTXTEMPVAR_0: + case BCODE_PUSH_CTXTEMPVAR_1: + case BCODE_PUSH_CTXTEMPVAR_2: + case BCODE_PUSH_CTXTEMPVAR_3: + case BCODE_STORE_INTO_CTXTEMPVAR_0: + case BCODE_STORE_INTO_CTXTEMPVAR_1: + case BCODE_STORE_INTO_CTXTEMPVAR_2: + case BCODE_STORE_INTO_CTXTEMPVAR_3: + case BCODE_POP_INTO_CTXTEMPVAR_0: + case BCODE_POP_INTO_CTXTEMPVAR_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); + + handle_ctxtempvar: + if ((bcode >> 3) & 1) + { + /* store or pop */ + + if ((bcode >> 2) & 1) + { + DECODE_OUT_2 ("pop_into_ctxtempvar %d %d", (int)b1, (int)b2); + } + else + { + DECODE_OUT_2 ("store_into_ctxtempvar %d %d", (int)b1, (int)b2); + } + } + else + { + /* push */ + DECODE_OUT_2 ("push_ctxtempvar %d %d", (int)b1, (int)b2); + } + + break; + /* -------------------------------------------------------- */ + + 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); + goto handle_objvar; + + case BCODE_PUSH_OBJVAR_0: + case BCODE_PUSH_OBJVAR_1: + case BCODE_PUSH_OBJVAR_2: + case BCODE_PUSH_OBJVAR_3: + case BCODE_STORE_INTO_OBJVAR_0: + case BCODE_STORE_INTO_OBJVAR_1: + case BCODE_STORE_INTO_OBJVAR_2: + case BCODE_STORE_INTO_OBJVAR_3: + case BCODE_POP_INTO_OBJVAR_0: + case BCODE_POP_INTO_OBJVAR_1: + case BCODE_POP_INTO_OBJVAR_2: + case BCODE_POP_INTO_OBJVAR_3: + /* 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); + + handle_objvar: + if ((bcode >> 3) & 1) + { + /* store or pop */ + if ((bcode >> 2) & 1) + { + DECODE_OUT_2 ("pop_into_objvar %d %d", (int)b1, (int)b2); + } + else + { + DECODE_OUT_2 ("store_into_objvar %d %d", (int)b1, (int)b2); + } + } + else + { + DECODE_OUT_2 ("push_objvar %d %d", (int)b1, (int)b2); + } + + break; + + /* -------------------------------------------------------- */ + case BCODE_SEND_MESSAGE_X: + 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); + goto handle_send_message; + + case BCODE_SEND_MESSAGE_0: + case BCODE_SEND_MESSAGE_1: + case BCODE_SEND_MESSAGE_2: + case BCODE_SEND_MESSAGE_3: + case BCODE_SEND_MESSAGE_TO_SUPER_0: + case BCODE_SEND_MESSAGE_TO_SUPER_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); + + handle_send_message: + DECODE_OUT_3 ("send_message%s nargs=%d selector=%d", (((bcode >> 2) & 1)? "_to_super": ""), (int)b1, (int)b2); + break; + + /* -------------------------------------------------------- */ + + case BCODE_PUSH_RECEIVER: + DECODE_OUT_0 ("push_receiver"); + break; + + case BCODE_PUSH_NIL: + DECODE_OUT_0 ("push_nil"); + break; + + case BCODE_PUSH_TRUE: + DECODE_OUT_0 ("push_true"); + break; + + case BCODE_PUSH_FALSE: + DECODE_OUT_0 ("push_false"); + break; + + case BCODE_PUSH_CONTEXT: + DECODE_OUT_0 ("push_context"); + break; + + case BCODE_PUSH_NEGONE: + DECODE_OUT_0 ("push_negone"); + break; + + case BCODE_PUSH_ZERO: + DECODE_OUT_0 ("push_zero"); + break; + + case BCODE_PUSH_ONE: + DECODE_OUT_0 ("push_one"); + break; + + case BCODE_PUSH_TWO: + DECODE_OUT_0 ("push_two"); + break; + + case BCODE_PUSH_INTLIT: + FETCH_PARAM_CODE_TO (stix, b1); + DECODE_OUT_1 ("push_intlit %d", (int)b1); + break; + + case BCODE_PUSH_NEGINTLIT: + FETCH_PARAM_CODE_TO (stix, b1); + DECODE_OUT_1 ("push_negintlit %d", (int)-b1); + break; + + /* -------------------------------------------------------- */ + + case BCODE_DUP_STACKTOP: + DECODE_OUT_0 ("dup_stacktop"); + break; + + case BCODE_POP_STACKTOP: + DECODE_OUT_0 ("pop_stacktop"); + break; + + case BCODE_RETURN_STACKTOP: + DECODE_OUT_0 ("return_stacktop"); + break; + + case BCODE_RETURN_RECEIVER: + DECODE_OUT_0 ("return_receiver"); + break; + + case BCODE_RETURN_FROM_BLOCK: + DECODE_OUT_0 ("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); + + DECODE_OUT_2 ("make_block %d %d", (int)b1, (int)b2); + + STIX_ASSERT (b1 >= 0); + STIX_ASSERT (b2 >= b1); + break; + + + case BCODE_SEND_BLOCK_COPY: + DECODE_OUT_0 ("send_block_copy"); + break; + + case BCODE_NOOP: + /* do nothing */ + DECODE_OUT_0 ("noop"); + break; + + default: +printf ("UNKNOWN BYTE CODE ENCOUNTERED %x\n", (int)bcode); + stix->errnum = STIX_EINTERN; + break; + + } + } + + /* print literal frame contents */ + for (ip = 0; ip < STIX_OBJ_GET_SIZE(mth) - STIX_METHOD_NAMED_INSTVARS; ip++) + { + printf (" %8lu ", (unsigned long int)ip); + print_object (stix, mth->slot[ip]); + printf ("\n"); + } + + return 0; +} + +int stix_decode (stix_t* stix, stix_oop_method_t mth) +{ + return decode (stix, mth); +} diff --git a/stix/lib/exec.c b/stix/lib/exec.c index 7b10d66..1dcf554 100644 --- a/stix/lib/exec.c +++ b/stix/lib/exec.c @@ -96,38 +96,11 @@ #if defined(STIX_USE_PROCSTK) #define LOAD_ACTIVE_SP(stix) LOAD_SP(stix, (stix)->processor->active) #define STORE_ACTIVE_SP(stix) STORE_SP(stix, (stix)->processor->active) - -/* TODO: stack bound check when pushing */ - #define ACTIVE_STACK_PUSH(stix,v) \ - do { \ - (stix)->sp = (stix)->sp + 1; \ - (stix)->processor->active->slot[(stix)->sp] = v; \ - } while (0) - - #define ACTIVE_STACK_GET(stix,v_sp) ((stix)->processor->active->slot[v_sp]) - #define ACTIVE_STACK_SET(stix,v_sp,v_obj) ((stix)->processor->active->slot[v_sp] = v_obj) - #else #define LOAD_ACTIVE_SP(stix) LOAD_SP(stix, (stix)->active_context) #define STORE_ACTIVE_SP(stix) STORE_SP(stix, (stix)->active_context) - - #define ACTIVE_STACK_PUSH(stix,v) \ - do { \ - (stix)->sp = (stix)->sp + 1; \ - (stix)->active_context->slot[(stix)->sp] = v; \ - } while (0) - - #define ACTIVE_STACK_GET(stix,v_sp) ((stix)->active_context->slot[v_sp]) - #define ACTIVE_STACK_SET(stix,v_sp,v_obj) ((stix)->active_context->slot[v_sp] = v_obj) #endif -#define ACTIVE_STACK_GETTOP(stix) ACTIVE_STACK_GET(stix, (stix)->sp) -#define ACTIVE_STACK_SETTOP(stix,v_obj) ACTIVE_STACK_SET(stix, (stix)->sp, v_obj) - -#define ACTIVE_STACK_POP(stix) ((stix)->sp = (stix)->sp - 1) -#define ACTIVE_STACK_UNPOP(stix) ((stix)->sp = (stix)->sp + 1) -#define ACTIVE_STACK_POPS(stix,count) ((stix)->sp = (stix)->sp - (count)) -#define ACTIVE_STACK_ISEMPTY(stix) ((stix)->sp <= -1) #if defined(STIX_USE_PROCSTK) #define SWITCH_ACTIVE_CONTEXT(stix,v_ctx) \ @@ -1028,12 +1001,12 @@ static STIX_INLINE int activate_new_method (stix_t* stix, stix_oop_method_t mth) for (i = nargs; i > 0; ) { /* copy argument */ - ctx->slot[--i] = ACTIVE_STACK_GETTOP (stix); - ACTIVE_STACK_POP (stix); + ctx->slot[--i] = STIX_STACK_GETTOP (stix); + STIX_STACK_POP (stix); } /* copy receiver */ - ctx->receiver_or_source = ACTIVE_STACK_GETTOP (stix); - ACTIVE_STACK_POP (stix); + ctx->receiver_or_source = STIX_STACK_GETTOP (stix); + STIX_STACK_POP (stix); STIX_ASSERT (stix->sp >= -1); @@ -1222,7 +1195,7 @@ TODO: overcome this problem stix_poptmps (stix, 3); if (!proc) return -1; - ACTIVE_STACK_PUSH (stix, ass->value); /* push the receiver - the object referenced by 'objname' */ + 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) */ STIX_ASSERT (stix->processor->active == proc); @@ -1242,17 +1215,17 @@ static int prim_dump (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs >= 0); printf ("RECEIVER: "); - print_object (stix, ACTIVE_STACK_GET(stix, stix->sp - nargs)); + print_object (stix, STIX_STACK_GET(stix, stix->sp - nargs)); printf ("\n"); for (i = nargs; i > 0; ) { --i; printf ("ARGUMENT: "); - print_object (stix, ACTIVE_STACK_GET(stix, stix->sp - i)); + print_object (stix, STIX_STACK_GET(stix, stix->sp - i)); printf ("\n"); } - ACTIVE_STACK_POPS (stix, nargs); + STIX_STACK_POPS (stix, nargs); return 1; /* success */ } @@ -1262,13 +1235,13 @@ static int prim_identical (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); b = (rcv == arg)? stix->_true: stix->_false; - ACTIVE_STACK_POP (stix); - ACTIVE_STACK_SETTOP (stix, b); + STIX_STACK_POP (stix); + STIX_STACK_SETTOP (stix, b); return 1; } @@ -1278,13 +1251,13 @@ static int prim_not_identical (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); b = (rcv != arg)? stix->_true: stix->_false; - ACTIVE_STACK_POP (stix); - ACTIVE_STACK_SETTOP (stix, b); + STIX_STACK_POP (stix); + STIX_STACK_SETTOP (stix, b); return 1; } @@ -1293,9 +1266,9 @@ static int prim_class (stix_t* stix, stix_ooi_t nargs) stix_oop_t rcv, c; STIX_ASSERT (nargs == 0); - rcv = ACTIVE_STACK_GETTOP (stix); + rcv = STIX_STACK_GETTOP (stix); c = STIX_CLASSOF(stix, rcv); - ACTIVE_STACK_SETTOP (stix, c); + STIX_STACK_SETTOP (stix, c); return 1; /* success */ } @@ -1305,7 +1278,7 @@ static int prim_basic_new (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 0); - rcv = ACTIVE_STACK_GETTOP (stix); + rcv = STIX_STACK_GETTOP (stix); if (STIX_CLASSOF(stix, rcv) != stix->_class) { @@ -1317,7 +1290,7 @@ static int prim_basic_new (stix_t* stix, stix_ooi_t nargs) if (!obj) return -1; /* emulate 'pop receiver' and 'push result' */ - ACTIVE_STACK_SETTOP (stix, obj); + STIX_STACK_SETTOP (stix, obj); return 1; /* success */ } @@ -1328,14 +1301,14 @@ static int prim_basic_new_with_size (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); + rcv = STIX_STACK_GET(stix, stix->sp - 1); if (STIX_CLASSOF(stix, rcv) != stix->_class) { /* the receiver is not a class object */ return 0; } - szoop = ACTIVE_STACK_GET(stix, stix->sp); + szoop = STIX_STACK_GET(stix, stix->sp); if (stix_inttooow (stix, szoop, &size) <= 0) { /* integer out of range or not integer */ @@ -1354,8 +1327,8 @@ static int prim_basic_new_with_size (stix_t* stix, stix_ooi_t nargs) /* remove the argument and replace the receiver with a new object * instantiated */ - ACTIVE_STACK_POP (stix); - ACTIVE_STACK_SETTOP (stix, obj); + STIX_STACK_POP (stix); + STIX_STACK_SETTOP (stix, obj); return 1; /* success */ } @@ -1386,11 +1359,11 @@ static int prim_ngc_dispose (stix_t* stix, stix_ooi_t nargs) stix_oop_t rcv; STIX_ASSERT (nargs == 0); - rcv = ACTIVE_STACK_GETTOP (stix); + rcv = STIX_STACK_GETTOP (stix); stix_freemem (stix, rcv); - ACTIVE_STACK_SETTOP (stix, stix->_nil); + STIX_STACK_SETTOP (stix, stix->_nil); return 1; /* success */ } @@ -1400,13 +1373,13 @@ static int prim_shallow_copy (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 0); - rcv = ACTIVE_STACK_GETTOP (stix); + rcv = STIX_STACK_GETTOP (stix); obj = stix_shallowcopy (stix, rcv); if (!obj) return -1; /* emulate 'pop receiver' and 'push result' */ - ACTIVE_STACK_SETTOP (stix, obj); + STIX_STACK_SETTOP (stix, obj); return 1; /* success */ } @@ -1416,11 +1389,11 @@ static int prim_basic_size (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 0); - rcv = ACTIVE_STACK_GETTOP(stix); + rcv = STIX_STACK_GETTOP(stix); sz = stix_oowtoint (stix, STIX_OBJ_GET_SIZE(rcv)); if (!sz) return -1; /* hard failure */ - ACTIVE_STACK_SETTOP(stix, sz); + STIX_STACK_SETTOP(stix, sz); return 1; } @@ -1432,14 +1405,14 @@ static int prim_basic_at (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); + rcv = STIX_STACK_GET(stix, stix->sp - 1); if (!STIX_OOP_IS_POINTER(rcv)) { /* the receiver is a special numeric object, not a normal pointer */ return 0; } - pos = ACTIVE_STACK_GET(stix, stix->sp); + pos = STIX_STACK_GET(stix, stix->sp); if (stix_inttooow (stix, pos, &idx) <= 0) { /* negative integer or not integer */ @@ -1480,8 +1453,8 @@ static int prim_basic_at (stix_t* stix, stix_ooi_t nargs) return -1; } - ACTIVE_STACK_POP (stix); - ACTIVE_STACK_SETTOP (stix, v); + STIX_STACK_POP (stix); + STIX_STACK_SETTOP (stix, v); return 1; } @@ -1492,14 +1465,14 @@ static int prim_basic_at_put (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 2); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 2); + rcv = STIX_STACK_GET(stix, stix->sp - 2); if (!STIX_OOP_IS_POINTER(rcv)) { /* the receiver is a special numeric object, not a normal pointer */ return 0; } - pos = ACTIVE_STACK_GET(stix, stix->sp - 1); - val = ACTIVE_STACK_GET(stix, stix->sp); + pos = STIX_STACK_GET(stix, stix->sp - 1); + val = STIX_STACK_GET(stix, stix->sp); if (stix_inttooow (stix, pos, &idx) <= 0) { @@ -1571,9 +1544,9 @@ static int prim_basic_at_put (stix_t* stix, stix_ooi_t nargs) return -1; } - ACTIVE_STACK_POPS (stix, 2); + STIX_STACK_POPS (stix, 2); /* TODO: return receiver or value? */ - ACTIVE_STACK_SETTOP (stix, val); + STIX_STACK_SETTOP (stix, val); return 1; } @@ -1591,7 +1564,7 @@ static int prim_context_goto (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); + rcv = STIX_STACK_GET(stix, stix->sp - 1); if (STIX_CLASSOF(stix, rcv) != stix->_method_context) { #if defined(STIX_DEBUG_EXEC_001) @@ -1600,7 +1573,7 @@ printf ("prim_context_goto: PRIMITVE RECEIVER IS NOT A METHOD CONTEXT\n"); return 0; } - pc = ACTIVE_STACK_GET(stix, stix->sp); + pc = STIX_STACK_GET(stix, stix->sp); if (!STIX_OOP_IS_SMOOI(pc) || STIX_OOP_TO_SMOOI(pc) < 0) { #if defined(STIX_DEBUG_EXEC_001) @@ -1612,7 +1585,7 @@ printf ("prim_context_goto: PRIMITVE ARGUMENT IS INVALID\n"); ((stix_oop_context_t)rcv)->ip = pc; LOAD_ACTIVE_IP (stix); - ACTIVE_STACK_POPS (stix, 2); /* pop both the argument and the receiver */ + STIX_STACK_POPS (stix, 2); /* pop both the argument and the receiver */ return 1; } @@ -1638,7 +1611,7 @@ static int __block_value (stix_t* stix, stix_ooi_t rcv_blkctx_offset, stix_ooi_t * itself. Let me simply clone a block context to allow reentrancy like this * while the block context is active */ - rcv_blkctx = (stix_oop_context_t)ACTIVE_STACK_GET(stix, stix->sp - rcv_blkctx_offset); + rcv_blkctx = (stix_oop_context_t)STIX_STACK_GET(stix, stix->sp - rcv_blkctx_offset); if (STIX_CLASSOF(stix, rcv_blkctx) != stix->_block_context) { /* the receiver must be a block context */ @@ -1684,7 +1657,7 @@ printf ("PRIM BlockContext value FAIL - NARGS MISMATCH\n"); if (!blkctx) return -1; /* get rcv_blkctx again to be GC-safe for stix_instantiate() above */ - rcv_blkctx = (stix_oop_context_t)ACTIVE_STACK_GET(stix, stix->sp - rcv_blkctx_offset); + rcv_blkctx = (stix_oop_context_t)STIX_STACK_GET(stix, stix->sp - rcv_blkctx_offset); STIX_ASSERT (STIX_CLASSOF(stix, rcv_blkctx) == stix->_block_context); #if 0 @@ -1709,7 +1682,7 @@ printf ("PRIM BlockContext value FAIL - NARGS MISMATCH\n"); * to pass array elements to the new block */ stix_oop_oop_t xarg; STIX_ASSERT (nargs == 1); - xarg = (stix_oop_oop_t)ACTIVE_STACK_GETTOP (stix); + xarg = (stix_oop_oop_t)STIX_STACK_GETTOP (stix); STIX_ASSERT (STIX_ISTYPEOF(stix,xarg,STIX_OBJ_TYPE_OOP)); STIX_ASSERT (STIX_OBJ_GET_SIZE(xarg) == num_first_arg_elems); for (i = 0; i < num_first_arg_elems; i++) @@ -1722,10 +1695,10 @@ printf ("PRIM BlockContext value FAIL - NARGS MISMATCH\n"); /* copy the arguments to the stack */ for (i = 0; i < nargs; i++) { - blkctx->slot[i] = ACTIVE_STACK_GET(stix, stix->sp - nargs + i + 1); + blkctx->slot[i] = STIX_STACK_GET(stix, stix->sp - nargs + i + 1); } } - ACTIVE_STACK_POPS (stix, nargs + 1); /* pop arguments and receiver */ + STIX_STACK_POPS (stix, nargs + 1); /* pop arguments and receiver */ STIX_ASSERT (blkctx->home != stix->_nil); blkctx->sp = STIX_SMOOI_TO_OOP(local_ntmprs - 1); @@ -1774,7 +1747,7 @@ static int prim_block_new_process (stix_t* stix, stix_ooi_t nargs) { stix_oop_t xarg; - xarg = ACTIVE_STACK_GETTOP(stix); + xarg = STIX_STACK_GETTOP(stix); if (!STIX_ISTYPEOF(stix,xarg,STIX_OBJ_TYPE_OOP)) { /* the only optional argument must be an OOP-indexable @@ -1785,7 +1758,7 @@ static int prim_block_new_process (stix_t* stix, stix_ooi_t nargs) num_first_arg_elems = STIX_OBJ_GET_SIZE(xarg); } - rcv_blkctx = (stix_oop_context_t)ACTIVE_STACK_GET(stix, stix->sp - nargs); + rcv_blkctx = (stix_oop_context_t)STIX_STACK_GET(stix, stix->sp - nargs); if (STIX_CLASSOF(stix, rcv_blkctx) != stix->_block_context) { /* the receiver must be a block context */ @@ -1811,7 +1784,7 @@ printf ("PRIMITVE VALUE RECEIVER IS NOT A BLOCK CONTEXT\n"); /* __block_value() has popped all arguments and the receiver. * PUSH the return value instead of changing the stack top */ - ACTIVE_STACK_PUSH (stix, (stix_oop_t)proc); + STIX_STACK_PUSH (stix, (stix_oop_t)proc); return 1; } @@ -1820,7 +1793,7 @@ static int prim_process_resume (stix_t* stix, stix_ooi_t nargs) stix_oop_t rcv; STIX_ASSERT (nargs == 0); - rcv = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp); if (STIX_CLASSOF(stix,rcv) != stix->_process) return 0; resume_process (stix, (stix_oop_process_t)rcv); /* TODO: error check */ @@ -1834,7 +1807,7 @@ static int prim_process_terminate (stix_t* stix, stix_ooi_t nargs) stix_oop_t rcv; STIX_ASSERT (nargs == 0); - rcv = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp); if (STIX_CLASSOF(stix,rcv) != stix->_process) return 0; terminate_process (stix, (stix_oop_process_t)rcv); @@ -1848,7 +1821,7 @@ static int prim_process_yield (stix_t* stix, stix_ooi_t nargs) stix_oop_t rcv; STIX_ASSERT (nargs == 0); - rcv = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp); if (STIX_CLASSOF(stix,rcv) != stix->_process) return 0; yield_process (stix, (stix_oop_process_t)rcv); @@ -1862,7 +1835,7 @@ static int prim_semaphore_signal (stix_t* stix, stix_ooi_t nargs) stix_oop_t rcv; STIX_ASSERT (nargs == 0); - rcv = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp); if (STIX_CLASSOF(stix,rcv) != stix->_semaphore) return 0; signal_semaphore (stix, (stix_oop_semaphore_t)rcv); @@ -1876,7 +1849,7 @@ static int prim_semaphore_wait (stix_t* stix, stix_ooi_t nargs) stix_oop_t rcv; STIX_ASSERT (nargs == 0); - rcv = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp); if (STIX_CLASSOF(stix,rcv) != stix->_semaphore) return 0; await_semaphore (stix, (stix_oop_semaphore_t)rcv); @@ -1891,8 +1864,8 @@ static int prim_processor_schedule (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); if (rcv != (stix_oop_t)stix->processor || STIX_CLASSOF(stix,arg) != stix->_process) { @@ -1913,14 +1886,14 @@ static int prim_processor_add_timed_semaphore (stix_t* stix, stix_ooi_t nargs) if (nargs == 3) { - nsec = ACTIVE_STACK_GET (stix, stix->sp); + nsec = STIX_STACK_GET (stix, stix->sp); if (!STIX_OOP_IS_SMOOI(nsec)) return 0; } else nsec = STIX_SMOOI_TO_OOP(0); - sec = ACTIVE_STACK_GET(stix, stix->sp - nargs + 2); - sem = (stix_oop_semaphore_t)ACTIVE_STACK_GET(stix, stix->sp - nargs + 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - nargs); + sec = STIX_STACK_GET(stix, stix->sp - nargs + 2); + sem = (stix_oop_semaphore_t)STIX_STACK_GET(stix, stix->sp - nargs + 1); + rcv = STIX_STACK_GET(stix, stix->sp - nargs); if (rcv != (stix_oop_t)stix->processor) return 0; if (STIX_CLASSOF(stix,sem) != stix->_semaphore) return 0; @@ -1934,8 +1907,8 @@ static int prim_processor_add_timed_semaphore (stix_t* stix, stix_ooi_t nargs) /* Is this more desired??? - ACTIVE_STACK_POPS (stix, nargs); - ACTIVE_STACK_SETTOP (stix, stix->_false); + STIX_STACK_POPS (stix, nargs); + STIX_STACK_SETTOP (stix, stix->_false); return 1; */ } @@ -1958,7 +1931,7 @@ static int prim_processor_add_timed_semaphore (stix_t* stix, stix_ooi_t nargs) if (add_to_sem_heap (stix, sem) <= -1) return -1; - ACTIVE_STACK_POPS (stix, nargs); + STIX_STACK_POPS (stix, nargs); return 1; } @@ -1971,8 +1944,8 @@ static int prim_processor_remove_semaphore (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - sem = (stix_oop_semaphore_t)ACTIVE_STACK_GET(stix, stix->sp); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); + sem = (stix_oop_semaphore_t)STIX_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); /* TODO: remove a semaphore from IO handler if it's registered... * remove a semaphore from XXXXXXXXXXXXXX */ @@ -1988,7 +1961,7 @@ static int prim_processor_remove_semaphore (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT(sem->heap_index == STIX_SMOOI_TO_OOP(-1)); } - ACTIVE_STACK_POPS (stix, nargs); + STIX_STACK_POPS (stix, nargs); return 1; } @@ -1998,18 +1971,18 @@ static int prim_processor_return_to (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 2); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 2); - ret = ACTIVE_STACK_GET(stix, stix->sp - 1); - ctx = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 2); + ret = STIX_STACK_GET(stix, stix->sp - 1); + ctx = STIX_STACK_GET(stix, stix->sp); if (rcv != (stix_oop_t)stix->processor) return 0; if (STIX_CLASSOF(stix, ctx) != stix->_block_context && STIX_CLASSOF(stix, ctx) != stix->_method_context) return 0; - ACTIVE_STACK_POPS (stix, nargs + 1); /* pop arguments and receiver */ + STIX_STACK_POPS (stix, nargs + 1); /* pop arguments and receiver */ - ACTIVE_STACK_PUSH (stix, ret); + STIX_STACK_PUSH (stix, ret); SWITCH_ACTIVE_CONTEXT (stix, (stix_oop_context_t)ctx); return 1; @@ -2021,15 +1994,15 @@ static int prim_processor_force_context (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - ctx = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + ctx = STIX_STACK_GET(stix, stix->sp); if (rcv != (stix_oop_t)stix->processor) return 0; if (STIX_CLASSOF(stix, ctx) != stix->_block_context && STIX_CLASSOF(stix, ctx) != stix->_method_context) return 0; - ACTIVE_STACK_POPS (stix, nargs + 1); /* pop arguments and receiver */ + STIX_STACK_POPS (stix, nargs + 1); /* pop arguments and receiver */ /* TODO: push nothing??? */ SWITCH_ACTIVE_CONTEXT (stix, (stix_oop_context_t)ctx); @@ -2043,14 +2016,14 @@ static int prim_integer_add (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); res = stix_addints (stix, rcv, arg); if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ - ACTIVE_STACK_POP (stix); - ACTIVE_STACK_SETTOP (stix, res); + STIX_STACK_POP (stix); + STIX_STACK_SETTOP (stix, res); return 1; } @@ -2060,14 +2033,14 @@ static int prim_integer_sub (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); res = stix_subints (stix, rcv, arg); if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ - ACTIVE_STACK_POP (stix); - ACTIVE_STACK_SETTOP (stix, res); + STIX_STACK_POP (stix); + STIX_STACK_SETTOP (stix, res); return 1; } @@ -2077,14 +2050,14 @@ static int prim_integer_mul (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); res = stix_mulints (stix, rcv, arg); if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ - ACTIVE_STACK_POP (stix); - ACTIVE_STACK_SETTOP (stix, res); + STIX_STACK_POP (stix); + STIX_STACK_SETTOP (stix, res); return 1; } @@ -2094,15 +2067,15 @@ static int prim_integer_quo (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); quo = stix_divints (stix, rcv, arg, 0, STIX_NULL); if (!quo) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ /* TODO: STIX_EDIVBY0 soft or hard failure? */ - ACTIVE_STACK_POP (stix); - ACTIVE_STACK_SETTOP (stix, quo); + STIX_STACK_POP (stix); + STIX_STACK_SETTOP (stix, quo); return 1; } @@ -2112,15 +2085,15 @@ static int prim_integer_rem (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); quo = stix_divints (stix, rcv, arg, 0, &rem); if (!quo) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ /* TODO: STIX_EDIVBY0 soft or hard failure? */ - ACTIVE_STACK_POP (stix); - ACTIVE_STACK_SETTOP (stix, rem); + STIX_STACK_POP (stix); + STIX_STACK_SETTOP (stix, rem); return 1; } @@ -2130,15 +2103,15 @@ static int prim_integer_quo2 (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); quo = stix_divints (stix, rcv, arg, 1, STIX_NULL); if (!quo) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ /* TODO: STIX_EDIVBY0 soft or hard failure? */ - ACTIVE_STACK_POP (stix); - ACTIVE_STACK_SETTOP (stix, quo); + STIX_STACK_POP (stix); + STIX_STACK_SETTOP (stix, quo); return 1; } @@ -2148,15 +2121,15 @@ static int prim_integer_rem2 (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); quo = stix_divints (stix, rcv, arg, 1, &rem); if (!quo) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ /* TODO: STIX_EDIVBY0 soft or hard failure? */ - ACTIVE_STACK_POP (stix); - ACTIVE_STACK_SETTOP (stix, rem); + STIX_STACK_POP (stix); + STIX_STACK_SETTOP (stix, rem); return 1; } @@ -2166,12 +2139,12 @@ static int prim_integer_negated (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 0); - rcv = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp); res = stix_negateint (stix, rcv); if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ - ACTIVE_STACK_SETTOP (stix, res); + STIX_STACK_SETTOP (stix, res); return 1; } @@ -2181,14 +2154,14 @@ static int prim_integer_bitat (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); res = stix_bitatint (stix, rcv, arg); if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ - ACTIVE_STACK_POP (stix); - ACTIVE_STACK_SETTOP (stix, res); + STIX_STACK_POP (stix); + STIX_STACK_SETTOP (stix, res); return 1; } @@ -2198,14 +2171,14 @@ static int prim_integer_bitand (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); res = stix_bitandints (stix, rcv, arg); if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ - ACTIVE_STACK_POP (stix); - ACTIVE_STACK_SETTOP (stix, res); + STIX_STACK_POP (stix); + STIX_STACK_SETTOP (stix, res); return 1; } @@ -2215,14 +2188,14 @@ static int prim_integer_bitor (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); res = stix_bitorints (stix, rcv, arg); if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ - ACTIVE_STACK_POP (stix); - ACTIVE_STACK_SETTOP (stix, res); + STIX_STACK_POP (stix); + STIX_STACK_SETTOP (stix, res); return 1; } @@ -2232,14 +2205,14 @@ static int prim_integer_bitxor (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); res = stix_bitxorints (stix, rcv, arg); if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ - ACTIVE_STACK_POP (stix); - ACTIVE_STACK_SETTOP (stix, res); + STIX_STACK_POP (stix); + STIX_STACK_SETTOP (stix, res); return 1; } @@ -2249,12 +2222,12 @@ static int prim_integer_bitinv (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 0); - rcv = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp); res = stix_bitinvint (stix, rcv); if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ - ACTIVE_STACK_SETTOP (stix, res); + STIX_STACK_SETTOP (stix, res); return 1; } @@ -2264,14 +2237,14 @@ static int prim_integer_bitshift (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); res = stix_bitshiftint (stix, rcv, arg); if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ - ACTIVE_STACK_POP (stix); - ACTIVE_STACK_SETTOP (stix, res); + STIX_STACK_POP (stix); + STIX_STACK_SETTOP (stix, res); return 1; } @@ -2281,14 +2254,14 @@ static int prim_integer_eq (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); res = stix_eqints (stix, rcv, arg); if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ - ACTIVE_STACK_POP (stix); - ACTIVE_STACK_SETTOP (stix, res); + STIX_STACK_POP (stix); + STIX_STACK_SETTOP (stix, res); return 1; } @@ -2298,14 +2271,14 @@ static int prim_integer_ne (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); res = stix_neints (stix, rcv, arg); if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ - ACTIVE_STACK_POP (stix); - ACTIVE_STACK_SETTOP (stix, res); + STIX_STACK_POP (stix); + STIX_STACK_SETTOP (stix, res); return 1; } @@ -2315,14 +2288,14 @@ static int prim_integer_lt (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); res = stix_ltints (stix, rcv, arg); if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ - ACTIVE_STACK_POP (stix); - ACTIVE_STACK_SETTOP (stix, res); + STIX_STACK_POP (stix); + STIX_STACK_SETTOP (stix, res); return 1; } @@ -2332,14 +2305,14 @@ static int prim_integer_gt (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); res = stix_gtints (stix, rcv, arg); if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ - ACTIVE_STACK_POP (stix); - ACTIVE_STACK_SETTOP (stix, res); + STIX_STACK_POP (stix); + STIX_STACK_SETTOP (stix, res); return 1; } @@ -2349,14 +2322,14 @@ static int prim_integer_le (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); res = stix_leints (stix, rcv, arg); if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ - ACTIVE_STACK_POP (stix); - ACTIVE_STACK_SETTOP (stix, res); + STIX_STACK_POP (stix); + STIX_STACK_SETTOP (stix, res); return 1; } @@ -2366,14 +2339,14 @@ static int prim_integer_ge (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); res = stix_geints (stix, rcv, arg); if (!res) return (stix->errnum == STIX_EINVAL? 0: -1); /* soft or hard failure */ - ACTIVE_STACK_POP (stix); - ACTIVE_STACK_SETTOP (stix, res); + STIX_STACK_POP (stix); + STIX_STACK_SETTOP (stix, res); return 1; } @@ -2384,8 +2357,8 @@ static int prim_integer_inttostr (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); if (!STIX_OOP_IS_SMOOI(arg)) return 0; /* soft failure */ radix = STIX_OOP_TO_SMOOI(arg); @@ -2394,7 +2367,7 @@ static int prim_integer_inttostr (stix_t* stix, stix_ooi_t nargs) str = stix_inttostr (stix, rcv, radix); if (!str) return (stix->errnum == STIX_EINVAL? 0: -1); - ACTIVE_STACK_SETTOP (stix, str); + STIX_STACK_SETTOP (stix, str); return 1; } @@ -2405,8 +2378,8 @@ static int prim_ffi_open (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); if (!STIX_ISTYPEOF(stix, arg, STIX_OBJ_TYPE_CHAR)) { @@ -2429,9 +2402,9 @@ static int prim_ffi_open (stix_t* stix, stix_ooi_t nargs) return 0; } - ACTIVE_STACK_POP (stix); + STIX_STACK_POP (stix); /* TODO: how to hold an address? as an integer???? or a byte array? fix this not to loose accuracy*/ - ACTIVE_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(handle)); + STIX_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(handle)); return 1; } @@ -2445,8 +2418,8 @@ static int prim_ffi_close (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 1); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 1); - arg = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 1); + arg = STIX_STACK_GET(stix, stix->sp); if (!STIX_OOP_IS_SMOOI(arg)) { @@ -2454,7 +2427,7 @@ static int prim_ffi_close (stix_t* stix, stix_ooi_t nargs) return 0; } - ACTIVE_STACK_POP (stix); + STIX_STACK_POP (stix); handle = (void*)STIX_OOP_TO_SMOOI(arg); /* TODO: how to store void* ???. fix this not to loose accuracy */ if (stix->vmprim.mod_close) stix->vmprim.mod_close (stix, handle); @@ -2468,10 +2441,10 @@ static int prim_ffi_call (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 3); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 3); - fun = ACTIVE_STACK_GET(stix, stix->sp - 2); - sig = ACTIVE_STACK_GET(stix, stix->sp - 1); - args = ACTIVE_STACK_GET(stix, stix->sp); + 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); if (!STIX_OOP_IS_SMOOI(fun)) /* TODO: how to store pointer */ { @@ -2570,7 +2543,7 @@ printf ("CALL MODE 222 ERROR %d %d\n", dcGetError (dc), DC_ERROR_UNSUPPORTED_MOD } - ACTIVE_STACK_POPS (stix, nargs); + STIX_STACK_POPS (stix, nargs); switch (((stix_oop_char_t)sig)->slot[0]) { @@ -2579,7 +2552,7 @@ printf ("CALL MODE 222 ERROR %d %d\n", dcGetError (dc), DC_ERROR_UNSUPPORTED_MOD case 'c': { char r = dcCallChar (dc, f); - ACTIVE_STACK_SETTOP (stix, STIX_CHAR_TO_OOP(r)); + STIX_STACK_SETTOP (stix, STIX_CHAR_TO_OOP(r)); break; } @@ -2588,21 +2561,21 @@ printf ("CALL MODE 222 ERROR %d %d\n", dcGetError (dc), DC_ERROR_UNSUPPORTED_MOD int r = dcCallInt (dc, f); printf ("CALLED... %d\n", r); printf ("CALL ERROR %d %d\n", dcGetError (dc), DC_ERROR_UNSUPPORTED_MODE); - ACTIVE_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(r)); + STIX_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(r)); break; } case 'l': { long r = dcCallLong (dc, f); - ACTIVE_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(r)); + STIX_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(r)); break; } case 'L': { long long r = dcCallLongLong (dc, f); - ACTIVE_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(r)); + STIX_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(r)); break; } @@ -2623,7 +2596,7 @@ printf ("CALL ERROR %d %d\n", dcGetError (dc), DC_ERROR_UNSUPPORTED_MODE); return -1; /* TODO: proper error h andling */ } - ACTIVE_STACK_SETTOP (stix, s); + STIX_STACK_SETTOP (stix, s); break; } @@ -2648,9 +2621,9 @@ static int prim_ffi_getsym (stix_t* stix, stix_ooi_t nargs) STIX_ASSERT (nargs == 2); - rcv = ACTIVE_STACK_GET(stix, stix->sp - 2); - fun = ACTIVE_STACK_GET(stix, stix->sp - 1); - hnd = ACTIVE_STACK_GET(stix, stix->sp); + rcv = STIX_STACK_GET(stix, stix->sp - 2); + fun = STIX_STACK_GET(stix, stix->sp - 1); + hnd = STIX_STACK_GET(stix, stix->sp); if (!STIX_OOP_IS_SMOOI(hnd)) /* TODO: how to store pointer */ { @@ -2675,9 +2648,9 @@ printf ("wrong function name...\n"); return 0; } - ACTIVE_STACK_POPS (stix, 2); + STIX_STACK_POPS (stix, 2); /* TODO: how to hold an address? as an integer???? or a byte array? */ - ACTIVE_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(sym)); + STIX_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(sym)); return 1; } @@ -2931,7 +2904,7 @@ static int send_message (stix_t* stix, stix_oop_char_t selector, int to_super, s STIX_ASSERT (STIX_OBJ_GET_FLAGS_TYPE(selector) == STIX_OBJ_TYPE_CHAR); STIX_ASSERT (STIX_CLASSOF(stix, selector) == stix->_symbol); - receiver = ACTIVE_STACK_GET(stix, stix->sp - nargs); + receiver = STIX_STACK_GET(stix, stix->sp - nargs); #if defined(STIX_DEBUG_EXEC_001) printf (" RECEIVER = "); @@ -2944,7 +2917,11 @@ printf ("\n"); method = find_method (stix, receiver, &mthname, to_super); if (!method) { - static stix_ooch_t fbm[] = { 'd', 'o', 'e', 's', 'N', 'o', 't', 'U', 'n', 'd', 'e', 'r', 's', 't', 'a', 'n', 'd', ':' }; + static stix_ooch_t fbm[] = { + 'd', 'o', 'e', 's', + 'N', 'o', 't', + 'U', 'n', 'd', 'e', 'r', 's', 't', 'a', 'n', 'd', ':' + }; mthname.ptr = fbm; mthname.len = 18; @@ -2954,7 +2931,7 @@ printf ("\n"); /* TODO: improve this hard error handling */ stix_oop_t c; -/* TODO: remove this print out.... or have it gracefully returned to the caller side */ +/* TODO: remove this print-out.... or have it gracefully returned to the caller side */ c = STIX_CLASSOF(stix,receiver); printf ("HARD FAILURE ERROR [IMAGE PROBLEM] - receiver ["); print_object (stix, receiver); @@ -2973,9 +2950,9 @@ printf ("\n"); * has been called. */ /* TODO: if i manipulate the stack this way here, the stack track for the last call is kind of lost. * how can i preserve it gracefully? */ - ACTIVE_STACK_POPS (stix, nargs); + STIX_STACK_POPS (stix, nargs); nargs = 1; - ACTIVE_STACK_PUSH (stix, (stix_oop_t)selector); + STIX_STACK_PUSH (stix, (stix_oop_t)selector); } } @@ -2987,49 +2964,49 @@ printf ("\n"); { case STIX_METHOD_PREAMBLE_RETURN_RECEIVER: DBGOUT_EXEC_0 ("METHOD_PREAMBLE_RETURN_RECEIVER"); - ACTIVE_STACK_POPS (stix, nargs); /* pop arguments only*/ + STIX_STACK_POPS (stix, nargs); /* pop arguments only*/ break; case STIX_METHOD_PREAMBLE_RETURN_NIL: DBGOUT_EXEC_0 ("METHOD_PREAMBLE_RETURN_NIL"); - ACTIVE_STACK_POPS (stix, nargs); - ACTIVE_STACK_SETTOP (stix, stix->_nil); + STIX_STACK_POPS (stix, nargs); + STIX_STACK_SETTOP (stix, stix->_nil); break; case STIX_METHOD_PREAMBLE_RETURN_TRUE: DBGOUT_EXEC_0 ("METHOD_PREAMBLE_RETURN_TRUE"); - ACTIVE_STACK_POPS (stix, nargs); - ACTIVE_STACK_SETTOP (stix, stix->_true); + STIX_STACK_POPS (stix, nargs); + STIX_STACK_SETTOP (stix, stix->_true); break; case STIX_METHOD_PREAMBLE_RETURN_FALSE: DBGOUT_EXEC_0 ("METHOD_PREAMBLE_RETURN_FALSE"); - ACTIVE_STACK_POPS (stix, nargs); - ACTIVE_STACK_SETTOP (stix, stix->_false); + STIX_STACK_POPS (stix, nargs); + STIX_STACK_SETTOP (stix, stix->_false); break; case STIX_METHOD_PREAMBLE_RETURN_INDEX: DBGOUT_EXEC_1 ("METHOD_PREAMBLE_RETURN_INDEX %d", (int)STIX_METHOD_GET_PREAMBLE_INDEX(preamble)); - ACTIVE_STACK_POPS (stix, nargs); - ACTIVE_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(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))); break; case STIX_METHOD_PREAMBLE_RETURN_NEGINDEX: DBGOUT_EXEC_1 ("METHOD_PREAMBLE_RETURN_NEGINDEX %d", (int)STIX_METHOD_GET_PREAMBLE_INDEX(preamble)); - ACTIVE_STACK_POPS (stix, nargs); - ACTIVE_STACK_SETTOP (stix, STIX_SMOOI_TO_OOP(-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))); break; case STIX_METHOD_PREAMBLE_RETURN_INSTVAR: { stix_oop_oop_t rcv; - ACTIVE_STACK_POPS (stix, nargs); /* pop arguments only */ + STIX_STACK_POPS (stix, nargs); /* pop arguments only */ DBGOUT_EXEC_1 ("METHOD_PREAMBLE_RETURN_INSTVAR %d", (int)STIX_METHOD_GET_PREAMBLE_INDEX(preamble)); /* replace the receiver by an instance variable of the receiver */ - rcv = (stix_oop_oop_t)ACTIVE_STACK_GETTOP(stix); + rcv = (stix_oop_oop_t)STIX_STACK_GETTOP(stix); STIX_ASSERT (STIX_OBJ_GET_FLAGS_TYPE(rcv) == STIX_OBJ_TYPE_OOP); STIX_ASSERT (STIX_OBJ_GET_SIZE(rcv) > STIX_METHOD_GET_PREAMBLE_INDEX(preamble)); @@ -3049,7 +3026,7 @@ printf ("\n"); } /* this accesses the instance variable of the receiver */ - ACTIVE_STACK_SET (stix, stix->sp, rcv->slot[STIX_METHOD_GET_PREAMBLE_INDEX(preamble)]); + STIX_STACK_SET (stix, stix->sp, rcv->slot[STIX_METHOD_GET_PREAMBLE_INDEX(preamble)]); break; } @@ -3276,7 +3253,7 @@ printf ("BCODE = %x\n", bcode); push_instvar: DBGOUT_EXEC_1 ("PUSH_INSTVAR %d", (int)b1); STIX_ASSERT (STIX_OBJ_GET_FLAGS_TYPE(stix->active_context->origin->receiver_or_source) == STIX_OBJ_TYPE_OOP); - ACTIVE_STACK_PUSH (stix, ((stix_oop_oop_t)stix->active_context->origin->receiver_or_source)->slot[b1]); + STIX_STACK_PUSH (stix, ((stix_oop_oop_t)stix->active_context->origin->receiver_or_source)->slot[b1]); break; /* ------------------------------------------------- */ @@ -3296,7 +3273,7 @@ printf ("BCODE = %x\n", bcode); store_instvar: DBGOUT_EXEC_1 ("STORE_INTO_INSTVAR %d", (int)b1); STIX_ASSERT (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] = ACTIVE_STACK_GETTOP(stix); + ((stix_oop_oop_t)stix->active_context->origin->receiver_or_source)->slot[b1] = STIX_STACK_GETTOP(stix); break; /* ------------------------------------------------- */ @@ -3315,8 +3292,8 @@ printf ("BCODE = %x\n", bcode); pop_into_instvar: DBGOUT_EXEC_1 ("POP_INTO_INSTVAR %d", (int)b1); STIX_ASSERT (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] = ACTIVE_STACK_GETTOP(stix); - ACTIVE_STACK_POP (stix); + ((stix_oop_oop_t)stix->active_context->origin->receiver_or_source)->slot[b1] = STIX_STACK_GETTOP(stix); + STIX_STACK_POP (stix); break; /* ------------------------------------------------- */ @@ -3413,18 +3390,18 @@ printf ("BCODE = %x\n", bcode); { /* push - bit 4 on */ DBGOUT_EXEC_1 ("PUSH_TEMPVAR %d", (int)b1); - ACTIVE_STACK_PUSH (stix, ctx->slot[bx]); + STIX_STACK_PUSH (stix, ctx->slot[bx]); } else { /* store or pop - bit 5 off */ - ctx->slot[bx] = ACTIVE_STACK_GETTOP(stix); + ctx->slot[bx] = STIX_STACK_GETTOP(stix); if ((bcode >> 3) & 1) { /* pop - bit 3 on */ DBGOUT_EXEC_1 ("POP_INTO_TEMPVAR %d", (int)b1); - ACTIVE_STACK_POP (stix); + STIX_STACK_POP (stix); } else { @@ -3458,7 +3435,7 @@ printf ("BCODE = %x\n", bcode); print_object (stix, stix->active_method->slot[b1]); printf ("\n"); */ - ACTIVE_STACK_PUSH (stix, stix->active_method->slot[b1]); + STIX_STACK_PUSH (stix, stix->active_method->slot[b1]); break; /* ------------------------------------------------- */ @@ -3491,13 +3468,13 @@ printf ("BCODE = %x\n", bcode); if ((bcode >> 3) & 1) { /* store or pop */ - ass->value = ACTIVE_STACK_GETTOP(stix); + ass->value = STIX_STACK_GETTOP(stix); if ((bcode >> 2) & 1) { /* pop */ DBGOUT_EXEC_1("POP_INTO_OBJECT %d", (int)b1); - ACTIVE_STACK_POP (stix); + STIX_STACK_POP (stix); } else { @@ -3508,7 +3485,7 @@ printf ("BCODE = %x\n", bcode); { /* push */ DBGOUT_EXEC_1("PUSH_OBJECT %d", (int)b1); - ACTIVE_STACK_PUSH (stix, ass->value); + STIX_STACK_PUSH (stix, ass->value); } break; } @@ -3562,7 +3539,6 @@ return -1; DBGOUT_EXEC_1 ("JUMP2_FORWARD %d", (int)b1); stix->ip += MAX_CODE_JUMP + b1; break; - break; case BCODE_JUMP2_BACKWARD: FETCH_PARAM_CODE_TO (stix, b1); @@ -3609,12 +3585,12 @@ return -1; if ((bcode >> 3) & 1) { /* store or pop */ - ctx->slot[b2] = ACTIVE_STACK_GETTOP(stix); + ctx->slot[b2] = STIX_STACK_GETTOP(stix); if ((bcode >> 2) & 1) { /* pop */ - ACTIVE_STACK_POP (stix); + STIX_STACK_POP (stix); DBGOUT_EXEC_2 ("POP_INTO_CTXTEMPVAR %d %d", (int)b1, (int)b2); } else @@ -3625,7 +3601,7 @@ return -1; else { /* push */ - ACTIVE_STACK_PUSH (stix, ctx->slot[b2]); + STIX_STACK_PUSH (stix, ctx->slot[b2]); DBGOUT_EXEC_2 ("PUSH_CTXTEMPVAR %d %d", (int)b1, (int)b2); } /* @@ -3673,12 +3649,12 @@ printf ("\n"); { /* store or pop */ - t->slot[b1] = ACTIVE_STACK_GETTOP(stix); + t->slot[b1] = STIX_STACK_GETTOP(stix); if ((bcode >> 2) & 1) { /* pop */ - ACTIVE_STACK_POP (stix); + STIX_STACK_POP (stix); DBGOUT_EXEC_2 ("POP_INTO_OBJVAR %d %d", (int)b1, (int)b2); } else @@ -3690,7 +3666,7 @@ printf ("\n"); { /* push */ DBGOUT_EXEC_2 ("PUSH_OBJVAR %d %d", (int)b1, (int)b2); - ACTIVE_STACK_PUSH (stix, t->slot[b1]); + STIX_STACK_PUSH (stix, t->slot[b1]); } /* print_object (stix, t->slot[b1]); @@ -3739,59 +3715,59 @@ fflush (stdout); case BCODE_PUSH_RECEIVER: DBGOUT_EXEC_0 ("PUSH_RECEIVER"); - ACTIVE_STACK_PUSH (stix, stix->active_context->origin->receiver_or_source); + STIX_STACK_PUSH (stix, stix->active_context->origin->receiver_or_source); break; case BCODE_PUSH_NIL: DBGOUT_EXEC_0 ("PUSH_NIL"); - ACTIVE_STACK_PUSH (stix, stix->_nil); + STIX_STACK_PUSH (stix, stix->_nil); break; case BCODE_PUSH_TRUE: DBGOUT_EXEC_0 ("PUSH_TRUE"); - ACTIVE_STACK_PUSH (stix, stix->_true); + STIX_STACK_PUSH (stix, stix->_true); break; case BCODE_PUSH_FALSE: DBGOUT_EXEC_0 ("PUSH_FALSE"); - ACTIVE_STACK_PUSH (stix, stix->_false); + STIX_STACK_PUSH (stix, stix->_false); break; case BCODE_PUSH_CONTEXT: DBGOUT_EXEC_0 ("PUSH_CONTEXT"); - ACTIVE_STACK_PUSH (stix, (stix_oop_t)stix->active_context); + STIX_STACK_PUSH (stix, (stix_oop_t)stix->active_context); break; case BCODE_PUSH_NEGONE: DBGOUT_EXEC_0 ("PUSH_NEGONE"); - ACTIVE_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(-1)); + STIX_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(-1)); break; case BCODE_PUSH_ZERO: DBGOUT_EXEC_0 ("PUSH_ZERO"); - ACTIVE_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(0)); + STIX_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(0)); break; case BCODE_PUSH_ONE: DBGOUT_EXEC_0 ("PUSH_ONE"); - ACTIVE_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(1)); + STIX_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(1)); break; case BCODE_PUSH_TWO: DBGOUT_EXEC_0 ("PUSH_TWO"); - ACTIVE_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(2)); + STIX_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(2)); break; case BCODE_PUSH_INTLIT: FETCH_PARAM_CODE_TO (stix, b1); DBGOUT_EXEC_1 ("PUSH_INTLIT %d", (int)b1); - ACTIVE_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(b1)); + STIX_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(b1)); break; case BCODE_PUSH_NEGINTLIT: FETCH_PARAM_CODE_TO (stix, b1); DBGOUT_EXEC_1 ("PUSH_NEGINTLIT %d", (int)-b1); - ACTIVE_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(-b1)); + STIX_STACK_PUSH (stix, STIX_SMOOI_TO_OOP(-b1)); break; /* -------------------------------------------------------- */ @@ -3800,22 +3776,22 @@ fflush (stdout); { stix_oop_t t; DBGOUT_EXEC_0 ("DUP_STACKTOP"); - STIX_ASSERT (!ACTIVE_STACK_ISEMPTY(stix)); - t = ACTIVE_STACK_GETTOP(stix); - ACTIVE_STACK_PUSH (stix, t); + STIX_ASSERT (!STIX_STACK_ISEMPTY(stix)); + t = STIX_STACK_GETTOP(stix); + STIX_STACK_PUSH (stix, t); break; } case BCODE_POP_STACKTOP: DBGOUT_EXEC_0 ("POP_STACKTOP"); - STIX_ASSERT (!ACTIVE_STACK_ISEMPTY(stix)); - ACTIVE_STACK_POP (stix); + STIX_ASSERT (!STIX_STACK_ISEMPTY(stix)); + STIX_STACK_POP (stix); break; case BCODE_RETURN_STACKTOP: DBGOUT_EXEC_0 ("RETURN_STACKTOP"); - return_value = ACTIVE_STACK_GETTOP(stix); - ACTIVE_STACK_POP (stix); + return_value = STIX_STACK_GETTOP(stix); + STIX_STACK_POP (stix); goto handle_return; case BCODE_RETURN_RECEIVER: @@ -3955,7 +3931,7 @@ printf (">>>>>>>>>>>>>>>> METHOD RETURN FROM WITHIN A BLOCK. NON-LOCAL RETURN.. SWITCH_ACTIVE_CONTEXT (stix, stix->active_context->origin->sender); /* push the return value to the stack of the new active context */ - ACTIVE_STACK_PUSH (stix, return_value); + STIX_STACK_PUSH (stix, return_value); if (stix->active_context == stix->initial_context) { @@ -4020,11 +3996,11 @@ printf ("<>\n"); SWITCH_ACTIVE_CONTEXT (stix, (stix_oop_context_t)stix->active_context->sender); #else /* NOTE: GC must not performed between here and */ - return_value = ACTIVE_STACK_GETTOP(stix); - ACTIVE_STACK_POP (stix); /* pop off the return value */ + return_value = STIX_STACK_GETTOP(stix); + STIX_STACK_POP (stix); /* pop off the return value */ SWITCH_ACTIVE_CONTEXT (stix, (stix_oop_context_t)stix->active_context->sender); - ACTIVE_STACK_PUSH (stix, return_value); /* push it to the sender */ + STIX_STACK_PUSH (stix, return_value); /* push it to the sender */ /* NOTE: here. if so, return_value will point to a garbage. */ #endif } @@ -4075,7 +4051,7 @@ printf ("<>\n"); blkctx->origin = stix->active_context->origin; /* push the new block context to the stack of the active context */ - ACTIVE_STACK_PUSH (stix, (stix_oop_t)blkctx); + STIX_STACK_PUSH (stix, (stix_oop_t)blkctx); break; } @@ -4090,13 +4066,13 @@ printf ("<>\n"); /* it emulates thisContext blockCopy: nargs ofTmprCount: ntmprs */ STIX_ASSERT (stix->sp >= 2); - STIX_ASSERT (STIX_CLASSOF(stix, ACTIVE_STACK_GETTOP(stix)) == stix->_small_integer); - ntmprs = STIX_OOP_TO_SMOOI(ACTIVE_STACK_GETTOP(stix)); - ACTIVE_STACK_POP (stix); + STIX_ASSERT (STIX_CLASSOF(stix, STIX_STACK_GETTOP(stix)) == stix->_small_integer); + ntmprs = STIX_OOP_TO_SMOOI(STIX_STACK_GETTOP(stix)); + STIX_STACK_POP (stix); - STIX_ASSERT (STIX_CLASSOF(stix, ACTIVE_STACK_GETTOP(stix)) == stix->_small_integer); - nargs = STIX_OOP_TO_SMOOI(ACTIVE_STACK_GETTOP(stix)); - ACTIVE_STACK_POP (stix); + STIX_ASSERT (STIX_CLASSOF(stix, STIX_STACK_GETTOP(stix)) == stix->_small_integer); + nargs = STIX_OOP_TO_SMOOI(STIX_STACK_GETTOP(stix)); + STIX_STACK_POP (stix); STIX_ASSERT (nargs >= 0); STIX_ASSERT (ntmprs >= nargs); @@ -4112,7 +4088,7 @@ printf ("<>\n"); /* get the receiver to the block copy message after block context instantiation * not to get affected by potential GC */ - rctx = (stix_oop_context_t)ACTIVE_STACK_GETTOP(stix); + rctx = (stix_oop_context_t)STIX_STACK_GETTOP(stix); STIX_ASSERT (rctx == stix->active_context); /* [NOTE] @@ -4170,7 +4146,7 @@ printf ("<>\n"); blkctx->origin = rctx->origin; #endif - ACTIVE_STACK_SETTOP (stix, (stix_oop_t)blkctx); + STIX_STACK_SETTOP (stix, (stix_oop_t)blkctx); break; } diff --git a/stix/lib/main.c b/stix/lib/main.c index 6e3df63..10390a5 100644 --- a/stix/lib/main.c +++ b/stix/lib/main.c @@ -98,6 +98,8 @@ struct xtn_t stix_oow_t bchar_len; }; +/* ========================================================================= */ + static void* sys_alloc (stix_mmgr_t* mmgr, stix_oow_t size) { return malloc (size); @@ -121,8 +123,9 @@ static stix_mmgr_t sys_mmgr = STIX_NULL }; +/* ========================================================================= */ -static STIX_INLINE stix_ooi_t open_input (stix_t* stix, stix_io_arg_t* arg) +static STIX_INLINE stix_ooi_t open_input (stix_t* stix, stix_ioarg_t* arg) { if (arg->includer) { @@ -165,7 +168,7 @@ static STIX_INLINE stix_ooi_t open_input (stix_t* stix, stix_io_arg_t* arg) return 0; } -static STIX_INLINE stix_ooi_t read_input (stix_t* stix, stix_io_arg_t* arg) +static STIX_INLINE stix_ooi_t read_input (stix_t* stix, stix_ioarg_t* arg) { xtn_t* xtn = stix_getxtn(stix); stix_oow_t n, bcslen, ucslen, remlen; @@ -198,14 +201,14 @@ static STIX_INLINE stix_ooi_t read_input (stix_t* stix, stix_io_arg_t* arg) return ucslen; } -static STIX_INLINE stix_ooi_t close_input (stix_t* stix, stix_io_arg_t* arg) +static STIX_INLINE stix_ooi_t close_input (stix_t* stix, stix_ioarg_t* arg) { STIX_ASSERT (arg->handle != STIX_NULL); fclose ((FILE*)arg->handle); return 0; } -static stix_ooi_t input_handler (stix_t* stix, stix_io_cmd_t cmd, stix_io_arg_t* arg) +static stix_ooi_t input_handler (stix_t* stix, stix_iocmd_t cmd, stix_ioarg_t* arg) { switch (cmd) { @@ -223,6 +226,7 @@ static stix_ooi_t input_handler (stix_t* stix, stix_io_cmd_t cmd, stix_io_arg_t* return -1; } } +/* ========================================================================= */ static void* mod_open (stix_t* stix, const stix_ooch_t* name) { @@ -324,6 +328,49 @@ printf ("MOD_GETSYM [%s]\n", &buf[0]); #endif } +/* ========================================================================= */ + +static void log_write (stix_t* stix, int mask, const stix_ooch_t* msg, stix_oow_t len) +{ +#if defined(_WIN32) +# error NOT IMPLEMENTED + +#else + stix_bch_t buf[10]; + stix_oow_t ucslen, bcslen, msgidx; + int n; + + msgidx = 0; + + while (1) + { + ucslen = len; + bcslen = STIX_COUNTOF(buf) - len; + + n = stix_ucstoutf8 (&msg[msgidx], &ucslen, buf, &bcslen); + if (n == 0) + { + write (1, buf, bcslen); /* TODO: write all */ + break; + } + else if (n == -2) + { + STIX_ASSERT (ucslen > 0); /* if this fails, the buffer size must be increased */ + write (1, buf, bcslen); /* TODO: write all */ + msgidx += ucslen; + len -= ucslen; + } + else if (n <= -1) + { + /* conversion error */ + break; + } + } +#endif +} + +/* ========================================================================= */ + static char* syntax_error_msg[] = { "no error", @@ -380,12 +427,17 @@ static char* syntax_error_msg[] = "literal expected" }; +/* ========================================================================= */ + stix_ooch_t str_my_object[] = { 'M', 'y', 'O', 'b','j','e','c','t' }; stix_ooch_t str_main[] = { 'm', 'a', 'i', 'n' }; stix_t* g_stix = STIX_NULL; +/* ========================================================================= */ + + #if defined(__MSDOS__) && defined(_INTELC32_) static void (*prev_timer_intr_handler) (void); @@ -491,6 +543,8 @@ static void cancel_tick (void) #endif } +/* ========================================================================= */ + int main (int argc, char* argv[]) { stix_t* stix; @@ -524,6 +578,8 @@ int main (int argc, char* argv[]) vmprim.mod_open = mod_open; vmprim.mod_close = mod_close; vmprim.mod_getsym = mod_getsym; + vmprim.log_write = log_write; + #if defined(USE_LTDL) lt_dlinit (); diff --git a/stix/lib/mod-snd.c b/stix/lib/mod-snd.c index e0d52c4..4e53a8d 100644 --- a/stix/lib/mod-snd.c +++ b/stix/lib/mod-snd.c @@ -29,36 +29,17 @@ #include /* ------------------------------------------------------------------------ */ - -/* TODO: don't use these macros... */ -#define ACTIVE_STACK_PUSH(stix,v) \ - do { \ - (stix)->sp = (stix)->sp + 1; \ - (stix)->active_context->slot[(stix)->sp] = v; \ - } while (0) - -#define ACTIVE_STACK_POP(stix) ((stix)->sp = (stix)->sp - 1) -#define ACTIVE_STACK_UNPOP(stix) ((stix)->sp = (stix)->sp + 1) -#define ACTIVE_STACK_POPS(stix,count) ((stix)->sp = (stix)->sp - (count)) - -#define ACTIVE_STACK_GET(stix,v_sp) ((stix)->active_context->slot[v_sp]) -#define ACTIVE_STACK_SET(stix,v_sp,v_obj) ((stix)->active_context->slot[v_sp] = v_obj) -#define ACTIVE_STACK_GETTOP(stix) ACTIVE_STACK_GET(stix, (stix)->sp) -#define ACTIVE_STACK_SETTOP(stix,v_obj) ACTIVE_STACK_SET(stix, (stix)->sp, v_obj) - - - static int prim_open (stix_t* stix, stix_ooi_t nargs) { printf ("<<<<<<<<<<>>>>>>>>>>>>>>>>>\n"); - ACTIVE_STACK_POPS (stix, nargs); + STIX_STACK_POPS (stix, nargs); return 1; } static int prim_close (stix_t* stix, stix_ooi_t nargs) { printf ("<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>\n"); - ACTIVE_STACK_POPS (stix, nargs); + STIX_STACK_POPS (stix, nargs); return 1; } diff --git a/stix/lib/mod-snd.h b/stix/lib/mod-snd.h index 246fb6f..6f06e4b 100644 --- a/stix/lib/mod-snd.h +++ b/stix/lib/mod-snd.h @@ -1,7 +1,7 @@ /* * $Id$ * - Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved. + Copyright (c) 2006-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 diff --git a/stix/lib/stix-cmn.h b/stix/lib/stix-cmn.h index bfb083c..3b0218b 100644 --- a/stix/lib/stix-cmn.h +++ b/stix/lib/stix-cmn.h @@ -301,7 +301,7 @@ typedef struct stix_ucs_t stix_ucs_t; struct stix_bcs_t { stix_bch_t* ptr; - stix_oow_t len; + stix_oow_t len; }; typedef struct stix_bcs_t stix_bcs_t; diff --git a/stix/lib/stix-prv.h b/stix/lib/stix-prv.h index 33df748..e0ca376 100644 --- a/stix/lib/stix-prv.h +++ b/stix/lib/stix-prv.h @@ -44,14 +44,6 @@ * PUSH_CONTEXT, PUSH_INTLIT, PUSH_INTLIT, SEND_BLOCK_COPY */ #define STIX_USE_MAKE_BLOCK -/* 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 - -/* define this to use the stack allocated inside process stack */ -#define STIX_USE_PROCSTK - /* this is for gc debugging */ /*#define STIX_DEBUG_PROCESSOR*/ /*#define STIX_DEBUG_GC_001*/ @@ -244,38 +236,38 @@ /* SOURCE CODE I/O FOR COMPILER */ /* ========================================================================= */ -enum stix_io_cmd_t +enum stix_iocmd_t { STIX_IO_OPEN, STIX_IO_CLOSE, STIX_IO_READ }; -typedef enum stix_io_cmd_t stix_io_cmd_t; +typedef enum stix_iocmd_t stix_iocmd_t; struct stix_ioloc_t { - unsigned long line; /**< line */ - unsigned long colm; /**< column */ + unsigned long line; /**< line */ + unsigned long colm; /**< column */ const stix_ooch_t* file; /**< file specified in #include */ }; typedef struct stix_ioloc_t stix_ioloc_t; struct stix_iolxc_t { - stix_ooci_t c; /**< character */ + stix_ooci_t c; /**< character */ stix_ioloc_t l; /**< location */ }; typedef struct stix_iolxc_t stix_iolxc_t; /* -enum stix_io_arg_flag_t +enum stix_ioarg_flag_t { STIX_IO_INCLUDED = (1 << 0) }; -typedef enum stix_io_arg_flag_t stix_io_arg_flag_t; */ +typedef enum stix_ioarg_flag_t stix_ioarg_flag_t; */ -typedef struct stix_io_arg_t stix_io_arg_t; -struct stix_io_arg_t +typedef struct stix_ioarg_t stix_ioarg_t; +struct stix_ioarg_t { /** * [IN] I/O object name. @@ -285,7 +277,8 @@ struct stix_io_arg_t const stix_ooch_t* name; /** - * [OUT] I/O handle set by a handler. + * [OUT] I/O handle set by an open handler. + * [IN] I/O handle referenced in read and close handler. * The source stream handler can set this field when it opens a stream. * All subsequent operations on the stream see this field as set * during opening. @@ -301,7 +294,7 @@ struct stix_io_arg_t * [IN] points to the data of the includer. It is #STIX_NULL for the * main stream. */ - stix_io_arg_t* includer; + stix_ioarg_t* includer; /*-----------------------------------------------------------------*/ /*----------- from here down, internal use only -------------------*/ @@ -317,10 +310,10 @@ struct stix_io_arg_t /*-----------------------------------------------------------------*/ }; -typedef stix_ooi_t (*stix_io_impl_t) ( +typedef stix_ooi_t (*stix_ioimpl_t) ( stix_t* stix, - stix_io_cmd_t cmd, - stix_io_arg_t* arg + stix_iocmd_t cmd, + stix_ioarg_t* arg ); struct stix_iotok_t @@ -447,7 +440,7 @@ typedef struct stix_code_t stix_code_t; struct stix_compiler_t { /* input handler */ - stix_io_impl_t impl; + stix_ioimpl_t impl; /* information about the last meaningful character read. * this is a copy of curinp->lxc if no ungetting is performed. @@ -461,10 +454,10 @@ struct stix_compiler_t int nungots; /* static input data buffer */ - stix_io_arg_t arg; + stix_ioarg_t arg; /* pointer to the current input data. initially, it points to &arg */ - stix_io_arg_t* curinp; + stix_ioarg_t* curinp; /* the last token read */ stix_iotok_t tok; @@ -1080,6 +1073,35 @@ stix_oow_t stix_utf8touc ( stix_uch_t* uc ); +/** + * The stix_ucstoutf8() 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_ucstoutf8 (ucs, &ucslen, bcs, &bcslen); + * if (n <= -1) + * { + * // conversion error + * } + * \endcode + */ int stix_ucstoutf8 ( const stix_uch_t* ucs, stix_oow_t* ucslen, @@ -1261,7 +1283,7 @@ stix_oop_t stix_inttostr ( /* ========================================================================= */ STIX_EXPORT int stix_compile ( stix_t* stix, - stix_io_impl_t io + stix_ioimpl_t io ); STIX_EXPORT void stix_getsynerr ( diff --git a/stix/lib/stix.c b/stix/lib/stix.c index 13413f3..6ff7d28 100644 --- a/stix/lib/stix.c +++ b/stix/lib/stix.c @@ -252,7 +252,6 @@ int stix_getoption (stix_t* stix, stix_option_t id, void* value) return -1; } - stix_cb_t* stix_regcb (stix_t* stix, stix_cb_t* tmpl) { stix_cb_t* actual; diff --git a/stix/lib/stix.h b/stix/lib/stix.h index 52d2ae4..cfc046c 100644 --- a/stix/lib/stix.h +++ b/stix/lib/stix.h @@ -33,6 +33,13 @@ /* TODO: move this macro out to the build files.... */ #define STIX_INCLUDE_COMPILER +/* define this to use the stack allocated inside process stack */ +#define STIX_USE_PROCSTK + +/* 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 /* ========================================================================== */ /** @@ -454,6 +461,19 @@ struct stix_method_t 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 a 8-bit code and a 16-bit * index. * @@ -489,7 +509,7 @@ struct stix_method_t /* 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_PREAMBLE_INDEX_RANGE(num) ((num) >= STIX_METHOD_PREAMBLE_INDEX_MIN && (num) <= STIX_METHOD_PREAMBLE_INDEX_MAX) +#define STIX_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(num) ((num) >= STIX_METHOD_PREAMBLE_INDEX_MIN && (num) <= STIX_METHOD_PREAMBLE_INDEX_MAX) #define STIX_CONTEXT_NAMED_INSTVARS 8 typedef struct stix_context_t stix_context_t; @@ -637,15 +657,18 @@ typedef struct stix_t stix_t; * ========================================================================= */ #define STIX_MOD_NAME_LEN_MAX 120 -typedef void* (*stix_mod_open_t) (stix_t* stix, const stix_uch_t* name); +typedef void* (*stix_mod_open_t) (stix_t* stix, const stix_ooch_t* name); typedef void (*stix_mod_close_t) (stix_t* stix, void* handle); -typedef void* (*stix_mod_getsym_t) (stix_t* stix, void* handle, const stix_uch_t* name); +typedef void* (*stix_mod_getsym_t) (stix_t* stix, void* handle, const stix_ooch_t* name); + +typedef void (*stix_log_write_t) (stix_t* stix, int mask, const stix_ooch_t* msg, stix_oow_t len); struct stix_vmprim_t { stix_mod_open_t mod_open; stix_mod_close_t mod_close; stix_mod_getsym_t mod_getsym; + stix_log_write_t log_write; }; typedef struct stix_vmprim_t stix_vmprim_t; @@ -654,18 +677,18 @@ typedef struct stix_vmprim_t stix_vmprim_t; * IO MANIPULATION * ========================================================================= */ -/* TODO: MOVE stix_io_impl_t HERE */ +/* TODO: MOVE stix_ioimpl_t HERE */ /* ========================================================================= * CALLBACK MANIPULATION * ========================================================================= */ -typedef void (*stix_cb_impl_t) (stix_t* stix); +typedef void (*stix_cbimpl_t) (stix_t* stix); typedef struct stix_cb_t stix_cb_t; struct stix_cb_t { - stix_cb_impl_t gc; - stix_cb_impl_t fini; + stix_cbimpl_t gc; + stix_cbimpl_t fini; /* private below */ stix_cb_t* prev; @@ -821,6 +844,37 @@ struct stix_t #endif }; + + +#if defined(STIX_USE_PROCSTK) +/* 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) + +#else + #define STIX_STACK_PUSH(stix,v) \ + do { \ + (stix)->sp = (stix)->sp + 1; \ + (stix)->active_context->slot[(stix)->sp] = v; \ + } while (0) + + #define STIX_STACK_GET(stix,v_sp) ((stix)->active_context->slot[v_sp]) + #define STIX_STACK_SET(stix,v_sp,v_obj) ((stix)->active_context->slot[v_sp] = v_obj) +#endif + +#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) + #if defined(__cplusplus) extern "C" { #endif @@ -978,6 +1032,10 @@ STIX_EXPORT void stix_poptmps ( stix_oow_t count ); +STIX_EXPORT int stix_decode ( + stix_t* stix, + stix_oop_method_t mth +); /* Memory allocation/deallocation functions using stix's MMGR */