Skip to content

Instantly share code, notes, and snippets.

@gerdr
gerdr / test.pl
Created May 30, 2012 17:11
regex-dna failure golf
use v6;
sub my-subst($self, $matcher, $replacement,
:ii(:$samecase), :ss(:$samespace),
:$SET_CALLER_DOLLAR_SLASH, *%options) {
my $matches := $self.match($matcher, |%options);
return $self unless $matches;
if $matches ~~ Match {
$matches := ($matches,).list;
}
@gerdr
gerdr / gist:2852706
Created June 1, 2012 14:56
fix va_list test
diff --git a/config/auto/va_ptr/test_c.in b/config/auto/va_ptr/test_c.in
index f8eb2d4..7dee557 100644
--- a/config/auto/va_ptr/test_c.in
+++ b/config/auto/va_ptr/test_c.in
@@ -7,7 +7,7 @@ Copyright (C) 2005-2009, Parrot Foundation.
#include <stdarg.h>
#if defined VA_TYPE_REGISTER
-# define PARROT_VA_TO_VAPTR(x) (x)
+# define PARROT_VA_TO_VAPTR(x) ((va_list *)(x))
@gerdr
gerdr / utf8.c
Created June 4, 2012 16:05
UTF-8 encoder
/*
Copyright 2012 Gerhard R. <gerd.r.devel@googlemail.com>
Permission is granted to use, modify, and / or redistribute at will.
This includes removing authorship notices, re-use of code parts in
other software (with or without giving credit), and / or creating a
commercial product based on it.
This permission is not revocable by the author.
@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
@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 / 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 / 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 / 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 / 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 / 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