forked from M-Labs/nac3
52 lines
1.8 KiB
Rust
52 lines
1.8 KiB
Rust
|
use std::collections::HashMap;
|
||
|
|
||
|
use super::typedef::{SharedUnifier, Type};
|
||
|
use crossbeam::queue::SegQueue;
|
||
|
use crossbeam::sync::ShardedLock;
|
||
|
use rustpython_parser::ast::Stmt;
|
||
|
|
||
|
pub struct DefinitionId(usize);
|
||
|
|
||
|
pub enum TopLevelDef {
|
||
|
Class {
|
||
|
// object ID used for TypeEnum
|
||
|
object_id: usize,
|
||
|
// type variables bounded to the class.
|
||
|
type_vars: Vec<Type>,
|
||
|
// class fields and method signature.
|
||
|
fields: Vec<(String, Type)>,
|
||
|
// class methods, pointing to the corresponding function definition.
|
||
|
methods: Vec<(String, DefinitionId)>,
|
||
|
// ancestor classes, including itself.
|
||
|
ancestors: Vec<DefinitionId>,
|
||
|
},
|
||
|
Function {
|
||
|
signature: Type,
|
||
|
/// Function instance to symbol mapping
|
||
|
/// Key: string representation of type variable values, sorted by variable ID in ascending
|
||
|
/// order, including type variables associated with the class.
|
||
|
/// Value: function symbol name.
|
||
|
instance_to_symbol: HashMap<String, String>,
|
||
|
/// Function instances to annotated AST mapping
|
||
|
/// Key: string representation of type variable values, sorted by variable ID in ascending
|
||
|
/// order, including type variables associated with the class. Excluding rigid type
|
||
|
/// variables.
|
||
|
/// Value: AST annotated with types together with a unification table index. Could contain
|
||
|
/// rigid type variables that would be substituted when the function is instantiated.
|
||
|
instance_to_stmt: HashMap<String, (Stmt<Type>, usize)>,
|
||
|
},
|
||
|
}
|
||
|
|
||
|
pub struct CodeGenTask {
|
||
|
pub subst: HashMap<usize, Type>,
|
||
|
pub symbol_name: String,
|
||
|
pub body: Stmt<Type>,
|
||
|
pub unifier: SharedUnifier,
|
||
|
}
|
||
|
|
||
|
pub struct TopLevelContext {
|
||
|
pub definitions: Vec<ShardedLock<TopLevelDef>>,
|
||
|
pub unifiers: Vec<SharedUnifier>,
|
||
|
pub codegen_queue: SegQueue<CodeGenTask>,
|
||
|
}
|