Skip to content

Instantly share code, notes, and snippets.

View bdw's full-sized avatar
💭
Hacking

Bart Wiegmans bdw

💭
Hacking
View GitHub Profile
@bdw
bdw / explanation.md
Last active August 29, 2015 14:27
Pathological grammar case

Why this is a problem

I need to generate a transition state table. To do that, I find the combinations of rules that can be applied to a given rule. Before I can do that, note that nested rules are replaced by 'accented' values:

(tile: at (a (t)) r) becomes
(tile: at2 (t) t')
(tile: at (a t') r)

Hence, according to this, the (t) node can generate both r and t', and this is indistinguishable form the perspective of the (t) node.

@bdw
bdw / lvalue.c
Created April 29, 2015 19:42
lvalue demonstration
int * foo(void) {
int a = 4;
return &a;
}
int main() {
int a[5];
a[1] = 3; /* we assign something to the location a[1] */
printf("%d\n", a[0]); /* and now we read from the (uninitialized) location a[0] */
@bdw
bdw / docker-rm-images.sh
Created November 24, 2014 16:09
docker remove images and containers
#!/bin/bash
for id in `docker ps -a | cut -c 1-20 | grep -v 'CONTAINER ID'`; do docker rm -f $id; done
if [ "$1" = "-a" ]; then
for id in `docker images | cut -c 41-60 | grep -v 'IMAGE ID'`; do docker rmi -f $id; done
fi
@bdw
bdw / test-cmp-i.nqp
Created November 24, 2014 15:09
which is better (both are corect)
#!/usr/bin/env nqp-m
my int $i := 0;
sub foo (int $x) {
if (nqp::cmp_i($x, 50) > 0) {
nqp::say("$x: OH HAI");
} else {
nqp::say("$x: OH NOES");
}
}
@bdw
bdw / .gitignore
Last active August 29, 2015 14:07
Java Multicast Example
*.class
*~
@bdw
bdw / 122504.patch
Created August 31, 2014 16:05
fix bug 122504
diff --git a/src/vm/moar/ops/perl6_ops.c b/src/vm/moar/ops/perl6_ops.c
index 65eeb27..3599cd5 100644
--- a/src/vm/moar/ops/perl6_ops.c
+++ b/src/vm/moar/ops/perl6_ops.c
@@ -462,8 +462,9 @@ static MVMuint8 s_p6routinereturn[] = {
MVM_operand_obj | MVM_operand_read_reg,
};
static void p6routinereturn(MVMThreadContext *tc, MVMuint8 *cur_op) {
- MVMObject *ret = MVM_frame_find_lexical_by_name_rel_caller(tc, str_return,
- tc->cur_frame)->o;
@bdw
bdw / getcodeobj.patch
Created August 29, 2014 18:54
getcodeobj patch
diff --git a/src/core/frame.c b/src/core/frame.c
index 7669e39..41673b1 100644
--- a/src/core/frame.c
+++ b/src/core/frame.c
@@ -843,6 +843,8 @@ void MVM_frame_unwind_to(MVMThreadContext *tc, MVMFrame *frame, MVMuint8 *abs_ad
/* Gets a code object for a frame, lazily deserializing it if needed. */
MVMObject * MVM_frame_get_code_object(MVMThreadContext *tc, MVMCode *code) {
+ if (REPR(code)->ID != MVM_REPR_ID_MVMCode)
+ MVM_exception_throw_adhoc(tc, "getcodeobj needs a code ref");
@bdw
bdw / response.md
Created June 11, 2014 08:50
Mike Palls DynASM response

ARM

ARM should be relatively straightforward:

You'll need to move the shifting into parse_gpr() and parse_vr() in dasm_arm.lua. These should use waction() to emit a (new) VREG op for dynamic registers. The VREG op needs to know the shift amounts for merging the register number. Note that FPRs require an extra bit at a different shift position.

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
/* note - for windows this is different */
#include <sys/mman.h>
#include "dynasm/dasm_proto.h"
#include "dynasm/dasm_x86.h"
// DynASM directives.
@bdw
bdw / buffer.c
Created April 29, 2014 18:28
Proposed 'pointer buffer' implementation - pointer buffers are extremely common in moarvm
#include <stdlib.h>
struct MVMPointerBuffer {
union {
void ** v;
MVMObject **objects;
MVMCollectable **collectables;
MVMSpeshBB **spesh_bbs;
/* some other common pointer types */
} p;