gluon-lang / gluon

A static, type inferred and embeddable language written in Rust.
https://gluon-lang.org
MIT License
3.16k stars 145 forks source link

Add bindings to useful rust libraries #118

Open Marwes opened 7 years ago

Marwes commented 7 years ago

The current standard library is extremely minimal and so lacks a lot of stuff one may expect from a standard library. Creating and maintaining libraries are a ton of work though but if we use the embedding API it should prove much simpler (and we also get native performance for free!).

These libraries do not necessarily need to be part of the standard distribution but bindings to these (or others!) would be really useful.

Marking as beginner since this should not require to deep knowledge of the internals, see the Tutorial on embedding and the primitives or the regex_bind module for how this is currently done. Also, it should be easier to start exporting APIs which do not require &mut references.

Marwes commented 7 years ago

Adding simple bindings to regex, starting with just match : String -> String -> Bool and building from there would be a good idea.

nxnfufunezn commented 7 years ago

I would like to take this!

Marwes commented 7 years ago

Awesome! I noticed I didn't mention where to put these modules. I think for now the best place is in the main gluon crate as a submodule as the io module is now.

Don't hesitate to ask if you run into problems.

nxnfufunezn commented 7 years ago

What type result should be... RuntimeResult<> ?

Marwes commented 7 years ago

RuntimResult is used to indicate a function which may do a 'gluon panic' such as in array_index. Just as Rust would panic when doing an out of bounds index on a slice so do gluon (but 'gluon panic' are implemented without 'rust panic').

Only use it if you need a panicking function (such as array_index), otherwise you can return a Result<T, E> instead.

// Pseudo Rust
fn array_index(a: Array<A>) -> RuntimeResult<A, String>

// gluon type when embedded.
array_index : Array a -> a
Marwes commented 7 years ago

Basic bindings to regex was added in #244. Extending this work with a find function should be possible without to much complexity.

Marwes commented 6 years ago

Big integers would be nice to have http://rust-num.github.io/num/num_bigint/index.html !

oovm commented 5 years ago

Big integers can have prim literal 0n and type BigInt.

https://github.com/gluon-lang/gluon/blob/7b4a5a9923e8c01ebcbd60645d987f640883d880/base/src/ast.rs#L215-L221

BigInt(num_bigint::BigInt)

https://github.com/gluon-lang/gluon/blob/7b44c202ef17f2974e18d0b5998ac847f684b652/base/src/types/mod.rs#L217-L232

But how to deal with the original Int(i64) if it is a built-in type

Etherian commented 4 years ago

How about std::Time bindings? I'll look into it if you think it's a good idea.

Marwes commented 4 years ago

std::time is a good idea :+1: (just about anything in std that is useful in some way would be).