Skip to content

Commit

Permalink
🎉 Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeta611 committed Jun 20, 2024
0 parents commit fa797d9
Show file tree
Hide file tree
Showing 14 changed files with 497 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Builds, tests & co

on:
pull_request:
push:

permissions: read-all

jobs:
build:
strategy:
fail-fast: false
matrix:
os:
- macos-latest
- ubuntu-latest

runs-on: ${{ matrix.os }}

steps:
- name: Checkout tree
uses: actions/checkout@v4

- name: Set-up OCaml
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: "ocaml-variants.5.1.1+effect-syntax"

- run: opam install . --deps-only --with-test

- run: opam exec -- dune build

- run: opam exec -- dune runtest
89 changes: 89 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Created by https://www.toptal.com/developers/gitignore/api/ocaml,vim,macos
# Edit at https://www.toptal.com/developers/gitignore?templates=ocaml,vim,macos

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### OCaml ###
*.annot
*.cmo
*.cma
*.cmi
*.a
*.o
*.cmx
*.cmxs
*.cmxa

# ocamlbuild working directory
_build/

# ocamlbuild targets
*.byte
*.native

# oasis generated files
setup.data
setup.log

# Merlin configuring file for Vim and Emacs
.merlin

# Dune generated files
*.install

# Local OPAM switch
_opam/

### Vim ###
# Swap
[._]*.s[a-v][a-z]
!*.svg # comment out if you don't need vector files
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]

# Session
Session.vim
Sessionx.vim

# Temporary
.netrwhist
*~
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~

# End of https://www.toptal.com/developers/gitignore/api/ocaml,vim,macos
n
Expand Down
3 changes: 3 additions & 0 deletions .ocamlformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
profile = default
version = 0.26.2
wrap-comments = true
4 changes: 4 additions & 0 deletions bin/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(executable
(public_name react_trace)
(name main)
(libraries react_trace))
1 change: 1 addition & 0 deletions bin/main.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = print_endline "Hello, World!"
32 changes: 32 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
(lang dune 3.15)

(name react_trace)

(generate_opam_files true)

(source
(github React-Analysis/ReacttRace))

(authors "Jay Lee")

(maintainers "Jay Lee")

(license LICENSE)

; (documentation https://url/to/documentation)

(package
(name react_trace)
(synopsis "React Analyzer")
(description "ReacttRace is a tool for analyzing React programs.")
(depends
ocaml
dune
(ocaml-variants (= 5.1.1+effect-syntax))
base
logs
stdio)
(tags
(React "Static Analysis")))

; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project
26 changes: 26 additions & 0 deletions lib/batched_queue.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
open! Base

type 'a t = { f : 'a list; r : 'a list }

exception Empty_queue

let empty = { f = []; r = [] }
let is_empty = function { f = []; _ } -> true | _ -> false

let enqueue q x =
match q with
| { f = []; _ } -> { f = [ x ]; r = [] }
| { f; r } -> { f; r = x :: r }

let front = function
| { f = []; _ } -> raise Empty_queue
| { f = h :: _; _ } -> h

let dequeue = function
| { f = []; _ } -> raise Empty_queue
| { f = [ _ ]; r } -> { f = List.rev r; r = [] }
| { f = _ :: t; r } -> { f = t; r }

let size { f; r } = List.(length f + length r)
let to_list { f; r } = f @ List.rev r
let fold q = List.fold (to_list q)
83 changes: 83 additions & 0 deletions lib/domains.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
open! Base
open Syntax

module Env = struct
type 'a t = 'a Id.Map.t

let empty = Id.Map.empty
let lookup env ~id = Map.find env id
let extend env ~id ~value = Map.set env ~key:id ~data:value
end

module Store = struct
type 'a t = 'a Label.Map.t

let empty = Label.Map.empty
let lookup store ~label = Map.find_exn store label
let update store ~label ~value = Map.set store ~key:label ~data:value
end

module Tree_path = struct
module T = Int
include T

module Map = struct
open Map
include M (T)

let empty = empty (module T)
end
end

module Job_q = Batched_queue

type value =
| Unit
| Int of int
| View_spec of view_spec list
| Clos of clos
| Set_clos of set_clos
| Comp_clos of comp_clos
| Comp_thunk of comp_thunk

and clos = { param : Id.t; body : hook_free Expr.t; env : env }
and set_clos = { label : Label.t; path : path }
and comp_clos = { comp : Prog.comp; env : env }
and comp_thunk = { comp : Prog.comp; env : env; arg : value }
and view_spec = Vs_null | Vs_int of int | Vs_comp of comp_thunk
and env = value Env.t
and phase = P_init | P_update | P_retry | P_effect
and node_ctx = { decision : decision; st_store : st_store; tree_mem : tree_mem }
and decision = Idle | Retry | Update
and st_store = (value * job_q) Store.t
and job_q = clos Job_q.t

and part_view = {
view_spec : view_spec;
decision : decision;
st_store : st_store;
eff_q : job_q;
}

and tree =
| Leaf of tree_val
| Node of { part_view : part_view; children : path list }

and tree_val = Leaf_null | Leaf_int of int
and tree_mem = tree option Tree_path.Map.t
and path = Tree_path.t

let empty_env : env = Env.empty
let empty_st_store : st_store = Store.empty
let empty_tree_mem : tree_mem = Tree_path.Map.empty
let empty_setq : job_q = Job_q.empty
let empty_effq : job_q = Job_q.empty

let equal v1 v2 =
match (v1, v2) with
| Unit, Unit -> true
| Int i1, Int i2 -> i1 = i2
| _, _ -> false

let ( = ) = equal
let ( <> ) v1 v2 = not (equal v1 v2)
3 changes: 3 additions & 0 deletions lib/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(library
(name react_trace)
(libraries base logs stdio))
Loading

0 comments on commit fa797d9

Please sign in to comment.