Post Scarcity
A prototype for a post scarcity programming environment
Loading...
Searching...
No Matches
stack.c File Reference
#include <stdlib.h>
#include "memory/consspaceobject.h"
#include "memory/conspage.h"
#include "debug.h"
#include "memory/dump.h"
#include "ops/lispops.h"
#include "io/print.h"
#include "memory/stack.h"
#include "memory/vectorspace.h"
Include dependency graph for stack.c:

Go to the source code of this file.

Functions

void dump_frame (URL_FILE *output, struct cons_pointer frame_pointer)
 Dump a stackframe to this stream for debugging.
 
void dump_stack_trace (URL_FILE *output, struct cons_pointer pointer)
 
struct cons_pointer fetch_arg (struct stack_frame *frame, unsigned int index)
 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.
 

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()

◆ fetch_arg()

struct cons_pointer fetch_arg ( struct stack_frame frame,
unsigned int  index 
)

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