Skip to content

Instantly share code, notes, and snippets.

@wbbradley
wbbradley / output.txt
Last active January 11, 2019 20:17
Zion Intermediate Representation Example : For Loop
tests/test_for_loop.zion:1:4: test_for_loop.main = (λ_.let __v16 = (std.iter let __range_min__v13 = 1 in let __range_next__v14 = (std.+ 1 __range_min__v13) in let __range_max__v15 = 10 in (std.Range __range_min__v13 (std.- __range_next__v14 __range_min__v13) __range_max__v15)) in (while std.True match (__v16 ()) (std.Just(x) std.print x) (std.Nothing (break!)))) :: () -> std.ExitCode
src/parser.cpp:411:1: std.+ = __builtin_add_int :: Int -> Int -> Int
src/parser.cpp:393:1: std.- = __builtin_subtract_int :: Int -> Int -> Int
tests/test_for_loop.zion:2:16: std.Range = (λ__v10.return! (λ__v11.return! (λ__v12.return! ((__v10, __v11, __v12) as! std.Range Int)))) :: Int -> Int -> Int -> std.Range Int
tests/test_for_loop.zion:2:11: std.True = ((1,) as! std.Bool) :: std.Bool
tests/test_for_loop.zion:2:11: std.iter = (λri.let index = (std.Ref (std.__get_range_min ri)) in (return! (λ_.let cur_index = (std.load_value index) in (if (std.<= cur_index (std.__get_range_max ri)) then ({__builtin_store index (std.+ cur_index
module _
type Vec has {
x float
y float
z float
}
fn main() {
var positions [int: Vec]
module _
# test: pass
# expect: pass with 5
# expect: pass with 6
def main()
x := 5
foo := def (y int)
print("pass with " + (x + y))
global
type OwningBuffer C has
let raw *C
let length uint
def __finalize__(owning_buffer OwningBuffer any)
posix.free(owning_buffer.raw)
@wbbradley
wbbradley / worker_queue.py
Last active January 18, 2018 03:25
A convenient pattern for spawning worker threads and a queue in Python
import logging
from contextlib import contextmanager
from Queue import Queue
from threading import Thread
class ThreadStop(Exception):
pass
@wbbradley
wbbradley / fix-the-web
Last active January 11, 2018 16:45
Make this a bookmark in your Chrome.
javascript:if (1) {
var node = document.createElement('style');
node.innerHTML = "body { font-family: Georgia; width: 35em; line-height:1.5; margin-left: auto; margin-right: auto; } p { margin-top: 1em; }";
document.head.appendChild(node);
}
@wbbradley
wbbradley / tee.zion
Last active December 30, 2017 04:26
start of simple tee implementation
module tee
get sys
get file
def main()
if len(sys.args) == 2
newline := "\n"
f := file.open(sys.args[1], "w")
state := f.state
@wbbradley
wbbradley / 1. condition_refinement.zion
Last active December 4, 2017 14:58
Zion: Refining Types in Short-circuited Logical Expressions
module _
def gimme_bool() bool
return true
def main()
static_print(7)
static_print("hello")
static_print(gimme_bool())
static_print(gimme_bool() ? "foo" : 4.5)
@wbbradley
wbbradley / fix-private-hostname.sh
Last active May 16, 2017 20:08
put the private ip into /etc/hosts
# Run this after your AMI comes online
private_hostname=ip-$(curl http://169.254.169.254/latest/meta-data/local-ipv4 2>/dev/null | sed s/\\./-/g)
sudo su - -c "grep $private_hostname /etc/hosts || echo 127.0.0.1 $private_hostname >> /etc/hosts"
module _
# test: pass
type C{T} is
Ax(T, int, float) or
Bx(int, T, float) or
Cx(int, float, T)
def main()
a_int := Ax(4, 5, 2.1)