5
5
//! source maps).
6
6
7
7
use super :: prelude:: * ;
8
- use crate :: resugarings:: BinOp ;
9
-
10
- mod binops {
11
- pub use crate :: names:: rust_primitives:: hax:: machine_int:: { add, div, mul, rem, shr, sub} ;
12
- pub use crate :: names:: rust_primitives:: hax:: { logical_op_and, logical_op_or} ;
13
- }
8
+ use crate :: resugarings;
14
9
15
10
/// The Lean printer
16
11
#[ derive( Default ) ]
@@ -19,16 +14,7 @@ impl_doc_allocator_for!(LeanPrinter);
19
14
20
15
impl Printer for LeanPrinter {
21
16
fn resugaring_phases ( ) -> Vec < Box < dyn Resugaring > > {
22
- vec ! [ Box :: new( BinOp :: new( & [
23
- binops:: add( ) ,
24
- binops:: sub( ) ,
25
- binops:: mul( ) ,
26
- binops:: rem( ) ,
27
- binops:: div( ) ,
28
- binops:: shr( ) ,
29
- binops:: logical_op_and( ) ,
30
- binops:: logical_op_or( ) ,
31
- ] ) ) ]
17
+ vec ! [ Box :: new( resugarings:: FunctionApplications ) ]
32
18
}
33
19
34
20
const NAME : & str = "Lean" ;
@@ -155,25 +141,7 @@ set_option linter.unusedVariables false
155
141
unreachable ! ( )
156
142
}
157
143
}
158
- ExprKind :: App {
159
- head,
160
- args,
161
- generic_args,
162
- bounds_impls : _,
163
- trait_ : _,
164
- } => {
165
- let generic_args = ( !generic_args. is_empty ( ) ) . then_some (
166
- docs ! [
167
- line!( ) ,
168
- self . intersperse( generic_args, line!( ) ) . nest( INDENT )
169
- ]
170
- . group ( ) ,
171
- ) ;
172
- let args = ( !args. is_empty ( ) ) . then_some (
173
- docs ! [ line!( ) , intersperse!( args, line!( ) ) . nest( INDENT ) ] . group ( ) ,
174
- ) ;
175
- docs ! [ "← " , head, generic_args, args] . parens ( ) . group ( )
176
- }
144
+ ExprKind :: App { .. } => unreachable ! ( "See resugaring [FunctionApplications]" ) ,
177
145
ExprKind :: Literal ( literal) => docs ! [ literal] ,
178
146
ExprKind :: Array ( exprs) => {
179
147
docs ! [ "#v[" , intersperse!( exprs, reflow!( ", " ) ) . nest( INDENT ) ] . group ( )
@@ -254,38 +222,49 @@ set_option linter.unusedVariables false
254
222
resugared_expr_kind : & ' b ResugaredExprKind ,
255
223
) -> DocBuilder < ' a , Self , A > {
256
224
match resugared_expr_kind {
257
- ResugaredExprKind :: BinOp {
258
- op,
259
- lhs,
260
- rhs,
261
- generic_args : _,
225
+ ResugaredExprKind :: FunApp {
226
+ app,
227
+ head,
228
+ generic_args,
262
229
bounds_impls : _,
263
230
trait_ : _,
264
- } => {
265
- let symbol = if op == & binops:: add ( ) {
266
- "+?"
267
- } else if op == & binops:: sub ( ) {
268
- "-?"
269
- } else if op == & binops:: mul ( ) {
270
- "*?"
271
- } else if op == & binops:: div ( ) {
272
- "/?"
273
- } else if op == & binops:: rem ( ) {
274
- "%?"
275
- } else if op == & binops:: shr ( ) {
276
- ">>>?"
277
- } else if op == & binops:: logical_op_and ( ) {
278
- "&&"
279
- } else if op == & binops:: logical_op_or ( ) {
280
- "||"
281
- } else {
282
- unreachable ! ( )
283
- } ;
284
- docs ! [ "← " , lhs, softline!( ) , symbol, softline!( ) , rhs]
285
- . group ( )
286
- . parens ( )
231
+ } => match app {
232
+ FunApp :: Binary ( op, [ lhs, rhs] ) => {
233
+ let op = match op {
234
+ BinaryName :: Add => "+?" ,
235
+ BinaryName :: Sub => "-?" ,
236
+ BinaryName :: Mul => "*?" ,
237
+ BinaryName :: Rem => "%?" ,
238
+ BinaryName :: Div => "/?" ,
239
+ BinaryName :: Shr => ">>>?" ,
240
+ BinaryName :: Shl => "<<<?" ,
241
+ BinaryName :: LogicalAnd => "&&" ,
242
+ BinaryName :: LogicalOr => "||" ,
243
+ } ;
244
+ // This monad lifting should be handled by a phase/resugaring, see
245
+ // https://github.com/cryspen/hax/issues/1620
246
+ Some (
247
+ docs ! [ "← " , lhs, softline!( ) , op, softline!( ) , rhs]
248
+ . group ( )
249
+ . parens ( ) ,
250
+ )
251
+ }
252
+ _ => None ,
287
253
}
288
- _ => todo ! ( ) ,
254
+ . unwrap_or_else ( || {
255
+ let args = app. args ( ) ;
256
+ let generic_args = ( !generic_args. is_empty ( ) ) . then_some (
257
+ docs ! [
258
+ line!( ) ,
259
+ self . intersperse( generic_args, line!( ) ) . nest( INDENT )
260
+ ]
261
+ . group ( ) ,
262
+ ) ;
263
+ let args = ( !args. is_empty ( ) ) . then_some (
264
+ docs ! [ line!( ) , intersperse!( args, line!( ) ) . nest( INDENT ) ] . group ( ) ,
265
+ ) ;
266
+ docs ! [ "← " , head, generic_args, args] . parens ( ) . group ( )
267
+ } ) ,
289
268
}
290
269
}
291
270
0 commit comments