Skip to content

Commit

Permalink
Merge pull request #83 from Wodann/feature/struct-interop
Browse files Browse the repository at this point in the history
feat: add marshalling of structs
  • Loading branch information
Wodann authored Jan 29, 2020
2 parents 7e3659c + 6e85fa8 commit 1a5d56a
Show file tree
Hide file tree
Showing 22 changed files with 839 additions and 228 deletions.
3 changes: 1 addition & 2 deletions crates/mun/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ extern crate failure;
use std::time::Duration;

use clap::{App, AppSettings, Arg, ArgMatches, SubCommand};
use mun_abi::Reflection;
use mun_compiler::{host_triple, Config, PathOrInline, Target};
use mun_runtime::{invoke_fn, Runtime, RuntimeBuilder};
use mun_runtime::{invoke_fn, ReturnTypeReflection, Runtime, RuntimeBuilder};

fn main() -> Result<(), failure::Error> {
let matches = App::new("mun")
Expand Down
3 changes: 0 additions & 3 deletions crates/mun_abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@ homepage = "https://mun-lang.org"
repository = "https://github.com/mun-lang/mun"
license = "MIT OR Apache-2.0"
description = "Rust wrapper for the Mun ABI"

[dependencies]
md5 = "0.6.1"
2 changes: 1 addition & 1 deletion crates/mun_abi/c
Submodule c updated 1 files
+32 −1 include/mun_abi.h
58 changes: 53 additions & 5 deletions crates/mun_abi/src/autogen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* automatically generated by rust-bindgen */

#![allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
use crate::Privacy;
use crate::{Privacy, TypeGroup};

#[doc = " Represents a globally unique identifier (GUID)."]
#[doc = ""]
Expand Down Expand Up @@ -46,12 +46,14 @@ pub struct TypeInfo {
pub guid: Guid,
#[doc = " Type name"]
pub name: *const ::std::os::raw::c_char,
#[doc = " Type group"]
pub group: TypeGroup,
}
#[test]
fn bindgen_test_layout_TypeInfo() {
assert_eq!(
::std::mem::size_of::<TypeInfo>(),
24usize,
32usize,
concat!("Size of: ", stringify!(TypeInfo))
);
assert_eq!(
Expand Down Expand Up @@ -79,6 +81,16 @@ fn bindgen_test_layout_TypeInfo() {
stringify!(name)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<TypeInfo>())).group as *const _ as usize },
24usize,
concat!(
"Offset of field: ",
stringify!(TypeInfo),
"::",
stringify!(group)
)
);
}
#[doc = " Represents a function signature."]
#[doc = ""]
Expand Down Expand Up @@ -214,16 +226,22 @@ fn bindgen_test_layout_FunctionInfo() {
pub struct StructInfo {
#[doc = " Struct name"]
pub name: *const ::std::os::raw::c_char,
#[doc = " Struct fields' names"]
pub field_names: *const *const ::std::os::raw::c_char,
#[doc = " Struct fields' information"]
pub field_types: *const TypeInfo,
#[doc = " Struct fields' offsets"]
pub field_offsets: *const u16,
#[doc = " Struct fields' sizes (in bytes)"]
pub field_sizes: *const u16,
#[doc = " Number of fields"]
pub num_fields: u16,
}
#[test]
fn bindgen_test_layout_StructInfo() {
assert_eq!(
::std::mem::size_of::<StructInfo>(),
24usize,
48usize,
concat!("Size of: ", stringify!(StructInfo))
);
assert_eq!(
Expand All @@ -242,18 +260,48 @@ fn bindgen_test_layout_StructInfo() {
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<StructInfo>())).field_types as *const _ as usize },
unsafe { &(*(::std::ptr::null::<StructInfo>())).field_names as *const _ as usize },
8usize,
concat!(
"Offset of field: ",
stringify!(StructInfo),
"::",
stringify!(field_names)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<StructInfo>())).field_types as *const _ as usize },
16usize,
concat!(
"Offset of field: ",
stringify!(StructInfo),
"::",
stringify!(field_types)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<StructInfo>())).field_offsets as *const _ as usize },
24usize,
concat!(
"Offset of field: ",
stringify!(StructInfo),
"::",
stringify!(field_offsets)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<StructInfo>())).field_sizes as *const _ as usize },
32usize,
concat!(
"Offset of field: ",
stringify!(StructInfo),
"::",
stringify!(field_sizes)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<StructInfo>())).num_fields as *const _ as usize },
16usize,
40usize,
concat!(
"Offset of field: ",
stringify!(StructInfo),
Expand Down
Loading

0 comments on commit 1a5d56a

Please sign in to comment.