Skip to content

Instantly share code, notes, and snippets.

View jimblandy's full-sized avatar

Jim Blandy jimblandy

View GitHub Profile
@jimblandy
jimblandy / bah.js
Created March 27, 2019 21:32
This should print two completions before 'callback', right???
let g = newGlobal({newCompartment: true});
g.eval(`
async function f() {
debugger;
await Promise.resolve(3);
return "ok";
}
`);
let dbg = Debugger(g);
diff --git a/js/src/gc/Barrier.h b/js/src/gc/Barrier.h
--- a/js/src/gc/Barrier.h
+++ b/js/src/gc/Barrier.h
@@ -24,17 +24,17 @@
* write barrier should be invoked whenever a write can cause the set of things
* traced through by the GC to change. This includes:
* - writes to object properties
* - writes to array slots
* - writes to fields like JSObject::shape_ that we trace through
* - writes to fields in private data
@jimblandy
jimblandy / squeeze-solution.rs
Created February 28, 2019 21:57
Solution to the Squeeze challenge.
// You'll need this at the top of your crate:
// #![feature(optin_builtin_traits)]
//! The `squeeze` function.
//!
//! Omit unit values. That is:
//! - `squeeze(x, ())` returns `x`.
//! - `squeeze((), x)` returns `x`.
//! - `squeeze(x, y)` returns `(x, y)`, when neither `x` nor `y` is `()`.
//! - `squeeze((), ())` returns `()`.
@jimblandy
jimblandy / squeeze.rs
Created February 27, 2019 02:52
How would you go about implementing `squeeze`?
#[cfg(test)]
mod test {
use super::squeeze;
#[test]
fn test_squeeze() {
// The idea here is that any non-() type would work.
assert_eq!(squeeze(1i32, 2i32), (1, 2));
assert_eq!(squeeze(true, false), (true, false));
assert_eq!(squeeze("foo", Some("bar")), ("foo", Some("bar")));
@jimblandy
jimblandy / neg2.el
Last active February 2, 2019 21:38
Conversion to base -2, in Emacs Lisp.
;;; Don't just eval-buffer this; it's got a mix of definitions and example evaluations.
(defun neg2-range (width)
(if (zerop width) (cons 0 0)
(let ((range (neg2-range (1- width)))
(offset (expt -2 (1- width))))
(if (< offset 0)
(incf (car range) offset)
(incf (cdr range) offset))
range)))
@jimblandy
jimblandy / intersection.rs
Last active January 27, 2019 19:57
An extremely generic `Range`... intersection operation.
#![cfg_attr(test, feature(range_is_empty))]
use std::cmp::{min, max};
use std::ops::{Range, RangeInclusive, RangeFrom, RangeTo, RangeToInclusive, RangeFull};
pub trait Intersection<Right> {
type Output;
fn intersection(self, right: Right) -> Self::Output;
}
@jimblandy
jimblandy / generator-gc.md
Created October 27, 2018 22:40
Notes on the SpiderMonkey Debugger API, its hooks, generators, and garbage collection

One principle of Debugger's design is that its behavior should not be affected by the garbage collector. Like the rest of JavaScript, the programmer should be able to assume that objects have infinite lifetimes, and that the garbage collector recycles objects only when doing so would have no visible effect on the execution of the program. (Methods like findScripts and findObjects that scan the heap are exceptions; their behavior is sensitive to the garbage collector's activity—and cause plenty of trouble because of it.)

There is also a complementary principle, which is that Debugger should not impede the garbage collector's work more than necessary. For example, if the

@jimblandy
jimblandy / shapes.css
Created September 27, 2018 17:49
Files for reproducing Firefox shape editor bug
body {
font: 1.2em/1.3 Helvetica, arial, sans-serif;
}
.content {
max-width: 700px;
margin: 20px auto;
}
.content::before {
@jimblandy
jimblandy / lambda.lalrpop
Last active September 24, 2018 06:08
Working LALRPOP grammar for the lambda calculus
use ::Expr;
use ::app_chain;
grammar;
pub Expr = {
<Fun>,
<App>,
<Prim>,
};
use std::cmp::min;
use std::iter::FromIterator;
#[derive(Debug)]
enum Edit {
Delete,
Insert(char),
Replace(char),
Keep,
}