@@ -2,7 +2,7 @@ import {WARDuino} from '../debug/WARDuino';
22import { ackParser , breakpointParser , invokeParser , stateParser } from './Parsers' ;
33import { Breakpoint } from '../debug/Breakpoint' ;
44import { WASM } from '../sourcemap/Wasm' ;
5- import ieee754 from 'ieee754' ;
5+ import { write } from 'ieee754' ;
66import { SourceMap } from '../sourcemap/SourceMap' ;
77import { readFileSync } from 'fs' ;
88import { CompileOutput , CompilerFactory } from '../manage/Compiler' ;
@@ -11,7 +11,6 @@ import Interrupt = WARDuino.Interrupt;
1111import State = WARDuino . State ;
1212import Value = WASM . Value ;
1313import Type = WASM . Type ;
14- import Float = WASM . Float ;
1514
1615// An acknowledgement returned by the debugger
1716export interface Ack {
@@ -28,7 +27,6 @@ export interface Request<R> {
2827}
2928
3029export namespace Message {
31- import Float = WASM . Float ;
3230 import Inspect = WARDuino . Inspect ;
3331 export const run : Request < Ack > = {
3432 type : Interrupt . run ,
@@ -138,7 +136,7 @@ export namespace Message {
138136 export function updateModule ( wasm : string ) : Request < Ack > {
139137 function payload ( binary : Buffer ) : string {
140138 const w = new Uint8Array ( binary ) ;
141- const sizeHex : string = WASM . leb128 ( BigInt ( w . length ) ) ;
139+ const sizeHex : string = WASM . leb128 ( w . length ) ;
142140 const sizeBuffer = Buffer . allocUnsafe ( 4 ) ;
143141 sizeBuffer . writeUint32BE ( w . length ) ;
144142 const wasmHex = Buffer . from ( w ) . toString ( 'hex' ) ;
@@ -164,7 +162,7 @@ export namespace Message {
164162 }
165163 }
166164
167- export function invoke ( func : string , args : Value < Type > [ ] ) : Request < WASM . Value < Type > | Exception > {
165+ export function invoke ( func : string , args : Value [ ] ) : Request < WASM . Value | Exception > {
168166 function fidx ( map : SourceMap . Mapping , func : string ) : number {
169167 const fidx : number | void = map . functions . find ( ( closure : SourceMap . Closure ) => closure . name === func ) ?. index ;
170168 if ( fidx === undefined ) {
@@ -173,28 +171,23 @@ export namespace Message {
173171 return fidx ! ;
174172 }
175173
176- function convert ( args : Value < Type > [ ] ) {
174+ function convert ( args : Value [ ] ) {
177175 let payload : string = '' ;
178- args . forEach ( ( arg : Value < Type > ) => {
179- switch ( arg . type ) {
180- case WASM . Float . f32 :
181- case WASM . Float . f64 :
182- payload += ieeefloat ( < Value < Float > > arg )
183- break ;
184- case WASM . Integer . i32 :
185- case WASM . Integer . i64 :
186- payload += WASM . leb128 ( < bigint > arg . value ) ;
187- break ;
188- default :
189- break ;
176+ args . forEach ( ( arg : Value ) => {
177+ if ( arg . type === Type . i32 || arg . type === Type . i64 ) {
178+ payload += WASM . leb128 ( arg . value ) ;
179+ } else {
180+ const buff = Buffer . alloc ( arg . type === Type . f32 ? 4 : 8 ) ;
181+ write ( buff , arg . value , 0 , true , arg . type === Type . f32 ? 23 : 52 , buff . length ) ;
182+ payload += buff . toString ( 'hex' ) ;
190183 }
191184 } ) ;
192185 return payload ;
193186 }
194187
195188 return {
196189 type : Interrupt . invoke ,
197- payload : ( map : SourceMap . Mapping ) => `${ WASM . leb128 ( BigInt ( fidx ( map , func ) ) ) } ${ convert ( args ) } ` ,
190+ payload : ( map : SourceMap . Mapping ) => `${ WASM . leb128 ( fidx ( map , func ) ) } ${ convert ( args ) } ` ,
198191 parser : invokeParser
199192 }
200193 }
@@ -226,9 +219,3 @@ export namespace Message {
226219 }
227220 } ;
228221}
229-
230- function ieeefloat ( arg : Value < Float > ) : String {
231- const buff = Buffer . alloc ( arg . type === Float . f32 ? 4 : 8 ) ;
232- ieee754 . write ( buff , < number > arg . value , 0 , true , arg . type === Float . f32 ? 23 : 52 , buff . length ) ; // TODO write BigInt without loss of precision (don't use ieee754.write)
233- return buff . toString ( 'hex' ) ;
234- }
0 commit comments