From 39c720778fd999a1bad4279cab1cd962de5adade Mon Sep 17 00:00:00 2001 From: nickysn Date: Mon, 3 Aug 2020 13:01:35 +0000 Subject: [PATCH] [PATCH 142/188] adding mutable flag for global variables From fdd0998697323727e0fbd4af6322eb305f1a8960 Mon Sep 17 00:00:00 2001 From: Dmitry Boyarintsev Date: Wed, 25 Mar 2020 11:24:36 -0400 git-svn-id: branches/wasm@46138 - --- utils/wasmbin/wasmmodule.pas | 7 ++++--- utils/wasmbin/watparser.pas | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) 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);