Skip to content

Instantly share code, notes, and snippets.

@bakpakin
bakpakin / fix-include.diff
Created December 29, 2019 20:12
Fix include in Fennel 0.4.0-dev
diff --git a/fennel.lua b/fennel.lua
index d824823..f32873e 100644
--- a/fennel.lua
+++ b/fennel.lua
@@ -2604,7 +2604,7 @@ SPECIALS['include'] = function(ast, scope, parent, opts)
-- splice in source and memoize it
-- so we can include it again without duplication
- local target = gensym(scope)
+ local target = gensym(rootScope, "module")
@bakpakin
bakpakin / linecol.diff
Created September 22, 2019 20:11
Add line, column to stacktraces
diff --git a/src/core/debug.c b/src/core/debug.c
index f433869..2aa238d 100644
--- a/src/core/debug.c
+++ b/src/core/debug.c
@@ -150,8 +150,44 @@ void janet_stacktrace(JanetFiber *fiber, Janet err) {
if (frame->func && frame->pc) {
int32_t off = (int32_t)(frame->pc - def->bytecode);
if (def->sourcemap) {
+ /* Try to get line and column information */
JanetSourceMapping mapping = def->sourcemap[off];
@bakpakin
bakpakin / fix.diff
Created September 20, 2019 04:14
Fix for bad stacktraces in fennel.
diff --git a/fennel.lua b/fennel.lua
index 8c79320..58341df 100644
--- a/fennel.lua
+++ b/fennel.lua
@@ -2057,7 +2057,8 @@ local function traceback(msg, start)
local level = start or 2 -- Can be used to skip some frames
local lines = {}
if msg then
- table.insert(lines, msg)
+ local stripped = msg:gsub('^[^:]*:%d+:%s+', 'runtime error: ')
@bakpakin
bakpakin / fix.diff
Created September 7, 2019 01:56
Fix ambiguous Lua code emitted from Fennel
diff --git a/fennel.lua b/fennel.lua
index c079085..dd7252f 100644
--- a/fennel.lua
+++ b/fennel.lua
@@ -825,7 +825,8 @@ local function keepSideEffects(exprs, chunk, start, ast)
if se.type == 'expression' and se[1] ~= 'nil' then
emit(chunk, ('do local _ = %s end'):format(tostring(se)), ast)
elseif se.type == 'statement' then
- emit(chunk, tostring(se), ast)
+ local code = tostring(se)
@bakpakin
bakpakin / janet.hpkg
Created September 4, 2019 02:53
hermes janet package
core_modules = unpack_url(
url="https://github.com/buildpackagedeploy/hermes-core/archive/4f92d8aaa001406e58513929710027bc4b733cf2.tar.gz",
hash="sha256:db931edc4ddf71a8d749a09f14ed5d771f7099b898273176111452c4b9700983",
)
bootstrap_env = load_module(core_modules, "bootstrap.hpkg").bootstrap_env
janet_src = fetch_url(
url="https://github.com/janet-lang/janet/archive/v1.2.0.tar.gz",
hash="sha256:e824ee2da7dffab10bb7ce28917b57a82df82eebf713ad2bbb74ed7be36bd4f4"
(defn http-get
"Get some HTTP using curl"
[url]
(with [f (file/popen (string "curl -s " url))]
(:read f :all)))
(http-get "https://www.google.com")
static JanetFunction *global_cb = NULL;
Janet register_callback(int32_t argc, Janet *argv) {
janet_fixarity(argc, 1);
JanetFunction *cb = janet_getfunciton(argv, 0);
global_cb = cb;
// Make sure the callback is not garbage collected while waiting
janet_gcroot(argv[0]);
return janet_wrap_nil();
}
@bakpakin
bakpakin / diff.patch
Created June 6, 2019 19:34
Fennel include patch
diff --git a/fennel.lua b/fennel.lua
index 56ee209..a951d5f 100644
--- a/fennel.lua
+++ b/fennel.lua
@@ -422,6 +422,9 @@ local function makeScope(parent)
symmeta = setmetatable({}, {
__index = parent and parent.symmeta
}),
+ includes = setmetatable({}, {
+ __index = parent and parent.includes
@bakpakin
bakpakin / janetsh.rc
Created May 25, 2019 02:10
janetsh rc
(import shlib)
(defn ansi
"Take a string made by concatenating xs and colorize it for an ANSI terminal."
[code & xs]
(string "\e[" code "m" ;xs "\e[0m"))
(defn cmd
"Run a quick command and strip trailing newline."
[s]
@bakpakin
bakpakin / gist:c0295eb52ec1bcca1e3b353d154ed23b
Created March 12, 2019 18:32
Indented Fennel example by fennel.vim
(fn line-iter [packets]
(var buf "")
(fn recur []
(local (residual rest) (: buf :match "^(.*)\r\n(.*)$"))
(if residual
(do (set buf rest) residual)
(let [packet (packets)]
(when packet
(set buf (.. buf packet))
(recur))))))