Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

WIP: BridgeJS: Enum export support for multiple associated values of primitive types#434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@krodak
Copy link
Member

Introduction

This PR support for enums with associated values of primitive types to the BridgeJS plugin.

This is WIP just to discuss JS / Swift generated code side, I'm working on migrating this to new lifting / lowering approach and align with changes merged over last couple of days and will issue final PR soon.

In the meantime wanted to sync on

  • final d.ts interface
  • JS side shared helper + per enum helpers + use of additionaltmpRet = []; parameters - I'd integrate any feedback along migrating to new changes
  • Swift glue code - I'm moving shared_BJSBinaryReader and new extern methods toBridgeJSInstrincics.swift to align withmain updates, I'd integrate any feedback on those along the way as well

Overview

I've decided to go with DataView buffer to encode short type information and then payload, to pass single value across the boundaries and unpack it on the other side.

I started with single value primitives using what is currently available, then migrated to serializing parameters into JSON string and with current solution

Other option I've considered but rejected was to generate a separate WASM export function for each enum case - this eliminates the need for case dispatching and parameter packing, but on the other hand it would lead to WASM export explosion given that each case in each enum would end up as separate function and multiple associated values within single case would lead to unreadable long parameters chains.

Examples

Case Enum with Both Styles

@JSenumAPIResult{case success(String)case failure(Int)case flag(Bool)case rate(Float)case precise(Double)case info}@JSenumComplexResult{case success(String)case error(String,Int)case status(Bool,Int,String)case coordinates(Double,Double,Double)case comprehensive(Bool,Bool,Int,Int,Double,Double,String,String,String)case info}

Generated TypeScript:

exportconstAPIResult:{readonlyTag:{readonlySuccess:0;readonlyFailure:1;readonlyFlag:2;readonlyRate:3;readonlyPrecise:4;readonlyInfo:5;};};exporttypeAPIResult={tag:typeofAPIResult.Tag.Success;param0:string}|{tag:typeofAPIResult.Tag.Failure;param0:number}|{tag:typeofAPIResult.Tag.Flag;param0:boolean}|{tag:typeofAPIResult.Tag.Rate;param0:number}|{tag:typeofAPIResult.Tag.Precise;param0:number}|{tag:typeofAPIResult.Tag.Info}exportconstComplexResult:{readonlyTag:{readonlySuccess:0;readonlyError:1;readonlyStatus:2;readonlyCoordinates:3;readonlyComprehensive:4;readonlyInfo:5;};};exporttypeComplexResult={tag:typeofComplexResult.Tag.Success;param0:string}|{tag:typeofComplexResult.Tag.Error;param0:string;param1:number}|{tag:typeofComplexResult.Tag.Status;param0:boolean;param1:number;param2:string}|{tag:typeofComplexResult.Tag.Coordinates;param0:number;param1:number;param2:number}|{tag:typeofComplexResult.Tag.Comprehensive;param0:boolean;param1:boolean;param2:number;param3:number;param4:number;param5:number;param6:string;param7:string;param8:string}|{tag:typeofComplexResult.Tag.Info}

Testing

All tests are added, after mergingfix for nested types nesting and method calls are also working

Docs

Will be added in final PR after updating to accommodatemain changes

@krodakkrodak self-assigned thisAug 27, 2025
@krodak
Copy link
MemberAuthor

Closed in favor of#436

@krodakkrodak closed thisAug 27, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@kateinoigakukunkateinoigakukunAwaiting requested review from kateinoigakukun

Assignees

@krodakkrodak

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

@krodak

[8]ページ先頭

©2009-2025 Movatter.jp