50#define SMALL_INT_LIMIT 24
70 __int128_t result = ( __int128_t )
integerp( c ) ?
71 ( val == 0 ) ? carry : val : op ==
'*' ? 1 : 0;
73 L
"cell_value: raw value is %ld, is_first_cell = %s; '%4.4s'; returning ",
74 val, is_first_cell ?
"true" :
"false",
94 && (
pointer2cell( more ).payload.integer.value < 0 ) ) {
95 printf(
"WARNING: negative value %" PRId64
96 " passed as `more` to `make_integer`\n",
103 cell->
payload.integer.value = value;
104 cell->
payload.integer.more = more;
134 ( L
"acquire_integer passing to make_integer (outside small int range)\n",
196 __int128_t carry = 0;
203 L
"int128_to_integer: 64 bit overflow; setting carry to %ld\n",
209 newc->
payload.integer.value = ( int64_t ) val;
211 if (
integerp( less_significant ) ) {
214 lsc->
payload.integer.more =
new;
235 __int128_t carry = 0;
236 bool is_first_cell =
true;
245 while ( !
nilp( a ) || !
nilp( b ) || carry != 0 ) {
246 __int128_t av =
cell_value( a,
'+', is_first_cell );
247 __int128_t bv =
cell_value( b,
'+', is_first_cell );
248 __int128_t rv = ( av + bv ) + carry;
269 if (
nilp( result ) ) {
275 is_first_cell =
false;
293 for (
int i = 0; i < depth; i++ ) {
317 if (
nilp( partial ) ) {
347 bool is_first_b =
true;
362 __int128_t carry = 0;
373 L
"multiply_integers: a[i] = %Ld, b[j] = %Ld, i = %d\n",
379 __int128_t xj =
pointer2cell( ai ).payload.integer.value *
422 wint_t character = btowc(
hex_digits[digit] );
424 L
"integer_to_string_add_digit: digit is %d, digits is %d; returning: ",
461 __int128_t accumulator =
462 llabs(
pointer2cell( int_pointer ).payload.integer.value );
467 if ( accumulator == 0 &&
nilp( next ) ) {
470 while ( accumulator > 0 || !
nilp( next ) ) {
477 int offset = ( int ) ( accumulator % base );
479 L
"integer_to_string: digit is %ld, hexadecimal is %c, accumulator is: ",
488 accumulator = accumulator / base;
492 &&
pointer2cell( result ).payload.string.character == L
',' ) {
struct cons_pointer allocate_cell(uint32_t tag)
Allocates a cell with the specified tag.
struct cons_pointer inc_ref(struct cons_pointer pointer)
increment the reference count of the object at this cons pointer.
struct cons_pointer dec_ref(struct cons_pointer pointer)
Decrement the reference count of the object at this cons pointer.
union cons_space_object::@3 payload
#define NIL
a cons pointer which points to the special NIL cell
#define INTEGERTV
The string INTR, considered as an unsigned int.
struct cons_pointer make_string(wint_t c, struct cons_pointer tail)
Construct a string from the character c and this tail.
#define nilp(conspoint)
true if conspoint points to the special cell NIL, else false (there should only be one of these so it...
uint32_t offset
the index of the cell within the page
struct cons_pointer c_string_to_lisp_string(wchar_t *string)
Return a lisp string representation of this wide character string.
#define stringp(conspoint)
true if conspoint points to a string cell, else false
#define pointer2cell(pointer)
given a cons_pointer as argument, return the cell.
#define integerp(conspoint)
true if conspoint points to an integer cell, else false
An indirect pointer to a cons cell.
void debug_print_128bit(__int128_t n, int level)
print a 128 bit integer value to stderr, if verbosity matches level.
void debug_println(int level)
print a line feed to stderr, if verbosity matches level.
void debug_dump_object(struct cons_pointer pointer, int level)
Like dump_object, q.v., but protected by the verbosity mechanism.
void debug_printf(int level, wchar_t *format,...)
wprintf adapted for the debug logging system.
void debug_print(wchar_t *message, int level)
print this debug message to stderr, if verbosity matches level.
void debug_print_object(struct cons_pointer pointer, int level)
print the object indicated by this pointer to stderr, if verbosity matches level.
#define DEBUG_ARITH
Print messages debugging arithmetic operations.
#define DEBUG_IO
Print messages debugging input/output operations.
#define DEBUG_ALLOC
Print messages debugging memory allocation.
bool eq(struct cons_pointer a, struct cons_pointer b)
Shallow, and thus cheap, equality: true if these two objects are the same object, else false.
struct cons_pointer append_cell(struct cons_pointer partial, struct cons_pointer digit)
Return a copy of this partial with this digit appended.
bool small_int_cache_initialised
bool equal_integer_integer(struct cons_pointer a, struct cons_pointer b)
true if a and be are both integers whose value is the same value.
struct cons_pointer multiply_integers(struct cons_pointer a, struct cons_pointer b)
Return a pointer to an integer representing the product of the integers pointed to by a and b.
const char * hex_digits
hexadecimal digits for printing numbers.
void release_integer(struct cons_pointer p)
if the value of p is less than the size of the small integer cache (and thus it was presumably suppli...
__int128_t int128_to_integer(__int128_t val, struct cons_pointer less_significant, struct cons_pointer new)
Overwrite the value field of the integer indicated by new with the least significant INTEGER_BITS bit...
__int128_t cell_value(struct cons_pointer c, char op, bool is_first_cell)
Low level integer arithmetic, do not use elsewhere.
struct cons_pointer add_integers(struct cons_pointer a, struct cons_pointer b)
Return a pointer to an integer representing the sum of the integers pointed to by a and b.
struct cons_pointer small_int_cache[SMALL_INT_LIMIT]
struct cons_pointer integer_to_string(struct cons_pointer int_pointer, int base)
return a string representation of this integer, which may be a bignum.
struct cons_pointer integer_to_string_add_digit(int digit, int digits, struct cons_pointer tail)
don't use; private to integer_to_string, and somewhat dodgy.
struct cons_pointer acquire_integer(int64_t value, struct cons_pointer more)
Supply small valued integers from the small integer cache, if available.
struct cons_pointer base_partial(int depth)
struct cons_pointer make_integer(int64_t value, struct cons_pointer more)
Allocate an integer cell representing this value and return a cons_pointer to it.
#define replace_integer_i(p, i)
#define replace_integer_p(p, q)
bool is_negative(struct cons_pointer arg)
does this arg point to a negative number?
#define MAX_INTEGER
The maximum value we will allow in an integer cell: one less than 2^60: (let ((s (make-string-output-...
#define INTEGER_BIT_SHIFT
Number of value bits in an integer cell.