Skip to content

Instantly share code, notes, and snippets.

View doublec's full-sized avatar

Chris doublec

  • Perth, Australia
View GitHub Profile
@doublec
doublec / Makefile
Created August 30, 2012 04:23
ATS FFI example
all: base64
base64: base64.dats
atscc -o base64 base64.dats
staload "contrib/task/SATS/task.sats"
dynload "contrib/task/DATS/task.dats"
fn do_main (sch: scheduler) = begin
set_global_scheduler (sch);
task_spawn (16384, lam () => begin
print ("hello\n");
task_yield ();
print ("world\n")
fun foo {v:view} (pf: !v | b1: (!v | int) -<cloref> void):void = {
val v = 5
val () = b1(pf | v)
}
implement main () = {
var x: int? with pf_x
viewdef V = int? @ x
val () = foo {V} (pf_x | lam (pf | newval) => x := newval)
val () = printf("%d\n", @(x))
@doublec
doublec / test.dats
Created October 30, 2011 23:47
Structures and linear resources
%{^
typedef struct resource {
void* data;
int x;
} resource;
%}
absviewtype data_vt (l:addr)
extern fun data_vt_make (): [l:agz] (data_vt l ) = "mac#data_make"
extern fun data_vt_free {l:addr} (r: data_vt l): void = "mac#data_free"
@doublec
doublec / namecoin-hosts.c
Created May 12, 2011 05:27
namecoin-hosts
/*
Copyright (c) 2011, Chris Double
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
staload "libc/SATS/random.sats"
staload "libc/SATS/unistd.sats"
staload "libats/SATS/parworkshop.sats"
staload "libats/DATS/parworkshop.dats"
staload "prelude/DATS/array.dats"
#define ITER 100000000
#define NCPU 2
fn random_double (buf: &drand48_data): double = let
staload "libc/SATS/random.sats"
staload "libc/SATS/unistd.sats"
staload "libats/SATS/parworkshop.sats"
staload "libats/DATS/parworkshop.dats"
staload "prelude/DATS/array.dats"
#define ITER 100000000
#define NCPU 2
fn random_double (buf: &drand48_data): double = let
staload "libc/SATS/signal.sats"
staload "libc/SATS/stdio.sats"
staload "libc/SATS/unistd.sats"
staload "libc/sys/SATS/wait.sats"
staload "libc/sys/SATS/types.sats"
staload "libc/sys/SATS/socket.sats"
staload "libc/netinet/SATS/in.sats"
staload "libc/arpa/SATS/inet.sats"
staload "prelude/DATS/array0.dats"