Skip to content

Instantly share code, notes, and snippets.

Program Analysis, a Big Happy Family

The idea behind program analysis is simple, right? You just want to know stuff about your program before it runs, usually because you don't want unexpected problems to arise (those are better in movies.) Then why looking at Wikipedia gives you headaches? Just so many approaches, tools, languages 🤯

In this article I would like to give a glimpse of an overarching approach to program analysis, based on ideas from abstract interpretation. My goal is not to pinpoint a specific technique, but rather show how they have common core concepts, the differences being due mostly to algorithmic challenges. In other words, static analysis have a shared goal, but it's a challenge to make them precise and performant.

Code is meant to be executed by a computer. Take the following very simple function:

fun cantulupe(x) = {
@p4bl0-
p4bl0- / 00_readme.md
Last active October 12, 2023 09:09
A complete compiler for a simple language (in less than 150 LoC)

This project is a tiny compiler for a very simple language consisting of boolean expression.

The language has two constants: 1 for true and 0 for false, and 4 logic gates: ! (not), & (and), | (or), and ^ (xor).

It can also use parentheses to manage priorities.

Here is its grammar in BNF format:

expr ::= "0" | "1"

# Using a specific checkout of nixpkgs makes it easy to debug as you know exactly what the deps are.
# This being said in production you should pass the global nixpkgs to this file.
let nixpkgs-src = builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/56d94c8c69f8cac518027d191e2f8de678b56088.tar.gz";
sha256 = "1c812ssgmnmh97sarmp8jcykk0g57m8rsbfjg9ql9996ig6crsmi";
};
in
{ pkgs ? (import nixpkgs-src {}) }:
with pkgs;
with stdenv.lib;
@wsargent
wsargent / docker_cheat.md
Last active August 31, 2023 12:10
Docker cheat sheet
@i-e-b
i-e-b / Readme_NIX_OS.md
Last active July 4, 2023 16:53
/etc/nixos/configuration.nix

My experiments with an XMonad setup in NixOS. This is my work box now, so it pretty much works.

probably needs:

# useradd -m iain
# passwd iain ...
# passwd root ...
@ahammar
ahammar / RebindableIf.hs
Created May 11, 2012 04:15
Example of overloading if-then-else in Haskell
{-# LANGUAGE RebindableSyntax #-}
import Prelude
data Height = Tall | Short
class IfThenElse b where
ifThenElse :: b -> a -> a -> a
instance IfThenElse Bool where
@novaluke
novaluke / 0-Q&A.md
Last active April 29, 2023 17:23
I want to use Nix for development, but... -- answers to common concerns about Nix

Nix seems perfect for developers - until I try to use it...

Want to use Nix for development but you're not sure how? Concerned about the fluidity of nixpkgs channels or not being able to easily install arbitrary package versions?

When I first heard about Nix it seemed like the perfect tool for a developer. When I tried to actually use it for developing and deploying web apps, though, the pieces just didn't seem to add up.

@abiodun0
abiodun0 / rbt.hs
Created March 4, 2019 06:02
Red black tree, Haskell
module RedBlackTree
(
Tree,
empty,
member,
insert)
where
data Color = R | B deriving Show
@simonmichael
simonmichael / gist:1185421
Created September 1, 2011 03:59
ghc-pkg-clean, ghc-pkg-reset
# unregister broken GHC packages. Run this a few times to resolve dependency rot in installed packages.
# ghc-pkg-clean -f cabal/dev/packages*.conf also works.
function ghc-pkg-clean() {
for p in `ghc-pkg check $* 2>&1 | grep problems | awk '{print $6}' | sed -e 's/:$//'`
do
echo unregistering $p; ghc-pkg $* unregister $p
done
}
# remove all installed GHC/cabal packages, leaving ~/.cabal binaries and docs in place.