1. # XXX: Would like to have this class as Perl6::AST, but ran up against
  2. # problems with the serialization context calling it that.
  3. my class AST {
  4. has $!past;
  5. has $!quasi_context;
  6. has $!Str;
  7. submethod BUILD(:$past --> Nil) { $!past := $past }
  8. method incarnate($quasi_context, @unquote_asts) {
  9. my $incarnation = self.clone();
  10. nqp::bindattr(nqp::decont($incarnation), AST, '$!past', $incarnation.evaluate_unquotes(@unquote_asts));
  11. nqp::bindattr(nqp::decont($incarnation), AST, '$!quasi_context', $quasi_context);
  12. $incarnation;
  13. }
  14. method evaluate_unquotes(@unquote_asts) {
  15. my $pasts := nqp::list();
  16. for @unquote_asts {
  17. # TODO: find and report macro name
  18. X::TypeCheck::Splice.new(
  19. got => $_,
  20. expected => AST,
  21. action => 'unquote evaluation',
  22. ).throw unless nqp::istype($_,AST);
  23. nqp::push($pasts, nqp::getattr(nqp::decont($_), AST, '$!past'))
  24. }
  25. $!past.evaluate_unquotes($pasts);
  26. }
  27. method is_quasi_ast {
  28. so $!quasi_context;
  29. }
  30. method Str {
  31. $!Str;
  32. }
  33. }