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

feat: extern functions #96

Merged
merged 12 commits into from
Mar 7, 2020

Conversation

baszalmstra
Copy link
Collaborator

@baszalmstra baszalmstra commented Mar 7, 2020

This PR adds the ability to define and call external functions that must be added to the runtime. E.g.

/// This is a function that does not have an implementation in Mun but instead is linked 
/// dynamically when loading the assembly
extern fn tick_the_system();

fn main() {
  // The extern functions can be called like any other Mun function
  tick_the_system()
}

When creating a runtime the tick_the_system function must be added to the runtime by calling insert_fn.

Restrictions

  • Structs as parameters or return values are not yet supported

@codecov
Copy link

codecov bot commented Mar 7, 2020

Codecov Report

Merging #96 into master will decrease coverage by 0.64%.
The diff coverage is 62.67%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #96      +/-   ##
==========================================
- Coverage   77.22%   76.57%   -0.65%     
==========================================
  Files         124      127       +3     
  Lines        9816    10275     +459     
==========================================
+ Hits         7580     7868     +288     
- Misses       2236     2407     +171     
Impacted Files Coverage Δ
crates/mun_hir/src/ty/infer/coerce.rs 100.00% <0.00%> (ø)
crates/mun_target/src/lib.rs 100.00% <0.00%> (ø)
crates/mun_hir/src/ty/primitives.rs 39.81% <0.00%> (ø)
crates/mun_hir/src/builtin_type.rs 19.29% <0.00%> (ø)
crates/mun_hir/src/expr.rs 75.05% <0.00%> (+0.20%) ⬆️
crates/mun_runtime/src/macros.rs 72.22% <0.00%> (+0.52%) ⬆️
crates/mun_hir/src/ty/tests.rs 97.50% <0.00%> (+0.97%) ⬆️
crates/mun_hir/src/code_model.rs 76.40% <0.00%> (+1.60%) ⬆️
crates/mun_runtime/src/lib.rs 89.24% <0.00%> (+5.03%) ⬆️
crates/mun_abi/src/autogen_impl.rs 97.62% <0.00%> (+2.76%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9db3a2f...adde8ea. Read the comment docs.

crates/mun_hir/src/expr/validator.rs Outdated Show resolved Hide resolved
crates/mun_runtime/src/function.rs Outdated Show resolved Hide resolved
crates/mun_runtime/src/lib.rs Outdated Show resolved Hide resolved
crates/mun_runtime/src/lib.rs Outdated Show resolved Hide resolved
@Wodann
Copy link
Collaborator

Wodann commented Mar 7, 2020

@baszalmstra baszalmstra merged commit decbf12 into mun-lang:master Mar 7, 2020
@Wodann Wodann added this to the Mun v0.2 milestone May 14, 2020
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

Successfully merging this pull request may close these issues.

2 participants