Skip to content

Instantly share code, notes, and snippets.

View jubnzv's full-sized avatar

Georgiy Komarov jubnzv

View GitHub Profile
@jubnzv
jubnzv / aam.ml
Created August 5, 2022 12:10
Abstracting Abstract Machine in OCaml
open Core_kernel
open Printf
type var = string [@@deriving eq, ord, sexp]
type term = Ref of var
| Lam of var * term
| App of term * term [@@deriving eq, ord, sexp]
let rec pp_term = function
| Ref v -> v
#!/usr/bin/env ocaml
let startswith s1 s2 =
let len1 = String.length s1 and len2 = String.length s2 in
if len1 < len2 then false
else
let sub = String.sub s1 0 len2 in
String.equal sub s2
let check filepath =
@jubnzv
jubnzv / dir.ml
Created August 5, 2021 10:43 — forked from lindig/dir.ml
OCaml - list recursively regular files in a directory
(** [dir_is_empty dir] is true, if [dir] contains no files except
* "." and ".."
*)
let dir_is_empty dir =
Array.length (Sys.readdir dir) = 0
(** [dir_contents] returns the paths of all regular files that are
* contained in [dir]. Each file is a path starting with [dir].
@jubnzv
jubnzv / 1.Instructions.md
Created April 25, 2021 16:43 — forked from WesThorburn/1.Instructions.md
Linux: Compile C++ to WebAssembly and JavaScript using Emscripten and CMake

Linux: Compile C++ to WebAssembly and JavaScript using Emscripten and CMake

Download and Install Emscripten

  • My preferred installation location is /home/user
  • Get the latest sdk: git clone https://github.com/emscripten-core/emsdk.git
  • Enter the cloned directory: cd emsdk
  • Install the lastest sdk tools: ./emsdk install latest
  • Activate the latest sdk tools: ./emsdk activate latest
  • Activate path variables: source ./emsdk_env.sh
  • Configure emsdk in your bash profile by running: echo 'source "/home/user/emsdk/emsdk_env.sh"' >> $HOME/.bash_profile
#ifndef UBENCH_HPP
#define UBENCH_HPP
#include <algorithm>
#include <atomic>
#include <cstdint>
#include <ostream>
#include <time.h>
#include <unistd.h>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
class A {
public:
A(int Data) : Data(Data) {}
@jubnzv
jubnzv / table_to_string.lua
Created August 11, 2020 13:46 — forked from justnom/table_to_string.lua
Lua table to string
-- Convert a lua table into a lua syntactically correct string
function table_to_string(tbl)
local result = "{"
for k, v in pairs(tbl) do
-- Check the key type (ignore any numerical keys - assume its an array)
if type(k) == "string" then
result = result.."[\""..k.."\"]".."="
end
-- Check the value type
# This checks that tool will emit an error when trying to remove the symbol
# table when we have a group section linked with symtab.
# RUN: yaml2obj %s -o %t.o
# RUN: not llvm-objcopy -R .symtab %t.o %t1 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR -DINPUT=%t.o
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
#define __define_initcall(level,fn,id) \
static initcall_t __initcall_##fn##id __used \
__attribute__((__section__(".initcall" level ".init"))) = fn
#define core_initcall(fn) __define_initcall("1",fn,1)
#define subsys_initcall(fn) __define_initcall("4",fn,4)
#define late_initcall(fn) __define_initcall("7",fn,7)
/* trimmed, obviously... */