Post Scarcity
A prototype for a post scarcity programming environment
Loading...
Searching...
No Matches
intern.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

struct cons_pointer c_assoc (struct cons_pointer key, struct cons_pointer store)
 Implementation of assoc in C.
 
struct cons_pointer deep_bind (struct cons_pointer key, struct cons_pointer value)
 Binds this key to this value in the global oblist.
 
void dump_map (URL_FILE *output, struct cons_pointer pointer)
 
void free_hashmap (struct cons_pointer ptr)
 Free the hashmap indicated by this pointer.
 
uint32_t get_hash (struct cons_pointer ptr)
 Get the hash value for the cell indicated by this ptr; currently only implemented for string like things and integers.
 
struct cons_pointer hashmap_get (struct cons_pointer mapp, struct cons_pointer key)
 Get a value from a hashmap.
 
struct cons_pointer hashmap_keys (struct cons_pointer map)
 return a flat list of all the keys in the hashmap indicated by map.
 
struct cons_pointer hashmap_put (struct cons_pointer mapp, struct cons_pointer key, struct cons_pointer val)
 Store this val as the value of this key in this hashmap mapp.
 
struct cons_pointer hashmap_put_all (struct cons_pointer mapp, struct cons_pointer assoc)
 Copy all key/value pairs in this association list assoc into this hashmap mapp.
 
struct cons_pointer intern (struct cons_pointer key, struct cons_pointer environment)
 Ensure that a canonical copy of this key is bound in this environment, and return that canonical copy.
 
struct cons_pointer internedp (struct cons_pointer key, struct cons_pointer environment)
 Implementation of interned? in C.
 
struct cons_pointer make_hashmap (uint32_t n_buckets, struct cons_pointer hash_fn, struct cons_pointer write_acl)
 Make a hashmap with this number of buckets, using this hash_fn.
 
struct cons_pointer set (struct cons_pointer key, struct cons_pointer value, struct cons_pointer store)
 Return a new key/value store containing all the key/value pairs in this store with this key/value pair added to the front.
 

Variables

struct cons_pointer oblist
 The global object list/or, to put it differently, the root namespace.
 
struct cons_pointer privileged_symbol_nil
 the symbol NIL, which is special!
 

Function Documentation

◆ c_assoc()

struct cons_pointer c_assoc ( struct cons_pointer  key,
struct cons_pointer  store 
)

Implementation of assoc in C.

Like interned?, the final implementation will deal with stores which can be association lists or hashtables or hybrids of the two, but that will almost certainly be implemented in lisp.

If this key is lexically identical to a key in this store, return the value of that key from the store; otherwise return NIL.

Definition at line 327 of file intern.c.

References c_append(), c_car(), c_string_to_lisp_string(), c_type(), consp, CONSTV, DEBUG_BIND, debug_print(), debug_print_object(), debug_println(), equal(), hashmap_get(), hashmapp, NIL, nilp, cons_space_object::payload, pointer2cell, cons_space_object::tag, throw_exception(), and VECTORPOINTTV.

Referenced by c_apply(), get_default_stream(), hashmap_get(), internedp(), lisp_assoc(), lisp_eval(), lisp_repl(), and lisp_source().

◆ deep_bind()

struct cons_pointer deep_bind ( struct cons_pointer  key,
struct cons_pointer  value 
)

Binds this key to this value in the global oblist.

Definition at line 447 of file intern.c.

References consp, DEBUG_BIND, debug_print(), debug_print_object(), debug_println(), dec_ref(), inc_ref(), oblist, and set().

Referenced by bind_function(), bind_special(), bind_symbol_value(), lisp_set(), and lisp_set_shriek().

◆ dump_map()

void dump_map ( URL_FILE output,
struct cons_pointer  pointer 
)

◆ free_hashmap()

void free_hashmap ( struct cons_pointer  ptr)

Free the hashmap indicated by this pointer.

Definition at line 110 of file intern.c.

References DEBUG_ALLOC, debug_printf(), dec_ref(), hashmapp, nilp, cons_space_object::payload, vector_space_object::payload, and pointer2cell.

Referenced by free_vso().

◆ get_hash()

uint32_t get_hash ( struct cons_pointer  ptr)

Get the hash value for the cell indicated by this ptr; currently only implemented for string like things and integers.

Definition at line 81 of file intern.c.

References INTEGERTV, KEYTV, cons_space_object::payload, pointer2cell, STRINGTV, sxhash(), SYMBOLTV, cons_space_object::tag, and TRUETV.

Referenced by hashmap_get(), hashmap_put(), lisp_get_hash(), and lisp_make_hashmap().

◆ hashmap_get()

struct cons_pointer hashmap_get ( struct cons_pointer  mapp,
struct cons_pointer  key 
)

Get a value from a hashmap.

Note that this is here, rather than in memory/hashmap.c, because it is closely tied in with c_assoc, q.v.

Definition at line 220 of file intern.c.

References authorised(), c_assoc(), get_hash(), hashmapp, NIL, nilp, vector_space_object::payload, pointer_to_vso, and truep.

Referenced by c_assoc(), hashmap_put_all(), and print_map().

◆ hashmap_keys()

struct cons_pointer hashmap_keys ( struct cons_pointer  map)

return a flat list of all the keys in the hashmap indicated by map.

Definition at line 162 of file intern.c.

References authorised(), c_car(), c_cdr(), hashmapp, make_cons(), NIL, nilp, vector_space_object::payload, pointer_to_vso, and truep.

Referenced by c_keys(), hashmap_put_all(), lisp_hashmap_keys(), and print_map().

◆ hashmap_put()

struct cons_pointer hashmap_put ( struct cons_pointer  mapp,
struct cons_pointer  key,
struct cons_pointer  val 
)

Store this val as the value of this key in this hashmap mapp.

If current user is authorised to write to this hashmap, modifies the hashmap and returns it; if not, clones the hashmap, modifies the clone, and returns that.

Definition at line 385 of file intern.c.

References authorised(), clone_hashmap(), get_hash(), hashmapp, inc_ref(), make_cons(), nilp, vector_space_object::payload, and pointer_to_vso.

Referenced by hashmap_put_all(), lisp_hashmap_put(), read_map(), and set().

◆ hashmap_put_all()

struct cons_pointer hashmap_put_all ( struct cons_pointer  mapp,
struct cons_pointer  assoc 
)

Copy all key/value pairs in this association list assoc into this hashmap mapp.

If current user is authorised to write to this hashmap, modifies the hashmap and returns it; if not, clones the hashmap, modifies the clone, and returns that.

Definition at line 183 of file intern.c.

References c_car(), c_cdr(), consp, hashmap_get(), hashmap_keys(), hashmap_put(), hashmap_put_all(), hashmapp, nilp, pointer_to_vso, and TRUE.

Referenced by hashmap_put_all(), and lisp_hashmap_put_all().

◆ intern()

struct cons_pointer intern ( struct cons_pointer  key,
struct cons_pointer  environment 
)

Ensure that a canonical copy of this key is bound in this environment, and return that canonical copy.

If there is currently no such binding, create one with the value NIL.

Definition at line 478 of file intern.c.

References internedp(), NIL, nilp, and set().

Referenced by make_symbol_or_key().

◆ internedp()

struct cons_pointer internedp ( struct cons_pointer  key,
struct cons_pointer  store 
)

Implementation of interned? in C.

The final implementation if interned? will deal with stores which can be association lists or hashtables or hybrids of the two, but that will almost certainly be implemented in lisp.

If this key is lexically identical to a key in this store, return the key from the store (so that later when we want to retrieve a value, an eq test will work); otherwise return NIL.

Definition at line 281 of file intern.c.

References c_assoc(), c_type(), DEBUG_BIND, debug_print(), debug_print_object(), equal(), keywordp, NIL, nilp, privileged_symbol_nil, and symbolp.

Referenced by intern(), lisp_eval(), and make_symbol_or_key().

◆ make_hashmap()

struct cons_pointer make_hashmap ( uint32_t  n_buckets,
struct cons_pointer  hash_fn,
struct cons_pointer  write_acl 
)

Make a hashmap with this number of buckets, using this hash_fn.

If hash_fn is NIL, use the standard hash funtion.

Definition at line 137 of file intern.c.

References hashmap_payload::buckets, hashmap_payload::hash_fn, HASHTV, inc_ref(), make_vso(), hashmap_payload::n_buckets, NIL, pointer_to_vso, and hashmap_payload::write_acl.

Referenced by clone_hashmap(), lisp_make_hashmap(), main(), and read_map().

◆ set()

struct cons_pointer set ( struct cons_pointer  key,
struct cons_pointer  value,
struct cons_pointer  store 
)

Return a new key/value store containing all the key/value pairs in this store with this key/value pair added to the front.

Definition at line 412 of file intern.c.

References c_type(), consp, DEBUG_BIND, debug_dump_object(), debug_print(), debug_print_object(), debug_printf(), debug_println(), hashmap_put(), hashmapp, lisp_string_to_c_string(), make_cons(), NIL, and nilp.

Referenced by deep_bind(), eval_lambda(), intern(), and lisp_repl().

Variable Documentation

◆ oblist

struct cons_pointer oblist
extern

The global object list/or, to put it differently, the root namespace.

What is added to this during system setup is 'global', that is, visible to all sessions/threads. What is added during a session/thread is local to that session/thread (because shallow binding). There must be some way for a user to make the contents of their own environment persistent between threads but I don't know what it is yet. At some stage there must be a way to rebind deep values so they're visible to all users/threads, but again I don't yet have any idea how that will work.

Definition at line 48 of file intern.c.

Referenced by deep_bind(), lisp_oblist(), lisp_repl(), lisp_set(), main(), make_symbol_or_key(), and repl().

◆ privileged_symbol_nil

struct cons_pointer privileged_symbol_nil
extern

the symbol NIL, which is special!

Definition at line 54 of file intern.c.

Referenced by internedp(), main(), and maybe_bind_init_symbols().