Skip to content

Instantly share code, notes, and snippets.

@gerdr
gerdr / gist:4182415
Created December 1, 2012 14:00
File::Spec fail
Obsolete use of | or \ with sigil on param $arr
Too many positional parameters passed; got 2 but expected 1
in method catfile at /home/gerdr/.perl6/lib/File/Spec/Cygwin.pm:10
in method catfile at /home/gerdr/.perl6/lib/File/Spec.pm:23
in method postcircumfix:<( )> at /home/gerdr/.perl6/lib/Inline/C.pm:117
in at src/gen/BOOTSTRAP.pm:852
in any at src/gen/BOOTSTRAP.pm:836
@gerdr
gerdr / debugging
Created October 13, 2012 21:51
Parrot IO readline fail
$ gdb install/bin/perl6
[...]
(gdb) break Parrot_api_run_bytecode
Breakpoint 1 at 0x401778
(gdb) break Parrot_io_readline_s
Function "Parrot_io_readline_s" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 2 (Parrot_io_readline_s) pending.
(gdb) run -e 'pir::print__is(pir::getstdin__P.readline)'
grammar Syntax {
token TOP { ^ <list> $ }
token list { <expression>+ % <.space>+ }
token expression {
<match=.atom>
| <match=.parens>
| <match=.squares>
}
@gerdr
gerdr / gist:3742384
Created September 18, 2012 10:06
How many levels of indirection are necessary to implement Perl6 container semantics?

How many levels of indirection are necessary to implement Perl6 container semantics?

This is based on reading the spec and not looking at implementations.

  • lexical environment -> container

Perl6 features custom containers. In principle, the container could be inlined into the environment as its type is known statically. Another way to do this would be to always inline the default container and add a member referencing the custom one.

  • container -> container storage
@gerdr
gerdr / dirwalk.pl
Created June 16, 2012 19:03
recursive directory walking
sub dirwalk(Str $dir = '.', Mu :$d = none(<. ..>), Mu :$f = *,
:&dx = -> $ {}, :&fx = -> $ {}) {
for dir($dir, :test(*)) {
given "$dir/$_".IO but $_ {
when .f {
&fx.(.path) if $f.ACCEPTS($_)
}
when .d {
dirwalk(.path, :$d, :$f, :&dx, :&fx) if $d.ACCEPTS($_)
}
@gerdr
gerdr / pow2.c
Created June 12, 2012 14:17
next greater power of 2
static inline size_t next_greater_pow2(size_t size)
{
enum { SIZE_BIT = CHAR_BIT * sizeof (size_t) };
for(unsigned exp = 0; (1 << exp) < SIZE_BIT; ++exp)
size |= size >> (1 << exp);
return ++size;
}
@gerdr
gerdr / foo.c
Created June 11, 2012 11:31
gcc bug
void foo(void)
{
static int (*bar)[42];
static const int (*baz)[42];
baz = bar;
}
@gerdr
gerdr / foo.pl
Created June 7, 2012 20:39
LEAVE fail with multi
use v6;
multi sub foo() {
say 'here';
LEAVE say 'not here';
}
foo;
@gerdr
gerdr / ufo
Created June 7, 2012 20:14
ufo with dwimmy dependency generation
#!/usr/bin/env perl6
sub dirwalk($dir = '.', Mu :$d = none(<. ..>), Mu :$f = *,
:&dx = -> $ {}, :&fx = -> $ {}) {
for dir($dir, :test(*)) -> $name {
given "$dir/$name" {
when .IO.f {
&fx.($_) if $f.ACCEPTS($name)
}
when .IO.d {
@gerdr
gerdr / TODO.md
Created June 5, 2012 22:56
m0 C implementation TODO
  • implement both signed and unsigned integer division/remainder ops
  • make callframes variably-sized
  • add hashtable implementation: necessary for CHUNK_MAP/linking stage
  • use unions instead of uint64_t as register type
  • namespacing cleanup (prefix external symbols)
  • add structure for strings
  • make integer size configurable or mandate 64-bit integers