Skip to content

Instantly share code, notes, and snippets.

@FROGGS

FROGGS/box_i.pl Secret

Created July 17, 2013 20:40
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 FROGGS/c865b021b1eb5420337f to your computer and use it in GitHub Desktop.
Save FROGGS/c865b021b1eb5420337f to your computer and use it in GitHub Desktop.
use nqp-mo;
my $knowhow := nqp::knowhow();
my $bi_type := $knowhow.new_type(:name('TestBigInt'), :repr('P6bigint'));
$bi_type.HOW.compose($bi_type);
sub str($x) { nqp::tostr_I($x) };
sub iseq($x, $y) { nqp::iseq_I($x, nqp::box_i($y, $bi_type)) }
sub box($x) { nqp::box_i($x, $bi_type) }
say(str( nqp::box_i(4, $bi_type) ));
# Now we'll create a type that boxes a P6bigint.
my $bi_boxer := NQPClassHOW.new_type(:name('TestPerl6Int'), :repr('P6opaque'));
$bi_boxer.HOW.add_attribute($bi_boxer, NQPAttribute.new(
:name('$!value'), :type($bi_type), :box_target(1)
));
$bi_boxer.HOW.add_parent($bi_boxer, NQPMu);
$bi_boxer.HOW.compose($bi_boxer);
# Try some basic operations with it.
say(str( nqp::box_i(4, $bi_boxer) ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment