package ppx_hardcaml

  1. Overview
  2. Docs
PPX extension for HardCaml

Install

Dune Dependency

Authors

Maintainers

Sources

v1.1.0.tar.gz
sha256=f6eb3d01d2543edc1c16a3e63300a473b2cc1358bd11b6f14b3cfa18c3aa265d
md5=b8579a655eac7331f39b33e27bbfef02

Description

Tags

syntax

Published: 20 Dec 2016

README

README.org

#+TITLE: PPX rewriter for HardCaml
#+AUTHOR: Xavier Guerin

This module provides a ~PPX~ rewriter for some of [[https://github.com/ujamjar/hardcaml][HardCaml]] syntax:

- Enable the use of pervasive operator names to manipulate signals
- Reuse the 2D string indexing syntax for signal indexing

* Examples

** Operators

Original syntax:

#+BEGIN_SRC ocaml
let some_function a b =
  a &: b
#+END_SRC

Using the PPX rewriter:

#+BEGIN_SRC ocaml
let some_function a b =
  [%hw a land b]
#+END_SRC

Using the ~let%~ extension of the PPX rewriter:

#+BEGIN_SRC ocaml
let some_function a b =
  let%hw result = a land b in
  result
#+END_SRC

Signal in binary operations are also automatically resized using ~uresize~ to ~max a b~.

** Indexing

Original syntax:

#+BEGIN_SRC ocaml
let some_function a =
  a.[7:0]
#+END_SRC

Using the PPX rewriter:

#+BEGIN_SRC ocaml
let some_function a =
  [%hw a.[7,0]]
#+END_SRC

Using the expression ~let%~ extension of the PPX rewriter:

#+BEGIN_SRC ocaml
let some_function a =
  let%hw result = a.[7,0] in
  result
#+END_SRC

Using the structural ~let%~ extension of the PPX rewriter:

#+BEGIN_SRC ocaml
let%hw some_function a =
  a.[7,0]
#+END_SRC

* Hardware constants

Hardware constants can be built using the ~h~ integer constant suffix: ~0x17h~, ~32h~, ~0b0001000h~.

* Signed operations

Signed operations are accessible the ~[%hw.signed]~ extension.

* Implementation details

- The ~[%hw]~ extension is recursively applied to function calls, tuples, and lists
- When using the expression ~let%hw~ syntax, the extension is only applied to the value-binding part of the expression
- When using the structural ~let%hw~ syntax, the extension is recursively applied to all expressions

Dependencies (5)

  1. hardcaml >= "1.1.0" & < "2.0.0"
  2. ppx_tools
  3. ocamlfind build & >= "1.3.2"
  4. ocamlbuild build
  5. ocaml >= "4.03"

Dev Dependencies (1)

  1. ounit with-test

Used by

None

Conflicts

None

OCaml

Innovation. Community. Security.