Post Scarcity
A prototype for a post scarcity programming environment
Loading...
Searching...
No Matches
peano.h File Reference
Include dependency graph for peano.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define INT_CELL_BASE   ((__int128_t)MAX_INTEGER + 1)
 
#define INTEGER_BIT_SHIFT   (60)
 Number of value bits in an integer cell.
 
#define MAX_INTEGER   ((__int128_t)0x0fffffffffffffffL)
 The maximum value we will allow in an integer cell: one less than 2^60: (let ((s (make-string-output-stream))) (format s "0x0~XL" (- (expt 2 60) 1)) (string-downcase (get-output-stream-string s))) "0x0fffffffffffffffl".
 

Functions

struct cons_pointer absolute (struct cons_pointer arg)
 
bool is_negative (struct cons_pointer arg)
 does this arg point to a negative number?
 
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 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 lisp_divide (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
 Divide one number by another.
 
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 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_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_subtract (struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
 Subtract one number from another.
 
struct cons_pointer negative (struct cons_pointer arg)
 return a cons_pointer indicating a number which is the 0 - the number indicated by arg.
 
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 arg2 from that indicated by arg1, in the context of this frame.
 
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 integer, ratio or real, or NAN if arg is not any of these.
 
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 integer, ratio or real, or NAN if arg is not any of these.
 
bool zerop (struct cons_pointer arg)
 return true if this arg points to a number whose value is zero.
 

Macro Definition Documentation

◆ INT_CELL_BASE

#define INT_CELL_BASE   ((__int128_t)MAX_INTEGER + 1)

Definition at line 26 of file peano.h.

◆ INTEGER_BIT_SHIFT

#define INTEGER_BIT_SHIFT   (60)

Number of value bits in an integer cell.

Definition at line 32 of file peano.h.

◆ MAX_INTEGER

#define MAX_INTEGER   ((__int128_t)0x0fffffffffffffffL)

The maximum value we will allow in an integer cell: one less than 2^60: (let ((s (make-string-output-stream))) (format s "0x0~XL" (- (expt 2 60) 1)) (string-downcase (get-output-stream-string s))) "0x0fffffffffffffffl".

So left shifting and right shifting by 60 bits is correct.

Definition at line 25 of file peano.h.

Function Documentation

◆ absolute()

◆ is_negative()

bool is_negative ( struct cons_pointer  arg)

does this arg point to a negative number?

Definition at line 70 of file peano.c.

References INTEGERTV, is_negative(), cons_space_object::payload, pointer2cell, RATIOTV, REALTV, and cons_space_object::tag.

Referenced by absolute(), integer_to_string(), is_negative(), lisp_is_negative(), and multiply_integers().

◆ lisp_absolute()

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.

(absolute arg)

Parameters
envthe evaluation environment - ignored;
framethe stack frame.
Returns
the absolute value of the number represented by the first argument, or NIL if it was not a number.

Definition at line 207 of file peano.c.

References absolute().

Referenced by main().

◆ lisp_add()

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.

Parameters
envthe evaluation environment - ignored;
framethe stack frame.
Returns
a pointer to an integer, ratio or real.
Exceptions
ifany argument is not a number, returns an exception.

Definition at line 314 of file peano.c.

References add_2(), args_in_frame, c_car(), c_cdr(), consp, dec_ref(), eq(), exceptionp, make_integer(), NIL, and nilp.

Referenced by main().

◆ lisp_divide()

struct cons_pointer lisp_divide ( struct stack_frame frame,
struct cons_pointer  frame_pointer,
struct cons_pointer  env 
)

Divide one number by another.

If more than two arguments are passed in the frame, the additional arguments are ignored.

Parameters
envthe evaluation environment - ignored;
framethe stack frame.
Returns
a pointer to an integer or real.
Exceptions
ifeither argument is not a number, returns an exception.

Definition at line 655 of file peano.c.

References c_string_to_lisp_string(), dec_ref(), divide_ratio_ratio(), exceptionp, EXCEPTIONTV, inc_ref(), INTEGERTV, make_integer(), make_ratio(), make_real(), NIL, pointer2cell, RATIOTV, REALTV, cons_space_object::tag, throw_exception(), and to_long_double().

Referenced by main().

◆ lisp_is_negative()

struct cons_pointer lisp_is_negative ( struct stack_frame frame,
struct cons_pointer  frame_pointer,
struct cons_pointer  env 
)

Function: is this number negative?

  • (negative? arg)
Parameters
envthe evaluation environment - ignored;
framethe stack frame.
Returns
T if the first argument was a negative number, or NIL if it was not.

Definition at line 531 of file peano.c.

References is_negative(), NIL, and TRUE.

Referenced by main().

◆ lisp_multiply()

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.

Parameters
envthe evaluation environment - ignored;
framethe stack frame.
Returns
a pointer to an integer, ratio or real.
Exceptions
ifany argument is not a number, returns an exception.

Definition at line 453 of file peano.c.

References args_in_frame, c_car(), c_cdr(), consp, DEBUG_ARITH, debug_print(), debug_print_object(), debug_println(), exceptionp, make_integer(), multiply_one_arg, NIL, and nilp.

Referenced by main().

◆ lisp_ratio_to_real()

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.

Parameters
frame
frame_pointer
env
Returns
struct cons_pointer a pointer to a real

Definition at line 755 of file peano.c.

References c_ratio_to_ld(), DEBUG_ARITH, debug_print(), debug_print_object(), make_real(), NIL, and ratiop.

Referenced by main().

◆ lisp_subtract()

struct cons_pointer lisp_subtract ( struct stack_frame frame,
struct cons_pointer  frame_pointer,
struct cons_pointer  env 
)

Subtract one number from another.

If more than two arguments are passed in the frame, the additional arguments are ignored.

Parameters
envthe evaluation environment - ignored;
framethe stack frame.
Returns
a pointer to an integer, ratio or real.
Exceptions
ifeither argument is not a number, returns an exception.

Definition at line 640 of file peano.c.

References subtract_2().

Referenced by main().

◆ negative()

struct cons_pointer negative ( struct cons_pointer  arg)

return a cons_pointer indicating a number which is the 0 - the number indicated by arg.

Definition at line 489 of file peano.c.

References EXCEPTIONTV, INTEGERTV, make_integer(), make_ratio(), make_real(), negative(), NIL, NILTV, cons_space_object::payload, pointer2cell, RATIOTV, REALTV, cons_space_object::tag, to_long_double(), TRUE, and TRUETV.

Referenced by negative(), read_number(), subtract_2(), and subtract_ratio_ratio().

◆ subtract_2()

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 arg2 from that indicated by arg1, in the context of this frame.

Definition at line 544 of file peano.c.

References add_integers(), c_string_to_lisp_string(), dec_ref(), exceptionp, EXCEPTIONTV, inc_ref(), INTEGERTV, make_integer(), make_ratio(), make_real(), negative(), NIL, pointer2cell, RATIOTV, REALTV, subtract_ratio_ratio(), throw_exception(), and to_long_double().

Referenced by lisp_subtract().

◆ to_long_double()

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 integer, ratio or real, or NAN if arg is not any of these.

  • a pointer to an integer, ratio or real.
Todo:
cannot throw an exception out of here, which is a problem if a ratio may legally have zero as a divisor, or something which is not a number is passed in.

Definition at line 124 of file peano.c.

References DEBUG_ARITH, debug_print(), debug_print_object(), debug_printf(), INTEGERTV, cons_space_object::payload, pointer2cell, RATIOTV, REALTV, cons_space_object::tag, and to_long_double().

Referenced by add_2(), equal(), lisp_divide(), multiply_2(), negative(), read_number(), subtract_2(), to_long_double(), and to_long_int().

◆ to_long_int()

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 integer, ratio or real, or NAN if arg is not any of these.

  • a pointer to an integer, ratio or real.
Todo:
cannot throw an exception out of here, which is a problem if a ratio may legally have zero as a divisor, or something which is not a number (or is a big number) is passed in.

Definition at line 176 of file peano.c.

References INTEGERTV, cons_space_object::payload, pointer2cell, RATIOTV, REALTV, cons_space_object::tag, and to_long_double().

Referenced by lisp_make_hashmap().

◆ zerop()

bool zerop ( struct cons_pointer  arg)

return true if this arg points to a number whose value is zero.

Definition at line 41 of file peano.c.

References DEBUG_ARITH, debug_dump_object(), debug_print(), integerp, INTEGERTV, cons_space_object::payload, pointer2cell, RATIOTV, REALTV, cons_space_object::tag, and zerop().

Referenced by add_2(), multiply_2(), and zerop().