11 |
|
|
12 |
typedef struct stack_item |
typedef struct stack_item |
13 |
{ |
{ |
14 |
enum {value, string, ref, func} type; |
enum {value, string, ref, func, symbol} type; |
15 |
union { |
union { |
16 |
void* ptr; |
void* ptr; |
17 |
int val; |
int val; |
110 |
mk_hashentry(in_hashtbl, temp, id); |
mk_hashentry(in_hashtbl, temp, id); |
111 |
} |
} |
112 |
|
|
113 |
|
void def_sym(hashtbl in_hashtbl, const char* id) |
114 |
|
{ |
115 |
|
stackitem* temp= malloc(sizeof(stackitem)); |
116 |
|
|
117 |
|
temp->type= symbol; |
118 |
|
|
119 |
|
mk_hashentry(in_hashtbl, temp, id); |
120 |
|
} |
121 |
|
|
122 |
int push_ref(stackitem** stack_head, hashtbl in_hash, const char* in_string) |
int push_ref(stackitem** stack_head, hashtbl in_hash, const char* in_string) |
123 |
{ |
{ |
124 |
void* handle; |
void* handle; |
131 |
if(new_item->content.ptr==NULL) { |
if(new_item->content.ptr==NULL) { |
132 |
handle= dlopen(NULL, RTLD_LAZY); |
handle= dlopen(NULL, RTLD_LAZY); |
133 |
symbol= dlsym(handle, in_string); |
symbol= dlsym(handle, in_string); |
134 |
if(dlerror()==NULL) { |
if(dlerror()==NULL) |
135 |
def_func(in_hash, symbol, in_string); |
def_func(in_hash, symbol, in_string); |
136 |
new_item->content.ptr= *hash(in_hash, in_string); |
else |
137 |
new_item->type= ref; |
def_sym(in_hash, in_string); |
138 |
} |
|
139 |
|
new_item->content.ptr= *hash(in_hash, in_string); |
140 |
|
new_item->type= ref; |
141 |
} |
} |
142 |
|
|
143 |
push(stack_head, new_item); |
push(stack_head, new_item); |
168 |
break; |
break; |
169 |
case ref: |
case ref: |
170 |
case func: |
case func: |
171 |
|
case symbol: |
172 |
printf("%ld: %p\n", counter, stack_head->content.ptr); |
printf("%ld: %p\n", counter, stack_head->content.ptr); |
173 |
break; |
break; |
174 |
} |
} |