Post Scarcity
A prototype for a post scarcity programming environment
Loading...
Searching...
No Matches
stack.c File Reference
#include <stdlib.h>
#include "debug.h"
#include "io/print.h"
#include "memory/conspage.h"
#include "memory/consspaceobject.h"
#include "memory/dump.h"
#include "memory/stack.h"
#include "memory/vectorspace.h"
#include "ops/lispops.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_frame_context (URL_FILE *output, struct cons_pointer frame_pointer, int depth)
 
void dump_frame_context_fragment (URL_FILE *output, struct cons_pointer frame_pointer)
 
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.
 
struct cons_pointer frame_get_previous (struct cons_pointer frame_pointer)
 
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 280 of file stack.c.

References stack_frame::arg, stack_frame::args, cons_space_object::count, dump_frame_context(), 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_frame_context()

void dump_frame_context ( URL_FILE output,
struct cons_pointer  frame_pointer,
int  depth 
)

Definition at line 257 of file stack.c.

References dump_frame_context_fragment(), frame_get_previous(), get_stack_frame(), nilp, and url_fwprintf.

Referenced by dump_frame().

◆ dump_frame_context_fragment()

void dump_frame_context_fragment ( URL_FILE output,
struct cons_pointer  frame_pointer 
)

Definition at line 247 of file stack.c.

References stack_frame::arg, get_stack_frame(), print(), and url_fwprintf.

Referenced by dump_frame_context().

◆ 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 323 of file stack.c.

References args_in_frame, NIL, and pointer2cell.

Referenced by lisp_and(), lisp_append(), lisp_cond(), lisp_eq(), lisp_equal(), lisp_let(), lisp_list(), and lisp_or().

◆ frame_get_previous()

struct cons_pointer frame_get_previous ( struct cons_pointer  frame_pointer)

Definition at line 236 of file stack.c.

References get_stack_frame(), NIL, and stack_frame::previous.

Referenced by dump_frame_context().

◆ free_stack_frame()

void free_stack_frame ( struct stack_frame frame)

Free this stack frame.

Definition at line 222 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)

◆ 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 181 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, 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, privileged_string_memory_exhausted, 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().