0.pre8.28
[sbcl/lichteblau.git] / src / runtime / dynbind.c
blob5f26c2a72e7b888be6ec52efcfe55320d7ddaa81
1 /*
2 * support for dynamic binding from C
3 */
5 /*
6 * This software is part of the SBCL system. See the README file for
7 * more information.
9 * This software is derived from the CMU CL system, which was
10 * written at Carnegie Mellon University and released into the
11 * public domain. The software is in the public domain and is
12 * provided with absolutely no warranty. See the COPYING and CREDITS
13 * files for more information.
16 #include "runtime.h"
17 #include "sbcl.h"
18 #include "globals.h"
19 #include "dynbind.h"
20 #include "thread.h"
21 #include "genesis/symbol.h"
22 #include "genesis/binding.h"
23 #include "genesis/thread.h"
25 #if defined(__i386__)
26 #define GetBSP() ((struct binding *)SymbolValue(BINDING_STACK_POINTER,thread))
27 #define SetBSP(value) SetSymbolValue(BINDING_STACK_POINTER, (lispobj)(value),thread)
28 #else
29 #define GetBSP() ((struct binding *)current_binding_stack_pointer)
30 #define SetBSP(value) (current_binding_stack_pointer=(lispobj *)(value))
31 #endif
33 void bind_variable(lispobj symbol, lispobj value, void *th)
35 lispobj old_tl_value;
36 struct binding *binding;
37 struct thread *thread=(struct thread *)th;
38 struct symbol *sym=(struct symbol *)native_pointer(symbol);
39 binding = GetBSP();
40 SetBSP(binding+1);
41 #ifdef LISP_FEATURE_SB_THREAD
42 if(!sym->tls_index) {
43 sym->tls_index=SymbolValue(FREE_TLS_INDEX,0);
44 SetSymbolValue(FREE_TLS_INDEX,
45 make_fixnum(fixnum_value(sym->tls_index)+1),0);
47 #endif
48 old_tl_value=SymbolTlValue(symbol,thread);
49 binding->value = old_tl_value;
50 binding->symbol = symbol;
51 SetTlSymbolValue(symbol, value,thread);
54 void
55 unbind(void *th)
57 struct thread *thread=(struct thread *)th;
58 struct binding *binding;
59 lispobj symbol;
61 binding = GetBSP() - 1;
63 symbol = binding->symbol;
65 SetTlSymbolValue(symbol, binding->value,thread);
67 binding->symbol = 0;
69 SetBSP(binding);
72 void
73 unbind_to_here(lispobj *bsp,void *th)
75 struct thread *thread=(struct thread *)th;
76 struct binding *target = (struct binding *)bsp;
77 struct binding *binding = GetBSP();
78 lispobj symbol;
80 while (target < binding) {
81 binding--;
83 symbol = binding->symbol;
84 if (symbol) {
85 SetTlSymbolValue(symbol, binding->value,thread);
86 binding->symbol = 0;
89 SetBSP(binding);