@ -484,12 +484,12 @@ impl ExecutorContext {
|
|||||||
|
|
||||||
let result = match &mut repr {
|
let result = match &mut repr {
|
||||||
ModuleRepr::Root => Err(exec_state.circular_import_error(&path, source_range)),
|
ModuleRepr::Root => Err(exec_state.circular_import_error(&path, source_range)),
|
||||||
ModuleRepr::Kcl(_, Some((env_ref, items))) => Ok((*env_ref, items.clone())),
|
ModuleRepr::Kcl(_, Some((_, env_ref, items))) => Ok((*env_ref, items.clone())),
|
||||||
ModuleRepr::Kcl(program, cache) => self
|
ModuleRepr::Kcl(program, cache) => self
|
||||||
.exec_module_from_ast(program, module_id, &path, exec_state, source_range)
|
.exec_module_from_ast(program, module_id, &path, exec_state, source_range)
|
||||||
.await
|
.await
|
||||||
.map(|(_, er, items)| {
|
.map(|(val, er, items)| {
|
||||||
*cache = Some((er, items.clone()));
|
*cache = Some((val, er, items.clone()));
|
||||||
(er, items)
|
(er, items)
|
||||||
}),
|
}),
|
||||||
ModuleRepr::Foreign(geom) => Err(KclError::Semantic(KclErrorDetails {
|
ModuleRepr::Foreign(geom) => Err(KclError::Semantic(KclErrorDetails {
|
||||||
@ -524,13 +524,14 @@ impl ExecutorContext {
|
|||||||
|
|
||||||
let result = match &mut repr {
|
let result = match &mut repr {
|
||||||
ModuleRepr::Root => Err(exec_state.circular_import_error(&path, source_range)),
|
ModuleRepr::Root => Err(exec_state.circular_import_error(&path, source_range)),
|
||||||
|
ModuleRepr::Kcl(_, Some((val, _, _))) => Ok(val.clone()),
|
||||||
ModuleRepr::Kcl(program, cached_items) => {
|
ModuleRepr::Kcl(program, cached_items) => {
|
||||||
let result = self
|
let result = self
|
||||||
.exec_module_from_ast(program, module_id, &path, exec_state, source_range)
|
.exec_module_from_ast(program, module_id, &path, exec_state, source_range)
|
||||||
.await;
|
.await;
|
||||||
match result {
|
match result {
|
||||||
Ok((val, env, items)) => {
|
Ok((val, env, items)) => {
|
||||||
*cached_items = Some((env, items));
|
*cached_items = Some((val.clone(), env, items));
|
||||||
Ok(val)
|
Ok(val)
|
||||||
}
|
}
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
@ -2302,14 +2303,16 @@ impl FunctionSource {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use tokio::io::AsyncWriteExt;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
execution::{memory::Stack, parse_execute, ContextType},
|
execution::{memory::Stack, parse_execute, ContextType},
|
||||||
parsing::ast::types::{DefaultParamVal, Identifier, Parameter},
|
parsing::ast::types::{DefaultParamVal, Identifier, Parameter},
|
||||||
ExecutorSettings,
|
ExecutorSettings,
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
|
||||||
use tokio::io::AsyncWriteExt;
|
|
||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
async fn test_assign_args_to_params() {
|
async fn test_assign_args_to_params() {
|
||||||
|
@ -4,13 +4,13 @@ use anyhow::Result;
|
|||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use super::{types::UnitLen, EnvironmentRef, ExecState, MetaSettings};
|
|
||||||
use crate::{
|
use crate::{
|
||||||
errors::KclErrorDetails,
|
errors::KclErrorDetails,
|
||||||
execution::{
|
execution::{
|
||||||
annotations::{SETTINGS, SETTINGS_UNIT_LENGTH},
|
annotations::{SETTINGS, SETTINGS_UNIT_LENGTH},
|
||||||
types::{NumericType, PrimitiveType, RuntimeType},
|
types::{NumericType, PrimitiveType, RuntimeType, UnitLen},
|
||||||
Face, Helix, ImportedGeometry, Metadata, Plane, Sketch, Solid, TagIdentifier,
|
EnvironmentRef, ExecState, Face, Helix, ImportedGeometry, MetaSettings, Metadata, Plane, Sketch, Solid,
|
||||||
|
TagIdentifier,
|
||||||
},
|
},
|
||||||
parsing::ast::types::{
|
parsing::ast::types::{
|
||||||
DefaultParamVal, FunctionExpression, KclNone, Literal, LiteralValue, Node, TagDeclarator, TagNode,
|
DefaultParamVal, FunctionExpression, KclNone, Literal, LiteralValue, Node, TagDeclarator, TagNode,
|
||||||
|
@ -780,7 +780,10 @@ impl ExecutorContext {
|
|||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
results_tx.send((module_id, module_path, result)).await.unwrap();
|
results_tx
|
||||||
|
.send((module_id, module_path, result))
|
||||||
|
.await
|
||||||
|
.unwrap_or_default();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
@ -800,7 +803,10 @@ impl ExecutorContext {
|
|||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
results_tx.send((module_id, module_path, result)).await.unwrap();
|
results_tx
|
||||||
|
.send((module_id, module_path, result))
|
||||||
|
.await
|
||||||
|
.unwrap_or_default();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -809,13 +815,13 @@ impl ExecutorContext {
|
|||||||
|
|
||||||
while let Some((module_id, _, result)) = results_rx.recv().await {
|
while let Some((module_id, _, result)) = results_rx.recv().await {
|
||||||
match result {
|
match result {
|
||||||
Ok((_, session_data, variables)) => {
|
Ok((val, session_data, variables)) => {
|
||||||
let mut repr = exec_state.global.module_infos[&module_id].take_repr();
|
let mut repr = exec_state.global.module_infos[&module_id].take_repr();
|
||||||
|
|
||||||
let ModuleRepr::Kcl(_, cache) = &mut repr else {
|
let ModuleRepr::Kcl(_, cache) = &mut repr else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
*cache = Some((session_data, variables.clone()));
|
*cache = Some((val, session_data, variables.clone()));
|
||||||
|
|
||||||
exec_state.global.module_infos[&module_id].restore_repr(repr);
|
exec_state.global.module_infos[&module_id].restore_repr(repr);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
errors::{KclError, KclErrorDetails},
|
errors::{KclError, KclErrorDetails},
|
||||||
|
exec::KclValue,
|
||||||
execution::{EnvironmentRef, PreImportedGeometry},
|
execution::{EnvironmentRef, PreImportedGeometry},
|
||||||
fs::{FileManager, FileSystem},
|
fs::{FileManager, FileSystem},
|
||||||
parsing::ast::types::{ImportPath, Node, Program},
|
parsing::ast::types::{ImportPath, Node, Program},
|
||||||
@ -94,7 +95,7 @@ pub(crate) fn read_std(mod_name: &str) -> Option<&'static str> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Info about a module.
|
/// Info about a module.
|
||||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize)]
|
||||||
pub struct ModuleInfo {
|
pub struct ModuleInfo {
|
||||||
/// The ID of the module.
|
/// The ID of the module.
|
||||||
pub(crate) id: ModuleId,
|
pub(crate) id: ModuleId,
|
||||||
@ -117,11 +118,11 @@ impl ModuleInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::large_enum_variant)]
|
#[allow(clippy::large_enum_variant)]
|
||||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize)]
|
||||||
pub enum ModuleRepr {
|
pub enum ModuleRepr {
|
||||||
Root,
|
Root,
|
||||||
// AST, memory, exported names
|
// AST, memory, exported names
|
||||||
Kcl(Node<Program>, Option<(EnvironmentRef, Vec<String>)>),
|
Kcl(Node<Program>, Option<(Option<KclValue>, EnvironmentRef, Vec<String>)>),
|
||||||
Foreign(PreImportedGeometry),
|
Foreign(PreImportedGeometry),
|
||||||
Dummy,
|
Dummy,
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user