@@ -6,21 +6,22 @@ use crate::vm::Program;
6
6
use crate :: Error ;
7
7
use crate :: { Object , RefValue } ;
8
8
use indexmap:: { indexmap, IndexMap , IndexSet } ;
9
+ use log;
9
10
use std:: collections:: { HashMap , HashSet } ;
10
11
11
12
#[ derive( Debug ) ]
12
13
pub ( in crate :: compiler) struct ImlProgram {
14
+ main : ImlValue ,
13
15
statics : IndexMap < ImlValue , Option < Parselet > > , // static values with optional final parselet replacement
14
16
pub errors : Vec < Error > , // errors collected during finalization (at least these are unresolved symbols)
15
- pub debug : bool , // Debug
16
17
}
17
18
18
19
impl ImlProgram {
19
20
pub fn new ( main : ImlValue ) -> Self {
20
21
ImlProgram {
22
+ main : main. clone ( ) ,
21
23
statics : indexmap ! ( main => None ) ,
22
24
errors : Vec :: new ( ) ,
23
- debug : false ,
24
25
}
25
26
}
26
27
@@ -58,13 +59,21 @@ impl ImlProgram {
58
59
and nullable parselet detection occurs.
59
60
*/
60
61
pub fn compile ( mut self ) -> Result < Program , Vec < Error > > {
62
+ log:: info!( "{} compile" , self . main) ;
63
+
61
64
let mut finalize = HashSet :: new ( ) ; // list of consuming parselets required to be finalized
62
65
63
66
// Loop until end of statics is reached
64
67
let mut idx = 0 ;
65
68
66
69
// self.statics grows inside of this while loop, therefore this condition.
67
70
while idx < self . statics . len ( ) {
71
+ log:: trace!(
72
+ "idx = {: >3}, statics.len() = {: >3}" ,
73
+ idx,
74
+ self . statics. len( )
75
+ ) ;
76
+
68
77
// Pick only intermediate parselets, other static values are directly moved
69
78
let parselet = match self . statics . get_index_mut ( idx) . unwrap ( ) {
70
79
( _, Some ( _) ) => unreachable ! ( ) , // may not exist!
@@ -75,7 +84,7 @@ impl ImlProgram {
75
84
}
76
85
} ;
77
86
78
- // println !("\n::: {} {:?} :::\n ", idx, parselet.borrow().name);
87
+ log :: trace !( "idx = {: >3}, parselet = {:?}" , idx, parselet. borrow( ) . name) ;
79
88
80
89
// Memoize parselets required to be finalized (needs a general rework later...)
81
90
if parselet. borrow ( ) . model . borrow ( ) . is_consuming {
@@ -96,12 +105,10 @@ impl ImlProgram {
96
105
}
97
106
98
107
// Finalize parselets
99
- if self . debug {
100
- println ! ( "--- Parselets to finalize ---" ) ;
108
+ log:: info!( "{} has {} parselets to finalize" , self . main, finalize. len( ) ) ;
101
109
102
- for ( i, parselet) in finalize. iter ( ) . enumerate ( ) {
103
- println ! ( "{:?} => {:#?}" , i, parselet) ;
104
- }
110
+ for ( i, parselet) in finalize. iter ( ) . enumerate ( ) {
111
+ log:: trace!( " {: >3} => {:#?}" , i, parselet) ;
105
112
}
106
113
107
114
let leftrec = self . finalize ( finalize) ;
@@ -127,11 +134,11 @@ impl ImlProgram {
127
134
} )
128
135
. collect ( ) ;
129
136
130
- /*
137
+ log:: info!( "{} has {} statics compiled" , self . main, statics. len( ) ) ;
138
+
131
139
for ( i, value) in statics. iter ( ) . enumerate ( ) {
132
- println !("{ } : {:?}", i, value.borrow() );
140
+ log :: trace !( " {: >3 } : {:# ?}" , i, value) ;
133
141
}
134
- */
135
142
136
143
Ok ( Program :: new ( statics) )
137
144
}
@@ -370,17 +377,19 @@ impl ImlProgram {
370
377
}
371
378
}
372
379
373
- /*
374
- println!("--- final config ---");
380
+ log:: info!(
381
+ "{} has {} parselets finalized" ,
382
+ self . statics. keys( ) [ 0 ] ,
383
+ parselets. len( )
384
+ ) ;
375
385
376
386
for parselet in & parselets {
377
- println !(
378
- "{} consuming={:?}",
387
+ log :: trace !(
388
+ " {} consuming={:?}" ,
379
389
parselet. borrow( ) . name. as_deref( ) . unwrap_or( "(unnamed)" ) ,
380
390
configs[ & parselet]
381
391
) ;
382
392
}
383
- */
384
393
385
394
configs. into_iter ( ) . map ( |( k, v) | ( k, v. leftrec ) ) . collect ( )
386
395
}
0 commit comments