Types

piplin.protocols/typeof

[this]

Return type obj for this obj.

piplin.core/kindof

[a]

piplin.core/anontype

[kind]

Returns an anonymous type of the given kind. Useful to promote to jvm types.

piplin.core/cast

[type expr]

Converts the given expr to the given type. If the expr is immediate, this returns the same thing as (promote type expr). If the expr is a runtime value, this returns an astfrag.

Modules

piplin.core/modulize

[computation state] [module-name computation state]

piplin.core/compile-root

[module   inputs]

piplin.core/input

[name type]

Simulation

piplin.core/sim

[compiled-module cycles]

piplin.core/spit-trace

[path trace]

Writes the trace to the file with the given name (path is a String)

piplin.core/trace->gtkwave

[trace]

Opens the given trace in GTKWave

Verilog

piplin.core/->verilog

[compiled-module outputs]

piplin.core/verify

[module cycles]

Bits

piplin.core/bits

[n]

Make a new bits type object.

piplin.core/bit-width-of

Takes a type and returns the number of bits needed to represent that type

piplin.core/serialize

[expr]

Gets the bits representation of its argument. Supports AST frags.

piplin.core/deserialize

[type bits]

Takes a type and bits, and converts the bits to the given type.

piplin.core/bit-cat

[] [bs] [b1 b2] [b1 b2   more]

piplin.core/bit-slice

[expr low high]

Takes an expr of type bits and returns a subrange of the bits.

piplin.core/bit-and

piplin.core/bit-or

piplin.core/bit-xor

piplin.core/bit-not

piplin.core/bit-shift-left

piplin.core/bit-shift-right

Boolean Logic/Equality

piplin.core/=

= is a very common function. It must be implemented explicitly (rather than using the def-binary-binop function) in order to explicitly check whether they’re both not ASTNodes, and if so to delegate to Clojure’s =. This is because not every object subject to = participates in the piplin typesystem, whereas all numbers do participate, so this isn’t an issue for >, <, <=, >=, etc.

piplin.core/not=

[x] [x y] [x y   more]

piplin.core/and

[] [x] [x y] [x y   more]

piplin.core/or

[] [x] [x y] [x y   more]

piplin.core/not

[x]

not is important to implement ;-)

Conditionals

piplin.core/mux2

[sel v1 v2]

piplin.core/cond

[  more]

piplin.core/condp

[pred expr   clauses]

Math Ops

piplin.core/+

piplin.core/-

piplin.core/*

piplin.core/inc

[x]

Increments x

piplin.core/dec

[x]

Decrements x

piplin.core/<

piplin.core/<=

piplin.core/>

piplin.core/>=

piplin.core/zero?

[x]

Returns true if x is 0

piplin.core/pos?

[x]

Returns true if x is positive

piplin.core/neg?

[x]

Returns true if x is negative

Numeric Types

piplin.core/uintm

[n]

Makes a new uintm type object with the given number of bits.

piplin.core/sints

[n]

Makes a new sints type object with the given number of bits.

piplin.core/sign-extend

[width' num]

Takes an sints and a longer width and sign-extends the sints.

piplin.core/sfxpts

[i f]

Makes a new sfxpts type object with i integer bits and f fractional bits.

piplin.core/complex

[real imag]

Makes a new complex number type with the real part having type real and the imaginary part having type imag. real and imag must support addition, subtraction, and multiplication.

piplin.core/real-part

[complex]

Returns the real part of a complex number.

piplin.core/imag-part

[complex]

Returns the real part of a complex number.

Arrays

piplin.core/array

[type length]

piplin.core/store

[array write-enable index v] [a we i v   more]

clojure.core/assoc

[map key val] [map key val   kvs]

associate. When applied to a map, returns a new map of the same (hashed/sorted) type, that contains the mapping of key(s) to val(s). When applied to a vector, returns a new vector that contains val at index. Note - index must be <= (count vector).

clojure.core/get

[map key] [map key not-found]

Returns the value mapped to key, not-found or nil if key not present.

Bundles

piplin.core/bundle

[schema]

Takes a map of keys to types and returns a bundle type with that schema.

clojure.core/assoc

[map key val] [map key val   kvs]

associate. When applied to a map, returns a new map of the same (hashed/sorted) type, that contains the mapping of key(s) to val(s). When applied to a vector, returns a new vector that contains val at index. Note - index must be <= (count vector).

clojure.core/update-in

[m [k   ks] f   args]

‘Updates’ a value in a nested associative structure, where ks is a sequence of keys and f is a function that will take the old value and any supplied args and return the new value, and returns a new nested structure. If any levels do not exist, hash-maps will be created.

clojure.core/get

[map key] [map key not-found]

Returns the value mapped to key, not-found or nil if key not present.

Enums and Unions

piplin.core/enum

[coll   more]

Takes a collection of keywords or a map of keywords to bits and returns it as an enum type.

piplin.core/union

[schema   backing-enum]

Takes a map of keywords to types and an optional enum and returns a tagged union type whose keys are elements of the given enum or the default enum of the map’s keys.

piplin.core/union-match

[u   clauses]

Takes a union u and a clause for each key in the schema. Clauses are of the form:

  (:key binding ...)

where :key is the keyword, binding is the form that the value is bound to, and … is an implicit do within a cond-like form.

You can use any destructuring syntax as the binding form.

Other

piplin.core/log2

[v]

Log base 2

piplin.types/uninst

[pipinst]

Takes a pipinst and makes it into an AST frag