@@ -12,7 +12,7 @@ use super::format::{LineBuilder, Symbol, format_effect, nav_symbol_epsilon, widt
1212use super :: ids:: TypeId ;
1313use super :: instructions:: StepId ;
1414use super :: module:: { Instruction , Module } ;
15- use super :: type_meta:: TypeKind ;
15+ use super :: type_meta:: { TypeData , TypeKind } ;
1616use super :: { Call , Match , Return , Trampoline } ;
1717
1818/// Generate a human-readable dump of the bytecode module.
@@ -79,20 +79,20 @@ impl DumpContext {
7979 step_labels. insert ( 0 , "_ObjWrap" . to_string ( ) ) ;
8080 for i in 0 ..entrypoints. len ( ) {
8181 let ep = entrypoints. get ( i) ;
82- let name = strings. get ( ep. name ) . to_string ( ) ;
83- step_labels. insert ( ep. target , name) ;
82+ let name = strings. get ( ep. name ( ) ) . to_string ( ) ;
83+ step_labels. insert ( ep. target ( ) , name) ;
8484 }
8585
8686 let mut node_type_names = BTreeMap :: new ( ) ;
8787 for i in 0 ..node_types. len ( ) {
8888 let t = node_types. get ( i) ;
89- node_type_names. insert ( t. id , strings. get ( t. name ) . to_string ( ) ) ;
89+ node_type_names. insert ( t. id ( ) , strings. get ( t. name ( ) ) . to_string ( ) ) ;
9090 }
9191
9292 let mut node_field_names = BTreeMap :: new ( ) ;
9393 for i in 0 ..node_fields. len ( ) {
9494 let f = node_fields. get ( i) ;
95- node_field_names. insert ( f. id , strings. get ( f. name ) . to_string ( ) ) ;
95+ node_field_names. insert ( f. id ( ) , strings. get ( f. name ( ) ) . to_string ( ) ) ;
9696 }
9797
9898 // Collect all strings for unlinked mode lookups
@@ -182,53 +182,74 @@ fn dump_types_defs(out: &mut String, module: &Module, ctx: &DumpContext) {
182182 // All types are now in type_defs, including builtins
183183 for i in 0 ..types. defs_count ( ) {
184184 let def = types. get_def ( i) ;
185- let kind = def. type_kind ( ) . expect ( "valid type kind" ) ;
186-
187- let formatted = match kind {
188- // Primitive types
189- TypeKind :: Void => "<Void>" . to_string ( ) ,
190- TypeKind :: Node => "<Node>" . to_string ( ) ,
191- TypeKind :: String => "<String>" . to_string ( ) ,
192- // Composite types
193- TypeKind :: Struct => format ! ( "Struct M{:0mw$}:{}" , def. data, def. count) ,
194- TypeKind :: Enum => format ! ( "Enum M{:0mw$}:{}" , def. data, def. count) ,
195- // Wrapper types
196- TypeKind :: Optional => format ! ( "Optional(T{:0tw$})" , def. data) ,
197- TypeKind :: ArrayZeroOrMore => format ! ( "ArrayStar(T{:0tw$})" , def. data) ,
198- TypeKind :: ArrayOneOrMore => format ! ( "ArrayPlus(T{:0tw$})" , def. data) ,
199- TypeKind :: Alias => format ! ( "Alias(T{:0tw$})" , def. data) ,
200- } ;
201185
202- // Generate comment for non-primitives (comments are dim)
203- let comment = match kind {
204- TypeKind :: Void | TypeKind :: Node | TypeKind :: String => String :: new ( ) ,
205- TypeKind :: Struct => {
206- let fields: Vec < _ > = types
207- . members_of ( & def)
208- . map ( |m| strings. get ( m. name ) . to_string ( ) )
209- . collect ( ) ;
210- format ! ( "{} ; {{ {} }}{}" , c. dim, fields. join( ", " ) , c. reset)
211- }
212- TypeKind :: Enum => {
213- let variants: Vec < _ > = types
214- . members_of ( & def)
215- . map ( |m| strings. get ( m. name ) . to_string ( ) )
216- . collect ( ) ;
217- format ! ( "{} ; {}{}" , c. dim, variants. join( " | " ) , c. reset)
218- }
219- TypeKind :: Optional => {
220- let inner_name = format_type_name ( TypeId ( def. data ) , module, ctx) ;
221- format ! ( "{} ; {}?{}" , c. dim, inner_name, c. reset)
186+ let ( formatted, comment) = match def. classify ( ) {
187+ TypeData :: Primitive ( kind) => {
188+ let name = match kind {
189+ TypeKind :: Void => "<Void>" ,
190+ TypeKind :: Node => "<Node>" ,
191+ TypeKind :: String => "<String>" ,
192+ _ => unreachable ! ( ) ,
193+ } ;
194+ ( name. to_string ( ) , String :: new ( ) )
222195 }
223- TypeKind :: ArrayZeroOrMore => {
224- let inner_name = format_type_name ( TypeId ( def. data ) , module, ctx) ;
225- format ! ( "{} ; {}*{}" , c. dim, inner_name, c. reset)
196+ TypeData :: Wrapper { kind, inner } => {
197+ let formatted = match kind {
198+ TypeKind :: Optional => format ! ( "Optional(T{:0tw$})" , inner. 0 ) ,
199+ TypeKind :: ArrayZeroOrMore => format ! ( "ArrayStar(T{:0tw$})" , inner. 0 ) ,
200+ TypeKind :: ArrayOneOrMore => format ! ( "ArrayPlus(T{:0tw$})" , inner. 0 ) ,
201+ TypeKind :: Alias => format ! ( "Alias(T{:0tw$})" , inner. 0 ) ,
202+ _ => unreachable ! ( ) ,
203+ } ;
204+ let comment = match kind {
205+ TypeKind :: Optional => {
206+ let inner_name = format_type_name ( inner, module, ctx) ;
207+ format ! ( "{} ; {}?{}" , c. dim, inner_name, c. reset)
208+ }
209+ TypeKind :: ArrayZeroOrMore => {
210+ let inner_name = format_type_name ( inner, module, ctx) ;
211+ format ! ( "{} ; {}*{}" , c. dim, inner_name, c. reset)
212+ }
213+ TypeKind :: ArrayOneOrMore => {
214+ let inner_name = format_type_name ( inner, module, ctx) ;
215+ format ! ( "{} ; {}+{}" , c. dim, inner_name, c. reset)
216+ }
217+ TypeKind :: Alias => String :: new ( ) ,
218+ _ => unreachable ! ( ) ,
219+ } ;
220+ ( formatted, comment)
226221 }
227- TypeKind :: ArrayOneOrMore => {
228- let inner_name = format_type_name ( TypeId ( def. data ) , module, ctx) ;
229- format ! ( "{} ; {}+{}" , c. dim, inner_name, c. reset)
222+ TypeData :: Composite {
223+ kind,
224+ member_start,
225+ member_count,
226+ } => {
227+ let formatted = match kind {
228+ TypeKind :: Struct => {
229+ format ! ( "Struct M{:0mw$}:{}" , member_start, member_count)
230+ }
231+ TypeKind :: Enum => format ! ( "Enum M{:0mw$}:{}" , member_start, member_count) ,
232+ _ => unreachable ! ( ) ,
233+ } ;
234+ let comment = match kind {
235+ TypeKind :: Struct => {
236+ let fields: Vec < _ > = types
237+ . members_of ( & def)
238+ . map ( |m| strings. get ( m. name ( ) ) . to_string ( ) )
239+ . collect ( ) ;
240+ format ! ( "{} ; {{ {} }}{}" , c. dim, fields. join( ", " ) , c. reset)
241+ }
242+ TypeKind :: Enum => {
243+ let variants: Vec < _ > = types
244+ . members_of ( & def)
245+ . map ( |m| strings. get ( m. name ( ) ) . to_string ( ) )
246+ . collect ( ) ;
247+ format ! ( "{} ; {}{}" , c. dim, variants. join( " | " ) , c. reset)
248+ }
249+ _ => unreachable ! ( ) ,
250+ } ;
251+ ( formatted, comment)
230252 }
231- TypeKind :: Alias => String :: new ( ) ,
232253 } ;
233254
234255 writeln ! ( out, "T{i:0tw$} = {formatted}{comment}" ) . unwrap ( ) ;
@@ -288,7 +309,7 @@ fn format_type_name(type_id: TypeId, module: &Module, ctx: &DumpContext) -> Stri
288309
289310 // Check if it's a primitive type
290311 if let Some ( def) = types. get ( type_id)
291- && let Some ( kind) = def. type_kind ( )
312+ && let TypeData :: Primitive ( kind) = def. classify ( )
292313 && let Some ( name) = kind. primitive_name ( )
293314 {
294315 return format ! ( "<{}>" , name) ;
@@ -297,8 +318,8 @@ fn format_type_name(type_id: TypeId, module: &Module, ctx: &DumpContext) -> Stri
297318 // Try to find a name in types.names
298319 for i in 0 ..types. names_count ( ) {
299320 let entry = types. get_name ( i) ;
300- if entry. type_id == type_id {
301- return strings. get ( entry. name ) . to_string ( ) ;
321+ if entry. type_id ( ) == type_id {
322+ return strings. get ( entry. name ( ) ) . to_string ( ) ;
302323 }
303324 }
304325
@@ -320,8 +341,8 @@ fn dump_entrypoints(out: &mut String, module: &Module, ctx: &DumpContext) {
320341 let mut entries: Vec < _ > = ( 0 ..entrypoints. len ( ) )
321342 . map ( |i| {
322343 let ep = entrypoints. get ( i) ;
323- let name = strings. get ( ep. name ) ;
324- ( name, ep. target , ep. result_type . 0 )
344+ let name = strings. get ( ep. name ( ) ) ;
345+ ( name, ep. target ( ) , ep. result_type ( ) . 0 )
325346 } )
326347 . collect ( ) ;
327348 entries. sort_by_key ( |( name, _, _) | * name) ;
0 commit comments