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

Generate Go code from WIT representation #12

Closed
wants to merge 1 commit into from
Closed

Generate Go code from WIT representation #12

wants to merge 1 commit into from

Conversation

ydnar
Copy link
Collaborator

@ydnar ydnar commented Oct 26, 2023

This PR is a WIP for generating Go code from the JSON representation of fully-resolved WIT file(s).

@ydnar ydnar self-assigned this Oct 27, 2023
@ydnar ydnar force-pushed the ydnar/gen branch 3 times, most recently from d901ee3 to 0d72040 Compare November 2, 2023 17:47
@ydnar ydnar force-pushed the ydnar/gen branch 5 times, most recently from 1fcf13f to 603259f Compare January 28, 2024 02:43
@ydnar ydnar force-pushed the ydnar/gen branch 5 times, most recently from e82d774 to 51ee738 Compare February 9, 2024 00:58
wit: ID type

This will be removed in a future commit.

wit/gen: add Package.Decls

internal/go/gen, bindgen, wit: refactor

bindgen: Option types

bindgen: initial commit of func Go()

cmd/wit-bindgen-go: syntax -> wit

cmd/wit-bindgen-go: add basic generate command

internal/go/gen: Ident type

bindgen, internal/go, wit: WIP

Generating valid Go names from WIT names:
1. Scan for an explicit mapping, e.g. wasi:clocks/wall-clock -> wasi/clocks/wallclock
2. Perform string conversion, e.g. : -> /, strip -
3. (optional) validate short package name as valid Go identifier
4. Check against list of Go reserved words
5. For decl names, convert to Go-style names (TitleCase), check against existing decl

bindgen, internal/go: WIP

cmd/wit-bindgen-go: add --map wit=go ... flag

bindgen, cmd/wit-bindgen-go: implement generated by for DO NOT EDIT comment

internal/design: stab at what a generated interface for wasi:clocks/wall-clock could look like

_design: multiple Go modules

_design: WIP for imported and exported type

_design/import-and-export: add README

_design/import-and-export: fix typo

bindgen, wit: WIP

remove go.work and secondary go.mod file

_design -> design, with go:build tags

wasm/cm: importable Component Model primitive types

design/wasi/io/poll: hand-rolled example for wasi:io/poll

design/wasi/io/poll: right ABI?

design/import-and-export: remove build tags where not necessary

design/wasi/io: update WIP

design/wasi/io/poll: improve comments

design/wasi/io/poll: wasmexport methods should call the real methods on the type

design/wasi/io: add world.wit source

design: reorganized

design/{export,import}: further explorations

design/export/wasi/io/poll: exploring own/borrow semantics

wasm/cm: Resource, Handle, Own, Borrow types

wasm/cm: Resource, Handle, Own, Borrow types

design: further experimentation

cabi, design: post-return function to free allocated memory

wasm/cabi: combine cabi and wasm/cm packages

wasm/cabi: update README links

cmd/wit-bindgen-go/cmd/generate: update to github.com/urfave/cli/v3 API changes

cabi, design: move cabi back out of wasm directory

cabi: add some TODOs

wit: rename PackageName to ID; add extension (world, interface)

bindgen, wit: update use of ID

wit, testdata: ID -> Ident

internal/go/gen: fix test

wit: move Ident to ident.go and add tests

bidngen, internal/go/gen: start generating Go names

bindgen, internal/go/gen: more Go code generation; WIP

cmd/wit-bindgen-go/cmd/generate, internal/go/gen: PackagePath function to load go.mod file

cmd/wit-bindgen-go/cmd/generate: add -o flag

internal/go/gen: Unique name generator

internal/go/gen: add package, file, import manipulation

bindgen, cmd/wit-bindgen-go/cmd/generate: PackageRoot option

bindgen, wit: generate multiple Go packages

design/wasi/io/streams: try version directories

bindgen: WIP on package path and name generation

bindgen: update comments

bindgen: WIP

bindgen, cmd/wit-bindgen-go/cmd/generate: remove - from Go package paths

wit: fix typo

bindgen: WIP emitting Go names for types in correct packages

bindgen: emit functions; WIP

bindgen: remove packageForWorld method

bindgen: fake wasmimport lines

bindgen: add TODO about mapping WIT functions and typedefs to Go decls

internal/go/gen: replace Imports type with Imports func

bindgen: export Go name helpers

bindgen: rename isSep to notLetterDigit

internal/go/gen: rename AddImport to Import

bindgen, internal/go/gen: update Unique function

internal/go/gen: NewFile -> File

bindgen, internal/go/gen: update AddDecl

bindgen, internal/go/gen: Decl returns Decl{}

bindgen: map wit.TypeDef and wit.Function to gen.Decl

bindgen: update comments

cmd/wit-bindgen-go/cmd/generate: note generated package list

internal/go/gen: remove File.ImportDecls

internal/go/gen: FormatDocComments

bindgen, cmd/wit-bindgen-go/cmd/generate, internal/go/gen: generate Go code into individual files in packages

Write doc comments from WIT into files; set type aliases to any // TODO

bindgen: serialize WIT docs into Go doc comments for types and functions

bindgen: start breaking out type generation

bindgen: rearrange deck chairs

bindgen: stub out option<T>

internal/go/gen: use golang.org/x/mod/modfile

internal/go/gen: require IsGo for HasPackageDocs

internal/go/gen: reorganize

wit: omit doc comments when ctx == nil

bindgen: print WIT definition in doc comments for each type

wit: use tab indentation instead of 4 spaces

This is necessary for Go doc comments that embed original WIT definition.

testdata: regenerate with tab indentation

bindgen: declare types before defining them

wit: test that all TypeDef roots have named owners

Anonymous interfaces can use types, but should point to a type owned by a named interface.

design/wasi/io/poll/exports: update design for exported interfaces

cabi: tweak
@ydnar ydnar closed this Feb 9, 2024
@ydnar ydnar deleted the ydnar/gen branch February 9, 2024 01:06
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.

1 participant