Post Scarcity
A prototype for a post scarcity programming environment
Loading...
Searching...
No Matches
vectorspace.h
Go to the documentation of this file.
1/**
2 * vectorspace.h
3 *
4 * Declarations common to all vector space objects.
5 *
6 *
7 * (c) 2017 Simon Brooke <simon@journeyman.cc>
8 * Licensed under GPL version 2.0, or, at your option, any later version.
9 */
10
11#include <stdbool.h>
12#include <stdint.h>
13#include <stdio.h>
14/*
15 * wide characters
16 */
17#include <wchar.h>
18#include <wctype.h>
19
20#include "consspaceobject.h"
21#include "hashmap.h"
22
23#ifndef __vectorspace_h
24#define __vectorspace_h
25
26/*
27 * part of the implementation structure of a namespace.
28 */
29#define HASHTAG "HASH"
30#define HASHTV 1213415752
31
32#define hashmapp(conspoint)((check_tag(conspoint,HASHTV)))
33
34/*
35 * a namespace (i.e. a binding of names to values, implemented as a hashmap)
36 * TODO: but note that a namespace is now essentially a hashmap with a write ACL
37 * whose name is interned.
38 */
39#define NAMESPACETAG "NMSP"
40#define NAMESPACETV 1347636558
41
42#define namespacep(conspoint)(check_tag(conspoint,NAMESPACETV))
43
44/*
45 * a vector of cons pointers.
46 */
47#define VECTORTAG "VECT"
48#define VECTORTV 1413694806
49
50#define vectorp(conspoint)(check_tag(conspoint,VECTORTV))
51
52/**
53 * given a pointer to a vector space object, return the object.
54 */
55#define pointer_to_vso(pointer)((vectorpointp(pointer)? (struct vector_space_object *) pointer2cell(pointer).payload.vectorp.address : (struct vector_space_object *) NULL))
56
57/**
58 * given a vector space object, return its canonical pointer.
59 */
60#define vso_get_vecp(vso)((((vector_space_object)vso)->header.vecp))
61
62struct cons_pointer make_vso( uint32_t tag, uint64_t payload_size );
63
64void free_vso( struct cons_pointer pointer );
65
66/**
67 * the header which forms the start of every vector space object.
68 */
70 /** the tag (type) of this vector-space object. */
71 union {
72 /** the tag considered as bytes. */
73 char bytes[TAGLENGTH];
74 /** the tag considered as a number */
75 uint32_t value;
76 } tag;
77 /** back pointer to the vector pointer which uniquely points to this vso */
79 /** the size of my payload, in bytes */
80 uint64_t size;
81};
82
83/**
84 * The payload of a hashmap. The number of buckets is assigned at run-time,
85 * and is stored in n_buckets. Each bucket is something ASSOC can consume:
86 * i.e. either an assoc list or a further hashmap.
87 */
89 struct cons_pointer hash_fn; /* function for hashing values in this hashmap, or `NIL` to use
90 the default hashing function */
91 struct cons_pointer write_acl; /* it seems to me that it is likely that the
92 * principal difference between a hashmap and a
93 * namespace is that a hashmap has a write ACL
94 * of `NIL`, meaning not writeable by anyone */
95 uint32_t n_buckets; /* number of hash buckets */
96 uint32_t unused; /* for word alignment and possible later expansion */
97 struct cons_pointer buckets[]; /* actual hash buckets, which should be `NIL`
98 * or assoc lists or (possibly) further hashmaps. */
99};
100
101
102/** a vector_space_object is just a vector_space_header followed by a
103 * lump of bytes; what we deem to be in there is a function of the tag,
104 * and at this stage we don't have a good picture of what these may be.
105 *
106 * \see stack_frame for an example payload;
107 * \see make_empty_frame for an example of how to initialise and use one.
108 */
110 /** the header of this object */
112 /** we'll malloc `size` bytes for payload, `payload` is just the first of these.
113 * \todo this is almost certainly not idiomatic C. */
114 union {
115 /** the payload considered as bytes */
116 char bytes;
117 struct hashmap_payload hashmap;
119};
120
121#endif
#define TAGLENGTH
The length of a tag, in bytes.
An indirect pointer to a cons cell.
struct cons_pointer hash_fn
Definition vectorspace.h:89
uint32_t n_buckets
Definition vectorspace.h:95
struct cons_pointer write_acl
Definition vectorspace.h:91
union vector_space_object::@5 payload
we'll malloc size bytes for payload, payload is just the first of these.
void free_vso(struct cons_pointer pointer)
for vector space pointers, free the actual vector-space object.
uint32_t unused
Definition vectorspace.h:96
struct vector_space_header header
the header of this object
struct cons_pointer vecp
back pointer to the vector pointer which uniquely points to this vso
Definition vectorspace.h:78
union vector_space_header::@4 tag
the tag (type) of this vector-space object.
struct cons_pointer buckets[]
Definition vectorspace.h:97
struct cons_pointer make_vso(uint32_t tag, uint64_t payload_size)
Allocate a vector space object with this payload_size and tag, and return a cons_pointer which points...
Definition vectorspace.c:75
uint64_t size
the size of my payload, in bytes
Definition vectorspace.h:80
The payload of a hashmap.
Definition vectorspace.h:88
the header which forms the start of every vector space object.
Definition vectorspace.h:69
a vector_space_object is just a vector_space_header followed by a lump of bytes; what we deem to be i...