Skip to content

Commit

Permalink
fix: Refer to registered types by their full name
Browse files Browse the repository at this point in the history
BREAKING CHANGE

```
vm.register_type::<MyType>("test.MyType");
vm.find_type_info("MyType"); // ERROR
vm.find_type_info("test.MyType"); // OK
```
  • Loading branch information
Marwes committed Apr 21, 2019
1 parent 602220b commit a2daace
Show file tree
Hide file tree
Showing 25 changed files with 138 additions and 97 deletions.
3 changes: 2 additions & 1 deletion examples/marshalling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ fn marshal_wrapper() -> Result<()> {
Ok(())
}

#[derive(Userdata, Debug, Clone)]
#[derive(Userdata, Debug, Clone, VmType)]
#[gluon(vm_type = "WindowHandle")]
struct WindowHandle {
id: Arc<u64>,
metadata: Arc<str>,
Expand Down
6 changes: 4 additions & 2 deletions repl/src/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,16 @@ macro_rules! impl_userdata {
};
}

#[derive(Userdata)]
#[derive(Userdata, VmType)]
#[gluon(vm_type = "Editor")]
struct Editor {
editor: Mutex<rustyline::Editor<Completer>>,
}

impl_userdata! { Editor }

#[derive(Userdata)]
#[derive(Userdata, VmType)]
#[gluon(vm_type = "CpuPool")]
struct CpuPool(self::futures_cpupool::CpuPool);

impl_userdata! { CpuPool }
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ impl Compiler {

pub const PRELUDE: &'static str = r#"
let __implicit_prelude = import! std.prelude
let { Num, Eq, Ord, Show, Functor, Applicative, Monad, Option, Bool, ? } = __implicit_prelude
let { IO, Num, Eq, Ord, Show, Functor, Applicative, Monad, Option, Bool, ? } = __implicit_prelude
let { (+), (-), (*), (/), (==), (/=), (<), (<=), (>=), (>), (++), show, not, flat_map } = __implicit_prelude
Expand Down
17 changes: 10 additions & 7 deletions src/std_lib/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ impl<'vm, 'value> Getable<'vm, 'value> for Headers {

// By implementing `Userdata` on `Body` it can be automatically pushed and retrieved from gluon
// threads
#[derive(Userdata)]
#[derive(Userdata, VmType)]
#[gluon(vm_type = "std.http.types.Body")]
#[gluon(crate_name = "::vm")]
// Representation of a http body that is in the prograss of being read
pub struct Body(Arc<Mutex<Box<Stream<Item = PushAsRef<Chunk, [u8]>, Error = vm::Error> + Send>>>);
Expand All @@ -127,13 +128,14 @@ fn read_chunk(
}

// A http body that is being written
#[derive(Userdata)]
#[derive(Userdata, VmType)]
#[gluon(vm_type = "std.http.types.ResponseBody")]
#[gluon(crate_name = "::vm")]
pub struct ResponseBody(Arc<Mutex<Option<hyper::body::Sender>>>);

impl fmt::Debug for ResponseBody {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "hyper::Response")
write!(f, "ResponseBody")
}
}

Expand Down Expand Up @@ -176,7 +178,8 @@ fn write_response(
})
}

#[derive(Debug, Userdata)]
#[derive(Debug, Userdata, VmType)]
#[gluon(vm_type = "std.http.types.Uri")]
#[gluon(crate_name = "::vm")]
struct Uri(http::Uri);

Expand Down Expand Up @@ -383,9 +386,9 @@ pub fn load_types(vm: &Thread) -> vm::Result<ExternModule> {
vm,
record! {
// Define the types so that they can be used from gluon
type Body => Body,
type ResponseBody => ResponseBody,
type Uri => Uri,
type std::http::types::Body => Body,
type std::http::types::ResponseBody => ResponseBody,
type std::http::types::Uri => Uri,
type std::http::Method => String,
type std::http::StatusCode => u16,
type std::http::Request => Request,
Expand Down
4 changes: 2 additions & 2 deletions src/std_lib/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ pub fn load(vm: &Thread) -> Result<ExternModule> {
ExternModule::new(
vm,
record! {
type File => GluonFile,
type std::io::File => GluonFile,
type OpenOptions => OpenOptions,
type IO a => IO<A>,
type std::io::IO a => IO<A>,
flat_map => TypedBytecode::<FlatMap>::new("std.io.prim.flat_map", 3, flat_map),
wrap => TypedBytecode::<Wrap>::new("std.io.prim.wrap", 2, wrap),
open_file_with => primitive!(2, std::io::prim::open_file_with),
Expand Down
13 changes: 8 additions & 5 deletions src/std_lib/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ extern crate rand_xorshift;

use self::rand::{Rng, SeedableRng};

use crate::vm::api::{RuntimeResult, IO};
use crate::vm::thread::Thread;
use crate::vm::types::VmInt;
use crate::vm::{self, ExternModule};
use crate::vm::{
self,
api::{RuntimeResult, IO},
thread::Thread,
types::VmInt,
ExternModule,
};

#[derive(Clone, Debug, Userdata, VmType)]
#[gluon(vm_type = "std.random.XorShiftRng")]
Expand Down Expand Up @@ -67,7 +70,7 @@ pub fn load(vm: &Thread) -> vm::Result<ExternModule> {
ExternModule::new(
vm,
record! {
type XorShiftRng => XorShiftRng,
type std::random::XorShiftRng => XorShiftRng,
next_int => primitive!(1, std::random::prim::next_int),
next_float => primitive!(1, std::random::prim::next_float),
gen_int_range => primitive!(2, std::random::prim::gen_int_range),
Expand Down
2 changes: 1 addition & 1 deletion std/disposable.glu
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@NO-IMPLICIT-PRELUDE
//! A `Disposable` abstracts over different kinds of resources.

let { wrap, flat_map } = import! std.io.prim
let { IO, wrap, flat_map } = import! std.io.prim
let { Bool } = import! std.types


Expand Down
4 changes: 2 additions & 2 deletions std/effect/st.glu
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ let { Eff, inject_rest, ? } = import! std.effect
let { map } = import! std.functor
let { wrap } = import! std.applicative
let { (<<) } = import! std.function
let { ref, (<-), load } = import! std.reference
let { Reference, ref, (<-), load } = import! std.reference

type STRef s a = { __ref : Ref a }
type STRef s a = { __ref : Reference a }
type State s r a =
| New : forall b . b -> State s r (STRef s b)
| Read : STRef s a -> State s r a
Expand Down
4 changes: 3 additions & 1 deletion std/http.glu
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ let {
Request,
StatusCode,
Response,
ResponseBody,
HttpEffect,
HttpState, } = import! std.http.types
HttpState,
Uri, } = import! std.http.types
let http_prim = import! std.http.prim

let status =
Expand Down
4 changes: 3 additions & 1 deletion std/http/types.glu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let { Body, ResponseBody, StatusCode, Method, Request, Response, Headers, HttpState } = import! std.http.prim_types
let { Body, ResponseBody, StatusCode, Method, Request, Response, Headers, HttpState, Uri } = import! std.http.prim_types

let { Eff } = import! std.effect
let { Error } = import! std.effect.error
Expand All @@ -19,6 +19,8 @@ type HttpEffect r a = [| alt : Alt, state : State HttpState, lift : Lift IO | r
StatusCode,
Headers,
Response,
ResponseBody,
HttpEffect,
HttpState,
Uri,
}
2 changes: 1 addition & 1 deletion std/io.glu
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@NO-IMPLICIT-PRELUDE
//! Functions for working with I/O

let io_prim @ { IO } = import! std.io.prim
let io_prim @ { IO, File } = import! std.io.prim
let { Read } = import! std.io.read
let { Write } = import! std.io.write
let { Disposable } = import! std.disposable
Expand Down
6 changes: 3 additions & 3 deletions std/io/read.glu
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//@NO-IMPLICIT-PRELUDE
//! Functions and types for working with `Read`ers.

let { wrap, flat_map, default_buf_len } = import! std.io.prim
let { IO, wrap, flat_map, default_buf_len } = import! std.io.prim
let { Option, Bool } = import! std.types
let { Disposable, dispose, is_disposed } = import! std.disposable
let { (>), (<=), (>=), min } = import! std.cmp
let { assert } = import! std.assert
let { not } = import! std.bool
let { ? } = import! std.int
let { Result } = import! std.result
let { ref, load, (<-) } = import! std.reference
let { Reference, ref, load, (<-) } = import! std.reference
let array = import! std.array
let string = import! std.string

Expand Down Expand Up @@ -65,7 +65,7 @@ let default_read_to_end read : forall a . (a -> Int -> IO (Option (Array Byte)))
/// If you are reading all data at once, buffering is not necessary.
type Buffered r = {
reader : r,
buf : Ref (Array Byte),
buf : Reference (Array Byte),
capacity : Int,
}

Expand Down
6 changes: 3 additions & 3 deletions std/io/write.glu
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
let string = import! std.string
let array = import! std.array
let { wrap } = import! std.applicative
let { flat_map, wrap, default_buf_len, throw } = import! std.io.prim
let { IO, flat_map, wrap, default_buf_len, throw } = import! std.io.prim
let { Disposable, dispose, is_disposed } = import! std.disposable
let { (<-), load, ref } = import! std.reference
let { Reference, (<-), load, ref } = import! std.reference
let { ? } = import! std.int
let { assert } = import! std.assert
let { (>=), (>), (==) } = import! std.cmp
Expand Down Expand Up @@ -68,7 +68,7 @@ let flush ?write : [Write a] -> a -> IO () = write.flush
/// If you are writing all data at once, buffering is not necessary.
type Buffered w = {
writer : w,
buf : Ref (Array Byte),
buf : Reference (Array Byte),
capacity : Int,
}

Expand Down
3 changes: 3 additions & 0 deletions std/prelude.glu
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@NO-IMPLICIT-PRELUDE
//! Definitions which gets implicit re-export in every file.

let { IO } = import! std.io.prim
let { Option } = import! std.types
let { Functor } = import! std.functor
let { Applicative, (*>), wrap } = import! std.applicative
Expand All @@ -20,6 +21,8 @@ let { error } = import! std.prim
let { flat_map } = import! std.monad

{
IO,

Ordering,

Semigroup,
Expand Down
3 changes: 2 additions & 1 deletion std/random.glu
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! _This module is only available if gluon is compiled with the `rand` feature._

let prim = import! std.random.prim
let prim @ { XorShiftRng } = import! std.random.prim

type RandomGen g = { next : g -> { value : Int, gen : g } }

Expand All @@ -18,6 +18,7 @@ let xor_shift_rng =

{
RandomGen,
XorShiftRng,

xor_shift_rng,

Expand Down
3 changes: 2 additions & 1 deletion std/reference.glu
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! A mutable reference type

let reference = import! std.reference.prim
let reference @ { Reference } = import! std.reference.prim
#[infix(right, 9)]
let (<-) = reference.(<-)
{
Reference,
(<-),
..
reference
Expand Down
2 changes: 1 addition & 1 deletion std/regex.glu
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! Bindings for rust-lang/regex

let { Match, eq_Match, show_Match } = import! std.regex.types
let regex_prim = import! std.regex.prim
let regex_prim @ { Regex, Error } = import! std.regex.prim

{
Match,
Expand Down
2 changes: 1 addition & 1 deletion std/stream.glu
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let { Option } = import! std.option
let { Monoid } = import! std.monoid
let { Semigroup, (<>) } = import! std.semigroup
let { Foldable } = import! std.foldable
let { lazy, force } = import! std.lazy
let { Lazy, lazy, force } = import! std.lazy

rec
type Stream_ a =
Expand Down
Loading

0 comments on commit a2daace

Please sign in to comment.