diff --git a/utils/wasmbin/wasmmodule.pas b/utils/wasmbin/wasmmodule.pas index 53bced0459..8426a5309a 100644 --- a/utils/wasmbin/wasmmodule.pas +++ b/utils/wasmbin/wasmmodule.pas @@ -114,9 +114,10 @@ type TWasmGlobal = class(TObject) public - id : TWasmId; - tp : byte; // byte; - value : TWasmInstrList; + id : TWasmId; + tp : byte; // byte; + isMutable : Boolean; // is mutable + value : TWasmInstrList; LinkInfo : TLinkInfo; ExportInfo : TExportInfo; function StartValue: TWasmInstrList; diff --git a/utils/wasmbin/watparser.pas b/utils/wasmbin/watparser.pas index dba13b7f76..6556a613f1 100644 --- a/utils/wasmbin/watparser.pas +++ b/utils/wasmbin/watparser.pas @@ -429,15 +429,25 @@ begin allowValue := false; end else if sc.token=weExport then begin // export - end else - ErrorExpectButFound(sc, 'import or export') + end; end; - if sc.token in WasmTypeTokens then begin - TokenTypeToValType(sc.token, dst.tp); + // parsing type. Global can be mutable type (mut i32) + + if (sc.token=weOpenBrace) then sc.Next; + if sc.token = weMut then begin + dst.isMutable := true; sc.Next; end; + if (sc.token in WasmTypeTokens) then begin + TokenTypeToValType(sc.token, dst.tp); + sc.Next; + end else + ErrorExpectButFound(sc, 'type'); + + if dst.isMutable then ConsumeToken(sc, weCloseBrace); + if allowValue and (sc.token = weOpenBrace) then begin sc.Next; ParseInstrList(sc, dst.StartValue);