|
Post Scarcity 0.0.6
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. | |
| uint32_t | get_tag_value (struct cons_pointer pointer) |
| given a cons_pointer as argument, return the tag. | |
| 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. | |
Variables | |
| struct cons_pointer | privileged_keyword_cause = NIL |
Keywords used when constructing exceptions: :payload. | |
| struct cons_pointer | privileged_keyword_documentation = NIL |
keywords used in documentation: :documentation. | |
| struct cons_pointer | privileged_keyword_location = NIL |
Keywords used when constructing exceptions: :location. | |
| struct cons_pointer | privileged_keyword_name = NIL |
keywords used in documentation: :name. | |
| struct cons_pointer | privileged_keyword_payload = NIL |
Keywords used when constructing exceptions: :payload. | |
| struct cons_pointer | privileged_keyword_primitive = NIL |
keywords used in documentation: :primitive. | |
| 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 207 of file consspaceobject.c.
References authorised(), consp, NIL, pointer2cell, and truep.
Referenced by c_append(), c_apply(), c_keys(), c_progn(), equal_map_map(), eval_cond_clause(), eval_forms(), eval_lambda(), hashmap_keys(), hashmap_put_all(), internedp(), lisp_add(), lisp_cond(), lisp_let(), lisp_make_hashmap(), lisp_mapcar(), lisp_multiply(), lisp_repl(), print_map(), read_list(), read_path(), and search_store().
| 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 221 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_count(), c_keys(), c_length(), c_progn(), c_reverse(), equal(), equal_map_map(), eval_cond_clause(), eval_forms(), eval_lambda(), hashmap_keys(), hashmap_put_all(), internedp(), lisp_add(), lisp_cond(), lisp_cons(), lisp_let(), lisp_make_hashmap(), lisp_mapcar(), lisp_multiply(), lisp_repl(), make_stack_frame(), print_map(), read_path(), and search_store().
| 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 246 of file consspaceobject.c.
Referenced by equal_map_map(), and 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 521 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 538 of file consspaceobject.c.
References make_string(), and NIL.
Referenced by add_2(), add_integer_ratio(), add_meta_string(), add_ratio_ratio(), bind_function(), bind_special(), c_append(), c_apply(), clone_hashmap(), eval_cond_clause(), integer_to_string(), lisp_car(), lisp_cdr(), lisp_divide(), lisp_eval(), lisp_let(), lisp_make_hashmap(), lisp_open(), lisp_set(), lisp_set_shriek(), main(), make_empty_frame(), make_ratio(), make_symbol_or_key(), maybe_bind_init_symbols(), multiply_2(), multiply_integer_ratio(), multiply_ratio_ratio(), read_continuation(), read_number(), search_store(), 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 553 of file consspaceobject.c.
References make_symbol, and NIL.
Referenced by add_2(), add_integer_ratio(), add_ratio_ratio(), bind_function(), bind_special(), bind_value(), c_append(), c_apply(), c_quote(), eval_cond_clause(), lisp_car(), lisp_cdr(), lisp_divide(), lisp_eval(), lisp_internedp(), lisp_let(), lisp_repl(), lisp_set(), lisp_set_shriek(), lisp_source(), lisp_try(), main(), make_ratio(), maybe_bind_init_symbols(), multiply_2(), multiply_integer_ratio(), multiply_ratio_ratio(), print(), read_continuation(), read_number(), read_path(), search_store(), and subtract_2().
| 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 178 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 VECTORPOINTTV.
Referenced by hashmap_get(), lisp_metadata(), lisp_type(), multiply_2(), and search_store().
| 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 363 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 73 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 131 of file consspaceobject.c.
References cons_space_object::count, DEBUG_ALLOC, debug_printf(), debug_println(), free_cell(), NIL, cons_space_object::payload, pointer2cell, cons_space_object::tag, TAGLENGTH, and VECTORPOINTTAG.
Referenced by add_integer_ratio(), bind_function(), bind_special(), bind_value(), c_apply(), c_progn(), check_exception(), divide_ratio_ratio(), eval_form(), eval_lambda(), free_cell(), free_hashmap(), free_init_symbols(), free_stack_frame(), lisp_add(), lisp_divide(), lisp_internedp(), 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().
| uint32_t get_tag_value | ( | struct cons_pointer | pointer | ) |
given a cons_pointer as argument, return the tag.
Definition at line 163 of file consspaceobject.c.
References pointer2cell, pointer_to_vso, and VECTORPOINTTV.
Referenced by c_apply(), maybe_fixup_exception_location(), and search_store().
| 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 100 of file consspaceobject.c.
References cons_space_object::count, DEBUG_ALLOC, debug_printf(), debug_println(), MAXREFERENCE, cons_space_object::payload, pointer2cell, cons_space_object::tag, TAGLENGTH, and VECTORPOINTTAG.
Referenced by clone_hashmap(), lisp_divide(), lisp_mapcar(), lisp_print(), 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 259 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_cond_clause(), 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(), maybe_fixup_exception_location(), multiply_2(), print(), read_continuation(), read_list(), read_path(), repl(), search_store(), set(), and throw_exception_with_cause().
| 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 282 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_empty_frame(), make_symbol_or_key(), and throw_exception_with_cause().
| 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 300 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 322 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 339 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 489 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 463 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 422 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 390 of file consspaceobject.c.
References allocate_cell(), calculate_hash(), check_tag(), DEBUG_ALLOC, debug_dump_object(), debug_printf(), debug_println(), 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 434 of file consspaceobject.c.
References c_string_to_lisp_string(), KEYTV, make_exception(), make_string_like_thing(), NIL, 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 506 of file consspaceobject.c.
References allocate_cell(), cons_space_object::payload, pointer2cell, and WRITETV.
Referenced by lisp_open(), and main().
| struct cons_pointer privileged_keyword_cause = NIL |
Keywords used when constructing exceptions: :payload.
Keywords used when constructing exceptions: :cause.
Instantiated in init.c, q.v.
Definition at line 46 of file consspaceobject.c.
Referenced by maybe_bind_init_symbols(), and throw_exception_with_cause().
| struct cons_pointer privileged_keyword_documentation = NIL |
keywords used in documentation: :documentation.
Instantiated in init.c, q. v.
Definition at line 53 of file consspaceobject.c.
Referenced by bind_function(), bind_special(), free_init_symbols(), and maybe_bind_init_symbols().
| struct cons_pointer privileged_keyword_location = NIL |
Keywords used when constructing exceptions: :location.
Instantiated in init.cq.v.
Definition at line 34 of file consspaceobject.c.
Referenced by main(), maybe_bind_init_symbols(), maybe_fixup_exception_location(), and throw_exception_with_cause().
| struct cons_pointer privileged_keyword_name = NIL |
keywords used in documentation: :name.
Instantiated in init.c, q. v.
Definition at line 59 of file consspaceobject.c.
Referenced by bind_function(), bind_special(), free_init_symbols(), maybe_bind_init_symbols(), and maybe_fixup_exception_location().
| struct cons_pointer privileged_keyword_payload = NIL |
Keywords used when constructing exceptions: :payload.
Instantiated in init.c, q.v.
Definition at line 40 of file consspaceobject.c.
Referenced by main(), maybe_bind_init_symbols(), maybe_fixup_exception_location(), and throw_exception_with_cause().
| struct cons_pointer privileged_keyword_primitive = NIL |
keywords used in documentation: :primitive.
Instantiated in init.c, q. v.
Definition at line 65 of file consspaceobject.c.
Referenced by bind_function(), bind_special(), free_init_symbols(), and maybe_bind_init_symbols().