-
Notifications
You must be signed in to change notification settings - Fork 29
/
gsc_tcc.cpp
executable file
·168 lines (124 loc) · 3.17 KB
/
gsc_tcc.cpp
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include "gsc_tcc.hpp"
#if COMPILE_TCC != 0
int gsc_tcc_new()
{
TCCState *s;
#if DEBUG_TCC
printf("%s()\n", __FUNCTION__);
#endif
s = tcc_new();
s->nostdlib = 1;
return stackReturnInt((int) s);
}
int gsc_tcc_add_include_path()
{
TCCState *s;
char *pathname;
int helper = 0;
helper += stackGetParamInt(1, (int *)&s);
helper += stackGetParamString(2, &pathname);
#if DEBUG_TCC
printf("%s(TCCState *s=%.8p, char *pathname=\"%s\")\n", __FUNCTION__, s, pathname);
#endif
if (helper != 2)
{
printf("scriptengine> wrongs args for %s(TCCState *s=%.8p, char *pathname=\"%s\")\n", __FUNCTION__, s, pathname);
return stackPushUndefined();
}
int ret = (int) tcc_add_include_path(s, pathname);
return stackReturnInt(ret);
}
#include <pthread.h>
TCCState *global_s;
char *global_filename;
int global_ret;
void *thread_for_tcc_add_file(void *arg)
{
//global_ret = tcc_add_file(global_s, global_filename);
TCCState *s;
s = tcc_new();
s->nostdlib = 1;
tcc_add_include_path(s, "/usr/include");
tcc_add_include_path(s, "include");
//tcc_add_library(s, "c"); // libc
tcc_add_file(s, "first.c");
//tcc_run(s, 0, (char **)NULL);
//tcc_delete(s);
printf("test");
}
int tcc_add_file_thread(TCCState *s, char *filename)
{
global_s = s;
global_filename = filename;
pthread_t thread1;
pthread_attr_t settings;
int stacksize;
int ret = pthread_attr_init(&settings);
if (ret != 0)
{
printf("> [ERROR] pthread_attr_init() failed.\n");
return 0;
}
stacksize = 1024*1024*20;
ret = pthread_attr_setstacksize(&settings, stacksize);
if (ret != 0)
{
printf("> [ERROR] pthread_attr_setstacksize failed.\n");
return 0;
}
printf("> [INFO] Stack-Size set to %d Bytes (%.2f KB, %.2f MB)\n", stacksize, (float)(stacksize/1024), (float)((stacksize/1024)/1024));
pthread_create (&thread1, &settings, thread_for_tcc_add_file, NULL);
//pthread_join(thread1, NULL);
return global_ret;
}
int gsc_tcc_add_file()
{
TCCState *s;
char *filename;
int helper = 0;
helper += stackGetParamInt(1, (int *)&s);
helper += stackGetParamString(2, &filename);
#if DEBUG_TCC
printf("%s(TCCState *s=%.8p, char *filename=\"%s\")\n", __FUNCTION__, s, filename);
#endif
if (helper != 2)
{
printf("scriptengine> wrongs args for %s(TCCState *s=%.8p, char *filename=\"%s\")\n", __FUNCTION__, s, filename);
return stackPushUndefined();
}
int ret = (int) tcc_add_file_thread(s, filename);
return stackReturnInt(ret);
}
int gsc_tcc_run()
{
TCCState *s;
int helper = 0;
helper += stackGetParamInt(1, (int *)&s);
#if DEBUG_TCC
printf("%s(TCCState *s=%.8p)\n", __FUNCTION__, s);
#endif
if (helper != 1)
{
printf("scriptengine> wrongs args for %s(TCCState *s=%.8p)\n", __FUNCTION__, s);
return stackPushUndefined();
}
int ret = (int) tcc_run(s, 0, (char **)NULL);
return stackReturnInt(ret);
}
int gsc_tcc_delete()
{
TCCState *s;
int helper = 0;
helper += stackGetParamInt(1, (int *)&s);
#if DEBUG_TCC
printf("%s(TCCState *s=%.8p)\n", __FUNCTION__, s);
#endif
if (helper != 1)
{
printf("scriptengine> wrongs args for %s(TCCState *s=%.8p)\n", __FUNCTION__, s);
return stackPushUndefined();
}
tcc_delete(s);
return stackPushUndefined();
}
#endif