@@ -173,6 +173,8 @@ and al_to_heaptype: value -> heaptype = function
173173 | v -> error_value " heaptype" v
174174
175175and al_to_reftype: value -> reftype = function
176+ | CaseV ("FUNCREF" , [] ) -> Null , FuncHT
177+ | CaseV ("EXTERNREF" , [] ) -> Null , ExternHT
176178 | CaseV ("REF" , [ n ; ht ]) -> al_to_null n, al_to_heaptype ht
177179 | v -> error_value " reftype" v
178180
@@ -197,11 +199,12 @@ and al_to_valtype: value -> valtype = function
197199 | CaseV (" I32" , _) | CaseV (" I64" , _)
198200 | CaseV ("F32" , _ ) | CaseV ("F64" , _ ) as v -> NumT (al_to_numtype v)
199201 | CaseV ("V128" , [] ) -> VecT V128T
200- | CaseV ("REF" , _ ) as v -> RefT (al_to_reftype v)
202+ | CaseV (( "REF" | "FUNCREF" | "EXTERNREF" ) , _ ) as v -> RefT (al_to_reftype v)
201203 | CaseV ("BOT" , [] ) -> BotT
202204 | v -> error_value " valtype" v
203205
204206let al_to_blocktype: value -> blocktype = function
207+ | OptV _ as v when ! version = 1 -> ValBlockType (al_to_opt al_to_valtype v)
205208 | CaseV ("_IDX" , [ idx ]) -> VarBlockType (al_to_idx idx)
206209 | CaseV ("_RESULT" , [ vt_opt ]) -> ValBlockType (al_to_opt al_to_valtype vt_opt)
207210 | v -> error_value " blocktype" v
@@ -216,10 +219,14 @@ let al_to_globaltype: value -> globaltype = function
216219 | v -> error_value " globaltype" v
217220
218221let al_to_tabletype: value -> tabletype = function
222+ | CaseV ("[" , _ ) as v when ! version = 1 -> TableT (I32AT , al_to_limits v, (Null , FuncHT ))
223+ | TupV [ limits; rt ] | CaseV ("" , [ limits ; rt ]) -> TableT (I32AT , al_to_limits limits, al_to_reftype rt)
219224 | TupV [ at; limits; rt ] | CaseV (_ , [ at ; limits ; rt ]) -> TableT (al_to_addrtype at, al_to_limits limits, al_to_reftype rt)
220225 | v -> error_value " tabletype" v
221226
222227let al_to_memorytype: value -> memorytype = function
228+ | CaseV ("[" , _ ) as v when ! version = 1 -> MemoryT (I32AT , al_to_limits v)
229+ | CaseV ("PAGE" , [ limits ]) -> MemoryT (I32AT , al_to_limits limits)
223230 | CaseV ("PAGE" , [ at ; limits ]) -> MemoryT (al_to_addrtype at, al_to_limits limits)
224231 | v -> error_value " memorytype" v
225232
@@ -792,6 +799,8 @@ and al_to_instr': value -> Ast.instr' = function
792799 | CaseV ("RETURN" , [] ) -> Return
793800 | CaseV ("CALL" , [ idx ]) -> Call (al_to_idx idx)
794801 | CaseV ("CALL_REF" , [ typeuse ]) -> CallRef (al_to_idx_of_typeuse typeuse)
802+ | CaseV ("CALL_INDIRECT" , [ idx ]) when ! version = 1 ->
803+ CallIndirect (0l @@ no_region, al_to_idx idx)
795804 | CaseV ("CALL_INDIRECT" , [ idx1 ; typeuse2 ]) ->
796805 CallIndirect (al_to_idx idx1, al_to_idx_of_typeuse typeuse2)
797806 | CaseV ("RETURN_CALL" , [ idx ]) -> ReturnCall (al_to_idx idx)
@@ -810,8 +819,13 @@ and al_to_instr': value -> Ast.instr' = function
810819 | CaseV ("VSTORE" , vstoreop ) -> let idx, op = al_to_vstoreop vstoreop in VecStore (idx, op)
811820 | CaseV ("VSTORE_LANE" , vlaneop ) ->
812821 let idx, op, i = al_to_vlaneop vlaneop in VecStoreLane (idx, op, i)
822+ | CaseV ("MEMORY.SIZE" , [] ) when ! version < = 2 -> MemorySize (0l @@ no_region)
823+ | CaseV ("MEMORY.GROW" , [] ) when ! version < = 2 -> MemoryGrow (0l @@ no_region)
813824 | CaseV ("MEMORY.SIZE" , [ idx ]) -> MemorySize (al_to_idx idx)
814825 | CaseV ("MEMORY.GROW" , [ idx ]) -> MemoryGrow (al_to_idx idx)
826+ | CaseV ("MEMORY.FILL" , [] ) when ! version < = 2 -> MemoryFill (0l @@ no_region)
827+ | CaseV ("MEMORY.COPY" , [] ) when ! version < = 2 -> MemoryCopy (0l @@ no_region, 0l @@ no_region)
828+ | CaseV ("MEMORY.INIT" , [ idx ]) when ! version < = 2 -> MemoryInit (0l @@ no_region, al_to_idx idx)
815829 | CaseV ("MEMORY.FILL" , [ idx ]) -> MemoryFill (al_to_idx idx)
816830 | CaseV ("MEMORY.COPY" , [ idx1 ; idx2 ]) -> MemoryCopy (al_to_idx idx1, al_to_idx idx2)
817831 | CaseV ("MEMORY.INIT" , [ idx1 ; idx2 ]) -> MemoryInit (al_to_idx idx1, al_to_idx idx2)
@@ -855,6 +869,8 @@ let al_to_const: value -> const = al_to_list al_to_instr |> al_to_phrase
855869(* Deconstruct module *)
856870
857871let al_to_type: value -> type_ = function
872+ | CaseV ("TYPE" , [ ft ]) when ! version < = 2 ->
873+ RecT [SubT (Final , [] , al_to_comptype ft)] @@ no_region
858874 | CaseV ("TYPE" , [ rt ]) -> al_to_phrase al_to_rectype rt
859875 | v -> error_value " type" v
860876
@@ -876,6 +892,10 @@ let al_to_global': value -> global' = function
876892let al_to_global: value -> global = al_to_phrase al_to_global'
877893
878894let al_to_table': value -> table' = function
895+ | CaseV ("TABLE" , [ tt ]) when ! version < = 2 ->
896+ let TableT (_, _, rt) as tt' = al_to_tabletype tt in
897+ let _, ht = rt in
898+ Table (tt', [RefNull ht @@ no_region] @@ no_region)
879899 | CaseV ("TABLE" , [ tt ; const ]) ->
880900 Table (al_to_tabletype tt, al_to_const const)
881901 | v -> error_value " table" v
@@ -899,18 +919,26 @@ let al_to_segmentmode': value -> segmentmode' = function
899919let al_to_segmentmode: value -> segmentmode = al_to_phrase al_to_segmentmode'
900920
901921let al_to_elem': value -> elem' = function
922+ | CaseV ("ELEM" , [ offset ; indices ]) when ! version = 1 ->
923+ let const x = [RefFunc (al_to_idx x) @@ no_region] @@ no_region in
924+ Elem ((Null , FuncHT ), al_to_list const indices,
925+ Active (0l @@ no_region, al_to_const offset) @@ no_region)
902926 | CaseV ("ELEM" , [ rt ; consts ; mode ]) ->
903927 Elem (al_to_reftype rt, al_to_list al_to_const consts, al_to_segmentmode mode)
904928 | v -> error_value " elem" v
905929let al_to_elem: value -> elem = al_to_phrase al_to_elem'
906930
907931let al_to_data': value -> data' = function
932+ | CaseV ("DATA" , [ offset ; bytes ]) when ! version = 1 ->
933+ Data (al_to_bytes bytes, Active (0l @@ no_region, al_to_const offset) @@ no_region)
908934 | CaseV ("DATA" , [ bytes ; mode ]) ->
909935 Data (al_to_bytes bytes, al_to_segmentmode mode)
910936 | v -> error_value " data" v
911937let al_to_data: value -> data = al_to_phrase al_to_data'
912938
913939let al_to_externtype = function
940+ | CaseV ("FUNC" , [CaseV ("->" , _ ) as ft ]) when ! version < = 2 ->
941+ ExternFuncT (Def (DefT (RecT [SubT (Final , [] , al_to_comptype ft)], 0l )))
914942 | CaseV ("FUNC" , [typeuse ]) -> ExternFuncT (al_to_typeuse typeuse)
915943 | CaseV ("GLOBAL" , [globaltype ]) -> ExternGlobalT (al_to_globaltype globaltype)
916944 | CaseV ("TABLE" , [tabletype ]) -> ExternTableT (al_to_tabletype tabletype)
@@ -1973,6 +2001,8 @@ let al_of_data data =
19732001
19742002
19752003let al_of_externtype = function
2004+ | ExternFuncT (Def dt ) when ! version < = 2 ->
2005+ CaseV (" FUNC" , [al_of_comptype (Types. expand_deftype dt)])
19762006 | ExternFuncT (typeuse ) -> CaseV (" FUNC" , [al_of_typeuse typeuse])
19772007 | ExternGlobalT (globaltype ) -> CaseV (" GLOBAL" , [al_of_globaltype globaltype])
19782008 | ExternTableT (tabletype ) -> CaseV (" TABLE" , [al_of_tabletype tabletype])
0 commit comments