Skip to content

Instantly share code, notes, and snippets.

@dvanhorn
dvanhorn / transcript.txt
Created Feb 6, 2021
macos linking hell
View transcript.txt
☞ # finds .dylib version first, but that's not the kind of linking we're doing
☞ # so barfs
☞ ld -lunistring -exported_symbol _uc_is_property_white_space -r -arch x86_64 -o runtime.o
ld: warning: /usr/local/lib/libunistring.dylib, ignoring unexpected dylib file
Undefined symbols for architecture x86_64:
"_uc_is_property_white_space", referenced from:
-exported_symbol[s_list] command line option
ld: symbol(s) not found for architecture x86_64
☞ # finds .a version because ain't no search, so it works, but ugh.
☞ ld /usr/local/lib/libunistring.a -exported_symbol _uc_is_property_white_space -r -arch x86_64 -o runtime.o
View call_f.s
global frog
global duck
default rel
section .text
extern ptr_to_f
extern f
frog:
sub rsp, 8
lea rax, [rel f wrt ..plt]
call rax
View call_f.s
global frog
global duck
default rel
section .text
extern ptr_to_f
extern f
frog:
sub rsp, 8
lea rax, [rel f wrt ..plt]
call rax
@dvanhorn
dvanhorn / linux_transcript.md
Last active Jan 25, 2021
problem running indirect function call via ffi
View linux_transcript.md

Here's a transcipt of something very similar that seems to result in an infinite loop on Linux. :(

dvanhorn@starburst:small $ cat f.c
int f() {
  return 42;
}

int (*ptr_to_f)() = f;
@dvanhorn
dvanhorn / f.c
Created Jan 20, 2021
can't link an external call in a shared library
View f.c
int f () {
return 42;
}
@dvanhorn
dvanhorn / push.yml
Created Jan 5, 2021
GHA for Racket with scribble and deploy via rsync
View push.yml
on:
- push
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@main
- name: Install dependencies
@dvanhorn
dvanhorn / advent-05.rkt
Created Dec 5, 2020
Advent of Code, Day 5, Part II
View advent-05.rkt
#lang racket
(define in "...")
(define ss
(sort (for/list ([l (in-list (with-input-from-string in port->lines))])
(string->number
(string-append "#b"
(regexp-replaces l '(("F" "0")
("B" "1")
("L" "0")
@dvanhorn
dvanhorn / advent-04.rkt
Created Dec 5, 2020
Advent of Code, Day 4, Part II
View advent-04.rkt
#lang racket
(define in "...")
(define rules
(list
(cons "byr" (λ (x) (let ((y (string->number x))) (and y (<= 1920 y 2002)))))
(cons "iyr" (λ (x) (let ((y (string->number x))) (and y (<= 2010 y 2020)))))
(cons "eyr" (λ (x) (let ((y (string->number x))) (and y (<= 2020 y 2030)))))
(cons "hgt" (λ (x) (let ((y (string-length x)))
(and (<= 3 y)
@dvanhorn
dvanhorn / checkedc-monolith.rkt
Created Dec 4, 2020
Redex model of Checked C (monolithic style)
View checkedc-monolith.rkt
#lang racket
(provide (all-defined-out))
(require redex/reduction-semantics)
;; Redex model of Achieving Safety Incrementally with Checked C,
;; by Ruef, Lampropoulos, Sweet, Tarditi, & Hicks, POST'19.
;; http://www.cs.umd.edu/~mwh/papers/checkedc-incr.pdf
;; This is written in a monolithic-style where there is a single judgment
;; "⊢" that takes a relation name and input and ouput (in order to be
@dvanhorn
dvanhorn / advent-03.rkt
Created Dec 3, 2020
Advent of Code, Day 3, Part II
View advent-03.rkt
#lang racket
(define in "...")
(define (string-ref-mod xs i)
(string-ref xs (modulo i (string-length xs))))
(define lines (call-with-input-string in port->lines))
(define (c δx δy)
(for/sum ([x (in-range 0 +inf.0 δx)]