Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial JSON support #1741

Merged
merged 4 commits into from
Mar 28, 2021
Merged

Initial JSON support #1741

merged 4 commits into from
Mar 28, 2021

Conversation

aykevl
Copy link
Member

@aykevl aykevl commented Mar 24, 2021

This PR adds initial support for the encoding/json package. It is far from complete (structs don't work yet, for example) but it seems to actually work for encoding some trivial types.

They both reversed the direction of the check, in a way that mostly
cancelled each other out. Of course they're still mostly unimplemented,
but it's better if they're not wrong.
This is important as golden test output and to verify that the output is
correct. Later improvements and bug fixes are clearly visible in the IR,
and unintentional changes will also be immediately spotted.
This is required for correctly differentiating between interface types.
This commit adds a new transform that converts reflect Implements()
calls to runtime.interfaceImplements. At the moment, the Implements()
method is not yet implemented (how ironic) but if the value passed to
Implements is known at compile time the method call can be optimized to
runtime.interfaceImplements to make it a regular interface assert.

This commit is the last change necessary to add basic support for the
encoding/json package. The json package is certainly not yet fully
supported, but some trivial objects can be converted to JSON.
@deadprogram
Copy link
Member

Still much to be done, but a most impressive step forward, and with the unit tests to prove it. Good work @aykevl

Now merging.

@deadprogram deadprogram merged commit bcce296 into dev Mar 28, 2021
@deadprogram deadprogram deleted the json-2 branch March 28, 2021 12:00
@atdiar
Copy link

atdiar commented Mar 31, 2021

Does tinygo support the use of encoding/json for unmarshalling json formatted data into the basic go types (besides custom structs) now?
I need to unmarshal into map[string]interface{}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants