This is broken, but the stack limit feature works. Some debugging needed.
This commit is contained in:
parent
2536e76617
commit
d1ce893633
12 changed files with 164 additions and 111 deletions
|
|
@ -26,6 +26,12 @@
|
|||
#include "memory/vectorspace.h"
|
||||
#include "ops/lispops.h"
|
||||
|
||||
/**
|
||||
* @brief If non-zero, maximum depth of stack.
|
||||
*
|
||||
*/
|
||||
uint32_t stack_limit = 0;
|
||||
|
||||
/**
|
||||
* set a register in a stack frame. Alwaye use this to do so,
|
||||
* because that way we can be sure the inc_ref happens!
|
||||
|
|
@ -68,17 +74,19 @@ struct stack_frame *get_stack_frame( struct cons_pointer pointer ) {
|
|||
|
||||
/**
|
||||
* Make an empty stack frame, and return it.
|
||||
*
|
||||
* This function does the actual meat of making the frame.
|
||||
*
|
||||
* @param previous the current top-of-stack;
|
||||
* @param env the environment in which evaluation happens.
|
||||
* @param depth the depth of the new frame.
|
||||
* @return the new frame, or NULL if memory is exhausted.
|
||||
*/
|
||||
struct cons_pointer make_empty_frame( struct cons_pointer previous ) {
|
||||
struct cons_pointer in_make_empty_frame( struct cons_pointer previous,
|
||||
uint32_t depth ) {
|
||||
debug_print( L"Entering make_empty_frame\n", DEBUG_ALLOC );
|
||||
struct cons_pointer result =
|
||||
make_vso( STACKFRAMETV, sizeof( struct stack_frame ) );
|
||||
|
||||
debug_dump_object( result, DEBUG_ALLOC );
|
||||
|
||||
if ( !nilp( result ) ) {
|
||||
struct stack_frame *frame = get_stack_frame( result );
|
||||
/*
|
||||
|
|
@ -86,6 +94,7 @@ struct cons_pointer make_empty_frame( struct cons_pointer previous ) {
|
|||
*/
|
||||
|
||||
frame->previous = previous;
|
||||
frame->depth = depth;
|
||||
|
||||
/*
|
||||
* clearing the frame with memset would probably be slightly quicker, but
|
||||
|
|
@ -99,7 +108,7 @@ struct cons_pointer make_empty_frame( struct cons_pointer previous ) {
|
|||
frame->arg[i] = NIL;
|
||||
}
|
||||
|
||||
frame->depth = (nilp(previous)) ? 0 : (get_stack_frame(previous))->depth + 1;
|
||||
debug_dump_object( result, DEBUG_ALLOC );
|
||||
}
|
||||
debug_print( L"Leaving make_empty_frame\n", DEBUG_ALLOC );
|
||||
debug_dump_object( result, DEBUG_ALLOC );
|
||||
|
|
@ -107,6 +116,37 @@ struct cons_pointer make_empty_frame( struct cons_pointer previous ) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Make an empty stack frame, and return it.
|
||||
*
|
||||
* This function does the error checking around actual construction.
|
||||
*
|
||||
* @param previous the current top-of-stack;
|
||||
* @param env the environment in which evaluation happens.
|
||||
* @return the new frame, or NULL if memory is exhausted.
|
||||
*/
|
||||
struct cons_pointer make_empty_frame( struct cons_pointer previous ) {
|
||||
struct cons_pointer result = NIL;
|
||||
uint32_t depth =
|
||||
( nilp( previous ) ) ? 0 : ( get_stack_frame( previous ) )->depth + 1;
|
||||
|
||||
if ( stack_limit > 0 && stack_limit > depth ) {
|
||||
result = in_make_empty_frame( previous, depth );
|
||||
} else {
|
||||
result =
|
||||
make_exception( c_string_to_lisp_string
|
||||
( L"Stack limit exceeded." ), previous );
|
||||
}
|
||||
|
||||
if ( nilp( result ) ) {
|
||||
/* i.e. out of memory */
|
||||
result =
|
||||
make_exception( privileged_string_memory_exhausted, previous );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate a new stack frame with its previous pointer set to this value,
|
||||
* its arguments set up from these args, evaluated in this env.
|
||||
|
|
@ -121,11 +161,7 @@ struct cons_pointer make_stack_frame( struct cons_pointer previous,
|
|||
debug_print( L"Entering make_stack_frame\n", DEBUG_STACK );
|
||||
struct cons_pointer result = make_empty_frame( previous );
|
||||
|
||||
if ( nilp( result ) ) {
|
||||
/* i.e. out of memory */
|
||||
result =
|
||||
make_exception( privileged_string_memory_exhausted, previous );
|
||||
} else {
|
||||
if ( !exceptionp( result ) ) {
|
||||
struct stack_frame *frame = get_stack_frame( result );
|
||||
|
||||
while ( frame->args < args_in_frame && consp( args ) ) {
|
||||
|
|
@ -191,12 +227,7 @@ struct cons_pointer make_special_frame( struct cons_pointer previous,
|
|||
|
||||
struct cons_pointer result = make_empty_frame( previous );
|
||||
|
||||
if ( nilp( result ) ) {
|
||||
/* i.e. out of memory */
|
||||
result =
|
||||
make_exception( c_string_to_lisp_string( L"Memory exhausted." ),
|
||||
previous );
|
||||
} else {
|
||||
if ( !exceptionp( result ) ) {
|
||||
struct stack_frame *frame = get_stack_frame( result );
|
||||
|
||||
while ( frame->args < args_in_frame && !nilp( args ) ) {
|
||||
|
|
@ -288,8 +319,7 @@ void dump_frame( URL_FILE *output, struct cons_pointer frame_pointer ) {
|
|||
|
||||
if ( frame != NULL ) {
|
||||
url_fwprintf( output, L"Stack frame %d with %d arguments:\n",
|
||||
frame->depth;
|
||||
frame->args );
|
||||
frame->depth, frame->args );
|
||||
dump_frame_context( output, frame_pointer, 4 );
|
||||
|
||||
for ( int arg = 0; arg < frame->args; arg++ ) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue