This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
# The Expat License | |
# | |
# Copyright (c) 2018, Shlomi Fish | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
# inspired by https://narimiran.github.io/2018/05/10/python-numpy-nim.html | |
use nqp; | |
constant N = 10_000; | |
constant sigma = 0.1e0; | |
constant f = (2 / N).Num; | |
constant mu = 0.001e0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
timo@schmand /tmp> perl6 --profile=heap testshellmem.p6 shell | |
Before shell call : 101.664 kb | |
html is 230457 chars | |
After shell call : 210.332 kb | |
After forced gc: 249.704 kb | |
html is 230457 chars | |
After shell call : 323.016 kb | |
After forced gc: 354.232 kb | |
html is 230457 chars | |
After shell call : 401.640 kb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define trace_spesh_optimize | |
dont-repeat | |
python | |
import tempfile | |
import os | |
import gdb | |
spesh_trace_target_folder = tempfile.mkdtemp("", "moar-spesh-trace") | |
spesh_trace_target_file = os.path.join(spesh_trace_target_folder, "speshdump.txt") | |
os.system("git init " + spesh_trace_target_folder) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grammar g{ | |
token garble {<[2]>}; | |
token alpha1 {<[2]>}; | |
token beta { <[q]> }; | |
token delta {<+garble +beta>}; | |
token delta1 {<+garble>}; | |
token delta2 {<+alpha1 +beta>} | |
} | |
say so "2" ~~ /<g::delta1>/; # OK | |
say so "2" ~~ /<g::delta2>/; # OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
use Test; | |
sub combinations_with_replacement(@iterable, $r) { | |
gather { | |
cwr(@iterable, [], $r); | |
} | |
} | |
sub cwr(@iterable, @state, $r) { | |
my $place = @state.elems; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is my solution to GRAPH. | |
# it offers an interactive mode and some test cases | |
use v6; | |
class Graph { | |
has @!nodes; | |
has %!neighbour; | |
method connect($a, $b) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct MVMCompUnitBody { | |
MVMuint8 * data_start; /* 0 8 */ | |
MVMuint32 data_size; /* 8 4 */ | |
/* XXX 4 bytes hole, try to pack */ | |
MVMObject * * coderefs; /* 16 8 */ | |
MVMuint32 num_frames; /* 24 4 */ | |
MVMuint32 orig_frames; /* 28 4 */ | |
MVMStaticFrame * main_frame; /* 32 8 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!perl6 | |
use NativeCall; | |
my $samplerate = 44100; | |
my $frequency = 440; | |
sub gen-sin(Int $sample-rate, Int $frequency) { | |
my num $spf = $sample-rate.Num / $frequency.Num; | |
my num $twopi = (2 * pi).Num; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# remove this to get an output from this again. | |
use trace; | |
do { | |
# putting a "use trace" into this block will | |
# give a trace as well as the expected results | |
#use trace; | |
.say for <hello how are you>; |