@@ -45,12 +45,17 @@ def to_graphviz type
4545# Start at Any. All types are subtypes of Any.
4646any = Type . new "Any"
4747# Build the effect universe.
48- frame = any . subtype "Frame"
4948world = any . subtype "World"
49+ other = world . subtype "Other"
50+ frame = world . subtype "Frame"
5051pc = frame . subtype "PC"
5152locals = frame . subtype "Locals"
5253stack = frame . subtype "Stack"
5354
55+ # Use the smallest unsigned value needed to describe all effect bits
56+ # If it becomes an issue, this can be generated but for now we do it manually
57+ $int_label = "u8"
58+
5459# Define a new type that can be subclassed (most of them).
5560# If c_name is given, mark the rb_cXYZ object as equivalent to this exact type.
5661def base_type name , c_name : nil
@@ -79,13 +84,13 @@ def final_type name, base: $object, c_name: nil
7984
8085# Assign individual bits to type leaves and union bit patterns to nodes with subtypes
8186num_bits = 0
82- $bits = { "None" => [ "0u64 " ] }
87+ $bits = { "None" => [ "0 #{ $int_label } " ] }
8388$numeric_bits = { "None" => 0 }
8489Set [ any , *any . all_subtypes ] . sort_by ( &:name ) . each { |type |
8590 subtypes = type . subtypes
8691 if subtypes . empty?
8792 # Assign bits for leaves
88- $bits[ type . name ] = [ "1u64 << #{ num_bits } " ]
93+ $bits[ type . name ] = [ "1 #{ $int_label } << #{ num_bits } " ]
8994 $numeric_bits[ type . name ] = 1 << num_bits
9095 num_bits += 1
9196 else
@@ -116,17 +121,17 @@ def add_union name, type_names
116121puts "mod bits {"
117122$bits. keys . sort . map { |type_name |
118123 subtypes = $bits[ type_name ] . join ( " | " )
119- puts " pub const #{ type_name } : u64 = #{ subtypes } ;"
124+ puts " pub const #{ type_name } : #{ $int_label } = #{ subtypes } ;"
120125}
121- puts " pub const AllBitPatterns: [(&str, u64 ); #{ $bits. size } ] = ["
126+ puts " pub const AllBitPatterns: [(&str, #{ $int_label } ); #{ $bits. size } ] = ["
122127# Sort the bit patterns by decreasing value so that we can print the densest
123128# possible to-string representation of a Type. For example, CSigned instead of
124129# CInt8|CInt16|...
125130$numeric_bits. sort_by { |key , val | -val } . each { |type_name , _ |
126131 puts " (\" #{ type_name } \" , #{ type_name } ),"
127132}
128133puts " ];"
129- puts " pub const NumEffectBits: u64 = #{ num_bits } ;
134+ puts " pub const NumEffectBits: #{ $int_label } = #{ num_bits } ;
130135}"
131136
132137puts "pub mod effects {
0 commit comments