Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jnthn's full-sized avatar

Jonathan Worthington jnthn

View GitHub Profile
@jnthn
jnthn / eval.p6
Last active March 23, 2017 11:14
use Test;
lives-ok {
await Promise.allof((^3).map: {
start {
for ^200 {
EVAL "True";
}
}
});
@jnthn
jnthn / ffs.c
Created March 8, 2017 12:09 — forked from bdw/ffs.c
cross-platform first set bit
#include <stdio.h>
#include <stdlib.h>
#define MVMint32 int
#ifdef __GNUC__
#define FFS(x) __builtin_ffs(x)
#elif defined(_MSC_VER)
static __inline MVMint32 FFS(MVMint32 x) {
MVMint32 i = 0;
Slide 3: Cross Compiler
- The NQP and Rakudo compilers are also cross-compilers by this definition,
since their output works on any platform
Slide 9: sysroot
- So if I follow, this is only relevant to compiling native code, and it says
where the headers etc. for that target platform live?
Slide 14:
- The MoarVM build process builds itself a minilua as a build tool. If I
@jnthn
jnthn / answers.md
Last active February 25, 2016 20:48
Answers to some concurrency questions
  1. Should two different taps of a a serial supply be run simultaneuosly?

$ perl6 -e 'my $p = Supplier.new; my $s = $p.Supply; $s.serial.say; $s.tap({ sleep 1; "42 {now}".say; }); $s.tap({ sleep 1; "43 {now}".say }); $p.emit(42); sleep 3;' True 42 Instant:1449454902.847377 43 Instant:1449454903.854135

No. Supplies do not introduce concurrency, at least not unless you explicitly ask for it with something like the start method. So the emit here is doing no more than a loop through the taps, calling the closures passed to tap one

class BoundedChannel is Channel {
has $!lock = Lock.new;
has $!send-cond = $!lock.condition;
has $.limit is required;
method send(|c) {
$!lock.lock();
LEAVE $!lock.unlock();
while $!limit == 0 {
$!send-cond.wait();
multi trait_mod:<is>(Attribute:D $attr, :$chainymutable!) {
$attr does role {
method compose(Mu \package) {
my constant NO_ARG = Mu.new;
my $this_attr = self;
package.^add_method:
$this_attr.name.substr(2), # strip sigil
method (Mu \value = NO_ARG) {
if value =:= NO_ARG {
$this_attr.get_value(self)
C:\consulting\rakudo>perl6-m -Ilib t\04-nativecall\11-cpp.t
# Error while compiling C++ script:
# Running 'g++ --shared -fPIC -o 11-cpp.dll t/04-nativecall/11-cpp.cpp':
# 'g++' is not recognized as an internal or external command,
# operable program or batch file.
1..0 # Skip: Cannot compile C++ script
Given this example code, where we uncomment one of the commented lines (and yeah, this is a
very slow way to do a Range, but I didn't actually implement ranges yet):
my $i = 0;
my $nums := GLRSeq.from-loop({ ++$i }, { $i < 100000 });
my @b := GLRArrayCircumfix();
# @b = $nums.GLRmap({ next unless .is-prime; $_ });
# @b = $nums.race(:degree(1)).GLRmap({ next unless .is-prime; $_ });
# @b = $nums.race(:degree(2)).GLRmap({ next unless .is-prime; $_ });
# @b = $nums.race(:degree(3)).GLRmap({ next unless .is-prime; $_ });
@jnthn
jnthn / glr.p6
Last active August 29, 2015 14:26
Great List Re-implementation: initial draft/exploration
# This file contains some work-in-progress bottom-up design work for the GLR.
# All types and operators introduced are prefixed with GLR, so there are no
# conflicts with those in core (the GLR prefix has even been used where there
# isn't anything in core to conflict with, to make clear what's being added).
# There's no syntax sugar, but rather explanations of what some syntax will
# desugar to are included. The various MAIN subs do tests to check correctness
# and various benchmarks to compare with what we have in Rakudo today.
# Up-front summary:
# * (1, 2, 3) makes a List; there is no Parcel. List supports laziness and