Post Scarcity 0.0.6
A prototype for a post scarcity programming environment
Loading...
Searching...
No Matches
consspaceobject.c File Reference
#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"
Include dependency graph for consspaceobject.c:

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.
 

Function Documentation

◆ c_car()

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().

◆ c_cdr()

◆ c_length()

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.

References c_cdr(), and nilp.

Referenced by equal_map_map(), and lisp_length().

◆ c_string_to_lisp_keyword()

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().

◆ c_string_to_lisp_string()

◆ c_string_to_lisp_symbol()

◆ c_type()

struct cons_pointer c_type ( struct cons_pointer  pointer)

Get the Lisp type of the single argument.

Parameters
pointera pointer to the object whose type is requested.
Returns
As a Lisp string, the tag of the object which is at that pointer.

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().

◆ calculate_hash()

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().

◆ check_tag()

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().

◆ dec_ref()

struct cons_pointer dec_ref ( struct cons_pointer  pointer)

◆ get_tag_value()

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().

◆ inc_ref()

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().

◆ make_cons()

◆ make_exception()

struct cons_pointer make_exception ( struct cons_pointer  message,
struct cons_pointer  frame_pointer 
)

Construct an exception cell.

Parameters
messageshould be a lisp string describing the problem, but actually any cons pointer will do;
frame_pointershould 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().

◆ make_function()

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().

◆ make_lambda()

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().

◆ make_nlambda()

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().

◆ make_read_stream()

struct cons_pointer make_read_stream ( URL_FILE input,
struct cons_pointer  metadata 
)

Construct a cell which points to a stream open for reading.

Parameters
inputthe C stream to wrap.
metadataa pointer to an associaton containing metadata on the stream.
Returns
a pointer to the new read 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().

◆ make_special()

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().

◆ make_string()

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.

Parameters
cthe character to add (prepend);
tailthe 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().

◆ make_string_like_thing()

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().

◆ 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.

Parameters
cthe character to add (prepend);
tailthe symbol which is being built.
tagthe 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().

◆ make_write_stream()

struct cons_pointer make_write_stream ( URL_FILE output,
struct cons_pointer  metadata 
)

Construct a cell which points to a stream open for writing.

Parameters
outputthe C stream to wrap.
metadataa pointer to an associaton containing metadata on the stream.
Returns
a pointer to the new read 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().

Variable Documentation

◆ privileged_keyword_cause

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().

◆ privileged_keyword_documentation

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().

◆ privileged_keyword_location

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().

◆ privileged_keyword_name

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().

◆ privileged_keyword_payload

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().

◆ privileged_keyword_primitive

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().