Skip to content

Instantly share code, notes, and snippets.

@skids
skids / perl6asm
Last active December 14, 2015 00:19
possible asm-like methods for native types in Perl6
This is just food for thought/spit-balling. Most methods would only be available across the various native int/uint/buf types and NSA.
# bit population counts (note that this is not .msb, which is implemented as 1's compliment)
method bitslead(Bool(Any) $sense) # Count leading zeros/ones
method bitslead() # Count leading sign bits according to sign
method bitstrail(Bool(Any) $sense) # Count trailing zeros/ones
method bitcount(Bool(Any) $sense) # Count zeros/ones population
method bitcount() # sizeof * 8 (Count all bits)
# endianness conversion, bit reflection, permutations, frobbing
@skids
skids / ws_sequence.pm6
Created June 18, 2013 05:47
Strange whitespace problem with sequence operator.
# This works in star 13 05
say 1, { $_ + 1 } ... * > 3;
# This does not
say 1, { $_ + 1 }
... * > 3;
@skids
skids / pir_loses_class_vars.txt
Created March 19, 2014 02:05
Perl6 role-local vars invisible through two layers of compilation, but not one
# grep . /tmp/f*.pm6
/tmp/f1.pm6:role A {
/tmp/f1.pm6: my @f = 1,2,3;
/tmp/f1.pm6: method f ( ) { @f.perl.say };
/tmp/f1.pm6:}
/tmp/f1.pm6:1;
/tmp/f2.pm6:use f1;
/tmp/f2.pm6:class C does A { }
/tmp/f2.pm6:1;
/tmp/f3.pm6:use f2;
# perl6
Missing or wrong version of dependency 'gen/parrot/stage2/QRegex.nqp'
current instr.: '' pc 16529 (src/gen/perl6-pod.pir:6594) (src/Perl6/Pod.nqp:499)
called from Sub '' pc 1903 (gen/parrot/stage2/module_loader.pir:880) (src/vm/parrot/ModuleLoader.nqp:47)
called from Sub '' pc 1931 (gen/parrot/stage2/module_loader.pir:889) (src/vm/parrot/ModuleLoader.nqp:55)
called from Sub 'load_module' pc 1593 (gen/parrot/stage2/module_loader.pir:738) (src/vm/parrot/ModuleLoader.nqp:52)
called from Sub '' pc 195128 (src/gen/perl6-actions.pir:78209) (src/Perl6/Actions.nqp:7241)
called from Sub '' pc 1903 (gen/parrot/stage2/module_loader.pir:880) (src/vm/parrot/ModuleLoader.nqp:47)
called from Sub '' pc 1931 (gen/parrot/stage2/module_loader.pir:889) (src/vm/parrot/ModuleLoader.nqp:55)
# Still golfing, but this is metastable under moarvm on my system.
# Try: for i in 0 1 2 3 4 5 6 7 8 9 ; do perl6 this_file.pm6; done;
class C {
my %store{Any};
multi method foo is rw {
%store{self}<foo> //= [];
%store{self}<foo>;
}
$ perl6-j -e 'role A { my @S = 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1;} ; class C does A { };'
===SORRY!===
None of the parametric role variants for 'A' matched the arguments supplied.
java.lang.IllegalArgumentException: bad parameter count 256
$ perl6-j -e 'role A { my @S = 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
All the following was done in the star-04-14 tree on 64-bit Debian.
Before running Configure.pl I replaced the bitop guts functions in
the files nqp/src/vm/parrot/ops/nqp_bigint.ops
with the versions found in my original fix here:
https://gist.github.com/skids/4187527
I verified the changes were still there after the build so
there was no re-checkout.
@skids
skids / xpra input delay
Created October 8, 2014 17:52
xpra input delay
2014-10-08 13:24:05,765 processing packet key-action
2014-10-08 13:24:05,765 will process ui packet key-action
2014-10-08 13:24:05,860 processing packet key-action
2014-10-08 13:24:05,861 will process ui packet key-action
2014-10-08 13:24:08,972 processing packet ping
2014-10-08 13:24:08,972 process non-ui packet ping
2014-10-08 13:24:08,972 add_packet_to_queue(ping_echo ...)
2014-10-08 13:24:09,202 sending ping to Protocol(SocketConnection(/home/bjulin/.
xpra/XXX-100)) with time=1412789049202
2014-10-08 13:24:09,203 get_keycode(38, Up, ('mod2',)) is_native_keymap=False, f
@skids
skids / ascii_v_utf8.txt
Created January 7, 2015 03:47
encoding for Digest::MD5
While building some dwimmy prefab classes for Sum, I was faced with
choosing which encoding is "dwimmy" for string arguments. I found
that perl5's Digest::MD5 disagrees with perl6's compat module.
# perl6-m -MSum::MD -e 'class myMD5 does Sum::MD5 does Sum::Marshal::Raw { }; myMD5.new.finalize("OHAIá".encode("ascii")).base(16).say;'
103E95F18E83AF205B1F6645A5A2E672
# perl6-m -MSum::MD -e 'class myMD5 does Sum::MD5 does Sum::Marshal::Raw { }; myMD5.new.finalize("OHAIá".encode("utf8")).base(16).say;'
ADB19C50200CA4D2E03DF482F3CCAB0
# perl6-m -MDigest::MD5 -e 'say Digest::MD5.md5_hex("OHAIá")'
103e95f18e83af205b1f6645a5a2e672
@skids
skids / gist:11d8dca21973925c7850
Created January 19, 2015 03:36
rakudo newline dependent behavior
# cat /tmp/A.pm6
role A [ :$bs where { True } = 512] { }
# PERL6LIB=/tmp/ perl6-m -e 'use A; class B does A[ ] { }; B.new;'
===SORRY!===
None of the parametric role variants for 'A' matched the arguments supplied.
Cannot modify an immutable Block
# emacs /tmp/A.pm6
# cat /tmp/A.pm6
role A [ :$bs where { True }