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 / ve.py
Created February 14, 2014 08:39
Really easy virtualenv wrapper
#!/usr/bin/env python
import argparse
import os
import os.path
import sys
import subprocess
import shutil
try:
import virtualenv
<h3>What is your e-mail address and IRC nick?</h3>
<p>bartwiegmans@gmail.com, brrt on freenode</p>
<h3>What is your web page, blog, or microblog?</h3>
<p><a href="https://plus.google.com/u/0/+BartWiegmans/posts">I have a google+ page</a> - although I don't actually post a lot of things there.</p>
@bdw
bdw / compact.py
Created March 21, 2014 23:02
An algorithm to compact arrays (python). I figured it out but I can't explain why it works.
def compact(a_list):
# strategy - find the first empty and nonempty items
empty, nonempty = 0, 0
while empty < len(a_list) and nonempty < len(a_list):
# ok, so in principle this works really well... why?
# what happens is that nonempty looks for the earliest nonempty
# element and empty looks for the earliest empty element
if a_list[nonempty] is None:
nonempty += 1
@bdw
bdw / broken-re.py
Created March 25, 2014 14:11
showing python re is subtly broken
#!/usr/bin/env python
import re
s = r'"foo \" bar" baz "quix"'
# same regex right?
p_a = r'"(\\"|[^"])*"'
p_b = r'"([^"]|\\")*"'
# no
print(re.match(p_a, s).group(0))
@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;
#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 / 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.

@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 / 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 / .gitignore
Last active August 29, 2015 14:07
Java Multicast Example
*.class
*~