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

Foreign Function Import #25

Open
keean opened this issue Oct 4, 2016 · 6 comments
Open

Foreign Function Import #25

keean opened this issue Oct 4, 2016 · 6 comments

Comments

@keean
Copy link
Owner

keean commented Oct 4, 2016

This issue is for discussing the mechanism that will be used for interfacing and importing foreign functions.

@keean keean mentioned this issue Oct 4, 2016
@keean
Copy link
Owner Author

keean commented Oct 4, 2016

I don't understand. You have to have a way to lift types and functions out of Javascript into Zenscript. There are only two realistic options:

Provide binding syntax. I explained above it is useful to hand craft bindings. This does not preclude auto generation of the bindings. For Felix I autogenerated bindings for some huge libraries. And then spent weeks fixing them.
The binding constructions have to part of the language.

Allow naked JS. I don't think this is what you want.
If there's another option, I don't know what it is.

The other option is to have the type system span both languages. So we can directly give types to some JavaScript functions. Then we just import them and give a type signature.

@keean
Copy link
Owner Author

keean commented Oct 4, 2016

I an going to start with this simple syntax:

foreign console.log(String) : ()

To bring the foreign function into scope with the specified type.

@shelby3
Copy link

shelby3 commented Oct 4, 2016

@keean wrote:

So we can directly give types to some JavaScript functions.

The type of JavaScript stuff is always any and thus we can't do anything with it in our type system unless we are just writing and not reading. For reading in values, we must have wrappers that actually check values at runtime and enforce the types it assigns to them.

Also on writing we may need to do conversion for example to Number, unless we have a Number type in our language which models the JavaScript type.

@keean
Copy link
Owner Author

keean commented Oct 4, 2016

The type of JavaScript stuff is always any and thus we can't do anything with it in our type system. We have to have wrappers that actually check values at runtime and enforce the types it assigns to them.

Not when you are calling out. Calling JS from Zen we control the types that are given to the function, so if you declare colsole.log takes a String, you will only be able to pass a string to it.

For return values we would give them a datatype with runtime tags, so they would get assigned into a disjoint union and you can match on the type in Zen.

I would have a builtin datatype like this:

data JSType = Undefined | Null | Boolean(Boolean) | Number(Float) | String(String) | Symbol(String)

Function types and object types will need a bit more thought.

@shelby3
Copy link

shelby3 commented Oct 5, 2016

Are we sure a JavaScript Number is equivalent to the native Float type on CPUs? I assume we want to use a native type?

@keean
Copy link
Owner Author

keean commented Oct 5, 2016

@shelby3 it might be a double, I will check, but the principle is this will let us write any wrapper code for native inside our language where things are type safe.

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

No branches or pull requests

2 participants