Skip to content
dynbind.c 1.32 KiB
Newer Older
wlott's avatar
wlott committed
/*
 * Support for dynamic binding from C.
 */

#include "lisp.h"
#include "internals.h"
#include "globals.h"
#include "dynbind.h"

cwang's avatar
cwang committed
#if defined(ibmrt) || defined(i386) || defined(__x86_64)
wlott's avatar
wlott committed
#define GetBSP() ((struct binding *)SymbolValue(BINDING_STACK_POINTER))
#define SetBSP(value) SetSymbolValue(BINDING_STACK_POINTER, (lispobj)(value))
#else
#define GetBSP() ((struct binding *)current_binding_stack_pointer)
#define SetBSP(value) (current_binding_stack_pointer=(lispobj *)(value))
#endif

void
bind_variable(lispobj symbol, lispobj value)
wlott's avatar
wlott committed
{
    lispobj old_value;
    struct binding *binding;
wlott's avatar
wlott committed

    old_value = SymbolValue(symbol);
    binding = GetBSP();
    SetBSP(binding + 1);
wlott's avatar
wlott committed

    binding->value = old_value;
    binding->symbol = symbol;
    SetSymbolValue(symbol, value);
wlott's avatar
wlott committed
}

wlott's avatar
wlott committed
{
    struct binding *binding;
    lispobj symbol;

    binding = GetBSP() - 1;
wlott's avatar
wlott committed

    symbol = binding->symbol;
wlott's avatar
wlott committed

    SetSymbolValue(symbol, binding->value);
wlott's avatar
wlott committed

    binding->symbol = 0;

    SetBSP(binding);
wlott's avatar
wlott committed
}

void
unbind_to_here(lispobj * bsp)
wlott's avatar
wlott committed
{
    struct binding *target = (struct binding *) bsp;
wlott's avatar
wlott committed
    struct binding *binding = GetBSP();
    lispobj symbol;

    while (target < binding) {
	binding--;

	symbol = binding->symbol;

	if (symbol) {
	    SetSymbolValue(symbol, binding->value);
	    binding->symbol = 0;
	}

    }
    SetBSP(binding);
}