@@ -10,6 +10,16 @@ pub struct JitSig {
1010 pub ret : Option < JitType > ,
1111}
1212
13+ impl JitSig {
14+ pub fn to_cif ( & self ) -> libffi:: middle:: Cif {
15+ let ret = match self . ret {
16+ Some ( ref ty) => ty. to_libffi ( ) ,
17+ None => libffi:: middle:: Type :: void ( ) ,
18+ } ;
19+ libffi:: middle:: Cif :: new ( Vec :: new ( ) , ret)
20+ }
21+ }
22+
1323#[ derive( Clone , PartialEq ) ]
1424pub enum JitType {
1525 Int ,
@@ -23,6 +33,13 @@ impl JitType {
2333 Self :: Float => types:: F64 ,
2434 }
2535 }
36+
37+ fn to_libffi ( & self ) -> libffi:: middle:: Type {
38+ match self {
39+ Self :: Int => libffi:: middle:: Type :: i64 ( ) ,
40+ Self :: Float => libffi:: middle:: Type :: f64 ( ) ,
41+ }
42+ }
2643}
2744
2845#[ derive( Clone ) ]
@@ -132,8 +149,9 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
132149 Ok ( ( ) )
133150 }
134151 Instruction :: BinaryOperation { op, .. } => {
135- let a = self . stack . pop ( ) . ok_or ( JitCompileError :: BadBytecode ) ? ;
152+ // the rhs is popped off first
136153 let b = self . stack . pop ( ) . ok_or ( JitCompileError :: BadBytecode ) ?;
154+ let a = self . stack . pop ( ) . ok_or ( JitCompileError :: BadBytecode ) ?;
137155 match ( a. ty , b. ty ) {
138156 ( JitType :: Int , JitType :: Int ) => match op {
139157 BinaryOperator :: Add => {
0 commit comments