@@ -266,12 +266,10 @@ export class Compiler extends DiagnosticEmitter {
266266 this . startFunction = startFunctionInstance ;
267267 this . currentFunction = startFunctionInstance ;
268268
269- // compile entry file(s) while traversing to reachable elements
269+ // compile entry file(s) while traversing reachable elements
270270 var sources = program . sources ;
271271 for ( let i = 0 , k = sources . length ; i < k ; ++ i ) {
272- if ( sources [ i ] . isEntry ) {
273- this . compileSource ( sources [ i ] ) ;
274- }
272+ if ( sources [ i ] . isEntry ) this . compileSource ( sources [ i ] ) ;
275273 }
276274
277275 // compile the start function if not empty
@@ -326,7 +324,7 @@ export class Compiler extends DiagnosticEmitter {
326324 ) ;
327325 }
328326
329- // import memory if requested
327+ // import memory if requested (default memory is named '0' by Binaryen)
330328 if ( options . importMemory ) module . addMemoryImport ( "0" , "env" , "memory" ) ;
331329
332330 // set up function table
@@ -343,7 +341,7 @@ export class Compiler extends DiagnosticEmitter {
343341 functionTableExported = true ;
344342 }
345343
346- // import table if requested
344+ // import table if requested (default table is named '0' by Binaryen)
347345 if ( options . importTable ) {
348346 module . addTableImport ( "0" , "env" , "table" ) ;
349347 if ( ! functionTableExported ) module . addTableExport ( "0" , "table" ) ;
@@ -354,6 +352,7 @@ export class Compiler extends DiagnosticEmitter {
354352
355353 // sources
356354
355+ /** Compiles a source by looking it up by path first. */
357356 compileSourceByPath ( normalizedPathWithoutExtension : string , reportNode : Node ) : void {
358357 var source = this . program . lookupSourceByPath ( normalizedPathWithoutExtension ) ;
359358 if ( ! source ) {
@@ -366,8 +365,9 @@ export class Compiler extends DiagnosticEmitter {
366365 this . compileSource ( source ) ;
367366 }
368367
368+ /** Compiles a source. */
369369 compileSource ( source : Source ) : void {
370- if ( source . is ( CommonFlags . COMPILED ) ) return ;
370+ if ( source . is ( CommonFlags . COMPILED ) ) return ;
371371 source . set ( CommonFlags . COMPILED ) ;
372372
373373 // compile top-level statements
@@ -2098,12 +2098,16 @@ export class Compiler extends DiagnosticEmitter {
20982098 )
20992099 : this . module . createI64 ( 0 ) ;
21002100 }
2101+ case TypeKind . F64 : {
2102+ if ( ! ( element . is ( CommonFlags . BUILTIN ) && contextualType == Type . f32 ) ) {
2103+ return this . module . createF64 ( ( < VariableLikeElement > element ) . constantFloatValue ) ;
2104+ }
2105+ // otherwise fall-through: basically precomputes f32.demote/f64 of NaN / Infinity
2106+ this . currentType = Type . f32 ;
2107+ }
21012108 case TypeKind . F32 : {
21022109 return this . module . createF32 ( ( < VariableLikeElement > element ) . constantFloatValue ) ;
21032110 }
2104- case TypeKind . F64 : {
2105- return this . module . createF64 ( ( < VariableLikeElement > element ) . constantFloatValue ) ;
2106- }
21072111 default : {
21082112 assert ( false ) ;
21092113 return this . module . createUnreachable ( ) ;
@@ -2324,18 +2328,14 @@ export class Compiler extends DiagnosticEmitter {
23242328 expr = module . createUnary ( UnaryOp . TruncF32ToI64 , expr ) ;
23252329 } else {
23262330 expr = module . createUnary ( UnaryOp . TruncF32ToI32 , expr ) ;
2327- if ( toType . is ( TypeFlags . SMALL ) ) {
2328- expr = makeSmallIntegerWrap ( expr , toType , module ) ;
2329- }
2331+ if ( toType . is ( TypeFlags . SHORT ) ) expr = makeSmallIntegerWrap ( expr , toType , module ) ;
23302332 }
23312333 } else {
23322334 if ( toType . is ( TypeFlags . LONG ) ) {
23332335 expr = module . createUnary ( UnaryOp . TruncF32ToU64 , expr ) ;
23342336 } else {
23352337 expr = module . createUnary ( UnaryOp . TruncF32ToU32 , expr ) ;
2336- if ( toType . is ( TypeFlags . SMALL ) ) {
2337- expr = makeSmallIntegerWrap ( expr , toType , module ) ;
2338- }
2338+ if ( toType . is ( TypeFlags . SHORT ) ) expr = makeSmallIntegerWrap ( expr , toType , module ) ;
23392339 }
23402340 }
23412341
@@ -2346,18 +2346,14 @@ export class Compiler extends DiagnosticEmitter {
23462346 expr = module . createUnary ( UnaryOp . TruncF64ToI64 , expr ) ;
23472347 } else {
23482348 expr = module . createUnary ( UnaryOp . TruncF64ToI32 , expr ) ;
2349- if ( toType . is ( TypeFlags . SMALL ) ) {
2350- expr = makeSmallIntegerWrap ( expr , toType , module ) ;
2351- }
2349+ if ( toType . is ( TypeFlags . SHORT ) ) expr = makeSmallIntegerWrap ( expr , toType , module ) ;
23522350 }
23532351 } else {
23542352 if ( toType . is ( TypeFlags . LONG ) ) {
23552353 expr = module . createUnary ( UnaryOp . TruncF64ToU64 , expr ) ;
23562354 } else {
23572355 expr = module . createUnary ( UnaryOp . TruncF64ToU32 , expr ) ;
2358- if ( toType . is ( TypeFlags . SMALL ) ) {
2359- expr = makeSmallIntegerWrap ( expr , toType , module ) ;
2360- }
2356+ if ( toType . is ( TypeFlags . SHORT ) ) expr = makeSmallIntegerWrap ( expr , toType , module ) ;
23612357 }
23622358 }
23632359 }
@@ -2415,9 +2411,7 @@ export class Compiler extends DiagnosticEmitter {
24152411 // i64 to i32
24162412 if ( ! toType . is ( TypeFlags . LONG ) ) {
24172413 expr = module . createUnary ( UnaryOp . WrapI64 , expr ) ; // discards upper bits
2418- if ( toType . is ( TypeFlags . SMALL ) ) {
2419- expr = makeSmallIntegerWrap ( expr , toType , module ) ;
2420- }
2414+ if ( toType . is ( TypeFlags . SHORT ) ) expr = makeSmallIntegerWrap ( expr , toType , module ) ;
24212415 }
24222416
24232417 // i32 to i64
@@ -2426,7 +2420,7 @@ export class Compiler extends DiagnosticEmitter {
24262420
24272421 // i32 or smaller to even smaller or same size int with change of sign
24282422 } else if (
2429- toType . is ( TypeFlags . SMALL ) &&
2423+ toType . is ( TypeFlags . SHORT ) &&
24302424 (
24312425 fromType . size > toType . size ||
24322426 (
@@ -4097,7 +4091,7 @@ export class Compiler extends DiagnosticEmitter {
40974091 leftExpr = module . createTeeLocal ( tempLocal . index , leftExpr ) ;
40984092 }
40994093
4100- possiblyOverflows = this . currentType . is ( TypeFlags . SMALL | TypeFlags . INTEGER ) ;
4094+ possiblyOverflows = this . currentType . is ( TypeFlags . SHORT | TypeFlags . INTEGER ) ;
41014095 condExpr = makeIsTrueish ( leftExpr , this . currentType , module ) ;
41024096
41034097 // simplify when cloning left without side effects was successful
@@ -4143,7 +4137,7 @@ export class Compiler extends DiagnosticEmitter {
41434137 leftExpr = module . createTeeLocal ( tempLocal . index , leftExpr ) ;
41444138 }
41454139
4146- possiblyOverflows = this . currentType . is ( TypeFlags . SMALL | TypeFlags . INTEGER ) ; // if right did
4140+ possiblyOverflows = this . currentType . is ( TypeFlags . SHORT | TypeFlags . INTEGER ) ; // if right did
41474141 condExpr = makeIsTrueish ( leftExpr , this . currentType , module ) ;
41484142
41494143 // simplify when cloning left without side effects was successful
@@ -4179,7 +4173,7 @@ export class Compiler extends DiagnosticEmitter {
41794173 }
41804174 }
41814175 if ( possiblyOverflows && wrapSmallIntegers ) {
4182- assert ( this . currentType . is ( TypeFlags . SMALL | TypeFlags . INTEGER ) ) ; // must be a small int
4176+ assert ( this . currentType . is ( TypeFlags . SHORT | TypeFlags . INTEGER ) ) ; // must be a small int
41834177 expr = makeSmallIntegerWrap ( expr , this . currentType , module ) ;
41844178 }
41854179 return compound
@@ -6201,7 +6195,7 @@ export class Compiler extends DiagnosticEmitter {
62016195 }
62026196
62036197 if ( possiblyOverflows ) {
6204- assert ( currentType . is ( TypeFlags . SMALL | TypeFlags . INTEGER ) ) ;
6198+ assert ( currentType . is ( TypeFlags . SHORT | TypeFlags . INTEGER ) ) ;
62056199 setValue = makeSmallIntegerWrap ( setValue , currentType , module ) ;
62066200 }
62076201
@@ -6252,7 +6246,7 @@ export class Compiler extends DiagnosticEmitter {
62526246 false // wrapped below
62536247 ) ;
62546248 currentType = this . currentType ;
6255- possiblyOverflows = currentType . is ( TypeFlags . SMALL | TypeFlags . INTEGER ) ; // if operand already did
6249+ possiblyOverflows = currentType . is ( TypeFlags . SHORT | TypeFlags . INTEGER ) ; // if operand already did
62566250 break ;
62576251 }
62586252 case Token . MINUS : {
@@ -6553,7 +6547,7 @@ export class Compiler extends DiagnosticEmitter {
65536547 }
65546548 }
65556549 if ( possiblyOverflows && wrapSmallIntegers ) {
6556- assert ( currentType . is ( TypeFlags . SMALL | TypeFlags . INTEGER ) ) ;
6550+ assert ( currentType . is ( TypeFlags . SHORT | TypeFlags . INTEGER ) ) ;
65576551 expr = makeSmallIntegerWrap ( expr , currentType , module ) ;
65586552 }
65596553 return compound
0 commit comments