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

Meet host-defined functions registry #6

Merged
merged 1 commit into from
Feb 29, 2024
Merged

Meet host-defined functions registry #6

merged 1 commit into from
Feb 29, 2024

Conversation

orsinium
Copy link
Collaborator

Both wasman and wazero allow to define functions that accept a slice of raw ValueType as input and return a slice of raw ValueType as output. In both cases, the raw representation is the same and uses uint64 as the underlying type. Also, wazero requires all functions in a module to be defined in one go.

To solve code duplication issues and avoid using reflection in wazero, this PR introduces a Modules registry:

modules := funcs.Modules{
	"env": {
		"hello": funcs.F00(func() {
			println("I'm alive!")
		}),
	},
}

The registry is not used in any way in this PR yet but it will be used something like this (which will replace the current DefineFunc):

interpreter.Modules(modules)

@orsinium orsinium requested a review from deadprogram February 28, 2024 14:26
@deadprogram
Copy link
Member

I'd really like to preserve the ability to infer the call function to use based on the signature, e.g.

modules := funcs.Modules{
	"env": {
		"hello": helloFunc,
                "add": addFunc,
	},
}

func helloFunc() {
        println("I'm alive!")
}

func addFunc(x, y int32) int32 {
        return x+y
}

@orsinium
Copy link
Collaborator Author

orsinium commented Feb 28, 2024

I'd really like to preserve the ability to infer the call function to use based on the signature, e.g.

Can it be done without reflect?

What I do is not much different, you just need to wrap it which isn't too verbose:

modules := funcs.Modules{
	"env": {
		"hello": funcs.F00(helloFunc),
                "add": funcs.F21(addFunc),
	},
}

@deadprogram
Copy link
Member

Would be good to look at https://github.com/stealthrocket/wazergo for inspiration here?

@deadprogram
Copy link
Member

I think this is a great step in the direction we need, which is being able to be called from guest, and not needing reflection. Now merging, thanks @orsinium

@deadprogram deadprogram merged commit dfefe5a into main Feb 29, 2024
1 check passed
@deadprogram deadprogram deleted the funcs branch February 29, 2024 16:58
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.

2 participants