@@ -204,6 +204,8 @@ export class Options {
204
204
explicitStart : bool = false ;
205
205
/** Static memory start offset. */
206
206
memoryBase : i32 = 0 ;
207
+ /** Static table start offset. */
208
+ tableBase : i32 = 0 ;
207
209
/** Global aliases, mapping alias names as the key to internal names to be aliased as the value. */
208
210
globalAliases : Map < string , string > | null = null ;
209
211
/** Features to activate by default. These are the finished proposals. */
@@ -500,7 +502,9 @@ export class Compiler extends DiagnosticEmitter {
500
502
501
503
// set up function table (first elem is blank)
502
504
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 ) ) ;
504
508
505
509
// import and/or export table if requested (default table is named '0' by Binaryen)
506
510
if ( options . importTable ) {
@@ -992,7 +996,11 @@ export class Compiler extends DiagnosticEmitter {
992
996
993
997
// Initialize to zero if there's no initializer
994
998
} 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
+ }
996
1004
}
997
1005
998
1006
var internalName = global . internalName ;
@@ -1644,12 +1652,11 @@ export class Compiler extends DiagnosticEmitter {
1644
1652
ensureFunctionTableEntry ( instance : Function ) : i32 {
1645
1653
assert ( instance . is ( CommonFlags . COMPILED ) ) ;
1646
1654
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 ;
1651
1656
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 ;
1653
1660
if ( ! instance . is ( CommonFlags . TRAMPOLINE ) && instance . signature . requiredParameters < instance . signature . parameterTypes . length ) {
1654
1661
// insert the trampoline if the function has optional parameters
1655
1662
instance = this . ensureTrampoline ( instance ) ;
@@ -2990,7 +2997,7 @@ export class Compiler extends DiagnosticEmitter {
2990
2997
contextualType : Type ,
2991
2998
constraints : Constraints
2992
2999
) : ExpressionRef {
2993
- assert ( element . is ( CommonFlags . INLINED ) ) ;
3000
+ assert ( element . is ( CommonFlags . INLINED | CommonFlags . RESOLVED ) ) ;
2994
3001
var type = element . type ;
2995
3002
switch (
2996
3003
! ( constraints & ( Constraints . CONV_IMPLICIT | Constraints . CONV_EXPLICIT ) ) &&
0 commit comments