|
Post Scarcity
A prototype for a post scarcity programming environment
|
#include <stdint.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <wchar.h>#include <wctype.h>#include "authorise.h"#include "debug.h"#include "io/print.h"#include "memory/conspage.h"#include "memory/consspaceobject.h"#include "memory/stack.h"#include "memory/vectorspace.h"#include "ops/intern.h"Go to the source code of this file.
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. | |
| uint32_t | calculate_hash (wint_t c, struct cons_pointer ptr) |
| Return a hash value for this string like thing. | |
| 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 meta, 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 meta, struct cons_pointer(*executable)(struct stack_frame *frame, struct cons_pointer, struct cons_pointer env)) |
| Construct a cell which points to an executable Lisp special form. | |
| 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_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().
| uint32_t calculate_hash | ( | wint_t | c, |
| struct cons_pointer | ptr | ||
| ) |
Return a hash value for this string like thing.
What's important here is that two strings with the same characters in the same order should have the same hash value, even if one was created using "foobar" and the other by (append "foo" "bar"). I think this function has that property. I doubt that it's the most efficient hash function to have that property.
returns 0 for things which are not string like.
Definition at line 281 of file consspaceobject.c.
References KEYTV, nilp, cons_space_object::payload, pointer2cell, STRINGTV, SYMBOLTV, and cons_space_object::tag.
Referenced by make_string_like_thing().
| 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 | meta, |
| 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 | meta, |
| struct cons_pointer(*)(struct stack_frame *frame, struct cons_pointer, struct cons_pointer env) | executable | ||
| ) |
Construct a cell which points to an executable Lisp special form.
Definition at line 379 of file consspaceobject.c.
References allocate_cell(), inc_ref(), cons_space_object::payload, pointer2cell, and SPECIALTV.
Referenced by bind_special().
| 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().