Simpler implementation
This commit is contained in:
parent
13981e1997
commit
424a4c831e
1 changed files with 13 additions and 31 deletions
|
|
@ -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.}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue