Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
69 changes: 54 additions & 15 deletions doc/libraries_ref_guide/LibDoc/Prelude.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3531,17 +3531,6 @@ \subsubsection{Tuples}
\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 );
\end{verbatim}

\paragraph{TupleSize}

\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.

Expand Down Expand Up @@ -3577,8 +3566,6 @@ \subsubsection{Tuples}
\end{tabular}
\end{center}

\paragraph{AppendTuple}

\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.

Expand All @@ -3591,7 +3578,7 @@ \subsubsection{Tuples}

\begin{libverbatim}
typeclass AppendTuple #(type a, type b, type c)
dependencies (a b determines c);
dependencies ((a, b) determines c);
function c appendTuple(a x, b y);
function Tuple2#(a, b) splitTuple(c x);
endtypeclass
Expand Down Expand Up @@ -3627,6 +3614,11 @@ \subsubsection{Tuples}
{\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);
Expand All @@ -3641,7 +3633,7 @@ \subsubsection{Tuples}
Tuple2#(Tuple2#(Bool, Int#(8)), Tuple2#(String, Bit#(4))) parts =
splitTuple(t4);

// Appending with unit type
// 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
Expand Down Expand Up @@ -6319,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
25 changes: 11 additions & 14 deletions doc/libraries_ref_guide/LibDoc/Vector.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2273,8 +2273,6 @@ \subsubsection{Converting to and from Vectors}
\hline
\end{tabular}

\paragraph{ConcatTuple}

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
Expand All @@ -2291,7 +2289,7 @@ \subsubsection{Converting to and from Vectors}

\begin{libverbatim}
typeclass ConcatTuple #(numeric type n, type a, type b)
dependencies (n a determines b);
dependencies ((n, a) determines b);
function b concatTuple(Vector#(n, a) v);
function Vector#(n, a) unconcatTuple(b x);
endtypeclass
Expand All @@ -2301,7 +2299,7 @@ \subsubsection{Converting to and from Vectors}
\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 flattening: each element is appended to
\item Larger vectors convert by appending each element tuple to
form a larger tuple
\end{itemize}

Expand Down Expand Up @@ -2330,7 +2328,15 @@ \subsubsection{Converting to and from Vectors}
\hline
\end{tabular}

{\bf Example - ConcatTuple}
{\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}
Expand Down Expand Up @@ -2386,15 +2392,6 @@ \subsubsection{Converting to and from Vectors}
\end{libverbatim}


{\bf Example - Converting to and from Vectors}

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}


\subsubsection{ListN}

\index{ListN@\te{ListN} (type)}
Expand Down
129 changes: 129 additions & 0 deletions testsuite/bsc.lib/Prelude/CurryTypeClass.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
-----------------------------------------------------------------------
-- Test for the Curry type class and curryN/uncurryN functions
-----------------------------------------------------------------------

package CurryTypeClass where

import Vector

-----------------------------------------------------------------------
-- Test with Tuple2
-----------------------------------------------------------------------

add2Tuple :: (Int 32, Int 32) -> Int 32
add2Tuple t = tpl_1 t + tpl_2 t

add2 :: Int 32 -> Int 32 -> Int 32
add2 a b = a + b

testCurry2 :: Bool
testCurry2 =
let curried :: Int 32 -> Int 32 -> Int 32
curried = curryN add2Tuple
result1 :: Int 32
result1 = curried 5 10
uncurried :: (Int 32, Int 32) -> Int 32
uncurried = uncurryN add2
result2 :: Int 32
result2 = uncurried (5, 10)
in result1 == 15 && result2 == 15


-----------------------------------------------------------------------
-- Test with Tuple3
-----------------------------------------------------------------------

add3Tuple :: (Int 32, Int 32, Int 32) -> Int 32
add3Tuple t = tpl_1 t + tpl_2 t + tpl_3 t

add3 :: Int 32 -> Int 32 -> Int 32 -> Int 32
add3 a b c = a + b + c

testCurry3 :: Bool
testCurry3 =
let curried :: Int 32 -> Int 32 -> Int 32 -> Int 32
curried = curryN add3Tuple
result1 :: Int 32
result1 = curried 1 2 3
uncurried :: (Int 32, Int 32, Int 32) -> Int 32
uncurried = uncurryN add3
result2 :: Int 32
result2 = uncurried (1, 2, 3)
in result1 == 6 && result2 == 6


-----------------------------------------------------------------------
-- Test with Tuple4
-----------------------------------------------------------------------

add4Tuple :: (Int 32, Int 32, Int 32, Int 32) -> Int 32
add4Tuple t = tpl_1 t + tpl_2 t + tpl_3 t + tpl_4 t

add4 :: Int 32 -> Int 32 -> Int 32 -> Int 32 -> Int 32
add4 a b c d = a + b + c + d

testCurry4 :: Bool
testCurry4 =
let curried :: Int 32 -> Int 32 -> Int 32 -> Int 32 -> Int 32
curried = curryN add4Tuple
result1 :: Int 32
result1 = curried 1 2 3 4
uncurried :: (Int 32, Int 32, Int 32, Int 32) -> Int 32
uncurried = uncurryN add4
result2 :: Int 32
result2 = uncurried (1, 2, 3, 4)
in result1 == 10 && result2 == 10


-----------------------------------------------------------------------
-- Test roundtrip: curryN . uncurryN = id and uncurryN . curryN = id
-----------------------------------------------------------------------

testRoundtrip :: Bool
testRoundtrip =
-- Test that uncurrying then currying gets back the original behavior
let temp :: (Int 32, Int 32, Int 32) -> Int 32
temp = uncurryN add3
f1 :: Int 32 -> Int 32 -> Int 32 -> Int 32
f1 = curryN temp
result1 :: Int 32
result1 = f1 10 20 30
-- Test that currying then uncurrying gets back the original behavior
f2 :: (Int 32, Int 32, Int 32) -> Int 32
f2 = uncurryN (curryN add3Tuple)
result2 :: Int 32
result2 = f2 (10, 20, 30)
in result1 == 60 && result2 == 60


-----------------------------------------------------------------------
-- Test with unit tuple (special case)
-----------------------------------------------------------------------

fromUnitTuple :: () -> Int 32
fromUnitTuple _ = 42

testUnitTuple :: Bool
testUnitTuple =
let curried :: Int 32
curried = curryN fromUnitTuple
in curried == 42


-----------------------------------------------------------------------
-- Module for testing
-----------------------------------------------------------------------

{-# verilog sysCurryTypeClass #-}
sysCurryTypeClass :: Module Empty
sysCurryTypeClass =
module
rules
"test": when True ==>
action
$display "Test Curry2: %b" testCurry2
$display "Test Curry3: %b" testCurry3
$display "Test Curry4: %b" testCurry4
$display "Test Roundtrip: %b" testRoundtrip
$display "Test Unit Tuple: %b" testUnitTuple
$finish 0
1 change: 1 addition & 0 deletions testsuite/bsc.lib/Prelude/Prelude.exp
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ compile_verilog_fail_no_internal_error Eq3
test_c_veri_bs_modules TuplePack {}
test_c_veri_bs_modules TupleSize {}
test_c_veri_bs_modules AppendTuple {}
test_c_veri_bs_modules CurryTypeClass {}
5 changes: 5 additions & 0 deletions testsuite/bsc.lib/Prelude/sysCurryTypeClass.out.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Test Curry2: 1
Test Curry3: 1
Test Curry4: 1
Test Roundtrip: 1
Test Unit Tuple: 1
Loading