Skip to content

Instantly share code, notes, and snippets.

View dherman's full-sized avatar

Dave Herman dherman

View GitHub Profile
pub struct Parser<I> {
pub lexer: Lexer<I>,
pub shared_cx: Rc<Cell<joker::context::Context>>,
pub parser_cx: context::Context
}
impl<'a> From<&'a str> for Parser<Chars<'a>> {
fn from(s: &'a str) -> Parser<Chars<'a>> {
Parser::from(s.chars())
}
pub struct Parser<I> {
pub lexer: Lexer<I>,
pub shared_cx: Rc<Cell<joker::context::Context>>,
pub parser_cx: context::Context
}
impl<'a> From<&'a str> for Parser<Chars<'a>> {
fn from(s: &'a str) -> Parser<Chars<'a>> {
Parser::from(s.chars())
}
mod b {
pub use c::*;
self::d::m!;
}
mod c {
mod d {
pub macro_rules! m { }
}
}
int main() {
int *p = 0;
*p = 42;
return 0;
}
%%RegistryPrototype%%[ @@iterator ]
%%RegistryPrototype%%.get(key) -> RegistryEntry
%%RegistryPrototype%%.set(key, module)
%%RegistryPrototype%%.has(key) -> boolean
%%RegistryPrototype%%.delete(key)
get %%RegistryEntryPrototype%%.stage -> "fetch" or "translate" or "instantiate" or "satisfy" or "link" or "ready"
get %%RegistryEntryPrototype%%.module -> module object or null
%%RegistryEntryPrototype%%.load(stage) -> promise
%%RegistryEntryPrototype%%.result(stage) -> promise or undefined
@dherman
dherman / src.rs
Last active October 12, 2015 20:46
version 2: allocation as statics with scope parameter
extern crate nanny;
use nanny::vm::Call;
use nanny::value::{Integer, Number, Object, Array};
use nanny::mem::Handle;
use nanny::scope::Scope;
use std::ffi::CString;
// Rust implementations of Node functions must be linked without mangled names.
@dherman
dherman / src.rs
Created October 12, 2015 20:34
version 1: allocation as scope methods
extern crate nanny;
use nanny::vm::Call;
use nanny::value::Object;
use nanny::mem::Handle;
use nanny::scope::Scope;
use std::ffi::CString;
// Rust implementations of Node functions must be linked without mangled names.
@dherman
dherman / irccloud.js
Created October 11, 2015 07:34
some useful commands for doing batch IRC admin in IRCCloud via the developer console
// print all the active PM conversations in moz IRC
console.log(JSON.stringify(Array.prototype.slice.call($("#buffers .connection:has(.buffer[href*='irc.mozilla.org']) ul.conversations > li.conversation .label")).map(span => span.firstChild.wholeText)))
// print all archived PM conversations in moz IRC
console.log(JSON.stringify(Array.prototype.slice.call($("#buffers .connection:has(.buffer[href*='irc.mozilla.org']) ul.openArchives > li.conversation .label")).map(span => span.firstChild.wholeText)))
// delete all conversations from a `spambots` array
(function(textarea) {
spambots.forEach((nick, i) => setTimeout(() => {
textarea.focus();
@dherman
dherman / node-polyglot.md
Last active September 29, 2015 17:24
making node friendlier to other languages

I've run into a bit of an issue with integrating build steps for native modules written in other languages. In my case I'm working with Rust, but I think this applies to any compiled language other than C/C++. For example, here's an article about writing native modules in C# that came to a similar solution.

I see a few alternative solutions to integrating a third-party compiler into the build workflow. I'm mostly interested in getting to a mutual understanding about the recommended practice, but some of these options also suggest possible changes to the node/npm tooling.

(1) Recommend using actions

Gyp actions let you call out to arbitrary external commands and specify their inputs and outputs so that they hook into the build flow. This almost sounds perfect, except for the fact that actions occur during the configure phase of node-g

--- node-gyp-original/lib/configure.js 2015-09-29 00:11:34.000000000 -0700
+++ node-gyp-modified/lib/configure.js 2015-09-29 00:08:22.000000000 -0700
@@ -19,6 +19,8 @@
, spawn = cp.spawn
, execFile = cp.execFile
, win = process.platform == 'win32'
+ , config
+ , defaults
exports.usage = 'Generates ' + (win ? 'MSVC project files' : 'a Makefile') + ' for the current module'