@@ -354,33 +354,33 @@ const compileStatement = (
354354
355355 // biome-ignore format: keep loop structure
356356 return wat (
357- // Start counter at 0
358- i32 . const ( 0 ) ,
359- local . set ( counterIndex ) ,
360- block . start ( ) ,
361- loop . start ( ) ,
362- // check if we reached max iterations
363- local . get ( counterIndex ) ,
364- i32 . const ( MAX_ITERATIONS ) ,
365- i32 . ge_u ( ) ,
366- if_ . start ( ) , // counter >= maxIters
367- misc . unreachable ( ) , // infinite loop, throw error
368- if_ . end ( ) ,
369- local . get ( counterIndex ) ,
370- i32 . const ( 1 ) ,
371- i32 . add ( ) , // increment counter
372- local . set ( counterIndex ) ,
357+ // Start counter at 0
358+ i32 . const ( 0 ) ,
359+ local . set ( counterIndex ) ,
360+ block . start ( ) ,
361+ loop . start ( ) ,
362+ // check if we reached max iterations
363+ local . get ( counterIndex ) ,
364+ i32 . const ( MAX_ITERATIONS ) ,
365+ i32 . ge_u ( ) ,
366+ if_ . start ( ) , // counter >= maxIters
367+ misc . unreachable ( ) , // infinite loop, throw error
368+ if_ . end ( ) ,
369+ local . get ( counterIndex ) ,
370+ i32 . const ( 1 ) ,
371+ i32 . add ( ) , // increment counter
372+ local . set ( counterIndex ) ,
373373
374- condition ,
375- fn . call ( func ( ) . is_truthy ) ,
376- i32 . eqz ( ) , // check if condition is false
377- loop . br_if ( 1 ) , // break out of outer block
374+ condition ,
375+ fn . call ( func ( ) . is_truthy ) ,
376+ i32 . eqz ( ) , // check if condition is false
377+ loop . br_if ( 1 ) , // break out of outer block
378378
379- body ,
380- loop . br ( 0 ) , // loop back
381- loop . end ( ) ,
382- block . end ( ) ,
383- ) ;
379+ body ,
380+ loop . br ( 0 ) , // loop back
381+ loop . end ( ) ,
382+ block . end ( ) ,
383+ ) ;
384384 }
385385 case "ForStatement" : {
386386 const { assignment, condition, increment, body } = stmt ;
@@ -407,62 +407,62 @@ const compileStatement = (
407407 const counterIndex = consumeScratchIndex ( ) ;
408408 // biome-ignore format: keep loop structure
409409 return wat (
410- // Start counter at 0
411- i32 . const ( 0 ) ,
412- local . set ( counterIndex ) ,
410+ // Start counter at 0
411+ i32 . const ( 0 ) ,
412+ local . set ( counterIndex ) ,
413413
414- init , // e.g. i := 0
415- step ,
416- fn . call ( func ( ) . unbox_number ) ,
417- f64 . const ( 0 ) ,
418- f64 . lt ( ) , // step < 0 ?
419- local . set ( isDescending ) ,
414+ init , // e.g. i := 0
415+ step ,
416+ fn . call ( func ( ) . unbox_number ) ,
417+ f64 . const ( 0 ) ,
418+ f64 . lt ( ) , // step < 0 ?
419+ local . set ( isDescending ) ,
420420
421- block . start ( ) ,
422- loop . start ( ) ,
423- // check if we reached max iterations
424- local . get ( counterIndex ) ,
425- i32 . const ( MAX_ITERATIONS ) ,
426- i32 . ge_u ( ) ,
427- if_ . start ( ) , // counter >= maxIters
428- misc . unreachable ( ) , // infinite loop, throw error
429- if_ . end ( ) ,
430- local . get ( counterIndex ) ,
431- i32 . const ( 1 ) ,
432- i32 . add ( ) , // increment counter
433- local . set ( counterIndex ) ,
421+ block . start ( ) ,
422+ loop . start ( ) ,
423+ // check if we reached max iterations
424+ local . get ( counterIndex ) ,
425+ i32 . const ( MAX_ITERATIONS ) ,
426+ i32 . ge_u ( ) ,
427+ if_ . start ( ) , // counter >= maxIters
428+ misc . unreachable ( ) , // infinite loop, throw error
429+ if_ . end ( ) ,
430+ local . get ( counterIndex ) ,
431+ i32 . const ( 1 ) ,
432+ i32 . add ( ) , // increment counter
433+ local . set ( counterIndex ) ,
434434
435- local . get ( isDescending ) ,
436- if_ . start ( valType ( "i32" ) ) , // descending case
437- local . get ( loopVar . index ) ,
438- fn . call ( func ( ) . unbox_number ) ,
439- cond ,
440- fn . call ( func ( ) . unbox_number ) ,
441- f64 . lt ( ) , // i < cond ? 1 : 0
442- if_ . else ( ) , // ascending case
443- local . get ( loopVar . index ) ,
444- fn . call ( func ( ) . unbox_number ) ,
445- cond ,
446- fn . call ( func ( ) . unbox_number ) ,
447- f64 . gt ( ) , // i > cond ? 1 : 0
448- if_ . end ( ) ,
449- loop . br_if ( 1 ) , // exit if 1
435+ local . get ( isDescending ) ,
436+ if_ . start ( valType ( "i32" ) ) , // descending case
437+ local . get ( loopVar . index ) ,
438+ fn . call ( func ( ) . unbox_number ) ,
439+ cond ,
440+ fn . call ( func ( ) . unbox_number ) ,
441+ f64 . lt ( ) , // i < cond ? 1 : 0
442+ if_ . else ( ) , // ascending case
443+ local . get ( loopVar . index ) ,
444+ fn . call ( func ( ) . unbox_number ) ,
445+ cond ,
446+ fn . call ( func ( ) . unbox_number ) ,
447+ f64 . gt ( ) , // i > cond ? 1 : 0
448+ if_ . end ( ) ,
449+ loop . br_if ( 1 ) , // exit if 1
450450
451- loopBody ,
451+ loopBody ,
452452
453- // increment the loop variable
454- local . get ( loopVar . index ) ,
455- fn . call ( func ( ) . unbox_number ) ,
456- step ,
457- fn . call ( func ( ) . unbox_number ) ,
458- f64 . add ( ) ,
459- fn . call ( func ( ) . box_number ) ,
460- local . set ( loopVar . index ) ,
453+ // increment the loop variable
454+ local . get ( loopVar . index ) ,
455+ fn . call ( func ( ) . unbox_number ) ,
456+ step ,
457+ fn . call ( func ( ) . unbox_number ) ,
458+ f64 . add ( ) ,
459+ fn . call ( func ( ) . box_number ) ,
460+ local . set ( loopVar . index ) ,
461461
462- loop . br ( 0 ) , // loop back
463- loop . end ( ) ,
464- block . end ( ) ,
465- ) ;
462+ loop . br ( 0 ) , // loop back
463+ loop . end ( ) ,
464+ block . end ( ) ,
465+ ) ;
466466 }
467467 case "FunctionDeclStatement" : {
468468 const { name, params, body } = stmt ;
@@ -556,40 +556,40 @@ const compileExpression = (
556556 if ( nativeOp && expr . operator === "+" ) {
557557 // biome-ignore format: keep if structure
558558 return wat (
559- left ,
560- fn . call ( func ( ) . is_string ) ,
561- right ,
562- fn . call ( func ( ) . is_string ) ,
563- i32 . or ( ) , // is_string(left) || is_string(right)
564- if_ . start ( valType ( "i32" ) ) ,
565- left ,
566- right ,
567- fn . call ( func ( ) . concat ) ,
568- if_ . else ( ) ,
569- left ,
570- fn . call ( func ( ) . is_bool ) ,
571- right ,
572- fn . call ( func ( ) . is_bool ) ,
573- i32 . or ( ) ,
574- if_ . start ( valType ( "i32" ) ) , // is_bool(left) || is_bool(right)
575- left ,
576- fn . call ( func ( ) . to_number ) ,
577- fn . call ( func ( ) . unbox_number ) ,
578- right ,
579- fn . call ( func ( ) . to_number ) ,
580- fn . call ( func ( ) . unbox_number ) ,
581- f64 . add ( ) ,
582- fn . call ( func ( ) . box_number ) ,
583- if_ . else ( ) , // just add them otherwise
584- left ,
585- fn . call ( func ( ) . unbox_number ) ,
586- right ,
587- fn . call ( func ( ) . unbox_number ) ,
588- f64 . add ( ) ,
589- fn . call ( func ( ) . box_number ) ,
590- if_ . end ( ) , // bool
591- if_ . end ( ) , // string
592- ) ;
559+ left ,
560+ fn . call ( func ( ) . is_string ) ,
561+ right ,
562+ fn . call ( func ( ) . is_string ) ,
563+ i32 . or ( ) , // is_string(left) || is_string(right)
564+ if_ . start ( valType ( "i32" ) ) ,
565+ left ,
566+ right ,
567+ fn . call ( func ( ) . concat ) ,
568+ if_ . else ( ) ,
569+ left ,
570+ fn . call ( func ( ) . is_bool ) ,
571+ right ,
572+ fn . call ( func ( ) . is_bool ) ,
573+ i32 . or ( ) ,
574+ if_ . start ( valType ( "i32" ) ) , // is_bool(left) || is_bool(right)
575+ left ,
576+ fn . call ( func ( ) . to_number ) ,
577+ fn . call ( func ( ) . unbox_number ) ,
578+ right ,
579+ fn . call ( func ( ) . to_number ) ,
580+ fn . call ( func ( ) . unbox_number ) ,
581+ f64 . add ( ) ,
582+ fn . call ( func ( ) . box_number ) ,
583+ if_ . else ( ) , // just add them otherwise
584+ left ,
585+ fn . call ( func ( ) . unbox_number ) ,
586+ right ,
587+ fn . call ( func ( ) . unbox_number ) ,
588+ f64 . add ( ) ,
589+ fn . call ( func ( ) . box_number ) ,
590+ if_ . end ( ) , // bool
591+ if_ . end ( ) , // string
592+ ) ;
593593 }
594594
595595 // Native operators supported for f64
@@ -633,31 +633,31 @@ const compileExpression = (
633633 const scratch = consumeScratchIndex ( ) ;
634634 // biome-ignore format: keep if structure
635635 return wat (
636- left , // evaluate A
637- local . set ( scratch ) ,
638- local . get ( scratch ) ,
639- fn . call ( func ( ) . is_truthy ) ,
640- if_ . start ( valType ( "i32" ) ) ,
641- right , // evaluate and return B
642- if_ . else ( ) ,
643- local . get ( scratch ) , // return A
644- if_ . end ( ) ,
645- ) ;
636+ left , // evaluate A
637+ local . set ( scratch ) ,
638+ local . get ( scratch ) ,
639+ fn . call ( func ( ) . is_truthy ) ,
640+ if_ . start ( valType ( "i32" ) ) ,
641+ right , // evaluate and return B
642+ if_ . else ( ) ,
643+ local . get ( scratch ) , // return A
644+ if_ . end ( ) ,
645+ ) ;
646646 }
647647 case "or" : {
648648 const scratch = consumeScratchIndex ( ) ;
649649 // biome-ignore format: keep if structure
650650 return wat (
651- left , // evaluate A
652- local . set ( scratch ) ,
653- local . get ( scratch ) ,
654- fn . call ( func ( ) . is_truthy ) ,
655- if_ . start ( valType ( "i32" ) ) ,
656- local . get ( scratch ) , //return A
657- if_ . else ( ) ,
658- right , // evaluate and return B
659- if_ . end ( ) ,
660- ) ;
651+ left , // evaluate A
652+ local . set ( scratch ) ,
653+ local . get ( scratch ) ,
654+ fn . call ( func ( ) . is_truthy ) ,
655+ if_ . start ( valType ( "i32" ) ) ,
656+ local . get ( scratch ) , //return A
657+ if_ . else ( ) ,
658+ right , // evaluate and return B
659+ if_ . end ( ) ,
660+ ) ;
661661 }
662662 default :
663663 throw new Error ( `Unsupported binary operator: ${ expr . operator } ` ) ;
0 commit comments