@@ -1310,63 +1310,82 @@ let transl_signature = (~functions, ~imports, signature) => {
13101310 },
13111311 imports. specs,
13121312 );
1313- let sign =
1314- List . map(
1315- fun
1316- | TSigValue (vid , {val_repr, val_internalpath} as vd ) => {
1317- let id =
1318- switch (val_internalpath) {
1319- | PIdent (id ) => id
1320- | PExternal (_ ) =>
1321- switch (Path_tbl . find_opt(imports. path_map, val_internalpath)) {
1322- | Some (id ) => id
1323- | None =>
1324- failwith (
1325- "Impossible: path to import not found "
1326- ++ Path . name(val_internalpath),
1327- )
1328- }
1329- };
1313+ let rec process_item = (~prefix= "" , item) => {
1314+ switch (item) {
1315+ | TSigValue (vid , {val_repr, val_internalpath} as vd ) =>
1316+ let id =
1317+ switch (val_internalpath) {
1318+ | PIdent (id ) => id
1319+ | PExternal (_ ) =>
1320+ switch (Path_tbl . find_opt(imports. path_map, val_internalpath)) {
1321+ | Some (id ) => id
1322+ | None =>
1323+ failwith (
1324+ "Impossible: path to import not found "
1325+ ++ Path . name(val_internalpath),
1326+ )
1327+ }
1328+ };
1329+ exports :=
1330+ [
1331+ WasmGlobalExport ({
1332+ ex_global_name: prefix ++ Ident . name(vid),
1333+ ex_global_internal_name: Ident . unique_name(id),
1334+ }),
1335+ ... exports^,
1336+ ] ;
1337+ switch (val_repr) {
1338+ | ReprFunction (args , rets , _ ) =>
1339+ switch (Ident_tbl . find_opt(func_map, id)) {
1340+ | Some (internal_name ) =>
1341+ let external_name = Ident . name(vid);
13301342 exports :=
13311343 [
1332- GlobalExport ({
1333- ex_global_name : Ident . name(vid) ,
1334- ex_global_internal_name : Ident . unique_name(id) ,
1344+ WasmFunctionExport ({
1345+ ex_function_name : prefix ++ external_name ,
1346+ ex_function_internal_name : internal_name ,
13351347 }),
13361348 ... exports^,
13371349 ] ;
1338- switch (val_repr) {
1339- | ReprFunction (args , rets , _ ) =>
1340- switch (Ident_tbl . find_opt(func_map, id)) {
1341- | Some (internal_name ) =>
1342- let external_name = Ident . name(vid);
1343- exports :=
1344- [
1345- FunctionExport ({
1346- ex_function_name: external_name,
1347- ex_function_internal_name: internal_name,
1348- }),
1349- ... exports^,
1350- ] ;
1351- TSigValue (
1352- vid,
1353- {
1354- ... vd,
1355- val_repr: ReprFunction (args, rets, Direct (external_name)),
1356- },
1357- );
1358- | _ =>
1359- TSigValue (
1360- vid,
1361- {... vd, val_repr: ReprFunction (args, rets, Indirect )},
1362- )
1363- }
1364- | ReprValue (_ ) => TSigValue (vid, vd)
1365- };
1350+ TSigValue (
1351+ vid,
1352+ {
1353+ ... vd,
1354+ val_repr: ReprFunction (args, rets, Direct (external_name)),
1355+ },
1356+ );
1357+ | _ =>
1358+ TSigValue (
1359+ vid,
1360+ {... vd, val_repr: ReprFunction (args, rets, Indirect )},
1361+ )
13661362 }
1367- | _ as item => item,
1368- signature. Cmi_format . cmi_sign,
1369- );
1363+ | ReprValue (_ ) => TSigValue (vid, vd)
1364+ };
1365+ | TSigModule (tid , decl , rs ) =>
1366+ let decl =
1367+ switch (decl. md_type) {
1368+ | TModIdent (_ )
1369+ | TModAlias (_ ) => decl
1370+ | TModSignature (_ ) when Option . is_some(decl. md_filepath) => decl
1371+ | TModSignature (signature ) => {
1372+ ... decl,
1373+ md_type:
1374+ TModSignature (
1375+ List . map(
1376+ process_item(
1377+ ~prefix= Printf . sprintf("% s % s ." , prefix, Ident . name(tid)),
1378+ ),
1379+ signature,
1380+ ),
1381+ ),
1382+ }
1383+ };
1384+ TSigModule (tid, decl, rs);
1385+ | _ as item => item
1386+ };
1387+ };
1388+ let sign = List . map(process_item, signature. Cmi_format . cmi_sign);
13701389 ({... signature, cmi_sign: sign}, exports^ );
13711390};
13721391
0 commit comments