1. my class Code does Callable { # declared in BOOTSTRAP
  2. # class Code is Any
  3. # has Code $!do; # Low level code object
  4. # has Signature $!signature; # Signature object
  5. # has @!compstuff; # Place for the compiler to hang stuff
  6. multi method ACCEPTS(Code:D $self: Mu $topic) {
  7. $self.count ?? $self($topic) !! $self()
  8. }
  9. method arity(Code:D:) { nqp::getattr_i($!signature,Signature,'$!arity') }
  10. method count(Code:D:) { nqp::getattr($!signature,Signature,'$!count') }
  11. method signature(Code:D:) { $!signature }
  12. proto method prec(|) { * }
  13. multi method prec() { my % }
  14. multi method prec(Str:D $) { '' }
  15. multi method Str(Code:D:) {
  16. warn( self.WHAT.perl ~ " object coerced to string (please use .gist or .perl to do that)"); self.name
  17. }
  18. method outer(Code:D:) {
  19. nqp::ifnull(nqp::getcodeobj(nqp::p6staticouter($!do)), Mu)
  20. }
  21. # returns an identifier for this code object
  22. # that is the same even for cloned closures
  23. method static_id(Code:D:) {
  24. nqp::p6box_i(nqp::where(nqp::getstaticcode($!do)));
  25. }
  26. multi method new(Code:) { X::Cannot::New.new(class => self).throw }
  27. method file(Code:D:) {
  28. nqp::getcodelocation($!do)<file>;
  29. }
  30. method line(Code:D:) {
  31. nqp::getcodelocation($!do)<line>;
  32. }
  33. multi method perl(Code:D:) { '{ ... }' }
  34. }