@ -1,5 +1,5 @@
use crate ::{
use crate ::{
value ::Numeric ,
value ::{ JsValue , Numeric } ,
vm ::{ opcode ::Operation , ShouldExit } ,
vm ::{ opcode ::Operation , ShouldExit } ,
Context , JsBigInt , JsResult ,
Context , JsBigInt , JsResult ,
} ;
} ;
@ -17,11 +17,16 @@ impl Operation for Dec {
fn execute ( context : & mut Context < ' _ > ) -> JsResult < ShouldExit > {
fn execute ( context : & mut Context < ' _ > ) -> JsResult < ShouldExit > {
let value = context . vm . pop ( ) ;
let value = context . vm . pop ( ) ;
match value . to_numeric ( context ) ? {
match value {
JsValue ::Integer ( number ) if number > i32 ::MIN = > {
context . vm . push ( number - 1 ) ;
}
_ = > match value . to_numeric ( context ) ? {
Numeric ::Number ( number ) = > context . vm . push ( number - 1 f64 ) ,
Numeric ::Number ( number ) = > context . vm . push ( number - 1 f64 ) ,
Numeric ::BigInt ( bigint ) = > {
Numeric ::BigInt ( bigint ) = > {
context . vm . push ( JsBigInt ::sub ( & bigint , & JsBigInt ::one ( ) ) ) ;
context . vm . push ( JsBigInt ::sub ( & bigint , & JsBigInt ::one ( ) ) ) ;
}
}
} ,
}
}
Ok ( ShouldExit ::False )
Ok ( ShouldExit ::False )
}
}
@ -40,6 +45,12 @@ impl Operation for DecPost {
fn execute ( context : & mut Context < ' _ > ) -> JsResult < ShouldExit > {
fn execute ( context : & mut Context < ' _ > ) -> JsResult < ShouldExit > {
let value = context . vm . pop ( ) ;
let value = context . vm . pop ( ) ;
match value {
JsValue ::Integer ( number ) if number > i32 ::MIN = > {
context . vm . push ( number - 1 ) ;
context . vm . push ( value ) ;
}
_ = > {
let value = value . to_numeric ( context ) ? ;
let value = value . to_numeric ( context ) ? ;
match value {
match value {
Numeric ::Number ( number ) = > context . vm . push ( number - 1 f64 ) ,
Numeric ::Number ( number ) = > context . vm . push ( number - 1 f64 ) ,
@ -48,6 +59,8 @@ impl Operation for DecPost {
}
}
}
}
context . vm . push ( value ) ;
context . vm . push ( value ) ;
}
}
Ok ( ShouldExit ::False )
Ok ( ShouldExit ::False )
}
}
}
}