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

Go to the source code of this file.

Macros

#define stackframep(vso)   (((struct vector_space_object *)vso)->header.tag.value == STACKFRAMETV)
 is this vector-space object a stack frame?
 
#define STACKFRAMETAG   "STAK"
 stack.h
 
#define STACKFRAMETV   1262572627
 

Functions

void dump_frame (URL_FILE *output, struct cons_pointer pointer)
 Dump a stackframe to this stream for debugging.
 
void dump_stack_trace (URL_FILE *output, struct cons_pointer frame_pointer)
 
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.
 
void free_stack_frame (struct stack_frame *frame)
 Free this stack frame.
 
struct stack_frameget_stack_frame (struct cons_pointer pointer)
 get the actual stackframe object from this pointer, or NULL if pointer is not a stackframe pointer.
 
struct cons_pointer make_empty_frame (struct cons_pointer previous)
 Make an empty stack frame, and return it.
 
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.
 
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 these args, evaluated in this env.
 
void set_reg (struct stack_frame *frame, int reg, struct cons_pointer value)
 set a register in a stack frame.
 

Macro Definition Documentation

◆ stackframep

#define stackframep (   vso)    (((struct vector_space_object *)vso)->header.tag.value == STACKFRAMETV)

is this vector-space object a stack frame?

Definition at line 36 of file stack.h.

◆ STACKFRAMETAG

#define STACKFRAMETAG   "STAK"

stack.h

The Lisp evaluation stack.

Stack frames could be implemented in cons space; indeed, the stack could simply be an assoc list consed onto the front of the environment. But such a stack would be costly to search. The design sketched here, with stack frames as special objects, SHOULD be substantially more efficient, but does imply we need to generalise the idea of cons pages with freelists to a more general 'equal sized object pages', so that allocating/freeing stack frames can be more efficient.

Stack frames are not yet a first class object; they have no VECP pointer in cons space.

(c) 2017 Simon Brooke simon.nosp@m.@jou.nosp@m.rneym.nosp@m.an.c.nosp@m.c Licensed under GPL version 2.0, or, at your option, any later version. macros for the tag of a stack frame.

Definition at line 30 of file stack.h.

◆ STACKFRAMETV

#define STACKFRAMETV   1262572627

Definition at line 31 of file stack.h.

Function Documentation

◆ dump_frame()

void dump_frame ( URL_FILE output,
struct cons_pointer  frame_pointer 
)

Dump a stackframe to this stream for debugging.

Parameters
outputthe stream
frame_pointerthe pointer to the frame

Definition at line 244 of file stack.c.

References stack_frame::arg, stack_frame::args, cons_space_object::count, get_stack_frame(), stack_frame::more, nilp, pointer2cell, print(), cons_space_object::tag, url_fputws, and url_fwprintf.

Referenced by dump_object(), and dump_stack_trace().

◆ dump_stack_trace()

void dump_stack_trace ( URL_FILE output,
struct cons_pointer  frame_pointer 
)

◆ fetch_arg()

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 at line 286 of file stack.c.

References args_in_frame, NIL, and pointer2cell.

Referenced by lisp_append(), lisp_let(), and lisp_list().

◆ free_stack_frame()

void free_stack_frame ( struct stack_frame frame)

Free this stack frame.

Definition at line 224 of file stack.c.

References stack_frame::arg, args_in_frame, DEBUG_ALLOC, debug_print(), dec_ref(), stack_frame::more, and nilp.

Referenced by free_vso().

◆ get_stack_frame()

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 at line 53 of file stack.c.

References debug_print(), debug_printf(), DEBUG_STACK, vector_space_object::payload, pointer2cell, stackframep, and vectorpointp.

Referenced by c_apply(), dump_frame(), dump_stack_trace(), eval_form(), free_vso(), lisp_repl(), make_empty_frame(), make_special_frame(), make_stack_frame(), and repl().

◆ make_empty_frame()

struct cons_pointer make_empty_frame ( struct cons_pointer  previous)

Make an empty stack frame, and return it.

Parameters
previousthe current top-of-stack;
envthe environment in which evaluation happens.
Returns
the new frame, or NULL if memory is exhausted.

Definition at line 75 of file stack.c.

References stack_frame::arg, stack_frame::args, args_in_frame, DEBUG_ALLOC, debug_dump_object(), debug_print(), stack_frame::function, get_stack_frame(), make_vso(), stack_frame::more, NIL, nilp, stack_frame::previous, and STACKFRAMETV.

Referenced by eval_form(), make_special_frame(), and make_stack_frame().

◆ make_special_frame()

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.

Parameters
previousthe previous stack frame;
argsa list of the arguments to be stored in this stack frame;
envthe execution environment;
Returns
a new special frame.

Definition at line 183 of file stack.c.

References stack_frame::args, args_in_frame, c_string_to_lisp_string(), consp, debug_dump_object(), debug_print(), DEBUG_STACK, exceptionp, get_stack_frame(), inc_ref(), make_empty_frame(), make_exception(), stack_frame::more, nilp, cons_space_object::payload, pointer2cell, and set_reg().

Referenced by c_apply().

◆ make_stack_frame()

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 these args, evaluated in this env.

Parameters
previousthe current top-of-stack; @args the arguments to load into this frame;
envthe environment in which evaluation happens.
Returns
the new frame, or an exception if one occurred while building it.

Definition at line 116 of file stack.c.

References stack_frame::args, args_in_frame, c_string_to_lisp_string(), consp, debug_dump_object(), debug_print(), debug_print_object(), debug_printf(), DEBUG_STACK, eval_form(), eval_forms(), exceptionp, get_stack_frame(), inc_ref(), make_empty_frame(), make_exception(), stack_frame::more, nilp, cons_space_object::payload, pointer2cell, and set_reg().

Referenced by c_apply(), and repl().

◆ set_reg()

void set_reg ( struct stack_frame frame,
int  reg,
struct cons_pointer  value 
)

set a register in a stack frame.

Alwaye use this to do so, because that way we can be sure the inc_ref happens!

Definition at line 33 of file stack.c.

References stack_frame::arg, stack_frame::args, debug_print_object(), debug_printf(), debug_println(), DEBUG_STACK, dec_ref(), and inc_ref().

Referenced by eval_form(), lisp_apply(), make_special_frame(), and make_stack_frame().