Skip to content

Instantly share code, notes, and snippets.

@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 / 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-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 / utf8.janet
Last active January 19, 2022 11:34
Use pegs to parse utf8
###
### utf8.janet
###
### Pure janet utf8 utils. You should probably just use C.
###
(defn utf8-encode
"Convert a sequence of codepoints to a string."
[x]
(def buf @"")
@bakpakin
bakpakin / pkgbuild-janet-lang.patch
Created May 16, 2020 15:20
Fix pkgbuild skipping static libraries and adds /usr/lib/janet for jpm.
diff --git a/PKGBUILD b/PKGBUILD
index 479ef5e..fc24851 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -12,6 +12,7 @@ provides=('janet')
conflicts=('janet-lang-git')
source=("$pkgname-$pkgver.tar.gz::https://github.com/janet-lang/janet/archive/v${pkgver}.tar.gz")
sha256sums=('02724d6074a0d6fa53a548e8bdaaf49999f082e30b277c73444900f739a53062')
+options=('staticlibs')
@bakpakin
bakpakin / client.janet
Created August 10, 2020 19:31
Broken pipe handling in server
(with [conn (net/connect "127.0.0.1" "8000")]
(printf "Connected to %q!" conn)
(:write conn "Echo...")
(print "Wrote to connection...")
(def res (:read conn 1024))
(print "client done")
(pp res))
Running test suite 3 tests...
✔ (range 10): true
✔ (range 1 10): true
✔ zipcoll: true
✔ def-: true
✔ match 1: true
✔ match 2: true
✔ match 3: true
ClJ1bm5pbmcgdGVzdCBzdWl0ZSAzIHRlc3RzLi4uCiAgChtbMzJt4pyUG1swbSAocmFuZ2UgMTAp
OiB0cnVlChtbMzJt4pyUG1swbSAocmFuZ2UgMSAxMCk6IHRydWUKG1szMm3inJQbWzBtIHppcGNv
bGw6IHRydWUKG1szMm3inJQbWzBtIGRlZi06IHRydWUKG1szMm3inJQbWzBtIG1hdGNoIDE6IHRy
dWUKG1szMm3inJQbWzBtIG1hdGNoIDI6IHRydWUKG1szMm3inJQbWzBtIG1hdGNoIDM6IHRydWUK
G1szMm3inJQbWzBtIHJlZ3Jlc3Npb24gMTogdHJ1ZQobWzMybeKclBtbMG0gc2Nhbi1udW1iZXIg
MTogdHJ1ZQobWzMybeKclBtbMG0gc2Nhbi1udW1iZXIgLTE6IHRydWUKG1szMm3inJQbWzBtIHNj
YW4tbnVtYmVyIDEuM2U0OiB0cnVlChtbMzJt4pyUG1swbSBpZi1ub3QgMTogdHJ1ZQobWzMybeKc
lBtbMG0gaWYtbm90IDI6IHRydWUKG1szMm3inJQbWzBtIGlmLW5vdCAzOiB0cnVlChtbMzJt4pyU
G1swbSBpZi1ub3QgNDogdHJ1ZQobWzMybeKclBtbMG0gdW5sZXNzOiB0cnVlChtbMzJt4pyUG1sw
bSBsb29wIDpwYWlyczogdHJ1ZQobWzMybeKclBtbMG0gYmFkIGFyaXR5IDE6IHRydWUKG1szMm3i
@bakpakin
bakpakin / main.janet
Last active December 7, 2020 02:09
Janet preloading
(import preloader)
# Files that a use may want to load
(def mod1 (require "mod1"))
(def mod2 (require "mod2"))
(defn main [& args]
(preloader/preload "@mod1" mod1)
(preloader/preload "@mod2" mod2)
(dofile "some-user-file.janet"))
@bakpakin
bakpakin / *-by.janet
Last active March 4, 2021 03:52
group-by, partition-by in Janet
(defn group-by
``Group elements of `ind` by a function `f` and put the resutls into a table. The keys of
the table are the distinct return values of `f`, and the values are arrays of all elements `x` of `ind`
such that `(f x)` is equal to the key.``
[f ind]
(def ret @{})
(each x ind
(def y (f x))
(if-let [arr (get ret y)]