Post Scarcity
A prototype for a post scarcity programming environment
Loading...
Searching...
No Matches
stack.h
Go to the documentation of this file.
1/**
2 * stack.h
3 *
4 * The Lisp evaluation stack.
5 *
6 * Stack frames could be implemented in cons space; indeed, the stack
7 * could simply be an assoc list consed onto the front of the environment.
8 * But such a stack would be costly to search. The design sketched here,
9 * with stack frames as special objects, SHOULD be substantially more
10 * efficient, but does imply we need to generalise the idea of cons pages
11 * with freelists to a more general 'equal sized object pages', so that
12 * allocating/freeing stack frames can be more efficient.
13 *
14 * Stack frames are not yet a first class object; they have no VECP pointer
15 * in cons space.
16 *
17 * (c) 2017 Simon Brooke <simon@journeyman.cc>
18 * Licensed under GPL version 2.0, or, at your option, any later version.
19 */
20
21#ifndef __psse_stack_h
22#define __psse_stack_h
23
24#include "consspaceobject.h"
25#include "conspage.h"
26
27/**
28 * macros for the tag of a stack frame.
29 */
30#define STACKFRAMETAG "STAK"
31#define STACKFRAMETV 1262572627
32
33/**
34 * is this vector-space object a stack frame?
35 */
36#define stackframep(vso)(((struct vector_space_object *)vso)->header.tag.value == STACKFRAMETV)
37
38void set_reg( struct stack_frame *frame, int reg, struct cons_pointer value );
39
40struct stack_frame *get_stack_frame( struct cons_pointer pointer );
41
42struct cons_pointer make_empty_frame( struct cons_pointer previous );
43
44struct cons_pointer make_stack_frame( struct cons_pointer previous,
45 struct cons_pointer args,
46 struct cons_pointer env );
47
48void free_stack_frame( struct stack_frame *frame );
49
50void dump_frame( URL_FILE * output, struct cons_pointer pointer );
51
52void dump_stack_trace( URL_FILE * output, struct cons_pointer frame_pointer );
53
54struct cons_pointer fetch_arg( struct stack_frame *frame, unsigned int n );
55
56struct cons_pointer make_special_frame( struct cons_pointer previous,
57 struct cons_pointer args,
58 struct cons_pointer env );
59
60/*
61 * struct stack_frame is defined in consspaceobject.h to break circularity
62 * \todo refactor.
63 */
64
65#endif
An indirect pointer to a cons cell.
A stack frame.
struct cons_pointer fetch_arg(struct stack_frame *frame, unsigned int n)
Fetch a pointer to the value of the local variable at this index.
Definition stack.c:286
struct cons_pointer make_special_frame(struct cons_pointer previous, struct cons_pointer args, struct cons_pointer env)
A 'special' frame is exactly like a normal stack frame except that the arguments are unevaluated.
Definition stack.c:183
void set_reg(struct stack_frame *frame, int reg, struct cons_pointer value)
set a register in a stack frame.
Definition stack.c:33
struct stack_frame * get_stack_frame(struct cons_pointer pointer)
get the actual stackframe object from this pointer, or NULL if pointer is not a stackframe pointer.
Definition stack.c:53
void dump_frame(URL_FILE *output, struct cons_pointer pointer)
Dump a stackframe to this stream for debugging.
Definition stack.c:244
void dump_stack_trace(URL_FILE *output, struct cons_pointer frame_pointer)
Definition stack.c:268
void free_stack_frame(struct stack_frame *frame)
Free this stack frame.
Definition stack.c:224
struct cons_pointer make_empty_frame(struct cons_pointer previous)
Make an empty stack frame, and return it.
Definition stack.c:75
struct cons_pointer make_stack_frame(struct cons_pointer previous, struct cons_pointer args, struct cons_pointer env)
Allocate a new stack frame with its previous pointer set to this value, its arguments set up from the...
Definition stack.c:116