diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1995-10-17 09:58:41 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1995-10-17 09:58:41 -0200 |
commit | 2cffb08a5c770678999a313a83c76652a3d02d4c (patch) | |
tree | 2a638e6dc4e4682863aadcff0073fa7af0c6198e /inout.c | |
parent | 15f40fddca66301a53f8b0adf41958c7e9add945 (diff) | |
download | lua-2cffb08a5c770678999a313a83c76652a3d02d4c.tar.gz lua-2cffb08a5c770678999a313a83c76652a3d02d4c.tar.bz2 lua-2cffb08a5c770678999a313a83c76652a3d02d4c.zip |
new style for debug information about functions: no more SETFUNCTION
opcodes. When a function is called, its entry in the stack is marked with
LUA_T_(C)MARK, so function 'luaD_stackedfunction' can find it if
needed.
Functions now have their file names in the headers, so there is no need
of 'addfile' and the like.
Diffstat (limited to 'inout.c')
-rw-r--r-- | inout.c | 109 |
1 files changed, 9 insertions, 100 deletions
@@ -5,7 +5,7 @@ | |||
5 | ** Also provides some predefined lua functions. | 5 | ** Also provides some predefined lua functions. |
6 | */ | 6 | */ |
7 | 7 | ||
8 | char *rcs_inout="$Id: inout.c,v 2.21 1995/10/04 14:20:26 roberto Exp roberto $"; | 8 | char *rcs_inout="$Id: inout.c,v 2.22 1995/10/09 13:06:20 roberto Exp roberto $"; |
9 | 9 | ||
10 | #include <stdio.h> | 10 | #include <stdio.h> |
11 | #include <stdlib.h> | 11 | #include <stdlib.h> |
@@ -31,20 +31,9 @@ char *rcs_inout="$Id: inout.c,v 2.21 1995/10/04 14:20:26 roberto Exp roberto $"; | |||
31 | Word lua_linenumber; | 31 | Word lua_linenumber; |
32 | Bool lua_debug; | 32 | Bool lua_debug; |
33 | Word lua_debugline = 0; | 33 | Word lua_debugline = 0; |
34 | char *lua_parsedfile; | ||
34 | 35 | ||
35 | 36 | ||
36 | /* Internal variables */ | ||
37 | |||
38 | typedef struct FuncStackNode { | ||
39 | struct FuncStackNode *next; | ||
40 | char *file; | ||
41 | Word function; | ||
42 | Word line; | ||
43 | } FuncStackNode; | ||
44 | |||
45 | static FuncStackNode *funcStack = NULL; | ||
46 | static Word nfuncstack=0; | ||
47 | |||
48 | static FILE *fp; | 37 | static FILE *fp; |
49 | static char *st; | 38 | static char *st; |
50 | 39 | ||
@@ -70,16 +59,17 @@ static int stringinput (void) | |||
70 | */ | 59 | */ |
71 | char *lua_openfile (char *fn) | 60 | char *lua_openfile (char *fn) |
72 | { | 61 | { |
73 | lua_linenumber = 1; | ||
74 | lua_setinput (fileinput); | 62 | lua_setinput (fileinput); |
75 | fp = fopen (fn, "r"); | 63 | fp = fopen (fn, "r"); |
76 | if (fp == NULL) | 64 | if (fp == NULL) |
77 | { | 65 | { |
78 | static char buff[255]; | 66 | static char buff[255]; |
79 | sprintf(buff, "unable to open file %.230s", fn); | 67 | sprintf(buff, "unable to open file `%.200s'", fn); |
80 | return buff; | 68 | return buff; |
81 | } | 69 | } |
82 | return lua_addfile (fn); | 70 | lua_linenumber = 1; |
71 | lua_parsedfile = lua_constcreate(fn)->ts.str; | ||
72 | return NULL; | ||
83 | } | 73 | } |
84 | 74 | ||
85 | /* | 75 | /* |
@@ -89,7 +79,6 @@ void lua_closefile (void) | |||
89 | { | 79 | { |
90 | if (fp != NULL) | 80 | if (fp != NULL) |
91 | { | 81 | { |
92 | lua_delfile(); | ||
93 | fclose (fp); | 82 | fclose (fp); |
94 | fp = NULL; | 83 | fp = NULL; |
95 | } | 84 | } |
@@ -98,16 +87,12 @@ void lua_closefile (void) | |||
98 | /* | 87 | /* |
99 | ** Function to open a string to be input unit | 88 | ** Function to open a string to be input unit |
100 | */ | 89 | */ |
101 | char *lua_openstring (char *s) | 90 | void lua_openstring (char *s) |
102 | { | 91 | { |
103 | lua_linenumber = 1; | ||
104 | lua_setinput (stringinput); | 92 | lua_setinput (stringinput); |
105 | st = s; | 93 | st = s; |
106 | { | 94 | lua_linenumber = 1; |
107 | char sn[64]; | 95 | lua_parsedfile = lua_constcreate("(string)")->ts.str; |
108 | sprintf (sn, "String: %10.10s...", s); | ||
109 | return lua_addfile (sn); | ||
110 | } | ||
111 | } | 96 | } |
112 | 97 | ||
113 | /* | 98 | /* |
@@ -115,75 +100,6 @@ char *lua_openstring (char *s) | |||
115 | */ | 100 | */ |
116 | void lua_closestring (void) | 101 | void lua_closestring (void) |
117 | { | 102 | { |
118 | lua_delfile(); | ||
119 | } | ||
120 | |||
121 | |||
122 | /* | ||
123 | ** Called to execute SETFUNCTION opcode, this function pushs a function into | ||
124 | ** function stack. | ||
125 | */ | ||
126 | void lua_pushfunction (char *file, Word function) | ||
127 | { | ||
128 | FuncStackNode *newNode; | ||
129 | if (nfuncstack++ >= MAXFUNCSTACK) | ||
130 | { | ||
131 | lua_error("function stack overflow"); | ||
132 | } | ||
133 | newNode = new(FuncStackNode); | ||
134 | newNode->function = function; | ||
135 | newNode->file = file; | ||
136 | newNode->line= lua_debugline; | ||
137 | newNode->next = funcStack; | ||
138 | funcStack = newNode; | ||
139 | } | ||
140 | |||
141 | /* | ||
142 | ** Called to execute RESET opcode, this function pops a function from | ||
143 | ** function stack. | ||
144 | */ | ||
145 | void lua_popfunction (void) | ||
146 | { | ||
147 | FuncStackNode *temp = funcStack; | ||
148 | if (temp == NULL) return; | ||
149 | --nfuncstack; | ||
150 | lua_debugline = temp->line; | ||
151 | funcStack = temp->next; | ||
152 | luaI_free(temp); | ||
153 | } | ||
154 | |||
155 | /* | ||
156 | ** Report bug building a message and pushing it on the stack. | ||
157 | */ | ||
158 | void luaI_reportbug (char *s, int err) | ||
159 | { | ||
160 | char msg[MAXMESSAGE]; | ||
161 | strcpy (msg, s); | ||
162 | if (lua_debugline != 0) | ||
163 | { | ||
164 | if (funcStack) | ||
165 | { | ||
166 | FuncStackNode *func = funcStack; | ||
167 | int line = lua_debugline; | ||
168 | sprintf (strchr(msg,0), "\n\tactive stack:\n"); | ||
169 | do | ||
170 | { | ||
171 | sprintf (strchr(msg,0), | ||
172 | "\t-> function \"%s\" at file \"%s\":%u\n", | ||
173 | lua_constant[func->function]->str, func->file, line); | ||
174 | line = func->line; | ||
175 | func = func->next; | ||
176 | if (err) lua_popfunction(); | ||
177 | } while (func); | ||
178 | } | ||
179 | else | ||
180 | { | ||
181 | sprintf (strchr(msg,0), | ||
182 | "\n\tin statement begining at line %u of file \"%s\"", | ||
183 | lua_debugline, lua_filename()); | ||
184 | } | ||
185 | } | ||
186 | lua_pushstring(msg); | ||
187 | } | 103 | } |
188 | 104 | ||
189 | 105 | ||
@@ -297,10 +213,3 @@ void luaI_error (void) | |||
297 | lua_error(s); | 213 | lua_error(s); |
298 | } | 214 | } |
299 | 215 | ||
300 | void luaI_getstack (void) | ||
301 | { | ||
302 | char *s = lua_getstring(lua_getparam(1)); | ||
303 | if (s == NULL) s = ""; | ||
304 | luaI_reportbug(s, 0); | ||
305 | } | ||
306 | |||