diff --git a/nimterop/types.nim b/nimterop/types.nim index cfbdf2b..15fe317 100644 --- a/nimterop/types.nim +++ b/nimterop/types.nim @@ -32,33 +32,23 @@ elif defined(cpp): type 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) = type typ* = distinct int - 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): typ {.borrow.} - proc `-`*(x: int, y: typ): typ {.borrow.} - proc `-`*(x, y: typ): typ {.borrow.} - - 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.} + enumOp(`+`, typ, typ) + enumOp(`-`, typ, typ) + enumOp(`*`, typ, typ) + enumOp(`<`, typ, bool) + enumOp(`<=`, typ, bool) + enumOp(`==`, typ, bool) + enumOp(`div`, typ, typ) + enumOp(`mod`, typ, typ) proc `shl`*(x: typ, y: int): 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, 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.} \ No newline at end of file