Skip to content

Commit

Permalink
bindings/emscripten: add EIP-2537 serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
dot-asm committed Jun 13, 2024
1 parent 14da1a1 commit 4d9214b
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions bindings/emscripten/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,20 @@
{ return wrapPointer(_P1_Affine_to_jacobian_0(this.ptr), P1); };;
"""
p1_cpp += """
byte* EMSCRIPTEN_KEEPALIVE P1_Affine_serialize_eip2537_0(const P1_Affine* self)
{ byte out[128*1];
self->serialize_eip2537(out);
return out;
}
"""
p1_js += """
P1_Affine.prototype['serialize_eip2537'] = P1_Affine.prototype.serialize_eip2537 = /** @this{Object} */
function()
{ var out = _P1_Affine_serialize_eip2537_0(this.ptr);
return new Uint8Array(HEAPU8.subarray(out, out + 128*1));
};;
"""
p1_cpp += """
byte* EMSCRIPTEN_KEEPALIVE P1_Affine_serialize_0(const P1_Affine* self)
{ byte out[96*1];
self->serialize(out);
Expand Down Expand Up @@ -340,6 +354,20 @@
{ return wrapPointer(_P1_to_affine_0(this.ptr), P1_Affine); };;
"""
p1_cpp += """
byte* EMSCRIPTEN_KEEPALIVE P1_serialize_eip2537_0(const P1* self)
{ byte out[128*1];
self->serialize_eip2537(out);
return out;
}
"""
p1_js += """
P1.prototype['serialize_eip2537'] = P1.prototype.serialize_eip2537 = /** @this{Object} */
function()
{ var out = _P1_serialize_eip2537_0(this.ptr);
return new Uint8Array(HEAPU8.subarray(out, out + 96*1));
};;
"""
p1_cpp += """
byte* EMSCRIPTEN_KEEPALIVE P1_serialize_0(const P1* self)
{ byte out[96*1];
self->serialize(out);
Expand Down Expand Up @@ -1151,7 +1179,7 @@ def xchg_1vs2(matchobj):
print("//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", file=fd)
print(common_cpp, file=fd)
print(p1_cpp, file=fd)
print(re.sub(r'((?<!f)[pgPG\*])([12])', xchg_1vs2, p1_cpp), file=fd)
print(re.sub(r'((?<![if])[pgPG\*])([12])', xchg_1vs2, p1_cpp), file=fd)
print("}", file=fd) # close extern "C" {
fd.close()

Expand All @@ -1162,7 +1190,7 @@ def xchg_1vs2(matchobj):
print("//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", file=fd)
print(common_js, file=fd)
print(p1_js, file=fd)
print(re.sub(r'((?<!f)[pgPG\*])([12])', xchg_1vs2, p1_js), file=fd)
print(re.sub(r'((?<![if])[pgPG\*])([12])', xchg_1vs2, p1_js), file=fd)
fd.close()

subprocess.check_call([os.path.join(os.path.dirname(emcc), "tools", "webidl_binder"),
Expand Down

0 comments on commit 4d9214b

Please sign in to comment.