11use std:: fmt;
22use std:: fmt:: { Display , Formatter } ;
33
4- use crate :: ast:: { Class , Constant , ConstructorCall , Expr , Method , Operation , Statement } ;
5- use hlbc:: fmt:: EnhancedFmt ;
4+ use hlbc:: fmt:: { BytecodeFmt , EnhancedFmt } ;
65use hlbc:: types:: { Function , RefField , Type } ;
76use hlbc:: { Bytecode , Resolve } ;
87
8+ use crate :: ast:: { Class , Constant , ConstructorCall , Expr , Method , Operation , Statement } ;
9+
910#[ derive( Clone ) ]
1011pub struct FormatOptions {
1112 indent : String ,
@@ -100,17 +101,19 @@ impl Method {
100101 }
101102}
102103
103- impl Display for Constant {
104- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
104+ impl Constant {
105+ fn fmt ( & self , f : & mut Formatter , code : & Bytecode ) -> fmt:: Result {
105106 use Constant :: * ;
106- match self {
107- InlineInt ( c) => Display :: fmt ( c, f) ,
108- Int ( c) => Display :: fmt ( c, f) ,
109- Float ( c) => Display :: fmt ( c, f) ,
110- String ( c) => write ! ( f, "\" {c}\" " ) ,
111- Bool ( c) => Display :: fmt ( c, f) ,
112- Null => Display :: fmt ( "null" , f) ,
113- This => Display :: fmt ( "this" , f) ,
107+ match * self {
108+ InlineInt ( c) => Display :: fmt ( & c, f) ,
109+ Int ( c) => EnhancedFmt . fmt_refint ( f, code, c) ,
110+ Float ( c) => EnhancedFmt . fmt_reffloat ( f, code, c) ,
111+ String ( c) => {
112+ write ! ( f, "\" {}\" " , c. display:: <EnhancedFmt >( code) )
113+ }
114+ Bool ( c) => Display :: fmt ( & c, f) ,
115+ Null => f. write_str ( "null" ) ,
116+ This => f. write_str ( "this" ) ,
114117 }
115118 }
116119}
@@ -176,7 +179,7 @@ impl Expr {
176179 . enumerate( )
177180 . map( |( i, f) | {
178181 fmtools:: fmt! { move
179- { f. name} ": " { disp!( values. get( & RefField ( i) ) . unwrap( ) ) }
182+ { f. name( code ) } ": " { disp!( values. get( & RefField ( i) ) . unwrap( ) ) }
180183 }
181184 } ) ) } "}"
182185 }
@@ -188,7 +191,7 @@ impl Expr {
188191 Expr :: Call ( call) => {
189192 { disp!( call. fun) } "(" { fmtools:: join( ", " , call. args. iter( ) . map( |e| disp!( e) ) ) } ")"
190193 }
191- Expr :: Constant ( c) => { { c } } ,
194+ Expr :: Constant ( c) => { |f| c . fmt ( f , code ) ? ; } ,
192195 Expr :: Constructor ( ConstructorCall { ty, args } ) => {
193196 "new " { ty. display:: <EnhancedFmt >( code) } "(" { fmtools:: join( ", " , args. iter( ) . map( |e| disp!( e) ) ) } ")"
194197 }
0 commit comments