Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type LongInteger<bit[64]>: # Declare a type named "Integer" that is represented by 64 bits
- declare op Add: "+" # Create a new operator with the "+" symbol called Add
- Add style: infix, left, 2 # Add is a left-associative infix binary operator
- Add type: Integer, Integer -> closure # Declare the type of the operation "+". Takes two LongIntegers and returns a LongInteger (closure)
- 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)
- Add flags: carry # Create the carry flag
- # The following few lines are just declarations for bit combinations and flags
- Add rule: [0, 0] -> 0 # Two zeros added equal zero
- Add rule: ([0, 1] | [1, 0]) -> 1 # | can be used to alternate combinations
- Add rule: [0, 0], carry -> 1 # Two zeros added when the carry flag is true equals 1
- Add rule: ([0, 1] | [1, 0]), carry -> 0, carry
- Add rule: [1, 1], carry -> 1, carry
- 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