New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[codegen] conversion from FREE_IMAGE_FORMAT to itself is pointless #72
Comments
We talked about this on IRC, make nimterop emit |
why not detect and avoid emitting the converter instead? |
That was deemed too complicated for something that could be easily silenced with a pragma, but maybe it's easier now? |
well let's leave this open as a low priority thing |
The converter has actually been a little problematic for me. ImageMagick uses a MagickBoolean enum for bools (MagickTrue/False), so I made a converter to turn it into |
i always wondered! @genotrance ? |
Nimterop originally generated enums but that doesn't always work for wrapped C enums since they can often be out of order in value. Nim doesn't like that and compile fails. Instead we simply generate const values. But now, you also need a type since that enum type can be used as params and return values. So you need a converter from the const to int. Tracking will be tedious since every enum will need to be checked if it is the same type as the one it will be converted from. Easier to just suppress the message. |
So, an enum consists of a |
type
enumtype = distinct int
const
enumval = 5
proc enumproc(val: enumtype) =
echo val.int
enumproc(enumval)
You get an error cause Nim won't explicitly convert |
Related conversation. |
like @zestyr , I really don’t like the proposal
(similar to but really, i think the best is to use |
We cannot delegate everything to the user, it will make the tool hard to use. Already people are struggling with the interface. We also need this working upfront without which I prefer @zestyr's solution to create a generic template in types. I don't mind types.nim growing because it will be compiled out by Nim if portions are unused. |
I've created a branch implementing enums as discussed here. Please review and provide your feedback. https://github.com/genotrance/nimterop/compare/enumnoncon?expand=1 |
Looks good, but the pattern can be simplified: template genOp*(op, typ, output) =
proc op*(x: typ, y: int): output {.borrow.}
proc op*(x: int, y: typ): output {.borrow.}
proc op*(x, y: typ): output {.borrow.}
template defineEnum*(typ: untyped) =
type
typ* = distinct int
genOp(`+`, typ, typ)
genOp(`-`, typ, typ)
genOp(`*`, typ, typ)
genOp(`<`, typ, bool)
genOp(`<=`, typ, bool)
genOp(`==`, typ, bool)
#genOp(`shl`, typ, typ)
#genOp(`shr`, typ, typ)
genOp(`div`, typ, typ)
genOp(`mod`, typ, typ)
proc `$`*(x: typ): string {.borrow.} I've commented out shl/shr because they trigger this error: enum.nim(19, 8) Error: type mismatch: got <proc [*missing parameters*](x: T: SomeUnsignedInt, y: SomeInteger): T: SomeUnsignedInt{.noSideEffect.}
| proc [*missing parameters*](x: int8, y: SomeInteger): int8{.noSideEffect.}
| proc [*missing parameters*](x: int32, y: SomeInteger): int32{.noSideEffect.}
| proc [*missing parameters*](x: int64, y: SomeInteger): int64{.noSideEffect.}
| proc [*missing parameters*](x: int16, y: SomeInteger): int16{.noSideEffect.}
| proc [*missing parameters*](x: int, y: SomeInteger): int{.noSideEffect.},
type footype, type footype>
but expected one of:
template genOp(op, typ, output): untyped
first type mismatch at position: 1
required type: untyped
but expression 'shl' is of type: None
expression: genOp(shl, footype, footype) |
Pushed an update. |
same input example as #71
Hint: conversion from FREE_IMAGE_FORMAT to itself is pointless [ConvFromXtoItselfNotNeeded]
comes from this:
The text was updated successfully, but these errors were encountered: