From 0f82cd3c4090f9538c3d81ae3377dc88bffb6cb4 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 4 Nov 2019 21:50:19 +0100 Subject: [PATCH] doc(runtime-core) Write more documentation. --- lib/runtime-core/src/vm.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/runtime-core/src/vm.rs b/lib/runtime-core/src/vm.rs index dc92c788f..240f71e1c 100644 --- a/lib/runtime-core/src/vm.rs +++ b/lib/runtime-core/src/vm.rs @@ -498,25 +498,33 @@ impl Ctx { } } -/// Used to provide type safety (ish) for passing around function pointers. +/// Represents a function pointer. It is mostly used in the +/// `typed_func` module within the `wrap` functions, to wrap imported +/// functions. #[repr(C)] pub struct Func { _private: [u8; 0], } +/// Represents a function environment pointer, like a captured +/// environment of a closure. It is mostly used in the `typed_func` +/// module within the `wrap` functions, to wrap imported functions. #[repr(C)] pub struct FuncEnv { _private: [u8; 0], } +/// Represents a function context. It is used by imported function +/// only. #[derive(Debug)] #[repr(C)] -pub struct FuncCtx { +pub(crate) struct FuncCtx { pub(crate) vmctx: NonNull, pub(crate) func_env: Option>, } -/// An imported function, which contains the vmctx that owns this function. +/// An imported function is a function pointer associated to a +/// function context. #[derive(Debug, Clone)] #[repr(C)] pub struct ImportedFunc { @@ -524,7 +532,7 @@ pub struct ImportedFunc { pub(crate) func_ctx: NonNull, } -// manually implemented because ImportedFunc contains raw pointers +// Manually implemented because ImportedFunc contains raw pointers // directly; `Func` is marked Send (But `Ctx` actually isn't! (TODO: // review this, shouldn't `Ctx` be Send?)) unsafe impl Send for ImportedFunc {}