@@ -193,7 +193,8 @@ import {
193
193
writeF32 ,
194
194
writeF64 ,
195
195
uniqueMap ,
196
- isPowerOf2
196
+ isPowerOf2 ,
197
+ v128_zero
197
198
} from "./util" ;
198
199
199
200
/** Compiler options. */
@@ -3058,10 +3059,11 @@ export class Compiler extends DiagnosticEmitter {
3058
3059
if ( initExpr ) {
3059
3060
let precomp = module . runExpression ( initExpr , ExpressionRunnerFlags . PreserveSideeffects ) ;
3060
3061
if ( precomp ) {
3061
- initExpr = precomp ;
3062
- let local = new Local ( name , - 1 , type , flow . parentFunction ) ;
3062
+ initExpr = precomp ; // always use precomputed initExpr
3063
+ let local : Local | null = null ;
3063
3064
switch ( < u32 > getExpressionType ( initExpr ) ) {
3064
3065
case < u32 > NativeType . I32 : {
3066
+ local = new Local ( name , - 1 , type , flow . parentFunction ) ;
3065
3067
local . setConstantIntegerValue (
3066
3068
i64_new (
3067
3069
getConstValueI32 ( initExpr ) ,
@@ -3072,6 +3074,7 @@ export class Compiler extends DiagnosticEmitter {
3072
3074
break ;
3073
3075
}
3074
3076
case < u32 > NativeType . I64 : {
3077
+ local = new Local ( name , - 1 , type , flow . parentFunction ) ;
3075
3078
local . setConstantIntegerValue (
3076
3079
i64_new (
3077
3080
getConstValueI64Low ( initExpr ) ,
@@ -3082,33 +3085,33 @@ export class Compiler extends DiagnosticEmitter {
3082
3085
break ;
3083
3086
}
3084
3087
case < u32 > NativeType . F32 : {
3088
+ local = new Local ( name , - 1 , type , flow . parentFunction ) ;
3085
3089
local . setConstantFloatValue ( < f64 > getConstValueF32 ( initExpr ) , type ) ;
3086
3090
break ;
3087
3091
}
3088
3092
case < u32 > NativeType . F64 : {
3093
+ local = new Local ( name , - 1 , type , flow . parentFunction ) ;
3089
3094
local . setConstantFloatValue ( getConstValueF64 ( initExpr ) , type ) ;
3090
3095
break ;
3091
3096
}
3092
- default : {
3093
- assert ( false ) ;
3094
- return module . unreachable ( ) ;
3095
- }
3096
3097
}
3097
- // Create a virtual local that doesn't actually exist in WebAssembly
3098
- let scopedLocals = flow . scopedLocals ;
3099
- if ( ! scopedLocals ) flow . scopedLocals = scopedLocals = new Map ( ) ;
3100
- else if ( scopedLocals . has ( name ) ) {
3101
- let existing = assert ( scopedLocals . get ( name ) ) ;
3102
- this . errorRelated (
3103
- DiagnosticCode . Duplicate_identifier_0 ,
3104
- declaration . name . range ,
3105
- existing . declaration . name . range ,
3106
- name
3107
- ) ;
3108
- return this . module . unreachable ( ) ;
3098
+ if ( local ) {
3099
+ // Add as a virtual local that doesn't actually exist in WebAssembly
3100
+ let scopedLocals = flow . scopedLocals ;
3101
+ if ( ! scopedLocals ) flow . scopedLocals = scopedLocals = new Map ( ) ;
3102
+ else if ( scopedLocals . has ( name ) ) {
3103
+ let existing = assert ( scopedLocals . get ( name ) ) ;
3104
+ this . errorRelated (
3105
+ DiagnosticCode . Duplicate_identifier_0 ,
3106
+ declaration . name . range ,
3107
+ existing . declaration . name . range ,
3108
+ name
3109
+ ) ;
3110
+ return this . module . unreachable ( ) ;
3111
+ }
3112
+ scopedLocals . set ( name , local ) ;
3113
+ isStatic = true ;
3109
3114
}
3110
- scopedLocals . set ( name , local ) ;
3111
- isStatic = true ;
3112
3115
}
3113
3116
} else {
3114
3117
this . error (
@@ -11035,8 +11038,6 @@ export class Compiler extends DiagnosticEmitter {
11035
11038
11036
11039
// helpers
11037
11040
11038
- const v128_zero = new Uint8Array ( 16 ) ;
11039
-
11040
11041
function mangleImportName (
11041
11042
element : Element ,
11042
11043
declaration : DeclarationStatement
0 commit comments