pyvm: split op handlers into ops_core/ops_box/ops_ctrl; add ops_flow + intrinsic; delegate vm.py without behavior change
net-plugin: modularize constants (consts.rs) and sockets (sockets.rs); remove legacy commented socket code; fix unused imports mir: move instruction unit tests to tests/mir_instruction_unit.rs (file lean-up); no semantic changes runner/pyvm: ensure using pre-strip; misc docs updates Build: cargo build ok; legacy cfg warnings remain as before
This commit is contained in:
@ -38,6 +38,16 @@ pub fn ast_to_json(ast: &ASTNode) -> Value {
|
||||
"then": then_body.into_iter().map(|s| ast_to_json(&s)).collect::<Vec<_>>(),
|
||||
"else": else_body.map(|v| v.into_iter().map(|s| ast_to_json(&s)).collect::<Vec<_>>()),
|
||||
}),
|
||||
ASTNode::TryCatch { try_body, catch_clauses, finally_body, .. } => json!({
|
||||
"kind": "TryCatch",
|
||||
"try": try_body.into_iter().map(|s| ast_to_json(&s)).collect::<Vec<_>>(),
|
||||
"catch": catch_clauses.into_iter().map(|cc| json!({
|
||||
"type": cc.exception_type,
|
||||
"var": cc.variable_name,
|
||||
"body": cc.body.into_iter().map(|s| ast_to_json(&s)).collect::<Vec<_>>()
|
||||
})).collect::<Vec<_>>(),
|
||||
"cleanup": finally_body.map(|v| v.into_iter().map(|s| ast_to_json(&s)).collect::<Vec<_>>())
|
||||
}),
|
||||
ASTNode::FunctionDeclaration { name, params, body, is_static, is_override, .. } => json!({
|
||||
"kind": "FunctionDeclaration",
|
||||
"name": name,
|
||||
@ -155,6 +165,20 @@ pub fn json_to_ast(v: &Value) -> Option<ASTNode> {
|
||||
span: Span::unknown(),
|
||||
}
|
||||
}
|
||||
"TryCatch" => {
|
||||
let try_b = v.get("try")?.as_array()?.iter().filter_map(json_to_ast).collect::<Vec<_>>();
|
||||
let mut catches = Vec::new();
|
||||
if let Some(arr) = v.get("catch").and_then(|x| x.as_array()) {
|
||||
for c in arr.iter() {
|
||||
let exc_t = match c.get("type") { Some(t) if !t.is_null() => t.as_str().map(|s| s.to_string()), _ => None };
|
||||
let var = match c.get("var") { Some(vv) if !vv.is_null() => vv.as_str().map(|s| s.to_string()), _ => None };
|
||||
let body = c.get("body")?.as_array()?.iter().filter_map(json_to_ast).collect::<Vec<_>>();
|
||||
catches.push(nyash_rust::ast::CatchClause { exception_type: exc_t, variable_name: var, body, span: Span::unknown() });
|
||||
}
|
||||
}
|
||||
let cleanup = v.get("cleanup").and_then(|cl| cl.as_array().map(|arr| arr.iter().filter_map(json_to_ast).collect::<Vec<_>>()));
|
||||
ASTNode::TryCatch { try_body: try_b, catch_clauses: catches, finally_body: cleanup, span: Span::unknown() }
|
||||
}
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user