@@ -204,6 +204,8 @@ export class Options {
204204 explicitStart : bool = false ;
205205 /** Static memory start offset. */
206206 memoryBase : i32 = 0 ;
207+ /** Static table start offset. */
208+ tableBase : i32 = 0 ;
207209 /** Global aliases, mapping alias names as the key to internal names to be aliased as the value. */
208210 globalAliases : Map < string , string > | null = null ;
209211 /** Features to activate by default. These are the finished proposals. */
@@ -500,7 +502,9 @@ export class Compiler extends DiagnosticEmitter {
500502
501503 // set up function table (first elem is blank)
502504 var functionTable = this . functionTable ;
503- module . setFunctionTable ( 1 + functionTable . length , Module . UNLIMITED_TABLE , functionTable , module . i32 ( 1 ) ) ;
505+ var tableBase = this . options . tableBase ;
506+ if ( ! tableBase ) tableBase = 1 ; // leave first elem blank
507+ module . setFunctionTable ( tableBase + functionTable . length , Module . UNLIMITED_TABLE , functionTable , module . i32 ( tableBase ) ) ;
504508
505509 // import and/or export table if requested (default table is named '0' by Binaryen)
506510 if ( options . importTable ) {
@@ -992,7 +996,11 @@ export class Compiler extends DiagnosticEmitter {
992996
993997 // Initialize to zero if there's no initializer
994998 } else {
995- initExpr = this . makeZero ( type ) ;
999+ if ( global . is ( CommonFlags . INLINED ) ) {
1000+ initExpr = this . compileInlineConstant ( global , global . type , Constraints . PREFER_STATIC | Constraints . WILL_RETAIN ) ;
1001+ } else {
1002+ initExpr = this . makeZero ( type ) ;
1003+ }
9961004 }
9971005
9981006 var internalName = global . internalName ;
@@ -1644,12 +1652,11 @@ export class Compiler extends DiagnosticEmitter {
16441652 ensureFunctionTableEntry ( instance : Function ) : i32 {
16451653 assert ( instance . is ( CommonFlags . COMPILED ) ) ;
16461654 var index = instance . functionTableIndex ;
1647- if ( index >= 0 ) {
1648- assert ( index != 0 ) ; // first elem must be blank
1649- return index ;
1650- }
1655+ if ( index >= 0 ) return index ;
16511656 var functionTable = this . functionTable ;
1652- index = 1 + functionTable . length ; // first elem is blank
1657+ var tableBase = this . options . tableBase ;
1658+ if ( ! tableBase ) tableBase = 1 ; // leave first elem blank
1659+ index = tableBase + functionTable . length ;
16531660 if ( ! instance . is ( CommonFlags . TRAMPOLINE ) && instance . signature . requiredParameters < instance . signature . parameterTypes . length ) {
16541661 // insert the trampoline if the function has optional parameters
16551662 instance = this . ensureTrampoline ( instance ) ;
@@ -2990,7 +2997,7 @@ export class Compiler extends DiagnosticEmitter {
29902997 contextualType : Type ,
29912998 constraints : Constraints
29922999 ) : ExpressionRef {
2993- assert ( element . is ( CommonFlags . INLINED ) ) ;
3000+ assert ( element . is ( CommonFlags . INLINED | CommonFlags . RESOLVED ) ) ;
29943001 var type = element . type ;
29953002 switch (
29963003 ! ( constraints & ( Constraints . CONV_IMPLICIT | Constraints . CONV_EXPLICIT ) ) &&
0 commit comments