Skip to content

Instantly share code, notes, and snippets.

View alcides's full-sized avatar

Alcides Fonseca alcides

View GitHub Profile
@alcides
alcides / f.lean
Last active June 14, 2021 09:33
Lean3 and SMT Solvers for Refinement Types
import tactic.suggest
import tactic.basic
import smt
open smt_tactic
set_option pp.all true
lemma example_of_something_for_which_smt_is_useful
(f : list nat → list nat) (a b c : list nat) :
@alcides
alcides / RebuildException.py
Created March 23, 2021 19:54
Rebuilds Exceptions from name
import importlib
class MyError(Exception):
pass
def __str__(self):
return "HERE"
try:
print("hi")
@alcides
alcides / compilador.py
Created February 12, 2021 18:29
O meu primeiro compilador
# Depende do Lark: pip3 install lark-parser
import os
import sys
from lark import Lark
from lark.lexer import Token
def get_contents(fname):
return open(fname).read()
from z3 import *
from itertools import combinations
s = Solver()
h1, h2, h3, h4, l, b1, b2 = Ints("h1 h2 h3 h4 l b1 b2")
hippos = [h1, h2, h3, h4]
for w in [223,235,248,272]:
@alcides
alcides / ConstantUtils.java
Created May 29, 2020 19:50
Convert Java floats and doubles to LLVM float and double Hex literals.
package com.alcidesfonseca.llvmgenerator;
/*
* Helper functions to convert float and double constants to LLVM format
*
* Inspired by Scala Native
* */
public class ConstantUtils {
public String floatToLLVM(float f) {
from z3 import *
y,g,r,b = Ints("y g r b")
c1, c2, c3, c4 = Ints("c1 c2 c3 c4")
s = Solver()
for v in [y,g,r,b]:
s.add(z3.And(v > 0, v < 10))
@alcides
alcides / main.jl
Created January 19, 2020 12:58
Refined Types in Julia
import Base.+
import Base.-
import Base.<
import Base.Meta.@lower
struct Refined{T, cond} # <: T where {T <: Number}
e::T
Refined{T, cond}(x::T) where {T, cond} = new{T, cond}(x)
end
@alcides
alcides / HelloWorld.java
Last active May 24, 2019 16:49
Ficheiro de teste para javafx
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class HelloWorld extends Application {
@alcides
alcides / example.rs
Created February 18, 2019 14:48
Rust MPSC solution for the petition challenge
/*
A solution for the "Vasco Vasconcelos Petition challenge", using rust mpsc package.
Alcides Fonseca <[email protected]>
How to run:
rustc example.rs && ./example
*/
@alcides
alcides / wrap_java_e_nao_so.py
Created April 10, 2018 09:41
Explanation of wrap-around in Java
"""
Doc:
https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.18.2
If an integer addition overflows, then the result is the low-order bits of the mathematical sum as represented in some sufficiently large two's-complement format.
"""