Skip to content

Commit

Permalink
Start on LLVM codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
yorickpeterse committed Nov 22, 2022
1 parent d454bb2 commit 6fa59f2
Show file tree
Hide file tree
Showing 17 changed files with 3,486 additions and 763 deletions.
5 changes: 2 additions & 3 deletions compiler/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use crate::type_check::define_types::{
use crate::type_check::expressions::{DefineConstants, Expressions};
use crate::type_check::imports::DefineImportedTypes;
use crate::type_check::methods::{
define_builtin_functions, CheckMainMethod, DefineMethods,
DefineModuleMethodNames, ImplementTraitMethods,
CheckMainMethod, DefineMethods, DefineModuleMethodNames,
ImplementTraitMethods,
};
use std::env::current_dir;
use std::ffi::OsStr;
Expand Down Expand Up @@ -187,7 +187,6 @@ impl Compiler {
&& DefineMethods::run_all(state, modules)
&& CheckMainMethod::run(state)
&& ImplementTraitMethods::run_all(state, modules)
&& define_builtin_functions(state)
&& DefineConstants::run_all(state, modules)
&& Expressions::run_all(state, modules)
}
Expand Down
39 changes: 25 additions & 14 deletions compiler/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,15 @@ impl ConstExpression {
Self::Invalid(ref l) => l,
}
}

pub(crate) fn is_simple_literal(&self) -> bool {
matches!(
self,
ConstExpression::Int(_)
| ConstExpression::Float(_)
| ConstExpression::String(_)
)
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -2056,12 +2065,13 @@ impl<'a> LowerToHir<'a> {

fn call(&mut self, node: ast::Call) -> Expression {
if self.is_builtin_call(&node) {
if !self.module.is_std(&self.state.db) {
self.state.diagnostics.invalid_builtin_function(
self.file(),
node.location.clone(),
);
}
// TODO: re-enable
// if !self.module.is_std(&self.state.db) {
// self.state.diagnostics.invalid_builtin_function(
// self.file(),
// node.location.clone(),
// );
// }

return Expression::BuiltinCall(Box::new(BuiltinCall {
info: None,
Expand Down Expand Up @@ -2610,12 +2620,13 @@ impl<'a> LowerToHir<'a> {
})),
ast::Expression::Call(call) => {
if self.is_builtin_call(&call) {
if !self.module.is_std(&self.state.db) {
self.state.diagnostics.invalid_builtin_function(
self.file(),
call.location.clone(),
);
}
// TODO: re-enable
// if !self.module.is_std(&self.state.db) {
// self.state.diagnostics.invalid_builtin_function(
// self.file(),
// call.location.clone(),
// );
// }

Expression::BuiltinCall(Box::new(BuiltinCall {
info: None,
Expand Down Expand Up @@ -2938,7 +2949,7 @@ impl<'a> LowerToHir<'a> {
Expression::BuiltinCall(Box::new(BuiltinCall {
info: None,
name: Identifier {
name: types::BuiltinName::PanicThrown.name().to_string(),
name: types::BuiltinFunction::PanicThrown.name().to_string(),
location: location.clone(),
},
arguments: vec![Expression::IdentifierRef(Box::new(
Expand Down Expand Up @@ -5960,7 +5971,7 @@ mod tests {
BuiltinCall {
info: None,
name: Identifier {
name: types::BuiltinName::PanicThrown
name: types::BuiltinFunction::PanicThrown
.name()
.to_string(),
location: cols(8, 14)
Expand Down
Loading

0 comments on commit 6fa59f2

Please sign in to comment.