Skip to content

Instantly share code, notes, and snippets.

@thautwarm
thautwarm / llvm-exc.md
Last active July 1, 2018 03:44
LLVM Exception handling
#include <stdio.h>
#include <stdlib.h>

class Object {
  public:
  virtual ~Object() {}
};
@thautwarm
thautwarm / no nightly
Created July 23, 2018 05:12
no nightly
https://play.rust-lang.org/?gist=36c36edf00f2c903727ce881bd4e7ae9&version=stable&mode=debug&edition=2015

no macro leads to success:

struct A end
struct B end
function f()
enum1 = A()
enum2 = B()
begin
    let enum_test = enum1
        begin
@thautwarm
thautwarm / test.fs
Last active November 17, 2018 07:45
compelling variable sized struct in LLVM IR
[<Fact>]
let ``nested push32`` () =
let var = ref None
let var2 = ref None
let var3 = ref None
let arg1 = ref <| Some "arg1"
let arg2 = ref <| Some "arg2"
let type_here = Push32 <| I 32
@thautwarm
thautwarm / hkt.ts
Created December 12, 2018 03:29
higher kinded types implementation
interface HKT<K, T>{
}
interface Monad<M> {
bind: <A, B>(m: HKT<M, A>, k: (a: A) => HKT<M, B>) => HKT<M, B>
return: <A>(a: A) => HKT<M, A>
// ret$: <A>(m: (a: A) => HKT<M, A>) => HKT<M, A>
}
class Maybe implements Monad<Maybe> {
@thautwarm
thautwarm / HKT.hs
Created July 24, 2019 18:42
HKTs via type classes
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE RankNTypes #-}
import Unsafe.Coerce
import Prelude hiding ((>>=))
data App a b
class TypeApp cons k0 k1 | k1 -> cons k0, cons k0 -> k1 where
inj :: k1 -> App cons k0
ipython profile create && \
pip install -U moshmosh-base -i https://pypi.org/simple --no-compile &&\
wget https://raw.githubusercontent.com/thautwarm/moshmosh/master/moshmosh_ipy.py &&\
mv moshmosh_ipy.py /home/$USER/.ipython/profile_default/startup/moshmosh_ipy.py
@thautwarm
thautwarm / print.asm
Created October 30, 2019 13:39
mips-print
.word 0x10000002 ; MERL cookie
.word 0x0000010c ; File Length (in bytes) is 268
.word 0x000000ec ; Code Length (in bytes) is 236
print:
sw $1, -4($30)
sw $2, -8($30)
sw $3, -12($30)
sw $4, -16($30)
sw $5, -20($30)
sw $6, -24($30)
@thautwarm
thautwarm / alloc.asm
Created October 30, 2019 13:40
mips-alloc
.word 0x10000002 ; MERL cookie
.word 0x00000760 ; File Length (in bytes) is 1888
.word 0x00000640 ; Code Length (in bytes) is 1600
init:
sw $1, -4($30)
sw $2, -8($30)
sw $3, -12($30)
sw $4, -16($30)
sw $5, -20($30)
sw $6, -24($30)
@thautwarm
thautwarm / type_sort1.jl
Created April 1, 2020 10:33
use for static julia type utils
function sort_type(ts :: Vector{Type})
n = length(ts)
if n == 1
ts
elseif n == 2
a, b = ts[1], ts[2]
if a <: b
[a, b]
elseif b <: a
[b, a]