|
@@ -195,7 +195,9 @@ begin
|
|
sc.Next;
|
|
sc.Next;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure ParseFuncParamResult(sc: TWatScanner; dst: TWasmFuncType);
|
|
|
|
|
|
+// lookForRefId (if true) parses for the case of (type 0)
|
|
|
|
+// (if false) just looks for (param i32) (result i32)
|
|
|
|
+procedure ParseTypeUse(sc: TWatScanner; dst: TWasmFuncType; lookForRefId: Boolean);
|
|
var
|
|
var
|
|
tk : TWatToken;
|
|
tk : TWatToken;
|
|
nm : integer;
|
|
nm : integer;
|
|
@@ -203,7 +205,7 @@ var
|
|
p : TWasmParam;
|
|
p : TWasmParam;
|
|
begin
|
|
begin
|
|
tk := sc.token;
|
|
tk := sc.token;
|
|
- if tk = weType then begin
|
|
|
|
|
|
+ if lookForRefId and (tk = weType) then begin
|
|
sc.Next;
|
|
sc.Next;
|
|
if not ParseNumOfId(sc, nm, id) then
|
|
if not ParseNumOfId(sc, nm, id) then
|
|
Exit;
|
|
Exit;
|
|
@@ -274,7 +276,7 @@ begin
|
|
// 2 - table reference index. Which should always be zero.
|
|
// 2 - table reference index. Which should always be zero.
|
|
ConsumeToken(sc, weOpenBrace);
|
|
ConsumeToken(sc, weOpenBrace);
|
|
ft := ci.addInstType;
|
|
ft := ci.addInstType;
|
|
- ParseFuncParamResult(sc, ft);
|
|
|
|
|
|
+ ParseTypeUse(sc, ft, true);
|
|
ci.operandNum := 0; // table reference index
|
|
ci.operandNum := 0; // table reference index
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -345,7 +347,7 @@ begin
|
|
ConsumeAnyOpenToken(sc, tk);
|
|
ConsumeAnyOpenToken(sc, tk);
|
|
|
|
|
|
if tk in [weType, weParam, weResult] then
|
|
if tk in [weType, weParam, weResult] then
|
|
- ParseFuncParamResult(sc, dst.functype);
|
|
|
|
|
|
+ ParseTypeUse(sc, dst.functype, true);
|
|
|
|
|
|
while tk = weLocal do begin
|
|
while tk = weLocal do begin
|
|
p:=dst.AddLocal;
|
|
p:=dst.AddLocal;
|
|
@@ -361,6 +363,24 @@ begin
|
|
ConsumeToken(sc, weCloseBrace);
|
|
ConsumeToken(sc, weCloseBrace);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure ParseTypeDef(sc: TWatScanner; dst: TWasmFuncType);
|
|
|
|
+begin
|
|
|
|
+ if sc.token=weType then sc.Next;
|
|
|
|
+
|
|
|
|
+ if (sc.token in [weNumber, weIdent]) then
|
|
|
|
+ ParseNumOfId(sc, dst.typeNum, dst.typeIdx);
|
|
|
|
+
|
|
|
|
+ ConsumeToken(sc, weOpenBrace);
|
|
|
|
+ ConsumeToken(sc, weFunc);
|
|
|
|
+
|
|
|
|
+ if (sc.token = weOpenBrace) then begin
|
|
|
|
+ sc.Next;
|
|
|
|
+ ParseTypeUse(sc, dst, false);
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ ConsumeToken(sc, weCloseBrace);
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure ParseData(sc: TWatScanner; dst: TWasmData);
|
|
procedure ParseData(sc: TWatScanner; dst: TWasmData);
|
|
var
|
|
var
|
|
l : integer;
|
|
l : integer;
|
|
@@ -533,6 +553,10 @@ begin
|
|
ParseData(sc, dst.AddData);
|
|
ParseData(sc, dst.AddData);
|
|
symlist.Clear;
|
|
symlist.Clear;
|
|
end;
|
|
end;
|
|
|
|
+ weType: begin
|
|
|
|
+ symlist.Clear;
|
|
|
|
+ ParseTypeDef(sc, dst.AddType);
|
|
|
|
+ end;
|
|
else
|
|
else
|
|
ErrorExpectButFound(sc, 'func', TokenStr[sc.token]);
|
|
ErrorExpectButFound(sc, 'func', TokenStr[sc.token]);
|
|
end;
|
|
end;
|