45 switch ( cell.
tag.value ) {
53 }
while ( result &&
integerp( arg ) );
60 result = ( cell.
payload.real.value == 0 );
74 switch ( cell.
tag.value ) {
76 result = cell.
payload.integer.value < 0;
82 result = ( cell.
payload.real.value < 0 );
94 switch ( cell.
tag.value ) {
102 cell.
payload.ratio.divisor,
false );
125 long double result = 0;
128 switch ( cell.
tag.value ) {
131 result = (
long double ) cell.
payload.integer.value;
150 result = cell.
payload.real.value;
179 switch ( cell.
tag.value ) {
184 result = cell.
payload.integer.value;
190 result = lroundl( cell.
payload.real.value );
231 if (
zerop( arg1 ) ) {
233 }
else if (
zerop( arg2 ) ) {
237 switch ( cell1.
tag.value ) {
242 switch ( cell2.
tag.value ) {
259 ( L
"Cannot add: not a number" ),
265 switch ( cell2.
tag.value ) {
282 ( L
"Cannot add: not a number" ),
295 ( L
"Cannot add: not a number" ),
324 result =
add_2( frame, frame_pointer, result, frame->arg[i] );
325 if ( !
eq( tmp, result ) ) {
333 result =
add_2( frame, frame_pointer, result,
c_car( more ) );
334 if ( !
eq( tmp, result ) ) {
338 more =
c_cdr( more );
363 if (
zerop( arg1 ) ) {
365 }
else if (
zerop( arg2 ) ) {
368 switch ( cell1.
tag.value ) {
373 switch ( cell2.
tag.value ) {
392 ( L
"Cannot multiply: argument 2 is not a number: " ),
399 switch ( cell2.
tag.value ) {
418 ( L
"Cannot multiply: argument 2 is not a number" ),
430 ( L
"Cannot multiply: argument 1 is not a number" ),
444#define multiply_one_arg(arg) {if (exceptionp(arg)){result=arg;}else{tmp = result; result = multiply_2( frame, frame_pointer, result, arg ); if ( !eq( tmp, result ) ) dec_ref( tmp );}}
472 while (
consp( more )
475 more =
c_cdr( more );
493 switch ( cell.
tag.value ) {
507 cell.
payload.ratio.divisor,
false );
582 ( L
"Cannot subtract: not a number" ),
611 ( L
"Cannot subtract: not a number" ),
622 ( L
"Cannot subtract: not a number" ),
644 return subtract_2( frame, frame_pointer, frame->arg[0], frame->arg[1] );
663 switch ( arg0.
tag.value ) {
665 result = frame->arg[0];
668 switch ( arg1.
tag.value ) {
670 result = frame->arg[1];
675 frame->arg[1],
true);
694 ( L
"Cannot divide: not a number" ),
700 switch ( arg1.
tag.value ) {
702 result = frame->arg[1];
724 ( L
"Cannot divide: not a number" ),
730 result =
exceptionp( frame->arg[1] ) ? frame->arg[1] :
736 ( L
"Cannot divide: not a number" ),
#define ratiop(conspoint)
true if conspoint points to a rational number cell, else false
#define exceptionp(conspoint)
true if conspoint points to an exception, else false
union cons_space_object::@2 tag
union cons_space_object::@3 payload
#define NIL
a cons pointer which points to the special NIL cell
struct cons_pointer c_cdr(struct cons_pointer arg)
Implementation of cdr in C.
#define INTEGERTV
The string INTR, considered as an unsigned int.
#define RATIOTV
The string RTIO, considered as an unsigned int.
#define consp(conspoint)
true if conspoint points to a cons cell, else false
#define nilp(conspoint)
true if conspoint points to the special cell NIL, else false (there should only be one of these so it...
#define TRUETV
The string TRUE, considered as an unsigned int.
#define REALTV
The string REAL, considered as an unsigned int.
struct cons_pointer c_string_to_lisp_string(wchar_t *string)
Return a lisp string representation of this wide character string.
struct cons_pointer inc_ref(struct cons_pointer pointer)
increment the reference count of the object at this cons pointer.
#define NILTV
The string NIL, considered as an unsigned int.
#define EXCEPTIONTV
The string EXEP, considered as an unsigned int.
#define TRUE
a cons pointer which points to the special T cell
struct cons_pointer c_car(struct cons_pointer arg)
Implementation of car in C.
struct cons_pointer c_type(struct cons_pointer pointer)
Get the Lisp type of the single argument.
struct cons_pointer dec_ref(struct cons_pointer pointer)
Decrement the reference count of the object at this cons pointer.
#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
struct cons_pointer make_cons(struct cons_pointer car, struct cons_pointer cdr)
Construct a cons cell from this pair of pointers.
An indirect pointer to a cons cell.
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.
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 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.
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 make_integer(int64_t value, struct cons_pointer more)
Allocate an integer cell representing this value and return a cons_pointer to it.
struct cons_pointer throw_exception(struct cons_pointer message, struct cons_pointer frame_pointer)
Throw an exception.
struct cons_pointer lisp_absolute(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function: calculate the absolute value of a number.
struct cons_pointer absolute(struct cons_pointer arg)
struct cons_pointer multiply_2(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer arg1, struct cons_pointer arg2)
return a cons_pointer indicating a number which is the product of the numbers indicated by arg1 and a...
struct cons_pointer negative(struct cons_pointer arg)
return a cons_pointer indicating a number which is the 0 - the number indicated by arg.
bool is_negative(struct cons_pointer arg)
does this arg point to a negative number?
struct cons_pointer lisp_ratio_to_real(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function: return a real (approcimately) equal in value to the ratio which is the first argument.
struct cons_pointer lisp_is_negative(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function: is this number negative?
struct cons_pointer add_2(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer arg1, struct cons_pointer arg2)
return a cons_pointer indicating a number which is the sum of the numbers indicated by arg1 and arg2.
struct cons_pointer lisp_subtract(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Subtract one number from another.
struct cons_pointer lisp_divide(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Divide one number by another.
#define multiply_one_arg(arg)
long double to_long_double(struct cons_pointer arg)
Return the closest possible binary64 representation to the value of this arg, expected to be an integ...
struct cons_pointer lisp_multiply(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Multiply an indefinite number of numbers together.
struct cons_pointer lisp_add(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Add an indefinite number of numbers together.
struct cons_pointer subtract_2(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer arg1, struct cons_pointer arg2)
return a cons_pointer indicating a number which is the result of subtracting the number indicated by ...
bool zerop(struct cons_pointer arg)
return true if this arg points to a number whose value is zero.
int64_t to_long_int(struct cons_pointer arg)
Return the closest possible int64_t representation to the value of this arg, expected to be an intege...
long double c_ratio_to_ld(struct cons_pointer rat)
convert a ratio to an equivalent long double.
struct cons_pointer add_ratio_ratio(struct cons_pointer arg1, struct cons_pointer arg2)
return a cons_pointer indicating a number which is the sum of the ratios indicated by arg1 and arg2.
struct cons_pointer multiply_ratio_ratio(struct cons_pointer arg1, struct cons_pointer arg2)
return a cons_pointer indicating a number which is the product of the ratios indicated by arg1 and ar...
struct cons_pointer divide_ratio_ratio(struct cons_pointer arg1, struct cons_pointer arg2)
return a cons_pointer to a ratio which represents the value of the ratio indicated by arg1 divided by...
struct cons_pointer multiply_integer_ratio(struct cons_pointer intarg, struct cons_pointer ratarg)
return a cons_pointer indicating a number which is the product of the intger indicated by intarg and ...
struct cons_pointer add_integer_ratio(struct cons_pointer intarg, struct cons_pointer ratarg)
return a cons_pointer indicating a number which is the sum of the intger indicated by intarg and the ...
struct cons_pointer subtract_ratio_ratio(struct cons_pointer arg1, struct cons_pointer arg2)
return a cons_pointer indicating a number which is the difference of the ratios indicated by arg1 and...
struct cons_pointer make_ratio(struct cons_pointer dividend, struct cons_pointer divisor, bool simplify)
Construct a ratio frame from this dividend and divisor, expected to be integers, in the context of th...
struct cons_pointer make_real(long double value)
Allocate a real number cell representing this value and return a cons pointer to it.