This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE BangPatterns #-} | |
import qualified Data.Vector.Unboxed as V | |
import System.CPUTime | |
import Text.Printf | |
time :: IO t -> IO t | |
time a = do | |
start <- getCPUTime | |
v <- a | |
end <- getCPUTime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main | |
import Data.Vect | |
toVec : List a -> (n : Nat ** Vect n a) | |
toVec [] = (_ ** []) | |
toVec (x::xs) with (toVec xs) | |
| (k ** v) = (S k ** x :: v) | |
myFun : Vect n1 Int -> Vect n2 Int -> LTE n1 n2 -> Int | |
myFun xs ys p = foldr (+) 0 xs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.complex, std.stdio, std.random, std.parallelism, std.math : hypot; | |
import std.getopt, std.datetime.stopwatch, std.array, std.algorithm : max, min, reduce; | |
import std.format, std.range : iota; | |
struct Wall { double y, x1, x2; } // x1 < x2 | |
struct Point { double x, y; } | |
bool intersects(Point p1, Point p2, ref Wall wall) { | |
if (min(p1.y, p2.y) > wall.y) return false; | |
if (max(p1.y, p2.y) < wall.y) return false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ILogger { | |
void log(string msg); | |
} | |
class BoringLogger : ILogger { | |
overrride void log(string msg) {...} | |
} | |
class ColorfulLogger : ILogger { | |
overrride void log(string msg) {...} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Batteries | |
type point = { x : int; y : int } | |
let f from_y to_y from_x to_x = | |
let a = (from_y --^ to_y/2) |> Enum.map (fun y -> {x=from_x; y=y}) in | |
let b = (to_y/2 --^ to_y) |> Enum.map (fun y -> {x=to_x; y=y}) in | |
Enum.append a b |> Array.of_enum;; | |
let g from_y to_y from_x to_x = | |
let t = to_y/2 in | |
Array.init (to_y - from_y) (fun i -> let y = i + from_y in if y < t then {x=from_x; y=y} else {x=to_x;y=y});; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.stdio, std.algorithm, std.range, std.array, std.datetime.stopwatch; | |
struct Point { int x, y; } | |
auto f(int from_y, int to_y, int from_x, int to_x) { | |
return chain( iota(from_y, to_y/2).map!(y => Point(from_x, y)), | |
iota(to_y/2, to_y) .map!(y => Point(to_x, y)) ).array; | |
} | |
auto g(int from_y, int to_y, int from_x, int to_x) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified Data.ByteString.Lazy.Char8 as L8 | |
import Network.HTTP.Client (defaultManagerSettings, newManager) | |
import Network.HTTP.Simple | |
import Network.HTTP.Client.TLS | |
import System.Directory | |
import qualified Data.Map as M | |
import Data.List (sortBy) | |
import Control.Monad | |
import Control.Applicative | |
import System.Environment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cap=134217728 | |
arrSize=16385 | |
next uni=8192 | |
cap=8192 | |
arrSize=129 | |
next uni=64 | |
cap=64 | |
arrSize=9 | |
next uni=8 | |
n for 64 = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case ADD|RRR: | |
case ADD_RRR: | |
if (code[ip+1]==code[ip+2]) { | |
a.mov(eax, dword_ptr(edi, code[ip+3]*4)); | |
a.add(dword_ptr(edi, code[ip+1]*4), eax); | |
} else { | |
a.mov(eax, dword_ptr(edi, code[ip+2]*4)); | |
a.add(eax, dword_ptr(edi, code[ip+3]*4)); | |
a.mov(dword_ptr(edi, code[ip+1]*4), eax); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "lvm2jit.h" | |
#include <stdio.h> | |
#include <vector> | |
LVM2jit::LVM2jit(int stacksize, int heapsize) | |
: fun(NULL) | |
{ | |
frame = (int*)calloc(stacksize, 1); | |
heap = (BYTE*)calloc(heapsize, 1); | |
callstack = (context_t*)calloc(10000, sizeof(context_t)); |