lib/nydp/builtin.rb in nydp-0.5.1 vs lib/nydp/builtin.rb in nydp-0.6.0
- old
+ new
@@ -1,55 +1,33 @@
module Nydp::Builtin
module Base
+ @@reraise_errors = []
include Nydp::Helper
- def builtin_invoke vm, args ; raise "#{self.class.name} : please implement #builtin_invoke" ; end
- def builtin_invoke_1 vm ; builtin_invoke vm, Nydp::NIL ; end
- def builtin_invoke_2 vm, a ; builtin_invoke vm, cons(a) ; end
- def builtin_invoke_3 vm, a0, a1 ; builtin_invoke vm, cons(a0, cons(a1)) ; end
- def builtin_invoke_4 vm, a0, a1, a2 ; builtin_invoke vm, cons(a0, cons(a1, cons(a2))) ; end
-
- def invoke_1 vm
- builtin_invoke_1 vm
- rescue StandardError => e
- handle_error e
+ def self.ignore_errors kla
+ @@reraise_errors << kla
end
- def invoke_2 vm, arg
- builtin_invoke_2 vm, arg
- rescue StandardError => e
- handle_error e, arg
- end
+ ignore_errors Nydp::Error
- def invoke_3 vm, arg_0, arg_1
- builtin_invoke_3 vm, arg_0, arg_1
- rescue StandardError => e
- handle_error e, arg_0, arg_1
- end
-
- def invoke_4 vm, arg_0, arg_1, arg_2
- builtin_invoke_4 vm, arg_0, arg_1, arg_2
- rescue StandardError => e
- handle_error e, arg_0, arg_1, arg_2
- end
-
- # called from 'apply (among others)
- def invoke vm, args
- builtin_invoke vm, args
- rescue StandardError => e
- handle_error e, *(args.to_a)
- end
-
def handle_error e, *args
case e
- when Nydp::Error
+ when *@@reraise_errors
raise e
else
- arg_msg = args.map { |a| " #{a.inspect}"}.join("\n")
- new_msg = "Called #{self.inspect}\nwith args\n#{arg_msg}"
+ arg_msg = args.map { |a| "#{a._nydp_inspect}"}.join("\n").split(/\n/).map { |s| " #{s}"}.join("\n")
+ new_msg = "Called #{self._nydp_inspect}\nwith args\n#{arg_msg}"
raise new_msg
end
end
+
+ def call *args
+ builtin_call *args
+ rescue => e
+ handle_error e, *args
+ end
+
+ alias _nydp_call call
def name
cname = self.class.name.split("::").last
cname = cname.gsub(/([a-z])([A-Z])/) { |m| "#{m[0]}-#{m[1].downcase}" }
cname = cname.gsub(/^([A-Z])/) { |m| m.downcase }