Compare commits
No commits in common. "02522dd36d34ab363d6d19824a40b60b776a4306" and "70a968d7a0995a20027366cd7e4ad143c3fced87" have entirely different histories.
02522dd36d
...
70a968d7a0
@ -9,7 +9,6 @@ fn main() -> i32 {
|
||||
i32::memcpy(potus, otus, 1);
|
||||
|
||||
printf("log10 %f\n", f64::round(123.3) as f64);
|
||||
printf("sqrt %f\n", f64::sqrt(2) as f64);
|
||||
printf("log10 %f\n", potus[0] as f64);
|
||||
return potus[0];
|
||||
}
|
@ -192,9 +192,13 @@ impl AnalysisState {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_symbol(&mut self, definition: usize, kind: SemanticKind) -> SymbolId {
|
||||
pub fn new_symbol(&mut self, definition: usize, kind: SemanticKind, module_id: SourceModuleId) -> SymbolId {
|
||||
let id = SymbolId(self.symbol_table.len());
|
||||
self.symbol_table.push(Symbol { kind, definition });
|
||||
self.symbol_table.push(Symbol {
|
||||
kind,
|
||||
definition,
|
||||
module_id,
|
||||
});
|
||||
id
|
||||
}
|
||||
|
||||
@ -219,6 +223,7 @@ impl AnalysisState {
|
||||
pub struct Symbol {
|
||||
pub kind: SemanticKind,
|
||||
pub definition: usize,
|
||||
pub module_id: SourceModuleId,
|
||||
}
|
||||
|
||||
pub struct AnalysisScope<'a> {
|
||||
@ -301,6 +306,7 @@ pub enum SemanticKind {
|
||||
Type,
|
||||
Struct,
|
||||
Comment,
|
||||
Operator,
|
||||
Keyword,
|
||||
Reference(SourceModuleId, SymbolId),
|
||||
}
|
||||
@ -322,6 +328,7 @@ impl SemanticKind {
|
||||
SemanticKind::Property => SemanticTokenType::PROPERTY,
|
||||
SemanticKind::Struct => SemanticTokenType::STRUCT,
|
||||
SemanticKind::Comment => SemanticTokenType::COMMENT,
|
||||
SemanticKind::Operator => SemanticTokenType::OPERATOR,
|
||||
SemanticKind::Keyword => SemanticTokenType::KEYWORD,
|
||||
SemanticKind::Default => return None,
|
||||
SemanticKind::Reference(module_id, symbol_id) => {
|
||||
@ -353,6 +360,7 @@ impl SemanticKind {
|
||||
SemanticKind::Property => SemanticTokenModifier::DECLARATION,
|
||||
SemanticKind::Struct => SemanticTokenModifier::DEFINITION,
|
||||
SemanticKind::Comment => return None,
|
||||
SemanticKind::Operator => return None,
|
||||
SemanticKind::Keyword => return None,
|
||||
SemanticKind::Reference(..) => SEMANTIC_REFERENCE,
|
||||
};
|
||||
@ -467,7 +475,7 @@ pub fn analyze_context(
|
||||
_ => None,
|
||||
};
|
||||
if let Some(semantic) = semantic_token {
|
||||
let symbol = scope.state.new_symbol(i, semantic);
|
||||
let symbol = scope.state.new_symbol(i, semantic, module.module_id);
|
||||
scope.state.set_symbol(i, symbol);
|
||||
}
|
||||
}
|
||||
@ -529,7 +537,9 @@ pub fn analyze_context(
|
||||
let struct_idx = scope
|
||||
.token_idx(&typedef.meta, |t| matches!(t, Token::Identifier(_)))
|
||||
.unwrap_or(typedef.meta.range.end);
|
||||
let struct_symbol = scope.state.new_symbol(struct_idx, SemanticKind::Struct);
|
||||
let struct_symbol = scope
|
||||
.state
|
||||
.new_symbol(struct_idx, SemanticKind::Struct, module.module_id);
|
||||
scope.state.set_symbol(struct_idx, struct_symbol);
|
||||
|
||||
let ty = TypeKind::CustomType(CustomTypeKey(typedef.name.clone(), typedef.source_module));
|
||||
@ -553,7 +563,9 @@ pub fn analyze_context(
|
||||
Some(field.1.clone()),
|
||||
);
|
||||
|
||||
let field_symbol = scope.state.new_symbol(field_idx, SemanticKind::Property);
|
||||
let field_symbol = scope
|
||||
.state
|
||||
.new_symbol(field_idx, SemanticKind::Property, module.module_id);
|
||||
scope.state.set_symbol(field_idx, field_symbol);
|
||||
|
||||
scope.state.properties.insert(
|
||||
@ -575,7 +587,7 @@ pub fn analyze_context(
|
||||
let idx = scope
|
||||
.token_idx(¶m.meta, |t| matches!(t, Token::Identifier(_)))
|
||||
.unwrap_or(param.meta.range.end);
|
||||
let symbol = scope.state.new_symbol(idx, SemanticKind::Variable);
|
||||
let symbol = scope.state.new_symbol(idx, SemanticKind::Variable, module.module_id);
|
||||
scope.state.set_symbol(idx, symbol);
|
||||
scope.variables.insert(param.name.clone(), symbol);
|
||||
}
|
||||
@ -605,7 +617,7 @@ pub fn analyze_context(
|
||||
let idx = scope
|
||||
.token_idx(&function.signature(), |t| matches!(t, Token::Identifier(_)))
|
||||
.unwrap_or(function.signature().range.end);
|
||||
let symbol = scope.state.new_symbol(idx, SemanticKind::Function);
|
||||
let symbol = scope.state.new_symbol(idx, SemanticKind::Function, module.module_id);
|
||||
scope.state.set_symbol(idx, symbol);
|
||||
scope
|
||||
.state
|
||||
@ -632,7 +644,9 @@ pub fn analyze_context(
|
||||
let param_idx = inner_scope
|
||||
.token_idx(¶m.meta, |t| matches!(t, Token::Identifier(_)))
|
||||
.unwrap_or(function.signature().range.end);
|
||||
let param_symbol = inner_scope.state.new_symbol(param_idx, SemanticKind::Variable);
|
||||
let param_symbol = inner_scope
|
||||
.state
|
||||
.new_symbol(param_idx, SemanticKind::Variable, module.module_id);
|
||||
inner_scope.state.set_symbol(param_idx, param_symbol);
|
||||
inner_scope.variables.insert(param.name.clone(), param_symbol);
|
||||
}
|
||||
@ -664,7 +678,7 @@ pub fn analyze_context(
|
||||
let idx = scope
|
||||
.token_idx(&function.signature(), |t| matches!(t, Token::Identifier(_)))
|
||||
.unwrap_or(function.signature().range.end);
|
||||
let function_symbol = scope.state.new_symbol(idx, SemanticKind::Function);
|
||||
let function_symbol = scope.state.new_symbol(idx, SemanticKind::Function, module.module_id);
|
||||
scope.state.set_symbol(idx, function_symbol);
|
||||
scope.state.functions.insert(function.name.clone(), function_symbol);
|
||||
scope
|
||||
@ -687,7 +701,9 @@ pub fn analyze_context(
|
||||
let idx = inner_scope
|
||||
.token_idx(¶m.meta, |t| matches!(t, Token::Identifier(_)))
|
||||
.unwrap_or(function.signature().range.end);
|
||||
let symbol = inner_scope.state.new_symbol(idx, SemanticKind::Variable);
|
||||
let symbol = inner_scope
|
||||
.state
|
||||
.new_symbol(idx, SemanticKind::Variable, module.module_id);
|
||||
inner_scope.state.set_symbol(idx, symbol);
|
||||
inner_scope.variables.insert(param.name.clone(), symbol);
|
||||
}
|
||||
@ -728,7 +744,9 @@ pub fn analyze_block(
|
||||
let idx = scope
|
||||
.token_idx(&named_variable_ref.2, |t| matches!(t, Token::Identifier(_)))
|
||||
.unwrap_or(named_variable_ref.2.range.end);
|
||||
let symbol = scope.state.new_symbol(idx, SemanticKind::Variable);
|
||||
let symbol = scope
|
||||
.state
|
||||
.new_symbol(idx, SemanticKind::Variable, source_module.module_id);
|
||||
scope.state.set_symbol(idx, symbol);
|
||||
scope.variables.insert(named_variable_ref.1.clone(), symbol);
|
||||
|
||||
@ -776,11 +794,13 @@ pub fn analyze_expr(
|
||||
.token_idx(&var_ref.2, |t| matches!(t, Token::Identifier(_)))
|
||||
.unwrap_or(var_ref.2.range.end);
|
||||
let symbol = if let Some(symbol_id) = scope.variables.get(&var_ref.1) {
|
||||
scope
|
||||
.state
|
||||
.new_symbol(idx, SemanticKind::Reference(source_module.module_id, *symbol_id))
|
||||
scope.state.new_symbol(
|
||||
idx,
|
||||
SemanticKind::Reference(source_module.module_id, *symbol_id),
|
||||
source_module.module_id,
|
||||
)
|
||||
} else {
|
||||
scope.state.new_symbol(idx, SemanticKind::Type)
|
||||
scope.state.new_symbol(idx, SemanticKind::Type, source_module.module_id)
|
||||
};
|
||||
scope.state.set_symbol(idx, symbol);
|
||||
}
|
||||
@ -820,11 +840,15 @@ pub fn analyze_expr(
|
||||
let field_symbol = if let Some((module_id, symbol_id)) =
|
||||
scope.find_property(accessed_type.clone(), name.clone())
|
||||
{
|
||||
scope.state.new_symbol(
|
||||
field_idx,
|
||||
SemanticKind::Reference(module_id, symbol_id),
|
||||
source_module.module_id,
|
||||
)
|
||||
} else {
|
||||
scope
|
||||
.state
|
||||
.new_symbol(field_idx, SemanticKind::Reference(module_id, symbol_id))
|
||||
} else {
|
||||
scope.state.new_symbol(field_idx, SemanticKind::Property)
|
||||
.new_symbol(field_idx, SemanticKind::Property, source_module.module_id)
|
||||
};
|
||||
scope.state.set_symbol(field_idx, field_symbol);
|
||||
|
||||
@ -859,11 +883,15 @@ pub fn analyze_expr(
|
||||
.unwrap_or(expr.1.range.end);
|
||||
|
||||
let struct_symbol = if let Some(symbol_id) = scope.state.types.get(&struct_type) {
|
||||
scope.state.new_symbol(
|
||||
struct_idx,
|
||||
SemanticKind::Reference(source_module.module_id, *symbol_id),
|
||||
source_module.module_id,
|
||||
)
|
||||
} else {
|
||||
scope
|
||||
.state
|
||||
.new_symbol(struct_idx, SemanticKind::Reference(source_module.module_id, *symbol_id))
|
||||
} else {
|
||||
scope.state.new_symbol(struct_idx, SemanticKind::Struct)
|
||||
.new_symbol(struct_idx, SemanticKind::Struct, source_module.module_id)
|
||||
};
|
||||
scope.state.set_symbol(struct_idx, struct_symbol);
|
||||
|
||||
@ -874,11 +902,15 @@ pub fn analyze_expr(
|
||||
|
||||
let field_symbol =
|
||||
if let Some(symbol_id) = scope.state.properties.get(&(struct_type.clone(), field_name.clone())) {
|
||||
scope.state.new_symbol(
|
||||
field_idx,
|
||||
SemanticKind::Reference(source_module.module_id, *symbol_id),
|
||||
source_module.module_id,
|
||||
)
|
||||
} else {
|
||||
scope
|
||||
.state
|
||||
.new_symbol(field_idx, SemanticKind::Reference(source_module.module_id, *symbol_id))
|
||||
} else {
|
||||
scope.state.new_symbol(field_idx, SemanticKind::Property)
|
||||
.new_symbol(field_idx, SemanticKind::Property, source_module.module_id)
|
||||
};
|
||||
|
||||
scope.state.set_symbol(field_idx, field_symbol);
|
||||
@ -888,14 +920,18 @@ pub fn analyze_expr(
|
||||
}
|
||||
mir::ExprKind::Literal(_) => {
|
||||
if let Some(idx) = scope.token_idx(&expr.1, |t| matches!(t, Token::StringLit(_) | Token::CharLit(_))) {
|
||||
scope.state.new_symbol(idx, SemanticKind::String);
|
||||
scope
|
||||
.state
|
||||
.new_symbol(idx, SemanticKind::String, source_module.module_id);
|
||||
} else if let Some(idx) = scope.token_idx(&expr.1, |t| {
|
||||
matches!(
|
||||
t,
|
||||
Token::DecimalValue(_) | Token::HexadecimalValue(_) | Token::OctalValue(_) | Token::BinaryValue(_)
|
||||
)
|
||||
}) {
|
||||
scope.state.new_symbol(idx, SemanticKind::Number);
|
||||
scope
|
||||
.state
|
||||
.new_symbol(idx, SemanticKind::Number, source_module.module_id);
|
||||
}
|
||||
}
|
||||
mir::ExprKind::BinOp(_, lhs, rhs, _) => {
|
||||
@ -913,11 +949,15 @@ pub fn analyze_expr(
|
||||
.token_idx(&meta, |t| matches!(t, Token::Identifier(_)))
|
||||
.unwrap_or(meta.range.end);
|
||||
let symbol = if let Some((module_id, symbol_id)) = scope.functions.get(name) {
|
||||
scope.state.new_symbol(
|
||||
idx,
|
||||
SemanticKind::Reference(*module_id, *symbol_id),
|
||||
source_module.module_id,
|
||||
)
|
||||
} else {
|
||||
scope
|
||||
.state
|
||||
.new_symbol(idx, SemanticKind::Reference(*module_id, *symbol_id))
|
||||
} else {
|
||||
scope.state.new_symbol(idx, SemanticKind::Function)
|
||||
.new_symbol(idx, SemanticKind::Function, source_module.module_id)
|
||||
};
|
||||
scope.state.set_symbol(idx, symbol);
|
||||
}
|
||||
@ -937,11 +977,15 @@ pub fn analyze_expr(
|
||||
};
|
||||
|
||||
let type_symbol = if let Some((module_id, symbol_id)) = scope.types.get(&invoked_ty) {
|
||||
scope.state.new_symbol(
|
||||
type_idx,
|
||||
SemanticKind::Reference(*module_id, *symbol_id),
|
||||
source_module.module_id,
|
||||
)
|
||||
} else {
|
||||
scope
|
||||
.state
|
||||
.new_symbol(type_idx, SemanticKind::Reference(*module_id, *symbol_id))
|
||||
} else {
|
||||
scope.state.new_symbol(type_idx, SemanticKind::Type)
|
||||
.new_symbol(type_idx, SemanticKind::Type, source_module.module_id)
|
||||
};
|
||||
scope.state.set_symbol(type_idx, type_symbol);
|
||||
|
||||
@ -951,11 +995,15 @@ pub fn analyze_expr(
|
||||
let fn_symbol = if let Some((module_id, symbol_id)) =
|
||||
scope.associated_functions.get(&(invoked_ty.clone(), name.clone()))
|
||||
{
|
||||
scope.state.new_symbol(
|
||||
fn_idx,
|
||||
SemanticKind::Reference(*module_id, *symbol_id),
|
||||
source_module.module_id,
|
||||
)
|
||||
} else {
|
||||
scope
|
||||
.state
|
||||
.new_symbol(fn_idx, SemanticKind::Reference(*module_id, *symbol_id))
|
||||
} else {
|
||||
scope.state.new_symbol(fn_idx, SemanticKind::Function)
|
||||
.new_symbol(fn_idx, SemanticKind::Function, source_module.module_id)
|
||||
};
|
||||
scope.state.set_symbol(fn_idx, fn_symbol);
|
||||
|
||||
|
@ -20,6 +20,7 @@ fn main() -> Result<(), std::io::Error> {
|
||||
let mir_path = parent.with_extension("mir");
|
||||
let asm_path = parent.with_extension("asm");
|
||||
|
||||
#[cfg(feature = "log_output")]
|
||||
let before = std::time::SystemTime::now();
|
||||
|
||||
let text = fs::read_to_string(&path)?;
|
||||
@ -53,13 +54,16 @@ fn main() -> Result<(), std::io::Error> {
|
||||
fs::write(&object_path, &obj_buffer).expect("Could not write Object-file!");
|
||||
fs::write(&llir_path, &llir).expect("Could not write LLIR-file!");
|
||||
fs::write(&mir_path, &mir).expect("Could not write MIR-file!");
|
||||
let after = std::time::SystemTime::now();
|
||||
println!(
|
||||
"Compilation took: {:.2}ms\n",
|
||||
(after.duration_since(before).unwrap().as_micros() as f32) / 1000.
|
||||
);
|
||||
#[cfg(feature = "log_output")]
|
||||
{
|
||||
let after = std::time::SystemTime::now();
|
||||
println!(
|
||||
"Compilation took: {:.2}ms\n",
|
||||
(after.duration_since(before).unwrap().as_micros() as f32) / 1000.
|
||||
);
|
||||
|
||||
println!("Linking {:?}", &object_path);
|
||||
println!("Linking {:?}", &object_path);
|
||||
}
|
||||
|
||||
let linker = std::env::var("LD").unwrap_or("ld".to_owned());
|
||||
let mut linker = LDRunner::from_command(&linker).with_library("c").with_library("m");
|
||||
|
@ -721,7 +721,7 @@ impl Expression {
|
||||
expr.resolve_ref(typerefs).cast_into(type_kind)
|
||||
}
|
||||
ExprKind::AssociatedFunctionCall(type_kind, function_call) => {
|
||||
*type_kind = type_kind.or_default()?;
|
||||
*type_kind = type_kind.or_default().unwrap();
|
||||
let true_function = state
|
||||
.scope
|
||||
.get_associated_function(&pass::AssociatedFunctionKey(
|
||||
|
Loading…
Reference in New Issue
Block a user