Incremental naming
This commit is contained in:
+12
-6
@@ -34,7 +34,6 @@ pub struct StructRef {
|
|||||||
pub export: bool,
|
pub export: bool,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub fields: HashMap<String, Arc<VarRef>>,
|
pub fields: HashMap<String, Arc<VarRef>>,
|
||||||
pub methods: HashMap<String, FunctionRef>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -63,10 +62,12 @@ impl TopLevelHirScope {
|
|||||||
|
|
||||||
pub fn function_ref(&mut self, tlss: &TopLevelSymbolScope, symbol: &FunctionSymbol) {
|
pub fn function_ref(&mut self, tlss: &TopLevelSymbolScope, symbol: &FunctionSymbol) {
|
||||||
if self.variables.get(&symbol.name).is_none() {
|
if self.variables.get(&symbol.name).is_none() {
|
||||||
|
let name = self.get_name(symbol.export);
|
||||||
|
|
||||||
if let Some(_) = tlss.functions.get(&symbol.name) {
|
if let Some(_) = tlss.functions.get(&symbol.name) {
|
||||||
let rf = FunctionRef {
|
let rf = FunctionRef {
|
||||||
export: symbol.export,
|
export: symbol.export,
|
||||||
name: symbol.name.clone(),
|
name: name.clone(),
|
||||||
params: symbol
|
params: symbol
|
||||||
.params
|
.params
|
||||||
.iter()
|
.iter()
|
||||||
@@ -81,7 +82,7 @@ impl TopLevelHirScope {
|
|||||||
self.variables.insert(
|
self.variables.insert(
|
||||||
symbol.name.clone(),
|
symbol.name.clone(),
|
||||||
Arc::new(VarRef {
|
Arc::new(VarRef {
|
||||||
name: symbol.name.clone(),
|
name: name.clone(),
|
||||||
var_type: Arc::new(TypeRef::Function(rf)),
|
var_type: Arc::new(TypeRef::Function(rf)),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -96,21 +97,22 @@ impl TopLevelHirScope {
|
|||||||
tlss: &TopLevelSymbolScope,
|
tlss: &TopLevelSymbolScope,
|
||||||
symbol: &StructSymbol,
|
symbol: &StructSymbol,
|
||||||
) -> Arc<TypeRef> {
|
) -> Arc<TypeRef> {
|
||||||
|
let name = self.get_name(symbol.export);
|
||||||
|
|
||||||
let rf = Arc::new(TypeRef::Struct(StructRef {
|
let rf = Arc::new(TypeRef::Struct(StructRef {
|
||||||
export: symbol.export,
|
export: symbol.export,
|
||||||
name: symbol.name.clone(),
|
name: name.clone(),
|
||||||
fields: symbol
|
fields: symbol
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(name, v)| (name.clone(), self.var_ref(tlss, v)))
|
.map(|(name, v)| (name.clone(), self.var_ref(tlss, v)))
|
||||||
.collect(),
|
.collect(),
|
||||||
methods: HashMap::new(),
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
self.variables.insert(
|
self.variables.insert(
|
||||||
symbol.name.clone(),
|
symbol.name.clone(),
|
||||||
Arc::new(VarRef {
|
Arc::new(VarRef {
|
||||||
name: symbol.name.clone(),
|
name: name.clone(),
|
||||||
var_type: rf.clone(),
|
var_type: rf.clone(),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -167,4 +169,8 @@ impl TopLevelHirScope {
|
|||||||
pub fn next_var_idx(&self) -> usize {
|
pub fn next_var_idx(&self) -> usize {
|
||||||
self.var_idx.fetch_add(1, Ordering::Relaxed) + 1
|
self.var_idx.fetch_add(1, Ordering::Relaxed) + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_name(&self, export: bool) -> String {
|
||||||
|
format!("{}{}", if export { 'V' } else { 'v' }, self.next_var_idx())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,8 +89,6 @@ impl LocalScope {
|
|||||||
) -> Option<Arc<TypeRef>> {
|
) -> Option<Arc<TypeRef>> {
|
||||||
let mut current_type = self.get_type_from_expr(initial)?;
|
let mut current_type = self.get_type_from_expr(initial)?;
|
||||||
|
|
||||||
dbg!(current_type.clone(), initial, postfixes);
|
|
||||||
|
|
||||||
for postfix in postfixes {
|
for postfix in postfixes {
|
||||||
match postfix {
|
match postfix {
|
||||||
Postfix::FieldAccess(id) => match &*current_type {
|
Postfix::FieldAccess(id) => match &*current_type {
|
||||||
|
|||||||
Reference in New Issue
Block a user