Simpler implementation

This commit is contained in:
Ganesh Viswanathan 2019-01-30 12:36:11 -06:00
commit 424a4c831e

View file

@ -32,33 +32,23 @@ elif defined(cpp):
type type
wchar_t* {.importc.} = object wchar_t* {.importc.} = object
template enumOp*(op, typ, typout) =
proc op*(x: typ, y: int): typout {.borrow.}
proc op*(x: int, y: typ): typout {.borrow.}
proc op*(x, y: typ): typout {.borrow.}
template defineEnum*(typ: untyped) = template defineEnum*(typ: untyped) =
type type
typ* = distinct int typ* = distinct int
proc `+`*(x: typ, y: int): typ {.borrow.} enumOp(`+`, typ, typ)
proc `+`*(x: int, y: typ): typ {.borrow.} enumOp(`-`, typ, typ)
proc `+`*(x, y: typ): typ {.borrow.} enumOp(`*`, typ, typ)
enumOp(`<`, typ, bool)
proc `-`*(x: typ, y: int): typ {.borrow.} enumOp(`<=`, typ, bool)
proc `-`*(x: int, y: typ): typ {.borrow.} enumOp(`==`, typ, bool)
proc `-`*(x, y: typ): typ {.borrow.} enumOp(`div`, typ, typ)
enumOp(`mod`, typ, typ)
proc `*`*(x: typ, y: int): typ {.borrow.}
proc `*`*(x: int, y: typ): typ {.borrow.}
proc `*`*(x, y: typ): typ {.borrow.}
proc `<`*(x: typ, y: int): bool {.borrow.}
proc `<`*(x: int, y: typ): bool {.borrow.}
proc `<`*(x, y: typ): bool {.borrow.}
proc `<=`*(x: typ, y: int): bool {.borrow.}
proc `<=`*(x: int, y: typ): bool {.borrow.}
proc `<=`*(x, y: typ): bool {.borrow.}
proc `==`*(x: typ, y: int): bool {.borrow.}
proc `==`*(x: int, y: typ): bool {.borrow.}
proc `==`*(x, y: typ): bool {.borrow.}
proc `shl`*(x: typ, y: int): typ {.borrow.} proc `shl`*(x: typ, y: int): typ {.borrow.}
proc `shl`*(x: int, y: typ): typ {.borrow.} proc `shl`*(x: int, y: typ): typ {.borrow.}
@ -68,12 +58,4 @@ template defineEnum*(typ: untyped) =
proc `shr`*(x: int, y: typ): typ {.borrow.} proc `shr`*(x: int, y: typ): typ {.borrow.}
proc `shr`*(x, y: typ): typ {.borrow.} proc `shr`*(x, y: typ): typ {.borrow.}
proc `div`*(x: typ, y: int): typ {.borrow.}
proc `div`*(x: int, y: typ): typ {.borrow.}
proc `div`*(x, y: typ): typ {.borrow.}
proc `mod`*(x: typ, y: int): typ {.borrow.}
proc `mod`*(x: int, y: typ): typ {.borrow.}
proc `mod`*(x, y: typ): typ {.borrow.}
proc `$` *(x: typ): string {.borrow.} proc `$` *(x: typ): string {.borrow.}