Skip to content

Instantly share code, notes, and snippets.

View jnthn's full-sized avatar

Jonathan Worthington jnthn

View GitHub Profile
@jnthn
jnthn / foo.c
Created November 22, 2011 23:18
#include <stdio.h>
__declspec(dllexport) /* comment this line out if not on Windows */
int GotValues(int a, float b)
{
printf("Got %d\nGot %f\n", a, b);
return 69;
}
diff --git a/src/QRegex/P6Regex/Actions.nqp b/src/QRegex/P6Regex/Actions.nqp
index 6e2ff9f..4fe6772 100644
--- a/src/QRegex/P6Regex/Actions.nqp
+++ b/src/QRegex/P6Regex/Actions.nqp
@@ -396,20 +396,33 @@ class QRegex::P6Regex::Actions is HLL::Actions {
my $qast;
if $<name> {
my $name := ~$<name>;
- $qast := QAST::Regex.new( PAST::Node.new($name), :rxtype<subrule>, :subtype<method>, :node($/) );
+ $qast := QAST::Regex.new( PAST::Node.new($name), :rxtype<subrule>, :subtype<method>,
# Hopefully easy...
grammar Busted1 {
token TOP { <foo> }
proto token foo { <*> }
token foo:sym<a> {
:my $x := 42;
.+
}
token foo:sym<b> { aa }
}
grammar Foo {
token TOP { <val> }
proto token val { <*> }
token val:sym<int> { <[0..9]> }
token val:sym<num> { <[0..9]> '.' <[0..9]> }
}
say(~Foo.parse('1.2'));
grammar Foo {
token TOP { <val> }
proto token val { <*> }
token val:sym<num> { <[0..9]> '.' <[0..9]> }
token val:sym<int> { <[0..9]> }
}
say(~Foo.parse('1.2'));
grammar Foo {
token TOP { <val> }
proto token val { <*> }
token val:sym<num> { <[0123456789]>+ '.' <[0123456789]>+ }
token val:sym<int> { <[0123456789]>+ }
}
say(~Foo.parse('12.34'));
> say 3.141592653589e0
0.552631241154582
> say 3.14159265358e0
0.515444474724007
> say 3.1415926535e0
0.958221835195889
> say 3.141592653e0
3.141592653
@jnthn
jnthn / in.pl
Created November 14, 2011 21:55
my $knowhow := pir::get_knowhow__P();
my $bi_type := $knowhow.new_type(:name('TestBigInt'), :repr('P6bigint'));
$bi_type.HOW.compose($bi_type);
sub str($x) { pir::nqp_bigint_to_str__SP($x) };
my $float := 123456789e240;
say($float);
say(str(nqp::fromnum_I($float, $bi_type)));
say(nqp::tonum_I(nqp::fromnum_I($float, $bi_type)));
diff --git a/src/Perl6/Actions.pm b/src/Perl6/Actions.pm
diff --git a/src/Perl6/Grammar.pm b/src/Perl6/Grammar.pm
index d4b1d94..20ac91c 100644
--- a/src/Perl6/Grammar.pm
+++ b/src/Perl6/Grammar.pm
@@ -28,7 +28,10 @@ grammar Perl6::Grammar is HLL::Grammar {
my $*ST := pir::isnull($file) ??
Perl6::SymbolTable.new(:handle(~pir::time__N())) !!
Perl6::SymbolTable.new(:handle(~pir::time__N()), :description($file));
-

A New REPR API

If anything, this is a simplification.

type_object_for(HOW)

This one stays just the same as before; it's the operation that creates an s-table, a type object and ties everything together.

allocate(OBJECT)

This partially replaces instance_of, but it only does the memory allocation portion of the work. We'll also need it for auto-boxing and cloning. The object passed is most