Skip to content

Commit e143485

Browse files
committed
Temp
1 parent bf598ad commit e143485

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+213
-168
lines changed

crates/rue-compiler/src/compiler.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
database::{Database, HirId, ScopeId, SymbolId, TypeId},
1212
hir::Hir,
1313
scope::Scope,
14-
ty::{PairType, Type, Value},
14+
value::{PairType, Type, Value},
1515
ErrorKind,
1616
};
1717

crates/rue-compiler/src/compiler/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rue_parser::{AstNode, Block, Stmt};
22

3-
use crate::{hir::Hir, ty::Value, ErrorKind, TypeId};
3+
use crate::{hir::Hir, value::Value, ErrorKind, TypeId};
44

55
use super::{stmt::Statement, Compiler};
66

crates/rue-compiler/src/compiler/builtins.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{
22
hir::Hir,
33
scope::Scope,
44
symbol::{Function, Symbol},
5-
ty::{FunctionType, Rest, Type},
5+
value::{FunctionType, Rest, Type},
66
Database, HirId, ScopeId, SymbolId, TypeId,
77
};
88

crates/rue-compiler/src/compiler/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
optimizer::{DependencyGraph, Optimizer},
1010
scope::Scope,
1111
symbol::{Module, Symbol},
12-
ty::Type,
12+
value::Type,
1313
Database, SymbolId,
1414
};
1515

crates/rue-compiler/src/compiler/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rue_parser::{AstNode, Expr};
22

3-
use crate::{ty::Value, TypeId};
3+
use crate::{value::Value, TypeId};
44

55
use super::Compiler;
66

crates/rue-compiler/src/compiler/expr/binary_expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rue_parser::{AstNode, BinaryExpr, BinaryOp, Expr};
44
use crate::{
55
compiler::Compiler,
66
hir::{BinOp, Hir},
7-
ty::{Guard, Value},
7+
value::{Guard, Value},
88
ErrorKind, HirId, TypeId,
99
};
1010

crates/rue-compiler/src/compiler/expr/block_expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rue_parser::{AstNode, Block};
22

3-
use crate::{compiler::Compiler, scope::Scope, ty::Value, ErrorKind, TypeId};
3+
use crate::{compiler::Compiler, scope::Scope, value::Value, ErrorKind, TypeId};
44

55
impl Compiler<'_> {
66
pub fn compile_block_expr(&mut self, block: &Block, expected_type: Option<TypeId>) -> Value {

crates/rue-compiler/src/compiler/expr/cast_expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rue_parser::{AstNode, CastExpr};
22

3-
use crate::{compiler::Compiler, ty::Value};
3+
use crate::{compiler::Compiler, value::Value};
44

55
impl Compiler<'_> {
66
pub fn compile_cast_expr(&mut self, cast: &CastExpr) -> Value {

crates/rue-compiler/src/compiler/expr/field_access_expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rue_parser::FieldAccessExpr;
33
use crate::{
44
compiler::Compiler,
55
hir::Hir,
6-
ty::{Guard, PairType, Type, Value},
6+
value::{Guard, PairType, Type, Value},
77
ErrorKind,
88
};
99

crates/rue-compiler/src/compiler/expr/function_call_expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rue_parser::{AstNode, FunctionCallExpr};
55
use crate::{
66
compiler::Compiler,
77
hir::Hir,
8-
ty::{FunctionType, Rest, Type, Value},
8+
value::{FunctionType, Rest, Type, Value},
99
ErrorKind, TypeId,
1010
};
1111

crates/rue-compiler/src/compiler/expr/group_expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rue_parser::GroupExpr;
22

3-
use crate::{compiler::Compiler, ty::Value, TypeId};
3+
use crate::{compiler::Compiler, value::Value, TypeId};
44

55
impl Compiler<'_> {
66
pub fn compile_group_expr(

crates/rue-compiler/src/compiler/expr/guard_expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rue_parser::{AstNode, GuardExpr};
44
use crate::{
55
compiler::Compiler,
66
hir::{BinOp, Hir},
7-
ty::{Guard, PairType, Type, Value},
7+
value::{Guard, PairType, Type, Value},
88
Comparison, ErrorKind, HirId, TypeId, WarningKind,
99
};
1010

crates/rue-compiler/src/compiler/expr/if_expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rue_parser::{AstNode, IfExpr};
22

3-
use crate::{compiler::Compiler, hir::Hir, ty::Value, TypeId};
3+
use crate::{compiler::Compiler, hir::Hir, value::Value, TypeId};
44

55
impl Compiler<'_> {
66
pub fn compile_if_expr(&mut self, if_expr: &IfExpr, expected_type: Option<TypeId>) -> Value {

crates/rue-compiler/src/compiler/expr/index_access_expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rue_parser::{AstNode, IndexAccessExpr};
22

33
use crate::{
44
compiler::Compiler,
5-
ty::{Type, Value},
5+
value::{Type, Value},
66
ErrorKind,
77
};
88

crates/rue-compiler/src/compiler/expr/initializer_expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rue_parser::{AstNode, InitializerExpr, InitializerField};
77
use crate::{
88
compiler::Compiler,
99
hir::Hir,
10-
ty::{Type, Value},
10+
value::{Type, Value},
1111
ErrorKind, HirId, TypeId,
1212
};
1313

crates/rue-compiler/src/compiler/expr/lambda_expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
hir::Hir,
66
scope::Scope,
77
symbol::{Function, Symbol},
8-
ty::{FunctionType, Rest, Type, Value},
8+
value::{FunctionType, Rest, Type, Value},
99
ErrorKind, TypeId,
1010
};
1111

crates/rue-compiler/src/compiler/expr/list_expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rue_parser::{AstNode, ListExpr};
33
use crate::{
44
compiler::Compiler,
55
hir::Hir,
6-
ty::{Type, Value},
6+
value::{Type, Value},
77
ErrorKind, TypeId,
88
};
99

crates/rue-compiler/src/compiler/expr/literal_expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clvmr::Allocator;
22
use num_bigint::BigInt;
33
use rue_parser::{LiteralExpr, SyntaxKind, SyntaxToken};
44

5-
use crate::{compiler::Compiler, hir::Hir, ty::Value, ErrorKind};
5+
use crate::{compiler::Compiler, hir::Hir, value::Value, ErrorKind};
66

77
impl Compiler<'_> {
88
pub fn compile_literal_expr(&mut self, literal: &LiteralExpr) -> Value {

crates/rue-compiler/src/compiler/expr/pair_expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rue_parser::{AstNode, PairExpr};
33
use crate::{
44
compiler::Compiler,
55
hir::Hir,
6-
ty::{PairType, Type, Value},
6+
value::{PairType, Type, Value},
77
TypeId,
88
};
99

crates/rue-compiler/src/compiler/expr/path_expr.rs

+24-16
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use crate::{
77
Compiler,
88
},
99
hir::Hir,
10-
symbol::{Const, Function, Let, Symbol},
11-
ty::{Type, Value},
10+
symbol::{Function, Symbol},
11+
value::{Type, Value},
1212
ErrorKind,
1313
};
1414

@@ -59,20 +59,28 @@ impl Compiler<'_> {
5959
return self.unknown();
6060
}
6161

62-
let type_id =
63-
self.symbol_type(symbol_id)
64-
.unwrap_or_else(|| match self.db.symbol(symbol_id) {
65-
Symbol::Unknown | Symbol::Module(..) => unreachable!(),
66-
Symbol::Function(Function { ty, .. })
67-
| Symbol::InlineFunction(Function { ty, .. }) => {
68-
self.db.alloc_type(Type::Function(ty.clone()))
69-
}
70-
Symbol::Parameter(type_id)
71-
| Symbol::Let(Let { type_id, .. })
72-
| Symbol::Const(Const { type_id, .. })
73-
| Symbol::InlineConst(Const { type_id, .. }) => *type_id,
74-
});
62+
let override_type_id = self.symbol_type(symbol_id);
7563

76-
Value::new(self.db.alloc_hir(Hir::Reference(symbol_id)), type_id)
64+
match self.db.symbol(symbol_id).clone() {
65+
Symbol::Unknown | Symbol::Module(..) => unreachable!(),
66+
Symbol::Function(Function { ty, .. }) | Symbol::InlineFunction(Function { ty, .. }) => {
67+
let type_id = self.db.alloc_type(Type::Function(ty.clone()));
68+
Value::new(
69+
self.db.alloc_hir(Hir::Reference(symbol_id)),
70+
override_type_id.unwrap_or(type_id),
71+
)
72+
}
73+
Symbol::Parameter(type_id) => Value::new(
74+
self.db.alloc_hir(Hir::Reference(symbol_id)),
75+
override_type_id.unwrap_or(type_id),
76+
),
77+
Symbol::Let(mut value) | Symbol::Const(mut value) | Symbol::InlineConst(mut value) => {
78+
if let Some(type_id) = override_type_id {
79+
value.type_id = type_id;
80+
}
81+
value.hir_id = self.db.alloc_hir(Hir::Reference(symbol_id));
82+
value
83+
}
84+
}
7785
}
7886
}

crates/rue-compiler/src/compiler/expr/prefix_expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rue_parser::{AstNode, PrefixExpr, PrefixOp};
33
use crate::{
44
compiler::Compiler,
55
hir::{BinOp, Hir},
6-
ty::Value,
6+
value::Value,
77
};
88

99
impl Compiler<'_> {

crates/rue-compiler/src/compiler/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::HashSet;
22

33
use rue_parser::Item;
44

5-
use crate::{symbol::Symbol, ty::Type, ErrorKind, SymbolId, TypeId};
5+
use crate::{symbol::Symbol, value::Type, ErrorKind, SymbolId, TypeId};
66

77
use super::Compiler;
88

crates/rue-compiler/src/compiler/item/const_item.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
use rue_parser::{AstNode, ConstItem};
22

3-
use crate::{
4-
compiler::Compiler,
5-
hir::Hir,
6-
symbol::{Const, Symbol},
7-
SymbolId,
8-
};
3+
use crate::{compiler::Compiler, hir::Hir, symbol::Symbol, value::Value, SymbolId};
94

105
impl Compiler<'_> {
116
/// Define a constant in the current scope, but don't lower its body.
@@ -21,9 +16,9 @@ impl Compiler<'_> {
2116
let hir_id = self.db.alloc_hir(Hir::Unknown);
2217

2318
if const_item.inline().is_some() {
24-
*self.db.symbol_mut(symbol_id) = Symbol::InlineConst(Const { type_id, hir_id });
19+
*self.db.symbol_mut(symbol_id) = Symbol::InlineConst(Value::new(hir_id, type_id));
2520
} else {
26-
*self.db.symbol_mut(symbol_id) = Symbol::Const(Const { type_id, hir_id });
21+
*self.db.symbol_mut(symbol_id) = Symbol::Const(Value::new(hir_id, type_id));
2722
}
2823

2924
if let Some(name) = const_item.name() {
@@ -40,24 +35,25 @@ impl Compiler<'_> {
4035
return;
4136
};
4237

43-
let (Symbol::Const(Const { type_id, .. }) | Symbol::InlineConst(Const { type_id, .. })) =
38+
let (Symbol::Const(Value { type_id, .. }) | Symbol::InlineConst(Value { type_id, .. })) =
4439
self.db.symbol(symbol_id).clone()
4540
else {
4641
unreachable!();
4742
};
4843

49-
let output = self.compile_expr(&expr, Some(type_id));
44+
let mut value = self.compile_expr(&expr, Some(type_id));
5045

5146
// Ensure that the expression is assignable to the constant's type.
52-
self.type_check(output.type_id, type_id, const_item.syntax().text_range());
47+
self.type_check(value.type_id, type_id, const_item.syntax().text_range());
48+
value.type_id = type_id;
5349

5450
// We ignore type guards here for now.
5551
// Just set the constant HIR.
56-
let (Symbol::Const(Const { hir_id, .. }) | Symbol::InlineConst(Const { hir_id, .. })) =
52+
let (Symbol::Const(symbol_value) | Symbol::InlineConst(symbol_value)) =
5753
self.db.symbol_mut(symbol_id)
5854
else {
5955
unreachable!();
6056
};
61-
*hir_id = output.hir_id;
57+
*symbol_value = value;
6258
}
6359
}

crates/rue-compiler/src/compiler/item/enum_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rue_parser::EnumItem;
88
use crate::{
99
compiler::Compiler,
1010
hir::Hir,
11-
ty::{EnumType, EnumVariantType, Type},
11+
value::{EnumType, EnumVariantType, Type},
1212
ErrorKind, TypeId,
1313
};
1414

crates/rue-compiler/src/compiler/item/function_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
hir::Hir,
66
scope::Scope,
77
symbol::{Function, Symbol},
8-
ty::{FunctionType, Rest, Type},
8+
value::{FunctionType, Rest, Type},
99
ErrorKind, SymbolId,
1010
};
1111

crates/rue-compiler/src/compiler/item/struct_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rue_parser::{StructField, StructItem};
33

44
use crate::{
55
compiler::Compiler,
6-
ty::{StructType, Type},
6+
value::{StructType, Type},
77
TypeId,
88
};
99

crates/rue-compiler/src/compiler/item/type_alias_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rue_parser::{AstNode, TypeAliasItem};
22

3-
use crate::{compiler::Compiler, ty::Type, TypeId};
3+
use crate::{compiler::Compiler, value::Type, TypeId};
44

55
impl Compiler<'_> {
66
/// Define a type for an alias in the current scope, but leave it as unknown for now.

crates/rue-compiler/src/compiler/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rue_parser::SyntaxToken;
22

3-
use crate::{symbol::Symbol, ty::Type, ErrorKind, SymbolId, TypeId};
3+
use crate::{symbol::Symbol, value::Type, ErrorKind, SymbolId, TypeId};
44

55
use super::Compiler;
66

crates/rue-compiler/src/compiler/stmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{ty::Value, HirId, ScopeId};
1+
use crate::{value::Value, HirId, ScopeId};
22

33
mod if_stmt;
44
mod let_stmt;

crates/rue-compiler/src/compiler/stmt/let_stmt.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
use rue_parser::{AstNode, LetStmt};
22

3-
use crate::{
4-
compiler::Compiler,
5-
scope::Scope,
6-
symbol::{Let, Symbol},
7-
ScopeId,
8-
};
3+
use crate::{compiler::Compiler, scope::Scope, symbol::Symbol, ScopeId};
94

105
impl Compiler<'_> {
116
/// Compiles a let statement and returns its new scope id.
@@ -18,7 +13,7 @@ impl Compiler<'_> {
1813
let expected_type = let_stmt.ty().map(|ty| self.compile_type(ty));
1914

2015
// Compile the expression.
21-
let value = let_stmt
16+
let mut value = let_stmt
2217
.expr()
2318
.map(|expr| self.compile_expr(&expr, expected_type))
2419
.unwrap_or(self.unknown());
@@ -35,10 +30,11 @@ impl Compiler<'_> {
3530
return None;
3631
};
3732

38-
*self.db.symbol_mut(symbol_id) = Symbol::Let(Let {
39-
type_id: expected_type.unwrap_or(value.type_id),
40-
hir_id: value.hir_id,
41-
});
33+
if let Some(expected_type) = expected_type {
34+
value.type_id = expected_type;
35+
}
36+
37+
*self.db.symbol_mut(symbol_id) = Symbol::Let(value);
4238

4339
// Every let binding is a new scope for now, to ensure references are resolved in the proper order.
4440
let mut let_scope = Scope::default();

crates/rue-compiler/src/compiler/symbol_table.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use std::collections::HashSet;
33
use indexmap::{IndexMap, IndexSet};
44

55
use crate::{
6-
optimizer::DependencyGraph, symbol::Symbol, ty::Type, Database, SymbolId, TypeId, WarningKind,
6+
optimizer::DependencyGraph, symbol::Symbol, value::Type, Database, SymbolId, TypeId,
7+
WarningKind,
78
};
89

910
#[derive(Debug, Default)]

crates/rue-compiler/src/compiler/ty/function_type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rue_parser::{AstNode, FunctionType as Ast};
44

55
use crate::{
66
compiler::Compiler,
7-
ty::{FunctionType, Rest, Type},
7+
value::{FunctionType, Rest, Type},
88
ErrorKind, TypeId,
99
};
1010

0 commit comments

Comments
 (0)