feat: Add compact AST dump
Introduce a new `dump_ast_compact` function for the environment and Dumper. This function provides a simplified, human-readable representation of the AST, focusing on inferred types and purity markers instead of detailed debug information. This change adds: - A `compact` flag to the `Dumper` struct. - The `dump_compact` method to the `Dumper`. - The `dump_ast_compact` method to the `Environment`. - A new `dump_ast_compact` command-line argument for the `ast` binary. - A new MCP server endpoint `dump_ast_compact`. - A `CompactMetadata` trait to abstract over different metadata types for compact display. - Updates to documentation and CLI help messages.
This commit is contained in:
+18
-2
@@ -70,10 +70,12 @@ impl MycMcpServer {
|
||||
}
|
||||
}
|
||||
|
||||
/// Dumps the compiled and optimized AST for a Myc expression.
|
||||
/// Dumps the compiled and optimized AST for a Myc expression (verbose debug format).
|
||||
#[tool(description = "Compile a Myc expression and return a human-readable dump of \
|
||||
the compiled AST. Useful for understanding how the compiler transforms code \
|
||||
through its optimization and lowering passes.")]
|
||||
through its optimization and lowering passes. \
|
||||
Returns the full debug format including binding addresses and stack offsets. \
|
||||
Use dump_ast_compact for a cleaner view focused on types and purity.")]
|
||||
fn dump_ast(&self, Parameters(CodeInput { code }): Parameters<CodeInput>) -> String {
|
||||
let env = Self::make_env();
|
||||
match env.dump_ast(&code) {
|
||||
@@ -82,6 +84,20 @@ impl MycMcpServer {
|
||||
}
|
||||
}
|
||||
|
||||
/// Dumps the compiled AST in compact, human-readable format.
|
||||
#[tool(description = "Compile a Myc expression and return a compact AST dump showing \
|
||||
inferred types (e.g. 'fn([int]) -> bool') and purity markers ('!' for impure, \
|
||||
'~' for side-effect-free). '[tail]' marks tail-call positions. \
|
||||
Omits internal details like stack offsets and binding addresses. \
|
||||
Prefer this over dump_ast when you want to understand the type structure of an expression.")]
|
||||
fn dump_ast_compact(&self, Parameters(CodeInput { code }): Parameters<CodeInput>) -> String {
|
||||
let env = Self::make_env();
|
||||
match env.dump_ast_compact(&code) {
|
||||
Ok(dump) => dump,
|
||||
Err(e) => format!("Error: {}", e),
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks the syntax and types of a Myc expression without executing it.
|
||||
#[tool(description = "Check the syntax and types of a Myc expression without running it. \
|
||||
Returns 'OK' if the code is valid, or a list of compiler diagnostics on error. \
|
||||
|
||||
Reference in New Issue
Block a user