|
Post Scarcity
A prototype for a post scarcity programming environment
|
#include <stdbool.h>#include <stdint.h>#include <stdio.h>#include <wchar.h>#include <wctype.h>#include "io/fopen.h"Go to the source code of this file.
Data Structures | |
| struct | cons_payload |
| payload of a cons cell. More... | |
| struct | cons_pointer |
| An indirect pointer to a cons cell. More... | |
| struct | cons_space_object |
| an object in cons space. More... | |
| union | cons_space_object.payload |
| union | cons_space_object.tag |
| struct | exception_payload |
| Payload of an exception. More... | |
| struct | free_payload |
| payload of a free cell. More... | |
| struct | function_payload |
| Payload of a function cell. More... | |
| struct | integer_payload |
| payload of an integer cell. More... | |
| struct | lambda_payload |
| payload for lambda and nlambda cells. More... | |
| struct | ratio_payload |
| payload for ratio cells. More... | |
| struct | real_payload |
| payload for a real number cell. More... | |
| struct | special_payload |
| Payload of a special form cell. More... | |
| struct | stack_frame |
| A stack frame. More... | |
| struct | stream_payload |
| payload of a read or write stream cell. More... | |
| struct | string_payload |
| payload of a string cell. More... | |
| struct | time_payload |
| The payload of a time cell: an unsigned 128 bit value representing micro- seconds since the estimated date of the Big Bang (actually, for convenience, 14Bn years before 1st Jan 1970 (the UNIX epoch)) More... | |
| struct | vectorp_payload |
| payload of a vector pointer cell. More... | |
| union | vectorp_payload.tag |
| the tag of the vector-space object. More... | |
Macros | |
| #define | args_in_frame 8 |
| #define | consp(conspoint) (check_tag(conspoint,CONSTV)) |
true if conspoint points to a cons cell, else false | |
| #define | CONSTAG "CONS" |
| An ordinary cons cell: | |
| #define | CONSTV 1397641027 |
The string CONS, considered as an unsigned int. | |
| #define | exceptionp(conspoint) (check_tag(conspoint,EXCEPTIONTV)) |
true if conspoint points to an exception, else false | |
| #define | EXCEPTIONTAG "EXEP" |
| An exception. | |
| #define | EXCEPTIONTV 1346721861 |
The string EXEP, considered as an unsigned int. | |
| #define | FREETAG "FREE" |
| An unallocated cell on the free list - should never be encountered by a Lisp function. | |
| #define | FREETV 1162170950 |
The string FREE, considered as an unsigned int. | |
| #define | functionp(conspoint) (check_tag(conspoint,FUNCTIONTV)) |
true if conspoint points to a function cell, else false | |
| #define | FUNCTIONTAG "FUNC" |
| An ordinary Lisp function - one whose arguments are pre-evaluated. | |
| #define | FUNCTIONTV 1129207110 |
The string FUNC, considered as an unsigned int. | |
| #define | integerp(conspoint) (check_tag(conspoint,INTEGERTV)) |
true if conspoint points to an integer cell, else false | |
| #define | INTEGERTAG "INTR" |
| An integer number (bignums are integers). | |
| #define | INTEGERTV 1381256777 |
The string INTR, considered as an unsigned int. | |
| #define | KEYTAG "KEYW" |
| A keyword - an interned, self-evaluating string. | |
| #define | KEYTV 1465468235 |
The string KEYW, considered as an unsigned int. | |
| #define | keywordp(conspoint) (check_tag(conspoint,KEYTV)) |
true if conspoint points to a keyword, else false | |
| #define | lambdap(conspoint) (check_tag(conspoint,LAMBDATV)) |
true if conspoint points to a Lambda binding cell, else false | |
| #define | LAMBDATAG "LMDA" |
| A lambda cell. | |
| #define | LAMBDATV 1094995276 |
The string LMDA, considered as an unsigned int. | |
| #define | LAZYCONSTAG "LZYC" |
| Tag for a lazy cons cell. | |
| #define | LAZYSTRTAG "LZYS" |
| Tag for a lazy string cell. | |
| #define | LAZYWRKRTAG "WRKR" |
| Tag for a lazy worker cell. | |
| #define | loopp(conspoint) (check_tag(conspoint,LOOPTV)) |
true if conspoint points to a loop recursion, else false. | |
| #define | LOOPTAG "LOOP" |
| A loop exit is a special kind of exception which has exactly the same payload as an exception. | |
| #define | LOOPTV 1347374924 |
The string LOOX, considered as an unsigned int. | |
| #define | make_keyword(c, t) (make_symbol_or_key( c, t, KEYTV)) |
| #define | make_symbol(c, t) (make_symbol_or_key( c, t, SYMBOLTV)) |
| #define | MAXREFERENCE 4294967295 |
| the maximum possible value of a reference count | |
| #define | NIL (struct cons_pointer){ 0, 0} |
| a cons pointer which points to the special NIL cell | |
| #define | nilp(conspoint) (check_tag(conspoint,NILTV)) |
true if conspoint points to the special cell NIL, else false (there should only be one of these so it's slightly redundant). | |
| #define | NILTAG "NIL " |
| The special cons cell at address {0,0} whose car and cdr both point to itself. | |
| #define | NILTV 541870414 |
The string NIL, considered as an unsigned int. | |
| #define | NLAMBDATAG "NLMD" |
| An nlambda cell. | |
| #define | NLAMBDATV 1145916494 |
The string NLMD, considered as an unsigned int. | |
| #define | numberp(conspoint) (check_tag(conspoint,INTEGERTV)||check_tag(conspoint,RATIOTV)||check_tag(conspoint,REALTV)) |
true if conspoint points to some sort of a number cell, else false | |
| #define | pointer2cell(pointer) ((conspages[pointer.page]->cell[pointer.offset])) |
| given a cons_pointer as argument, return the cell. | |
| #define | ratiop(conspoint) (check_tag(conspoint,RATIOTV)) |
true if conspoint points to a rational number cell, else false | |
| #define | RATIOTAG "RTIO" |
| A rational number, stored as pointers two integers representing dividend and divisor respectively. | |
| #define | RATIOTV 1330205778 |
The string RTIO, considered as an unsigned int. | |
| #define | readp(conspoint) (check_tag(conspoint,READTV)) |
true if conspoint points to a read stream cell, else false | |
| #define | READTAG "READ" |
| An open read stream. | |
| #define | READTV 1145128274 |
The string READ, considered as an unsigned int. | |
| #define | realp(conspoint) (check_tag(conspoint,REALTV)) |
true if conspoint points to a real number cell, else false | |
| #define | REALTAG "REAL" |
A real number, represented internally as an IEEE 754-2008 binary64. | |
| #define | REALTV 1279346002 |
The string REAL, considered as an unsigned int. | |
| #define | sequencep(conspoint) (check_tag(conspoint,CONSTV)||check_tag(conspoint,STRINGTV)||check_tag(conspoint,SYMBOLTV)) |
true if conspoint points to a sequence (list, string or, later, vector), else false. | |
| #define | specialp(conspoint) (check_tag(conspoint,SPECIALTV)) |
true if conspoint points to a special form cell, else false | |
| #define | SPECIALTAG "SPFM" |
| A special form - one whose arguments are not pre-evaluated but passed as provided. | |
| #define | SPECIALTV 1296453715 |
The string SPFM, considered as an unsigned int. | |
| #define | streamp(conspoint) (check_tag(conspoint,READTV)||check_tag(conspoint,WRITETV)) |
| #define | stringp(conspoint) (check_tag(conspoint,STRINGTV)) |
true if conspoint points to a string cell, else false | |
| #define | STRINGTAG "STRG" |
| A string of characters, organised as a linked list. | |
| #define | STRINGTV 1196577875 |
The string STRG, considered as an unsigned int. | |
| #define | symbolp(conspoint) (check_tag(conspoint,SYMBOLTV)) |
true if conspoint points to a symbol cell, else false | |
| #define | SYMBOLTAG "SYMB" |
| A symbol is just like a string except not self-evaluating. | |
| #define | SYMBOLTV 1112365395 |
The string SYMB, considered as an unsigned int. | |
| #define | tag2uint(tag) ((uint32_t)*tag) |
| a macro to convert a tag into a number | |
| #define | TAGLENGTH 4 |
| The length of a tag, in bytes. | |
| #define | timep(conspoint) (check_tag(conspoint,TIMETV)) |
true if conspoint points to a time cell, else false. | |
| #define | TIMETAG "TIME" |
| A time stamp. | |
| #define | TIMETV 1162692948 |
The string TIME, considered as an unsigned int. | |
| #define | tp(conspoint) (check_tag(conspoint,TRUETV)) |
true if conspoint points to a true cell, else false (there should only be one of these so it's slightly redundant). | |
| #define | TRUE (struct cons_pointer){ 0, 1} |
| a cons pointer which points to the special T cell | |
| #define | truep(conspoint) (!check_tag(conspoint,NILTV)) |
true if conspoint points to something that is truthy, i.e. | |
| #define | TRUETAG "TRUE" |
| The special cons cell at address {0,1} which is canonically different from NIL. | |
| #define | TRUETV 1163219540 |
The string TRUE, considered as an unsigned int. | |
| #define | vectorpointp(conspoint) (check_tag(conspoint,VECTORPOINTTV)) |
true if conspoint points to a vector pointer, else false. | |
| #define | VECTORPOINTTAG "VECP" |
| A pointer to an object in vector space. | |
| #define | VECTORPOINTTV 1346585942 |
The string VECP, considered as an unsigned int. | |
| #define | writep(conspoint) (check_tag(conspoint,WRITETV)) |
true if conspoint points to a write stream cell, else false. | |
| #define | WRITETAG "WRIT" |
| An open write stream. | |
| #define | WRITETV 1414091351 |
The string WRIT, considered as an unsigned int. | |
Functions | |
| struct cons_pointer | c_car (struct cons_pointer arg) |
| Implementation of car in C. | |
| struct cons_pointer | c_cdr (struct cons_pointer arg) |
| Implementation of cdr in C. | |
| int | c_length (struct cons_pointer arg) |
Implementation of length in C. | |
| struct cons_pointer | c_string_to_lisp_keyword (wchar_t *symbol) |
| Return a lisp keyword representation of this wide character string. | |
| struct cons_pointer | c_string_to_lisp_string (wchar_t *string) |
| Return a lisp string representation of this wide character string. | |
| struct cons_pointer | c_string_to_lisp_symbol (wchar_t *symbol) |
| Return a lisp symbol representation of this wide character string. | |
| struct cons_pointer | c_type (struct cons_pointer pointer) |
| Get the Lisp type of the single argument. | |
| bool | check_tag (struct cons_pointer pointer, uint32_t value) |
True if the value of the tag on the cell at this pointer is this value, or, if the tag of the cell is VECP, if the value of the tag of the vectorspace object indicated by the cell is this value, else false. | |
| struct cons_pointer | dec_ref (struct cons_pointer pointer) |
| Decrement the reference count of the object at this cons pointer. | |
| struct cons_pointer | inc_ref (struct cons_pointer pointer) |
| increment the reference count of the object at this cons pointer. | |
| struct cons_pointer | make_cons (struct cons_pointer car, struct cons_pointer cdr) |
| Construct a cons cell from this pair of pointers. | |
| struct cons_pointer | make_exception (struct cons_pointer message, struct cons_pointer frame_pointer) |
| Construct an exception cell. | |
| struct cons_pointer | make_function (struct cons_pointer src, struct cons_pointer(*executable)(struct stack_frame *, struct cons_pointer, struct cons_pointer)) |
| Construct a cell which points to an executable Lisp function. | |
| struct cons_pointer | make_lambda (struct cons_pointer args, struct cons_pointer body) |
| Construct a lambda (interpretable source) cell. | |
| struct cons_pointer | make_nlambda (struct cons_pointer args, struct cons_pointer body) |
| Construct an nlambda (interpretable source) cell; to a lambda as a special form is to a function. | |
| struct cons_pointer | make_read_stream (URL_FILE *input, struct cons_pointer metadata) |
| Construct a cell which points to a stream open for reading. | |
| struct cons_pointer | make_special (struct cons_pointer src, struct cons_pointer(*executable)(struct stack_frame *, struct cons_pointer, struct cons_pointer)) |
| struct cons_pointer | make_string (wint_t c, struct cons_pointer tail) |
Construct a string from the character c and this tail. | |
| struct cons_pointer | make_string_like_thing (wint_t c, struct cons_pointer tail, uint32_t tag) |
| Construct a string from this character (which later will be UTF) and this tail. | |
| struct cons_pointer | make_symbol_or_key (wint_t c, struct cons_pointer tail, uint32_t tag) |
Construct a symbol or keyword from the character c and this tail. | |
| struct cons_pointer | make_write_stream (URL_FILE *output, struct cons_pointer metadata) |
| Construct a cell which points to a stream open for writing. | |
| struct cons_payload |
payload of a cons cell.
Definition at line 447 of file consspaceobject.h.
| Data Fields | ||
|---|---|---|
| struct cons_pointer | car | Contents of the Address Register, naturally. |
| struct cons_pointer | cdr | Contents of the Decrement Register, naturally. |
| struct cons_pointer |
An indirect pointer to a cons cell.
Definition at line 415 of file consspaceobject.h.
| Data Fields | ||
|---|---|---|
| uint32_t | offset | the index of the cell within the page |
| uint32_t | page | the index of the page on which this cell resides |
| struct cons_space_object |
an object in cons space.
Definition at line 626 of file consspaceobject.h.
| Data Fields | ||
|---|---|---|
| struct cons_pointer | access | cons pointer to the access control list of this cell |
| uint32_t | count | the count of the number of references to this cell |
| union cons_space_object.payload | payload | |
| union cons_space_object.tag | tag | |
| union cons_space_object.payload |
Definition at line 638 of file consspaceobject.h.
| Data Fields | ||
|---|---|---|
| struct cons_payload | cons | if tag == CONSTAG |
| struct exception_payload | exception | if tag == EXCEPTIONTAG || tag == LOOPTAG |
| struct free_payload | free | if tag == FREETAG |
| struct function_payload | function | if tag == FUNCTIONTAG |
| struct integer_payload | integer | if tag == INTEGERTAG |
| struct lambda_payload | lambda | if tag == LAMBDATAG or NLAMBDATAG |
| struct cons_payload | nil | if tag == NILTAG; we'll treat the special cell NIL as just a cons |
| struct ratio_payload | ratio | if tag == RATIOTAG |
| struct real_payload | real | if tag == REALTAG |
| struct special_payload | special | if tag == SPECIALTAG |
| struct stream_payload | stream | if tag == READTAG || tag == WRITETAG |
| struct string_payload | string | if tag == STRINGTAG || tag == SYMBOLTAG |
| struct cons_payload | t | if tag == TRUETAG; we'll treat the special cell T as just a cons |
| struct time_payload | time | if tag == TIMETAG |
| struct vectorp_payload | vectorp | if tag == VECTORPTAG |
| union cons_space_object.tag |
Definition at line 627 of file consspaceobject.h.
| Data Fields | ||
|---|---|---|
| char | bytes[TAGLENGTH] | the tag (type) of this cell, considered as bytes |
| uint32_t | value | the tag considered as a number |
| struct exception_payload |
Payload of an exception.
Message should be a Lisp string; frame should be a pointer to an (unfreed) stack frame.
Definition at line 458 of file consspaceobject.h.
| Data Fields | ||
|---|---|---|
| struct cons_pointer | frame | pointer to the (unfreed) stack frame in which the exception was thrown. |
| struct cons_pointer | payload | The payload: usually a Lisp string but in practice anything printable will do. |
| struct free_payload |
payload of a free cell.
For the time being identical to a cons cell, but it may not be so in future.
Definition at line 494 of file consspaceobject.h.
| Data Fields | ||
|---|---|---|
| struct cons_pointer | car | |
| struct cons_pointer | cdr | |
| struct integer_payload |
payload of an integer cell.
An integer is in principle a sequence of cells; only 60 bits (+ sign bit) are actually used in each cell. If the value exceeds 60 bits, the least significant 60 bits are stored in the first cell in the chain, the next 60 in the next cell, and so on. Only the value of the first cell in any chain should be negative.
Definition at line 508 of file consspaceobject.h.
| Data Fields | ||
|---|---|---|
| struct cons_pointer | more |
the next (more significant) cell in the chain, or NIL if there are no more. |
| int64_t | value |
the value of the payload (i.e. 60 bits) of this cell. |
| struct lambda_payload |
payload for lambda and nlambda cells.
Definition at line 519 of file consspaceobject.h.
| Data Fields | ||
|---|---|---|
| struct cons_pointer | args | the arument list |
| struct cons_pointer | body | the body of the function to be applied to the arguments. |
| struct ratio_payload |
payload for ratio cells.
Both dividend and divisor must point to integer cells.
Definition at line 529 of file consspaceobject.h.
| Data Fields | ||
|---|---|---|
| struct cons_pointer | dividend | a pointer to an integer representing the dividend |
| struct cons_pointer | divisor | a pointer to an integer representing the divisor. |
| struct real_payload |
payload for a real number cell.
Internals of this liable to change to give 128 bits precision, but I'm not sure of the detail.
Definition at line 540 of file consspaceobject.h.
| Data Fields | ||
|---|---|---|
| long double | value | the value of the number |
| struct stack_frame |
A stack frame.
Yes, I know it isn't a cons-space object, but it's defined here to avoid circularity.
Definition at line 431 of file consspaceobject.h.
| Data Fields | ||
|---|---|---|
| struct cons_pointer | arg[args_in_frame] | first 8 arument bindings. |
| int | args | the number of arguments provided. |
| struct cons_pointer | function | the function to be called. |
| struct cons_pointer | more | list of any further argument bindings. |
| struct cons_pointer | previous | the previous frame. |
| struct stream_payload |
payload of a read or write stream cell.
Definition at line 568 of file consspaceobject.h.
| Data Fields | ||
|---|---|---|
| struct cons_pointer | meta |
metadata on the stream (e.g. its file attributes if a file, its HTTP headers if a URL, etc). Expected to be an association, or nil. Not yet implemented. |
| URL_FILE * | stream | the stream to read from or write to. |
| struct string_payload |
payload of a string cell.
At least at first, only one UTF character will be stored in each cell. The doctrine that 'a symbol is just a string' didn't work; however, the payload of a symbol or keyword cell is identical to the payload of a string cell, except that a keyword may store a hash of its own value in the padding.
Definition at line 584 of file consspaceobject.h.
| Data Fields | ||
|---|---|---|
| struct cons_pointer | cdr | the remainder of the string following this character. |
| wint_t | character | the actual character stored in this cell |
| uint32_t | hash | a hash of the string value, computed at store time. |
| struct time_payload |
The payload of a time cell: an unsigned 128 bit value representing micro- seconds since the estimated date of the Big Bang (actually, for convenience, 14Bn years before 1st Jan 1970 (the UNIX epoch))
Definition at line 598 of file consspaceobject.h.
| Data Fields | ||
|---|---|---|
| unsigned __int128 | value | |
| struct vectorp_payload |
payload of a vector pointer cell.
Definition at line 605 of file consspaceobject.h.
| Data Fields | ||
|---|---|---|
| void * | address |
the address of the actual vector space object (
|
| uint32_t | padding | unused padding to word-align the address |
| union vectorp_payload.tag | tag |
the tag of the vector-space object. NOTE that the vector space object should itself have the identical tag. |
| union vectorp_payload.tag |
the tag of the vector-space object.
NOTE that the vector space object should itself have the identical tag.
Definition at line 608 of file consspaceobject.h.
| Data Fields | ||
|---|---|---|
| char | bytes[TAGLENGTH] | the tag (type) of the vector-space object this cell points to, considered as bytes. |
| uint32_t | value | the tag considered as a number |
| #define args_in_frame 8 |
Definition at line 425 of file consspaceobject.h.
true if conspoint points to a cons cell, else false
Definition at line 308 of file consspaceobject.h.
| #define CONSTAG "CONS" |
An ordinary cons cell:
Definition at line 40 of file consspaceobject.h.
| #define CONSTV 1397641027 |
The string CONS, considered as an unsigned int.
Definition at line 46 of file consspaceobject.h.
| #define exceptionp | ( | conspoint | ) | (check_tag(conspoint,EXCEPTIONTV)) |
true if conspoint points to an exception, else false
Definition at line 313 of file consspaceobject.h.
| #define EXCEPTIONTAG "EXEP" |
An exception.
TODO: we need a means of dealing with different classes of exception, and we don't have one yet.
Definition at line 52 of file consspaceobject.h.
| #define EXCEPTIONTV 1346721861 |
The string EXEP, considered as an unsigned int.
Definition at line 57 of file consspaceobject.h.
| #define FREETAG "FREE" |
An unallocated cell on the free list - should never be encountered by a Lisp function.
Definition at line 63 of file consspaceobject.h.
| #define FREETV 1162170950 |
The string FREE, considered as an unsigned int.
Definition at line 68 of file consspaceobject.h.
| #define functionp | ( | conspoint | ) | (check_tag(conspoint,FUNCTIONTV)) |
true if conspoint points to a function cell, else false
Definition at line 318 of file consspaceobject.h.
| #define FUNCTIONTAG "FUNC" |
An ordinary Lisp function - one whose arguments are pre-evaluated.
Definition at line 75 of file consspaceobject.h.
| #define FUNCTIONTV 1129207110 |
The string FUNC, considered as an unsigned int.
Definition at line 80 of file consspaceobject.h.
true if conspoint points to an integer cell, else false
Definition at line 353 of file consspaceobject.h.
| #define INTEGERTAG "INTR" |
An integer number (bignums are integers).
Definition at line 85 of file consspaceobject.h.
| #define INTEGERTV 1381256777 |
The string INTR, considered as an unsigned int.
Definition at line 90 of file consspaceobject.h.
| #define KEYTAG "KEYW" |
A keyword - an interned, self-evaluating string.
Definition at line 95 of file consspaceobject.h.
| #define KEYTV 1465468235 |
The string KEYW, considered as an unsigned int.
Definition at line 100 of file consspaceobject.h.
true if conspoint points to a keyword, else false
Definition at line 323 of file consspaceobject.h.
true if conspoint points to a Lambda binding cell, else false
Definition at line 328 of file consspaceobject.h.
| #define LAMBDATAG "LMDA" |
A lambda cell.
Lambdas are the interpretable (source) versions of functions.
Definition at line 106 of file consspaceobject.h.
| #define LAMBDATV 1094995276 |
The string LMDA, considered as an unsigned int.
Definition at line 111 of file consspaceobject.h.
| #define LAZYCONSTAG "LZYC" |
Tag for a lazy cons cell.
A lazy cons cell is like a cons cell, but lazy.
Definition at line 130 of file consspaceobject.h.
| #define LAZYSTRTAG "LZYS" |
Tag for a lazy string cell.
A lazy string cell is like a string cell, but lazy.
Definition at line 138 of file consspaceobject.h.
| #define LAZYWRKRTAG "WRKR" |
true if conspoint points to a loop recursion, else false.
Definition at line 333 of file consspaceobject.h.
| #define LOOPTAG "LOOP" |
A loop exit is a special kind of exception which has exactly the same payload as an exception.
Definition at line 117 of file consspaceobject.h.
| #define LOOPTV 1347374924 |
The string LOOX, considered as an unsigned int.
Definition at line 122 of file consspaceobject.h.
| #define make_keyword | ( | c, | |
| t | |||
| ) | (make_symbol_or_key( c, t, KEYTV)) |
Definition at line 752 of file consspaceobject.h.
| #define make_symbol | ( | c, | |
| t | |||
| ) | (make_symbol_or_key( c, t, SYMBOLTV)) |
Definition at line 750 of file consspaceobject.h.
| #define MAXREFERENCE 4294967295 |
the maximum possible value of a reference count
Definition at line 287 of file consspaceobject.h.
| #define NIL (struct cons_pointer){ 0, 0} |
a cons pointer which points to the special NIL cell
Definition at line 277 of file consspaceobject.h.
true if conspoint points to the special cell NIL, else false (there should only be one of these so it's slightly redundant).
Definition at line 303 of file consspaceobject.h.
| #define NILTAG "NIL " |
The special cons cell at address {0,0} whose car and cdr both point to itself.
Definition at line 152 of file consspaceobject.h.
| #define NILTV 541870414 |
The string NIL, considered as an unsigned int.
Definition at line 157 of file consspaceobject.h.
| #define NLAMBDATAG "NLMD" |
An nlambda cell.
NLambdas are the interpretable (source) versions of special forms.
Definition at line 163 of file consspaceobject.h.
| #define NLAMBDATV 1145916494 |
The string NLMD, considered as an unsigned int.
Definition at line 168 of file consspaceobject.h.
| #define numberp | ( | conspoint | ) | (check_tag(conspoint,INTEGERTV)||check_tag(conspoint,RATIOTV)||check_tag(conspoint,REALTV)) |
true if conspoint points to some sort of a number cell, else false
Definition at line 374 of file consspaceobject.h.
| #define pointer2cell | ( | pointer | ) | ((conspages[pointer.page]->cell[pointer.offset])) |
given a cons_pointer as argument, return the cell.
Definition at line 297 of file consspaceobject.h.
true if conspoint points to a rational number cell, else false
Definition at line 358 of file consspaceobject.h.
| #define RATIOTAG "RTIO" |
A rational number, stored as pointers two integers representing dividend and divisor respectively.
Definition at line 174 of file consspaceobject.h.
| #define RATIOTV 1330205778 |
The string RTIO, considered as an unsigned int.
Definition at line 179 of file consspaceobject.h.
true if conspoint points to a read stream cell, else false
Definition at line 363 of file consspaceobject.h.
| #define READTAG "READ" |
An open read stream.
Definition at line 184 of file consspaceobject.h.
| #define READTV 1145128274 |
The string READ, considered as an unsigned int.
Definition at line 189 of file consspaceobject.h.
true if conspoint points to a real number cell, else false
Definition at line 368 of file consspaceobject.h.
| #define REALTAG "REAL" |
A real number, represented internally as an IEEE 754-2008 binary64.
Definition at line 194 of file consspaceobject.h.
| #define REALTV 1279346002 |
The string REAL, considered as an unsigned int.
Definition at line 199 of file consspaceobject.h.
| #define sequencep | ( | conspoint | ) | (check_tag(conspoint,CONSTV)||check_tag(conspoint,STRINGTV)||check_tag(conspoint,SYMBOLTV)) |
true if conspoint points to a sequence (list, string or, later, vector), else false.
Definition at line 380 of file consspaceobject.h.
true if conspoint points to a special form cell, else false
Definition at line 338 of file consspaceobject.h.
| #define SPECIALTAG "SPFM" |
A special form - one whose arguments are not pre-evaluated but passed as provided.
Definition at line 206 of file consspaceobject.h.
| #define SPECIALTV 1296453715 |
The string SPFM, considered as an unsigned int.
Definition at line 211 of file consspaceobject.h.
Definition at line 392 of file consspaceobject.h.
true if conspoint points to a string cell, else false
Definition at line 343 of file consspaceobject.h.
| #define STRINGTAG "STRG" |
A string of characters, organised as a linked list.
Definition at line 216 of file consspaceobject.h.
| #define STRINGTV 1196577875 |
The string STRG, considered as an unsigned int.
Definition at line 221 of file consspaceobject.h.
true if conspoint points to a symbol cell, else false
Definition at line 348 of file consspaceobject.h.
| #define SYMBOLTAG "SYMB" |
A symbol is just like a string except not self-evaluating.
Definition at line 226 of file consspaceobject.h.
| #define SYMBOLTV 1112365395 |
The string SYMB, considered as an unsigned int.
Definition at line 231 of file consspaceobject.h.
| #define tag2uint | ( | tag | ) | ((uint32_t)*tag) |
a macro to convert a tag into a number
Definition at line 292 of file consspaceobject.h.
| #define TAGLENGTH 4 |
The length of a tag, in bytes.
Definition at line 30 of file consspaceobject.h.
true if conspoint points to a time cell, else false.
Definition at line 404 of file consspaceobject.h.
| #define TIMETAG "TIME" |
A time stamp.
Definition at line 236 of file consspaceobject.h.
| #define TIMETV 1162692948 |
The string TIME, considered as an unsigned int.
Definition at line 241 of file consspaceobject.h.
true if conspoint points to a true cell, else false (there should only be one of these so it's slightly redundant).
Also note that anything that is not NIL is truthy.
Definition at line 399 of file consspaceobject.h.
| #define TRUE (struct cons_pointer){ 0, 1} |
a cons pointer which points to the special T cell
Definition at line 282 of file consspaceobject.h.
true if conspoint points to something that is truthy, i.e.
anything but NIL.
Definition at line 410 of file consspaceobject.h.
| #define TRUETAG "TRUE" |
The special cons cell at address {0,1} which is canonically different from NIL.
Definition at line 247 of file consspaceobject.h.
| #define TRUETV 1163219540 |
The string TRUE, considered as an unsigned int.
Definition at line 252 of file consspaceobject.h.
| #define vectorpointp | ( | conspoint | ) | (check_tag(conspoint,VECTORPOINTTV)) |
true if conspoint points to a vector pointer, else false.
Definition at line 385 of file consspaceobject.h.
| #define VECTORPOINTTAG "VECP" |
A pointer to an object in vector space.
Definition at line 257 of file consspaceobject.h.
| #define VECTORPOINTTV 1346585942 |
The string VECP, considered as an unsigned int.
Definition at line 262 of file consspaceobject.h.
true if conspoint points to a write stream cell, else false.
Definition at line 390 of file consspaceobject.h.
| #define WRITETAG "WRIT" |
An open write stream.
Definition at line 267 of file consspaceobject.h.
| #define WRITETV 1414091351 |
The string WRIT, considered as an unsigned int.
Definition at line 272 of file consspaceobject.h.
| struct cons_pointer c_car | ( | struct cons_pointer | arg | ) |
Implementation of car in C.
If arg is not a cons, or the current user is not authorised to read it, does not error but returns nil.
Definition at line 125 of file consspaceobject.c.
References authorised(), consp, NIL, pointer2cell, and truep.
Referenced by c_append(), c_apply(), c_assoc(), c_keys(), c_progn(), eval_forms(), eval_lambda(), hashmap_keys(), hashmap_put_all(), lisp_add(), lisp_cond(), lisp_let(), lisp_make_hashmap(), lisp_mapcar(), lisp_multiply(), lisp_repl(), print_map(), read_list(), and read_path().
| struct cons_pointer c_cdr | ( | struct cons_pointer | arg | ) |
Implementation of cdr in C.
If arg is not a sequence, or the current user is not authorised to read it,does not error but returns nil.
Definition at line 139 of file consspaceobject.c.
References authorised(), CONSTV, KEYTV, NIL, cons_space_object::payload, pointer2cell, STRINGTV, SYMBOLTV, cons_space_object::tag, and truep.
Referenced by c_append(), c_apply(), c_keys(), c_length(), c_progn(), c_reverse(), eval_forms(), eval_lambda(), hashmap_keys(), hashmap_put_all(), lisp_add(), lisp_cond(), lisp_cons(), lisp_let(), lisp_make_hashmap(), lisp_mapcar(), lisp_multiply(), lisp_repl(), print_map(), and read_path().
| int c_length | ( | struct cons_pointer | arg | ) |
Implementation of length in C.
If arg is not a cons, does not error but returns 0.
Definition at line 164 of file consspaceobject.c.
Referenced by lisp_length().
| struct cons_pointer c_string_to_lisp_keyword | ( | wchar_t * | symbol | ) |
Return a lisp keyword representation of this wide character string.
In keywords, I am accepting only lower case characters and numbers.
Definition at line 437 of file consspaceobject.c.
References make_keyword, and NIL.
Referenced by add_meta_integer(), add_meta_string(), lisp_metadata(), lisp_source(), main(), and maybe_bind_init_symbols().
| struct cons_pointer c_string_to_lisp_string | ( | wchar_t * | string | ) |
Return a lisp string representation of this wide character string.
Definition at line 454 of file consspaceobject.c.
References make_string(), and NIL.
Referenced by add_2(), add_integer_ratio(), add_meta_string(), add_ratio_ratio(), c_append(), c_apply(), c_assoc(), clone_hashmap(), integer_to_string(), lisp_car(), lisp_cdr(), lisp_cond(), lisp_divide(), lisp_eval(), lisp_let(), lisp_make_hashmap(), lisp_open(), lisp_set(), lisp_set_shriek(), main(), make_ratio(), make_special_frame(), make_stack_frame(), make_symbol_or_key(), multiply_2(), multiply_integer_ratio(), multiply_ratio_ratio(), read_continuation(), read_number(), subtract_2(), and time_to_string().
| struct cons_pointer c_string_to_lisp_symbol | ( | wchar_t * | symbol | ) |
Return a lisp symbol representation of this wide character string.
Definition at line 469 of file consspaceobject.c.
References make_symbol, and NIL.
Referenced by bind_function(), bind_special(), bind_value(), c_quote(), lisp_repl(), lisp_source(), lisp_try(), main(), maybe_bind_init_symbols(), print(), and read_path().
| struct cons_pointer c_type | ( | struct cons_pointer | pointer | ) |
Get the Lisp type of the single argument.
| pointer | a pointer to the object whose type is requested. |
Definition at line 100 of file consspaceobject.c.
References vector_space_object::header, make_string(), NIL, pointer2cell, pointer_to_vso, cons_space_object::tag, vector_space_header::tag, TAGLENGTH, and VECTORPOINTTAG.
Referenced by c_assoc(), internedp(), lisp_metadata(), lisp_type(), multiply_2(), and set().
| bool check_tag | ( | struct cons_pointer | pointer, |
| uint32_t | value | ||
| ) |
True if the value of the tag on the cell at this pointer is this value, or, if the tag of the cell is VECP, if the value of the tag of the vectorspace object indicated by the cell is this value, else false.
Definition at line 35 of file consspaceobject.c.
References vector_space_object::header, pointer2cell, pointer_to_vso, cons_space_object::tag, vector_space_header::tag, and VECTORPOINTTV.
Referenced by free_cell(), and make_string_like_thing().
| struct cons_pointer dec_ref | ( | struct cons_pointer | pointer | ) |
Decrement the reference count of the object at this cons pointer.
If a count has reached MAXREFERENCE it cannot be decremented. If a count is decremented to zero the cell should be freed.
Returns the pointer, or, if the cell has been freed, NIL.
Definition at line 80 of file consspaceobject.c.
References cons_space_object::count, free_cell(), NIL, and pointer2cell.
Referenced by add_integer_ratio(), bind_function(), bind_special(), bind_value(), c_apply(), c_progn(), check_exception(), deep_bind(), divide_ratio_ratio(), eval_form(), eval_lambda(), free_cell(), free_hashmap(), free_init_symbols(), free_stack_frame(), lisp_add(), lisp_divide(), lisp_mapcar(), lisp_print(), lisp_progn(), lisp_read(), lisp_repl(), main(), make_ratio(), print(), read_number(), read_path(), release_integer(), repl(), set_reg(), subtract_2(), and subtract_ratio_ratio().
| struct cons_pointer inc_ref | ( | struct cons_pointer | pointer | ) |
increment the reference count of the object at this cons pointer.
You can't roll over the reference count. Once it hits the maximum value you cannot increment further.
Returns the pointer.
Definition at line 62 of file consspaceobject.c.
References cons_space_object::count, MAXREFERENCE, and pointer2cell.
Referenced by c_apply(), c_progn(), clone_hashmap(), deep_bind(), eval_form(), eval_lambda(), hashmap_put(), int128_to_integer(), lisp_divide(), lisp_eval(), lisp_mapcar(), lisp_print(), lisp_progn(), lisp_read(), lisp_repl(), lisp_source(), make_cons(), make_exception(), make_function(), make_hashmap(), make_lambda(), make_nlambda(), make_ratio(), make_special(), make_special_frame(), make_stack_frame(), read_number(), set_reg(), and subtract_2().
| struct cons_pointer make_cons | ( | struct cons_pointer | car, |
| struct cons_pointer | cdr | ||
| ) |
Construct a cons cell from this pair of pointers.
Definition at line 177 of file consspaceobject.c.
References allocate_cell(), CONSTV, inc_ref(), NIL, cons_space_object::payload, and pointer2cell.
Referenced by add_integer_ratio(), add_meta_integer(), add_meta_string(), add_ratio_ratio(), bind_function(), bind_special(), c_append(), c_keys(), c_quote(), c_reverse(), compose_body(), eval_forms(), eval_lambda(), hashmap_keys(), hashmap_put(), lisp_apply(), lisp_cons(), lisp_eval(), lisp_let(), lisp_list(), lisp_make_hashmap(), lisp_mapcar(), lisp_metadata(), lisp_repl(), lisp_set(), lisp_set_shriek(), lisp_source(), lisp_try(), main(), multiply_2(), print(), read_continuation(), read_list(), read_path(), repl(), and set().
| struct cons_pointer make_exception | ( | struct cons_pointer | message, |
| struct cons_pointer | frame_pointer | ||
| ) |
Construct an exception cell.
| message | should be a lisp string describing the problem, but actually any cons pointer will do; |
| frame_pointer | should be the pointer to the frame in which the exception occurred. |
Definition at line 200 of file consspaceobject.c.
References allocate_cell(), EXCEPTIONTV, inc_ref(), NIL, cons_space_object::payload, and pointer2cell.
Referenced by clone_hashmap(), lisp_make_hashmap(), lisp_open(), make_special_frame(), make_stack_frame(), make_symbol_or_key(), and throw_exception().
| struct cons_pointer make_function | ( | struct cons_pointer | src, |
| struct cons_pointer(*)(struct stack_frame *, struct cons_pointer, struct cons_pointer) | executable | ||
| ) |
Construct a cell which points to an executable Lisp function.
Definition at line 218 of file consspaceobject.c.
References allocate_cell(), FUNCTIONTV, inc_ref(), cons_space_object::payload, and pointer2cell.
Referenced by bind_function().
| struct cons_pointer make_lambda | ( | struct cons_pointer | args, |
| struct cons_pointer | body | ||
| ) |
Construct a lambda (interpretable source) cell.
Definition at line 240 of file consspaceobject.c.
References allocate_cell(), inc_ref(), LAMBDATV, cons_space_object::payload, and pointer2cell.
Referenced by lisp_lambda().
| struct cons_pointer make_nlambda | ( | struct cons_pointer | args, |
| struct cons_pointer | body | ||
| ) |
Construct an nlambda (interpretable source) cell; to a lambda as a special form is to a function.
Definition at line 257 of file consspaceobject.c.
References allocate_cell(), inc_ref(), NLAMBDATV, cons_space_object::payload, and pointer2cell.
Referenced by lisp_nlambda().
| struct cons_pointer make_read_stream | ( | URL_FILE * | input, |
| struct cons_pointer | metadata | ||
| ) |
Construct a cell which points to a stream open for reading.
| input | the C stream to wrap. |
| metadata | a pointer to an associaton containing metadata on the stream. |
Definition at line 405 of file consspaceobject.c.
References allocate_cell(), cons_space_object::payload, pointer2cell, and READTV.
Referenced by lisp_open(), and main().
| struct cons_pointer make_special | ( | struct cons_pointer | src, |
| struct cons_pointer(*)(struct stack_frame *, struct cons_pointer, struct cons_pointer) | executable | ||
| ) |
| struct cons_pointer make_string | ( | wint_t | c, |
| struct cons_pointer | tail | ||
| ) |
Construct a string from the character c and this tail.
A string is implemented as a flat list of cells each of which has one character and a pointer to the next; in the last cell the pointer to next is NIL.
| c | the character to add (prepend); |
| tail | the string which is being built. |
Definition at line 338 of file consspaceobject.c.
References make_string_like_thing(), and STRINGTV.
Referenced by c_reverse(), c_string_to_lisp_string(), c_type(), integer_to_string(), integer_to_string_add_digit(), lisp_car(), lisp_cons(), lisp_read_char(), lisp_slurp(), read_continuation(), and read_string().
| struct cons_pointer make_string_like_thing | ( | wint_t | c, |
| struct cons_pointer | tail, | ||
| uint32_t | tag | ||
| ) |
Construct a string from this character (which later will be UTF) and this tail.
A string is implemented as a flat list of cells each of which has one character and a pointer to the next; in the last cell the pointer to next is NIL.
Definition at line 308 of file consspaceobject.c.
References allocate_cell(), calculate_hash(), check_tag(), DEBUG_ALLOC, debug_printf(), NIL, NILTV, cons_space_object::payload, and pointer2cell.
Referenced by c_append(), make_string(), and make_symbol_or_key().
| struct cons_pointer make_symbol_or_key | ( | wint_t | c, |
| struct cons_pointer | tail, | ||
| uint32_t | tag | ||
| ) |
Construct a symbol or keyword from the character c and this tail.
Each is internally identical to a string except for having a different tag.
| c | the character to add (prepend); |
| tail | the symbol which is being built. |
| tag | the tag to use: expected to be "SYMB" or "KEYW" |
Definition at line 350 of file consspaceobject.c.
References c_string_to_lisp_string(), intern(), internedp(), KEYTV, make_exception(), make_string_like_thing(), NIL, nilp, oblist, and SYMBOLTV.
Referenced by c_reverse(), read_continuation(), and read_symbol_or_key().
| struct cons_pointer make_write_stream | ( | URL_FILE * | output, |
| struct cons_pointer | metadata | ||
| ) |
Construct a cell which points to a stream open for writing.
| output | the C stream to wrap. |
| metadata | a pointer to an associaton containing metadata on the stream. |
Definition at line 422 of file consspaceobject.c.
References allocate_cell(), cons_space_object::payload, pointer2cell, and WRITETV.
Referenced by lisp_open(), and main().