Skip to content

Instantly share code, notes, and snippets.

@cognominal
Created August 2, 2015 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cognominal/efa78cd052e6b9ef7268 to your computer and use it in GitHub Desktop.
Save cognominal/efa78cd052e6b9ef7268 to your computer and use it in GitHub Desktop.
tentative example of ParamTypeCheck use
use QAST:from<NQP>;
use nqp;
my $ast := QAST::Block.new(
QAST::Op.new(:op<call>,
QAST::Block.new(
QAST::Var.new(:name<$a>, :scope<param>, :decl<var>,
QAST::ParamTypeCheck.new(
QAST::Op.new(:op<istrue>, QAST::Var.new(:name<$a>, :scope<param>)))),
QAST::Op.new(:op<say>,
QAST::Op.new(:op<callmethod>, :name<Str>,QAST::Var.new(:name<$a>, :scope<param>))
)
),
QAST::Ival(:value(42))
)
);
say($ast.dump());
say(exec_qast($ast));
sub exec_qast($qast) {
my $*QAST_BLOCK_NO_CLOSE := 1;
my $code := nqp::getcomp('nqp').compile($qast, :from('ast'));
$code();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment