Skip to content

Commit e51945a

Browse files
committed
Working on structs
1 parent 94c0ab8 commit e51945a

File tree

12 files changed

+171
-105
lines changed

12 files changed

+171
-105
lines changed

crates/crunch-parser/src/parser/expr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ use crunch_shared::{
1010
tracing,
1111
trees::{
1212
ast::{
13-
Arm, Block, BlockColor, BlockExpr, Expr, ExprKind, For, If, IfCond, Literal,
14-
LiteralVal, Loop, Match, StructField, StructLiteral, Type, While,
13+
Arm, Block, BlockExpr, Expr, ExprKind, For, If, IfCond, Literal, LiteralVal, Loop,
14+
Match, StructField, StructLiteral, Type, While,
1515
},
16-
ItemPath, Sided,
16+
BlockColor, ItemPath, Sided,
1717
},
1818
};
1919

crates/crunch-shared/src/trees/ast.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
error::{Locatable, Location, Span},
33
strings::{StrInterner, StrT},
4-
trees::{Attribute, CallConv, ItemPath, Sided, Sign, Vis},
4+
trees::{Attribute, BlockColor, CallConv, ItemPath, Sided, Sign, Vis},
55
};
66
#[cfg(feature = "no-std")]
77
use alloc::{
@@ -305,14 +305,6 @@ pub struct BlockExpr<'ctx> {
305305
pub colors: Vec<BlockColor>,
306306
}
307307

308-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
309-
#[repr(u8)]
310-
pub enum BlockColor {
311-
Unsafe,
312-
Async,
313-
Const,
314-
}
315-
316308
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
317309
pub struct If<'ctx> {
318310
pub clauses: Vec<IfCond<'ctx>>,

crates/crunch-shared/src/trees/hir.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pub use crate::trees::{
33
BinaryOp, CompOp, Float, Integer, Literal as AstLiteral, LiteralVal as AstLiteralVal, Rune,
44
Text, Type as AstType,
55
},
6-
Attribute, ItemPath, Signedness, Vis,
6+
Attribute, BlockColor, ItemPath, Signedness, Vis,
77
};
88
use crate::{
99
error::{Locatable, Location, Span},
@@ -215,24 +215,39 @@ pub struct Break<'ctx> {
215215
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
216216
pub struct Block<T> {
217217
pub block: Vec<T>,
218+
pub colors: Vec<BlockColor>,
218219
pub loc: Location,
219220
}
220221

221222
impl<T> Block<T> {
222223
pub fn new(block: Vec<T>, loc: Location) -> Self {
223-
Self { block, loc }
224+
Self {
225+
block,
226+
colors: Vec::new(),
227+
loc,
228+
}
224229
}
225230

226231
pub fn empty(loc: Location) -> Self {
227232
Self {
228233
block: Vec::new(),
234+
colors: Vec::new(),
229235
loc,
230236
}
231237
}
232238

233239
pub fn with_capacity(loc: Location, capacity: usize) -> Self {
234240
Self {
235241
block: Vec::with_capacity(capacity),
242+
colors: Vec::new(),
243+
loc,
244+
}
245+
}
246+
247+
pub fn with_capacity_and_colors(loc: Location, capacity: usize, colors: usize) -> Self {
248+
Self {
249+
block: Vec::with_capacity(capacity),
250+
colors: Vec::with_capacity(colors),
236251
loc,
237252
}
238253
}
@@ -241,6 +256,17 @@ impl<T> Block<T> {
241256
self.block.push(item);
242257
}
243258

259+
pub fn push_color(&mut self, color: BlockColor) {
260+
self.colors.push(color);
261+
}
262+
263+
pub fn extend_colors<I>(&mut self, colors: I)
264+
where
265+
I: Iterator<Item = BlockColor>,
266+
{
267+
self.colors.extend(colors);
268+
}
269+
244270
pub fn insert(&mut self, idx: usize, item: T) {
245271
self.block.insert(idx, item);
246272
}
@@ -279,7 +305,11 @@ impl<T> Block<T> {
279305
block.push(item);
280306
}
281307

282-
Self { block, loc }
308+
Self {
309+
block,
310+
colors: Vec::new(),
311+
loc,
312+
}
283313
}
284314
}
285315

crates/crunch-shared/src/trees/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,11 @@ impl Default for Vis {
246246
Self::FileLocal
247247
}
248248
}
249+
250+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
251+
#[repr(u8)]
252+
pub enum BlockColor {
253+
Unsafe,
254+
Async,
255+
Const,
256+
}

crates/crunch-typecheck/build.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,32 @@ fn traverse<P: AsRef<Path>, F: Fn(&DirEntry)>(dir: P, func: &F) -> io::Result<()
4343
}
4444

4545
fn build_ddlog() -> Result<(), Box<dyn Error>> {
46+
const DDLOG_ARGS: &[&str] = &[
47+
#[cfg(windows)]
48+
"ddlog",
49+
"-i",
50+
"ddlog/typecheck.dl",
51+
"-L",
52+
".",
53+
"--output-dir",
54+
"typecheck_ddlog",
55+
"--omit-profile",
56+
"--omit-workspace",
57+
"--run-rustfmt",
58+
];
59+
4660
if env::var("DDLOG_HOME").is_err() {
4761
println!("cargo:warning=`DDLOG_HOME` is not set, building may not work properly");
4862
}
4963

50-
Command::new("ddlog")
51-
.args(&[
52-
"-i",
53-
"ddlog/typecheck.dl",
54-
"-L",
55-
".",
56-
"--output-dir",
57-
"typecheck_ddlog",
58-
"--omit-profile",
59-
"--omit-workspace",
60-
"--run-rustfmt",
61-
])
62-
.spawn()?
63-
.wait()?;
64+
if cfg!(windows) {
65+
Command::new("wsl")
66+
} else {
67+
Command::new("ddlog")
68+
}
69+
.args(DDLOG_ARGS)
70+
.spawn()?
71+
.wait()?;
6472

6573
Ok(())
6674
}

crates/crunch-typecheck/ddlog/typecheck.dl

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -46,42 +46,10 @@ UnifiedTypes(expr_id, unified_type) :-
4646
Types(type_id, ty),
4747
var unified_type = Aggregate((expr_id), unify_types((type_id, ty))).
4848

49-
function unify_types(types: Group<'K, (TypeId, Type)>): Result<TypeId, string> {
50-
var uni_type_id = None {};
51-
var uni_type = None {};
52-
49+
function unify_types(types: Group<'K, (TypeId, Type)>): TypeId {
5350
for (ty in types) {
54-
if (ty.0 < min_type_id) {
55-
min_type_id = ty.0;
56-
min_type = ty.1
57-
}
51+
dbg(ty);
5852
};
5953

60-
Ok { uni_type_id }
54+
1
6155
}
62-
63-
// // Get the types out of literals
64-
// PropagateExprType(id, kind, ty) :- InputExpressions(id, kind, _),
65-
// ExprLit { .lit = var lit } = kind.ival(),
66-
// var ty = lit.typeof().
67-
// // Get the types out of assignments
68-
// PropagateExprType(id, kind, ty) :- InputExpressions(id, kind, _),
69-
// ExprAssign { .expr_id = var expr_id } = kind.ival(),
70-
// PropagateExprType(expr_id, _, ty).
71-
// // Get the types of variables by looking at their assignment
72-
// PropagateExprType(id, kind, ty) :- InputExpressions(id, kind, _),
73-
// ExprVar { .variable = var expr_var } = kind.ival(),
74-
// PropagateExprType(_, prop_kind, ty),
75-
// ExprAssign { .variable = var prop_var } = prop_kind.ival(),
76-
// expr_var == prop_var.
77-
//
78-
// output relation ClampUnknownInt(id: ExprId, kind: Intern<ExprKind>, ty: Intern<TypeKind>)
79-
// // Clamp totally unknown integers to i32
80-
// ClampUnknownInt(id, kind, ty) :- PropagateExprType(id, kind, ty),
81-
// Int { None, None } = ty.ival(),
82-
// var ty = intern(Int { Some{true}, Some{32} }).
83-
//
84-
// // Allow other types to pass through unaffected
85-
// ClampUnknownInt(id, kind, ty) :- PropagateExprType(id, kind, ty),
86-
// Int { Some{}, Some{} } = ty.ival().
87-
// ClampUnknownInt(id, kind, ty) :- PropagateExprType(id, kind, ty), not ty.is_int().
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use core::fmt::Debug;
22

33
pub fn dbg<T: Debug>(thing: T) -> T {
4-
dbg!(thing)
4+
println!("[ddlog debug]: {:?}", thing);
5+
thing
56
}

crates/crunch-typecheck/typecheck_ddlog/Cargo.toml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ autobins = false
66
build = "src/build.rs"
77

88
[features]
9-
default = []
9+
default = ["command-line"]
1010
flatbuf = ["differential_datalog/flatbuf", "types/flatbuf", "value/flatbuf"]
1111
profile = ["cpuprofiler"]
12-
# ovsdb = ["ddlog_ovsdb_adapter", "types/ovsdb", "value/ovsdb"]
13-
# command-line = ["cmd_parser", "rustop"]
12+
ovsdb = ["ddlog_ovsdb_adapter", "types/ovsdb", "value/ovsdb"]
13+
command-line = ["cmd_parser", "rustop"]
1414

1515
[target.'cfg(not(windows))'.build-dependencies]
1616
libtool = "0.1"
1717

1818
[dependencies.differential_datalog]
1919
path = "./differential_datalog"
2020

21-
# [dependencies.cmd_parser]
22-
# path = "./cmd_parser"
23-
# optional = true
21+
[dependencies.cmd_parser]
22+
path = "./cmd_parser"
23+
optional = true
2424

25-
# [dependencies.ddlog_ovsdb_adapter]
26-
# path = "./ovsdb"
27-
# optional = true
25+
[dependencies.ddlog_ovsdb_adapter]
26+
path = "./ovsdb"
27+
optional = true
2828

2929
[dependencies.types]
3030
path = "./types"
@@ -43,7 +43,7 @@ once_cell = "1.4.1"
4343
libc = "0.2"
4444
num-traits = "0.2"
4545
num = { version = "0.2", features = ["serde"] }
46-
# rustop = { version = "1.0.2", optional = true }
46+
rustop = { version = "1.0.2", optional = true }
4747
serde = { version = "1.0", features = ["derive"] }
4848
timely = "0.11"
4949

@@ -61,3 +61,4 @@ name = "typecheck_ddlog"
6161
# crate-type = ["rlib", "staticlib"]
6262

6363
crate-type = ["rlib", "staticlib"]
64+

crates/crunch-typecheck/typecheck_ddlog/types/Cargo.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ autobins = false
77
[features]
88
default = []
99
flatbuf = ["flatbuffers", "differential_datalog/flatbuf"]
10-
# ovsdb = ["ddlog_ovsdb_adapter"]
10+
ovsdb = ["ddlog_ovsdb_adapter"]
1111

1212
[dependencies.differential_datalog]
1313
path = "../differential_datalog"
1414

15-
# [dependencies.ddlog_ovsdb_adapter]
16-
# path = "../ovsdb"
17-
# optional = true
15+
[dependencies.ddlog_ovsdb_adapter]
16+
path = "../ovsdb"
17+
optional = true
1818

1919
[dependencies]
2020
abomonation = "0.7"
@@ -40,5 +40,6 @@ name = "types"
4040
path = "lib.rs"
4141

4242

43+
4344
[dependencies.arc-interner]
44-
version = "0.1"
45+
version="0.1"

0 commit comments

Comments
 (0)