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

Go to the source code of this file.

Data Structures

struct  cons_page
 a cons page is essentially just an array of cons space objects. More...
 

Macros

#define CONSPAGESIZE   1024
 the number of cons cells on a cons page.
 
#define NCONSPAGES   64
 the number of cons pages we will initially allow for.
 

Functions

struct cons_pointer allocate_cell (uint32_t tag)
 Allocates a cell with the specified tag.
 
void dump_pages (URL_FILE *output)
 dump the allocated pages to this output stream.
 
void free_cell (struct cons_pointer pointer)
 Frees the cell at the specified pointer; for all the types of cons-space object which point to other cons-space objects, cascade the decrement.
 
void initialise_cons_pages ()
 initialise the cons page system; to be called exactly once during startup.
 
void summarise_allocation ()
 

Variables

struct cons_pageconspages [NCONSPAGES]
 An array of pointers to cons pages.
 
struct cons_pointer freelist
 The (global) pointer to the (global) freelist.
 

Data Structure Documentation

◆ cons_page

struct cons_page

a cons page is essentially just an array of cons space objects.

It might later have a local free list (i.e. list of free cells on this page) and a pointer to the next cons page, but my current view is that that's probably unneccessary.

Definition at line 48 of file conspage.h.

Collaboration diagram for cons_page:
[legend]
Data Fields
struct cons_space_object cell[CONSPAGESIZE]

Macro Definition Documentation

◆ CONSPAGESIZE

#define CONSPAGESIZE   1024

the number of cons cells on a cons page.

The maximum value this can be (and consequently, the size which, by version 1, it will default to) is the maximum value of an unsigned 32 bit integer, which is to say 4294967296. However, we'll start small.

Definition at line 24 of file conspage.h.

◆ NCONSPAGES

#define NCONSPAGES   64

the number of cons pages we will initially allow for.

For convenience we'll set up an array of cons pages this big; however, later we will want a mechanism for this to be able to grow dynamically to the maximum we can currently allow, which is 4294967296.

Note that this means the total number of addressable cons cells is 1.8e19, each of 20 bytes; or 3e20 bytes in total; and there are up to a maximum of 4e9 of heap space objects, each of potentially 4e9 bytes. So we're talking about a potential total of 8e100 bytes of addressable memory, which is only slightly more than the number of atoms in the universe.

Definition at line 40 of file conspage.h.

Function Documentation

◆ allocate_cell()

struct cons_pointer allocate_cell ( uint32_t  tag)

Allocates a cell with the specified tag.

Dangerous, primitive, low level.

Parameters
tagthe tag of the cell to allocate - must be a valid cons space tag.
Returns
the cons pointer which refers to the cell allocated.
Todo:
handle the case where another cons_page cannot be allocated; return an exception. Which, as we cannot create such an exception when cons space is exhausted, means we must construct it at init time.

Definition at line 222 of file conspage.c.

References allocate_cell(), cons_space_object::count, DEBUG_ALLOC, debug_printf(), freelist, FREETAG, make_cons_page(), NIL, cons_pointer::offset, cons_pointer::page, cons_space_object::payload, pointer2cell, cons_space_object::tag, TAGLENGTH, and total_cells_allocated.

Referenced by allocate_cell(), make_cons(), make_exception(), make_function(), make_integer(), make_lambda(), make_nlambda(), make_ratio(), make_read_stream(), make_real(), make_special(), make_string_like_thing(), make_time(), make_vec_pointer(), and make_write_stream().

◆ dump_pages()

void dump_pages ( URL_FILE output)

dump the allocated pages to this output stream.

Definition at line 124 of file conspage.c.

References CONSPAGESIZE, dump_object(), initialised_cons_pages, and url_fwprintf.

Referenced by main().

◆ free_cell()

void free_cell ( struct cons_pointer  pointer)

Frees the cell at the specified pointer; for all the types of cons-space object which point to other cons-space objects, cascade the decrement.

Dangerous, primitive, low level.

@pointer the cell to free

Definition at line 143 of file conspage.c.

References check_tag(), CONSTV, cons_space_object::count, DEBUG_ALLOC, debug_dump_object(), debug_printf(), dec_ref(), EXCEPTIONTV, free_vso(), freelist, FREETAG, FREETV, FUNCTIONTV, INTEGERTV, LAMBDATV, NIL, NLAMBDATV, cons_pointer::offset, cons_pointer::page, cons_space_object::payload, pointer2cell, RATIOTV, READTV, SPECIALTV, STRINGTV, SYMBOLTV, cons_space_object::tag, TAGLENGTH, total_cells_freed, url_fclose(), VECTORPOINTTV, and WRITETV.

Referenced by dec_ref().

◆ initialise_cons_pages()

void initialise_cons_pages ( )

initialise the cons page system; to be called exactly once during startup.

Definition at line 257 of file conspage.c.

References conspageinitihasbeencalled, conspages, DEBUG_ALLOC, debug_printf(), make_cons_page(), and NCONSPAGES.

Referenced by main().

◆ summarise_allocation()

void summarise_allocation ( )

Definition at line 271 of file conspage.c.

References total_cells_allocated, and total_cells_freed.

Referenced by main().

Variable Documentation

◆ conspages

struct cons_page* conspages[NCONSPAGES]
extern

An array of pointers to cons pages.

Definition at line 51 of file conspage.c.

Referenced by initialise_cons_pages(), and make_cons_page().

◆ freelist

struct cons_pointer freelist
extern

The (global) pointer to the (global) freelist.

Not sure whether this ultimately belongs in this file.

Definition at line 46 of file conspage.c.

Referenced by allocate_cell(), free_cell(), and make_cons_page().