From a9c48b75e6b9b77e556b127b839b570c09cb412d Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Mon, 26 Dec 2016 18:44:47 +0000 Subject: [PATCH] introduced the Error class to represent an error code as an object. rewrote STIX_ASSERT() to call stix_logbfmt() via stix_assertfailed() --- stix/kernel/Apex.st | 8 +- stix/kernel/Stdio.st | 16 +- stix/kernel/Stix.st | 13 -- stix/kernel/test-014.st | 32 ++-- stix/lib/Makefile.am | 1 - stix/lib/Makefile.in | 15 +- stix/lib/bigint.c | 255 ++++++++++++++------------- stix/lib/comp.c | 116 ++++++------- stix/lib/decode.c | 4 +- stix/lib/dic.c | 42 ++--- stix/lib/exec.c | 370 ++++++++++++++++++++------------------- stix/lib/gc.c | 372 +++++++++++++++++++++++++++++++++++----- stix/lib/heap.c | 6 +- stix/lib/ignite.c | 310 --------------------------------- stix/lib/logfmt.c | 6 +- stix/lib/logfmtv.h | 14 +- stix/lib/main.c | 6 +- stix/lib/obj.c | 18 +- stix/lib/proc.c | 6 +- stix/lib/rbt.c | 59 +++---- stix/lib/stix-cmn.h | 5 + stix/lib/stix-prv.h | 11 +- stix/lib/stix-rbt.h | 22 +-- stix/lib/stix.c | 152 ++++++++-------- stix/lib/stix.h | 125 ++++++++------ stix/lib/sym.c | 14 +- stix/lib/utf8.c | 13 +- stix/lib/utl.c | 6 +- stix/mod/console.c | 1 - stix/mod/stdio.c | 12 +- 30 files changed, 1003 insertions(+), 1027 deletions(-) delete mode 100644 stix/lib/ignite.c diff --git a/stix/kernel/Apex.st b/stix/kernel/Apex.st index afd4ef3..c6af017 100644 --- a/stix/kernel/Apex.st +++ b/stix/kernel/Apex.st @@ -332,4 +332,10 @@ } } - +#class Error(Apex) +{ + #method isError + { + ^true + } +} diff --git a/stix/kernel/Stdio.st b/stix/kernel/Stdio.st index f4e5c37..e750634 100644 --- a/stix/kernel/Stdio.st +++ b/stix/kernel/Stdio.st @@ -1,5 +1,7 @@ #class(#byte) Stdio(Object) from 'stdio' { + #dcl(#class) in out err. + (* * The following methods are generated by the module. * #method(#class) _newInstSize { } @@ -9,15 +11,12 @@ #method(#class) new: size { - ##self prohibited - ##raise exception. prohibited... + ## ignore the specified size ^(super new: (self _newInstSize)) } #method(#class) new { - ##self prohibited - ##raise exception. prohibited... ^(super new: (self _newInstSize)) } @@ -30,17 +29,20 @@ (* --------------------- #method(#class) input { - ^(super new) open: 0 for: 'r' + self.in isNil ifTrue: [ self.in := ^(super new) open: 0 for: 'r' ]. + ^self.in. } #method(#class) output { - ^(super new) open: 1 for: 'w' + self.out isNil ifTrue: [ self.out := ^(super new) open: 1 for: 'w' ]. + ^self.out. } #method(#class) error { - ^(super new) open: 2 for: 'w' + self.err isNil ifTrue: [ self.err := ^(super new) open: 2 for: 'w' ]. + ^self.err. } ------------------------ *) diff --git a/stix/kernel/Stix.st b/stix/kernel/Stix.st index 247b7c0..5c7c3d9 100644 --- a/stix/kernel/Stix.st +++ b/stix/kernel/Stix.st @@ -4,19 +4,6 @@ ######################################################################################### -#class Error(Object) -{ - #method(#class) signal: aString - { - "accept an arbitary object instead of a string. - the object can be sent displayString for string conversion" - } - - #method isError - { - ^true - } -} #class Magnitude(Object) { diff --git a/stix/kernel/test-014.st b/stix/kernel/test-014.st index 40361aa..ec2036b 100644 --- a/stix/kernel/test-014.st +++ b/stix/kernel/test-014.st @@ -126,26 +126,23 @@ ##v1 := Stdio2 open: '/tmp/1.txt' for: 'w+'. v1 := Stdio2 new open: '/tmp/1.txt' for: 'w+'. - ## v1 puts: 'hello'. - v1 puts ('hello', 'world', 'good', C'\n', C'\t', 'under my umbrella.', C'\n'). - v1 close. + (v1 isError) + ifTrue: [ + System logNl: ('Error in opening a file....'). + ] + ifFalse: [ + ## v1 puts: 'hello'. + v1 puts ('hello', 'world', 'good', C'\n', C'\t', 'under my umbrella.', C'\n'). + v1 close. + + + (*v1 format(10, 20) isNil ifFalse: [ + 'Beautiful life' dump. + ].*) + ]. nil isNil ifTrue: [ 'NIL NIL NIL' dump. ]. (Apex new) notNil ifTrue: [ 'APEX NIL NIL NIL' dump. ]. -(* - v1 format(10 20 30) isNil -procecure call is treated as if it is a unary message... - - - v1 format(10 , 20 , 30) isNil ifTrue: [ - xxxx - ]. -*) - - v1 format(10, 20) isNil ifFalse: [ - 'Beautiful life' dump. - ]. - self varg_test (10, 20, 30, 40, 50) dump. self varg_test2 (10, 20, 30, 40, 50) dump. self varg_test3 (10, 20, 30, 40, 50) dump. @@ -153,7 +150,6 @@ procecure call is treated as if it is a unary message... thisContext vargCount dump. } - #method(#class) varg_test() { 0 to: (thisContext vargCount - 1) do: [:k | diff --git a/stix/lib/Makefile.am b/stix/lib/Makefile.am index 9a6489d..775836f 100644 --- a/stix/lib/Makefile.am +++ b/stix/lib/Makefile.am @@ -47,7 +47,6 @@ libstix_la_SOURCES = \ logfmt.c \ gc.c \ heap.c \ - ignite.c \ obj.c \ proc.c \ rbt.c \ diff --git a/stix/lib/Makefile.in b/stix/lib/Makefile.in index c92749d..c83aa18 100644 --- a/stix/lib/Makefile.in +++ b/stix/lib/Makefile.in @@ -137,9 +137,9 @@ libstix_la_DEPENDENCIES = $(am__DEPENDENCIES_2) 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-exec.lo libstix_la-logfmt.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-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) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) @@ -414,7 +414,6 @@ libstix_la_SOURCES = \ logfmt.c \ gc.c \ heap.c \ - ignite.c \ obj.c \ proc.c \ rbt.c \ @@ -586,7 +585,6 @@ distclean-compile: @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-ignite.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@ @@ -684,13 +682,6 @@ libstix_la-heap.lo: heap.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-heap.lo `test -f 'heap.c' || echo '$(srcdir)/'`heap.c -libstix_la-ignite.lo: ignite.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-ignite.lo -MD -MP -MF $(DEPDIR)/libstix_la-ignite.Tpo -c -o libstix_la-ignite.lo `test -f 'ignite.c' || echo '$(srcdir)/'`ignite.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_la-ignite.Tpo $(DEPDIR)/libstix_la-ignite.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='ignite.c' object='libstix_la-ignite.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-ignite.lo `test -f 'ignite.c' || echo '$(srcdir)/'`ignite.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 diff --git a/stix/lib/bigint.c b/stix/lib/bigint.c index 0682f99..de4a8a5 100644 --- a/stix/lib/bigint.c +++ b/stix/lib/bigint.c @@ -126,13 +126,13 @@ static STIX_INLINE int oow_mul_overflow (stix_oow_t a, stix_oow_t b, stix_oow_t* #endif #if (STIX_SIZEOF_OOI_T == STIX_SIZEOF_INT) && defined(STIX_HAVE_BUILTIN_SMUL_OVERFLOW) -# define smooi_mul_overflow(a,b,c) __builtin_smul_overflow(a,b,c) +# 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(a,b,c) __builtin_smull_overflow(a,b,c) +# 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(a,b,c) __builtin_smulll_overflow(a,b,c) +# define smooi_mul_overflow(stix,a,b,c) __builtin_smulll_overflow(a,b,c) #else -static STIX_INLINE int smooi_mul_overflow (stix_ooi_t a, stix_ooi_t b, stix_ooi_t* c) +static STIX_INLINE int smooi_mul_overflow (stix_t* stix, stix_ooi_t a, stix_ooi_t b, stix_ooi_t* c) { /* take note that this function is not supposed to handle * the whole stix_ooi_t range. it handles the smooi subrange */ @@ -140,8 +140,8 @@ static STIX_INLINE int smooi_mul_overflow (stix_ooi_t a, stix_ooi_t b, stix_ooi_ #if (STIX_SIZEOF_UINTMAX_T > STIX_SIZEOF_OOI_T) stix_intmax_t k; - STIX_ASSERT (STIX_IN_SMOOI_RANGE(a)); - STIX_ASSERT (STIX_IN_SMOOI_RANGE(b)); + STIX_ASSERT (stix, STIX_IN_SMOOI_RANGE(a)); + STIX_ASSERT (stix, STIX_IN_SMOOI_RANGE(b)); k = (stix_intmax_t)a * (stix_intmax_t)b; *c = (stix_ooi_t)k; @@ -151,8 +151,8 @@ static STIX_INLINE int smooi_mul_overflow (stix_ooi_t a, stix_ooi_t b, stix_ooi_ stix_ooi_t ua, ub; - STIX_ASSERT (STIX_IN_SMOOI_RANGE(a)); - STIX_ASSERT (STIX_IN_SMOOI_RANGE(b)); + STIX_ASSERT (stix, STIX_IN_SMOOI_RANGE(a)); + STIX_ASSERT (stix, STIX_IN_SMOOI_RANGE(b)); *c = a * b; @@ -220,7 +220,7 @@ static int is_normalized_integer (stix_t* stix, stix_oop_t oop) stix_oow_t sz; sz = STIX_OBJ_GET_SIZE(oop); - STIX_ASSERT (sz >= 1); + STIX_ASSERT (stix, sz >= 1); return ((stix_oop_liword_t)oop)->slot[sz - 1] == 0? 0: 1; } @@ -233,7 +233,7 @@ STIX_INLINE static int is_bigint (stix_t* stix, stix_oop_t x) { stix_oop_t c; - STIX_ASSERT (STIX_OOP_IS_POINTER(x)); + STIX_ASSERT (stix, STIX_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? */ @@ -254,12 +254,12 @@ STIX_INLINE int stix_isint (stix_t* stix, stix_oop_t x) static STIX_INLINE int bigint_to_oow (stix_t* stix, stix_oop_t num, stix_oow_t* w) { - STIX_ASSERT (STIX_OOP_IS_POINTER(num)); - STIX_ASSERT (STIX_OBJ_GET_CLASS(num) == stix->_large_positive_integer || + 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); #if (STIX_LIW_BITS == STIX_OOW_BITS) - STIX_ASSERT (STIX_OBJ_GET_SIZE(num) >= 1); + STIX_ASSERT (stix, STIX_OBJ_GET_SIZE(num) >= 1); if (STIX_OBJ_GET_SIZE(num) == 1) { *w = ((stix_oop_word_t)num)->slot[0]; @@ -272,7 +272,7 @@ static STIX_INLINE int bigint_to_oow (stix_t* stix, stix_oop_t num, stix_oow_t* * you must not call this function with an unnormalized * large integer. */ - STIX_ASSERT (STIX_OBJ_GET_SIZE(num) >= 2); + STIX_ASSERT (stix, STIX_OBJ_GET_SIZE(num) >= 2); if (STIX_OBJ_GET_SIZE(num) == 2) { *w = MAKE_WORD (((stix_oop_halfword_t)num)->slot[0], ((stix_oop_halfword_t)num)->slot[1]); @@ -310,7 +310,7 @@ static STIX_INLINE int integer_to_oow (stix_t* stix, stix_oop_t x, stix_oow_t* w } } - STIX_ASSERT (is_bigint(stix, x)); + STIX_ASSERT (stix, is_bigint(stix, x)); return bigint_to_oow (stix, x, w); } @@ -341,7 +341,7 @@ int stix_inttooow (stix_t* stix, stix_oop_t x, stix_oow_t* w) static STIX_INLINE stix_oop_t make_bigint_with_oow (stix_t* stix, stix_oow_t w) { #if (STIX_LIW_BITS == STIX_OOW_BITS) - STIX_ASSERT (STIX_SIZEOF(stix_oow_t) == STIX_SIZEOF(stix_liw_t)); + 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]; @@ -358,7 +358,7 @@ static STIX_INLINE stix_oop_t make_bigint_with_ooi (stix_t* stix, stix_ooi_t i) #if (STIX_LIW_BITS == STIX_OOW_BITS) stix_oow_t w; - STIX_ASSERT (STIX_SIZEOF(stix_oow_t) == STIX_SIZEOF(stix_liw_t)); + STIX_ASSERT (stix, STIX_SIZEOF(stix_oow_t) == STIX_SIZEOF(stix_liw_t)); if (i >= 0) { w = i; @@ -369,7 +369,7 @@ static STIX_INLINE stix_oop_t make_bigint_with_ooi (stix_t* stix, stix_ooi_t i) /* 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 (i > STIX_TYPE_MIN(stix_ooi_t)); + STIX_ASSERT (stix, i > STIX_TYPE_MIN(stix_ooi_t)); w = -i; return stix_instantiate (stix, stix->_large_negative_integer, &w, 1); } @@ -386,7 +386,7 @@ static STIX_INLINE stix_oop_t make_bigint_with_ooi (stix_t* stix, stix_ooi_t i) } else { - STIX_ASSERT (i > STIX_TYPE_MIN(stix_ooi_t)); + STIX_ASSERT (stix, i > STIX_TYPE_MIN(stix_ooi_t)); w = -i; hw[0] = w /*& STIX_LBMASK(stix_oow_t,STIX_LIW_BITS)*/; hw[1] = w >> STIX_LIW_BITS; @@ -403,8 +403,8 @@ static STIX_INLINE stix_oop_t make_bloated_bigint_with_ooi (stix_t* stix, stix_o stix_oow_t w; stix_oop_t z; - STIX_ASSERT (extra <= STIX_OBJ_SIZE_MAX - 1); - STIX_ASSERT (STIX_SIZEOF(stix_oow_t) == STIX_SIZEOF(stix_liw_t)); + STIX_ASSERT (stix, extra <= STIX_OBJ_SIZE_MAX - 1); + STIX_ASSERT (stix, STIX_SIZEOF(stix_oow_t) == STIX_SIZEOF(stix_liw_t)); if (i >= 0) { w = i; @@ -412,7 +412,7 @@ static STIX_INLINE stix_oop_t make_bloated_bigint_with_ooi (stix_t* stix, stix_o } else { - STIX_ASSERT (i > STIX_TYPE_MIN(stix_ooi_t)); + STIX_ASSERT (stix, i > STIX_TYPE_MIN(stix_ooi_t)); w = -i; z = stix_instantiate (stix, stix->_large_negative_integer, STIX_NULL, 1 + extra); } @@ -426,7 +426,7 @@ static STIX_INLINE stix_oop_t make_bloated_bigint_with_ooi (stix_t* stix, stix_o stix_oow_t w; stix_oop_t z; - STIX_ASSERT (extra <= STIX_OBJ_SIZE_MAX - 2); + STIX_ASSERT (stix, extra <= STIX_OBJ_SIZE_MAX - 2); if (i >= 0) { w = i; @@ -436,7 +436,7 @@ static STIX_INLINE stix_oop_t make_bloated_bigint_with_ooi (stix_t* stix, stix_o } else { - STIX_ASSERT (i > STIX_TYPE_MIN(stix_ooi_t)); + STIX_ASSERT (stix, i > STIX_TYPE_MIN(stix_ooi_t)); w = -i; hw[0] = w /*& STIX_LBMASK(stix_oow_t,STIX_LIW_BITS)*/; hw[1] = w >> STIX_LIW_BITS; @@ -460,7 +460,7 @@ static STIX_INLINE stix_oop_t make_bigint_with_intmax (stix_t* stix, stix_intmax /* this is not a generic function. it can't handle v * if it's STIX_TYPE_MIN(stix_intmax_t) */ - STIX_ASSERT (v > STIX_TYPE_MIN(stix_intmax_t)); + STIX_ASSERT (stix, v > STIX_TYPE_MIN(stix_intmax_t)); ui = (v >= 0)? v: -v; len = 0; @@ -476,7 +476,7 @@ static STIX_INLINE stix_oop_t make_bigint_with_intmax (stix_t* stix, stix_intmax stix_oop_t stix_oowtoint (stix_t* stix, stix_oow_t w) { - STIX_ASSERT (STIX_TYPE_IS_UNSIGNED(stix_oow_t)); + STIX_ASSERT (stix, STIX_TYPE_IS_UNSIGNED(stix_oow_t)); /*if (STIX_IN_SMOOI_RANGE(w))*/ if (w <= STIX_SMOOI_MAX) { @@ -494,7 +494,7 @@ static STIX_INLINE stix_oop_t expand_bigint (stix_t* stix, stix_oop_t oop, stix_ stix_oow_t i; stix_oow_t count; - STIX_ASSERT (STIX_OOP_IS_POINTER(oop)); + STIX_ASSERT (stix, STIX_OOP_IS_POINTER(oop)); count = STIX_OBJ_GET_SIZE(oop); if (inc > STIX_OBJ_SIZE_MAX - count) @@ -521,7 +521,7 @@ static STIX_INLINE stix_oop_t _clone_bigint (stix_t* stix, stix_oop_t oop, stix_ stix_oop_t z; stix_oow_t i; - STIX_ASSERT (STIX_OOP_IS_POINTER(oop)); + STIX_ASSERT (stix, STIX_OOP_IS_POINTER(oop)); if (count <= 0) count = STIX_OBJ_GET_SIZE(oop); stix_pushtmp (stix, &oop); @@ -545,14 +545,14 @@ static STIX_INLINE stix_oop_t clone_bigint_negated (stix_t* stix, stix_oop_t oop { stix_oop_t c; - STIX_ASSERT (STIX_OOP_IS_POINTER(oop)); + STIX_ASSERT (stix, STIX_OOP_IS_POINTER(oop)); if (STIX_OBJ_GET_CLASS(oop) == stix->_large_positive_integer) { c = stix->_large_negative_integer; } else { - STIX_ASSERT (STIX_OBJ_GET_CLASS(oop) == stix->_large_negative_integer); + STIX_ASSERT (stix, STIX_OBJ_GET_CLASS(oop) == stix->_large_negative_integer); c = stix->_large_positive_integer; } @@ -592,7 +592,7 @@ static stix_oop_t normalize_bigint (stix_t* stix, stix_oop_t oop) { stix_oow_t count; - STIX_ASSERT (STIX_OOP_IS_POINTER(oop)); + STIX_ASSERT (stix, STIX_OOP_IS_POINTER(oop)); count = count_effective_digits (oop); #if (STIX_LIW_BITS == STIX_OOW_BITS) @@ -607,8 +607,8 @@ static stix_oop_t normalize_bigint (stix_t* stix, stix_oop_t oop) } else { - STIX_ASSERT (-STIX_SMOOI_MAX == STIX_SMOOI_MIN); - STIX_ASSERT (STIX_OBJ_GET_CLASS(oop) == stix->_large_negative_integer); + 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); } } @@ -622,7 +622,7 @@ static stix_oop_t normalize_bigint (stix_t* stix, stix_oop_t oop) } else { - STIX_ASSERT (STIX_OBJ_GET_CLASS(oop) == stix->_large_negative_integer); + 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]); } } @@ -637,8 +637,8 @@ static stix_oop_t normalize_bigint (stix_t* stix, stix_oop_t oop) } else { - STIX_ASSERT (-STIX_SMOOI_MAX == STIX_SMOOI_MIN); - STIX_ASSERT (STIX_OBJ_GET_CLASS(oop) == stix->_large_negative_integer); + 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); } } @@ -737,7 +737,7 @@ static STIX_INLINE int is_equal (stix_t* stix, stix_oop_t x, stix_oop_t 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; } -static void complement2_unsigned_array (const stix_liw_t* x, stix_oow_t xs, stix_liw_t* z) +static void complement2_unsigned_array (stix_t* stix, const stix_liw_t* x, stix_oow_t xs, stix_liw_t* z) { stix_oow_t i; stix_lidw_t w; @@ -762,7 +762,7 @@ static void complement2_unsigned_array (const stix_liw_t* x, stix_oow_t xs, 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 (carry == 0); + STIX_ASSERT (stix, 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) @@ -857,7 +857,7 @@ 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 (const stix_liw_t* x, stix_oow_t xs, const stix_liw_t* y, stix_oow_t ys, stix_liw_t* z) +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) { #if 1 stix_oow_t i; @@ -865,12 +865,12 @@ static STIX_INLINE stix_oow_t subtract_unsigned_array (const stix_liw_t* x, stix if (x == y) { - STIX_ASSERT (xs == ys); + STIX_ASSERT (stix, xs == ys); z[0] = 0; return 1; } - STIX_ASSERT (!is_less_unsigned_array(x, xs, y, ys)); + STIX_ASSERT (stix, !is_less_unsigned_array(x, xs, y, ys)); for (i = 0; i < ys; i++) { @@ -903,12 +903,12 @@ static STIX_INLINE stix_oow_t subtract_unsigned_array (const stix_liw_t* x, stix if (x == y) { - STIX_ASSERT (xs == ys); + STIX_ASSERT (stix, xs == ys); z[0] = 0; return 1; } - STIX_ASSERT (!is_less_unsigned_array(x, xs, y, ys)); + STIX_ASSERT (stix, !is_less_unsigned_array(x, xs, y, ys)); borrowed_word = (stix_lidw_t)1 << STIX_LIW_BITS; for (i = 0; i < ys; i++) @@ -940,7 +940,7 @@ static STIX_INLINE stix_oow_t subtract_unsigned_array (const stix_liw_t* x, stix } } - STIX_ASSERT (borrow == 0); + STIX_ASSERT (stix, borrow == 0); while (i > 1 && z[i - 1] == 0) i--; return i; /* the number of effective digits in the result */ @@ -1120,8 +1120,8 @@ 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 (ndigits_xl >= ndigits_xh); - STIX_ASSERT (ndigits_yl >= ndigits_yh); + STIX_ASSERT (stix, ndigits_xl >= ndigits_xh); + STIX_ASSERT (stix, ndigits_yl >= ndigits_yh); /* make a temporary buffer for (b0 + b1) and (a1 * b1) */ tmplen[0] = ndigits_xh + ndigits_yh; @@ -1186,10 +1186,10 @@ static STIX_INLINE stix_oow_t multiply_unsigned_array_karatsuba (stix_t* stix, c } /* (a0+a1)*(b0+b1) -(a0*b0) */ - xlen = subtract_unsigned_array(zsp, xlen, tmp[0], tmplen[0], zsp); + xlen = subtract_unsigned_array(stix, zsp, xlen, tmp[0], tmplen[0], zsp); /* (a0+a1)*(b0+b1) - (a0*b0) - (a1*b1) */ - xlen = subtract_unsigned_array(zsp, xlen, tmp[1], tmplen[1], zsp); + xlen = subtract_unsigned_array(stix, 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); @@ -1240,8 +1240,8 @@ oops: ndigits_yl = nshifts; /* ndigits of lower part of y */ ndigits_yh = ys - nshifts; /* ndigits of uppoer part of y */ - STIX_ASSERT (ndigits_xl >= ndigits_xh); - STIX_ASSERT (ndigits_yl >= ndigits_yh); + STIX_ASSERT (stix, ndigits_xl >= ndigits_xh); + STIX_ASSERT (stix, ndigits_yl >= ndigits_yh); /* make a temporary buffer for (b0 + b1) and (a1 * b1) */ tmplen[0] = ndigits_yl + ndigits_yh + 1; @@ -1305,11 +1305,11 @@ oops: } /* w = w - tmp[0] */ - xlen = subtract_unsigned_array(tmp[2], xlen, tmp[0], tmplen[0], tmp[2]); + xlen = subtract_unsigned_array(stix, 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(tmp[2], xlen, tmp[1], tmplen[1], zsp); + xlen = subtract_unsigned_array(stix, 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". */ @@ -1405,10 +1405,7 @@ static STIX_INLINE void rshift_unsigned_array (stix_liw_t* x, stix_oow_t xs, sti STIX_MEMSET (&x[xs - word_shifts], 0, word_shifts * STIX_SIZEOF(stix_liw_t)); } -static void divide_unsigned_array ( - 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 (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) { /* TODO: this function needs to be rewritten for performance improvement. * the binary long division is extremely slow for a big number */ @@ -1430,7 +1427,7 @@ static void divide_unsigned_array ( stix_oow_t rs, i , j; - STIX_ASSERT (xs >= ys); + STIX_ASSERT (stix, xs >= ys); STIX_MEMSET (q, 0, STIX_SIZEOF(*q) * xs); STIX_MEMSET (r, 0, STIX_SIZEOF(*q) * xs); @@ -1447,7 +1444,7 @@ static void divide_unsigned_array ( rs = count_effective (r, xs); if (!is_less_unsigned_array (r, rs, y, ys)) { - subtract_unsigned_array (r, rs, y, ys, r); + subtract_unsigned_array (stix, r, rs, y, ys, r); STIX_SETBITS (stix_liw_t, q[i], j, 1, 1); } } @@ -1489,7 +1486,7 @@ static stix_oop_t subtract_unsigned_integers (stix_t* stix, stix_oop_t x, stix_o { stix_oop_t z; - STIX_ASSERT (!is_less_unsigned(x, y)); + STIX_ASSERT (stix, !is_less_unsigned(x, y)); stix_pushtmp (stix, &x); stix_pushtmp (stix, &y); @@ -1497,7 +1494,7 @@ static stix_oop_t subtract_unsigned_integers (stix_t* stix, stix_oop_t x, stix_o stix_poptmps (stix, 2); if (!z) return STIX_NULL; - subtract_unsigned_array ( + 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); @@ -1551,7 +1548,7 @@ static stix_oop_t divide_unsigned_integers (stix_t* stix, stix_oop_t x, stix_oop stix_oop_t qq, rr; /* the caller must ensure that x >= y */ - STIX_ASSERT (!is_less_unsigned (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)); @@ -1566,7 +1563,7 @@ static stix_oop_t divide_unsigned_integers (stix_t* stix, stix_oop_t x, stix_oop stix_poptmps (stix, 3); if (!rr) return STIX_NULL; - divide_unsigned_array ( + 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); @@ -1585,8 +1582,8 @@ stix_oop_t stix_addints (stix_t* stix, stix_oop_t x, stix_oop_t y) /* no integer overflow/underflow must occur as the possible integer * range is narrowed by the tag bits used */ - STIX_ASSERT (STIX_SMOOI_MAX + STIX_SMOOI_MAX < STIX_TYPE_MAX(stix_ooi_t)); - STIX_ASSERT (STIX_SMOOI_MIN + STIX_SMOOI_MIN > STIX_TYPE_MIN(stix_ooi_t)); + 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)); i = STIX_OOP_TO_SMOOI(x) + STIX_OOP_TO_SMOOI(y); if (STIX_IN_SMOOI_RANGE(i)) return STIX_SMOOI_TO_OOP(i); @@ -1688,8 +1685,8 @@ stix_oop_t stix_subints (stix_t* stix, stix_oop_t x, stix_oop_t y) /* no integer overflow/underflow must occur as the possible integer * range is narrowed by the tag bits used */ - STIX_ASSERT (STIX_SMOOI_MAX - STIX_SMOOI_MIN < STIX_TYPE_MAX(stix_ooi_t)); - STIX_ASSERT (STIX_SMOOI_MIN - STIX_SMOOI_MAX > STIX_TYPE_MIN(stix_ooi_t)); + 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)); i = STIX_OOP_TO_SMOOI(x) - STIX_OOP_TO_SMOOI(y); if (STIX_IN_SMOOI_RANGE(i)) return STIX_SMOOI_TO_OOP(i); @@ -1786,7 +1783,7 @@ stix_oop_t stix_mulints (stix_t* stix, stix_oop_t x, stix_oop_t y) xv = STIX_OOP_TO_SMOOI(x); yv = STIX_OOP_TO_SMOOI(y); - if (smooi_mul_overflow (xv, yv, &i)) + if (smooi_mul_overflow (stix, xv, yv, &i)) { /* overflowed - convert x and y normal objects and carry on */ @@ -1916,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_IN_SMOOI_RANGE(q)); + STIX_ASSERT (stix, STIX_IN_SMOOI_RANGE(q)); r = xv - yv * q; /* xv % yv; */ if (r) @@ -1941,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 (r && !IS_SIGN_DIFF(yv, r)); + STIX_ASSERT (stix, r && !IS_SIGN_DIFF(yv, r)); } } else @@ -1965,14 +1962,14 @@ 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 (xv && !IS_SIGN_DIFF(xv, r)); + STIX_ASSERT (stix, xv && !IS_SIGN_DIFF(xv, r)); } } } if (rem) { - STIX_ASSERT (STIX_IN_SMOOI_RANGE(r)); + STIX_ASSERT (stix, STIX_IN_SMOOI_RANGE(r)); *rem = STIX_SMOOI_TO_OOP(r); } @@ -2231,7 +2228,7 @@ stix_oop_t stix_bitatint (stix_t* stix, stix_oop_t x, stix_oop_t y) #if defined(STIX_LIMIT_OBJ_SIZE) if (STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer) return STIX_SMOOI_TO_OOP(0); - STIX_ASSERT (STIX_OBJ_SIZE_BITS_MAX <= STIX_TYPE_MAX(stix_oow_t)); + STIX_ASSERT (stix, STIX_OBJ_SIZE_BITS_MAX <= STIX_TYPE_MAX(stix_oow_t)); if (STIX_OBJ_GET_CLASS(x) == stix->_large_positive_integer) { return STIX_SMOOI_TO_OOP (0); @@ -2246,7 +2243,7 @@ stix_oop_t stix_bitatint (stix_t* stix, stix_oop_t x, stix_oop_t y) if (STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer) return STIX_SMOOI_TO_OOP(0); sign = bigint_to_oow (stix, y, &w); - STIX_ASSERT (sign >= 0); + STIX_ASSERT (stix, sign >= 0); if (sign >= 1) { wp = (w - 1) / STIX_LIW_BITS; @@ -2256,7 +2253,7 @@ stix_oop_t stix_bitatint (stix_t* stix, stix_oop_t x, stix_oop_t y) { stix_oop_t quo, rem; - STIX_ASSERT (sign == 0); + STIX_ASSERT (stix, sign == 0); stix_pushtmp (stix, &x); y = stix_subints (stix, y, STIX_SMOOI_TO_OOP(1)); @@ -2269,7 +2266,7 @@ stix_oop_t stix_bitatint (stix_t* stix, stix_oop_t x, stix_oop_t y) if (!quo) return STIX_NULL; sign = integer_to_oow (stix, quo, &wp); - STIX_ASSERT (sign >= 0); + STIX_ASSERT (stix, sign >= 0); if (sign == 0) { /* too large. set it to xs so that it gets out of @@ -2277,9 +2274,9 @@ stix_oop_t stix_bitatint (stix_t* stix, stix_oop_t x, stix_oop_t y) wp = xs; } - STIX_ASSERT (STIX_OOP_IS_SMOOI(rem)); + STIX_ASSERT (stix, STIX_OOP_IS_SMOOI(rem)); bp = STIX_OOP_TO_SMOOI(rem); - STIX_ASSERT (bp >= 0 && bp < STIX_LIW_BITS); + STIX_ASSERT (stix, bp >= 0 && bp < STIX_LIW_BITS); } if (STIX_OBJ_GET_CLASS(x) == stix->_large_positive_integer) @@ -2429,7 +2426,7 @@ stix_oop_t stix_bitandints (stix_t* stix, stix_oop_t x, stix_oop_t y) ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w[0] & (stix_liw_t)w[1]; } - STIX_ASSERT (carry[1] == 0); + STIX_ASSERT (stix, 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. */ @@ -2439,7 +2436,7 @@ stix_oop_t stix_bitandints (stix_t* stix, stix_oop_t x, stix_oop_t y) carry[0] = w[0] >> STIX_LIW_BITS; ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w[0]; } - STIX_ASSERT (carry[0] == 0); + STIX_ASSERT (stix, carry[0] == 0); /* 2's complement on the final result */ ((stix_oop_liword_t)z)->slot[zs] = ~(stix_liw_t)0; @@ -2450,7 +2447,7 @@ stix_oop_t stix_bitandints (stix_t* stix, stix_oop_t x, stix_oop_t y) carry[0] = w[0] >> STIX_LIW_BITS; ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w[0]; } - STIX_ASSERT (carry[0] == 0); + STIX_ASSERT (stix, carry[0] == 0); STIX_OBJ_SET_CLASS (z, stix->_large_negative_integer); } @@ -2484,7 +2481,7 @@ stix_oop_t stix_bitandints (stix_t* stix, stix_oop_t x, stix_oop_t y) carry = w >> STIX_LIW_BITS; ((stix_oop_liword_t)z)->slot[i] = ((stix_oop_liword_t)x)->slot[i] & (stix_liw_t)w; } - STIX_ASSERT (carry == 0); + STIX_ASSERT (stix, carry == 0); /* handle the longer part in x than y * @@ -2649,7 +2646,7 @@ stix_oop_t stix_bitorints (stix_t* stix, stix_oop_t x, stix_oop_t y) ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w[0] | (stix_liw_t)w[1]; } - STIX_ASSERT (carry[1] == 0); + STIX_ASSERT (stix, 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 @@ -2665,7 +2662,7 @@ stix_oop_t stix_bitorints (stix_t* stix, stix_oop_t x, stix_oop_t y) carry[0] = w[0] >> STIX_LIW_BITS; ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w[0]; } - STIX_ASSERT (carry[0] == 0); + STIX_ASSERT (stix, carry[0] == 0); STIX_OBJ_SET_CLASS (z, stix->_large_negative_integer); } @@ -2689,7 +2686,7 @@ stix_oop_t stix_bitorints (stix_t* stix, stix_oop_t x, stix_oop_t y) ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w; } - STIX_ASSERT (carry == 0); + STIX_ASSERT (stix, carry == 0); goto adjust_to_negative; } else if (negy) @@ -2705,7 +2702,7 @@ stix_oop_t stix_bitorints (stix_t* stix, stix_oop_t x, stix_oop_t y) carry = w >> STIX_LIW_BITS; ((stix_oop_liword_t)z)->slot[i] = ((stix_oop_liword_t)x)->slot[i] | (stix_liw_t)w; } - STIX_ASSERT (carry == 0); + STIX_ASSERT (stix, carry == 0); /* [NOTE] * in theory, the lacking part in ys is all 1s when y is @@ -2867,7 +2864,7 @@ stix_oop_t stix_bitxorints (stix_t* stix, stix_oop_t x, stix_oop_t y) ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w[0] ^ (stix_liw_t)w[1]; } - STIX_ASSERT (carry[1] == 0); + STIX_ASSERT (stix, carry[1] == 0); /* treat the lacking part in y as all 1s */ for (; i < xs; i++) @@ -2876,7 +2873,7 @@ stix_oop_t stix_bitxorints (stix_t* stix, stix_oop_t x, stix_oop_t y) carry[0] = w[0] >> STIX_LIW_BITS; ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w[0] ^ (~(stix_liw_t)0); } - STIX_ASSERT (carry[0] == 0); + STIX_ASSERT (stix, carry[0] == 0); } else if (negx) { @@ -2898,7 +2895,7 @@ stix_oop_t stix_bitxorints (stix_t* stix, stix_oop_t x, stix_oop_t y) carry = w >> STIX_LIW_BITS; ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w; } - STIX_ASSERT (carry == 0); + STIX_ASSERT (stix, carry == 0); adjust_to_negative: /* 2's complement on the final result */ @@ -2910,7 +2907,7 @@ stix_oop_t stix_bitxorints (stix_t* stix, stix_oop_t x, stix_oop_t y) carry = w >> STIX_LIW_BITS; ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w; } - STIX_ASSERT (carry == 0); + STIX_ASSERT (stix, carry == 0); STIX_OBJ_SET_CLASS (z, stix->_large_negative_integer); } @@ -2927,7 +2924,7 @@ stix_oop_t stix_bitxorints (stix_t* stix, stix_oop_t x, stix_oop_t y) carry = w >> STIX_LIW_BITS; ((stix_oop_liword_t)z)->slot[i] = ((stix_oop_liword_t)x)->slot[i] ^ (stix_liw_t)w; } - STIX_ASSERT (carry == 0); + STIX_ASSERT (stix, carry == 0); /* treat the lacking part in y as all 1s */ for (; i < xs; i++) @@ -3017,7 +3014,7 @@ stix_oop_t stix_bitinvint (stix_t* stix, stix_oop_t x) carry = w >> STIX_LIW_BITS; ((stix_oop_liword_t)z)->slot[i] = ~(stix_liw_t)w; } - STIX_ASSERT (carry == 0); + STIX_ASSERT (stix, carry == 0); } else { @@ -3037,7 +3034,7 @@ stix_oop_t stix_bitinvint (stix_t* stix, stix_oop_t x) carry = w >> STIX_LIW_BITS; ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w; } - STIX_ASSERT (carry == 0); + STIX_ASSERT (stix, carry == 0); #else carry = 1; for (i = 0; i < xs; i++) @@ -3046,9 +3043,9 @@ stix_oop_t stix_bitinvint (stix_t* stix, stix_oop_t x) carry = w >> STIX_LIW_BITS; ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w; } - STIX_ASSERT (i == zs); + STIX_ASSERT (stix, i == zs); ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)carry; - STIX_ASSERT ((carry >> STIX_LIW_BITS) == 0); + STIX_ASSERT (stix, (carry >> STIX_LIW_BITS) == 0); #endif STIX_OBJ_SET_CLASS (z, stix->_large_negative_integer); @@ -3069,7 +3066,7 @@ static STIX_INLINE stix_oop_t rshift_negative_bigint (stix_t* stix, stix_oop_t x stix_lidw_t carry; stix_oow_t i, xs; - STIX_ASSERT (STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer); + STIX_ASSERT (stix, STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer); xs = STIX_OBJ_GET_SIZE(x); stix_pushtmp (stix, &x); @@ -3086,7 +3083,7 @@ static STIX_INLINE stix_oop_t rshift_negative_bigint (stix_t* stix, stix_oop_t x carry = w >> STIX_LIW_BITS; ((stix_oop_liword_t)z)->slot[i] = ~(stix_liw_t)w; } - STIX_ASSERT (carry == 0); + STIX_ASSERT (stix, carry == 0); /* shift to the right */ rshift_unsigned_array (((stix_oop_liword_t)z)->slot, xs, shift); @@ -3106,7 +3103,7 @@ static STIX_INLINE stix_oop_t rshift_negative_bigint (stix_t* stix, stix_oop_t x carry = w >> STIX_LIW_BITS; ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w; } - STIX_ASSERT (carry == 0); + STIX_ASSERT (stix, carry == 0); #else carry = 1; for (i = 0; i < xs; i++) @@ -3116,7 +3113,7 @@ static STIX_INLINE stix_oop_t rshift_negative_bigint (stix_t* stix, stix_oop_t x ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)w; } ((stix_oop_liword_t)z)->slot[i] = (stix_liw_t)carry; - STIX_ASSERT ((carry >> STIX_LIW_BITS) == 0); + STIX_ASSERT (stix, (carry >> STIX_LIW_BITS) == 0); #endif return z; /* z is not normalized */ @@ -3132,8 +3129,8 @@ static STIX_INLINE stix_oop_t rshift_negative_bigint_and_normalize (stix_t* stix stix_oow_t shift; int sign; - STIX_ASSERT (STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer); - STIX_ASSERT (STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer); + STIX_ASSERT (stix, STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer); + STIX_ASSERT (stix, STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer); /* for convenience in subtraction below. * it could be STIX_TYPE_MAX(stix_oow_t) @@ -3162,7 +3159,7 @@ static STIX_INLINE stix_oop_t rshift_negative_bigint_and_normalize (stix_t* stix /* no more shift */ return normalize_bigint (stix, z); } - STIX_ASSERT (sign <= -1); + STIX_ASSERT (stix, sign <= -1); } stix_pushtmp (stix, &y); @@ -3176,7 +3173,7 @@ static STIX_INLINE stix_oop_t rshift_negative_bigint_and_normalize (stix_t* stix stix_ooi_t v; v = STIX_OOP_TO_SMOOI(x); - STIX_ASSERT (v < 0); + STIX_ASSERT (stix, v < 0); /* normal right shift of a small negative integer */ if (shift >= STIX_OOI_BITS - 1) @@ -3199,7 +3196,7 @@ static STIX_INLINE stix_oop_t rshift_negative_bigint_and_normalize (stix_t* stix while (1); /* this part must not be reached */ - STIX_ASSERT (!"internal error - must not happen"); + STIX_ASSERT (stix, !"internal error - must not happen"); stix->errnum = STIX_EINTERN; return STIX_NULL; } @@ -3210,8 +3207,8 @@ static STIX_INLINE stix_oop_t rshift_positive_bigint_and_normalize (stix_t* stix stix_oow_t zs, shift; int sign; - STIX_ASSERT (STIX_OBJ_GET_CLASS(x) == stix->_large_positive_integer); - STIX_ASSERT (STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer); + STIX_ASSERT (stix, STIX_OBJ_GET_CLASS(x) == stix->_large_positive_integer); + STIX_ASSERT (stix, STIX_OBJ_GET_CLASS(y) == stix->_large_negative_integer); zs = STIX_OBJ_GET_SIZE(x); @@ -3246,7 +3243,7 @@ static STIX_INLINE stix_oop_t rshift_positive_bigint_and_normalize (stix_t* stix else { if (shift == 0) break; - STIX_ASSERT (sign <= -1); + STIX_ASSERT (stix, sign <= -1); } } while (1); @@ -3260,7 +3257,7 @@ static STIX_INLINE stix_oop_t lshift_bigint_and_normalize (stix_t* stix, stix_oo stix_oow_t wshift, shift; int sign; - STIX_ASSERT (STIX_OBJ_GET_CLASS(y) == stix->_large_positive_integer); + STIX_ASSERT (stix, STIX_OBJ_GET_CLASS(y) == stix->_large_positive_integer); /* this loop is very inefficient as shifting is repeated * with lshift_unsigned_array(). however, this part of the @@ -3300,16 +3297,16 @@ static STIX_INLINE stix_oop_t lshift_bigint_and_normalize (stix_t* stix, stix_oo { if (shift == 0) { - STIX_ASSERT (is_normalized_integer (stix, x)); + STIX_ASSERT (stix, is_normalized_integer (stix, x)); return x; } - STIX_ASSERT (sign >= 1); + STIX_ASSERT (stix, sign >= 1); } } while (1); /* this part must not be reached */ - STIX_ASSERT (!"internal error - must not happen"); + STIX_ASSERT (stix, !"internal error - must not happen"); stix->errnum = STIX_EINTERN; return STIX_NULL; } @@ -3466,7 +3463,7 @@ stix_oop_t stix_bitshiftint (stix_t* stix, stix_oop_t x, stix_oop_t y) /* the maximum number of bit shifts are guaranteed to be * small enough to fit into the stix_oow_t type. so i can * easily assume that all bits are shifted out */ - STIX_ASSERT (STIX_OBJ_SIZE_BITS_MAX <= STIX_TYPE_MAX(stix_oow_t)); + 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); #else if (negx) @@ -3483,7 +3480,7 @@ stix_oop_t stix_bitshiftint (stix_t* stix, stix_oop_t x, stix_oop_t y) * small enough to fit into the stix_oow_t type. so i can * simply return a failure here becuase it's surely too * large after shifting */ - STIX_ASSERT (STIX_TYPE_MAX(stix_oow_t) >= STIX_OBJ_SIZE_BITS_MAX); + 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; #else @@ -3510,7 +3507,7 @@ stix_oop_t stix_bitshiftint (stix_t* stix, stix_oop_t x, stix_oop_t y) /* right shift */ bigint_and_negative_oow: - STIX_ASSERT (sign <= -1); + STIX_ASSERT (stix, sign <= -1); if (negx) { @@ -3562,7 +3559,7 @@ stix_oop_t stix_strtoint (stix_t* stix, const stix_ooch_t* str, stix_oow_t len, radix = -radix; } - STIX_ASSERT (radix >= 2 && radix <= 36); + STIX_ASSERT (stix, radix >= 2 && radix <= 36); ptr = str; end = str + len; @@ -3667,7 +3664,7 @@ stix_oop_t stix_strtoint (stix_t* stix, const stix_ooch_t* str, stix_oow_t len, ptr--; } - STIX_ASSERT (w <= STIX_TYPE_MAX(stix_liw_t)); + STIX_ASSERT (stix, w <= STIX_TYPE_MAX(stix_liw_t)); if (hwlen == 0 || w > 0) hwp[hwlen++] = w; } else @@ -3693,7 +3690,7 @@ stix_oop_t stix_strtoint (stix_t* stix, const stix_ooch_t* str, stix_oow_t len, hwp = hw; } - STIX_ASSERT (ptr < end); + STIX_ASSERT (stix, ptr < end); do { r1 = 0; @@ -3740,25 +3737,25 @@ stix_oop_t stix_strtoint (stix_t* stix, const stix_ooch_t* str, stix_oow_t len, while (ptr < end); } - STIX_ASSERT (hwlen >= 1); + STIX_ASSERT (stix, hwlen >= 1); #if (STIX_LIW_BITS == STIX_OOW_BITS) if (hwlen == 1) { w = hwp[0]; - STIX_ASSERT (-STIX_SMOOI_MAX == STIX_SMOOI_MIN); + STIX_ASSERT (stix, -STIX_SMOOI_MAX == STIX_SMOOI_MIN); if (w <= STIX_SMOOI_MAX) return STIX_SMOOI_TO_OOP((stix_ooi_t)w * sign); } #elif (STIX_LIW_BITS == STIX_OOHW_BITS) if (hwlen == 1) { - STIX_ASSERT (hwp[0] <= STIX_SMOOI_MAX); + STIX_ASSERT (stix, hwp[0] <= STIX_SMOOI_MAX); return STIX_SMOOI_TO_OOP((stix_ooi_t)hwp[0] * sign); } else if (hwlen == 2) { w = MAKE_WORD(hwp[0], hwp[1]); - STIX_ASSERT (-STIX_SMOOI_MAX == STIX_SMOOI_MIN); + STIX_ASSERT (stix, -STIX_SMOOI_MAX == STIX_SMOOI_MIN); if (w <= STIX_SMOOI_MAX) return STIX_SMOOI_TO_OOP((stix_ooi_t)w * sign); } #else @@ -3776,10 +3773,10 @@ oops_einval: return STIX_NULL; } -static stix_oow_t oow_to_text (stix_oow_t w, int radix, stix_ooch_t* buf) +static stix_oow_t oow_to_text (stix_t* stix, stix_oow_t w, int radix, stix_ooch_t* buf) { stix_ooch_t* ptr; - STIX_ASSERT (radix >= 2 && radix <= 36); + STIX_ASSERT (stix, radix >= 2 && radix <= 36); ptr = buf; do @@ -3974,7 +3971,7 @@ stix_oop_t stix_inttostr (stix_t* stix, stix_oop_t num, int radix) stix_oow_t xlen = 0, seglen; stix_oop_t s; - STIX_ASSERT (radix >= 2 && radix <= 36); + STIX_ASSERT (stix, radix >= 2 && radix <= 36); if (!stix_isint(stix,num)) goto oops_einval; v = integer_to_oow (stix, num, &w); @@ -3989,7 +3986,7 @@ stix_oop_t stix_inttostr (stix_t* stix, stix_oop_t num, int radix) stix_ooch_t buf[STIX_OOW_BITS + 1]; stix_oow_t len; - len = oow_to_text (w, radix, buf); + len = oow_to_text (stix, w, radix, buf); if (v < 0) buf[len++] = '-'; reverse_string (buf, len); @@ -4038,7 +4035,7 @@ stix_oop_t stix_inttostr (stix_t* stix, stix_oop_t num, int radix) while (1); } - STIX_ASSERT (xpos >= 1); + STIX_ASSERT (stix, xpos >= 1); if (STIX_OBJ_GET_CLASS(num) == stix->_large_negative_integer) xbuf[--xpos] = '-'; s = stix_makestring (stix, &xbuf[xpos], xlen - xpos); @@ -4082,7 +4079,7 @@ stix_oop_t stix_inttostr (stix_t* stix, stix_oop_t num, int radix) { stix_liw_t* tmp; - divide_unsigned_array (a, as, b, bs, q, r); + divide_unsigned_array (stix, a, as, b, bs, q, r); /* get 'rs' before 'as' gets changed */ rs = count_effective (r, as); @@ -4102,19 +4099,19 @@ stix_oop_t stix_inttostr (stix_t* stix, stix_oop_t num, int radix) } #if (STIX_LIW_BITS == STIX_OOW_BITS) - STIX_ASSERT (rs == 1); + STIX_ASSERT (stix, rs == 1); w = r[0]; #elif (STIX_LIW_BITS == STIX_OOHW_BITS) if (rs == 1) w = r[0]; else { - STIX_ASSERT (rs == 2); + STIX_ASSERT (stix, rs == 2); w = MAKE_WORD (r[0], r[1]); } #else # error UNSUPPORTED LIW BIT SIZE #endif - seglen = oow_to_text (w, radix, &xbuf[xlen]); + seglen = oow_to_text (stix, w, radix, &xbuf[xlen]); xlen += seglen; if (r == a) break; /* reached the last block */ diff --git a/stix/lib/comp.c b/stix/lib/comp.c index 2c091aa..7e9479a 100644 --- a/stix/lib/comp.c +++ b/stix/lib/comp.c @@ -405,7 +405,7 @@ static int string_to_smooi (stix_t* stix, stix_oocs_t* str, int radixed, stix_oo ptr = str->ptr, end = str->ptr + str->len; - STIX_ASSERT (ptr < end); + STIX_ASSERT (stix, ptr < end); if (*ptr == '+' || *ptr == '-') { @@ -415,7 +415,7 @@ static int string_to_smooi (stix_t* stix, stix_oocs_t* str, int radixed, stix_oo if (radixed) { - STIX_ASSERT (ptr < end); + STIX_ASSERT (stix, ptr < end); base = 0; do @@ -429,7 +429,7 @@ static int string_to_smooi (stix_t* stix, stix_oocs_t* str, int radixed, stix_oo } else base = 10; - STIX_ASSERT (ptr < end); + STIX_ASSERT (stix, ptr < end); value = old_value = 0; while (ptr < end && (v = CHAR_TO_NUM(*ptr, base)) < base) @@ -452,7 +452,7 @@ static int string_to_smooi (stix_t* stix, stix_oocs_t* str, int radixed, stix_oo return -1; } - STIX_ASSERT (-STIX_SMOOI_MAX == STIX_SMOOI_MIN); + STIX_ASSERT (stix, -STIX_SMOOI_MAX == STIX_SMOOI_MIN); if (value > STIX_SMOOI_MAX) { stix->errnum = STIX_ERANGE; @@ -474,7 +474,7 @@ static stix_oop_t string_to_num (stix_t* stix, stix_oocs_t* str, int radixed) ptr = str->ptr, end = str->ptr + str->len; - STIX_ASSERT (ptr < end); + STIX_ASSERT (stix, ptr < end); if (*ptr == '+' || *ptr == '-') { @@ -484,7 +484,7 @@ static stix_oop_t string_to_num (stix_t* stix, stix_oocs_t* str, int radixed) if (radixed) { - STIX_ASSERT (ptr < end); + STIX_ASSERT (stix, ptr < end); base = 0; do @@ -588,7 +588,7 @@ static STIX_INLINE int add_token_char (stix_t* stix, stix_ooch_t c) static STIX_INLINE void unget_char (stix_t* stix, const stix_iolxc_t* c) { /* Make sure that the unget buffer is large enough */ - STIX_ASSERT (stix->c->nungots < STIX_COUNTOF(stix->c->ungot)); + STIX_ASSERT (stix, stix->c->nungots < STIX_COUNTOF(stix->c->ungot)); stix->c->ungot[stix->c->nungots++] = *c; } @@ -937,7 +937,7 @@ static int get_numlit (stix_t* stix, int negated) { /* collect the potential radix specifier */ r = CHAR_TO_NUM (c, 10); - STIX_ASSERT (r < 10); + STIX_ASSERT (stix, r < 10); radix = radix * 10 + r; } @@ -1570,7 +1570,7 @@ static void clear_io_names (stix_t* stix) { stix_iolink_t* cur; - STIX_ASSERT (stix->c != STIX_NULL); + STIX_ASSERT (stix, stix->c != STIX_NULL); while (stix->c->io_names) { @@ -1673,7 +1673,7 @@ static int end_include (stix_t* stix) cur = stix->c->curinp; stix->c->curinp = stix->c->curinp->includer; - STIX_ASSERT (cur->name != STIX_NULL); + STIX_ASSERT (stix, cur->name != STIX_NULL); stix_freemem (stix, cur); /* stix->parse.depth.incl--; */ @@ -2047,7 +2047,7 @@ static stix_ooi_t find_class_level_variable (stix_t* stix, stix_oop_class_t self if (self) { - STIX_ASSERT (STIX_CLASSOF(stix, self) == stix->_class); + STIX_ASSERT (stix, STIX_CLASSOF(stix, self) == stix->_class); /* [NOTE] * the loop here assumes that the class has the following @@ -2095,7 +2095,7 @@ static stix_ooi_t find_class_level_variable (stix_t* stix, stix_oop_class_t self while (super != stix->_nil) { - STIX_ASSERT (STIX_CLASSOF(stix, super) == stix->_class); + STIX_ASSERT (stix, STIX_CLASSOF(stix, super) == stix->_class); /* [NOTE] * the loop here assumes that the class has the following @@ -2138,7 +2138,7 @@ done: /* the class being compiled has a superclass */ - STIX_ASSERT (STIX_CLASSOF(stix, super) == stix->_class); + STIX_ASSERT (stix, STIX_CLASSOF(stix, super) == stix->_class); switch (index) { case VAR_INSTANCE: @@ -2562,8 +2562,8 @@ if super is variable-nonpointer, no instance variable is allowed. static int compile_unary_method_name (stix_t* stix) { - STIX_ASSERT (stix->c->mth.name.len == 0); - STIX_ASSERT (stix->c->mth.tmpr_nargs == 0); + STIX_ASSERT (stix, stix->c->mth.name.len == 0); + STIX_ASSERT (stix, stix->c->mth.tmpr_nargs == 0); if (add_method_name_fragment(stix, TOKEN_NAME(stix)) <= -1) return -1; GET_TOKEN (stix); @@ -2571,7 +2571,7 @@ static int compile_unary_method_name (stix_t* stix) if (TOKEN_TYPE(stix) == STIX_IOTOK_LPAREN) { /* this is a procedural style method */ - STIX_ASSERT (stix->c->mth.tmpr_nargs == 0); + STIX_ASSERT (stix, stix->c->mth.tmpr_nargs == 0); GET_TOKEN (stix); if (TOKEN_TYPE(stix) != STIX_IOTOK_RPAREN) @@ -2618,8 +2618,8 @@ static int compile_unary_method_name (stix_t* stix) static int compile_binary_method_name (stix_t* stix) { - STIX_ASSERT (stix->c->mth.name.len == 0); - STIX_ASSERT (stix->c->mth.tmpr_nargs == 0); + STIX_ASSERT (stix, stix->c->mth.name.len == 0); + STIX_ASSERT (stix, stix->c->mth.tmpr_nargs == 0); if (add_method_name_fragment(stix, TOKEN_NAME(stix)) <= -1) return -1; GET_TOKEN (stix); @@ -2632,14 +2632,14 @@ static int compile_binary_method_name (stix_t* stix) return -1; } - STIX_ASSERT (stix->c->mth.tmpr_nargs == 0); + STIX_ASSERT (stix, stix->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++; - STIX_ASSERT (stix->c->mth.tmpr_nargs == 1); + STIX_ASSERT (stix, stix->c->mth.tmpr_nargs == 1); /* this check should not be not necessary if (stix->c->mth.tmpr_nargs > MAX_CODE_NARGS) { @@ -2654,8 +2654,8 @@ static int compile_binary_method_name (stix_t* stix) static int compile_keyword_method_name (stix_t* stix) { - STIX_ASSERT (stix->c->mth.name.len == 0); - STIX_ASSERT (stix->c->mth.tmpr_nargs == 0); + STIX_ASSERT (stix, stix->c->mth.name.len == 0); + STIX_ASSERT (stix, stix->c->mth.tmpr_nargs == 0); do { @@ -2697,7 +2697,7 @@ static int compile_method_name (stix_t* stix) */ int n; - STIX_ASSERT (stix->c->mth.tmpr_count == 0); + STIX_ASSERT (stix, stix->c->mth.tmpr_count == 0); stix->c->mth.name_loc = stix->c->tok.loc; switch (TOKEN_TYPE(stix)) @@ -2729,7 +2729,7 @@ static int compile_method_name (stix_t* stix) } } - STIX_ASSERT (stix->c->mth.tmpr_nargs < MAX_CODE_NARGS); + STIX_ASSERT (stix, stix->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 */ @@ -2936,7 +2936,7 @@ static int get_variable_info (stix_t* stix, const stix_oocs_t* name, const stix_ const stix_ooch_t* dot; dot = stix_findoochar (name->ptr, name->len, '.'); - STIX_ASSERT (dot != STIX_NULL); + STIX_ASSERT (stix, dot != STIX_NULL); if (dot - (const stix_ooch_t*)name->ptr == 4 && stix_equaloochars(name->ptr, vocas[VOCA_SELF].str, 4)) { @@ -3004,8 +3004,8 @@ static int get_variable_info (stix_t* stix, const stix_oocs_t* name, const stix_ case VAR_CLASS: /* a class variable can be access by both instance methods and class methods */ - STIX_ASSERT (var->cls != STIX_NULL); - STIX_ASSERT (STIX_CLASSOF(stix, var->cls) == stix->_class); + STIX_ASSERT (stix, var->cls != STIX_NULL); + STIX_ASSERT (stix, STIX_CLASSOF(stix, var->cls) == stix->_class); /* increment the position by the number of class instance variables * as the class variables are placed after the class instance variables */ @@ -3175,14 +3175,14 @@ static int compile_block_expression (stix_t* stix) */ /* this function expects [ not to be consumed away */ - STIX_ASSERT (TOKEN_TYPE(stix) == STIX_IOTOK_LBRACK); + STIX_ASSERT (stix, TOKEN_TYPE(stix) == STIX_IOTOK_LBRACK); block_loc = stix->c->tok.loc; GET_TOKEN (stix); saved_tmprs_len = stix->c->mth.tmprs.len; saved_tmpr_count = stix->c->mth.tmpr_count; - STIX_ASSERT (stix->c->mth.blk_depth > 0); - STIX_ASSERT (stix->c->mth.blk_tmprcnt[stix->c->mth.blk_depth - 1] == saved_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); if (TOKEN_TYPE(stix) == STIX_IOTOK_COLON) { @@ -3395,7 +3395,7 @@ static int __read_byte_array_literal (stix_t* stix, stix_oop_t* xlit) { /* the token reader reads a valid token. no other errors * than the range error must not occur */ - STIX_ASSERT (stix->errnum == STIX_ERANGE); + STIX_ASSERT (stix, stix->errnum == STIX_ERANGE); /* if the token is out of the SMOOI range, it's too big or * to small to be a byte */ @@ -3454,7 +3454,7 @@ static int __read_array_literal (stix_t* stix, stix_oop_t* xlit) break; case STIX_IOTOK_CHARLIT: - STIX_ASSERT (TOKEN_NAME_LEN(stix) == 1); + STIX_ASSERT (stix, TOKEN_NAME_LEN(stix) == 1); lit = STIX_CHAR_TO_OOP(TOKEN_NAME_PTR(stix)[0]); break; @@ -3578,7 +3578,7 @@ static int compile_array_literal (stix_t* stix) stix_oop_t lit; stix_oow_t index; - STIX_ASSERT (stix->c->mth.arlit_count == 0); + STIX_ASSERT (stix, stix->c->mth.arlit_count == 0); if (read_array_literal(stix, &lit) <= -1 || add_literal(stix, lit, &index) <= -1 || @@ -3618,7 +3618,7 @@ static int compile_expression_primary (stix_t* stix, const stix_oocs_t* ident, c /* if a temporary variable is accessed inside a block, * use a special instruction to indicate it */ - STIX_ASSERT (var.pos < stix->c->mth.blk_tmprcnt[stix->c->mth.blk_depth]); + 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--) { if (var.pos >= stix->c->mth.blk_tmprcnt[i - 1]) @@ -3715,7 +3715,7 @@ static int compile_expression_primary (stix_t* stix, const stix_oocs_t* ident, c break; case STIX_IOTOK_CHARLIT: - STIX_ASSERT (TOKEN_NAME_LEN(stix) == 1); + 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); break; @@ -3818,7 +3818,7 @@ static int compile_unary_message (stix_t* stix, int to_super) stix_oow_t index; stix_oow_t nargs; - STIX_ASSERT (TOKEN_TYPE(stix) == STIX_IOTOK_IDENT); + STIX_ASSERT (stix, TOKEN_TYPE(stix) == STIX_IOTOK_IDENT); do { @@ -3875,7 +3875,7 @@ static int compile_binary_message (stix_t* stix, int to_super) stix_oocs_t binsel; stix_oow_t saved_binsels_len, binsel_offset; - STIX_ASSERT (TOKEN_TYPE(stix) == STIX_IOTOK_BINSEL); + STIX_ASSERT (stix, TOKEN_TYPE(stix) == STIX_IOTOK_BINSEL); do { @@ -3999,7 +3999,7 @@ static int compile_message_expression (stix_t* stix, int to_super) if (TOKEN_TYPE(stix) == STIX_IOTOK_BINSEL) { - STIX_ASSERT (stix->c->mth.code.len > noop_pos); + 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--; @@ -4010,7 +4010,7 @@ static int compile_message_expression (stix_t* stix, int to_super) if (TOKEN_TYPE(stix) == STIX_IOTOK_KEYWORD) { - STIX_ASSERT (stix->c->mth.code.len > noop_pos); + 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--; @@ -4027,7 +4027,7 @@ static int compile_message_expression (stix_t* stix, int to_super) if (compile_binary_message(stix, to_super) <= -1) return -1; if (TOKEN_TYPE(stix) == STIX_IOTOK_KEYWORD) { - STIX_ASSERT (stix->c->mth.code.len > noop_pos); + 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--; @@ -4058,7 +4058,7 @@ static int compile_message_expression (stix_t* stix, int to_super) else { /* delete the NOOP instruction inserted */ - STIX_ASSERT (stix->c->mth.code.len > noop_pos); + 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--; goto done; @@ -4110,7 +4110,7 @@ static int compile_method_expression (stix_t* stix, int pop) stix_oow_t index; int ret = 0; - STIX_ASSERT (pop == 0 || pop == 1); + STIX_ASSERT (stix, pop == 0 || pop == 1); STIX_MEMSET (&assignee, 0, STIX_SIZEOF(assignee)); if (TOKEN_TYPE(stix) == STIX_IOTOK_IDENT || @@ -4164,7 +4164,7 @@ static int compile_method_expression (stix_t* stix, int pop) /* if a temporary variable is accessed inside a block, * use a special instruction to indicate it */ - STIX_ASSERT (var.pos < stix->c->mth.blk_tmprcnt[stix->c->mth.blk_depth]); + 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--) { if (var.pos >= stix->c->mth.blk_tmprcnt[i - 1]) @@ -4485,7 +4485,7 @@ static int add_compiled_method (stix_t* stix) } else { - STIX_ASSERT (stix->c->mth.pftype == 4); + STIX_ASSERT (stix, stix->c->mth.pftype == 4); preamble_code = STIX_METHOD_PREAMBLE_ENSURE; preamble_index = 0; } @@ -4493,7 +4493,7 @@ static int add_compiled_method (stix_t* stix) if (stix->c->mth.variadic /*&& stix->c->mth.tmpr_nargs > 0*/) preamble_flags |= STIX_METHOD_PREAMBLE_FLAG_VARIADIC; - STIX_ASSERT (STIX_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(preamble_index)); + STIX_ASSERT (stix, STIX_OOI_IN_METHOD_PREAMBLE_INDEX_RANGE(preamble_index)); mth->owner = stix->c->cls.self_oop; mth->name = name; @@ -4625,8 +4625,8 @@ static int make_defined_class (stix_t* stix) { /* this is an internally created class object being defined. */ - STIX_ASSERT (STIX_CLASSOF(stix, stix->c->cls.self_oop) == stix->_class); - STIX_ASSERT (STIX_OBJ_GET_FLAGS_KERNEL (stix->c->cls.self_oop) == 1); + 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); if (spec != STIX_OOP_TO_SMOOI(stix->c->cls.self_oop->spec) || self_spec != STIX_OOP_TO_SMOOI(stix->c->cls.self_oop->selfspec)) @@ -4647,7 +4647,7 @@ static int make_defined_class (stix_t* stix) just_made = 1; stix->c->cls.self_oop = (stix_oop_class_t)tmp; - STIX_ASSERT (STIX_CLASSOF(stix, stix->c->cls.self_oop) == stix->_class); + STIX_ASSERT (stix, STIX_CLASSOF(stix, stix->c->cls.self_oop) == stix->_class); stix->c->cls.self_oop->spec = STIX_SMOOI_TO_OOP(spec); stix->c->cls.self_oop->selfspec = STIX_SMOOI_TO_OOP(self_spec); @@ -4818,7 +4818,7 @@ static int __compile_class_definition (stix_t* stix, int extend) if (extend) { /* extending class */ - STIX_ASSERT (stix->c->cls.flags == 0); + STIX_ASSERT (stix, stix->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); @@ -4842,7 +4842,7 @@ static int __compile_class_definition (stix_t* stix, int extend) stix->c->cls.super_oop = stix->c->cls.self_oop->superclass; - STIX_ASSERT ((stix_oop_t)stix->c->cls.super_oop == stix->_nil || + STIX_ASSERT (stix, (stix_oop_t)stix->c->cls.super_oop == stix->_nil || STIX_CLASSOF(stix, stix->c->cls.super_oop) == stix->_class); } else @@ -4921,7 +4921,7 @@ static int __compile_class_definition (stix_t* stix, int extend) { /* no class of such a name is found. it's a new definition, * which is normal for most new classes. */ - STIX_ASSERT (stix->c->cls.self_oop == STIX_NULL); + STIX_ASSERT (stix, stix->c->cls.self_oop == STIX_NULL); } if (super_is_nil) @@ -5023,7 +5023,7 @@ static int __compile_class_definition (stix_t* stix, int extend) { stix_ooch_t* ptr, * end; - STIX_ASSERT (STIX_CLASSOF(stix, pds) == stix->_string); + STIX_ASSERT (stix, STIX_CLASSOF(stix, pds) == stix->_string); ptr = pds->slot; end = pds->slot + STIX_OBJ_GET_SIZE(pds); @@ -5049,7 +5049,7 @@ static int __compile_class_definition (stix_t* stix, int extend) ptr++; } tok.len = ptr - tok.ptr; - STIX_ASSERT (tok.len > 0); + STIX_ASSERT (stix, tok.len > 0); if (dotted) { @@ -5127,7 +5127,7 @@ static int compile_class_definition (stix_t* stix, int extend) 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)); - STIX_ASSERT (STIX_COUNTOF(stix->c->cls.var_count) == STIX_COUNTOF(stix->c->cls.vars)); + 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++) { stix->c->cls.var_count[i] = 0; @@ -5246,7 +5246,7 @@ static int __compile_pooldic_definition (stix_t* stix) goto add_literal; case STIX_IOTOK_CHARLIT: - STIX_ASSERT (TOKEN_NAME_LEN(stix) == 1); + STIX_ASSERT (stix, TOKEN_NAME_LEN(stix) == 1); lit = STIX_CHAR_TO_OOP(TOKEN_NAME_PTR(stix)[0]); goto add_literal; @@ -5549,7 +5549,7 @@ int stix_compile (stix_t* stix, stix_ioimpl_t io) if (compile_stream (stix) <= -1) goto oops; /* close the stream */ - STIX_ASSERT (stix->c->curinp == &stix->c->arg); + STIX_ASSERT (stix, stix->c->curinp == &stix->c->arg); stix->c->impl (stix, STIX_IO_CLOSE, stix->c->curinp); return 0; @@ -5566,7 +5566,7 @@ oops: stix->c->impl (stix, STIX_IO_CLOSE, stix->c->curinp); prev = stix->c->curinp->includer; - STIX_ASSERT (stix->c->curinp->name != STIX_NULL); + STIX_ASSERT (stix, stix->c->curinp->name != STIX_NULL); STIX_MMGR_FREE (stix->mmgr, stix->c->curinp); stix->c->curinp = prev; } @@ -5577,6 +5577,6 @@ oops: void stix_getsynerr (stix_t* stix, stix_synerr_t* synerr) { - STIX_ASSERT (stix->c != STIX_NULL); + STIX_ASSERT (stix, stix->c != STIX_NULL); if (synerr) *synerr = stix->c->synerr; } diff --git a/stix/lib/decode.c b/stix/lib/decode.c index 0fca4d9..38d0916 100644 --- a/stix/lib/decode.c +++ b/stix/lib/decode.c @@ -481,8 +481,8 @@ return -1; LOG_INST_2 (stix, "make_block %zu %zu", b1, b2); - STIX_ASSERT (b1 >= 0); - STIX_ASSERT (b2 >= b1); + STIX_ASSERT (stix, b1 >= 0); + STIX_ASSERT (stix, b2 >= b1); break; case BCODE_SEND_BLOCK_COPY: diff --git a/stix/lib/dic.c b/stix/lib/dic.c index 650bfd0..708a9b5 100644 --- a/stix/lib/dic.c +++ b/stix/lib/dic.c @@ -71,10 +71,10 @@ static stix_oop_oop_t expand_bucket (stix_t* stix, stix_oop_oop_t oldbuc) ass = (stix_oop_association_t)oldbuc->slot[--oldsz]; if ((stix_oop_t)ass != stix->_nil) { - STIX_ASSERT (STIX_CLASSOF(stix,ass) == stix->_association); + STIX_ASSERT (stix, STIX_CLASSOF(stix,ass) == stix->_association); key = (stix_oop_char_t)ass->key; - STIX_ASSERT (STIX_CLASSOF(stix,key) == (stix_oop_t)stix->_symbol); + STIX_ASSERT (stix, STIX_CLASSOF(stix,key) == (stix_oop_t)stix->_symbol); index = stix_hashchars(key->slot, STIX_OBJ_GET_SIZE(key)) % newsz; while (newbuc->slot[index] != stix->_nil) index = (index + 1) % newsz; @@ -94,9 +94,9 @@ static stix_oop_association_t find_or_upsert (stix_t* stix, stix_oop_set_t dic, /* the system dictionary is not a generic dictionary. * it accepts only a symbol as a key. */ - STIX_ASSERT (STIX_CLASSOF(stix,key) == stix->_symbol); - STIX_ASSERT (STIX_CLASSOF(stix,dic->tally) == stix->_small_integer); - STIX_ASSERT (STIX_CLASSOF(stix,dic->bucket) == stix->_array); + 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); index = stix_hashchars(key->slot, STIX_OBJ_GET_SIZE(key)) % STIX_OBJ_GET_SIZE(dic->bucket); @@ -105,8 +105,8 @@ static stix_oop_association_t find_or_upsert (stix_t* stix, stix_oop_set_t dic, { ass = (stix_oop_association_t)dic->bucket->slot[index]; - STIX_ASSERT (STIX_CLASSOF(stix,ass) == stix->_association); - STIX_ASSERT (STIX_CLASSOF(stix,ass->key) == stix->_symbol); + STIX_ASSERT (stix, STIX_CLASSOF(stix,ass) == stix->_association); + STIX_ASSERT (stix, STIX_CLASSOF(stix,ass->key) == stix->_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))) @@ -128,7 +128,7 @@ static stix_oop_association_t find_or_upsert (stix_t* stix, stix_oop_set_t dic, } /* the key is not found. insert it. */ - STIX_ASSERT (STIX_OOP_IS_SMOOI(dic->tally)); + STIX_ASSERT (stix, STIX_OOP_IS_SMOOI(dic->tally)); tally = STIX_OOP_TO_SMOOI(dic->tally); if (tally >= STIX_SMOOI_MAX) { @@ -180,7 +180,7 @@ static stix_oop_association_t find_or_upsert (stix_t* stix, stix_oop_set_t dic, /* the current tally must be less than the maximum value. otherwise, * it overflows after increment below */ - STIX_ASSERT (tally < STIX_SMOOI_MAX); + STIX_ASSERT (stix, tally < STIX_SMOOI_MAX); dic->tally = STIX_SMOOI_TO_OOP(tally + 1); dic->bucket->slot[index] = (stix_oop_t)ass; @@ -200,8 +200,8 @@ static stix_oop_association_t lookup (stix_t* stix, stix_oop_set_t dic, const st stix_oow_t index; stix_oop_association_t ass; - STIX_ASSERT (STIX_CLASSOF(stix,dic->tally) == stix->_small_integer); - STIX_ASSERT (STIX_CLASSOF(stix,dic->bucket) == stix->_array); + STIX_ASSERT (stix, STIX_CLASSOF(stix,dic->tally) == stix->_small_integer); + STIX_ASSERT (stix, STIX_CLASSOF(stix,dic->bucket) == stix->_array); index = stix_hashchars(name->ptr, name->len) % STIX_OBJ_GET_SIZE(dic->bucket); @@ -209,8 +209,8 @@ static stix_oop_association_t lookup (stix_t* stix, stix_oop_set_t dic, const st { ass = (stix_oop_association_t)dic->bucket->slot[index]; - STIX_ASSERT (STIX_CLASSOF(stix,ass) == stix->_association); - STIX_ASSERT (STIX_CLASSOF(stix,ass->key) == stix->_symbol); + STIX_ASSERT (stix, STIX_CLASSOF(stix,ass) == stix->_association); + STIX_ASSERT (stix, STIX_CLASSOF(stix,ass->key) == stix->_symbol); if (name->len == STIX_OBJ_GET_SIZE(ass->key) && stix_equaloochars(name->ptr, ((stix_oop_char_t)ass->key)->slot, name->len)) @@ -228,13 +228,13 @@ static stix_oop_association_t lookup (stix_t* stix, stix_oop_set_t dic, const st stix_oop_association_t stix_putatsysdic (stix_t* stix, stix_oop_t key, stix_oop_t value) { - STIX_ASSERT (STIX_CLASSOF(stix,key) == stix->_symbol); + STIX_ASSERT (stix, STIX_CLASSOF(stix,key) == stix->_symbol); return find_or_upsert (stix, stix->sysdic, (stix_oop_char_t)key, value); } stix_oop_association_t stix_getatsysdic (stix_t* stix, stix_oop_t key) { - STIX_ASSERT (STIX_CLASSOF(stix,key) == stix->_symbol); + STIX_ASSERT (stix, STIX_CLASSOF(stix,key) == stix->_symbol); return find_or_upsert (stix, stix->sysdic, (stix_oop_char_t)key, STIX_NULL); } @@ -245,13 +245,13 @@ stix_oop_association_t stix_lookupsysdic (stix_t* stix, const stix_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) { - STIX_ASSERT (STIX_CLASSOF(stix,key) == stix->_symbol); + STIX_ASSERT (stix, STIX_CLASSOF(stix,key) == stix->_symbol); return find_or_upsert (stix, dic, (stix_oop_char_t)key, value); } stix_oop_association_t stix_getatdic (stix_t* stix, stix_oop_set_t dic, stix_oop_t key) { - STIX_ASSERT (STIX_CLASSOF(stix,key) == stix->_symbol); + STIX_ASSERT (stix, STIX_CLASSOF(stix,key) == stix->_symbol); return find_or_upsert (stix, dic, (stix_oop_char_t)key, STIX_NULL); } @@ -265,12 +265,12 @@ stix_oop_set_t stix_makedic (stix_t* stix, stix_oop_t cls, stix_oow_t size) stix_oop_set_t dic; stix_oop_t tmp; - STIX_ASSERT (STIX_CLASSOF(stix,cls) == stix->_class); + STIX_ASSERT (stix, STIX_CLASSOF(stix,cls) == stix->_class); dic = (stix_oop_set_t)stix_instantiate (stix, cls, STIX_NULL, 0); if (!dic) return STIX_NULL; - STIX_ASSERT (STIX_OBJ_GET_SIZE(dic) == STIX_SET_NAMED_INSTVARS); + STIX_ASSERT (stix, STIX_OBJ_GET_SIZE(dic) == STIX_SET_NAMED_INSTVARS); stix_pushtmp (stix, (stix_oop_t*)&dic); tmp = stix_instantiate (stix, stix->_array, STIX_NULL, size); @@ -280,8 +280,8 @@ stix_oop_set_t stix_makedic (stix_t* stix, stix_oop_t cls, stix_oow_t size) dic->tally = STIX_SMOOI_TO_OOP(0); dic->bucket = (stix_oop_oop_t)tmp; - STIX_ASSERT (STIX_OBJ_GET_SIZE(dic) == STIX_SET_NAMED_INSTVARS); - STIX_ASSERT (STIX_OBJ_GET_SIZE(dic->bucket) == size); + STIX_ASSERT (stix, STIX_OBJ_GET_SIZE(dic) == STIX_SET_NAMED_INSTVARS); + STIX_ASSERT (stix, STIX_OBJ_GET_SIZE(dic->bucket) == size); return dic; } diff --git a/stix/lib/exec.c b/stix/lib/exec.c index d1073c7..b67b56c 100644 --- a/stix/lib/exec.c +++ b/stix/lib/exec.c @@ -289,7 +289,7 @@ static stix_oop_process_t make_process (stix_t* stix, stix_oop_context_t c) proc->current_context = c; proc->sp = STIX_SMOOI_TO_OOP(-1); - STIX_ASSERT ((stix_oop_t)c->sender == stix->_nil); + STIX_ASSERT (stix, (stix_oop_t)c->sender == stix->_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)); @@ -307,7 +307,7 @@ static STIX_INLINE void sleep_active_process (stix_t* stix, int state) /* store the current active context to the current process. * it is the suspended context of the process to be suspended */ - STIX_ASSERT (stix->processor->active != stix->nil_process); + 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); } @@ -331,10 +331,10 @@ static STIX_INLINE void wake_new_process (stix_t* stix, stix_oop_process_t proc) static void switch_to_process (stix_t* stix, stix_oop_process_t proc, int new_state_for_old_active) { /* the new process must not be the currently active process */ - STIX_ASSERT (stix->processor->active != proc); + STIX_ASSERT (stix, stix->processor->active != proc); /* the new process must be in the runnable state */ - STIX_ASSERT (proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_RUNNABLE) || + STIX_ASSERT (stix, proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_RUNNABLE) || proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_WAITING)); sleep_active_process (stix, new_state_for_old_active); @@ -347,7 +347,7 @@ static STIX_INLINE stix_oop_process_t find_next_runnable_process (stix_t* stix) { stix_oop_process_t npr; - STIX_ASSERT (stix->processor->active->state == STIX_SMOOI_TO_OOP(PROC_STATE_RUNNING)); + 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; return npr; @@ -367,14 +367,14 @@ static STIX_INLINE int chain_into_processor (stix_t* stix, stix_oop_process_t pr * link it to the processor's process list. */ stix_ooi_t tally; - STIX_ASSERT ((stix_oop_t)proc->prev == stix->_nil); - STIX_ASSERT ((stix_oop_t)proc->next == stix->_nil); + STIX_ASSERT (stix, (stix_oop_t)proc->prev == stix->_nil); + STIX_ASSERT (stix, (stix_oop_t)proc->next == stix->_nil); - STIX_ASSERT (proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_SUSPENDED)); + STIX_ASSERT (stix, proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_SUSPENDED)); tally = STIX_OOP_TO_SMOOI(stix->processor->tally); - STIX_ASSERT (tally >= 0); + STIX_ASSERT (stix, tally >= 0); if (tally >= STIX_SMOOI_MAX) { #if defined(STIX_DEBUG_VM_PROCESSOR) @@ -408,11 +408,11 @@ static STIX_INLINE void unchain_from_processor (stix_t* stix, stix_oop_process_t /* the processor's process chain must be composed of running/runnable * processes only */ - STIX_ASSERT (proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_RUNNING) || + STIX_ASSERT (stix, proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_RUNNING) || proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_RUNNABLE)); tally = STIX_OOP_TO_SMOOI(stix->processor->tally); - STIX_ASSERT (tally > 0); + STIX_ASSERT (stix, tally > 0); if ((stix_oop_t)proc->prev != stix->_nil) proc->prev->next = proc->next; else stix->processor->runnable_head = proc->next; @@ -432,13 +432,13 @@ static STIX_INLINE void chain_into_semaphore (stix_t* stix, stix_oop_process_t p { /* append a process to the process list of a semaphore*/ - STIX_ASSERT ((stix_oop_t)proc->sem == stix->_nil); - STIX_ASSERT ((stix_oop_t)proc->prev == stix->_nil); - STIX_ASSERT ((stix_oop_t)proc->next == stix->_nil); + 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); if ((stix_oop_t)sem->waiting_head == stix->_nil) { - STIX_ASSERT ((stix_oop_t)sem->waiting_tail == stix->_nil); + STIX_ASSERT (stix, (stix_oop_t)sem->waiting_tail == stix->_nil); sem->waiting_head = proc; } else @@ -455,7 +455,7 @@ static STIX_INLINE void unchain_from_semaphore (stix_t* stix, stix_oop_process_t { stix_oop_semaphore_t sem; - STIX_ASSERT ((stix_oop_t)proc->sem != stix->_nil); + STIX_ASSERT (stix, (stix_oop_t)proc->sem != stix->_nil); sem = proc->sem; if ((stix_oop_t)proc->prev != stix->_nil) proc->prev->next = proc->next; @@ -492,12 +492,12 @@ static void terminate_process (stix_t* stix, stix_oop_process_t proc) /* a runnable or running process must not be chanined to the * process list of a semaphore */ - STIX_ASSERT ((stix_oop_t)proc->sem == stix->_nil); + STIX_ASSERT (stix, (stix_oop_t)proc->sem == stix->_nil); if (nrp == proc) { /* no runnable process after termination */ - STIX_ASSERT (stix->processor->active == stix->nil_process); + 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"); } else @@ -538,8 +538,8 @@ static void resume_process (stix_t* stix, stix_oop_process_t proc) if (proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_SUSPENDED)) { /* SUSPENED ---> RUNNING */ - STIX_ASSERT ((stix_oop_t)proc->prev == stix->_nil); - STIX_ASSERT ((stix_oop_t)proc->next == stix->_nil); + STIX_ASSERT (stix, (stix_oop_t)proc->prev == stix->_nil); + STIX_ASSERT (stix, (stix_oop_t)proc->next == stix->_nil); #if defined(STIX_DEBUG_VM_PROCESSOR) STIX_LOG1 (stix, STIX_LOG_IC | STIX_LOG_DEBUG, "Processor - process %O SUSPENDED->RUNNING\n", proc); @@ -557,7 +557,7 @@ static void resume_process (stix_t* stix, stix_oop_process_t proc) { /* RUNNABLE ---> RUNNING */ /* TODO: should i allow this? */ - STIX_ASSERT (stix->processor->active != proc); + STIX_ASSERT (stix, stix->processor->active != proc); switch_to_process (stix, proc, PROC_STATE_RUNNABLE); } #endif @@ -589,7 +589,7 @@ static void suspend_process (stix_t* stix, stix_oop_process_t proc) /* 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->processor->active == stix->nil_process); + STIX_ASSERT (stix, stix->processor->active == stix->nil_process); } else { @@ -600,7 +600,7 @@ static void suspend_process (stix_t* stix, stix_oop_process_t proc) * 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->processor->active != stix->nil_process); + STIX_ASSERT (stix, stix->processor->active != stix->nil_process); switch_to_process (stix, nrp, PROC_STATE_SUSPENDED); } } @@ -619,7 +619,7 @@ static void yield_process (stix_t* stix, stix_oop_process_t proc) stix_oop_process_t nrp; - STIX_ASSERT (proc == stix->processor->active); + STIX_ASSERT (stix, proc == stix->processor->active); nrp = find_next_runnable_process (stix); /* if there are more than 1 runnable processes, the next @@ -712,9 +712,9 @@ static void await_semaphore (stix_t* stix, stix_oop_semaphore_t sem) /* link the suspended process to the semaphore's process list */ chain_into_semaphore (stix, proc, sem); - STIX_ASSERT (sem->waiting_tail == proc); + STIX_ASSERT (stix, sem->waiting_tail == proc); - STIX_ASSERT (stix->processor->active != proc); + STIX_ASSERT (stix, stix->processor->active != proc); } } @@ -815,7 +815,7 @@ static int add_to_sem_heap (stix_t* stix, stix_oop_semaphore_t sem) stix->sem_heap_capa = new_capa; } - STIX_ASSERT (stix->sem_heap_count <= STIX_SMOOI_MAX); + STIX_ASSERT (stix, stix->sem_heap_count <= STIX_SMOOI_MAX); index = stix->sem_heap_count; stix->sem_heap[index] = sem; @@ -869,8 +869,8 @@ static stix_oop_process_t start_initial_process (stix_t* stix, stix_oop_context_ stix_oop_process_t proc; /* there must be no active process when this function is called */ - STIX_ASSERT (stix->processor->tally == STIX_SMOOI_TO_OOP(0)); - STIX_ASSERT (stix->processor->active == stix->nil_process); + STIX_ASSERT (stix, stix->processor->tally == STIX_SMOOI_TO_OOP(0)); + STIX_ASSERT (stix, stix->processor->active == stix->nil_process); proc = make_process (stix, c); if (!proc) return STIX_NULL; @@ -880,8 +880,8 @@ static stix_oop_process_t start_initial_process (stix_t* stix, stix_oop_context_ stix->processor->active = proc; /* do somthing that resume_process() would do with less overhead */ - STIX_ASSERT ((stix_oop_t)proc->current_context != stix->_nil); - STIX_ASSERT (proc->current_context == proc->initial_context); + 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); return proc; @@ -896,14 +896,14 @@ static STIX_INLINE int activate_new_method (stix_t* stix, stix_oop_method_t mth, ntmprs = STIX_OOP_TO_SMOOI(mth->tmpr_count); nargs = STIX_OOP_TO_SMOOI(mth->tmpr_nargs); - STIX_ASSERT (ntmprs >= 0); - STIX_ASSERT (nargs <= ntmprs); + STIX_ASSERT (stix, ntmprs >= 0); + STIX_ASSERT (stix, 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_METHOD_GET_PREAMBLE_FLAGS(STIX_OOP_TO_SMOOI(mth->preamble)) & STIX_METHOD_PREAMBLE_FLAG_VARIADIC); + STIX_ASSERT (stix, STIX_METHOD_GET_PREAMBLE_FLAGS(STIX_OOP_TO_SMOOI(mth->preamble)) & STIX_METHOD_PREAMBLE_FLAG_VARIADIC); actual_ntmprs = ntmprs + (actual_nargs - nargs); } else actual_ntmprs = ntmprs; @@ -971,7 +971,7 @@ static STIX_INLINE int activate_new_method (stix_t* stix, stix_oop_method_t mth, ctx->slot[--j] = STIX_STACK_GETTOP (stix); STIX_STACK_POP (stix); } - STIX_ASSERT (i == nargs); + STIX_ASSERT (stix, i == nargs); while (i > 0) { /* place normal argument before local temporaries */ @@ -992,7 +992,7 @@ static STIX_INLINE int activate_new_method (stix_t* stix, stix_oop_method_t mth, ctx->receiver_or_source = STIX_STACK_GETTOP (stix); STIX_STACK_POP (stix); - STIX_ASSERT (stix->sp >= -1); + STIX_ASSERT (stix, stix->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 @@ -1029,18 +1029,18 @@ static stix_oop_method_t find_method (stix_t* stix, stix_oop_t receiver, const s dic_no = STIX_METHOD_INSTANCE; } - STIX_ASSERT (c != stix->_nil); + STIX_ASSERT (stix, c != stix->_nil); if (super) { /* stix_oop_method_t m; - STIX_ASSERT (STIX_CLASSOF(stix, stix->active_context->origin) == stix->_method_context); + 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; */ - STIX_ASSERT (stix->active_method); - STIX_ASSERT (stix->active_method->owner); + 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 */ } @@ -1048,14 +1048,14 @@ static stix_oop_method_t find_method (stix_t* stix, stix_oop_t receiver, const s do { mthdic = ((stix_oop_class_t)c)->mthdic[dic_no]; - STIX_ASSERT ((stix_oop_t)mthdic != stix->_nil); - STIX_ASSERT (STIX_CLASSOF(stix, mthdic) == stix->_method_dictionary); + STIX_ASSERT (stix, (stix_oop_t)mthdic != stix->_nil); + STIX_ASSERT (stix, STIX_CLASSOF(stix, mthdic) == stix->_method_dictionary); ass = (stix_oop_association_t)stix_lookupdic (stix, mthdic, message); if (ass) { /* found the method */ - STIX_ASSERT (STIX_CLASSOF(stix, ass->value) == stix->_method); + STIX_ASSERT (stix, STIX_CLASSOF(stix, ass->value) == stix->_method); return (stix_oop_method_t)ass->value; } c = ((stix_oop_class_t)c)->superclass; @@ -1068,13 +1068,13 @@ not_found: /* 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_oop_t)mthdic != stix->_nil); - STIX_ASSERT (STIX_CLASSOF(stix, mthdic) == stix->_method_dictionary); + STIX_ASSERT (stix, (stix_oop_t)mthdic != stix->_nil); + STIX_ASSERT (stix, STIX_CLASSOF(stix, mthdic) == stix->_method_dictionary); ass = (stix_oop_association_t)stix_lookupdic (stix, mthdic, message); if (ass) { - STIX_ASSERT (STIX_CLASSOF(stix, ass->value) == stix->_method); + STIX_ASSERT (stix, STIX_CLASSOF(stix, ass->value) == stix->_method); return (stix_oop_method_t)ass->value; } } @@ -1137,14 +1137,14 @@ TODO: overcome this problem * 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->active_context == STIX_NULL); - STIX_ASSERT (stix->active_method == STIX_NULL); + STIX_ASSERT (stix, stix->active_context == STIX_NULL); + STIX_ASSERT (stix, stix->active_method == STIX_NULL); /* stix_gc() uses stix->processor when stix->active_context * is not NULL. at this poinst, stix->processor should point to * an instance of ProcessScheduler. */ - STIX_ASSERT ((stix_oop_t)stix->processor != stix->_nil); - STIX_ASSERT (stix->processor->tally == STIX_SMOOI_TO_OOP(0)); + STIX_ASSERT (stix, (stix_oop_t)stix->processor != stix->_nil); + STIX_ASSERT (stix, stix->processor->tally == STIX_SMOOI_TO_OOP(0)); /* start_initial_process() calls the SWITCH_ACTIVE_CONTEXT() macro. * the macro assumes a non-null value in stix->active_context. @@ -1161,10 +1161,10 @@ TODO: overcome this problem 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); - STIX_ASSERT (stix->processor->active->initial_context == ctx); - STIX_ASSERT (stix->processor->active->current_context == ctx); - STIX_ASSERT (stix->active_context == ctx); + 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); /* emulate the message sending */ return activate_new_method (stix, mth, 0); @@ -1175,7 +1175,7 @@ static int pf_dump (stix_t* stix, stix_ooi_t nargs) { stix_ooi_t i; - STIX_ASSERT (nargs >= 0); + STIX_ASSERT (stix, nargs >= 0); stix_logbfmt (stix, 0, "RECEIVER: %O\n", STIX_STACK_GET(stix, stix->sp - nargs)); for (i = nargs; i > 0; ) @@ -1194,7 +1194,7 @@ static void log_char_object (stix_t* stix, stix_oow_t mask, stix_oop_char_t msg) stix_oow_t rem; const stix_ooch_t* ptr; - STIX_ASSERT (STIX_OBJ_GET_FLAGS_TYPE(msg) == STIX_OBJ_TYPE_CHAR); + STIX_ASSERT (stix, STIX_OBJ_GET_FLAGS_TYPE(msg) == STIX_OBJ_TYPE_CHAR); rem = STIX_OBJ_GET_SIZE(msg); ptr = msg->slot; @@ -1205,7 +1205,7 @@ start_over: if (*ptr == '\0') { n = stix_logbfmt (stix, mask, "%C", *ptr); - STIX_ASSERT (n == 1); + STIX_ASSERT (stix, n == 1); rem -= n; ptr += n; goto start_over; @@ -1219,7 +1219,7 @@ start_over: * actually, this check is not needed because of '\0' skipping * at the beginning of the loop */ n = stix_logbfmt (stix, mask, "%C", *ptr); - STIX_ASSERT (n == 1); + STIX_ASSERT (stix, n == 1); } rem -= n; ptr += n; @@ -1232,7 +1232,7 @@ static int pf_log (stix_t* stix, stix_ooi_t nargs) stix_oow_t mask; stix_ooi_t k; - STIX_ASSERT (nargs >= 2); + STIX_ASSERT (stix, nargs >= 2); level = STIX_STACK_GETARG(stix, nargs, 0); if (!STIX_OOP_IS_SMOOI(level)) mask = STIX_LOG_APP | STIX_LOG_INFO; @@ -1296,7 +1296,7 @@ static int pf_identical (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, b; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -1311,7 +1311,7 @@ static int pf_not_identical (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, b; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -1326,7 +1326,7 @@ static int pf_class (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, c; - STIX_ASSERT (nargs == 0); + STIX_ASSERT (stix, nargs == 0); rcv = STIX_STACK_GETRCV(stix, nargs); c = STIX_CLASSOF(stix, rcv); @@ -1339,7 +1339,7 @@ static int pf_basic_new (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, obj; - STIX_ASSERT (nargs == 0); + STIX_ASSERT (stix, nargs == 0); rcv = STIX_STACK_GETRCV (stix, nargs); if (STIX_CLASSOF(stix, rcv) != stix->_class) @@ -1360,7 +1360,7 @@ static int pf_basic_new_with_size (stix_t* stix, stix_ooi_t nargs) stix_oop_t rcv, szoop, obj; stix_oow_t size; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); if (STIX_CLASSOF(stix, rcv) != stix->_class) @@ -1414,7 +1414,7 @@ static int pf_ngc_dispose (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv; - STIX_ASSERT (nargs == 0); + STIX_ASSERT (stix, nargs == 0); rcv = STIX_STACK_GETRCV (stix, nargs); stix_freemem (stix, rcv); @@ -1427,7 +1427,7 @@ static int pf_shallow_copy (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, obj; - STIX_ASSERT (nargs == 0); + STIX_ASSERT (stix, nargs == 0); rcv = STIX_STACK_GETRCV (stix, nargs); @@ -1445,7 +1445,7 @@ static int pf_basic_size (stix_t* stix, stix_ooi_t nargs) stix_oop_t rcv, sz; - STIX_ASSERT (nargs == 0); + STIX_ASSERT (stix, nargs == 0); rcv = STIX_STACK_GETRCV (stix, nargs); @@ -1468,7 +1468,7 @@ static int pf_basic_at (stix_t* stix, stix_ooi_t nargs) stix_oop_t rcv, pos, v; stix_oow_t idx; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); if (!STIX_OOP_IS_POINTER(rcv)) @@ -1527,7 +1527,7 @@ static int pf_basic_at_put (stix_t* stix, stix_ooi_t nargs) stix_oop_t rcv, pos, val; stix_oow_t idx; - STIX_ASSERT (nargs == 2); + STIX_ASSERT (stix, nargs == 2); rcv = STIX_STACK_GETRCV(stix, nargs); if (!STIX_OOP_IS_POINTER(rcv)) @@ -1623,7 +1623,7 @@ static int pf_context_goto (stix_t* stix, stix_ooi_t nargs) * return value. it's useful when you want to change the instruction * pointer while maintaining the stack level before the call */ - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); if (STIX_CLASSOF(stix, rcv) != stix->_method_context) @@ -1644,7 +1644,7 @@ static int pf_context_goto (stix_t* stix, stix_ooi_t nargs) ((stix_oop_context_t)rcv)->ip = pc; LOAD_ACTIVE_IP (stix); - STIX_ASSERT (nargs + 1 == 2); + STIX_ASSERT (stix, nargs + 1 == 2); STIX_STACK_POPS (stix, 2); /* pop both the argument and the receiver */ return 1; } @@ -1673,19 +1673,19 @@ static int __block_value (stix_t* stix, stix_oop_context_t rcv_blkctx, stix_ooi_ */ /* the receiver must be a block context */ - STIX_ASSERT (STIX_CLASSOF(stix, rcv_blkctx) == stix->_block_context); + STIX_ASSERT (stix, STIX_CLASSOF(stix, rcv_blkctx) == stix->_block_context); if (rcv_blkctx->receiver_or_source != stix->_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_OBJ_GET_SIZE(rcv_blkctx) > STIX_CONTEXT_NAMED_INSTVARS); + STIX_ASSERT (stix, STIX_OBJ_GET_SIZE(rcv_blkctx) > STIX_CONTEXT_NAMED_INSTVARS); STIX_LOG2 (stix, STIX_LOG_PRIMITIVE | STIX_LOG_ERROR, "Error(%hs) - re-valuing of a block context - %O\n", __PRIMITIVE_NAME__, rcv_blkctx); return 0; } - STIX_ASSERT (STIX_OBJ_GET_SIZE(rcv_blkctx) == STIX_CONTEXT_NAMED_INSTVARS); + STIX_ASSERT (stix, STIX_OBJ_GET_SIZE(rcv_blkctx) == STIX_CONTEXT_NAMED_INSTVARS); if (STIX_OOP_TO_SMOOI(rcv_blkctx->method_or_nargs) != actual_arg_count /* nargs */) { @@ -1700,7 +1700,7 @@ static int __block_value (stix_t* stix, stix_oop_context_t rcv_blkctx, stix_ooi_ * 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 (local_ntmprs >= actual_arg_count); + STIX_ASSERT (stix, local_ntmprs >= actual_arg_count); /* create a new block context to clone rcv_blkctx */ stix_pushtmp (stix, (stix_oop_t*)&rcv_blkctx); @@ -1729,10 +1729,10 @@ static int __block_value (stix_t* stix, stix_oop_context_t rcv_blkctx, stix_ooi_ /* 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 (nargs == 1); + STIX_ASSERT (stix, nargs == 1); 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); + STIX_ASSERT (stix, STIX_ISTYPEOF(stix,xarg,STIX_OBJ_TYPE_OOP)); + STIX_ASSERT (stix, STIX_OBJ_GET_SIZE(xarg) == num_first_arg_elems); for (i = 0; i < num_first_arg_elems; i++) { blkctx->slot[i] = xarg->slot[i]; @@ -1748,7 +1748,7 @@ static int __block_value (stix_t* stix, stix_oop_context_t rcv_blkctx, stix_ooi_ } STIX_STACK_POPS (stix, nargs + 1); /* pop arguments and receiver */ - STIX_ASSERT (blkctx->home != stix->_nil); + STIX_ASSERT (stix, blkctx->home != stix->_nil); blkctx->sp = STIX_SMOOI_TO_OOP(-1); /* not important at all */ blkctx->sender = stix->active_context; @@ -1844,7 +1844,7 @@ static int pf_block_new_process (stix_t* stix, stix_ooi_t nargs) static int pf_process_resume (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv; - STIX_ASSERT (nargs == 0); + STIX_ASSERT (stix, nargs == 0); rcv = STIX_STACK_GETRCV(stix, nargs); if (STIX_CLASSOF(stix,rcv) != stix->_process) return 0; @@ -1858,7 +1858,7 @@ static int pf_process_resume (stix_t* stix, stix_ooi_t nargs) static int pf_process_terminate (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv; - STIX_ASSERT (nargs == 0); + STIX_ASSERT (stix, 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 */ @@ -1874,7 +1874,7 @@ static int pf_process_terminate (stix_t* stix, stix_ooi_t nargs) static int pf_process_yield (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv; - STIX_ASSERT (nargs == 0); + STIX_ASSERT (stix, nargs == 0); rcv = STIX_STACK_GETRCV(stix, nargs); if (STIX_CLASSOF(stix,rcv) != stix->_process) return 0; @@ -1888,7 +1888,7 @@ static int pf_process_yield (stix_t* stix, stix_ooi_t nargs) static int pf_process_suspend (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv; - STIX_ASSERT (nargs == 0); + STIX_ASSERT (stix, nargs == 0); rcv = STIX_STACK_GETRCV(stix, nargs); if (STIX_CLASSOF(stix,rcv) != stix->_process) return 0; @@ -1902,7 +1902,7 @@ static int pf_process_suspend (stix_t* stix, stix_ooi_t nargs) static int pf_semaphore_signal (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv; - STIX_ASSERT (nargs == 0); + STIX_ASSERT (stix, nargs == 0); rcv = STIX_STACK_GETRCV(stix, nargs); if (STIX_CLASSOF(stix,rcv) != stix->_semaphore) return 0; @@ -1916,7 +1916,7 @@ static int pf_semaphore_signal (stix_t* stix, stix_ooi_t nargs) static int pf_semaphore_wait (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv; - STIX_ASSERT (nargs == 0); + STIX_ASSERT (stix, nargs == 0); rcv = STIX_STACK_GETRCV(stix, nargs); if (STIX_CLASSOF(stix,rcv) != stix->_semaphore) return 0; @@ -1931,7 +1931,7 @@ static int pf_processor_schedule (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -1951,7 +1951,7 @@ static int pf_processor_add_timed_semaphore (stix_t* stix, stix_ooi_t nargs) stix_oop_semaphore_t sem; stix_ntime_t now, ft; - STIX_ASSERT (nargs >= 2 || nargs <= 3); + STIX_ASSERT (stix, nargs >= 2 || nargs <= 3); if (nargs == 3) { @@ -1972,7 +1972,7 @@ static int pf_processor_add_timed_semaphore (stix_t* stix, stix_ooi_t nargs) sem->heap_index != STIX_SMOOI_TO_OOP(-1)) { delete_from_sem_heap (stix, STIX_OOP_TO_SMOOI(sem->heap_index)); - STIX_ASSERT(sem->heap_index == STIX_SMOOI_TO_OOP(-1)); + STIX_ASSERT (stix, sem->heap_index == STIX_SMOOI_TO_OOP(-1)); /* Is this more desired??? @@ -2013,7 +2013,7 @@ static int pf_processor_remove_semaphore (stix_t* stix, stix_ooi_t nargs) stix_oop_t rcv; stix_oop_semaphore_t sem; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); sem = (stix_oop_semaphore_t)STIX_STACK_GETARG(stix, nargs, 0); rcv = STIX_STACK_GETRCV(stix, nargs); @@ -2029,7 +2029,7 @@ static int pf_processor_remove_semaphore (stix_t* stix, stix_ooi_t nargs) { /* the semaphore is in the timed semaphore heap */ delete_from_sem_heap (stix, STIX_OOP_TO_SMOOI(sem->heap_index)); - STIX_ASSERT(sem->heap_index == STIX_SMOOI_TO_OOP(-1)); + STIX_ASSERT (stix, sem->heap_index == STIX_SMOOI_TO_OOP(-1)); } STIX_STACK_SETRETTORCV (stix, nargs); /* ^self */ @@ -2040,7 +2040,7 @@ static int pf_processor_return_to (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, ret, ctx; - STIX_ASSERT (nargs == 2); + STIX_ASSERT (stix, nargs == 2); rcv = STIX_STACK_GETRCV(stix, nargs); ret = STIX_STACK_GETARG(stix, nargs, 0); @@ -2070,7 +2070,7 @@ static int pf_integer_add (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -2086,7 +2086,7 @@ static int pf_integer_sub (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -2102,7 +2102,7 @@ static int pf_integer_mul (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -2118,7 +2118,7 @@ static int pf_integer_quo (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, quo; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -2135,7 +2135,7 @@ static int pf_integer_rem (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, quo, rem; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -2152,7 +2152,7 @@ static int pf_integer_quo2 (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, quo; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -2169,7 +2169,7 @@ static int pf_integer_rem2 (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, quo, rem; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -2186,7 +2186,7 @@ static int pf_integer_negated (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, res; - STIX_ASSERT (nargs == 0); + STIX_ASSERT (stix, nargs == 0); rcv = STIX_STACK_GETRCV(stix, nargs); @@ -2201,7 +2201,7 @@ static int pf_integer_bitat (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -2217,7 +2217,7 @@ static int pf_integer_bitand (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -2233,7 +2233,7 @@ static int pf_integer_bitor (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -2249,7 +2249,7 @@ static int pf_integer_bitxor (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -2265,7 +2265,7 @@ static int pf_integer_bitinv (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, res; - STIX_ASSERT (nargs == 0); + STIX_ASSERT (stix, nargs == 0); rcv = STIX_STACK_GETRCV(stix, nargs); @@ -2280,7 +2280,7 @@ static int pf_integer_bitshift (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -2296,7 +2296,7 @@ static int pf_integer_eq (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -2312,7 +2312,7 @@ static int pf_integer_ne (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -2328,7 +2328,7 @@ static int pf_integer_lt (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -2344,7 +2344,7 @@ static int pf_integer_gt (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -2360,7 +2360,7 @@ static int pf_integer_le (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -2376,7 +2376,7 @@ static int pf_integer_ge (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg, res; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -2393,7 +2393,7 @@ static int pf_integer_inttostr (stix_t* stix, stix_ooi_t nargs) stix_oop_t rcv, arg, str; stix_ooi_t radix; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -2409,12 +2409,32 @@ static int pf_integer_inttostr (stix_t* stix, stix_ooi_t nargs) return 1; } +static int pf_error_as_string (stix_t* stix, stix_ooi_t nargs) +{ + stix_oop_t rcv, str; + + STIX_ASSERT (stix, nargs == 0); + + rcv = STIX_STACK_GETRCV(stix, nargs); + if (!STIX_OOP_IS_ERROR(rcv)) return 0; + + //str = stix_makestring (stix, xxx, xxx); + STIX_STACK_SETRET (stix, nargs, str); + return 1; +} + +static int pf_error_text (stix_t* stix, stix_ooi_t nargs) +{ + + return -1; +} + static int pf_ffi_open (stix_t* stix, stix_ooi_t nargs) { stix_oop_t rcv, arg; void* handle; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -2452,7 +2472,7 @@ static int pf_ffi_close (stix_t* stix, stix_ooi_t nargs) stix_oop_t rcv, arg; void* handle; - STIX_ASSERT (nargs == 1); + STIX_ASSERT (stix, nargs == 1); rcv = STIX_STACK_GETRCV(stix, nargs); arg = STIX_STACK_GETARG(stix, nargs, 0); @@ -2476,7 +2496,7 @@ static int pf_ffi_call (stix_t* stix, stix_ooi_t nargs) #if defined(USE_DYNCALL) stix_oop_t rcv, fun, sig, args; - STIX_ASSERT (nargs == 3); + STIX_ASSERT (stix, nargs == 3); rcv = STIX_STACK_GET(stix, stix->sp - 3); fun = STIX_STACK_GET(stix, stix->sp - 2); @@ -2656,7 +2676,7 @@ static int pf_ffi_getsym (stix_t* stix, stix_ooi_t nargs) stix_oop_t rcv, hnd, fun; void* sym; - STIX_ASSERT (nargs == 2); + STIX_ASSERT (stix, nargs == 2); rcv = STIX_STACK_GET(stix, stix->sp - 2); fun = STIX_STACK_GET(stix, stix->sp - 1); @@ -2760,6 +2780,9 @@ static pf_t pftab[] = { 1, 1, pf_integer_ge, "_integer_ge" }, { 1, 1, pf_integer_inttostr, "_integer_inttostr" }, + { 0, 0, pf_error_as_string, "_error_as_string" }, + { 0, 0, pf_error_text, "_error_text" }, + { 1, 1, pf_ffi_open, "_ffi_open" }, { 1, 1, pf_ffi_close, "_ffi_close" }, { 2, 2, pf_ffi_getsym, "_ffi_getsym" }, @@ -2794,7 +2817,6 @@ static int start_method (stix_t* stix, stix_oop_method_t method, stix_oow_t narg preamble = STIX_OOP_TO_SMOOI(method->preamble); - /*STIX_ASSERT (STIX_OOP_TO_SMOOI(method->tmpr_nargs) == nargs);*/ if (nargs != STIX_OOP_TO_SMOOI(method->tmpr_nargs)) { @@ -2862,8 +2884,8 @@ static int start_method (stix_t* stix, stix_oop_method_t method, stix_oow_t narg /* replace the receiver by an instance variable of the receiver */ 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)); + 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)); if (rcv == (stix_oop_oop_t)stix->active_context) { @@ -2930,12 +2952,12 @@ static int start_method (stix_t* stix, stix_oop_method_t method, stix_oow_t narg if (handler) goto exec_handler; else { - STIX_ASSERT (pf_name_index >= 0); + STIX_ASSERT (stix, pf_name_index >= 0); name = method->slot[pf_name_index]; - STIX_ASSERT (STIX_ISTYPEOF(stix,name,STIX_OBJ_TYPE_CHAR)); - STIX_ASSERT (STIX_OBJ_GET_FLAGS_EXTRA(name)); - STIX_ASSERT (STIX_CLASSOF(stix,name) == stix->_symbol); + 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); handler = stix_querymod (stix, ((stix_oop_char_t)name)->slot, STIX_OBJ_GET_SIZE(name)); } @@ -2977,7 +2999,7 @@ static int start_method (stix_t* stix, stix_oop_method_t method, stix_oow_t narg } #if defined(STIX_USE_OBJECT_TRAILER) - STIX_ASSERT (STIX_OBJ_GET_FLAGS_TRAILER(method)); + 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 */ #else if (method->code == stix->_nil) @@ -2999,7 +3021,7 @@ static int start_method (stix_t* stix, stix_oop_method_t method, stix_oow_t narg } default: - STIX_ASSERT (preamble_code == STIX_METHOD_PREAMBLE_NONE || + 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; @@ -3015,9 +3037,9 @@ static int send_message (stix_t* stix, stix_oop_char_t selector, int to_super, s stix_oop_t receiver; stix_oop_method_t method; - STIX_ASSERT (STIX_OOP_IS_POINTER(selector)); - STIX_ASSERT (STIX_OBJ_GET_FLAGS_TYPE(selector) == STIX_OBJ_TYPE_CHAR); - STIX_ASSERT (STIX_CLASSOF(stix, selector) == stix->_symbol); + 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); receiver = STIX_STACK_GET(stix, stix->sp - nargs); @@ -3102,7 +3124,7 @@ int stix_execute (stix_t* stix) stix_ooi_t fetched_instruction_pointer; #endif - STIX_ASSERT (stix->active_context != STIX_NULL); + STIX_ASSERT (stix, stix->active_context != STIX_NULL); vm_startup (stix); stix->proc_switched = 0; @@ -3116,8 +3138,8 @@ int stix_execute (stix_t* stix) do { - STIX_ASSERT (STIX_OOP_IS_SMOOI(stix->sem_heap[0]->heap_ftime_sec)); - STIX_ASSERT (STIX_OOP_IS_SMOOI(stix->sem_heap[0]->heap_ftime_nsec)); + 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)); STIX_INITNTIME (&ft, STIX_OOP_TO_SMOOI(stix->sem_heap[0]->heap_ftime_sec), @@ -3146,8 +3168,8 @@ int stix_execute (stix_t* stix) * it uses wake_new_process() instead of * switch_to_process() as there is no running * process at this moment */ - STIX_ASSERT (proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_RUNNABLE)); - STIX_ASSERT (proc == stix->processor->runnable_head); + STIX_ASSERT (stix, proc->state == STIX_SMOOI_TO_OOP(PROC_STATE_RUNNABLE)); + STIX_ASSERT (stix, proc == stix->processor->runnable_head); wake_new_process (stix, proc); stix->proc_switched = 1; @@ -3170,7 +3192,7 @@ int stix_execute (stix_t* stix) if (stix->processor->active == stix->nil_process) { /* no more waiting semaphore and no more process */ - STIX_ASSERT (stix->processor->tally = STIX_SMOOI_TO_OOP(0)); + 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"); #if 0 @@ -3233,7 +3255,7 @@ int stix_execute (stix_t* stix) b1 = bcode & 0x7; /* low 3 bits */ push_instvar: LOG_INST_1 (stix, "push_instvar %zu", b1); - STIX_ASSERT (STIX_OBJ_GET_FLAGS_TYPE(stix->active_context->origin->receiver_or_source) == STIX_OBJ_TYPE_OOP); + 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]); break; @@ -3253,7 +3275,7 @@ int stix_execute (stix_t* stix) b1 = bcode & 0x7; /* low 3 bits */ store_instvar: LOG_INST_1 (stix, "store_into_instvar %zu", b1); - STIX_ASSERT (STIX_OBJ_GET_FLAGS_TYPE(stix->active_context->receiver_or_source) == STIX_OBJ_TYPE_OOP); + 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); break; @@ -3272,7 +3294,7 @@ int stix_execute (stix_t* stix) b1 = bcode & 0x7; /* low 3 bits */ pop_into_instvar: LOG_INST_1 (stix, "pop_into_instvar %zu", b1); - STIX_ASSERT (STIX_OBJ_GET_FLAGS_TYPE(stix->active_context->receiver_or_source) == STIX_OBJ_TYPE_OOP); + 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); break; @@ -3323,7 +3345,7 @@ int stix_execute (stix_t* stix) * in the relevant method context */ ctx = stix->active_context->origin; bx = b1; - STIX_ASSERT (STIX_CLASSOF(stix, ctx) == stix->_method_context); + STIX_ASSERT (stix, STIX_CLASSOF(stix, ctx) == stix->_method_context); #else /* otherwise, the index may point to a temporaries * declared inside a block */ @@ -3437,7 +3459,7 @@ int stix_execute (stix_t* stix) b1 = bcode & 0x3; /* low 2 bits */ handle_object: ass = (stix_oop_association_t)stix->active_method->slot[b1]; - STIX_ASSERT (STIX_CLASSOF(stix, ass) == stix->_association); + STIX_ASSERT (stix, STIX_CLASSOF(stix, ass) == stix->_association); if ((bcode >> 3) & 1) { @@ -3550,7 +3572,7 @@ return -1; handle_ctxtempvar: ctx = stix->active_context; - STIX_ASSERT ((stix_oop_t)ctx != stix->_nil); + STIX_ASSERT (stix, (stix_oop_t)ctx != stix->_nil); for (i = 0; i < b1; i++) { ctx = (stix_oop_context_t)ctx->home; @@ -3612,8 +3634,8 @@ return -1; handle_objvar: t = (stix_oop_oop_t)stix->active_method->slot[b2]; - STIX_ASSERT (STIX_OBJ_GET_FLAGS_TYPE(t) == STIX_OBJ_TYPE_OOP); - STIX_ASSERT (b1 < STIX_OBJ_GET_SIZE(t)); + STIX_ASSERT (stix, STIX_OBJ_GET_FLAGS_TYPE(t) == STIX_OBJ_TYPE_OOP); + STIX_ASSERT (stix, b1 < STIX_OBJ_GET_SIZE(t)); if ((bcode >> 3) & 1) { @@ -3753,7 +3775,7 @@ return -1; { stix_oop_t t; LOG_INST_0 (stix, "dup_stacktop"); - STIX_ASSERT (!STIX_STACK_ISEMPTY(stix)); + STIX_ASSERT (stix, !STIX_STACK_ISEMPTY(stix)); t = STIX_STACK_GETTOP(stix); STIX_STACK_PUSH (stix, t); break; @@ -3761,7 +3783,7 @@ return -1; case BCODE_POP_STACKTOP: LOG_INST_0 (stix, "pop_stacktop"); - STIX_ASSERT (!STIX_STACK_ISEMPTY(stix)); + STIX_ASSERT (stix, !STIX_STACK_ISEMPTY(stix)); STIX_STACK_POP (stix); break; @@ -3846,8 +3868,8 @@ return -1; * } */ - STIX_ASSERT (STIX_CLASSOF(stix, stix->active_context) == stix->_block_context); - STIX_ASSERT (STIX_CLASSOF(stix, stix->processor->active->initial_context) == stix->_block_context); + 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); /* decrement the instruction pointer back to the return instruction. * even if the context is reentered, it will just return. @@ -3865,7 +3887,7 @@ return -1; if (stix->active_context->origin == stix->active_context) { /* returning from a method */ - STIX_ASSERT (STIX_CLASSOF(stix, stix->active_context) == stix->_method_context); + STIX_ASSERT (stix, STIX_CLASSOF(stix, stix->active_context) == stix->_method_context); stix->ip = -1; } else @@ -3873,7 +3895,7 @@ return -1; stix_oop_context_t ctx; /* method return from within a block(including a non-local return) */ - STIX_ASSERT (STIX_CLASSOF(stix, stix->active_context) == stix->_block_context); + STIX_ASSERT (stix, STIX_CLASSOF(stix, stix->active_context) == stix->_block_context); ctx = stix->active_context; while ((stix_oop_t)ctx != stix->_nil) @@ -3897,8 +3919,8 @@ return -1; } /* cannot return from a method that has returned already */ - STIX_ASSERT (STIX_CLASSOF(stix, stix->active_context->origin) == stix->_method_context); - STIX_ASSERT (stix->active_context->origin->ip == STIX_SMOOI_TO_OOP(-1)); + 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)); 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? */ @@ -3909,7 +3931,7 @@ return -1; stix->active_context->origin->ip = STIX_SMOOI_TO_OOP(-1); } - STIX_ASSERT (STIX_CLASSOF(stix, stix->active_context->origin) == stix->_method_context); + STIX_ASSERT (stix, STIX_CLASSOF(stix, stix->active_context->origin) == stix->_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); @@ -3936,12 +3958,12 @@ return -1; { /* the new active context is the fake initial context. * this context can't get executed further. */ - STIX_ASSERT ((stix_oop_t)stix->active_context->sender == stix->_nil); - STIX_ASSERT (STIX_CLASSOF(stix, stix->active_context) == stix->_method_context); - STIX_ASSERT (stix->active_context->receiver_or_source == stix->_nil); - STIX_ASSERT (stix->active_context == stix->processor->active->initial_context); - STIX_ASSERT (stix->active_context->origin == stix->processor->active->initial_context->origin); - STIX_ASSERT (stix->active_context->origin == stix->active_context); + 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); /* NOTE: this condition is true for the processified block context also. * stix->active_context->origin == stix->processor->active->initial_context->origin @@ -3949,7 +3971,7 @@ return -1; * 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->sp == 0); + STIX_ASSERT (stix, stix->sp == 0); if (stix->option.trait & STIX_AWAIT_PROCS) terminate_process (stix, stix->processor->active); @@ -3969,7 +3991,7 @@ return -1; case BCODE_RETURN_FROM_BLOCK: LOG_INST_0 (stix, "return_from_block"); - STIX_ASSERT(STIX_CLASSOF(stix, stix->active_context) == stix->_block_context); + STIX_ASSERT (stix, STIX_CLASSOF(stix, stix->active_context) == stix->_block_context); if (stix->active_context == stix->processor->active->initial_context) { @@ -3978,7 +4000,7 @@ return -1; * over a block using the newProcess method. let's terminate * the process. */ - STIX_ASSERT ((stix_oop_t)stix->active_context->sender == stix->_nil); + STIX_ASSERT (stix, (stix_oop_t)stix->active_context->sender == stix->_nil); terminate_process (stix, stix->processor->active); } else @@ -4004,8 +4026,8 @@ return -1; LOG_INST_2 (stix, "make_block %zu %zu", b1, b2); - STIX_ASSERT (b1 >= 0); - STIX_ASSERT (b2 >= b1); + STIX_ASSERT (stix, b1 >= 0); + STIX_ASSERT (stix, b2 >= b1); /* the block context object created here is used as a base * object for block context activation. pf_block_value() @@ -4050,18 +4072,18 @@ return -1; LOG_INST_0 (stix, "send_block_copy"); /* it emulates thisContext blockCopy: nargs ofTmprCount: ntmprs */ - STIX_ASSERT (stix->sp >= 2); + STIX_ASSERT (stix, stix->sp >= 2); - STIX_ASSERT (STIX_CLASSOF(stix, STIX_STACK_GETTOP(stix)) == stix->_small_integer); + 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); - STIX_ASSERT (STIX_CLASSOF(stix, STIX_STACK_GETTOP(stix)) == stix->_small_integer); + 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); - STIX_ASSERT (nargs >= 0); - STIX_ASSERT (ntmprs >= nargs); + STIX_ASSERT (stix, nargs >= 0); + STIX_ASSERT (stix, ntmprs >= nargs); /* the block context object created here is used * as a base object for block context activation. @@ -4075,7 +4097,7 @@ 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 (rctx == stix->active_context); + STIX_ASSERT (stix, rctx == stix->active_context); /* [NOTE] * blkctx->sender is left to nil. it is set to the @@ -4112,14 +4134,14 @@ return -1; if (rctx->home == stix->_nil) { /* the context that receives the blockCopy message is a method context */ - STIX_ASSERT (STIX_CLASSOF(stix, rctx) == stix->_method_context); - STIX_ASSERT (rctx == (stix_oop_t)stix->active_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; } else { /* a block context is active */ - STIX_ASSERT (STIX_CLASSOF(stix, rctx) == stix->_block_context); + STIX_ASSERT (stix, STIX_CLASSOF(stix, rctx) == stix->_block_context); blkctx->origin = ((stix_oop_block_context_t)rctx)->origin; } #else @@ -4166,9 +4188,9 @@ int stix_invoke (stix_t* stix, const stix_oocs_t* objname, const stix_oocs_t* mt { int n; - STIX_ASSERT (stix->initial_context == STIX_NULL); - STIX_ASSERT (stix->active_context == STIX_NULL); - STIX_ASSERT (stix->active_method == STIX_NULL); + STIX_ASSERT (stix, stix->initial_context == STIX_NULL); + STIX_ASSERT (stix, stix->active_context == STIX_NULL); + STIX_ASSERT (stix, stix->active_method == STIX_NULL); if (start_initial_process_and_context (stix, objname, mthname) <= -1) return -1; stix->initial_context = stix->processor->active->initial_context; diff --git a/stix/lib/gc.c b/stix/lib/gc.c index dc20a63..14a3ee2 100644 --- a/stix/lib/gc.c +++ b/stix/lib/gc.c @@ -26,6 +26,305 @@ #include "stix-prv.h" + +/* + * Stix ..................... + * ^ ^ ^ : ....... + * | | | v v : + * | | +------------------- Class ..... + * | | ^ ^ + * | +-------- NilObject ......: : + * | ^........ nil : + * Object ...........................: + * ^ + * | + * + * The class hierarchy is roughly as follows: + * + * Stix + * Class + * NilObject + * Object + * Collection + * IndexedCollection + * FixedSizedCollection + * Array + * ByteArray + * String + * Symbol + * Set + * Dictionary + * SystemDictionary + * SymbolSet + * Magnitude + * Association + * Character + * Number + * Integer + * SmallInteger + * LargeInteger + * LargePositiveInteger + * LargeNegativeInteger + * + * Stix has no instance variables. + * Stix has 1 class variable: Sysdic + * + */ + +struct kernel_class_info_t +{ + stix_oow_t len; + stix_ooch_t name[20]; + stix_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) }, + + { 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) }, + + { 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) }, + + { 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) }, + + { 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) }, + + { 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) } +}; + +/* ----------------------------------------------------------------------- + * BOOTSTRAPPER + * ----------------------------------------------------------------------- */ + +static stix_oop_t alloc_kernel_class (stix_t* stix, stix_oow_t indexed_classvars, stix_oow_t spec) +{ + stix_oop_class_t c; + + c = (stix_oop_class_t)stix_allocoopobj (stix, STIX_CLASS_NAMED_INSTVARS + indexed_classvars); + if (!c) return STIX_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)); + + return (stix_oop_t)c; +} + +static int ignite_1 (stix_t* stix) +{ + /* + * 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); + + STIX_ASSERT (stix, stix->_class == STIX_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; + + STIX_ASSERT (stix, STIX_OBJ_GET_CLASS(stix->_class) == STIX_NULL); + STIX_OBJ_SET_CLASS (stix->_class, stix->_class); + + /* -------------------------------------------------------------- + * Apex - proto-object with 1 class variable. + * UndefinedObject - class for the nil object. + * Object - top of all ordinary objects. + * String + * Symbol + * Array + * ByteArray + * SymbolSet + * 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)); + + 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)); + + 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)); + + 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)); + + 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)); + /* 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)); + + if (!stix->_apex || !stix->_undefined_object || + !stix->_object || !stix->_string || + + !stix->_symbol || !stix->_array || + !stix->_byte_array || !stix->_symbol_set || !stix->_system_dictionary || + + !stix->_namespace || !stix->_pool_dictionary || + !stix->_method_dictionary || !stix->_method || !stix->_association || + + !stix->_method_context || !stix->_block_context || + !stix->_process || !stix->_semaphore || !stix->_process_scheduler || + + !stix->_true_class || !stix->_false_class || + !stix->_character || !stix->_small_integer || + !stix->_large_positive_integer || !stix->_large_negative_integer) return -1; + + STIX_OBJ_SET_CLASS (stix->_nil, stix->_undefined_object); + return 0; +} + +static int ignite_2 (stix_t* stix) +{ + stix_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; + + /* Create the symbol table */ + tmp = stix_instantiate (stix, stix->_symbol_set, STIX_NULL, 0); + if (!tmp) return -1; + stix->symtab = (stix_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() + * is called. */ + tmp = stix_instantiate (stix, stix->_array, STIX_NULL, stix->option.dfl_symtab_size); + if (!tmp) return -1; + stix->symtab->bucket = (stix_oop_oop_t)tmp; + + /* Create the system dictionary */ + tmp = (stix_oop_t)stix_makedic (stix, stix->_system_dictionary, stix->option.dfl_sysdic_size); + if (!tmp) return -1; + stix->sysdic = (stix_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); + if (!tmp) return -1; + stix->nil_process = (stix_oop_process_t)tmp; + stix->nil_process->sp = STIX_SMOOI_TO_OOP(-1); + + /* Create a process scheduler */ + tmp = (stix_oop_t)stix_instantiate (stix, stix->_process_scheduler, STIX_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; + + /* 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; + + return 0; +} + +static int ignite_3 (stix_t* stix) +{ + /* 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' }; + + stix_oow_t i; + stix_oop_t sym, cls; + stix_oop_t* stix_ptr; + + for (i = 0; i < STIX_COUNTOF(kernel_classes); i++) + { + sym = stix_makesymbol (stix, kernel_classes[i].name, kernel_classes[i].len); + if (!sym) return -1; + + cls = *(stix_oop_t*)((stix_uint8_t*)stix + kernel_classes[i].offset); + + if (!stix_putatsysdic(stix, sym, cls)) return -1; + stix_ptr++; + } + + /* Make the system dictionary available as the global name 'Stix' */ + sym = stix_makesymbol (stix, str_system, 6); + if (!sym) return -1; + if (!stix_putatsysdic(stix, sym, (stix_oop_t)stix->sysdic)) return -1; + + /* Make the process scheduler avaialble as the global name 'Processor' */ + sym = stix_makesymbol (stix, str_processor, 9); + if (!sym) return -1; + if (!stix_putatsysdic(stix, sym, (stix_oop_t)stix->processor)) return -1; + + return 0; +} + +int stix_ignite (stix_t* stix) +{ + STIX_ASSERT (stix, stix->_nil == STIX_NULL); + + stix->_nil = stix_allocbytes (stix, STIX_SIZEOF(stix_obj_t)); + if (!stix->_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; + + if (ignite_1(stix) <= -1 || ignite_2(stix) <= -1 || ignite_3(stix)) return -1; + + return 0; +} + +/* ----------------------------------------------------------------------- + * GARBAGE COLLECTOR + * ----------------------------------------------------------------------- */ + + static void compact_symbol_table (stix_t* stix, stix_oop_t _nil) { stix_oop_char_t symbol; @@ -39,9 +338,9 @@ static void compact_symbol_table (stix_t* stix, stix_oop_t _nil) /* 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_OOP_IS_SMOOI(stix->symtab->tally)); + STIX_ASSERT (stix, STIX_OOP_IS_SMOOI(stix->symtab->tally)); tally = STIX_OOP_TO_SMOOI(stix->symtab->tally); - STIX_ASSERT (tally >= 0); /* it must not be less than 0 */ + STIX_ASSERT (stix, 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 @@ -56,7 +355,7 @@ static void compact_symbol_table (stix_t* stix, stix_oop_t _nil) continue; } - STIX_ASSERT (stix->symtab->bucket->slot[index] != _nil); + STIX_ASSERT (stix, stix->symtab->bucket->slot[index] != _nil); for (i = 0, x = index, y = index; i < bucket_size; i++) { @@ -69,7 +368,7 @@ static void compact_symbol_table (stix_t* stix, stix_oop_t _nil) * at the current hash index */ symbol = (stix_oop_char_t)stix->symtab->bucket->slot[y]; - STIX_ASSERT (STIX_CLASSOF(stix,symbol) == stix->_symbol); + STIX_ASSERT (stix, STIX_CLASSOF(stix,symbol) == stix->_symbol); z = stix_hashchars(symbol->slot, STIX_OBJ_GET_SIZE(symbol)) % bucket_size; @@ -86,8 +385,8 @@ static void compact_symbol_table (stix_t* stix, stix_oop_t _nil) tally--; } - STIX_ASSERT (tally >= 0); - STIX_ASSERT (tally <= STIX_SMOOI_MAX); + STIX_ASSERT (stix, tally >= 0); + STIX_ASSERT (stix, tally <= STIX_SMOOI_MAX); stix->symtab->tally = STIX_SMOOI_TO_OOP(tally); } @@ -113,9 +412,9 @@ 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_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_OOP); - STIX_ASSERT (STIX_OBJ_GET_FLAGS_UNIT(oop) == STIX_SIZEOF(stix_oow_t)); - STIX_ASSERT (STIX_OBJ_GET_FLAGS_EXTRA(oop) == 0); /* no 'extra' for an OOP object */ + 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 */ nbytes = STIX_OBJ_BYTESOF(oop) + STIX_SIZEOF(stix_oow_t) + \ (stix_oow_t)((stix_oop_oop_t)oop)->slot[STIX_OBJ_GET_SIZE(oop)]; @@ -166,7 +465,7 @@ 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 (tmp != STIX_NULL); + STIX_ASSERT (stix, tmp != STIX_NULL); /* copy the payload to the new object */ STIX_MEMCPY (tmp, oop, STIX_SIZEOF(stix_obj_t) + nbytes_aligned); @@ -199,9 +498,9 @@ static stix_uint8_t* scan_new_heap (stix_t* stix, stix_uint8_t* ptr) { stix_oow_t nbytes; - STIX_ASSERT (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_OOP); - STIX_ASSERT (STIX_OBJ_GET_FLAGS_UNIT(oop) == STIX_SIZEOF(stix_oow_t)); - STIX_ASSERT (STIX_OBJ_GET_FLAGS_EXTRA(oop) == 0); /* no 'extra' for an OOP object */ + 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 */ nbytes = STIX_OBJ_BYTESOF(oop) + STIX_SIZEOF(stix_oow_t) + \ (stix_oow_t)((stix_oop_oop_t)oop)->slot[STIX_OBJ_GET_SIZE(oop)]; @@ -228,7 +527,7 @@ static stix_uint8_t* scan_new_heap (stix_t* stix, stix_uint8_t* ptr) * are garbages. */ size = STIX_PROCESS_NAMED_INSTVARS + STIX_OOP_TO_SMOOI(((stix_oop_process_t)oop)->sp) + 1; - STIX_ASSERT (size <= STIX_OBJ_GET_SIZE(oop)); + STIX_ASSERT (stix, size <= STIX_OBJ_GET_SIZE(oop)); } else { @@ -268,8 +567,8 @@ void stix_gc (stix_t* stix) { /* TODO: verify if this is correct */ - STIX_ASSERT ((stix_oop_t)stix->processor != stix->_nil); - STIX_ASSERT ((stix_oop_t)stix->processor->active != stix->_nil); + STIX_ASSERT (stix, (stix_oop_t)stix->processor != stix->_nil); + STIX_ASSERT (stix, (stix_oop_t)stix->processor->active != stix->_nil); /* store the stack pointer to the active process */ stix->processor->active->sp = STIX_SMOOI_TO_OOP(stix->sp); @@ -290,34 +589,13 @@ void stix_gc (stix_t* stix) stix->_true = stix_moveoop (stix, stix->_true); stix->_false = stix_moveoop (stix, stix->_false); - stix->_apex = stix_moveoop (stix, stix->_apex); - stix->_class = stix_moveoop (stix, stix->_class); - stix->_undefined_object = stix_moveoop (stix, stix->_undefined_object); - stix->_object = stix_moveoop (stix, stix->_object); - stix->_array = stix_moveoop (stix, stix->_array); - stix->_byte_array = stix_moveoop (stix, stix->_byte_array); - - stix->_string = stix_moveoop (stix, stix->_string); - stix->_symbol = stix_moveoop (stix, stix->_symbol); - stix->_symbol_set = stix_moveoop (stix, stix->_symbol_set); - stix->_system_dictionary = stix_moveoop (stix, stix->_system_dictionary); - stix->_namespace = stix_moveoop (stix, stix->_namespace); - stix->_pool_dictionary = stix_moveoop (stix, stix->_pool_dictionary); - stix->_method_dictionary = stix_moveoop (stix, stix->_method_dictionary); - stix->_method = stix_moveoop (stix, stix->_method); - stix->_association = stix_moveoop (stix, stix->_association); - stix->_method_context = stix_moveoop (stix, stix->_method_context); - stix->_block_context = stix_moveoop (stix, stix->_block_context); - stix->_semaphore = stix_moveoop (stix, stix->_semaphore); - stix->_process = stix_moveoop (stix, stix->_process); - stix->_process_scheduler = stix_moveoop (stix, stix->_process_scheduler); - stix->_true_class = stix_moveoop (stix, stix->_true_class); - stix->_false_class = stix_moveoop (stix, stix->_false_class); - stix->_character = stix_moveoop (stix, stix->_character); - - stix->_small_integer = stix_moveoop (stix, stix->_small_integer); - stix->_large_positive_integer = stix_moveoop (stix, stix->_large_positive_integer); - stix->_large_negative_integer = stix_moveoop (stix, stix->_large_negative_integer); + for (i = 0; i < STIX_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; + } 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); @@ -409,19 +687,19 @@ void stix_pushtmp (stix_t* stix, stix_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->tmp_count < STIX_COUNTOF(stix->tmp_stack)); + STIX_ASSERT (stix, stix->tmp_count < STIX_COUNTOF(stix->tmp_stack)); stix->tmp_stack[stix->tmp_count++] = oop_ptr; } void stix_poptmp (stix_t* stix) { - STIX_ASSERT (stix->tmp_count > 0); + STIX_ASSERT (stix, stix->tmp_count > 0); stix->tmp_count--; } void stix_poptmps (stix_t* stix, stix_oow_t count) { - STIX_ASSERT (stix->tmp_count >= count); + STIX_ASSERT (stix, stix->tmp_count >= count); stix->tmp_count -= count; } diff --git a/stix/lib/heap.c b/stix/lib/heap.c index 2741590..b788fbd 100644 --- a/stix/lib/heap.c +++ b/stix/lib/heap.c @@ -44,9 +44,9 @@ stix_heap_t* stix_makeheap (stix_t* stix, stix_oow_t size) heap->ptr = (stix_uint8_t*)STIX_ALIGN(((stix_uintptr_t)heap->base), STIX_SIZEOF(stix_oop_t)); heap->limit = heap->base + size; - STIX_ASSERT (heap->ptr >= heap->base); - STIX_ASSERT (heap->limit >= heap->base ); - STIX_ASSERT (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); /* if size is too small, heap->ptr may go past heap->limit even at * this moment depending on the alignment of heap->base. subsequent diff --git a/stix/lib/ignite.c b/stix/lib/ignite.c deleted file mode 100644 index 065e358..0000000 --- a/stix/lib/ignite.c +++ /dev/null @@ -1,310 +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 ..................... - * ^ ^ ^ : ....... - * | | | v v : - * | | +------------------- Class ..... - * | | ^ ^ - * | +-------- NilObject ......: : - * | ^........ nil : - * Object ...........................: - * ^ - * | - * - * The class hierarchy is roughly as follows: - * - * Stix - * Class - * NilObject - * Object - * Collection - * IndexedCollection - * FixedSizedCollection - * Array - * ByteArray - * String - * Symbol - * Set - * Dictionary - * SystemDictionary - * SymbolSet - * Magnitude - * Association - * Character - * Number - * Integer - * SmallInteger - * LargeInteger - * LargePositiveInteger - * LargeNegativeInteger - * - * Stix has no instance variables. - * Stix has 1 class variable: Sysdic - * - */ - -static stix_oop_t alloc_kernel_class (stix_t* stix, stix_oow_t indexed, stix_oow_t spec) -{ - stix_oop_class_t c; - - c = (stix_oop_class_t)stix_allocoopobj (stix, STIX_CLASS_NAMED_INSTVARS + indexed); - if (!c) return STIX_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, 0)); - - return (stix_oop_t)c; -} - -static int ignite_1 (stix_t* stix) -{ - /* - * Create fundamental class objects with some fields mis-initialized yet. - * Such fields include 'superclass', 'subclasses', 'name', etc. - */ - STIX_ASSERT (stix->_nil != STIX_NULL); - STIX_ASSERT (STIX_OBJ_GET_CLASS(stix->_nil) == STIX_NULL); - - STIX_ASSERT (stix->_class == STIX_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; - - STIX_ASSERT (STIX_OBJ_GET_CLASS(stix->_class) == STIX_NULL); - STIX_OBJ_SET_CLASS (stix->_class, stix->_class); - - /* -------------------------------------------------------------- - * Apex - proto-object with 1 class variable. - * UndefinedObject - class for the nil object. - * Object - top of all ordinary objects. - * String - * Symbol - * Array - * ByteArray - * SymbolSet - * 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)); - - 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)); - - 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)); - - 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)); - 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)); - /* 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)); - stix->_resource = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 0, STIX_OBJ_TYPE_OOP)); - - if (!stix->_apex || !stix->_undefined_object || - !stix->_object || !stix->_string || - - !stix->_symbol || !stix->_array || - !stix->_byte_array || !stix->_symbol_set || !stix->_system_dictionary || - - !stix->_namespace || !stix->_pool_dictionary || - !stix->_method_dictionary || !stix->_method || !stix->_association || - - !stix->_method_context || !stix->_block_context || - !stix->_process || !stix->_semaphore || !stix->_process_scheduler || - - !stix->_true_class || !stix->_false_class || - !stix->_character || !stix->_small_integer || - !stix->_large_positive_integer || !stix->_large_negative_integer || !stix->_resource) return -1; - - STIX_OBJ_SET_CLASS (stix->_nil, stix->_undefined_object); - return 0; -} - -static int ignite_2 (stix_t* stix) -{ - stix_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; - - /* Create the symbol table */ - tmp = stix_instantiate (stix, stix->_symbol_set, STIX_NULL, 0); - if (!tmp) return -1; - stix->symtab = (stix_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() - * is called. */ - tmp = stix_instantiate (stix, stix->_array, STIX_NULL, stix->option.dfl_symtab_size); - if (!tmp) return -1; - stix->symtab->bucket = (stix_oop_oop_t)tmp; - - /* Create the system dictionary */ - tmp = (stix_oop_t)stix_makedic (stix, stix->_system_dictionary, stix->option.dfl_sysdic_size); - if (!tmp) return -1; - stix->sysdic = (stix_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); - if (!tmp) return -1; - stix->nil_process = (stix_oop_process_t)tmp; - stix->nil_process->sp = STIX_SMOOI_TO_OOP(-1); - - /* Create a process scheduler */ - tmp = (stix_oop_t)stix_instantiate (stix, stix->_process_scheduler, STIX_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; - - /* 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; - - return 0; -} - -static int ignite_3 (stix_t* stix) -{ - /* Register kernel classes manually created so far to the system dictionary */ - - static struct symbol_name_t - { - stix_oow_t len; - stix_ooch_t str[20]; - } symnames[] = { - { 4, { 'A','p','e','x' } }, - { 15, { 'U','n','d','e','f','i','n','e','d','O','b','j','e','c','t' } }, - { 5, { 'C','l','a','s','s' } }, - { 6, { 'O','b','j','e','c','t' } }, - { 6, { 'S','t','r','i','n','g' } }, - - { 6, { 'S','y','m','b','o','l' } }, - { 5, { 'A','r','r','a','y' } }, - { 9, { 'B','y','t','e','A','r','r','a','y' } }, - { 9, { 'S','y','m','b','o','l','S','e','t' } }, - { 16, { 'S','y','s','t','e','m','D','i','c','t','i','o','n','a','r','y' } }, - - { 9, { 'N','a','m','e','s','p','a','c','e' } }, - { 14, { 'P','o','o','l','D','i','c','t','i','o','n','a','r','y' } }, - { 16, { 'M','e','t','h','o','d','D','i','c','t','i','o','n','a','r','y' } }, - { 14, { 'C','o','m','p','i','l','e','d','M','e','t','h','o','d' } }, - { 11, { 'A','s','s','o','c','i','a','t','i','o','n' } }, - - { 13, { 'M','e','t','h','o','d','C','o','n','t','e','x','t' } }, - { 12, { 'B','l','o','c','k','C','o','n','t','e','x','t' } }, - { 7, { 'P','r','o','c','e','s','s' } }, - { 9, { 'S','e','m','a','p','h','o','r','e' } }, - { 16, { 'P','r','o','c','e','s','s','S','c','h','e','d','u','l','e','r' } }, - { 4, { 'T','r','u','e' } }, - { 5, { 'F','a','l','s','e' } }, - { 9, { 'C','h','a','r','a','c','t','e','r' } }, - { 12, { 'S','m','a','l','l','I','n','t','e','g','e','r' } }, - { 20, { 'L','a','r','g','e','P','o','s','i','t','i','v','e','I','n','t','e','g','e','r' } }, - { 20, { 'L','a','r','g','e','N','e','g','a','t','i','v','e','I','n','t','e','g','e','r' } } - }; - - 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' }; - - stix_oow_t i; - stix_oop_t sym; - stix_oop_t* stix_ptr; - - stix_ptr = &stix->_apex; - /* [NOTE] - * The loop here repies on the proper order of fields in stix_t. - * Be sure to keep in sync the order of items in symnames and - * the releated fields of stix_t */ - for (i = 0; i < STIX_COUNTOF(symnames); i++) - { - sym = stix_makesymbol (stix, symnames[i].str, symnames[i].len); - if (!sym) return -1; - - if (!stix_putatsysdic(stix, sym, *stix_ptr)) return -1; - stix_ptr++; - } - - /* Make the system dictionary available as the global name 'Stix' */ - sym = stix_makesymbol (stix, str_system, 6); - if (!sym) return -1; - if (!stix_putatsysdic(stix, sym, (stix_oop_t)stix->sysdic)) return -1; - - /* Make the process scheduler avaialble as the global name 'Processor' */ - sym = stix_makesymbol (stix, str_processor, 9); - if (!sym) return -1; - if (!stix_putatsysdic(stix, sym, (stix_oop_t)stix->processor)) return -1; - - return 0; -} - -int stix_ignite (stix_t* stix) -{ - STIX_ASSERT (stix->_nil == STIX_NULL); - - stix->_nil = stix_allocbytes (stix, STIX_SIZEOF(stix_obj_t)); - if (!stix->_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; - - if (ignite_1(stix) <= -1 || ignite_2(stix) <= -1 || ignite_3(stix)) return -1; - - return 0; -} diff --git a/stix/lib/logfmt.c b/stix/lib/logfmt.c index e0d10e3..13d960e 100644 --- a/stix/lib/logfmt.c +++ b/stix/lib/logfmt.c @@ -316,16 +316,16 @@ static void print_object (stix_t* stix, stix_oow_t mask, stix_oop_t oop) { stix_logbfmt (stix, mask, "$%.1C", STIX_OOP_TO_CHAR(oop)); } - else if (STIX_OOP_IS_RSRC(oop)) + else if (STIX_OOP_IS_ERROR(oop)) { - stix_logbfmt (stix, mask, "%zX", stix->rsrc.ptr[STIX_OOP_TO_RSRC(oop)]); + stix_logbfmt (stix, mask, "E%08zd", STIX_OOP_TO_ERROR(oop)); } else { stix_oop_class_t c; stix_oow_t i; - STIX_ASSERT (STIX_OOP_IS_POINTER(oop)); + STIX_ASSERT (stix, STIX_OOP_IS_POINTER(oop)); c = (stix_oop_class_t)STIX_OBJ_GET_CLASS(oop); /*STIX_CLASSOF(stix, oop);*/ if ((stix_oop_t)c == stix->_large_negative_integer) diff --git a/stix/lib/logfmtv.h b/stix/lib/logfmtv.h index a931b19..f8143c9 100644 --- a/stix/lib/logfmtv.h +++ b/stix/lib/logfmtv.h @@ -112,11 +112,11 @@ int logfmtv (stix_t* stix, const fmtchar_t* fmt, stix_fmtout_t* data, va_list ap fltfmt = &stix->d->fltfmt; fltout = &stix->d->fltout; - fltfmt->ptr = fltfmt->sbuf; - fltfmt->capa = STIX_COUNTOF(fltfmt->sbuf) - 1; + fltfmt->ptr = fltfmt->buf; + fltfmt->capa = STIX_COUNTOF(fltfmt->buf) - 1; - fltout->ptr = fltout->sbuf; - fltout->capa = STIX_COUNTOF(fltout->sbuf) - 1; + fltout->ptr = fltout->buf; + fltout->capa = STIX_COUNTOF(fltout->buf) - 1; #endif while (1) @@ -444,7 +444,7 @@ reswitch: stix_oow_t conv_len, src_len, tot_len = 0; while (n > 0) { - STIX_ASSERT (bslen > tot_len); + STIX_ASSERT (stix, bslen > tot_len); src_len = bslen - tot_len; conv_len = STIX_COUNTOF(conv_buf); @@ -575,7 +575,7 @@ reswitch: fmtlen = fmt - percent; if (fmtlen > fltfmt->capa) { - if (fltfmt->ptr == fltfmt->sbuf) + 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; @@ -635,7 +635,7 @@ reswitch: newcapa = precision + width + 32; if (fltout->capa < newcapa) { - STIX_ASSERT (fltout->ptr == fltout->sbuf); + STIX_ASSERT (stix, 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; diff --git a/stix/lib/main.c b/stix/lib/main.c index 1e9250f..dfc0912 100644 --- a/stix/lib/main.c +++ b/stix/lib/main.c @@ -192,7 +192,7 @@ static STIX_INLINE stix_ooi_t close_input (stix_t* stix, stix_ioarg_t* arg) bb_t* bb; bb = (bb_t*)arg->handle; - STIX_ASSERT (bb != STIX_NULL && bb->fp != STIX_NULL); + STIX_ASSERT (stix, bb != STIX_NULL && bb->fp != STIX_NULL); fclose (bb->fp); stix_freemem (stix, bb); @@ -211,7 +211,7 @@ static STIX_INLINE stix_ooi_t read_input (stix_t* stix, stix_ioarg_t* arg) bb = (bb_t*)arg->handle; - STIX_ASSERT (bb != STIX_NULL && bb->fp != STIX_NULL); + STIX_ASSERT (stix, bb != STIX_NULL && bb->fp != STIX_NULL); do { x = fgetc (bb->fp); @@ -445,7 +445,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 (ucslen > 0); /* if this fails, the buffer size must be increased */ + STIX_ASSERT (stix, 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; diff --git a/stix/lib/obj.c b/stix/lib/obj.c index df12c30..c22b563 100644 --- a/stix/lib/obj.c +++ b/stix/lib/obj.c @@ -175,10 +175,10 @@ static STIX_INLINE int decode_spec (stix_t* stix, stix_oop_t _class, stix_oow_t stix_oow_t named_instvar; stix_obj_type_t indexed_type; - STIX_ASSERT (STIX_OOP_IS_POINTER(_class)); - STIX_ASSERT (STIX_CLASSOF(stix, _class) == stix->_class); + STIX_ASSERT (stix, STIX_OOP_IS_POINTER(_class)); + STIX_ASSERT (stix, STIX_CLASSOF(stix, _class) == stix->_class); - STIX_ASSERT (STIX_OOP_IS_SMOOI(((stix_oop_class_t)_class)->spec)); + STIX_ASSERT (stix, STIX_OOP_IS_SMOOI(((stix_oop_class_t)_class)->spec)); spec = STIX_OOP_TO_SMOOI(((stix_oop_class_t)_class)->spec); named_instvar = STIX_CLASS_SPEC_NAMED_INSTVAR(spec); /* size of the named_instvar part */ @@ -200,7 +200,7 @@ static STIX_INLINE int decode_spec (stix_t* stix, stix_oop_t _class, stix_oow_t return -1; } - STIX_ASSERT (named_instvar + vlen <= STIX_OBJ_SIZE_MAX); + STIX_ASSERT (stix, named_instvar + vlen <= STIX_OBJ_SIZE_MAX); } else { @@ -235,7 +235,7 @@ static STIX_INLINE int decode_spec (stix_t* stix, stix_oop_t _class, stix_oow_t 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); return -1; } - STIX_ASSERT (named_instvar <= STIX_OBJ_SIZE_MAX); + STIX_ASSERT (stix, named_instvar <= STIX_OBJ_SIZE_MAX); } *type = indexed_type; @@ -250,7 +250,7 @@ stix_oop_t stix_instantiate (stix_t* stix, stix_oop_t _class, const void* vptr, stix_oow_t alloclen; stix_oow_t tmp_count = 0; - STIX_ASSERT (stix->_nil != STIX_NULL); + STIX_ASSERT (stix, stix->_nil != STIX_NULL); if (decode_spec (stix, _class, vlen, &type, &alloclen) <= -1) { @@ -267,7 +267,7 @@ stix_oop_t stix_instantiate (stix_t* stix, stix_oop_t _class, const void* vptr, * the variable part(indexed instance variables) are allowed. */ oop = stix_allocoopobj (stix, alloclen); - STIX_ASSERT (vptr == STIX_NULL); + STIX_ASSERT (stix, vptr == STIX_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 @@ -319,7 +319,7 @@ stix_oop_t stix_instantiate2 (stix_t* stix, stix_oop_t _class, const void* vptr, stix_oow_t alloclen; stix_oow_t tmp_count = 0; - STIX_ASSERT (stix->_nil != STIX_NULL); + STIX_ASSERT (stix, stix->_nil != STIX_NULL); if (decode_spec (stix, _class, vlen, &type, &alloclen) <= -1) { @@ -374,7 +374,7 @@ stix_oop_t stix_instantiatewithtrailer (stix_t* stix, stix_oop_t _class, stix_oo stix_oow_t alloclen; stix_oow_t tmp_count = 0; - STIX_ASSERT (stix->_nil != STIX_NULL); + STIX_ASSERT (stix, stix->_nil != STIX_NULL); if (decode_spec (stix, _class, vlen, &type, &alloclen) <= -1) { diff --git a/stix/lib/proc.c b/stix/lib/proc.c index 84207e2..419378b 100644 --- a/stix/lib/proc.c +++ b/stix/lib/proc.c @@ -27,8 +27,6 @@ #include "stix-prv.h" - - stix_oop_process_t stix_addnewproc (stix_t* stix) { stix_oop_process_t proc; @@ -37,8 +35,8 @@ stix_oop_process_t stix_addnewproc (stix_t* stix) if (!proc) return STIX_NULL; proc->state = STIX_SMOOI_TO_OOP(0); - - STIX_ASSERT (STIX_OBJ_GET_SIZE(proc) == STIX_PROCESS_NAMED_INSTVARS + stix->option.dfl_procstk_size); + + STIX_ASSERT (stix, STIX_OBJ_GET_SIZE(proc) == STIX_PROCESS_NAMED_INSTVARS + stix->option.dfl_procstk_size); return proc; } diff --git a/stix/lib/rbt.c b/stix/lib/rbt.c index 47f037b..60784de 100644 --- a/stix/lib/rbt.c +++ b/stix/lib/rbt.c @@ -67,7 +67,7 @@ STIX_INLINE stix_rbt_pair_t* stix_rbt_allocpair ( if (kcop == STIX_RBT_COPIER_INLINE) as += KTOB(rbt,klen); if (vcop == STIX_RBT_COPIER_INLINE) as += VTOB(rbt,vlen); - n = (stix_rbt_pair_t*) STIX_MMGR_ALLOC (rbt->mmgr, as); + n = (stix_rbt_pair_t*) STIX_MMGR_ALLOC (rbt->stix->mmgr, as); if (n == STIX_NULL) return STIX_NULL; n->color = STIX_RBT_RED; @@ -90,7 +90,7 @@ STIX_INLINE stix_rbt_pair_t* stix_rbt_allocpair ( KPTR(n) = kcop (rbt, kptr, klen); if (KPTR(n) == STIX_NULL) { - STIX_MMGR_FREE (rbt->mmgr, n); + STIX_MMGR_FREE (rbt->stix->mmgr, n); return STIX_NULL; } } @@ -114,7 +114,7 @@ STIX_INLINE stix_rbt_pair_t* stix_rbt_allocpair ( { if (rbt->style->freeer[STIX_RBT_KEY] != STIX_NULL) rbt->style->freeer[STIX_RBT_KEY] (rbt, KPTR(n), KLEN(n)); - STIX_MMGR_FREE (rbt->mmgr, n); + STIX_MMGR_FREE (rbt->stix->mmgr, n); return STIX_NULL; } } @@ -128,7 +128,7 @@ STIX_INLINE void stix_rbt_freepair (stix_rbt_t* rbt, stix_rbt_pair_t* pair) 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->mmgr, pair); + STIX_MMGR_FREE (rbt->stix->mmgr, pair); } static stix_rbt_style_t style[] = @@ -191,16 +191,16 @@ const stix_rbt_style_t* stix_getrbtstyle (stix_rbt_style_kind_t kind) return &style[kind]; } -stix_rbt_t* stix_rbt_open (stix_mmgr_t* mmgr, stix_oow_t xtnsize, int kscale, int vscale) +stix_rbt_t* stix_rbt_open (stix_t* stix, stix_oow_t xtnsize, int kscale, int vscale) { stix_rbt_t* rbt; - rbt = (stix_rbt_t*) STIX_MMGR_ALLOC (mmgr, STIX_SIZEOF(stix_rbt_t) + xtnsize); + rbt = (stix_rbt_t*) STIX_MMGR_ALLOC (stix->mmgr, STIX_SIZEOF(stix_rbt_t) + xtnsize); if (rbt == STIX_NULL) return STIX_NULL; - if (stix_rbt_init (rbt, mmgr, kscale, vscale) <= -1) + if (stix_rbt_init (rbt, stix, kscale, vscale) <= -1) { - STIX_MMGR_FREE (mmgr, rbt); + STIX_MMGR_FREE (stix->mmgr, rbt); return STIX_NULL; } @@ -211,14 +211,14 @@ stix_rbt_t* stix_rbt_open (stix_mmgr_t* mmgr, stix_oow_t xtnsize, int kscale, in void stix_rbt_close (stix_rbt_t* rbt) { stix_rbt_fini (rbt); - STIX_MMGR_FREE (rbt->mmgr, rbt); + STIX_MMGR_FREE (rbt->stix->mmgr, rbt); } -int stix_rbt_init (stix_rbt_t* rbt, stix_mmgr_t* mmgr, int kscale, int vscale) +int stix_rbt_init (stix_rbt_t* rbt, stix_t* stix, int kscale, int vscale) { /* do not zero out the extension */ STIX_MEMSET (rbt, 0, STIX_SIZEOF(*rbt)); - rbt->mmgr = mmgr; + rbt->stix = stix; rbt->scale[STIX_RBT_KEY] = (kscale < 1)? 1: kscale; rbt->scale[STIX_RBT_VAL] = (vscale < 1)? 1: vscale; @@ -243,11 +243,6 @@ void stix_rbt_fini (stix_rbt_t* rbt) stix_rbt_clear (rbt); } -stix_mmgr_t* stix_rbt_getmmgr (stix_rbt_t* rbt) -{ - return rbt->mmgr; -} - void* stix_rbt_getxtn (stix_rbt_t* rbt) { return (void*)(rbt + 1); @@ -260,7 +255,7 @@ const stix_rbt_style_t* stix_rbt_getstyle (const stix_rbt_t* rbt) void stix_rbt_setstyle (stix_rbt_t* rbt, const stix_rbt_style_t* style) { - STIX_ASSERT (style != STIX_NULL); + STIX_ASSERT (rbt->stix, style != STIX_NULL); rbt->style = style; } @@ -324,7 +319,7 @@ static void rotate (stix_rbt_t* rbt, stix_rbt_pair_t* pivot, int leftwise) stix_rbt_pair_t* parent, * z, * c; int cid1, cid2; - STIX_ASSERT (pivot != STIX_NULL); + STIX_ASSERT (rbt->stix, pivot != STIX_NULL); if (leftwise) { @@ -352,13 +347,13 @@ static void rotate (stix_rbt_t* rbt, stix_rbt_pair_t* pivot, int leftwise) } else { - STIX_ASSERT (parent->right == pivot); + STIX_ASSERT (rbt->stix, parent->right == pivot); parent->right = z; } } else { - STIX_ASSERT (rbt->root == pivot); + STIX_ASSERT (rbt->stix, rbt->root == pivot); rbt->root = z; } @@ -379,7 +374,7 @@ static void adjust (stix_rbt_t* rbt, stix_rbt_pair_t* pair) x_par = pair->parent; if (x_par->color == STIX_RBT_BLACK) break; - STIX_ASSERT (x_par->parent != STIX_NULL); + STIX_ASSERT (rbt->stix, x_par->parent != STIX_NULL); if (x_par == x_par->parent->child[LEFT]) { @@ -469,7 +464,7 @@ static stix_rbt_pair_t* change_pair_val ( } else { - STIX_ASSERT (pair->parent->right == pair); + STIX_ASSERT (rbt->stix, pair->parent->right == pair); pair->parent->right = p; } } @@ -542,7 +537,7 @@ static stix_rbt_pair_t* insert ( if (x_par == STIX_NULL) { /* the tree contains no pair */ - STIX_ASSERT (rbt->root == &rbt->xnil); + STIX_ASSERT (rbt->stix, rbt->root == &rbt->xnil); rbt->root = x_new; } else @@ -551,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 (x_par->right == &rbt->xnil); + STIX_ASSERT (rbt->stix, x_par->right == &rbt->xnil); x_par->right = x_new; } else { - STIX_ASSERT (x_par->left == &rbt->xnil); + STIX_ASSERT (rbt->stix, x_par->left == &rbt->xnil); x_par->left = x_new; } @@ -639,7 +634,7 @@ stix_rbt_pair_t* stix_rbt_cbsert ( } else { - STIX_ASSERT (tmp.parent->right == x_cur); + STIX_ASSERT (rbt->stix, tmp.parent->right == x_cur); tmp.parent->right = x_new; } } @@ -664,7 +659,7 @@ stix_rbt_pair_t* stix_rbt_cbsert ( if (x_par == STIX_NULL) { /* the tree contains no pair */ - STIX_ASSERT (rbt->root == &rbt->xnil); + STIX_ASSERT (rbt->stix, rbt->root == &rbt->xnil); rbt->root = x_new; } else @@ -673,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 (x_par->right == &rbt->xnil); + STIX_ASSERT (rbt->stix, x_par->right == &rbt->xnil); x_par->right = x_new; } else { - STIX_ASSERT (x_par->left == &rbt->xnil); + STIX_ASSERT (rbt->stix, x_par->left == &rbt->xnil); x_par->left = x_new; } @@ -738,7 +733,7 @@ static void adjust_for_delete (stix_rbt_t* rbt, stix_rbt_pair_t* pair, stix_rbt_ } else { - STIX_ASSERT (pair == par->right); + STIX_ASSERT (rbt->stix, pair == par->right); tmp = par->left; if (tmp->color == STIX_RBT_RED) { @@ -783,7 +778,7 @@ static void delete_pair (stix_rbt_t* rbt, stix_rbt_pair_t* pair) { stix_rbt_pair_t* x, * y, * par; - STIX_ASSERT (pair && !IS_NIL(rbt,pair)); + STIX_ASSERT (rbt->stix, pair && !IS_NIL(rbt,pair)); if (IS_NIL(rbt,pair->left) || IS_NIL(rbt,pair->right)) { @@ -961,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 (prev == x_cur->child[r]); + STIX_ASSERT (rbt->stix, prev == x_cur->child[r]); /* just move up to the parent */ prev = x_cur; x_cur = x_cur->parent; diff --git a/stix/lib/stix-cmn.h b/stix/lib/stix-cmn.h index db815c0..41eb912 100644 --- a/stix/lib/stix-cmn.h +++ b/stix/lib/stix-cmn.h @@ -548,6 +548,11 @@ struct stix_cmgr_t 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 * =========================================================================*/ diff --git a/stix/lib/stix-prv.h b/stix/lib/stix-prv.h index 9d6d86f..ac46792 100644 --- a/stix/lib/stix-prv.h +++ b/stix/lib/stix-prv.h @@ -65,7 +65,6 @@ /* TODO: delete these header inclusion lines */ #include -#include #if defined(__has_builtin) # if __has_builtin(__builtin_memset) @@ -101,8 +100,6 @@ # define STIX_MEMCMP(dst,src,size) memcmp(dst,src,size) #endif -#define STIX_ASSERT(x) assert(x) - #define STIX_ALIGN(x,y) ((((x) + (y) - 1) / (y)) * (y)) @@ -583,10 +580,13 @@ struct stix_compiler_t } mth; }; + + +/* typedef struct stix_bchbuf_t stix_bchbuf_t; struct stix_bchbuf_t { - stix_bch_t sbuf[128]; + stix_bch_t buf[128]; stix_bch_t* ptr; stix_oow_t capa; }; @@ -594,10 +594,11 @@ struct stix_bchbuf_t typedef struct stix_oochbuf_t stix_oochbuf_t; struct stix_oochbuf_t { - stix_ooch_t sbuf[128]; + stix_ooch_t buf[128]; stix_ooch_t* ptr; stix_oow_t capa; }; +*/ #endif diff --git a/stix/lib/stix-rbt.h b/stix/lib/stix-rbt.h index 9c3eb09..a99bebb 100644 --- a/stix/lib/stix-rbt.h +++ b/stix/lib/stix-rbt.h @@ -101,7 +101,7 @@ typedef enum stix_rbt_id_t stix_rbt_id_t; 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 */ + stix_oow_t dlen /* length of a key or a value */ ); /** @@ -109,8 +109,8 @@ typedef void* (*stix_rbt_copier_t) ( */ 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 */ + void* dptr, /**< pointer to a key or a value */ + stix_oow_t dlen /**< length of a key or a value */ ); /** @@ -234,11 +234,11 @@ typedef enum stix_rbt_style_kind_t stix_rbt_style_kind_t; */ struct stix_rbt_t { - stix_mmgr_t* mmgr; + stix_t* stix; const stix_rbt_style_t* style; - stix_oob_t scale[2]; /**< length scale */ + stix_oob_t scale[2]; /**< length scale */ stix_rbt_pair_t xnil; /**< internal nil node */ - stix_oow_t size; /**< number of pairs */ + stix_oow_t size; /**< number of pairs */ stix_rbt_pair_t* root; /**< root pair */ }; @@ -293,8 +293,8 @@ STIX_EXPORT const stix_rbt_style_t* stix_getrbtstyle ( * @return stix_rbt_t pointer on success, STIX_NULL on failure. */ STIX_EXPORT stix_rbt_t* stix_rbt_open ( - stix_mmgr_t* mmgr, /**< memory manager */ - stix_oow_t xtnsize, /**< extension size in bytes */ + stix_t* stix, + stix_oow_t xtnsize, /**< extension size in bytes */ int kscale, /**< key scale */ int vscale /**< value scale */ ); @@ -311,7 +311,7 @@ STIX_EXPORT void stix_rbt_close ( */ STIX_EXPORT int stix_rbt_init ( stix_rbt_t* rbt, /**< red-black tree */ - stix_mmgr_t* mmgr, /**< memory manager */ + stix_t* stix, int kscale, /**< key scale */ int vscale /**< value scale */ ); @@ -323,10 +323,6 @@ STIX_EXPORT void stix_rbt_fini ( stix_rbt_t* rbt /**< red-black tree */ ); -STIX_EXPORT stix_mmgr_t* stix_rbt_getmmgr ( - stix_rbt_t* rbt -); - STIX_EXPORT void* stix_rbt_getxtn ( stix_rbt_t* rbt ); diff --git a/stix/lib/stix.c b/stix/lib/stix.c index 2ccda0c..b24a417 100644 --- a/stix/lib/stix.c +++ b/stix/lib/stix.c @@ -31,7 +31,7 @@ stix_t* stix_open (stix_mmgr_t* mmgr, stix_oow_t xtnsize, stix_oow_t heapsize, c stix_t* stix; /* if this assertion fails, correct the type definition in stix.h */ - STIX_ASSERT (STIX_SIZEOF(stix_oow_t) == STIX_SIZEOF(stix_oop_t)); + STIX_ASSERT (stix, STIX_SIZEOF(stix_oow_t) == STIX_SIZEOF(stix_oop_t)); stix = STIX_MMGR_ALLOC (mmgr, STIX_SIZEOF(*stix) + xtnsize); if (stix) @@ -84,6 +84,8 @@ static void fill_bigint_tables (stix_t* stix) 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 (); @@ -102,18 +104,20 @@ int stix_init (stix_t* stix, stix_mmgr_t* mmgr, stix_oow_t heapsz, const stix_vm stix->newheap = stix_makeheap (stix, heapsz); if (!stix->newheap) goto oops; - if (stix_rbt_init (&stix->modtab, mmgr, STIX_SIZEOF(stix_ooch_t), 1) <= -1) 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_RSRC] = &stix->_resource; + 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); @@ -126,7 +130,7 @@ static stix_rbt_walk_t unload_module (stix_rbt_t* rbt, stix_rbt_pair_t* pair, vo stix_mod_data_t* mdp; mdp = STIX_RBT_VPTR(pair); - STIX_ASSERT (mdp != STIX_NULL); + STIX_ASSERT (stix, mdp != STIX_NULL); mdp->pair = STIX_NULL; /* to prevent stix_closemod() from calling stix_rbt_delete() */ stix_closemod (stix, mdp); @@ -166,14 +170,6 @@ void stix_fini (stix_t* stix) stix_killheap (stix, stix->curheap); stix_killheap (stix, stix->permheap); - if (stix->rsrc.ptr) - { - stix_freemem (stix, stix->rsrc.ptr); - stix->rsrc.free = 0; - stix->rsrc.capa = 0; - stix->rsrc.ptr = STIX_NULL; - } - /* deregister all callbacks */ while (stix->cblist) stix_deregcb (stix, stix->cblist); @@ -374,65 +370,6 @@ void stix_freemem (stix_t* stix, void* ptr) /* -------------------------------------------------------------------------- */ -/* TODO: remove RSRS code. so far, i find this not useful */ -stix_oop_t stix_makersrc (stix_t* stix, stix_oow_t v) -{ - stix_oop_t imm; - stix_oow_t avail; - - if (stix->rsrc.free >= stix->rsrc.capa) - { - stix_oow_t* tmp; - stix_ooi_t newcapa, i; - - newcapa = stix->rsrc.capa + 256; - - tmp = stix_reallocmem (stix, stix->rsrc.ptr, STIX_SIZEOF(*tmp) * newcapa); - if (!tmp) return STIX_NULL; - - for (i = stix->rsrc.capa; i < newcapa; i++) tmp[i] = i + 1; - stix->rsrc.free = i; - stix->rsrc.ptr = tmp; - stix->rsrc.capa = newcapa; - } - - avail = stix->rsrc.free; - stix->rsrc.free = stix->rsrc.ptr[stix->rsrc.free]; - stix->rsrc.ptr[avail] = v; - - /* there must not be too many immedates in the whole system. */ - STIX_ASSERT (STIX_IN_SMOOI_RANGE(avail)); - return STIX_RSRC_TO_OOP(avail); - - return imm; -} - -void stix_killrsrc (stix_t* stix, stix_oop_t imm) -{ - if (STIX_OOP_IS_RSRC(stix)) - { - stix_ooi_t v; - - v = STIX_OOP_TO_RSRC(stix); - - /* the value of v, if properly created by stix_makeimm(), must - * fall in the following range. when storing and loading the values - * from an image file, you must take extra care not to break this - * assertion */ - STIX_ASSERT (v >= 0 && v < stix->rsrc.capa); - stix->rsrc.ptr[v] = stix->rsrc.free; - stix->rsrc.free = v; - } -} - -stix_oow_t stix_getrsrcval (stix_t* stix, stix_oop_t imm) -{ - STIX_ASSERT (STIX_OOP_IS_RSRC(imm)); - return stix->rsrc.ptr[STIX_OOP_TO_RSRC(imm)]; -} - -/* -------------------------------------------------------------------------- */ - #define MOD_PREFIX "stix_mod_" #define MOD_PREFIX_LEN 9 @@ -566,7 +503,7 @@ stix_mod_data_t* stix_openmod (stix_t* stix, const stix_ooch_t* name, stix_oow_t STIX_DEBUG2 (stix, "Opened a module [%S] - %p\n", mdp->mod.name, mdp->handle); /* the module loader must ensure to set a proper query handler */ - STIX_ASSERT (mdp->mod.query != STIX_NULL); + STIX_ASSERT (stix, mdp->mod.query != STIX_NULL); return mdp; } @@ -604,7 +541,7 @@ int stix_importmod (stix_t* stix, stix_oop_t _class, const stix_ooch_t* name, st if (pair) { mdp = (stix_mod_data_t*)STIX_RBT_VPTR(pair); - STIX_ASSERT (mdp != STIX_NULL); + STIX_ASSERT (stix, mdp != STIX_NULL); } else { @@ -673,7 +610,7 @@ stix_pfimpl_t stix_querymod (stix_t* stix, const stix_ooch_t* pfid, stix_oow_t p if (pair) { mdp = (stix_mod_data_t*)STIX_RBT_VPTR(pair); - STIX_ASSERT (mdp != STIX_NULL); + STIX_ASSERT (stix, mdp != STIX_NULL); } else { @@ -709,13 +646,13 @@ int stix_genpfmethod (stix_t* stix, stix_mod_t* mod, stix_oop_t _class, stix_met stix_ooi_t preamble_flags = 0; static stix_ooch_t dot[] = { '.', '\0' }; - STIX_ASSERT (STIX_CLASSOF(stix, _class) == stix->_class); + 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_CLASSOF(stix, (stix_oop_t)cls->mthdic[type]) == stix->_method_dictionary); + STIX_ASSERT (stix, STIX_CLASSOF(stix, (stix_oop_t)cls->mthdic[type]) == stix->_method_dictionary); for (i = 0; mthname[i]; i++) { @@ -808,3 +745,66 @@ oops: return -1; } +/* -------------------------------------------------------------------------- + * SYSTEM DEPENDENT FUNCTIONS - TODO: MOVE THESE ELSE WHERE.......... + * -------------------------------------------------------------------------- */ +#include +#include +#include + +stix_errnum_t stix_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; + #if defined(EAGAIN) && defined(EWOULDBLOCK) && (EAGAIN != EWOULDBLOCK) + case EAGAIN: + case EWOULDBLOCK: return STIX_EAGAIN; + #elif defined(EAGAIN) + case EAGAIN: return STIX_EAGAIN; + #elif defined(EWOULDBLOCK) + case EWOULDBLOCK: return STIX_EAGAIN; + #endif + default: return STIX_ESYSERR; + } +} + +void stix_assertfailed (stix_t* stix, const stix_bch_t* expr, const stix_bch_t* file, stix_oow_t line) +{ + stix_logbfmt (stix, STIX_LOG_DEBUG, "ASSERTION FAILURE: %s at %s:%zu\n", expr, file, line); + + +#if defined(_WIN32) + ExitProcess (249); +#elif defined(__OS2__) + DosExit (EXIT_PROCESS, 249); +#elif defined(__DOS__) + { + union REGS regs; + regs.h.ah = DOS_EXIT; + regs.h.al = 249; + intdos (®s, ®s); + } +#elif defined(vms) || defined(__vms) + lib$stop (SS$_ABORT); /* use SS$_OPCCUS instead? */ + + /* this won't be reached since lib$stop() terminates the process */ + sys$exit (SS$_ABORT); /* this condition code can be shown with + * 'show symbol $status' from the command-line. */ +#elif defined(macintosh) + ExitToShell (); +#else + kill (getpid(), SIGABRT); + _exit (1); +#endif + +} diff --git a/stix/lib/stix.h b/stix/lib/stix.h index 7a6589e..9e65082 100644 --- a/stix/lib/stix.h +++ b/stix/lib/stix.h @@ -51,8 +51,17 @@ enum stix_errnum_t STIX_EINTERN, /**< internal error */ STIX_ESYSMEM, /**< insufficient system memory */ STIX_EOOMEM, /**< insufficient object memory */ + STIX_EINVAL, /**< invalid parameter or data */ 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 */ @@ -188,7 +197,7 @@ typedef enum stix_method_type_t stix_method_type_t; #define STIX_OOP_TAG_BITS 2 #define STIX_OOP_TAG_SMINT 1 #define STIX_OOP_TAG_CHAR 2 -#define STIX_OOP_TAG_RSRC 3 +#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) @@ -196,16 +205,14 @@ typedef enum stix_method_type_t stix_method_type_t; #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_RSRC(oop) (STIX_OOP_GET_TAG(oop) == STIX_OOP_TAG_RSRC) +#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) - -/* RSRC(resurce) is a index to the VM's resource table(stix->rsrc.ptr) */ -#define STIX_RSRC_TO_OOP(num) ((stix_oop_t)((((stix_oow_t)(num)) << STIX_OOP_TAG_BITS) | STIX_OOP_TAG_RSRC)) -#define STIX_OOP_TO_RSRC(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 @@ -660,14 +667,8 @@ struct stix_process_scheduler_t * 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_IS_SMOOI(oop)? (stix)->_small_integer: \ - STIX_OOP_IS_CHAR(oop)? (stix)->_character: STIX_OBJ_GET_CLASS(oop) \ -) -* */ #define STIX_CLASSOF(stix,oop) \ - (STIX_OOP_GET_TAG(oop)? *stix->tagged_classes[STIX_OOP_GET_TAG(oop)]: STIX_OBJ_GET_CLASS(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 @@ -692,8 +693,6 @@ struct stix_heap_t stix_uint8_t* ptr; /* next allocation pointer */ }; -typedef struct stix_t stix_t; - /* ========================================================================= * VIRTUAL MACHINE PRIMITIVES * ========================================================================= */ @@ -788,11 +787,13 @@ struct stix_mod_data_t }; 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; + stix_oow_t len; + stix_oow_t capa; }; typedef struct stix_sbuf_t stix_sbuf_t; @@ -837,13 +838,18 @@ struct stix_t 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; - /* == NEVER CHANGE THE ORDER OF FIELDS BELOW == */ - /* stix_ignite() assumes this order. make sure to update symnames in ignite_3() */ + /* ============================================================= + * 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 */ @@ -867,17 +873,22 @@ struct stix_t 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 + * ============================================================= */ - stix_oop_t _resource; - /* == NEVER CHANGE THE ORDER OF FIELDS ABOVE == */ - + /* ============================================================= + * 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 */ @@ -897,7 +908,9 @@ struct stix_t stix_oop_t* tmp_stack[256]; /* stack for temporaries */ stix_oow_t tmp_count; - /* == EXECUTION REGISTERS == */ + /* ============================================================= + * EXECUTION REGISTERS + * ============================================================= */ stix_oop_context_t initial_context; /* fake initial context */ stix_oop_context_t active_context; stix_oop_method_t active_method; @@ -907,7 +920,9 @@ struct stix_t 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 == */ + /* ============================================================= + * END EXECUTION REGISTERS + * ============================================================= */ /* == BIGINT CONVERSION == */ struct @@ -917,15 +932,6 @@ struct stix_t } bigint[37]; /* == END BIGINT CONVERSION == */ - /* == RSRC MANAGEMENT == */ - struct - { - stix_oow_t* ptr; - stix_oow_t free; - stix_oow_t capa; - } rsrc; - /* == END RSRC MANAGEMENT == */ - stix_sbuf_t sbuf[64]; #if defined(STIX_INCLUDE_COMPILER) @@ -958,7 +964,7 @@ struct stix_t * 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,ec) (STIX_STACK_POPS(stix, nargs), STIX_STACK_SETTOP(stix, STIX_ERROR_TO_OOP(ec))) /* ========================================================================= * STIX VM LOGGING @@ -1010,15 +1016,13 @@ typedef enum stix_log_mask_t stix_log_mask_t; /* ========================================================================= * STIX ASSERTION * ========================================================================= */ -#if 0 #if defined(NDEBUG) -# define STIX_ASSERT(expr) ((void)0) +# define STIX_ASSERT(stix,expr) ((void)0) #else -# define STIX_ASSERT(expr) (void)((expr) || \ - (stix_logbfmt ("%s at %s:%d", #expr, __FILE__, (int)__LINE__), 0)) -#endif +# define STIX_ASSERT(stix,expr) ((void)((expr) || (stix_assertfailed (stix, #expr, __FILE__, __LINE__), 0))) #endif + #if defined(__cplusplus) extern "C" { #endif @@ -1181,28 +1185,23 @@ STIX_EXPORT void stix_poptmps ( stix_oow_t count ); -STIX_EXPORT int stix_decode ( - stix_t* stix, - stix_oop_method_t mth, - const stix_oocs_t* classfqn -); - -/* Memory allocation/deallocation functions using stix's MMGR */ - +/* ========================================================================= + * SYSTEM MEMORY MANAGEMENT FUCNTIONS VIA MMGR + * ========================================================================= */ STIX_EXPORT void* stix_allocmem ( stix_t* stix, - stix_oow_t size + stix_oow_t size ); STIX_EXPORT void* stix_callocmem ( stix_t* stix, - stix_oow_t size + stix_oow_t size ); STIX_EXPORT void* stix_reallocmem ( stix_t* stix, void* ptr, - stix_oow_t size + stix_oow_t size ); STIX_EXPORT void stix_freemem ( @@ -1272,6 +1271,28 @@ STIX_EXPORT stix_ooi_t stix_logoofmt ( ... ); +/* ========================================================================= + * 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 e +); + + #if defined(__cplusplus) } #endif diff --git a/stix/lib/sym.c b/stix/lib/sym.c index 5d329f2..20b9111 100644 --- a/stix/lib/sym.c +++ b/stix/lib/sym.c @@ -70,8 +70,8 @@ static stix_oop_oop_t expand_bucket (stix_t* stix, stix_oop_oop_t oldbuc) symbol = (stix_oop_char_t)oldbuc->slot[--oldsz]; if ((stix_oop_t)symbol != stix->_nil) { - STIX_ASSERT (STIX_CLASSOF(stix,symbol) == stix->_symbol); - /*STIX_ASSERT (sym->size > 0);*/ + STIX_ASSERT (stix, STIX_CLASSOF(stix,symbol) == stix->_symbol); + /*STIX_ASSERT (stix, sym->size > 0);*/ index = stix_hashchars(symbol->slot, STIX_OBJ_GET_SIZE(symbol)) % newsz; while (newbuc->slot[index] != stix->_nil) index = (index + 1) % newsz; @@ -88,7 +88,7 @@ static stix_oop_t find_or_make_symbol (stix_t* stix, const stix_ooch_t* ptr, sti stix_oow_t index; stix_oop_char_t symbol; - STIX_ASSERT (len > 0); + STIX_ASSERT (stix, len > 0); if (len <= 0) { /* i don't allow an empty symbol name */ @@ -96,14 +96,14 @@ static stix_oop_t find_or_make_symbol (stix_t* stix, const stix_ooch_t* ptr, sti return STIX_NULL; } - STIX_ASSERT (STIX_CLASSOF(stix,stix->symtab->bucket) == stix->_array); + STIX_ASSERT (stix, STIX_CLASSOF(stix,stix->symtab->bucket) == stix->_array); index = stix_hashchars(ptr, len) % STIX_OBJ_GET_SIZE(stix->symtab->bucket); /* find a matching symbol in the open-addressed symbol table */ while (stix->symtab->bucket->slot[index] != stix->_nil) { symbol = (stix_oop_char_t)stix->symtab->bucket->slot[index]; - STIX_ASSERT (STIX_CLASSOF(stix,symbol) == (stix_oop_t)stix->_symbol); + STIX_ASSERT (stix, STIX_CLASSOF(stix,symbol) == (stix_oop_t)stix->_symbol); if (len == STIX_OBJ_GET_SIZE(symbol) && stix_equaloochars (ptr, symbol->slot, len)) @@ -121,7 +121,7 @@ static stix_oop_t find_or_make_symbol (stix_t* stix, const stix_ooch_t* ptr, sti } /* make a new symbol and insert it */ - STIX_ASSERT (STIX_OOP_IS_SMOOI(stix->symtab->tally)); + STIX_ASSERT (stix, STIX_OOP_IS_SMOOI(stix->symtab->tally)); tally = STIX_OOP_TO_SMOOI(stix->symtab->tally); if (tally >= STIX_SMOOI_MAX) { @@ -163,7 +163,7 @@ static stix_oop_t find_or_make_symbol (stix_t* stix, const stix_ooch_t* ptr, sti symbol = (stix_oop_char_t)stix_instantiate(stix, stix->_symbol, ptr, len); if (symbol) { - STIX_ASSERT (tally < STIX_SMOOI_MAX); + 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; } diff --git a/stix/lib/utf8.c b/stix/lib/utf8.c index 0726284..5e491a5 100644 --- a/stix/lib/utf8.c +++ b/stix/lib/utf8.c @@ -64,8 +64,8 @@ static STIX_INLINE __utf8_t* get_utf8_slot (stix_uch_t uc) { __utf8_t* cur, * end; - STIX_ASSERT (STIX_SIZEOF(stix_bch_t) == 1); - STIX_ASSERT (STIX_SIZEOF(stix_uch_t) >= 2); + /*STIX_ASSERT (stix, STIX_SIZEOF(stix_bch_t) == 1); + STIX_ASSERT (stix, STIX_SIZEOF(stix_uch_t) >= 2);*/ end = utf8_table + STIX_COUNTOF(utf8_table); cur = utf8_table; @@ -110,10 +110,10 @@ stix_oow_t stix_utf8touc (const stix_bch_t* utf8, stix_oow_t size, stix_uch_t* u { __utf8_t* cur, * end; - STIX_ASSERT (utf8 != STIX_NULL); - STIX_ASSERT (size > 0); - STIX_ASSERT (STIX_SIZEOF(stix_bch_t) == 1); - STIX_ASSERT (STIX_SIZEOF(stix_uch_t) >= 2); + /*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);*/ end = utf8_table + STIX_COUNTOF(utf8_table); cur = utf8_table; @@ -176,4 +176,3 @@ stix_oow_t stix_utf8touc (const stix_bch_t* utf8, stix_oow_t size, stix_uch_t* u return 0; /* error - invalid sequence */ } - diff --git a/stix/lib/utl.c b/stix/lib/utl.c index df6cc60..dba684a 100644 --- a/stix/lib/utl.c +++ b/stix/lib/utl.c @@ -275,7 +275,6 @@ int stix_copyoocstrtosbuf (stix_t* stix, const stix_ooch_t* str, int id) } - /* ----------------------------------------------------------------------- */ static STIX_INLINE int bcsn_to_ucsn_with_cmgr ( @@ -477,7 +476,7 @@ static STIX_INLINE int ucsn_to_bcsn_with_cmgr ( } /* it assumes that bcsbuf is large enough to hold a character */ - STIX_ASSERT (n <= STIX_COUNTOF(bcsbuf)); + /*STIX_ASSERT (stix, n <= STIX_COUNTOF(bcsbuf));*/ p++; mlen += n; } @@ -559,7 +558,7 @@ static int ucs_to_bcs_with_cmgr ( } /* it assumes that bcs is large enough to hold a character */ - STIX_ASSERT (n <= STIX_COUNTOF(bcs)); + /*STIX_ASSERT (stix, n <= STIX_COUNTOF(bcs));*/ p++; mlen += n; } @@ -639,4 +638,3 @@ int stix_ucstobcs (stix_t* stix, const stix_uch_t* ucs, stix_oow_t* ucslen, stix return ucsn_to_bcsn_with_cmgr (ucs, ucslen, bcs, bcslen, stix->cmgr); } } - diff --git a/stix/mod/console.c b/stix/mod/console.c index 655b7c5..fd427fb 100644 --- a/stix/mod/console.c +++ b/stix/mod/console.c @@ -66,7 +66,6 @@ static int pf_open (stix_t* stix, stix_ooi_t nargs) /* error */ } - rsrc = stix_makersrc (stix, h); #else diff --git a/stix/mod/stdio.c b/stix/mod/stdio.c index f5a4eb8..99f27b4 100644 --- a/stix/mod/stdio.c +++ b/stix/mod/stdio.c @@ -29,12 +29,9 @@ #include #include +#include #include -/* TODO: remvoe this assert use one defined in stix.h */ -#include -#define STIX_ASSERT(x) assert(x) - typedef struct stdio_t stdio_t; struct stdio_t { @@ -84,7 +81,8 @@ static int pf_open (stix_t* stix, stix_ooi_t nargs) if (!rcv->fp) { STIX_DEBUG2 (stix, "cannot open %s for %s\n", namebuf, modebuf); - return -1; /* TODO: return success with an object instead... */ + STIX_STACK_SETRETTOERROR (stix, nargs, stix_syserrtoerrnum(errno)); + return 1; } STIX_DEBUG3 (stix, "opened %s for %s - %p\n", namebuf, modebuf, rcv->fp); @@ -119,8 +117,6 @@ static int pf_puts (stix_t* stix, stix_ooi_t nargs) { stdio_t* rcv; stix_ooi_t i; - - rcv = (stdio_t*)STIX_STACK_GETRCV(stix, nargs); @@ -133,7 +129,7 @@ static int pf_puts (stix_t* stix, stix_ooi_t nargs) if (STIX_OOP_IS_CHAR(x)) { /* do some faking. */ - STIX_ASSERT (STIX_SIZEOF(tmpc) >= STIX_SIZEOF(stix_obj_t) + STIX_SIZEOF(stix_ooch_t)); + STIX_ASSERT (stix, STIX_SIZEOF(tmpc) >= STIX_SIZEOF(stix_obj_t) + STIX_SIZEOF(stix_ooch_t)); tmpc.slot[0] = STIX_OOP_TO_CHAR(x); x = (stix_oop_char_t)&tmpc;