Skip to content

Commit 74317d4

Browse files
committed
v0.12-preview.120.18+252
1 parent f5483b9 commit 74317d4

27 files changed

+192
-141
lines changed

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License
22

3-
Copyright (c) 2018 Jane Street Group, LLC <[email protected]>
3+
Copyright (c) 2018--2019 Jane Street Group, LLC <[email protected]>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Makefile

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
INSTALL_ARGS := $(if $(PREFIX),--prefix $(PREFIX),)
22

3-
# Default rule
43
default:
5-
jbuilder build @install
4+
dune build
65

76
install:
8-
jbuilder install $(INSTALL_ARGS)
7+
dune install $(INSTALL_ARGS)
98

109
uninstall:
11-
jbuilder uninstall $(INSTALL_ARGS)
10+
dune uninstall $(INSTALL_ARGS)
1211

1312
reinstall: uninstall install
1413

1514
clean:
16-
rm -rf _build
15+
dune clean
1716

1817
.PHONY: default install uninstall reinstall clean

bench/dune

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(library (name hardcaml_bench) (libraries hardcaml)
2+
(preprocess (pps ppx_jane)))

bench/jbuild

-6
This file was deleted.

dune-project

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(lang dune 1.5)

example/bench/dune

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(library (name hardcaml_examples_bench)
2+
(libraries hardcaml hardcaml_examples hardcaml_examples_tests)
3+
(preprocess (pps ppx_jane)))

example/bench/jbuild

-8
This file was deleted.

example/src/dune

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(library (name hardcaml_examples) (libraries hardcaml)
2+
(preprocess (pps ppx_deriving_hardcaml ppx_jane)))

example/src/jbuild

-6
This file was deleted.

example/test/dune

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(library (name hardcaml_examples_tests)
2+
(libraries base expect_test_helpers_kernel hardcaml hardcaml_examples
3+
hardcaml_step_testbench hardcaml_waveterm stdio)
4+
(preprocess (pps ppx_jane)))

example/test/jbuild

-12
This file was deleted.

hardcaml.opam

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
1-
opam-version: "1.2"
1+
opam-version: "2.0"
22
maintainer: "[email protected]"
33
authors: ["Jane Street Group, LLC <[email protected]>"]
44
homepage: "https://github.com/janestreet/hardcaml"
55
bug-reports: "https://github.com/janestreet/hardcaml/issues"
66
dev-repo: "git+https://github.com/janestreet/hardcaml.git"
7+
doc: "https://ocaml.janestreet.com/ocaml-core/latest/doc/hardcaml/index.html"
78
license: "MIT"
89
build: [
9-
["jbuilder" "build" "-p" name "-j" jobs]
10+
["dune" "build" "-p" name "-j" jobs]
1011
]
1112
depends: [
13+
"ocaml" {>= "4.07.0"}
1214
"base"
1315
"ppx_jane"
1416
"stdio"
1517
"topological_sort"
16-
"jbuilder" {build & >= "1.0+beta18.1"}
17-
"ocaml-migrate-parsetree" {>= "1.0"}
18-
"ppxlib" {>= "0.1.0"}
19-
"zarith" {>= "1.4"}
18+
"dune" {build & >= "1.5.1"}
19+
"zarith" {>= "1.5"}
2020
]
21-
available: [ ocaml-version >= "4.06.1" ]
22-
descr: "
23-
RTL Hardware Design in OCaml.
24-
21+
synopsis: "RTL Hardware Design in OCaml"
22+
description: "
2523
Hardcaml is an embedded DSL for designing and simulating hardware in OCaml.
2624
Generic hardware designs are easily expressed using features such as higher
2725
order functions, lists, maps etc. A built in simulator allows designs to

js/dune

Whitespace-only changes.

js/jbuild

-8
This file was deleted.

src/dune

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(library (name hardcaml) (public_name hardcaml) (c_names bits_stubs)
2+
(preprocess (pps ppx_jane -dont-check-doc-comments-attachment))
3+
(libraries base bigarray dynlink stdio topological_sort unix zarith))

src/interface.ml

+67-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,64 @@ module Create_fn (I : S) (O : S) = struct
1212
~outputs:(O.t : (string * int) O.t)]
1313
end
1414

15+
module Ast = struct
16+
module rec Ast : sig
17+
type t = Field.t list
18+
[@@deriving sexp_of]
19+
end = struct
20+
type t = Field.t list
21+
[@@deriving sexp_of]
22+
end
23+
and Field : sig
24+
type t =
25+
{ name : string
26+
; type_ : Type.t
27+
; sequence : Sequence.t option
28+
; doc : string option }
29+
[@@deriving sexp_of]
30+
end = struct
31+
type t =
32+
{ name : string
33+
; type_ : Type.t
34+
; sequence : Sequence.t option
35+
; doc : string option }
36+
[@@deriving sexp_of]
37+
end
38+
and Type : sig
39+
type t =
40+
| Signal of { bits : int; rtlname : string }
41+
| Module of { name : string; ast : Ast.t }
42+
[@@deriving sexp_of]
43+
end = struct
44+
type t =
45+
| Signal of { bits : int; rtlname : string }
46+
| Module of { name : string; ast : Ast.t }
47+
[@@deriving sexp_of]
48+
end
49+
and Sequence : sig
50+
module Kind : sig
51+
type t = Array | List
52+
[@@deriving sexp_of]
53+
end
54+
type t =
55+
{ kind : Kind.t
56+
; length : int }
57+
[@@deriving sexp_of]
58+
end = struct
59+
module Kind = struct
60+
type t = Array | List
61+
[@@deriving sexp_of]
62+
end
63+
type t =
64+
{ kind : Kind.t
65+
; length : int }
66+
[@@deriving sexp_of]
67+
end
68+
69+
type t = Ast.t
70+
[@@deriving sexp_of]
71+
end
72+
1573
module Make (X : Pre) : S with type 'a t := 'a X.t = struct
1674

1775
include X
@@ -158,10 +216,15 @@ module Empty = struct
158216
include Make (struct
159217
type nonrec 'a t = 'a t [@@deriving sexp_of]
160218
let t = None
161-
let iter ~f:_ _ = ()
162-
let iter2 ~f:_ _ _ = ()
163-
let map ~f:_ _ = None
164-
let map2 ~f:_ _ _ = None
219+
let iter _ ~f:_ = ()
220+
let iter2 _ _ ~f:_ = ()
221+
let map _ ~f:_ = None
222+
let map2 _ _ ~f:_ = None
165223
let to_list _ = []
166224
end)
167225
end
226+
227+
module type S_with_ast = sig
228+
include S
229+
val ast : Ast.t
230+
end

src/interface_intf.ml

+60-5
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,62 @@ module type Pre = sig
1818
[@@deriving sexp_of]
1919

2020
val t : (string * int) t
21-
val iter : f:('a -> unit) -> 'a t -> unit
22-
val iter2 : f:('a -> 'b -> unit) -> 'a t -> 'b t -> unit
23-
val map : f:('a -> 'b) -> 'a t -> 'b t
24-
val map2 : f:('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
21+
val iter : 'a t -> f:('a -> unit) -> unit
22+
val iter2 : 'a t -> 'b t -> f:('a -> 'b -> unit) -> unit
23+
val map : 'a t -> f:('a -> 'b) -> 'b t
24+
val map2 : 'a t -> 'b t -> f:('a -> 'b -> 'c) -> 'c t
2525
val to_list : 'a t -> 'a list
2626
end
2727

28+
module type Ast = sig
29+
(** The PPX can optionally generate an [ast] field containing an [Ast.t]. This
30+
represents the structure of the interface, including how it is constructed from
31+
fields, arrays, lists and sub-modules.
32+
33+
This is of particular use when generating further code from the interface i.e. a
34+
register interace specification.
35+
36+
[ast]s are not generated by default. *)
37+
module rec Ast : sig
38+
type t = Field.t list
39+
[@@deriving sexp_of]
40+
end
41+
and Field : sig
42+
type t =
43+
{ name : string
44+
(** Name of the field *)
45+
; type_ : Type.t
46+
(** Field type - a signal or a sub-module *)
47+
; sequence : Sequence.t option
48+
(** Is the field type an array or list? *)
49+
; doc : string option
50+
(** Ocaml documentation string, if any. Note that this must be placed in the [ml]
51+
and not [mli].*)
52+
}
53+
[@@deriving sexp_of]
54+
end
55+
and Type : sig
56+
type t =
57+
| Signal of { bits : int; rtlname : string }
58+
| Module of { name : string; ast : Ast.t }
59+
[@@deriving sexp_of]
60+
end
61+
and Sequence : sig
62+
module Kind : sig
63+
type t = Array | List
64+
[@@deriving sexp_of]
65+
end
66+
67+
type t =
68+
{ kind : Kind.t
69+
; length : int }
70+
[@@deriving sexp_of]
71+
end
72+
73+
type t = Ast.t
74+
[@@deriving sexp_of]
75+
end
76+
2877
module type Comb = sig
2978

3079
type 'a interface
@@ -170,14 +219,20 @@ end
170219

171220
module type Interface = sig
172221

173-
174222
module type Pre = Pre
175223
module type S = S
224+
module type Ast = Ast
176225

177226
module type Empty = Empty
178227

228+
module Ast : Ast
179229
module Empty : Empty
180230

231+
module type S_with_ast = sig
232+
include S
233+
val ast : Ast.t
234+
end
235+
181236
(** Type of functions representing the implementation of a circuit from an input to
182237
output interface. *)
183238
module Create_fn (I : S) (O : S) : sig

src/jbuild

-14
This file was deleted.

src/recipe.ml

+20-20
Original file line numberDiff line numberDiff line change
@@ -180,50 +180,50 @@ end
180180
module SVar = Same (struct
181181
type 'a t = 'a [@@deriving sexp_of]
182182
let t = "var", 0
183-
let iter ~f a = f a
184-
let iter2 ~f a b = f a b
185-
let map ~f a = f a
186-
let map2 ~f a b = f a b
183+
let iter a ~f = f a
184+
let iter2 a b ~f = f a b
185+
let map a ~f = f a
186+
let map2 a b ~f = f a b
187187
let to_list a = [ a ]
188188
end)
189189

190190
(* not so sure these are particularly useful; interfaces can do the job better *)
191191
module SList = Same (struct
192192
type 'a t = 'a list [@@deriving sexp_of]
193193
let t = []
194-
let iter ~f l = List.iter l ~f
195-
let iter2 ~f l0 l1 = List.iter2_exn l0 l1 ~f
196-
let map ~f l = List.map l ~f
197-
let map2 ~f l0 l1 = List.map2_exn l0 l1 ~f
194+
let iter l ~f = List.iter l ~f
195+
let iter2 l0 l1 ~f = List.iter2_exn l0 l1 ~f
196+
let map l ~f = List.map l ~f
197+
let map2 l0 l1 ~f = List.map2_exn l0 l1 ~f
198198
let to_list a = a
199199
end)
200200

201201
module SArray = Same (struct
202202
type 'a t = 'a array [@@deriving sexp_of]
203203
let t = [||]
204-
let iter ~f t = Array.iter t ~f
205-
let iter2 ~f t1 t2 = Array.iter2_exn t1 t2 ~f
206-
let map ~f a = Array.map a ~f
207-
let map2 ~f a b = Array.init (Array.length a) ~f:(fun i -> f a.(i) b.(i))
204+
let iter t ~f = Array.iter t ~f
205+
let iter2 t1 t2 ~f = Array.iter2_exn t1 t2 ~f
206+
let map a ~f = Array.map a ~f
207+
let map2 a b ~f = Array.init (Array.length a) ~f:(fun i -> f a.(i) b.(i))
208208
let to_list = Array.to_list
209209
end)
210210

211211
module STuple2 = Same (struct
212212
type 'a t = 'a * 'a [@@deriving sexp_of]
213213
let t = ("a", 0), ("b", 0)
214-
let iter ~f (a, b) = f a; f b
215-
let iter2 ~f (a, b) (c, d) = f a c; f b d
216-
let map ~f (a, b) = (f a, f b)
217-
let map2 ~f (a, b) (c, d) = (f a c, f b d)
214+
let iter (a, b) ~f = f a; f b
215+
let iter2 (a, b) (c, d) ~f = f a c; f b d
216+
let map (a, b) ~f = (f a, f b)
217+
let map2 (a, b) (c, d) ~f = (f a c, f b d)
218218
let to_list (a, b) = [ a; b ]
219219
end)
220220

221221
module STuple3 = Same (struct
222222
type 'a t = 'a * 'a * 'a [@@deriving sexp_of]
223223
let t = ("a", 0), ("b", 0), ("c", 0)
224-
let iter ~f (a, b, c) = f a; f b; f c
225-
let iter2 ~f:f' (a, b, c) (d, e, f) = f' a d; f' b e; f' c f
226-
let map ~f (a, b, c) = (f a, f b, f c)
227-
let map2 ~f:f' (a, b, c) (d, e, f) = (f' a d, f' b e, f' c f)
224+
let iter (a, b, c) ~f = f a; f b; f c
225+
let iter2 (a, b, c) (d, e, f) ~f:fn = fn a d; fn b e; fn c f
226+
let map (a, b, c) ~f = (f a, f b, f c)
227+
let map2 (a, b, c) (d, e, f) ~f:fn = (fn a d, fn b e, fn c f)
228228
let to_list (a, b, c) = [ a; b; c ]
229229
end)

0 commit comments

Comments
 (0)