| 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 |
} |
} |
| 236 |
if((*stack_head)==NULL) |
if((*stack_head)==NULL) |
| 237 |
return; |
return; |
| 238 |
|
|
| 239 |
if((*stack_head)->type==value) |
switch((*stack_head)->type){ |
| 240 |
|
case value: |
| 241 |
printf("%d", (*stack_head)->content.val); |
printf("%d", (*stack_head)->content.val); |
| 242 |
else if((*stack_head)->type==string) |
break; |
| 243 |
|
case string: |
| 244 |
printf("%s", (char*)(*stack_head)->content.ptr); |
printf("%s", (char*)(*stack_head)->content.ptr); |
| 245 |
else |
break; |
| 246 |
|
case symbol: |
| 247 |
|
printf("%s", (*stack_head)->id); |
| 248 |
|
case ref: |
| 249 |
|
default: |
| 250 |
printf("%p", (*stack_head)->content.ptr); |
printf("%p", (*stack_head)->content.ptr); |
| 251 |
|
break; |
| 252 |
|
} |
| 253 |
|
|
| 254 |
toss(stack_head); |
toss(stack_head); |
| 255 |
} |
} |
| 259 |
printf("\n"); |
printf("\n"); |
| 260 |
} |
} |
| 261 |
|
|
| 262 |
|
extern void quit() |
| 263 |
|
{ |
| 264 |
|
exit(EXIT_SUCCESS); |
| 265 |
|
} |
| 266 |
|
|
| 267 |
int main() |
int main() |
| 268 |
{ |
{ |
| 269 |
stackitem* s= NULL; |
stackitem* s= NULL; |