Improve formatting for globals
This commit is contained in:
		
							parent
							
								
									f5f55079a9
								
							
						
					
					
						commit
						8b1d1084a6
					
				| @ -49,6 +49,9 @@ impl Display for Module { | |||||||
|         for typedef in &self.typedefs { |         for typedef in &self.typedefs { | ||||||
|             writeln!(inner_f, "{}", typedef)?; |             writeln!(inner_f, "{}", typedef)?; | ||||||
|         } |         } | ||||||
|  |         for global in &self.globals { | ||||||
|  |             writeln!(inner_f, "global {} = {}", global.name, global.kind)?; | ||||||
|  |         } | ||||||
|         for (ty, fun) in &self.associated_functions { |         for (ty, fun) in &self.associated_functions { | ||||||
|             writeln!(inner_f, "(Assoc {}) {}", ty, fun)?; |             writeln!(inner_f, "(Assoc {}) {}", ty, fun)?; | ||||||
|         } |         } | ||||||
| @ -59,6 +62,26 @@ impl Display for Module { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | impl Display for GlobalKind { | ||||||
|  |     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||||||
|  |         match self { | ||||||
|  |             GlobalKind::Literal(literal) => Display::fmt(literal, f), | ||||||
|  |             GlobalKind::Array(global_kinds) => { | ||||||
|  |                 f.write_char('[')?; | ||||||
|  |                 let mut iter = global_kinds.iter(); | ||||||
|  |                 if let Some(global) = iter.next() { | ||||||
|  |                     Display::fmt(global, f)?; | ||||||
|  |                     while let Some(global) = iter.next() { | ||||||
|  |                         write!(f, ", ")?; | ||||||
|  |                         Display::fmt(global, f)?; | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |                 f.write_char(']') | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| impl Display for Import { | impl Display for Import { | ||||||
|     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||||||
|         write!(f, "import {}", self.0.join("::")) |         write!(f, "import {}", self.0.join("::")) | ||||||
| @ -280,7 +303,7 @@ impl Display for ExprKind { | |||||||
|                 write!(f, "::")?; |                 write!(f, "::")?; | ||||||
|                 Display::fmt(function_call, f) |                 Display::fmt(function_call, f) | ||||||
|             } |             } | ||||||
|             ExprKind::GlobalRef(global_value, type_kind) => write!(f, "todo globals"), |             ExprKind::GlobalRef(global_value, type_kind) => write!(f, "global<{}>(${})", type_kind, global_value), | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user