@@ -7,6 +7,7 @@ use std::fmt::Debug;
7
7
use std:: slice:: SliceIndex ;
8
8
use std:: sync:: Arc ;
9
9
10
+ use super :: semantics:: LocalExprs ;
10
11
use crate :: core:: semantics:: { self , ArcValue , Elim , Head , LazyValue , Value } ;
11
12
use crate :: core:: { Const , Item , Module , Prim , Term , UIntStyle } ;
12
13
use crate :: env:: { EnvLen , SharedEnv , UniqueEnv } ;
@@ -254,8 +255,8 @@ impl fmt::Display for BufferError {
254
255
impl std:: error:: Error for BufferError { }
255
256
256
257
pub struct Context < ' arena , ' data > {
257
- item_exprs : UniqueEnv < ArcValue < ' arena > > ,
258
- local_exprs : SharedEnv < ArcValue < ' arena > > ,
258
+ item_exprs : UniqueEnv < LazyValue < ' arena > > ,
259
+ local_exprs : LocalExprs < ' arena > ,
259
260
initial_buffer : Buffer < ' data > ,
260
261
pending_formats : Vec < ( usize , ArcValue < ' arena > ) > ,
261
262
cached_refs : HashMap < usize , Vec < ParsedRef < ' arena > > > ,
@@ -295,7 +296,7 @@ impl<'arena, 'data> Context<'arena, 'data> {
295
296
for item in module. items {
296
297
match item {
297
298
Item :: Def { expr, .. } => {
298
- let expr = self . eval_env ( ) . eval ( expr) ;
299
+ let expr = self . eval_env ( ) . delay ( expr) ;
299
300
self . item_exprs . push ( expr) ;
300
301
}
301
302
}
@@ -332,8 +333,8 @@ impl<'arena, 'data> Context<'arena, 'data> {
332
333
let mut exprs = Vec :: with_capacity ( formats. len ( ) ) ;
333
334
334
335
while let Some ( ( format, next_formats) ) = self . elim_env ( ) . split_telescope ( formats) {
335
- let expr = self . read_format ( reader, & format) ?;
336
- exprs. push ( LazyValue :: eager ( expr. clone ( ) ) ) ;
336
+ let expr = LazyValue :: eager ( self . read_format ( reader, & format) ?) ;
337
+ exprs. push ( expr. clone ( ) ) ;
337
338
formats = next_formats ( expr) ;
338
339
}
339
340
@@ -344,7 +345,9 @@ impl<'arena, 'data> Context<'arena, 'data> {
344
345
}
345
346
Value :: FormatCond ( _label, format, cond) => {
346
347
let value = self . read_format ( reader, & self . elim_env ( ) . force_lazy ( format) ) ?;
347
- let cond_res = self . elim_env ( ) . apply_closure ( cond, value. clone ( ) ) ;
348
+ let cond_res = self
349
+ . elim_env ( )
350
+ . apply_closure ( cond, LazyValue :: eager ( value. clone ( ) ) ) ;
348
351
349
352
match cond_res. as_ref ( ) {
350
353
Value :: ConstLit ( Const :: Bool ( true ) ) => Ok ( value) ,
@@ -366,8 +369,8 @@ impl<'arena, 'data> Context<'arena, 'data> {
366
369
while let Some ( ( format, next_formats) ) = self . elim_env ( ) . split_telescope ( formats) {
367
370
let mut reader = reader. clone ( ) ;
368
371
369
- let expr = self . read_format ( & mut reader, & format) ?;
370
- exprs. push ( LazyValue :: eager ( expr. clone ( ) ) ) ;
372
+ let expr = LazyValue :: eager ( self . read_format ( & mut reader, & format) ?) ;
373
+ exprs. push ( expr. clone ( ) ) ;
371
374
formats = next_formats ( expr) ;
372
375
373
376
max_relative_offset =
0 commit comments