Skip to content

Commit 5f1e008

Browse files
Type milestone (#38)
* type table, scope table, and linter is busted * type-milestone paused
1 parent 85f5b79 commit 5f1e008

File tree

2 files changed

+55
-20
lines changed

2 files changed

+55
-20
lines changed

linter/src/lib.rs

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use typetable::*;
1111

1212
type ResultTreeType = Result<(Rc<Box<TypeTree>>, Ty), usize>;
1313

14+
#[derive(Debug)]
1415
pub struct LintSource<'buf, 'ttb, 'sco> {
1516
buffer: &'buf str,
1617
idx: u32,
@@ -124,7 +125,7 @@ impl<'buf, 'ttb, 'sco> LintSource<'buf, 'ttb, 'sco> {
124125
self.inc_scope_tracker();
125126
if let Some(args) = td.args.as_ref() {
126127
args.iter().for_each(|x| {
127-
let res = self.lint_recurse(x);
128+
let res = self.check_arg_def(&x.into_arg_def());
128129
if let Ok(a) = res {
129130
largs.push(a.0);
130131
largs_curried.push(a.1);
@@ -311,15 +312,14 @@ impl<'buf, 'ttb, 'sco> LintSource<'buf, 'ttb, 'sco> {
311312
}
312313

313314
pub fn check_value_type(&mut self, _vt: &ValueType) -> ResultTreeType {
314-
let mut curried = Ty::Unknown;
315-
match _vt.val.token {
316-
Token::U64 => curried = Ty::U64,
317-
Token::U32 => curried = Ty::U32,
318-
Token::USize => curried = Ty::USize,
319-
Token::ISize => curried = Ty::ISize,
320-
Token::F64 => curried = Ty::F64,
321-
Token::U8 => curried = Ty::U8,
322-
Token::Char => curried = Ty::Char,
315+
let curried = match _vt.val.token {
316+
Token::U64 => Ty::U64,
317+
Token::U32 => Ty::U32,
318+
Token::USize => Ty::USize,
319+
Token::ISize => Ty::ISize,
320+
Token::F64 => Ty::F64,
321+
Token::U8 => Ty::U8,
322+
Token::Char => Ty::Char,
323323
_ => panic!("type lang issue, unmatched value type: {:?}", _vt.val),
324324
};
325325
let copied = curried.clone();
@@ -339,37 +339,54 @@ impl<'buf, 'ttb, 'sco> LintSource<'buf, 'ttb, 'sco> {
339339
let mut c_err: Option<Ty> = None;
340340
let mut c_undefined: Option<Ty> = None;
341341
let mut curried = Ty::Unknown;
342+
let mut tag = vec![];
342343

343344
if let Some(right) = &_sig.right_most_type {
344345
c_right = match self.lint_recurse(&right) {
345-
Err(_) => Some(Ty::Unknown),
346-
Ok(v) => Some(v.1),
346+
Err(_) => {
347+
tag.push(Ty::Unknown);
348+
Some(Ty::Unknown)
349+
}
350+
Ok(v) => {
351+
tag.push(v.1.clone());
352+
Some(v.1)
353+
}
347354
}
348355
}
349356
if let Some(left) = &_sig.left_most_type {
350357
c_left = match self.lint_recurse(&left) {
351-
Err(_) => Ty::Unknown,
352-
Ok(v) => v.1,
358+
Err(_) => {
359+
tag.push(Ty::Unknown);
360+
Ty::Unknown
361+
}
362+
Ok(v) => {
363+
tag.push(v.1.clone());
364+
v.1
365+
}
353366
}
354367
}
355368
if let Some(_) = &_sig.err {
356369
c_err = Some(Ty::Error);
370+
tag.push(Ty::Error);
357371
}
358372
if let Some(_) = &_sig.undef {
359373
c_undefined = Some(Ty::Undefined);
374+
tag.push(Ty::Undefined);
360375
}
361376
if c_right.is_some() || c_err.is_some() || c_undefined.is_some() {
362377
sig_info.left = c_left;
363378
sig_info.err = c_err;
364379
sig_info.undefined = c_undefined;
365380
sig_info.right = c_right;
366381
let full = tree!(SigTypes, sig_info);
382+
curried = Ty::Tag(tag);
367383

368384
return Ok((full, curried));
369385
}
370386

371-
let full = tree!(SingleType, c_left);
372-
return Ok((full, curried));
387+
curried = c_left.clone();
388+
let full = tree!(SingleType, curried);
389+
return Ok((full, c_left));
373390
}
374391

375392
pub fn check_self_value(&mut self) -> ResultTreeType {
@@ -835,7 +852,7 @@ impl<'buf, 'ttb, 'sco> LintSource<'buf, 'ttb, 'sco> {
835852

836853
let tbl = self.ttbls.get_mut(self.curr_scope as usize).unwrap();
837854

838-
let full: Rc<Box<TypeTree>> = tree!(SelfAccess, a);
855+
let full: Rc<Box<TypeTree>> = tree!(SelfInit, a);
839856
tbl.table.insert("self".to_string(), Rc::clone(&full));
840857

841858
return Ok((full, curried));
@@ -1237,6 +1254,24 @@ mod tests {
12371254
assert!(linter.issues.len() == 0);
12381255
}
12391256
#[test]
1257+
fn it_should_handle_sigs() {
1258+
const TEST_STR: &'static str = "
1259+
const val: zerror!?usize = 2
1260+
const val2: !?usize = 3
1261+
const val3: ?usize = 4
1262+
const val4: usize = 5
1263+
";
1264+
let lexer = TLexer::new(TEST_STR);
1265+
let mut parser = Parser::new(lexer);
1266+
let result = parser.all();
1267+
let mut tts = vec![];
1268+
let mut scps = vec![];
1269+
let mut linter = LintSource::new(TEST_STR, &mut scps, &mut tts);
1270+
let _ = linter.lint_check(&result.unwrap());
1271+
1272+
assert!(linter.issues.len() == 0);
1273+
}
1274+
#[test]
12401275
fn it_should_handle_global_data() {
12411276
const TEST_STR: &'static str = "const val: usize = 2
12421277
const main = fn() void { return 7 + val }

playground.ty

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ pub type Motorcycle = struct {
44
}
55

66
// Data has a type. can be manually declared with : <type>
7-
const x = 7;
8-
const y: usize = 7;
7+
const x = 7
8+
const y: usize = 7
99

1010
// Types have types
1111
// this is usually redundant
@@ -29,7 +29,7 @@ impl Car = trait(Movable) {
2929

3030
// default implementations can be achieved
3131
pub const set_wheels_default = fn(self: Movable, wheels: u8) void {
32-
self.wheels = wheels;
32+
self.wheels = wheels
3333
}
3434

3535
// default implementation

0 commit comments

Comments
 (0)