Skip to content

Conversation

leonidas1712
Copy link
Contributor

@leonidas1712 leonidas1712 commented Apr 20, 2024

  • All parameters must have type annotations
  • Type and length of arguments match function
  • Nested return statements applying to the current function must have same type as return type annotation
  • Add type annotations for higher order fn, semaphore, string
  • [ ] Polymorphic join return (might leave out)

Function is well-typed iff:

  1. all nested return stmts belonging to the function return the same type as the return type annotation, AND
  2. Somewhere in the block we encounter a terminating statement OR the last expression of the block has the same type as the return type

Similar to Go spec: https://go.dev/ref/spec#Terminating_statements

Higher order function annotations look like this:

fn apply(f: fn(int) -> int, x: int) -> int {
        f(x)
}

fn add(x: int) -> int {
      return x + 5;
}

apply(add, 9)
fn adder(x: int) -> fn(int) -> int {
      fn g(y: int) -> int {
          x + y
      }

      return g;
}

let add5 : fn(int) -> int = adder(5);
add5(10)

No time to add polymorphic join type, i.e join t only has type unit, doesn't take the type of the spawn

@leonidas1712 leonidas1712 marked this pull request as ready for review April 20, 2024 07:37
@leonidas1712 leonidas1712 requested a review from wxiaoyun April 20, 2024 07:37
let i = 0;
loop i < times {
let tmp = count;
yield;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this to make the race condition more obvious?

Copy link
Member

@wxiaoyun wxiaoyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is insane! LGTM

@leonidas1712 leonidas1712 merged commit e60ade5 into crabscript:master Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants