Skip to content

Commit

Permalink
Merge pull request #166 from baszalmstra/feature/function_prototype
Browse files Browse the repository at this point in the history
misc: adds function prototype
  • Loading branch information
baszalmstra authored May 8, 2020
2 parents ff08f1c + cfc210e commit 0d6e36d
Show file tree
Hide file tree
Showing 18 changed files with 348 additions and 287 deletions.
18 changes: 10 additions & 8 deletions crates/mun/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,16 @@ fn start(matches: &ArgMatches) -> Result<(), failure::Error> {

let borrowed = runtime.borrow();
let entry_point = matches.value_of("entry").unwrap_or("main");
let fn_info = borrowed.get_function_info(entry_point).ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::InvalidInput,
format!("Failed to obtain entry point '{}'", entry_point),
)
})?;

if let Some(ret_type) = fn_info.signature.return_type() {
let fn_definition = borrowed
.get_function_definition(entry_point)
.ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::InvalidInput,
format!("Failed to obtain entry point '{}'", entry_point),
)
})?;

if let Some(ret_type) = fn_definition.prototype.signature.return_type() {
let type_guid = &ret_type.guid;
if *type_guid == bool::type_guid() {
let result: bool =
Expand Down
2 changes: 1 addition & 1 deletion crates/mun_abi/c
Submodule c updated 1 files
+23 −11 include/mun_abi.h
98 changes: 60 additions & 38 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, StructMemoryKind, TypeGroup};
use crate::{StructMemoryKind, TypeGroup};

#[doc = " Represents a globally unique identifier (GUID)."]
#[doc = ""]
Expand Down Expand Up @@ -122,22 +122,18 @@ fn bindgen_test_layout_TypeInfo() {
#[repr(C)]
#[derive(Clone, Debug)]
pub struct FunctionSignature {
#[doc = " Function name"]
pub name: *const ::std::os::raw::c_char,
#[doc = " Argument types"]
pub arg_types: *const *const TypeInfo,
#[doc = " Optional return type"]
pub return_type: *const TypeInfo,
#[doc = " Number of argument types"]
pub num_arg_types: u16,
#[doc = " Function accessibility level"]
pub privacy: Privacy,
}
#[test]
fn bindgen_test_layout_FunctionSignature() {
assert_eq!(
::std::mem::size_of::<FunctionSignature>(),
32usize,
24usize,
concat!("Size of: ", stringify!(FunctionSignature))
);
assert_eq!(
Expand All @@ -146,97 +142,123 @@ fn bindgen_test_layout_FunctionSignature() {
concat!("Alignment of ", stringify!(FunctionSignature))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<FunctionSignature>())).name as *const _ as usize },
unsafe { &(*(::std::ptr::null::<FunctionSignature>())).arg_types as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(FunctionSignature),
"::",
stringify!(name)
stringify!(arg_types)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<FunctionSignature>())).arg_types as *const _ as usize },
unsafe { &(*(::std::ptr::null::<FunctionSignature>())).return_type as *const _ as usize },
8usize,
concat!(
"Offset of field: ",
stringify!(FunctionSignature),
"::",
stringify!(arg_types)
stringify!(return_type)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<FunctionSignature>())).return_type as *const _ as usize },
unsafe { &(*(::std::ptr::null::<FunctionSignature>())).num_arg_types as *const _ as usize },
16usize,
concat!(
"Offset of field: ",
stringify!(FunctionSignature),
"::",
stringify!(return_type)
stringify!(num_arg_types)
)
);
}
#[doc = " Represents a function prototype. A function prototype contains the name,"]
#[doc = " type signature, but not an implementation."]
#[doc = ""]
#[doc = " <div rustbindgen derive=\"Clone\" derive=\"Debug\"></div>"]
#[repr(C)]
#[derive(Clone, Debug)]
pub struct FunctionPrototype {
#[doc = " Function name"]
pub name: *const ::std::os::raw::c_char,
#[doc = " The type signature of the function"]
pub signature: FunctionSignature,
}
#[test]
fn bindgen_test_layout_FunctionPrototype() {
assert_eq!(
unsafe { &(*(::std::ptr::null::<FunctionSignature>())).num_arg_types as *const _ as usize },
24usize,
::std::mem::size_of::<FunctionPrototype>(),
32usize,
concat!("Size of: ", stringify!(FunctionPrototype))
);
assert_eq!(
::std::mem::align_of::<FunctionPrototype>(),
8usize,
concat!("Alignment of ", stringify!(FunctionPrototype))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<FunctionPrototype>())).name as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(FunctionSignature),
stringify!(FunctionPrototype),
"::",
stringify!(num_arg_types)
stringify!(name)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<FunctionSignature>())).privacy as *const _ as usize },
26usize,
unsafe { &(*(::std::ptr::null::<FunctionPrototype>())).signature as *const _ as usize },
8usize,
concat!(
"Offset of field: ",
stringify!(FunctionSignature),
stringify!(FunctionPrototype),
"::",
stringify!(privacy)
stringify!(signature)
)
);
}
#[doc = " Represents a function declaration."]
#[doc = " Represents a function definition. A function definition contains the name,"]
#[doc = " type signature, and a pointer to the implementation."]
#[doc = ""]
#[doc = " `fn_ptr` can be used to call the declared function."]
#[doc = ""]
#[doc = " <div rustbindgen derive=\"Clone\" derive=\"Debug\"></div>"]
#[repr(C)]
#[derive(Clone, Debug)]
pub struct FunctionInfo {
#[doc = " Function signature"]
pub signature: FunctionSignature,
pub struct FunctionDefinition {
#[doc = " Function prototype"]
pub prototype: FunctionPrototype,
#[doc = " Function pointer"]
pub fn_ptr: *const ::std::os::raw::c_void,
}
#[test]
fn bindgen_test_layout_FunctionInfo() {
fn bindgen_test_layout_FunctionDefinition() {
assert_eq!(
::std::mem::size_of::<FunctionInfo>(),
::std::mem::size_of::<FunctionDefinition>(),
40usize,
concat!("Size of: ", stringify!(FunctionInfo))
concat!("Size of: ", stringify!(FunctionDefinition))
);
assert_eq!(
::std::mem::align_of::<FunctionInfo>(),
::std::mem::align_of::<FunctionDefinition>(),
8usize,
concat!("Alignment of ", stringify!(FunctionInfo))
concat!("Alignment of ", stringify!(FunctionDefinition))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<FunctionInfo>())).signature as *const _ as usize },
unsafe { &(*(::std::ptr::null::<FunctionDefinition>())).prototype as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(FunctionInfo),
stringify!(FunctionDefinition),
"::",
stringify!(signature)
stringify!(prototype)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<FunctionInfo>())).fn_ptr as *const _ as usize },
unsafe { &(*(::std::ptr::null::<FunctionDefinition>())).fn_ptr as *const _ as usize },
32usize,
concat!(
"Offset of field: ",
stringify!(FunctionInfo),
stringify!(FunctionDefinition),
"::",
stringify!(fn_ptr)
)
Expand Down Expand Up @@ -331,7 +353,7 @@ pub struct ModuleInfo {
#[doc = " Module path"]
pub path: *const ::std::os::raw::c_char,
#[doc = " Module functions"]
pub functions: *const FunctionInfo,
pub functions: *const FunctionDefinition,
#[doc = " Number of module functions"]
pub num_functions: u32,
#[doc = " Module types"]
Expand Down Expand Up @@ -411,7 +433,7 @@ fn bindgen_test_layout_ModuleInfo() {
#[derive(Debug)]
pub struct DispatchTable {
#[doc = " Function signatures"]
pub signatures: *const FunctionSignature,
pub prototypes: *const FunctionPrototype,
#[doc = " Function pointers"]
pub fn_ptrs: *mut *const ::std::os::raw::c_void,
#[doc = " Number of functions"]
Expand All @@ -430,13 +452,13 @@ fn bindgen_test_layout_DispatchTable() {
concat!("Alignment of ", stringify!(DispatchTable))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<DispatchTable>())).signatures as *const _ as usize },
unsafe { &(*(::std::ptr::null::<DispatchTable>())).prototypes as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(DispatchTable),
"::",
stringify!(signatures)
stringify!(prototypes)
)
);
assert_eq!(
Expand Down
Loading

0 comments on commit 0d6e36d

Please sign in to comment.