Skip to content
Open
Show file tree
Hide file tree
Changes from 82 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
2c27a5d
Initial, hacky work on computing wrapper interface method types using…
krame505 Aug 1, 2024
5dd5a7f
Attempt at attachting port names with a primative on every input. Do…
krame505 Aug 8, 2024
dc8fa7f
Pass the input port names by tagging methods with a new primative
krame505 Aug 10, 2024
4130371
Refactor WrapMethod type class
krame505 Aug 10, 2024
fbee672
Input port splitting works end-to-end, modulo sanity checks and savin…
krame505 Aug 13, 2024
4615c55
Handle prefix for input port names via wrap typeclasses
krame505 Aug 13, 2024
aaf9e9a
Saving port types using WrapField type class method
krame505 Aug 13, 2024
0cad646
Bug fixes
krame505 Aug 13, 2024
ded14c2
Use WrapField to determine noinline foreign function types
krame505 Aug 14, 2024
3fbc8f2
Cleanup, add DeepSplitPorts type class
krame505 Aug 14, 2024
8cb4473
Add primMethod wrapper prim calls in vMkRWire1
krame505 Aug 15, 2024
7f2e12e
Update expected test output
krame505 Aug 15, 2024
d095b93
Re-add module arg port type saving, still need to do port name confli…
krame505 Aug 15, 2024
3b8b9b5
Fix saving Inout port types
krame505 Aug 15, 2024
2c26339
Update test expected output
krame505 Aug 15, 2024
7fc11e9
Update expected test output
krame505 Aug 15, 2024
46fd375
Fix prefix computation in genwrap 'to' function and port saving state…
krame505 Aug 16, 2024
9ad861d
Fix inadvertantly disabled type check for foreign functions
krame505 Aug 16, 2024
46bfafe
Add interface port name sanity checking after elaboration
krame505 Aug 17, 2024
6b93528
Fix bug introduced in computing split vector interface prefixes
krame505 Aug 17, 2024
8dd9823
Add sketch of splitting tuples
krame505 Aug 17, 2024
cb79bd6
Check for clash with default clock/reset ports
krame505 Aug 17, 2024
d1c5c58
Better error message for synthesizing an interface with a non-Bits me…
krame505 Aug 17, 2024
230e32f
Cleanup trailing whitespace
krame505 Aug 17, 2024
7f75867
Update expected results, testsuite passing
krame505 Aug 17, 2024
ec8d4b0
Reorganize port splitting utilites into a seperate library, add Shall…
krame505 Aug 17, 2024
200f6f7
More efficient implementation of splitting vectors
krame505 Aug 19, 2024
d78f6e4
Avoid extra _1 suffix for DeepSplitPorts on Int/UInt
krame505 Aug 19, 2024
2522a87
Add test cases for port splitting
krame505 Aug 19, 2024
a92ccb8
Add test of DeepSplitPorts with an explicit non-recursive instance
krame505 Aug 20, 2024
dfdfd18
Fix NoSplit instance
krame505 Aug 20, 2024
8524579
Add a comment
krame505 Aug 20, 2024
5543a7a
Stuff the field name in the WrapField type class as a type parameter …
krame505 Aug 20, 2024
8fbca9f
Fix trailing whitespace
krame505 Aug 20, 2024
84e9697
Addressing Ravi's comments
krame505 Aug 20, 2024
5e04b7d
Fix more comments
krame505 Aug 21, 2024
57c5824
Fix testsuite failure after error message tweak
krame505 Aug 22, 2024
35fd767
Record the full field name path in WrapField context, for better erro…
krame505 Aug 22, 2024
a4873ac
Don't surface implicit conditions from inside ICMethod
krame505 Aug 22, 2024
4f585a0
FIx trailing whitespace
krame505 Aug 23, 2024
ad67afd
Slightly less gross list deconstruction in IExpand
krame505 Aug 23, 2024
a7da176
Add more tests
krame505 Aug 23, 2024
244c703
Updated expected output for tests
nanavati Dec 19, 2024
364ce69
Stop including explicit indices in the string type argument to the Wr…
nanavati Sep 9, 2025
ede3091
Update position in expected error output.
nanavati Sep 10, 2025
b94b991
Clean up exports
krame505 Jan 21, 2025
6d23a48
Update expected test result
krame505 Nov 17, 2025
d971a02
Better position for error when wrong number of ports are returned by …
krame505 Nov 17, 2025
addfcbf
Include nolinline pragma in pPrint of Cforeign
krame505 Nov 18, 2025
008eb53
Make mkList take a Position argument
krame505 Nov 18, 2025
3987cac
Remove idPreludeCons, qualify idCons and idNil
krame505 Nov 18, 2025
9a05841
Add missing newline
krame505 Nov 18, 2025
e4d82ad
Avoid treating (a, ()) as a tuple of size 1
krame505 Nov 18, 2025
7cac8f4
Remove unused fsConcat
krame505 Nov 19, 2025
734e740
Remove outdated comment
krame505 Nov 19, 2025
db02f57
mkProxy -> mkTypeProxyExpr
krame505 Nov 19, 2025
b6d066b
Add util to unwrap a Port value
krame505 Nov 19, 2025
1448c16
Avoid stringHead of an empty string
krame505 Nov 19, 2025
c13b8b2
Fix error in NFData CDefn instance from rebasing
krame505 Dec 10, 2025
48f8f4b
Fix to avoid extra _ in deepSplitPortNames/shallowSplitPortNames when…
krame505 Jan 6, 2026
63fdebf
Update expected heap number in test
quark17 Jan 10, 2026
2bb6215
Tweak to TupleSize instance
krame505 Jan 12, 2026
ff61190
Add comments about DeepSplitPorts Int/UInt instances
krame505 Jan 12, 2026
2bcf7d4
Change pPrint for Cforeign to match pvPrint
krame505 Jan 12, 2026
f4fb885
Renaming PreIds ids
krame505 Jan 12, 2026
bfd96ce
Add missing final newline
krame505 Jan 12, 2026
7fc664d
Add comment on test for vector interface instance dicts combining
krame505 Jan 12, 2026
589f806
Revert error code being checked for noinline type-not-in-bits tests
krame505 Jan 12, 2026
e9dbbce
Eliminate EStringListNF
krame505 Jan 12, 2026
c4246ad
Check for too many arg_names supplied for a method
krame505 Jan 13, 2026
0dbb7fa
Add comments in GenWrap
krame505 Jan 13, 2026
ca5c308
Improve error message when a synthesized method or noinline function …
krame505 Jan 14, 2026
06d3552
Add docs for new tuple utilites (mostly written by Claude)
krame505 Jan 14, 2026
bbcfc56
Add test cases for tuple utilites (generated by Claude)
krame505 Jan 14, 2026
0864b75
Pass the current module name into handleContextReduction for better e…
krame505 Jan 14, 2026
194544d
Simplify vMkRWire1, rename to __mkRWireSubmodule, expand the comment
quark17 Jan 14, 2026
60df15d
Testsuite: Update expected PreludeBSV positions
quark17 Jan 14, 2026
fba6a10
Revert id_to_vName change
quark17 Jan 14, 2026
e336086
Clean up documentation
krame505 Jan 15, 2026
8418a29
Tests and docs for the Curry type class
krame505 Jan 15, 2026
fdbb48e
Misc cleanup
krame505 Jan 15, 2026
41ee7fc
Clean up tests
krame505 Jan 15, 2026
35c3713
Clean up uncurryN examples
krame505 Jan 16, 2026
fb52a66
Fix expected output
krame505 Jan 16, 2026
2de7074
Update order of defs in mkDesign.v.expected
krame505 Jan 20, 2026
3c855eb
Update location in ClockCheckCond error expected output, add a check …
krame505 Jan 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 147 additions & 0 deletions doc/libraries_ref_guide/LibDoc/Prelude.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3531,15 +3531,115 @@ \subsubsection{Tuples}
\end{tabular}
\end{center}

\te{TupleSize} provides a way to determine the number of elements in a tuple
at the type level. The size is represented as a numeric type parameter.

\index{TupleSize@\te{TupleSize} (type class)}
\index[typeclass]{TupleSize}

\begin{libverbatim}
typeclass TupleSize #(type a, numeric type n)
dependencies (a determines n);
endtypeclass
\end{libverbatim}

The type class has instances for unit type \te{void} with size 0, and for all
tuple types with their respective sizes. The numeric type \te{n} represents
the number of elements in the tuple.

\begin{center}
\begin{tabular}{|p{1.5 in}|p{3.8 in}|}
\hline
\multicolumn{2}{|c|}{\te{TupleSize} Instances}\\
\hline
\hline
\te{TupleSize \#(void, 0)}&The unit type has size 0.\\
\hline
\te{TupleSize \#(a, 1)}&A single element (non-tuple) has size 1.\\
\hline
\te{TupleSize \#((a, b), 2)}&A 2-tuple has size 2.\\
\hline
\te{TupleSize \#((a,b,c), 3)}&A 3-tuple has size 3.\\
\hline
\te{...}&Instances exist for all tuple sizes.\\
\hline
\end{tabular}
\end{center}

\te{AppendTuple} provides a way to join two tuples of arbitrary size into a single larger
tuple, and to split a tuple back into two parts.

\index{AppendTuple@\te{AppendTuple} (type class)}
\index{appendTuple@\texttt{appendTuple} (\texttt{AppendTuple} type class function)}
\index{splitTuple@\texttt{splitTuple} (\texttt{AppendTuple} type class function)}
\index[function]{Prelude!appendTuple}
\index[function]{Prelude!splitTuple}
\index[typeclass]{AppendTuple}

\begin{libverbatim}
typeclass AppendTuple #(type a, type b, type c)
dependencies ((a, b) determines c);
function c appendTuple(a x, b y);
function Tuple2#(a, b) splitTuple(c x);
endtypeclass
\end{libverbatim}

The type class has instances for various tuple combinations, including special
handling for unit type \te{void}.

\begin{center}
\begin{tabular}{|p{1.5 in}|p{3.8 in}|}
\hline
\multicolumn{2}{|c|}{\te{AppendTuple} Functions}\\
\hline
\hline
\te{appendTuple}&Concatenates two tuples \te{x} and \te{y} into a single
larger tuple. The elements from \te{x} appear first, followed by the elements
from \te{y}.\\
\cline{2-2}
&\\
& \te{function c appendTuple(a x, b y);}\\
&\\
\hline
\te{splitTuple}&Splits a tuple \te{x} into two parts. Returns a 2-tuple
containing the first part of type \te{a} and the second part of type \te{b}.\\
\cline{2-2}
&\\
& \te{function Tuple2\#(a, b) splitTuple(c x);}\\
&\\
\hline
\end{tabular}
\end{center}

{\bf Examples}

\begin{verbatim}
Tuple2#( Bool, int ) foo = tuple2( True, 25 );
Bool field1 = tpl_1( foo ); // this is value 1 in the list
int field2 = tpl_2( foo ); // this is value 2 in the list
foo = tuple2( !field1, field2 );

// Appending a 2-tuple and a 3-tuple to create a 5-tuple
Tuple2#(Bool, Int#(8)) t1 = tuple2(True, 42);
Tuple3#(String, Bit#(4), UInt#(16)) t2 = tuple3("test", 4'hA, 100);

Tuple5#(Bool, Int#(8), String, Bit#(4), UInt#(16)) t3 =
appendTuple(t1, t2);

// Splitting a 4-tuple into a 2-tuple and a 2-tuple
Tuple4#(Bool, Int#(8), String, Bit#(4)) t4 =
tuple4(True, 42, "test", 4'hA);

Tuple2#(Tuple2#(Bool, Int#(8)), Tuple2#(String, Bit#(4))) parts =
splitTuple(t4);

// Appending with unit type (void)
Tuple2#(Bool, Int#(8)) t5 = tuple2(False, 0);
Tuple2#(Bool, Int#(8)) t6 = appendTuple(t5, ?); // same as t5
Tuple2#(Bool, Int#(8)) t7 = appendTuple(?, t5); // same as t5
\end{verbatim}


% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\com{Array}
\subsubsection{Array}
Expand Down Expand Up @@ -6211,12 +6311,59 @@ \subsubsection{Operations on Functions}
\end{tabular}
\end{center}

\index{Curry@\te{Curry} (type class)}
\index[typeclass]{Curry}
\index{curryN@\te{curryN} (function)}
\index[function]{Prelude!curryN}
\index{uncurryN@\te{uncurryN} (function)}
\index[function]{Prelude!uncurryN}

The \te{Curry} typeclass generalizes the \te{curry} and \te{uncurry} functions
to work with tuples of any size (not just Tuple2).

\begin{libverbatim}
typeclass Curry#(type f, type g)
dependencies (f determines g);
function g curryN(f x);
function f uncurryN(g x);
endtypeclass
\end{libverbatim}

\begin{center}
\begin{tabular}{|p{1 in}|p{4 in}|}
\hline
\te{curryN}&Converts an uncurried function (taking an N-tuple argument) into a curried
function (taking N arguments one at a time). For example, \te{curryN} can convert a
function taking \te{Tuple3\#(a,b,c)} into a function \te{a -> b -> c -> result}.\\
\hline
\te{uncurryN}&The inverse of \te{curryN}. Converts a curried function (taking N arguments
one at a time) into an uncurried function (taking an N-tuple argument).\\
\hline
\end{tabular}
\end{center}


{\bf Examples}

\begin{libverbatim}
//using constFn to set the initial values of the registers in a list
List#(Reg#(Resource)) items <- mapM( constFn(mkReg(initRes)),upto(1,numAdd) );

// Using curryN with a 3-tuple
function Int#(32) add3Tuple(Tuple3#(Int#(32), Int#(32), Int#(32)) t);
return tpl_1(t) + tpl_2(t) + tpl_3(t);
endfunction

let add3Curried = curryN(add3Tuple);
Int#(32) result = add3Curried(1)(2)(3); // result = 6

// Using uncurryN
function Int#(32) add3(Int#(32) a, Int#(32) b, Int#(32) c);
return a + b + c;
endfunction

let add3Uncurried = uncurryN(add3);
Int#(32) result2 = add3Uncurried(tuple3(1, 2, 3)); // result2 = 6

return(pack(map(compose(head0,toList),state)));

Expand Down
111 changes: 110 additions & 1 deletion doc/libraries_ref_guide/LibDoc/Vector.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2273,15 +2273,124 @@ \subsubsection{Converting to and from Vectors}
\hline
\end{tabular}

The \te{ConcatTuple} type class provides functions to convert between a Vector
of tuples and a single flattened tuple. When you have a Vector where each
element is a tuple (or can be viewed as a tuple), \te{concatTuple} flattens
all the elements into one large tuple by concatenating them together. The
reverse operation, \te{unconcatTuple}, splits a large tuple back into a Vector
of smaller tuples.

\index{ConcatTuple@\te{ConcatTuple} (type class)}
\index{concatTuple@\texttt{concatTuple} (\texttt{ConcatTuple} type class function)}
\index{unconcatTuple@\texttt{unconcatTuple} (\texttt{ConcatTuple} type class function)}
\index[function]{Vector!concatTuple}
\index[function]{Vector!unconcatTuple}
\index[typeclass]{ConcatTuple}

{\bf Example - Converting to and from Vectors}
\begin{libverbatim}
typeclass ConcatTuple #(numeric type n, type a, type b)
dependencies ((n, a) determines b);
function b concatTuple(Vector#(n, a) v);
function Vector#(n, a) unconcatTuple(b x);
endtypeclass
\end{libverbatim}

The type class has instances for various vector sizes:
\begin{itemize}
\item A vector of size 0 converts to/from the unit type \te{void}
\item A vector of size 1 converts to/from a single element
\item Larger vectors convert by appending each element tuple to
form a larger tuple
\end{itemize}

\begin{tabular}{|p{1.2 in}|p{4.4 in}|}
\hline
\multicolumn{2}{|c|}{\te{ConcatTuple} Functions}\\
\hline
\hline
&\\ \te{concatTuple} & Flattens a Vector of tuples into a single large tuple
by concatenating all the tuple elements together. Each element of the vector
is appended sequentially to form the result tuple.\\
& \\ \cline{2-2}
&\begin{libverbatim}
function b concatTuple(Vector#(n, a) v);
\end{libverbatim}
\\
\hline
&\\ \te{unconcatTuple}&Splits a large tuple into a Vector of smaller tuples.
This is the inverse of \te{concatTuple}, distributing the tuple elements across
a Vector of the specified size.\\
& \\ \cline{2-2}
&\begin{libverbatim}
function Vector#(n, a) unconcatTuple(b x);
\end{libverbatim}
\\
\hline
\end{tabular}

{\bf Examples - Lists}

Convert the vector \te{my\_vector} to a list named \te{my\_list}.
\begin{libverbatim}
Vector#(5,Int#(13)) my_vector;
List#(Int#(13)) my_list = toList(my_vector);
\end{libverbatim}

{\bf Examples - Tuples}

Flatten a vector of 3 pairs (2-tuples) into a single 6-tuple:
\begin{libverbatim}
// Create a vector of three 2-tuples
Vector#(3, Tuple2#(Bool, Int#(8))) vec_of_pairs = vec(
tuple2(True, 1),
tuple2(False, 2),
tuple2(True, 3)
);

// Flatten into a single 6-tuple
Tuple6#(Bool, Int#(8), Bool, Int#(8), Bool, Int#(8)) flat =
concatTuple(vec_of_pairs);
// Result: (True, 1, False, 2, True, 3)

// Convert back to vector of pairs
Vector#(3, Tuple2#(Bool, Int#(8))) restored = unconcatTuple(flat);
\end{libverbatim}

Flatten a vector of 4 single elements (which can be viewed as 1-tuples) into a 4-tuple:
\begin{libverbatim}
Vector#(4, Int#(8)) vec_ints = vec(10, 20, 30, 40);

// Each Int#(8) is treated as a single element
Tuple4#(Int#(8), Int#(8), Int#(8), Int#(8)) tuple_ints =
concatTuple(vec_ints);
// Result: (10, 20, 30, 40)
\end{libverbatim}

Flatten a vector of 2 triples (3-tuples) into a single 6-tuple:
\begin{libverbatim}
Vector#(2, Tuple3#(Bool, UInt#(4), String)) vec_triples = vec(
tuple3(True, 5, "hello"),
tuple3(False, 10, "world")
);

Tuple6#(Bool, UInt#(4), String, Bool, UInt#(4), String) result =
concatTuple(vec_triples);
// Result: (True, 5, "hello", False, 10, "world")
\end{libverbatim}

Special cases:
\begin{libverbatim}
// Empty vector converts to unit type
Vector#(0, Tuple2#(Bool, Int#(8))) empty = nil;
void unit = concatTuple(empty);

// Single element vector returns just that element
Vector#(1, Tuple2#(Bool, Int#(8))) single =
vec(tuple2(True, 42));
Tuple2#(Bool, Int#(8)) pair = concatTuple(single);
// Result: (True, 42)
\end{libverbatim}


\subsubsection{ListN}

Expand Down
Loading
Loading