Post Scarcity 0.0.6
A prototype for a post scarcity programming environment
Loading...
Searching...
No Matches
intern.h File Reference
#include <stdbool.h>
Include dependency graph for intern.h:
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, and returns the key.
 
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, bool return_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 interned (struct cons_pointer key, struct cons_pointer environment)
 
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 search_store (struct cons_pointer key, struct cons_pointer store, bool return_key)
 (search-store key store return-key?) Search this store for this a key lexically identical to this key.
 
struct cons_pointer set (struct cons_pointer key, struct cons_pointer value, struct cons_pointer store)
 If this store is modifiable, add this key value pair to it.
 

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 478 of file intern.c.

References search_store().

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

◆ 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, and returns the key.

Definition at line 545 of file intern.c.

References DEBUG_BIND, debug_print(), debug_print_object(), debug_println(), 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 111 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 82 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,
bool  return_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 search_store, q.v.

Definition at line 221 of file intern.c.

References authorised(), c_type(), DEBUG_BIND, debug_print(), debug_print_object(), debug_printf(), get_hash(), hashmapp, NIL, nilp, vector_space_object::payload, pointer_to_vso, search_store(), and truep.

Referenced by equal_map_map(), hashmap_put_all(), print_map(), and search_store().

◆ 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 163 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(), equal_map_map(), 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 488 of file intern.c.

References authorised(), clone_hashmap(), DEBUG_BIND, debug_dump_object(), debug_print(), get_hash(), hashmapp, 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 184 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 TRUE.

Definition at line 563 of file intern.c.

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

◆ interned()

struct cons_pointer interned ( struct cons_pointer  key,
struct cons_pointer  environment 
)

Definition at line 424 of file intern.c.

References search_store().

Referenced by lisp_eval().

◆ internedp()

struct cons_pointer internedp ( struct cons_pointer  key,
struct cons_pointer  environment 
)

Implementation of interned? in C.

Parameters
keythe key to search for.
storethe store to search in.
Returns
struct cons_pointer t if the key was found, else nil.

Definition at line 436 of file intern.c.

References c_car(), c_cdr(), consp, eq(), equal(), hashmapp, internedp(), NIL, nilp, vector_space_object::payload, pointer_to_vso, and TRUE.

Referenced by intern(), internedp(), and lisp_internedp().

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

◆ search_store()

struct cons_pointer search_store ( struct cons_pointer  key,
struct cons_pointer  store,
bool  return_key 
)

(search-store key store return-key?) Search this store for this a key lexically identical to this key.

If found, then, if return-key? is non-nil, return the copy found in the store, else return the value associated with it.

At this stage the following structures are legal stores:

  1. an association list comprising (key . value) dotted pairs;
  2. a hashmap;
  3. a namespace (which for these purposes is identical to a hashmap);
  4. a hybrid list comprising both (key . value) pairs and hashmaps as first level items;
  5. such a hybrid list, but where the last CDR pointer is to a hashmap rather than to a cons sell or to nil.

This is over-complex and type 5 should be disallowed, but it will do for now.

Definition at line 305 of file intern.c.

References c_car(), c_cdr(), c_string_to_lisp_string(), c_string_to_lisp_symbol(), c_type(), consp, CONSTV, DEBUG_BIND, debug_print(), debug_print_object(), debug_printf(), equal(), EXCEPTIONTV, get_tag_value(), hashmap_get(), hashmapp, HASHTV, KEYTV, make_cons(), NAMESPACETV, NIL, nilp, pointer2cell, SYMBOLTV, and throw_exception().

Referenced by c_assoc(), hashmap_get(), and interned().

◆ set()

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

If this store is modifiable, add this key value pair to it.

Otherwise, 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 519 of file intern.c.

References consp, DEBUG_BIND, debug_print_binding(), debug_printf(), eq(), hashmap_put(), hashmapp, make_cons(), NIL, nilp, oblist, and pointer2cell.

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

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 49 of file intern.c.

Referenced by deep_bind(), lisp_assoc(), lisp_internedp(), lisp_oblist(), lisp_repl(), lisp_set(), main(), repl(), and set().

◆ privileged_symbol_nil

struct cons_pointer privileged_symbol_nil
extern

the symbol NIL, which is special!

Definition at line 55 of file intern.c.

Referenced by main(), and maybe_bind_init_symbols().