e397d0175264b08a17be0a627ca4adda508bd03a
[chise/ruby.git] / chise / qp.rb
1 # Copyright (C) 2003-2004 Kouichirou Eto, All rights reserved.
2 # This is free software with ABSOLUTELY NO WARRANTY.
3 # You can redistribute it and/or modify it under the terms of the GNU GPL2.
4
5 module QP
6   def caller_msg(ca)
7     file, linenum, msg = ca.first.split(/:([0-9]+):/)
8     msg = $1 if msg =~ /^in `(.+)'$/
9     File.basename(file)+":"+linenum+":"+msg
10   end
11
12   def ar_inspect(ar)
13     "["+ar.map {|arg| arg.inspect }.join(", ")+"]"
14   end
15
16   def runtime()
17     $__qp_t__ = Time.now unless defined? $__qp_t__
18     sprintf("%.1f", Time.now - $__qp_t__)
19   end
20
21   def qp(ca, *args)
22     QP.caller_msg(ca)+"\t"+QP.ar_inspect(args)
23   end
24
25   def tp(ca, *args)
26     QP.runtime()+":"+QP.qp(ca, *args)
27   end
28
29   module_function :caller_msg, :ar_inspect, :runtime, :qp, :tp
30 end
31
32 def qp(*args)
33   print QP.qp(caller(1), *args)+"\n"
34 end
35
36 def tp(*args)
37   print QP.tp(caller(1), *args)+"\n"
38 end