Skip to content

Instantly share code, notes, and snippets.

@raydiak
raydiak / matrix_test.pl6
Created February 2, 2014 07:05
fake 2D subscripts "is rw" problem
#!/usr/bin/env perl6
class Matrix4x4 is Array {
method at_pos ($i) is rw {
self.Array::[$_, $_+1, $_+2, $_+3] given $i * 4
}
method perl () {
self.defined ??
$?CLASS.perl ~ '.new(' ~ "\n" ~
#!/usr/bin/env perl6
my $file = open 'MIRRORED.BY';
my %data;
my $key;
for $file.lines {
when /^ \s* '#'/ {
next
@raydiak
raydiak / rule_prob.p6
Created October 3, 2014 02:51
cyclical rule problem
#!/usr/bin/env perl6
use v6;
grammar Problem {
token TOP { <expression> }
rule expression { <operation> | <value> }
rule operation {<expression> <operator> <expression>}
token operator { \+ | \- | \* | \/ }
> ./alg.p6 'y=m*x+b' x
relation: =
symbol: y
operation: add
operation: multiply
symbol: m
symbol: x
symbol: b
relation: =
symbol: x
#!/usr/bin/env perl6
use v6;
class Point {
has num $.x;
has num $.y;
method new(num $x, num $y ) {
self.bless: :$x, :$y;
}
@raydiak
raydiak / gist:44f56ace282e01bac71a
Created January 3, 2015 20:32
JSON::Tiny R-J failure
==> Fetching JSON::Tiny
==> Building JSON::Tiny
Compiling lib/JSON/Tiny/Actions.pm to jar
Compiling lib/JSON/Tiny/Grammar.pm to jar
java.lang.IllegalThreadStateException: process hasn't exited
in method close at gen/jvm/CORE.setting:15560
in block at /home/raydiak/.rakudobrew/jvm-HEAD/panda/lib/Panda/Builder.pm:136
in sub withp6lib at /home/raydiak/.rakudobrew/jvm-HEAD/panda/lib/Panda/Common.pm:29
in method build at /home/raydiak/.rakudobrew/jvm-HEAD/panda/lib/Panda/Builder.pm:114
in method install at /home/raydiak/.rakudobrew/jvm-HEAD/panda/lib/Panda.pm:118
@raydiak
raydiak / gist:e268376b2cb6280ad7d3
Created January 5, 2015 08:02
testing C::Parser one line at a time
print failing lines only:
cat zmq.h | perl6 -Ilib -MC::Parser -ne '.say unless C::Parser::StdC11Parser.parse($_)'
preprocessed and hand-formatted zmq.h, 1 statement per line for easy testing:
extern int *__errno_location (void) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__));
typedef long int ptrdiff_t;
// parse fails
typedef __off64_t __loff_t;
typedef __quad_t *__qaddr_t;
struct _IO_FILE;
typedef struct { __off_t __pos; __mbstate_t __state; } _G_fpos_t;
typedef struct { __off64_t __pos; __mbstate_t __state; } _G_fpos64_t;
struct _IO_jump_t;
struct _IO_FILE;
struct _IO_FILE_plus;
typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes);
#!/usr/bin/env perl6
use lib $?FILE.IO.parent.child('lib');
use C::Parser::Grammar;
class CFunction {
has $.name;
has $.return = Any;
has @.args = ();
@raydiak
raydiak / ZMQ.pm6
Created February 13, 2015 08:29
Script-generated P6 0MQ bindings
module ZMQ;
use NativeCall;
sub zmq_version (OpaquePointer, OpaquePointer, OpaquePointer) is native('zmq') {*};
sub zmq_errno () returns int is native('zmq') {*};
sub zmq_strerror (int) returns Str is native('zmq') {*};
sub zmq_ctx_new () returns OpaquePointer is native('zmq') {*};
sub zmq_ctx_term (OpaquePointer) returns int is native('zmq') {*};
sub zmq_ctx_shutdown (OpaquePointer) returns int is native('zmq') {*};