Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Builtin operators #257

Closed
brendanzab opened this issue Nov 5, 2020 · 0 comments · Fixed by #314
Closed

Builtin operators #257

brendanzab opened this issue Nov 5, 2020 · 0 comments · Fixed by #314

Comments

@brendanzab
Copy link
Member

brendanzab commented Nov 5, 2020

Some data formats require integer operations to be performed during parsing. It would be nice to implement some of these in Fathom!

Arithmetic operations:

  • global add_int : Int -> Int -> Int
  • global sub_int : Int -> Int -> Int
  • global mul_int : Int -> Int -> Int
  • global div_int : Int -> Int -> Int
  • global mod_int : Int -> Int -> Int
  • global neg_int : Int -> Int

Relational operations:

  • global lt_int : Int -> Int -> Bool
  • global le_int : Int -> Int -> Bool
  • global gt_int : Int -> Int -> Bool
  • global ge_int : Int -> Int -> Bool
  • global eq_int : Int -> Int -> Bool
  • global ne_int : Int -> Int -> Bool

Bitwise operations:

  • global shl_int : Int -> Int -> Int
  • global shr_int : Int -> Int -> Int
  • global and_int : Int -> Int -> Int
  • global or_int : Int -> Int -> Int
  • global xor_int : Int -> Int -> Int

Logical operations:

  • global not_bool : Bool -> Bool
  • global and_bool : Bool -> Bool -> Bool
  • global and_bool : Bool -> Bool -> Bool

Implementing some operators in the surface language might make these look a bit nicer for users!

Eventually it would be nice to give these precise types using refinement types, which would let us avoid overflows and wrapping issues in parsers (a common source of security vulnerabilities). It might be worth looking at the implementations of other languages like SPRITE, Liquid Haskell, F*, Wuffs, Dafny, ATS, etc. to get an idea for how we might want to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant