-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsysfun.c
134 lines (122 loc) · 2.59 KB
/
sysfun.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "exec.h"
symbol_list * symbol_list_init(void)
{
list_init_g(symbol_list);
}
void symbol_list_add(symbol_list **l,char *name,Tao_value *obj)
{
symbol_list *head = malloc(sizeof(symbol_list));
head->next=*l;
head->name=name;
head->obj=obj;
*l=head;
}
void symbol_list_kill(symbol_list *l)
{
if(l==NULL) return;
symbol_list *tmp;
while(l->next!=NULL)
{
tmp=l;
free(l);
l=tmp->next;
}
free(l);
}
sysfun_list * sysfun_list_init(void)
{
list_init_g(sysfun_list);
}
sysfun sysfun_find(sysfun_list *l,char *s)
{
while(l->next!=NULL)
{
if(strcmp(l->name,s)==0)
{
return l->func;
}
l=l->next;
}
return NULL;
}
void sysfun_list_add(sysfun_list **l,char *name,sysfun func)
{
sysfun_list *head = malloc(sizeof(sysfun_list));
head->next=*l;
head->func=func;
head->name=name;
*l=head;
}
void add_sysfun(sysfun_list **l)
{
sysfun_list_add(l,"print",sys_print);
sysfun_list_add(l,"input",sys_input);
sysfun_list_add(l,"int",sys_int);
//...
//...
}
Tao_value *sys_print(obj_list *args)
{
Tao_value *tmp=malloc(sizeof(Tao_value));
tmp->type=C_NONE;
char *end="";
while(!is_empty(args))
{
/*
if(strcmp("end",args->name))
{
end = ((str_object *)args->obj->ce->ob_to_str(args->obj))->str;
}
*/
//printf(((str_object *)args->obj->ce->ob_to_str(args->obj))->str);
switch(args->obj->type)
{
case C_INT:
printf("%ld",args->obj->value.int_value.val);
break;
case C_FLOAT:
printf("%f",args->obj->value.float_value.val);
break;
case C_BOOL:
printf(args->obj->value.bool_value.val==0?"False":"True");
break;
case C_STR:
printf("%s",args->obj->value.str_value.val);
break;
case C_NONE:
printf("%s","none");
break;
case C_USEROBJ:
///todo
//printf("%s","none");
break;
}
args=args->next;
}
printf("%s",end);
return tmp;//return none
}
Tao_value *sys_input(obj_list *args)
{
sys_print(args);
char *s=malloc(1001);
scanf("%[^\n]",s);
getchar();
Tao_value *tmp = new_str(s);
//free(s);
tmp->type=C_STR;
return tmp;
}
Tao_value *sys_int(obj_list *args)
{
if(args->obj->type==C_STR)
{
return new_int(atol(args->obj->value.str_value.val));
}else
{
return NULL;
}
}