@@ -6,7 +6,7 @@ import {WARDuino} from '../debug/WARDuino';
66import { JSONParse } from 'json-with-bigint' ;
77import State = WARDuino . State ;
88import nothing = WASM . nothing ;
9-
9+ import Type = WASM . Type ;
1010export function identityParser ( text : string ) {
1111 return stripEnd ( text ) ;
1212}
@@ -15,7 +15,7 @@ export function stateParser(text: string): State {
1515 return JSONParse ( text ) ;
1616}
1717
18- export function invokeParser ( text : string ) : WASM . Value < bigint | number > | Exception {
18+ export function invokeParser ( text : string ) : WASM . Value < Type > | Exception {
1919 if ( exception ( text ) ) {
2020 return { text : text } ;
2121 }
@@ -60,38 +60,50 @@ export function breakpointHitParser(text: string): Breakpoint {
6060}
6161
6262export function signed ( value : bigint , bits = 32 ) {
63- let x = BigInt ( value ) ;
63+ let x = value ;
6464 const sign = 1n << BigInt ( bits - 1 ) ;
6565 const mod = 1n << BigInt ( bits ) ;
6666 return x >= sign ? x - mod : x ;
6767
6868}
6969
70- function stacking ( objects : { value : bigint , type : any } [ ] ) : WASM . Value < bigint | number > [ ] {
71- const stacked : WASM . Value < bigint | number > [ ] = [ ] ;
70+ function extractType ( object : { value : bigint | number , type : any } ) : Type {
71+ if ( isNaN ( < number > object . value ) ) return WASM . Special . nan ;
72+ if ( < number > object . value === Infinity ) return WASM . Special . infinity ;
73+ return WASM . typing . get ( object . type . toLowerCase ( ) ) ?? WASM . Special . unknown ;
74+ }
75+
76+ function stacking ( objects : { value : bigint | number , type : any } [ ] ) : WASM . Value < Type > [ ] {
77+ const stacked : WASM . Value < Type > [ ] = [ ] ;
7278 for ( const object of objects ) {
73- const type : WASM . Type = WASM . typing . get ( object . type . toLowerCase ( ) ) ?? WASM . Type . unknown ;
79+ const type : WASM . Type = extractType ( object ) ;
7480 let buff ;
7581 switch ( type ) {
76- case WASM . Type . u32 :
77- case WASM . Type . u64 :
82+ case WASM . Special . nan :
83+ stacked . push ( { value : NaN , type : type } ) ;
84+ break ;
85+ case WASM . Special . infinity :
86+ stacked . push ( { value : Infinity , type : type } ) ;
87+ break ;
88+ case WASM . Integer . u32 :
89+ case WASM . Integer . u64 :
7890 stacked . push ( { value : object . value , type : type } ) ;
7991 break ;
80- case WASM . Type . i32 :
81- stacked . push ( { value : signed ( object . value , 32 ) , type : type } ) ;
92+ case WASM . Integer . i32 :
93+ stacked . push ( { value : signed ( BigInt ( object . value ) , 32 ) , type : type } ) ;
8294 break ;
83- case WASM . Type . i64 :
84- stacked . push ( { value : signed ( object . value , 64 ) , type : type } ) ;
95+ case WASM . Integer . i64 :
96+ stacked . push ( { value : signed ( BigInt ( object . value ) , 64 ) , type : type } ) ;
8597 break ;
86- case WASM . Type . f32 :
98+ case WASM . Float . f32 :
8799 buff = Buffer . from ( Number ( object . value . toString ( 16 ) ) . toString ( 16 ) , 'hex' ) ;
88100 stacked . push ( { value : ieee754 . read ( buff , 0 , false , 23 , buff . length ) , type : type } ) ;
89101 break ;
90- case WASM . Type . f64 :
102+ case WASM . Float . f64 :
91103 buff = Buffer . from ( BigInt ( object . value . toString ( 16 ) ) . toString ( 16 ) , 'hex' ) ;
92104 stacked . push ( { value : ieee754 . read ( buff , 0 , false , 52 , buff . length ) , type : type } ) ;
93105 break ;
94- case WASM . Type . unknown :
106+ case WASM . Special . unknown :
95107 break ;
96108 }
97109 }
0 commit comments