|
Post Scarcity
A prototype for a post scarcity programming environment
|
#include "memory/consspaceobject.h"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. | |
| #define INT_CELL_BASE ((__int128_t)MAX_INTEGER + 1) |
| #define INTEGER_BIT_SHIFT (60) |
| #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.
| struct cons_pointer absolute | ( | struct cons_pointer | arg | ) |
Definition at line 89 of file peano.c.
References absolute(), INTEGERTV, is_negative(), make_integer(), make_ratio(), make_real(), NIL, cons_space_object::payload, pointer2cell, RATIOTV, REALTV, and cons_space_object::tag.
Referenced by absolute(), and lisp_absolute().
| 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().
| 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)
| env | the evaluation environment - ignored; |
| frame | the stack frame. |
Definition at line 207 of file peano.c.
References absolute().
Referenced by main().
| 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.
| env | the evaluation environment - ignored; |
| frame | the stack frame. |
| if | any 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().
| 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.
| env | the evaluation environment - ignored; |
| frame | the stack frame. |
| if | either 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().
| struct cons_pointer lisp_is_negative | ( | struct stack_frame * | frame, |
| struct cons_pointer | frame_pointer, | ||
| struct cons_pointer | env | ||
| ) |
Function: is this number negative?
| env | the evaluation environment - ignored; |
| frame | the stack frame. |
Definition at line 531 of file peano.c.
References is_negative(), NIL, and TRUE.
Referenced by main().
| 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.
| env | the evaluation environment - ignored; |
| frame | the stack frame. |
| if | any 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().
| 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.
| frame | |
| frame_pointer | |
| env |
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().
| 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.
| env | the evaluation environment - ignored; |
| frame | the stack frame. |
| if | either argument is not a number, returns an exception. |
Definition at line 640 of file peano.c.
References subtract_2().
Referenced by main().
| 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().
| 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().
| 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.
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().
| 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.
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().
| 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().