ppc login works in mme main
This commit is contained in:
@@ -9,7 +9,6 @@ use std::collections::HashMap;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::sync::{Arc, Mutex, RwLock};
|
||||
use std::{thread, vec};
|
||||
use tracing::{debug, info, trace};
|
||||
|
||||
use crate::set_global_mize;
|
||||
use crate::config::{ConfigOpt, ConfigOptId, MizeFun};
|
||||
@@ -24,6 +23,7 @@ use crate::memstore::MemStore;
|
||||
use crate::mize_err;
|
||||
use crate::proto::MizeMessage;
|
||||
use crate::error::IntoMizeResult;
|
||||
use crate::prelude::*;
|
||||
|
||||
use self::connection::{ConnListener, Connection};
|
||||
use self::updater::handle_operation;
|
||||
@@ -47,7 +47,7 @@ mod tests;
|
||||
|
||||
static MSG_CHANNEL_SIZE: usize = 200;
|
||||
|
||||
static BUILD_TIME_CONFIG: &str = include_str!(std::env!("MIZE_BUILD_CONFIG"));
|
||||
static BUILD_TIME_CONFIG: &str = std::env!("MIZE_BUILD_CONFIG");
|
||||
|
||||
/// The Instance type is the heart of the mize system
|
||||
#[derive(Clone)]
|
||||
@@ -121,6 +121,35 @@ pub struct MethodMetadata {
|
||||
pub name: String,
|
||||
pub id: MizeId,
|
||||
pub kind: String, // "method", "effect", "thread"
|
||||
/// Raw signature string, e.g. `"String -> ()"` or `"Command, Func -> ()"`.
|
||||
pub signature: String,
|
||||
/// Parsed argument type names (left of `->`).
|
||||
pub arg_types: Vec<String>,
|
||||
/// Parsed return type name (right of `->`). Empty means unspecified / ItemData.
|
||||
pub return_type: String,
|
||||
}
|
||||
|
||||
/// Parse a method signature like `"String -> ()"` or `"Command, Func -> ()"`.
|
||||
/// Returns `(arg_types, return_type)` where `return_type` is empty if no `->` was given.
|
||||
pub fn parse_method_signature(signature: &str) -> (Vec<String>, String) {
|
||||
let signature = signature.trim();
|
||||
if signature.is_empty() {
|
||||
return (Vec::new(), String::new());
|
||||
}
|
||||
let (args_part, ret_part) = match signature.split_once("->") {
|
||||
Some((a, r)) => (a.trim(), r.trim().to_string()),
|
||||
None => (signature, String::new()),
|
||||
};
|
||||
let arg_types = if args_part.is_empty() {
|
||||
Vec::new()
|
||||
} else {
|
||||
args_part
|
||||
.split(',')
|
||||
.map(|s| s.trim().to_string())
|
||||
.filter(|s| !s.is_empty())
|
||||
.collect()
|
||||
};
|
||||
(arg_types, ret_part)
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -129,6 +158,10 @@ pub struct NativeMetadata {
|
||||
pub type_name: String,
|
||||
pub associated: Vec<String>,
|
||||
pub methods: Vec<String>,
|
||||
/// Signature strings parallel to `associated`.
|
||||
pub associated_sigs: Vec<String>,
|
||||
/// Signature strings parallel to `methods`.
|
||||
pub method_sigs: Vec<String>,
|
||||
}
|
||||
|
||||
pub struct InstanceRef {
|
||||
@@ -146,8 +179,8 @@ impl PartRef {
|
||||
}
|
||||
|
||||
impl MizePart for PartRef {
|
||||
fn id(&self) -> MizeId {
|
||||
self.id.clone()
|
||||
fn id(&self) -> MizeResult<MizeId> {
|
||||
Ok(self.id.clone())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,11 +193,15 @@ pub struct InstanceAsync {
|
||||
}
|
||||
|
||||
pub trait MizePart {
|
||||
fn id(&self) -> MizeId;
|
||||
fn id(&self) -> MizeResult<MizeId>;
|
||||
}
|
||||
|
||||
impl Mize {
|
||||
pub fn empty() -> MizeResult<Mize> {
|
||||
let runtime = tokio::runtime::Builder::new_multi_thread().enable_all().build()?;
|
||||
let guard = runtime.enter();
|
||||
std::mem::forget(guard);
|
||||
|
||||
let id_pool = Arc::new(Mutex::new(VecStringPool::default()));
|
||||
let namespace_pool_raw = StringPool::default();
|
||||
let connections = Arc::new(Mutex::new(Vec::new()));
|
||||
@@ -206,9 +243,7 @@ impl Mize {
|
||||
part_metadata: Arc::new(Mutex::new(HashMap::new())),
|
||||
|
||||
#[cfg(feature = "async")]
|
||||
runtime: Arc::new(Mutex::new(
|
||||
Runtime::new().mres_msg("Could not create async runtime")?,
|
||||
)),
|
||||
runtime: Arc::new(Mutex::new(runtime)),
|
||||
};
|
||||
|
||||
#[cfg(feature = "target-os")]
|
||||
@@ -244,7 +279,7 @@ impl Mize {
|
||||
console_log!("before loading build time config");
|
||||
|
||||
// load the config from build time
|
||||
let config = ItemData::from_toml(BUILD_TIME_CONFIG)?;
|
||||
let config = ItemData::from_json(BUILD_TIME_CONFIG.to_owned())?;
|
||||
instance.set_blocking("0", config);
|
||||
|
||||
#[cfg(feature = "target-wasm ")]
|
||||
@@ -546,7 +581,7 @@ impl Mize {
|
||||
}
|
||||
|
||||
/// Record a method/effect/thread declaration while in generate mode.
|
||||
pub fn record_method(&self, name: &str, id: MizeId, kind: &str) -> MizeResult<()> {
|
||||
pub fn record_method(&self, name: &str, id: MizeId, kind: &str, signature: &str) -> MizeResult<()> {
|
||||
let cur_part = self.cur_eval_part.lock()?.clone()
|
||||
.ok_or_else(|| mize_err!("no cur_eval_part set"))?;
|
||||
let mut metadata_map = self.part_metadata.lock()?;
|
||||
@@ -554,10 +589,14 @@ impl Mize {
|
||||
part_name: cur_part.dot(),
|
||||
..Default::default()
|
||||
});
|
||||
let (arg_types, return_type) = parse_method_signature(signature);
|
||||
let m = MethodMetadata {
|
||||
name: name.to_string(),
|
||||
id,
|
||||
kind: kind.to_string(),
|
||||
signature: signature.to_string(),
|
||||
arg_types,
|
||||
return_type,
|
||||
};
|
||||
match kind {
|
||||
"effect" => metadata.effects.push(m),
|
||||
@@ -568,7 +607,15 @@ impl Mize {
|
||||
}
|
||||
|
||||
/// Record a native type inclusion while in generate mode.
|
||||
pub fn record_native(&self, name: &str, type_name: &str, associated: Vec<String>, methods: Vec<String>) -> MizeResult<()> {
|
||||
pub fn record_native(
|
||||
&self,
|
||||
name: &str,
|
||||
type_name: &str,
|
||||
associated: Vec<String>,
|
||||
methods: Vec<String>,
|
||||
associated_sigs: Vec<String>,
|
||||
method_sigs: Vec<String>,
|
||||
) -> MizeResult<()> {
|
||||
let cur_part = self.cur_eval_part.lock()?.clone()
|
||||
.ok_or_else(|| mize_err!("no cur_eval_part set"))?;
|
||||
let mut metadata_map = self.part_metadata.lock()?;
|
||||
@@ -581,6 +628,8 @@ impl Mize {
|
||||
type_name: type_name.to_string(),
|
||||
associated,
|
||||
methods,
|
||||
associated_sigs,
|
||||
method_sigs,
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
@@ -805,12 +854,15 @@ impl Mize {
|
||||
) -> MizeResult<()> {
|
||||
let mut threads_inner = self.threads.lock()?;
|
||||
let mut next_thread_id = self.next_thread_id.lock()?;
|
||||
let tokio_handle = tokio::runtime::Handle::current();
|
||||
|
||||
let my_thread_id_no_mutex_guard = *next_thread_id;
|
||||
let _thread_mutex = self.threads.clone();
|
||||
let name_to_move = name.to_owned();
|
||||
let to_spawn = move || -> () {
|
||||
debug!("spawning thread: {}", name_to_move);
|
||||
let guard = tokio_handle.enter();
|
||||
std::mem::forget(guard);
|
||||
let _my_thread_id = my_thread_id_no_mutex_guard;
|
||||
|
||||
let res = func();
|
||||
@@ -883,8 +935,8 @@ impl Mize {
|
||||
let mut next_thread_id = self.next_thread_id.lock()?;
|
||||
|
||||
threads_inner.push((*next_thread_id, name.to_owned(), None));
|
||||
let runtime_inner = self.runtime.lock().unwrap();
|
||||
runtime_inner.spawn(func);
|
||||
let runtime = tokio::runtime::Handle::current();
|
||||
runtime.spawn(func);
|
||||
|
||||
*next_thread_id += 1;
|
||||
|
||||
@@ -893,9 +945,7 @@ impl Mize {
|
||||
|
||||
#[cfg(feature = "async")]
|
||||
pub fn async_get_handle(&self) -> Handle {
|
||||
let runtime_inner = self.runtime.lock().unwrap();
|
||||
let handle = runtime_inner.handle().to_owned();
|
||||
handle
|
||||
tokio::runtime::Handle::current()
|
||||
}
|
||||
|
||||
#[cfg(feature = "async")]
|
||||
@@ -916,16 +966,13 @@ impl Mize {
|
||||
.expect("mutex lock failed in spawn_async_blocking");
|
||||
|
||||
threads_inner.push((*next_thread_id, name.to_owned(), None));
|
||||
let runtime_inner = self.runtime.lock().unwrap();
|
||||
let handle = runtime_inner.handle().to_owned();
|
||||
let runtime = tokio::runtime::Handle::current();
|
||||
*next_thread_id += 1;
|
||||
|
||||
drop(runtime_inner);
|
||||
drop(threads_inner);
|
||||
drop(next_thread_id);
|
||||
|
||||
handle.enter();
|
||||
let result = handle.block_on(func);
|
||||
let result = runtime.block_on(func);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -958,24 +1005,29 @@ impl Mize {
|
||||
|
||||
let mut opt = config_opts
|
||||
.get_mut(&id)
|
||||
.ok_or_else(|| mize_err!("Config opt for {name} not in config_opts"))?;
|
||||
.ok_or_else(|| mize_err!("Config opt for {id} not in config_opts"))?;
|
||||
|
||||
if let Some(val) = opt.val.clone() {
|
||||
return Ok(val);
|
||||
}
|
||||
|
||||
// in case it is not cached run the fun if it exists
|
||||
if let Some(fun) = &opt.fun {
|
||||
if opt.fun.is_some() {
|
||||
let fun = opt.fun.take().unwrap();
|
||||
drop(config_opts);
|
||||
let res = fun()?;
|
||||
let mut config_opts = self.config_opts.lock().unwrap();
|
||||
let mut opt = config_opts.get_mut(&id).unwrap();
|
||||
opt.fun = Some(fun);
|
||||
opt.val = Some(res.clone());
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
Err(mize_err!("ConfigOpt {name} has no fun and no cached value"))
|
||||
Err(mize_err!("ConfigOpt {id} has no fun and no cached value"))
|
||||
}
|
||||
|
||||
pub fn dyn_call(&mut self, part_id: MizeId, method: &str, args: ItemData) -> MizeResult<ItemData> {
|
||||
debug!("dyn call {}.{} with args: {}", part_id, method, args);
|
||||
debug!("dyn call {}/{} with args: {}", part_id, method, args);
|
||||
let mut fun_values = self.fun_values.lock()?;
|
||||
|
||||
let id = part_id.clone().join(method)?;
|
||||
@@ -985,7 +1037,9 @@ impl Mize {
|
||||
|
||||
let calling_part = self.clone().cur_eval_part()?;
|
||||
self.clone().set_cur_eval_part(Some(part_id));
|
||||
println!("before call");
|
||||
let res = fun(args);
|
||||
println!("after call");
|
||||
self.clone().set_cur_eval_part(calling_part);
|
||||
let mut fun_values = self.fun_values.lock()?;
|
||||
fun_values.insert(id, fun);
|
||||
|
||||
Reference in New Issue
Block a user