Skip to content

Instantly share code, notes, and snippets.

# Imported Clojure functions
clojure('<=', 2) -> lte
clojure('dec', 1) -> dec
# Fibonacci function (recursive)
# Takes advantage of dodo ability to return more than one result at once
fun fib -> n, return, throw
(
'<='(n, 0) -> zero
if (zero) ->
@jido
jido / day4-cleanup.do0
Created December 8, 2022 20:43
Advent of Code day 4 solution in Dodo0 language
clojure('read-line', 0) -> readline
clojure('split', 2) -> split
clojure('nil?', 1) -> endOfFile
clojure('read-string', 1) -> asInt
fun loop -> count, break
(
readline() -> line
endOfFile(line) -> eof
if (eof) ->
@jido
jido / clock.r
Last active April 16, 2022 20:18
EST becomes EDT
> library(clock)
> x <- as.POSIXct("2020-11-01 00:30:00", "America/New_York")
> x <- add_hours(x, 0:2)
> x
[1] "2020-11-01 00:30:00 EDT" "2020-11-01 01:30:00 EDT"
[3] "2020-11-01 01:30:00 EST"
> add_years(x, 1)
[1] "2021-11-01 00:30:00 EDT" "2021-11-01 01:30:00 EDT"
[3] "2021-11-01 01:30:00 EDT"
> add_years(x, -1)
@jido
jido / extended64bit.jl
Created February 22, 2022 19:00
A way to represent integers up to 2^125 in 64 bits, based on the Posit representation of numbers.
# Note: this was tested on Arm64. It should work on any common 64 bit architecture.
# Note 2: typemin(Int64) means NaN and is not handled by the function.
extend64to128 = function(w :: Int64)
x = abs(w)
big = (x << 1) >> 63 # -1 if the number is extended (bit 62 set)
neg = (w >>> 62) | 1 # 11 for negative number, 01 for positive
rg = leading_zeros(~x << 1) # count the regime bits
# That's where it really starts.
@jido
jido / Cargo.toml
Created February 22, 2020 00:51
Calculate prime factors of a 64-bit number using Rust, FAST!
[package]
edition = "2020"
name = "prime_factors"
version = "1.1.1"
[dependencies]
rand = "0.7.3"
@jido
jido / positmacros.h
Created January 11, 2020 21:31
Macro to build a Posit at compile time
#ifndef positmacros_h
#define positmacros_h
#ifdef __cplusplus
extern "C"{
#endif
#include <stdint.h>
#define INT8_MASK 0x7f
@jido
jido / zig
Last active May 20, 2019 19:15
make install errors
[ 98%] Built target compiler
Scanning dependencies of target zig0
[ 98%] Building CXX object CMakeFiles/zig0.dir/src/main.cpp.o
[ 99%] Building CXX object CMakeFiles/zig0.dir/src/userland.cpp.o
[ 99%] Linking CXX executable zig0
[ 99%] Built target zig0
Scanning dependencies of target userland_target
[ 99%] Generating userland.o
ar rcs /Users/jido/dev/github/zig/libuserland.a /Users/jido/dev/github/zig/userland.o /Users/jido/Library/Application Support/zig/stage1/o/Kw399qJMMhP1xxYkT-9eyTN-lrfoF9WqGdLNtnNfyyKQhXGVkyyKpvSaF-xJEXD8/compiler_rt.o
[ 99%] Built target userland_target
@jido
jido / int32.s
Last active March 17, 2019 19:02
.intel_syntax noprefix
_add:
mov eax, edi
add eax, esi
jo plus_overflow
jmp r8
plus_overflow:
jmp r9
@jido
jido / int32.s
Last active March 16, 2019 20:41
Why do I get libdyld.dylib`stack_not_16_byte_aligned_error ?
-> 0x100000ee4 <+5>: callq 0x100000f74 ; symbol stub for: malloc
0x100000ee9 <+10>: addq $0x10, %rsp
0x100000eed <+14>: cmpq $0x0, %rax
0x100000ef1 <+18>: je 0x100000f3b ; Integer_bits_32_outofmemory
Target 0: (int32) stopped.
(lldb) reg read rbp rsp
rbp = 0x00007ffeefbff9e0
rsp = 0x00007ffeefbff9d8
(lldb) n
Process 23851 stopped
@jido
jido / int32.ll
Last active March 14, 2019 23:12
Problem: the alloca calls reserve 16 bytes each, so pointer arithmetic in "plus" is wrong
; ModuleID = 'integer.dodo'
; Function Attrs: noinline nounwind
define void @int32() {
%frame = alloca i8*, align 8
%context = alloca i8*, align 8
br label %test
plus:
%plus1 = load i8*, i8** %frame, align 8