[go: up one dir, main page]

Menu

[r49]: / trunk / eu.e  Maximize  Restore  History

Download this file

225 lines (189 with data), 5.2 kB

  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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
include std/dll.e
without type_check
without warning
with define EMBEDDED_OOEU
-- standard Euphoria includes
include std/text.e
include std/machine.e
export procedure Print( integer fn, object o )
print( fn, o )
end procedure
-- a nice pretty print file
include euslibs/print.e
-- include sprint.e
-- INTERPRETER front-end
public include global.e
include reswords.e as r
include error.e
include keylist.e
include c_out.e -- Translator output (leave in for now)
include symtab.e
include scanner.e
include emit.e
include parser.e
-- INTERPRETER back-end, written in Euphoria
public include execute.e
include sequencef.e
-- main program:
include main.e
-- begin mwl
-- handy stuff for embedded purposes:
export sequence symtab_table, slist_table, routine_table, variable_table,
crash_table, buckets_table, val_table, classes_table, members_table,
methods_table, lastintval_table, lastintsym_table, init_stack_table,
file_name_table, literal_table
integer current_env
symtab_table = {0}
slist_table = {0}
routine_table = {0}
variable_table = {0}
crash_table = {0}
buckets_table = {0}
val_table = {0}
classes_table = {0}
members_table = {0}
methods_table = {0}
lastintval_table = {0}
lastintsym_table = {0}
init_stack_table = {0}
file_name_table = {0}
literal_table = {0}
current_env = 1
procedure save_current_env()
symtab_table [current_env] = SymTab
slist_table [current_env] = slist
routine_table [current_env] = e_routine
variable_table [current_env] = e_variable
crash_table [current_env] = crash_table
buckets_table [current_env] = buckets
val_table [current_env] = val
classes_table [current_env] = class_table
members_table [current_env] = member_table
methods_table [current_env] = method_table
lastintval_table[current_env] = lastintval
lastintsym_table[current_env] = lastintsym
init_stack_table[current_env] = init_stack
file_name_table [current_env] = file_name
literal_table [current_env] = literal_init
end procedure
export procedure clear_env()
integer call_back_routine
sequence call_back_code
class_table = repeat( {}, CLASS_ENTRY )
method_table = repeat( {}, METHOD_ENTRY )
member_table = repeat( {}, MEMBER_ENTRY )
SymTab = {}
slist = {}
e_routine = {}
e_variable = {}
crash_list = {}
val = {}
lastintval = {}
lastintsym = {}
buckets = repeat( 0, NBUCKETS )
last_sym = 0
init_stack = {}
file_name = {}
literal_init = 0
-- only need one set of temps for call-backs
t_id = tmp_alloc()
t_arglist = tmp_alloc()
t_return_val = tmp_alloc()
call_back_code = {CALL_FUNC,
t_id,
t_arglist,
t_return_val,
CALL_BACK_RETURN
}
-- dummy call-back routine
call_back_routine = NewEntry("_call_back_", 0, 0, r:PROC, 0, 0, 0)
SymTab[call_back_routine] = SymTab[call_back_routine] &
repeat(0, SIZEOF_ROUTINE_ENTRY -
length(SymTab[call_back_routine]))
SymTab[call_back_routine][S_CODE] = call_back_code
InitSymTab()
InitBackEnd(0)
end procedure
export function new_env()
integer env, call_back_routine
env = find( -1, symtab_table )
if env = 0 then
symtab_table &= 0
slist_table &= 0
routine_table &= 0
variable_table &= 0
crash_table &= 0
buckets_table &= 0
val_table &= 0
classes_table &= 0
members_table &= 0
methods_table &= 0
lastintval_table &= 0
lastintsym_table &= 0
init_stack_table &= 0
file_name_table &= 0
literal_table &= 0
env = length( symtab_table )
end if
save_current_env()
clear_env()
current_env = env
return env
end function
export procedure switch_env( integer env )
if env < 1 or env > length(symtab_table) or env = current_env then
return
end if
save_current_env()
SymTab = symtab_table[env]
last_sym = length(SymTab)
slist = slist_table [env]
e_routine = routine_table[env]
e_variable = variable_table[env]
crash_list = crash_table[env]
buckets = buckets_table[env]
val = val_table[env]
class_table = classes_table[env]
member_table = members_table[env]
method_table = methods_table[env]
init_stack = init_stack_table[env]
file_name = file_name_table[env]
literal_init = literal_table[env]
current_env = env
end procedure
export function get_current_env()
return current_env
end function
export procedure cleanup_debugger()
if debugger > 0 then
c_proc( cleanup_cb, {})
end if
end procedure
export procedure set_embedded_call_back( atom cb )
embedded_call_back = define_c_proc( "", cb, { C_INT, C_INT } )
end procedure
export procedure illegal_builtin( sequence builtin )
integer illegal
if not length(builtin) then
return
end if
if atom( builtin[1] ) then
builtin = {builtin}
end if
illegal = routine_id("opILLEGAL")
for i = 1 to length( keylist ) do
if find( keylist[i][1], builtin ) then
operation[keylist[i][4]] = illegal
return
end if
end for
if find ( "?", builtin ) then
operation[QPRINT] = illegal
end if
end procedure
export function do_eval( sequence code )
return do_eval_exec( code )
end function
export function embed_routine( sequence name, integer rid, sequence params, integer is_func )
return embed_routine_exec( name, rid, params, is_func )
end function