-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathtrace.rb
41 lines (34 loc) · 928 Bytes
/
trace.rb
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
require 'stringio'
class Compiler
# Generating trace output for debugging purposes
def trace(pos,data,force=false)
return false if !@trace && !force
# A bit ugly, but prevents infinite recursion
# if we accidentally calls anything "traceworthy":
oldtrace = @trace
@trace = false
# Save, to minimize risk of interfering with the
# code.
@e.pushl(:eax)
@e.with_stack(2,true) do
if pos
pos = pos.short
end
sio = StringIO.new
sio << "#{pos ? pos+":" : " "} "
if data.is_a?(String)
sio << data << "\n"
else
print_sexp(data,sio,{:prune => true})
end
str = sio.string
ret = compile_eval_arg(nil,str)
@e.save_to_stack(ret,0)
@e.movl([:stderr],:eax)
@e.save_to_stack(:eax,1)
@e.call("fputs")
end
@e.popl(:eax)
@trace = oldtrace
end
end