@@ -130,6 +130,31 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
130130 Ok ( ( ) )
131131 }
132132
133+ fn load_const ( & mut self , constant : & Constant ) -> Result < ( ) , JitCompileError > {
134+ match constant {
135+ Constant :: Integer { value } => {
136+ let val = self . builder . ins ( ) . iconst (
137+ types:: I64 ,
138+ value. to_i64 ( ) . ok_or ( JitCompileError :: NotSupported ) ?,
139+ ) ;
140+ self . stack . push ( JitValue {
141+ val,
142+ ty : JitType :: Int ,
143+ } ) ;
144+ Ok ( ( ) )
145+ }
146+ Constant :: Float { value } => {
147+ let val = self . builder . ins ( ) . f64const ( * value) ;
148+ self . stack . push ( JitValue {
149+ val,
150+ ty : JitType :: Float ,
151+ } ) ;
152+ Ok ( ( ) )
153+ }
154+ _ => Err ( JitCompileError :: NotSupported )
155+ }
156+ }
157+
133158 fn add_instruction ( & mut self , instruction : & Instruction ) -> Result < ( ) , JitCompileError > {
134159 match instruction {
135160 Instruction :: JumpIfFalse { target } => {
@@ -175,29 +200,7 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
175200 let val = self . stack . pop ( ) . ok_or ( JitCompileError :: BadBytecode ) ?;
176201 self . store_variable ( name. clone ( ) , val)
177202 }
178- Instruction :: LoadConst {
179- value : Constant :: Integer { value } ,
180- } => {
181- let val = self . builder . ins ( ) . iconst (
182- types:: I64 ,
183- value. to_i64 ( ) . ok_or ( JitCompileError :: NotSupported ) ?,
184- ) ;
185- self . stack . push ( JitValue {
186- val,
187- ty : JitType :: Int ,
188- } ) ;
189- Ok ( ( ) )
190- }
191- Instruction :: LoadConst {
192- value : Constant :: Float { value } ,
193- } => {
194- let val = self . builder . ins ( ) . f64const ( * value) ;
195- self . stack . push ( JitValue {
196- val,
197- ty : JitType :: Float ,
198- } ) ;
199- Ok ( ( ) )
200- }
203+ Instruction :: LoadConst { value } => { self . load_const ( value) }
201204 Instruction :: ReturnValue => {
202205 let val = self . stack . pop ( ) . ok_or ( JitCompileError :: BadBytecode ) ?;
203206 if let Some ( ref ty) = self . sig . ret {
0 commit comments