Add metadata location to function calls
This commit is contained in:
parent
33d5ee03f0
commit
d7661cb968
@ -2,8 +2,8 @@
|
||||
extern fn puts(message: string) -> i32;
|
||||
|
||||
struct DivT {
|
||||
quot: i32,
|
||||
rem: i32,
|
||||
quotient: i32,
|
||||
remainder: i32,
|
||||
}
|
||||
|
||||
extern fn div(numerator: i32, denominator: i32) -> DivT;
|
||||
|
@ -89,11 +89,7 @@ impl BinaryOperator {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct FunctionCallExpression(
|
||||
pub String,
|
||||
pub Vec<Expression>,
|
||||
#[allow(dead_code)] pub TokenRange,
|
||||
);
|
||||
pub struct FunctionCallExpression(pub String, pub Vec<Expression>, pub TokenRange);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct IfExpression(
|
||||
|
@ -188,6 +188,7 @@ impl ast::Expression {
|
||||
.iter()
|
||||
.map(|e| e.process(module_id))
|
||||
.collect(),
|
||||
meta: fn_call_expr.2.as_meta(module_id),
|
||||
})
|
||||
}
|
||||
ast::ExpressionKind::BlockExpr(block) => {
|
||||
|
@ -648,11 +648,13 @@ impl mir::Expression {
|
||||
))
|
||||
}
|
||||
mir::ExprKind::FunctionCall(call) => {
|
||||
let ret_type = call
|
||||
let ret_type_kind = call
|
||||
.return_type
|
||||
.known()
|
||||
.expect("function return type unknown");
|
||||
|
||||
let ret_type = ret_type_kind.get_type(scope.type_values, scope.types);
|
||||
|
||||
let params = call
|
||||
.parameters
|
||||
.iter()
|
||||
@ -663,18 +665,56 @@ impl mir::Expression {
|
||||
.get(&call.name)
|
||||
.expect("function not found!");
|
||||
dbg!(&self, &callee.ir.value());
|
||||
Some(StackValue(
|
||||
StackValueKind::Immutable(
|
||||
scope
|
||||
|
||||
let val = scope
|
||||
.block
|
||||
.build(
|
||||
call.name.clone(),
|
||||
Instr::FunctionCall(callee.ir.value(), params),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
if let Some(debug) = &scope.debug {
|
||||
let location = call.meta.into_debug(scope.tokens).unwrap();
|
||||
let location_val = debug.info.location(&debug.scope, location);
|
||||
val.with_location(&mut scope.block, location_val);
|
||||
}
|
||||
|
||||
let ptr = if ret_type_kind != TypeKind::Void {
|
||||
let ptr = scope
|
||||
.block
|
||||
.build(&call.name, Instr::Alloca(ret_type.clone()))
|
||||
.unwrap();
|
||||
scope
|
||||
.block
|
||||
.build(format!("{}.store", call.name), Instr::Store(ptr, val))
|
||||
.unwrap();
|
||||
|
||||
Some(ptr)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
if let Some(ptr) = ptr {
|
||||
if state.should_load {
|
||||
Some(StackValue(
|
||||
StackValueKind::Immutable(
|
||||
scope
|
||||
.block
|
||||
.build(call.name.clone(), Instr::Load(ptr, ret_type))
|
||||
.unwrap(),
|
||||
),
|
||||
ret_type,
|
||||
ret_type_kind,
|
||||
))
|
||||
} else {
|
||||
Some(StackValue(
|
||||
StackValueKind::Immutable(ptr),
|
||||
TypeKind::Ptr(Box::new(ret_type_kind)),
|
||||
))
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
mir::ExprKind::If(if_expression) => if_expression.codegen(scope, state),
|
||||
mir::ExprKind::Block(block) => {
|
||||
|
@ -259,6 +259,7 @@ pub struct FunctionCall {
|
||||
pub name: String,
|
||||
pub return_type: TypeKind,
|
||||
pub parameters: Vec<Expression>,
|
||||
pub meta: Metadata,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -5,8 +5,7 @@ import std::intdiv;
|
||||
fn main() -> i32 {
|
||||
let hello = "hello world";
|
||||
|
||||
|
||||
print(hello);
|
||||
|
||||
return intdiv(10, 5).quot;
|
||||
return intdiv(15, 5).quotient;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user