diff --git a/stix/kernel/Stix.st b/stix/kernel/Stix.st index b8f314b..96aeb2a 100644 --- a/stix/kernel/Stix.st +++ b/stix/kernel/Stix.st @@ -115,6 +115,19 @@ { } +#class(#halfword) LargeInteger(Number) +{ +} + +#class(#halfword) LargePositiveInteger(LargeInteger) +{ +} + +#class(#halfword) LargeNegativeInteger(LargeInteger) +{ +} + + #include 'Collection.st'. #include 'Collection-ByteArray.st'. #include 'Collection-Array.st'. diff --git a/stix/lib/Makefile.am b/stix/lib/Makefile.am index dd60648..dee8116 100644 --- a/stix/lib/Makefile.am +++ b/stix/lib/Makefile.am @@ -46,6 +46,7 @@ libstix_la_SOURCES = \ sym.c \ dic.c \ proc.c \ + bigint.c \ ignite.c \ utf8.c \ comp.c \ diff --git a/stix/lib/Makefile.in b/stix/lib/Makefile.in index 69680b3..0bfc4b9 100644 --- a/stix/lib/Makefile.in +++ b/stix/lib/Makefile.in @@ -126,8 +126,9 @@ libstix_la_DEPENDENCIES = $(am__DEPENDENCIES_2) am_libstix_la_OBJECTS = libstix_la-stix-rbt.lo libstix_la-stix-utl.lo \ libstix_la-stix.lo libstix_la-heap.lo libstix_la-gc.lo \ libstix_la-obj.lo libstix_la-sym.lo libstix_la-dic.lo \ - libstix_la-proc.lo libstix_la-ignite.lo libstix_la-utf8.lo \ - libstix_la-comp.lo libstix_la-exec.lo libstix_la-debug.lo + libstix_la-proc.lo libstix_la-bigint.lo libstix_la-ignite.lo \ + libstix_la-utf8.lo libstix_la-comp.lo libstix_la-exec.lo \ + libstix_la-debug.lo libstix_la_OBJECTS = $(am_libstix_la_OBJECTS) libstix_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ @@ -381,6 +382,7 @@ libstix_la_SOURCES = \ sym.c \ dic.c \ proc.c \ + bigint.c \ ignite.c \ utf8.c \ comp.c \ @@ -588,6 +590,7 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-bigint.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-comp.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-debug.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstix_la-dic.Plo@am__quote@ @@ -696,6 +699,13 @@ libstix_la-proc.lo: proc.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-proc.lo `test -f 'proc.c' || echo '$(srcdir)/'`proc.c +libstix_la-bigint.lo: bigint.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstix_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libstix_la-bigint.lo -MD -MP -MF $(DEPDIR)/libstix_la-bigint.Tpo -c -o libstix_la-bigint.lo `test -f 'bigint.c' || echo '$(srcdir)/'`bigint.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstix_la-bigint.Tpo $(DEPDIR)/libstix_la-bigint.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='bigint.c' object='libstix_la-bigint.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstix_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libstix_la-bigint.lo `test -f 'bigint.c' || echo '$(srcdir)/'`bigint.c + 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 diff --git a/stix/lib/bigint.c b/stix/lib/bigint.c new file mode 100644 index 0000000..fbdb0cc --- /dev/null +++ b/stix/lib/bigint.c @@ -0,0 +1,213 @@ + +#include "stix-prv.h" + +/*static normalize_integer (*/ + +static stix_oop_t normalize (stix_t* stix, stix_oop_t z) +{ + return z; +} + +static STIX_INLINE int is_less_unsigned_array (const stix_oohw_t* x, stix_oow_t xs, const stix_oohw_t* y, stix_oow_t ys) +{ + stix_oow_t i; + + if (xs != ys) return xs < ys; + for (i = xs; i > 0; ) + { + --i; + if (x[i] != y[i]) return x[i] < y[i]; + } + + return 0; +} + +static STIX_INLINE int is_less_unsigned (stix_oop_t x, stix_oop_t y) +{ + return is_less_unsigned_array ( + ((stix_oop_halfword_t)x)->slot, STIX_OBJ_GET_SIZE(x), + ((stix_oop_halfword_t)y)->slot, STIX_OBJ_GET_SIZE(y)); +} + +static STIX_INLINE int is_less (stix_t* stix, stix_oop_t x, stix_oop_t y) +{ + if (STIX_OBJ_GET_CLASS(x) != STIX_OBJ_GET_CLASS(y)) + { + return STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer; + } + + return is_less_unsigned (x, y); +} + +static STIX_INLINE int is_equal (stix_t* stix, stix_oop_t x, stix_oop_t y) +{ + /* check if two large integers are equal to each other */ + return STIX_OBJ_GET_CLASS(x) == STIX_OBJ_GET_CLASS(y) && STIX_OBJ_GET_SIZE(x) == STIX_OBJ_GET_SIZE(y) && + STIX_MEMCMP(((stix_oop_halfword_t)x)->slot, ((stix_oop_halfword_t)y)->slot, STIX_OBJ_GET_SIZE(x) * STIX_SIZEOF(stix_oohw_t)) == 0; +} + +static STIX_INLINE stix_oow_t add_unsigned_array (const stix_oohw_t* x, stix_oow_t xs, const stix_oohw_t* y, stix_oow_t ys, stix_oohw_t* z) +{ + stix_oow_t i, w; + stix_oow_t carry = 0; + + STIX_ASSERT (xs >= ys); + + for (i = 0; i < ys; i++) + { + w = (stix_oow_t)x[i] + (stix_oow_t)y[i] + carry; + carry = w >> STIX_OOHW_BITS; + z[i] = w & STIX_LBMASK(stix_oow_t, STIX_OOHW_BITS); + } + + for (; i < xs; i++) + { + w = (stix_oow_t)x[i] + carry; + carry = w >> STIX_OOHW_BITS; + z[i] = w & STIX_LBMASK(stix_oow_t, STIX_OOHW_BITS); + } + + if (i > 1 && carry == 0) return i - 1; + z[i] = carry; + return i; +} + + +static STIX_INLINE stix_oow_t subtract_unsigned_array (const stix_oohw_t* x, stix_oow_t xs, const stix_oohw_t* y, stix_oow_t ys, stix_oohw_t* z) +{ + stix_oow_t i, w; + stix_oow_t borrow = 0; + stix_oow_t borrowed_word; + + STIX_ASSERT (!is_less_unsigned_array(x, xs, y, ys)); + + borrowed_word = (stix_oow_t)1 << STIX_OOHW_BITS; + for (i = 0; i < ys; i++) + { + w = (stix_oow_t)y[i] + borrow; + if ((stix_oow_t)x[i] >= w) + { + z[i] = x[i] - w; + borrow = 0; + } + else + { + z[i] = (borrowed_word + (stix_oow_t)x[i]) - w; + borrow = 1; + } + } + + for (; i < xs; i++) + { + if (x[i] >= borrow) + { + z[i] = x[i] - (stix_oohw_t)borrow; + borrow = 0; + } + else + { + z[i] = (borrowed_word + (stix_oow_t)x[i]) - borrow; + borrow = 1; + } + } + + STIX_ASSERT (borrow == 0); + return i; +} + +static stix_oop_t add_unsigned_integers (stix_t* stix, stix_oop_t x, stix_oop_t y) +{ + stix_oohw_t* a, * b; + stix_oow_t as, bs, zs, ks; + stix_oop_t z; + + as = STIX_OBJ_GET_SIZE(x); + bs = STIX_OBJ_GET_SIZE(y); + zs = (as >= bs? as: bs) + 1; + + stix_pushtmp (stix, &x); + stix_pushtmp (stix, &y); + z = stix_instantiate (stix, STIX_OBJ_GET_CLASS(x), STIX_NULL, zs); + stix_poptmps (stix, 2); + + if (as >= bs) + { + a = ((stix_oop_halfword_t)x)->slot; + b = ((stix_oop_halfword_t)y)->slot; + } + else + { + a = ((stix_oop_halfword_t)y)->slot; + b = ((stix_oop_halfword_t)x)->slot; + } + + ks = add_unsigned_array (a, as, b, bs, ((stix_oop_halfword_t)z)->slot); + if (ks <= zs) + { + /*normalize;*/ + } + + return z; +} + +static stix_oop_t subtract_unsigned_integers (stix_t* stix, stix_oop_t x, stix_oop_t y) +{ + stix_oop_t z; + + stix_pushtmp (stix, &x); + stix_pushtmp (stix, &y); + z = stix_instantiate (stix, stix->_large_positive_integer, STIX_NULL, STIX_OBJ_GET_SIZE(x)); + stix_poptmps (stix, 2); + + subtract_unsigned_array ( + ((stix_oop_halfword_t)x)->slot, STIX_OBJ_GET_SIZE(x), + ((stix_oop_halfword_t)y)->slot, STIX_OBJ_GET_SIZE(y), + ((stix_oop_halfword_t)z)->slot); + return z; +} + + +stix_oop_t stix_addbigints (stix_t* stix, stix_oop_t x, stix_oop_t y) +{ + stix_oop_t z; + + if (STIX_OBJ_GET_CLASS(x) != STIX_OBJ_GET_CLASS(y)) + { + if (STIX_OBJ_GET_CLASS(x) == stix->_large_negative_integer) + z = stix_subbigints (stix, y, x); + else + z = stix_subbigints (stix, x, y); + } + else + { + z = add_unsigned_integers (stix, x, y); + } + + return normalize(stix, z); +} + +#if 0 +stix_subbigints (stix_t* stix, stix_oop_t x, stix_oop_t y) +{ +/* TOOD: ensure both are LargeIntgers */ + + if (STIX_OBJ_GET_CLASS(x) != STIX_OBJ_GET_CLASS(y)) + { + z = add_unsigned (stix, x, y); + } + else + { + if (is_less_unsigned (x, y)) + { + z = subtract_unsigned (stix, y, x); /* get the opposite sign of x; */ + } + else + { + + z = subtract_unsigned (stix, x, y); /* take x's sign */ + } + } + + return normalize (stix, z); +} +#endif diff --git a/stix/lib/comp.c b/stix/lib/comp.c index 33e2d7e..dddff80 100644 --- a/stix/lib/comp.c +++ b/stix/lib/comp.c @@ -89,6 +89,7 @@ static struct voca_t { 7, { 'd','e','c','l','a','r','e' } }, { 6, { 'e','x','t','e','n','d' } }, { 5, { 'f','a','l','s','e' } }, + { 8, { 'h','a','l','f','w','o','r','d' } }, { 7, { 'i','n','c','l','u','d','e' } }, { 4, { 'm','a','i','n' } }, { 6, { 'm','e','t','h','o','d' } }, @@ -120,6 +121,7 @@ enum voca_id_t VOCA_DECLARE, VOCA_EXTEND, VOCA_FALSE, + VOCA_HALFWORD, VOCA_INCLUDE, VOCA_MAIN, VOCA_METHOD, @@ -1582,14 +1584,14 @@ static int end_include (stix_t* stix) * Byte-Code Generator * --------------------------------------------------------------------- */ -static STIX_INLINE int emit_byte_instruction (stix_t* stix, stix_byte_t code) +static STIX_INLINE int emit_byte_instruction (stix_t* stix, stix_oob_t code) { stix_size_t i; i = stix->c->mth.code.len + 1; if (i > stix->c->mth.code_capa) { - stix_byte_t* tmp; + stix_oob_t* tmp; i = STIX_ALIGN (i, CODE_BUFFER_ALIGN); @@ -1606,7 +1608,7 @@ static STIX_INLINE int emit_byte_instruction (stix_t* stix, stix_byte_t code) static int emit_single_param_instruction (stix_t* stix, int cmd, stix_oow_t param_1) { - stix_byte_t bc; + stix_oob_t bc; switch (cmd) { @@ -1619,7 +1621,7 @@ static int emit_single_param_instruction (stix_t* stix, int cmd, stix_oow_t para case BCODE_PUSH_LITERAL_0: if (param_1 < 8) { - bc = (stix_byte_t)(cmd & 0xF8) | (stix_byte_t)param_1; + bc = (stix_oob_t)(cmd & 0xF8) | (stix_oob_t)param_1; goto write_short; } else @@ -1638,7 +1640,7 @@ static int emit_single_param_instruction (stix_t* stix, int cmd, stix_oow_t para case BCODE_JUMP_IF_FALSE_0: if (param_1 < 4) { - bc = (stix_byte_t)(cmd & 0xFC) | (stix_byte_t)param_1; + bc = (stix_oob_t)(cmd & 0xFC) | (stix_oob_t)param_1; goto write_short; } else @@ -1678,7 +1680,7 @@ write_long: static int emit_double_param_instruction (stix_t* stix, int cmd, stix_size_t param_1, stix_size_t param_2) { - stix_byte_t bc; + stix_oob_t bc; switch (cmd) { @@ -1693,7 +1695,7 @@ static int emit_double_param_instruction (stix_t* stix, int cmd, stix_size_t par if (param_1 < 8 && param_2 < 0xFF) { /* low 2 bits of the instruction code is the first parameter */ - bc = (stix_byte_t)(cmd & 0xFC) | (stix_byte_t)param_1; + bc = (stix_oob_t)(cmd & 0xFC) | (stix_oob_t)param_1; goto write_short; } else @@ -3073,15 +3075,15 @@ printf ("\tfixed jump offset to %u\n", (unsigned int)jump_offset); } -static int add_to_balit_buffer (stix_t* stix, stix_byte_t b) +static int add_to_balit_buffer (stix_t* stix, stix_oob_t b) { if (stix->c->mth.balit_count >= stix->c->mth.balit_capa) { - stix_byte_t* tmp; + stix_oob_t* tmp; stix_size_t new_capa; new_capa = STIX_ALIGN (stix->c->mth.balit_count + 1, BALIT_BUFFER_ALIGN); - tmp = (stix_byte_t*)stix_reallocmem (stix, stix->c->mth.balit, new_capa * STIX_SIZEOF(*tmp)); + tmp = (stix_oob_t*)stix_reallocmem (stix, stix->c->mth.balit, new_capa * STIX_SIZEOF(*tmp)); if (!tmp) return -1; stix->c->mth.balit_capa = new_capa; @@ -3563,7 +3565,7 @@ printf ("\tpush int literal\n"); return 0; } -static stix_byte_t send_message_cmd[] = +static stix_oob_t send_message_cmd[] = { BCODE_SEND_MESSAGE_0, BCODE_SEND_MESSAGE_TO_SUPER_0 @@ -4472,6 +4474,13 @@ static int __compile_class_definition (stix_t* stix, int extend) stix->c->cls.indexed_type = STIX_OBJ_TYPE_CHAR; GET_TOKEN (stix); } + else if (is_token_symbol(stix, VOCA_HALFWORD)) + { + /* #class(#halfword) */ + stix->c->cls.flags |= CLASS_INDEXED; + stix->c->cls.indexed_type = STIX_OBJ_TYPE_HALFWORD; + GET_TOKEN (stix); + } else if (is_token_symbol(stix, VOCA_WORD)) { /* #class(#word) */ diff --git a/stix/lib/debug.c b/stix/lib/debug.c index b407df7..4f6f6f1 100644 --- a/stix/lib/debug.c +++ b/stix/lib/debug.c @@ -278,6 +278,15 @@ static void __dump_object (stix_t* stix, stix_oop_t oop, int depth) } printf ("]"); } + else if (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_HALFWORD) + { + printf (" #["); /* TODO: different symbol for word array ?? */ + for (i = 0; i < STIX_OBJ_GET_SIZE(oop); i++) + { + printf (" %ld", (long int)((stix_oop_halfword_t)oop)->slot[i]); + } + printf ("]"); + } else if (STIX_OBJ_GET_FLAGS_TYPE(oop) == STIX_OBJ_TYPE_WORD) { printf (" #["); /* TODO: different symbol for word array ?? */ diff --git a/stix/lib/exec.c b/stix/lib/exec.c index be45f33..113ec07 100644 --- a/stix/lib/exec.c +++ b/stix/lib/exec.c @@ -673,6 +673,11 @@ static int prim_basic_at (stix_t* stix, stix_ooi_t nargs) v = STIX_OOP_FROM_CHAR(((stix_oop_char_t)rcv)->slot[idx]); break; + case STIX_OBJ_TYPE_HALFWORD: + /* TODO: LargeInteger if the halfword is too large */ + v = STIX_OOP_FROM_SMINT(((stix_oop_halfword_t)rcv)->slot[idx]); + break; + case STIX_OBJ_TYPE_WORD: /* TODO: LargeInteger if the word is too large */ v = STIX_OOP_FROM_SMINT(((stix_oop_word_t)rcv)->slot[idx]); @@ -739,7 +744,6 @@ static int prim_basic_at_put (stix_t* stix, stix_ooi_t nargs) /* TOOD: must I check the range of the value? */ ((stix_oop_char_t)rcv)->slot[idx] = STIX_OOP_TO_SMINT(val); break; - case STIX_OBJ_TYPE_CHAR: if (!STIX_OOP_IS_CHAR(val)) @@ -750,14 +754,25 @@ static int prim_basic_at_put (stix_t* stix, stix_ooi_t nargs) ((stix_oop_char_t)rcv)->slot[idx] = STIX_OOP_TO_CHAR(val); break; + case STIX_OBJ_TYPE_HALFWORD: + if (!STIX_OOP_IS_SMINT(val)) + { + /* the value is not a number */ + return 0; + } + + /* if the small integer is too large, it will get truncated */ + ((stix_oop_halfword_t)rcv)->slot[idx] = STIX_OOP_TO_SMINT(val); + break; + case STIX_OBJ_TYPE_WORD: /* TODO: handle largeINteger */ if (!STIX_OOP_IS_SMINT(val)) { - /* the value is not a character */ + /* the value is not a number */ return 0; } - ((stix_oop_char_t)rcv)->slot[idx] = STIX_OOP_TO_SMINT(val); + ((stix_oop_word_t)rcv)->slot[idx] = STIX_OOP_TO_SMINT(val); break; case STIX_OBJ_TYPE_OOP: @@ -1727,7 +1742,7 @@ done: int stix_execute (stix_t* stix) { - stix_byte_t bcode; + stix_oob_t bcode; stix_ooi_t b1, b2; stix_oop_t return_value; diff --git a/stix/lib/gc.c b/stix/lib/gc.c index c5e71e9..0bdee01 100644 --- a/stix/lib/gc.c +++ b/stix/lib/gc.c @@ -289,8 +289,10 @@ void stix_gc (stix_t* stix) 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_integer = stix_moveoop (stix, stix->_large_integer); + + 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); 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); diff --git a/stix/lib/ignite.c b/stix/lib/ignite.c index fbe9167..bb1fbf1 100644 --- a/stix/lib/ignite.c +++ b/stix/lib/ignite.c @@ -62,6 +62,8 @@ * Integer * SmallInteger * LargeInteger + * LargePositiveInteger + * LargeNegativeInteger * * Stix has no instance variables. * Stix has 1 class variable: Sysdic @@ -143,7 +145,8 @@ static int ignite_1 (stix_t* stix) * 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_integer = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 1, STIX_OBJ_TYPE_OOP)); + stix->_large_positive_integer = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 1, STIX_OBJ_TYPE_HALFWORD)); + stix->_large_negative_integer = alloc_kernel_class (stix, 0, STIX_CLASS_SPEC_MAKE(0, 1, STIX_OBJ_TYPE_HALFWORD)); if (!stix->_apex || !stix->_undefined_object || !stix->_object || !stix->_string || @@ -158,7 +161,8 @@ static int ignite_1 (stix_t* stix) !stix->_process || !stix->_process_scheduler || !stix->_true_class || !stix->_false_class || - !stix->_character || !stix->_small_integer || !stix->_large_integer) return -1; + !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; @@ -213,7 +217,7 @@ static int ignite_3 (stix_t* stix) static struct symbol_name_t { stix_oow_t len; - stix_ooch_t str[16]; + 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' } }, @@ -241,7 +245,8 @@ static int ignite_3 (stix_t* stix) { 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' } }, - { 12, { 'L','a','r','g','e','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_stix[] = { 'S','t','i','x' }; diff --git a/stix/lib/obj.c b/stix/lib/obj.c index 912e1a0..3fcb695 100644 --- a/stix/lib/obj.c +++ b/stix/lib/obj.c @@ -74,7 +74,7 @@ stix_oop_t stix_allocoopobj (stix_t* stix, stix_oow_t size) } #if defined(STIX_USE_OBJECT_TRAILER) -stix_oop_t stix_allocoopobjwithtrailer (stix_t* stix, stix_oow_t size, const stix_byte_t* bptr, stix_oow_t blen) +stix_oop_t stix_allocoopobjwithtrailer (stix_t* stix, stix_oow_t size, const stix_oob_t* bptr, stix_oow_t blen) { stix_oop_oop_t hdr; stix_oow_t nbytes, nbytes_aligned; @@ -163,9 +163,9 @@ stix_oop_t stix_allocmbcharobj (stix_t* stix, const stix_ooch_t* ptr, stix_oow_t } */ -stix_oop_t stix_allocbyteobj (stix_t* stix, const stix_byte_t* ptr, stix_oow_t len) +stix_oop_t stix_allocbyteobj (stix_t* stix, const stix_oob_t* ptr, stix_oow_t len) { - return alloc_numeric_array (stix, ptr, len, STIX_OBJ_TYPE_BYTE, STIX_SIZEOF(stix_byte_t), 0); + return alloc_numeric_array (stix, ptr, len, STIX_OBJ_TYPE_BYTE, STIX_SIZEOF(stix_oob_t), 0); } stix_oop_t stix_allocwordobj (stix_t* stix, const stix_oow_t* ptr, stix_oow_t len) @@ -272,7 +272,7 @@ einval: #if defined(STIX_USE_OBJECT_TRAILER) -stix_oop_t stix_instantiatewithtrailer (stix_t* stix, stix_oop_t _class, stix_oow_t vlen, const stix_byte_t* tptr, stix_oow_t tlen) +stix_oop_t stix_instantiatewithtrailer (stix_t* stix, stix_oop_t _class, stix_oow_t vlen, const stix_oob_t* tptr, stix_oow_t tlen) { stix_oop_t oop; stix_oow_t spec; diff --git a/stix/lib/stix-cmn.h b/stix/lib/stix-cmn.h index 5124e7e..40475c9 100644 --- a/stix/lib/stix-cmn.h +++ b/stix/lib/stix-cmn.h @@ -226,7 +226,6 @@ typedef stix_uintptr_t stix_size_t; typedef stix_intptr_t stix_ssize_t; -typedef stix_uint8_t stix_byte_t; typedef char stix_bch_t; typedef stix_uint16_t stix_uch_t; /* TODO ... wchar_t??? */ @@ -438,4 +437,24 @@ struct stix_cmgr_t #endif + + +/* ========================================================================= + * BASIC STIX TYPES + * =========================================================================*/ + +typedef stix_uint8_t stix_oob_t; +/* NOTE: sizeof(stix_oop_t) must be equal to sizeof(stix_oow_t) */ +typedef stix_uintptr_t stix_oow_t; +typedef stix_intptr_t stix_ooi_t; + +typedef stix_ushortptr_t stix_oohw_t; /* half word - half word */ +typedef stix_shortptr_t stix_oohi_t; /* signed half word */ + +typedef stix_uch_t stix_ooch_t; +typedef stix_uci_t stix_ooci_t; +typedef stix_ucs_t stix_oocs_t; +#define STIX_OOCH_IS_UCH + + #endif diff --git a/stix/lib/stix-prv.h b/stix/lib/stix-prv.h index 64baaa5..cb16378 100644 --- a/stix/lib/stix-prv.h +++ b/stix/lib/stix-prv.h @@ -475,7 +475,7 @@ struct stix_compiler_t stix_size_t literal_capa; /* byte array elements */ - stix_byte_t* balit; + stix_oob_t* balit; stix_size_t balit_count; stix_size_t balit_capa; @@ -504,7 +504,7 @@ struct stix_compiler_t #if defined(STIX_USE_OBJECT_TRAILER) /* let it point to the trailer of the method */ -# define SET_ACTIVE_METHOD_CODE(stix) ((stix)->active_code = (stix_byte_t*)&(stix)->active_method->slot[STIX_OBJ_GET_SIZE((stix)->active_method) + 1 - STIX_METHOD_NAMED_INSTVARS]) +# define SET_ACTIVE_METHOD_CODE(stix) ((stix)->active_code = (stix_oob_t*)&(stix)->active_method->slot[STIX_OBJ_GET_SIZE((stix)->active_method) + 1 - STIX_METHOD_NAMED_INSTVARS]) #else /* let it point to the payload of the code byte array */ # define SET_ACTIVE_METHOD_CODE(stix) ((stix)->active_code = (stix)->active_method->code->slot) @@ -808,23 +808,6 @@ enum stix_bcode_t extern "C" { #endif -#if defined(STIX_OOCH_IS_UCH) -# define stix_hashchars(ptr,len) stix_hashuchars(ptr,len) -# define stix_compoocbcstr(str1,str2) stix_compucbcstr(str1,str2) -# define stix_compoocstr(str1,str2) stix_compucstr(str1,str2) -# define stix_copyoochars(dst,src,len) stix_copyuchars(dst,src,len) -# define stix_copybchtooochars(dst,src,len) stix_copybchtouchars(dst,src,len) -# define stix_copyoocstr(dst,len,src) stix_copyucstr(dst,len,src) -# define stix_findoochar(ptr,len,c) stix_finduchar(ptr,len,c) -#else -# define stix_hashchars(ptr,len) stix_hashbchars(ptr,len) -# define stix_compoocbcstr(str1,str2) stix_compbcstr(str1,str2) -# define stix_compoocstr(str1,str2) stix_compbcstr(str1,str2) -# define stix_copyoochars(dst,src,len) stix_copybchars(dst,src,len) -# define stix_copybchtooochars(dst,src,len) stix_copybchars(dst,src,len) -# define stix_copyoocstr(dst,len,src) stix_copybcstr(dst,len,src) -# define stix_findoochar(ptr,len,c) stix_findbchar(ptr,len,c) -#endif /* ========================================================================= */ /* heap.c */ @@ -890,7 +873,7 @@ stix_oop_t stix_allocoopobj ( stix_oop_t stix_allocoopobjwithtrailer ( stix_t* stix, stix_oow_t size, - const stix_byte_t* tptr, + const stix_oob_t* tptr, stix_oow_t tlen ); #endif @@ -903,7 +886,7 @@ stix_oop_t stix_alloccharobj ( stix_oop_t stix_allocbyteobj ( stix_t* stix, - const stix_byte_t* ptr, + const stix_oob_t* ptr, stix_oow_t len ); @@ -918,7 +901,7 @@ stix_oop_t stix_instantiatewithtrailer ( stix_t* stix, stix_oop_t _class, stix_oow_t vlen, - const stix_byte_t* tptr, + const stix_oob_t* tptr, stix_oow_t tlen ); #endif @@ -1052,6 +1035,21 @@ int stix_utf8toucs ( stix_size_t* ucslen ); +/* ========================================================================= */ +/* bigint.c */ +/* ========================================================================= */ +stix_oop_t stix_addbigints ( + stix_t* stix, + stix_oop_t x, + stix_oop_t y +); + +stix_oop_t stix_subbigints ( + stix_t* stix, + stix_oop_t x, + stix_oop_t y +); + /* ========================================================================= */ /* comp.c */ /* ========================================================================= */ diff --git a/stix/lib/stix-utl.c b/stix/lib/stix-utl.c index 60fc7f1..6b67b14 100644 --- a/stix/lib/stix-utl.c +++ b/stix/lib/stix-utl.c @@ -27,7 +27,7 @@ #include "stix-utl.h" -stix_size_t stix_hashbytes (const stix_byte_t* ptr, stix_size_t len) +stix_size_t stix_hashbytes (const stix_oob_t* ptr, stix_size_t len) { stix_size_t h = 0; const stix_uint8_t* bp, * be; @@ -40,7 +40,7 @@ stix_size_t stix_hashbytes (const stix_byte_t* ptr, stix_size_t len) stix_size_t stix_hashuchars (const stix_uch_t* ptr, stix_size_t len) { - return stix_hashbytes ((const stix_byte_t *)ptr, len * STIX_SIZEOF(*ptr)); + return stix_hashbytes ((const stix_oob_t *)ptr, len * STIX_SIZEOF(*ptr)); } int stix_equalchars (const stix_uch_t* str1, const stix_uch_t* str2, stix_size_t len) diff --git a/stix/lib/stix-utl.h b/stix/lib/stix-utl.h index 920de00..cc2177f 100644 --- a/stix/lib/stix-utl.h +++ b/stix/lib/stix-utl.h @@ -33,12 +33,30 @@ extern "C" { #endif +#if defined(STIX_OOCH_IS_UCH) +# define stix_hashchars(ptr,len) stix_hashuchars(ptr,len) +# define stix_compoocbcstr(str1,str2) stix_compucbcstr(str1,str2) +# define stix_compoocstr(str1,str2) stix_compucstr(str1,str2) +# define stix_copyoochars(dst,src,len) stix_copyuchars(dst,src,len) +# define stix_copybchtooochars(dst,src,len) stix_copybchtouchars(dst,src,len) +# define stix_copyoocstr(dst,len,src) stix_copyucstr(dst,len,src) +# define stix_findoochar(ptr,len,c) stix_finduchar(ptr,len,c) +#else +# define stix_hashchars(ptr,len) stix_hashbchars(ptr,len) +# define stix_compoocbcstr(str1,str2) stix_compbcstr(str1,str2) +# define stix_compoocstr(str1,str2) stix_compbcstr(str1,str2) +# define stix_copyoochars(dst,src,len) stix_copybchars(dst,src,len) +# define stix_copybchtooochars(dst,src,len) stix_copybchars(dst,src,len) +# define stix_copyoocstr(dst,len,src) stix_copybcstr(dst,len,src) +# define stix_findoochar(ptr,len,c) stix_findbchar(ptr,len,c) +#endif + /* ========================================================================= */ /* stix-utl.c */ /* ========================================================================= */ stix_size_t stix_hashbytes ( - const stix_byte_t* ptr, + const stix_oob_t* ptr, stix_size_t len ); diff --git a/stix/lib/stix.h b/stix/lib/stix.h index c70189e..611c98c 100644 --- a/stix/lib/stix.h +++ b/stix/lib/stix.h @@ -75,33 +75,26 @@ enum stix_trait_t }; typedef enum stix_trait_t stix_trait_t; -/* NOTE: sizeof(stix_oop_t) must be equal to sizeof(stix_oow_t) */ -typedef stix_uintptr_t stix_oow_t; -typedef stix_intptr_t stix_ooi_t; -typedef stix_ushortptr_t stix_oosw_t; /* short word - half word */ -typedef stix_shortptr_t stix_oosi_t; /* signed short word */ -typedef struct stix_obj_t stix_obj_t; -typedef struct stix_obj_t* stix_oop_t; - -typedef stix_uch_t stix_ooch_t; -typedef stix_uci_t stix_ooci_t; -typedef stix_ucs_t stix_oocs_t; -#define STIX_OOCH_IS_UCH +typedef struct stix_obj_t stix_obj_t; +typedef struct stix_obj_t* stix_oop_t; /* these are more specialized types for stix_obj_t */ -typedef struct stix_obj_oop_t stix_obj_oop_t; -typedef struct stix_obj_char_t stix_obj_char_t; -typedef struct stix_obj_byte_t stix_obj_byte_t; -typedef struct stix_obj_word_t stix_obj_word_t; +typedef struct stix_obj_oop_t stix_obj_oop_t; +typedef struct stix_obj_char_t stix_obj_char_t; +typedef struct stix_obj_byte_t stix_obj_byte_t; +typedef struct stix_obj_halfword_t stix_obj_halfword_t; +typedef struct stix_obj_word_t stix_obj_word_t; /* these are more specialized types for stix_oop_t */ -typedef struct stix_obj_oop_t* stix_oop_oop_t; -typedef struct stix_obj_char_t* stix_oop_char_t; -typedef struct stix_obj_byte_t* stix_oop_byte_t; -typedef struct stix_obj_word_t* stix_oop_word_t; +typedef struct stix_obj_oop_t* stix_oop_oop_t; +typedef struct stix_obj_char_t* stix_oop_char_t; +typedef struct stix_obj_byte_t* stix_oop_byte_t; +typedef struct stix_obj_halfword_t* stix_oop_halfword_t; +typedef struct stix_obj_word_t* stix_oop_word_t; -#define STIX_OOW_BITS (STIX_SIZEOF(stix_oow_t) * 8) -#define STIX_OOP_BITS (STIX_SIZEOF(stix_oop_t) * 8) +#define STIX_OOW_BITS (STIX_SIZEOF(stix_oow_t) * 8) +#define STIX_OOP_BITS (STIX_SIZEOF(stix_oop_t) * 8) +#define STIX_OOHW_BITS (STIX_SIZEOF(stix_oohw_t) * 8) /* * OOP encoding @@ -152,7 +145,9 @@ enum stix_obj_type_t STIX_OBJ_TYPE_OOP, STIX_OBJ_TYPE_CHAR, STIX_OBJ_TYPE_BYTE, - STIX_OBJ_TYPE_WORD + STIX_OBJ_TYPE_HALFWORD, + STIX_OBJ_TYPE_WORD, + /* STIX_OBJ_TYPE_UINT8, @@ -178,7 +173,7 @@ typedef enum stix_obj_type_t stix_obj_type_t; * _flags: * type: the type of a payload item. * one of STIX_OBJ_TYPE_OOP, STIX_OBJ_TYPE_CHAR, - * STIX_OBJ_TYPE_BYTE, STIX_OBJ_TYPE_WORD + * STIX_OBJ_TYPE_BYTE, STIX_OBJ_TYPE_HALFWORD, STIX_OBJ_TYPE_WORD * unit: the size of a payload item in bytes. * extra: 0 or 1. 1 indicates that the payload contains 1 more * item than the value of the size field. used for a @@ -283,7 +278,13 @@ struct stix_obj_char_t struct stix_obj_byte_t { STIX_OBJ_HEADER; - stix_byte_t slot[1]; + stix_oob_t slot[1]; +}; + +struct stix_obj_halfword_t +{ + STIX_OBJ_HEADER; + stix_oohw_t slot[1]; }; struct stix_obj_word_t @@ -296,7 +297,7 @@ typedef struct stix_trailer_t stix_trailer_t; struct stix_trailer_t { stix_oow_t size; - stix_byte_t slot[1]; + stix_oob_t slot[1]; }; #define STIX_SET_NAMED_INSTVARS 2 @@ -679,7 +680,8 @@ struct stix_t stix_oop_t _character; /* Character */ stix_oop_t _small_integer; /* SmallInteger */ - stix_oop_t _large_integer; + stix_oop_t _large_positive_integer; /* LargePositiveInteger */ + stix_oop_t _large_negative_integer; /* LargeNegativeInteger */ /* == NEVER CHANGE THE ORDER OF FIELDS ABOVE == */ stix_oop_set_t symtab; /* system-wide symbol table. instance of SymbolSet */ @@ -692,7 +694,7 @@ struct stix_t /* == EXECUTION REGISTERS == */ stix_oop_context_t active_context; stix_oop_method_t active_method; - stix_byte_t* active_code; + stix_oob_t* active_code; stix_ooi_t sp; stix_ooi_t ip; /* == END EXECUTION REGISTERS == */