Skip to content

Commit

Permalink
Type chk sem_create
Browse files Browse the repository at this point in the history
  • Loading branch information
leonidas1712 committed Apr 18, 2024
1 parent 372571d commit 9d3a01a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
6 changes: 3 additions & 3 deletions example/concurrency-04.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ fn increment(times: int) {
}
}

let tid_1 = spawn increment(l00);
let tid_2 = spawn increment(100);
let tid_3 = spawn increment(100);
let tid_1 = spawn increment(1000);
let tid_2 = spawn increment(1000);
let tid_3 = spawn increment(1000);

join tid_3;
join tid_2;
Expand Down
15 changes: 4 additions & 11 deletions src/parser/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,9 @@ pub enum Type {
Bool,
String,
UserFn(Box<FnTypeData>),
BuiltInFn, // type checking done separately since it can be polymorphic unlike user fn
ThreadId, // result of spawn
BuiltInFn, // type checking done separately since it can be polymorphic unlike user fn
ThreadId, // result of spawn
Semaphore,
Unit, // void type like Rust
Unitialised, // Type for variables that exist in a block but not yet declared - only used for TyEnv
}
Expand All @@ -443,15 +444,6 @@ impl Type {
}
}

#[test]
fn hi() {
let ty1 = dbg!(Type::Int.eq(&Type::UserFn(Box::new(FnTypeData {
params: vec![],
ret_type: Type::Bool
}))));
// dbg!(Type::Int.eq(&Type::Int));
}

impl Type {
/// Converts string to primitive type.
pub fn from_string(input: &str) -> Result<Type, ParseError> {
Expand Down Expand Up @@ -479,6 +471,7 @@ impl Display for Type {
Self::String => "string".to_string(),
Self::UserFn(fn_ty) => fn_ty.to_string(),
Self::ThreadId => "tid".to_string(),
Self::Semaphore => "sem".to_string(),
};

write!(f, "{}", string)
Expand Down
7 changes: 6 additions & 1 deletion src/types/src/check_fn_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,11 @@ impl<'prog> TypeChecker<'prog> {
}
}
}
// () -> semaphore
SEM_CREATE => {
// Fill out this block
todo!()
TypeChecker::check_arg_params_len(name, arg_types.len(), 0)?;
Type::Semaphore
}
SEM_SET => {
// Fill out this block
Expand Down Expand Up @@ -503,5 +505,8 @@ mod tests {

// Test int_to_float
expect_pass("let x : float = int_to_float(3); x", Type::Float);

// Test sem
expect_pass("let x = sem_create(); x", Type::Semaphore);
}
}

0 comments on commit 9d3a01a

Please sign in to comment.