Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ lcov.info
*.profraw
*.profdata
/target/llvm-cov-target/
/target/coverage/
/target/coverage/
4 changes: 0 additions & 4 deletions crates/plotnik-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ pub struct TypesOutputArgs {
#[arg(long, default_value = "typescript", value_name = "FORMAT")]
pub format: String,

/// Name for the root type (for anonymous expressions)
#[arg(long, default_value = "Query", value_name = "NAME")]
pub root_type: String,

/// Use verbose node shape (matches exec --verbose-nodes)
#[arg(long)]
pub verbose_nodes: bool,
Expand Down
6 changes: 4 additions & 2 deletions crates/plotnik-cli/src/commands/debug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ pub fn run(args: DebugArgs) {
if args.types
&& let Some(ref q) = query
{
let output =
plotnik_lib::query::type_check::emit_typescript(q.type_context(), q.interner());
let bytecode = q.emit().expect("bytecode emission failed");
let module =
plotnik_lib::bytecode::Module::from_bytes(bytecode).expect("module loading failed");
let output = plotnik_lib::bytecode::emit::emit_typescript(&module);
print!("{}", output);
}

Expand Down
15 changes: 9 additions & 6 deletions crates/plotnik-cli/src/commands/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ use std::path::PathBuf;

use plotnik_langs::Lang;
use plotnik_lib::Query;
use plotnik_lib::query::type_check::{EmitConfig, emit_typescript_with_config};
use plotnik_lib::bytecode::emit::{TsEmitConfig, emit_typescript_with_config};

pub struct TypesArgs {
pub query_text: Option<String>,
pub query_file: Option<PathBuf>,
pub lang: Option<String>,
pub format: String,
pub root_type: String,
pub verbose_nodes: bool,
pub no_node_type: bool,
pub export: bool,
Expand Down Expand Up @@ -44,15 +43,19 @@ pub fn run(args: TypesArgs) {
std::process::exit(1);
}

// Emit TypeScript types
let config = EmitConfig {
// Emit to bytecode first
let bytecode = query.emit().expect("bytecode emission failed");
let module =
plotnik_lib::bytecode::Module::from_bytes(bytecode).expect("module loading failed");

// Emit TypeScript types from bytecode
let config = TsEmitConfig {
export: args.export,
emit_node_type: !args.no_node_type,
root_type_name: args.root_type,
verbose_nodes: args.verbose_nodes,
};

let output = emit_typescript_with_config(query.type_context(), query.interner(), config);
let output = emit_typescript_with_config(&module, config);

// Write output
if let Some(ref path) = args.output {
Expand Down
1 change: 0 additions & 1 deletion crates/plotnik-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ fn main() {
query_file: query.query_file,
lang,
format: output.format,
root_type: output.root_type,
verbose_nodes: output.verbose_nodes,
no_node_type: output.no_node_type,
export: !output.no_export,
Expand Down
2 changes: 1 addition & 1 deletion crates/plotnik-lib/src/query/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::query::type_check::DefId;
use crate::query::visitor::{Visitor, walk_expr};

/// Result of dependency analysis.
#[derive(Debug, Clone, Default)]
#[derive(Clone, Debug, Default)]
pub struct DependencyAnalysis {
/// Strongly connected components in reverse topological order.
///
Expand Down
5 changes: 4 additions & 1 deletion crates/plotnik-lib/src/query/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ mod test_helpers {
}

pub fn emit_typescript(&self) -> String {
crate::query::type_check::emit_typescript(self.type_context(), self.interner())
let bytecode = self.emit().expect("bytecode emission should succeed");
let module = crate::bytecode::Module::from_bytes(bytecode)
.expect("module loading should succeed");
crate::bytecode::emit::emit_typescript(&module)
}
}
}
7 changes: 6 additions & 1 deletion crates/plotnik-lib/src/query/query_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use plotnik_langs::Lang;

use crate::{
SourceMap,
bytecode::Module,
query::query::{LinkedQuery, QueryAnalyzed, QueryBuilder},
};

Expand Down Expand Up @@ -85,7 +86,11 @@ impl QueryAnalyzed {
query.dump_diagnostics()
);
}
query.emit_typescript()

// Emit to bytecode and then emit TypeScript from the bytecode module
let bytecode = query.emit().expect("bytecode emission should succeed");
let module = Module::from_bytes(bytecode).expect("module loading should succeed");
crate::bytecode::emit::emit_typescript(&module)
}

#[track_caller]
Expand Down
2 changes: 1 addition & 1 deletion crates/plotnik-lib/src/query/symbol_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub const UNNAMED_DEF: &str = "_";
///
/// Stores the mapping from definition names to their AST expressions,
/// along with source file information for diagnostics.
#[derive(Debug, Clone, Default)]
#[derive(Clone, Debug, Default)]
pub struct SymbolTable {
/// Maps symbol name to its AST expression.
table: IndexMap<String, ast::Expr>,
Expand Down
2 changes: 1 addition & 1 deletion crates/plotnik-lib/src/query/type_check/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::types::{
};

/// Central registry for types, symbols, and expression metadata.
#[derive(Debug, Clone)]
#[derive(Clone, Debug)]
pub struct TypeContext {
types: Vec<TypeKind>,
type_map: HashMap<TypeKind, TypeId>,
Expand Down
Loading