Skip to content

Commit 1442779

Browse files
committed
Use cabi_ prefix instead of _ and use _ instead if - in post-return function
1 parent 0c42906 commit 1442779

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

design/mvp/CanonicalABI.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,18 +1359,18 @@ def canonical_module_type(ct: ComponentType) -> ModuleType:
13591359
imports.append(CoreImportDecl('', mangle_funcname(name, ft), flat_ft))
13601360

13611361
exports = []
1362-
exports.append(CoreExportDecl('_memory', CoreMemoryType(initial=0, maximum=None)))
1363-
exports.append(CoreExportDecl('_realloc', CoreFuncType(['i32','i32','i32','i32'], ['i32'])))
1362+
exports.append(CoreExportDecl('cabi_memory', CoreMemoryType(initial=0, maximum=None)))
1363+
exports.append(CoreExportDecl('cabi_realloc', CoreFuncType(['i32','i32','i32','i32'], ['i32'])))
13641364

13651365
start_ft = FuncType(start_params, start_results)
1366-
start_name = mangle_funcname('_start{cabi=' + CABI_VERSION + '}', start_ft)
1366+
start_name = mangle_funcname('cabi_start{cabi=' + CABI_VERSION + '}', start_ft)
13671367
exports.append(CoreExportDecl(start_name, flatten_functype(start_ft, 'lift')))
13681368

13691369
for name,ft in export_funcs:
13701370
flat_ft = flatten_functype(ft, 'lift')
13711371
exports.append(CoreExportDecl(mangle_funcname(name, ft), flat_ft))
13721372
if any(contains_dynamic_allocation(t) for t in ft.results):
1373-
exports.append(CoreExportDecl('_post-' + name, CoreFuncType(flat_ft.results, [])))
1373+
exports.append(CoreExportDecl('cabi_post_' + name, CoreFuncType(flat_ft.results, [])))
13741374

13751375
return ModuleType(imports, exports)
13761376

@@ -1389,15 +1389,15 @@ import/export with the function type mangled into the name. Additionally, each
13891389
export whose return type implies possible dynamic allocation is given a
13901390
`post-return` function so that it can deallocate after the caller reads the
13911391
return value. Lastly, all value imports and exports are concatenated into a
1392-
synthetic `_start` function that is called immediately after instantiation.
1392+
synthetic `cabi_start` function that is called immediately after instantiation.
13931393

13941394
For imports (which in Core WebAssembly are [two-level]), the first-level name
13951395
is set to be a zero-length string so that the entire rest of the first-level
13961396
string space is available for [shared-everything linking].
13971397

13981398
For imports and exports, the Canonical ABI assumes that `_` is not a valid
1399-
first character in a component-level import/export (as is currently the case in
1400-
`wit` [identifiers](WIT.md#identifiers)) and thus can safely be used to prefix
1399+
character in a component-level import/export (as is currently the case in `wit`
1400+
[identifiers](WIT.md#identifiers)) and thus can safely be used to prefix
14011401
auxiliary Canonical ABI-induced imports/exports.
14021402

14031403
Instance-mangling recursively builds a dotted path string (of instance names)

design/mvp/canonical-abi/definitions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,18 +1029,18 @@ def canonical_module_type(ct: ComponentType) -> ModuleType:
10291029
imports.append(CoreImportDecl('', mangle_funcname(name, ft), flat_ft))
10301030

10311031
exports = []
1032-
exports.append(CoreExportDecl('_memory', CoreMemoryType(initial=0, maximum=None)))
1033-
exports.append(CoreExportDecl('_realloc', CoreFuncType(['i32','i32','i32','i32'], ['i32'])))
1032+
exports.append(CoreExportDecl('cabi_memory', CoreMemoryType(initial=0, maximum=None)))
1033+
exports.append(CoreExportDecl('cabi_realloc', CoreFuncType(['i32','i32','i32','i32'], ['i32'])))
10341034

10351035
start_ft = FuncType(start_params, start_results)
1036-
start_name = mangle_funcname('_start{cabi=' + CABI_VERSION + '}', start_ft)
1036+
start_name = mangle_funcname('cabi_start{cabi=' + CABI_VERSION + '}', start_ft)
10371037
exports.append(CoreExportDecl(start_name, flatten_functype(start_ft, 'lift')))
10381038

10391039
for name,ft in export_funcs:
10401040
flat_ft = flatten_functype(ft, 'lift')
10411041
exports.append(CoreExportDecl(mangle_funcname(name, ft), flat_ft))
10421042
if any(contains_dynamic_allocation(t) for t in ft.results):
1043-
exports.append(CoreExportDecl('_post-' + name, CoreFuncType(flat_ft.results, [])))
1043+
exports.append(CoreExportDecl('cabi_post_' + name, CoreFuncType(flat_ft.results, [])))
10441044

10451045
return ModuleType(imports, exports)
10461046

design/mvp/canonical-abi/run_tests.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,9 @@ def test_cabi(ct, expect):
409409
),
410410
ModuleType(
411411
[CoreImportDecl('','a: func u8 -> u8', CoreFuncType(['i32'],['i32']))],
412-
[CoreExportDecl('_memory', CoreMemoryType(0, None)),
413-
CoreExportDecl('_realloc', CoreFuncType(['i32','i32','i32','i32'],['i32'])),
414-
CoreExportDecl('_start{cabi=0.1}: func (b:string) -> (d:list<u8>)',
412+
[CoreExportDecl('cabi_memory', CoreMemoryType(0, None)),
413+
CoreExportDecl('cabi_realloc', CoreFuncType(['i32','i32','i32','i32'],['i32'])),
414+
CoreExportDecl('cabi_start{cabi=0.1}: func (b:string) -> (d:list<u8>)',
415415
CoreFuncType(['i32','i32'],['i32'])),
416416
CoreExportDecl('c: func s8 -> s8', CoreFuncType(['i32'],['i32']))]
417417
)
@@ -429,12 +429,12 @@ def test_cabi(ct, expect):
429429
),
430430
ModuleType(
431431
[CoreImportDecl('','a.b: func u8 -> u8', CoreFuncType(['i32'],['i32']))],
432-
[CoreExportDecl('_memory', CoreMemoryType(0, None)),
433-
CoreExportDecl('_realloc', CoreFuncType(['i32','i32','i32','i32'],['i32'])),
434-
CoreExportDecl('_start{cabi=0.1}: func (a.c:float32) -> (d.f:float64)',
432+
[CoreExportDecl('cabi_memory', CoreMemoryType(0, None)),
433+
CoreExportDecl('cabi_realloc', CoreFuncType(['i32','i32','i32','i32'],['i32'])),
434+
CoreExportDecl('cabi_start{cabi=0.1}: func (a.c:float32) -> (d.f:float64)',
435435
CoreFuncType(['f32'],['f64'])),
436436
CoreExportDecl('d.e: func () -> list<string>', CoreFuncType([],['i32'])),
437-
CoreExportDecl('_post-d.e', CoreFuncType(['i32'],[]))]
437+
CoreExportDecl('cabi_post_d.e', CoreFuncType(['i32'],[]))]
438438
)
439439
)
440440
test_cabi( # from CanonicalABI.md
@@ -450,12 +450,12 @@ def test_cabi(ct, expect):
450450
ModuleType(
451451
[CoreImportDecl('','foo: func () -> ()', CoreFuncType([],[])),
452452
CoreImportDecl('','a.bar: func (x:u32, y:u32) -> u32', CoreFuncType(['i32','i32'],['i32']))],
453-
[CoreExportDecl('_memory', CoreMemoryType(0, None)),
454-
CoreExportDecl('_realloc', CoreFuncType(['i32','i32','i32','i32'],['i32'])),
455-
CoreExportDecl('_start{cabi=0.1}: func (v1:string) -> (v2:list<list<string>>)',
453+
[CoreExportDecl('cabi_memory', CoreMemoryType(0, None)),
454+
CoreExportDecl('cabi_realloc', CoreFuncType(['i32','i32','i32','i32'],['i32'])),
455+
CoreExportDecl('cabi_start{cabi=0.1}: func (v1:string) -> (v2:list<list<string>>)',
456456
CoreFuncType(['i32','i32'],['i32'])),
457457
CoreExportDecl('baz: func () -> string', CoreFuncType([],['i32'])),
458-
CoreExportDecl('_post-baz', CoreFuncType(['i32'],[]))]
458+
CoreExportDecl('cabi_post_baz', CoreFuncType(['i32'],[]))]
459459
)
460460
)
461461

0 commit comments

Comments
 (0)