yeslogic / fathom

🚧 (Alpha stage software) A declarative data definition language for formally specifying binary data formats. 🚧

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Builtin operators

brendanzab opened this issue · comments

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.