Fixed assigning arguments to slots in the frame; also fixed a bug in bind...
But did that by switching away from using Lisp calling convention, because that broke horribly. This is bad news and must be sorted out.
This commit is contained in:
parent
cb3dcb352e
commit
f915a9993f
14 changed files with 158 additions and 112 deletions
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
#include "memory/node.h"
|
||||
#include "memory/pointer.h"
|
||||
#include "memory/pso.h"
|
||||
|
|
@ -20,6 +22,8 @@
|
|||
|
||||
#include "payloads/cons.h"
|
||||
|
||||
#include "ops/reverse.h"
|
||||
|
||||
/**
|
||||
* @brief Construct a stack frame with this `previous` pointer, and arguments
|
||||
* taken from the remaining arguments to this function, which should all be
|
||||
|
|
@ -27,44 +31,60 @@
|
|||
*
|
||||
* @return a pso_pointer to the stack frame.
|
||||
*/
|
||||
struct pso_pointer make_frame( struct pso_pointer previous, ... ) {
|
||||
struct pso_pointer make_frame( int arg_count, struct pso_pointer previous,
|
||||
... ) {
|
||||
va_list args;
|
||||
va_start( args, previous );
|
||||
int count = va_arg( args, int );
|
||||
|
||||
struct pso_pointer frame_pointer = allocate( STACKTAG, 4 );
|
||||
struct pso4 *frame = ( struct pso4 * ) pointer_to_object( frame_pointer );
|
||||
|
||||
#ifdef DEBUG
|
||||
debug_printf( DEBUG_ALLOC, 0,
|
||||
L"\nAllocating stack frame with %d arguments at page %d, "
|
||||
L"offset %d...\n",
|
||||
arg_count, frame_pointer.page, frame_pointer.offset );
|
||||
#endif
|
||||
|
||||
frame->payload.stack_frame.previous = previous;
|
||||
|
||||
// I *think* the count starts with the number of args, so there are
|
||||
// one fewer actual args. Need to test to verify this!
|
||||
count--;
|
||||
int cursor = 0;
|
||||
frame->payload.stack_frame.args = count;
|
||||
if ( stackp( previous ) ) {
|
||||
struct pso4 *op = pointer_to_pso4( previous );
|
||||
frame->payload.stack_frame.depth = op->payload.stack_frame.depth + 1;
|
||||
} else {
|
||||
frame->payload.stack_frame.depth = 0;
|
||||
}
|
||||
|
||||
for ( ; cursor < count && cursor < args_in_frame; cursor++ ) {
|
||||
debug_printf( DEBUG_ALLOC, 1, L"depth is %d...\n",
|
||||
frame->payload.stack_frame.depth );
|
||||
|
||||
int cursor = 0;
|
||||
frame->payload.stack_frame.args = arg_count;
|
||||
|
||||
for ( ; cursor < arg_count && cursor < args_in_frame; cursor++ ) {
|
||||
struct pso_pointer argument = va_arg( args, struct pso_pointer );
|
||||
|
||||
frame->payload.stack_frame.arg[cursor] = inc_ref( argument );
|
||||
}
|
||||
if ( cursor < count ) {
|
||||
if ( cursor < arg_count ) {
|
||||
struct pso_pointer more_args = nil;
|
||||
|
||||
for ( ; cursor < count; cursor++ ) {
|
||||
for ( ; cursor < arg_count; cursor++ ) {
|
||||
more_args =
|
||||
c_cons( va_arg( args, struct pso_pointer ), more_args );
|
||||
}
|
||||
|
||||
// should be frame->payload.stack_frame.more = reverse( more_args), but
|
||||
// we don't have reverse yet. TODO: fix.
|
||||
frame->payload.stack_frame.more = more_args;
|
||||
frame->payload.stack_frame.more = c_reverse( more_args );
|
||||
} else {
|
||||
for ( ; cursor < args_in_frame; cursor++ ) {
|
||||
frame->payload.stack_frame.arg[cursor] = nil;
|
||||
}
|
||||
}
|
||||
|
||||
debug_printf( DEBUG_ALLOC, 1,
|
||||
L"Allocation of frame at page %d, offset %d completed.\n",
|
||||
frame_pointer.page, frame_pointer.offset );
|
||||
|
||||
return frame_pointer;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue