Advertisement
Hppavilion1

Bit Transformation Rules for Types

Dec 5th, 2015
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. type LongInteger<bit[64]>: # Declare a type named "Integer" that is represented by 64 bits
  2. declare op Add: "+" # Create a new operator with the "+" symbol called Add
  3. Add style: infix, left, 2 # Add is a left-associative infix binary operator
  4. Add type: Integer, Integer -> closure # Declare the type of the operation "+". Takes two LongIntegers and returns a LongInteger (closure)
  5. Add evaluation: bitwise, fromEnd, ignore # Determine the style of evaluation. In this case, it is a bitwise operator that works from the end and ignores leftover flags (overflows, in this case)
  6. Add flags: carry # Create the carry flag
  7.  
  8. # The following few lines are just declarations for bit combinations and flags
  9. Add rule: [0, 0] -> 0 # Two zeros added equal zero
  10. Add rule: ([0, 1] | [1, 0]) -> 1 # | can be used to alternate combinations
  11. Add rule: [0, 0], carry -> 1 # Two zeros added when the carry flag is true equals 1
  12. Add rule: ([0, 1] | [1, 0]), carry -> 0, carry
  13. Add rule: [1, 1], carry -> 1, carry
  14. Add rule: [1, 1] -> 0, carry # Two ones added when carry is set returns 0 with the carry flag set
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement