Created
July 29, 2021 21:23
-
-
Save timotheecour/5fc8f646d09cf32a85ed820723a41f72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```nim | |
type | |
InterfaceVTableAnimal = object | |
<0>say: proc (this: RootRef): string {.nimcall.} | |
<1>test2: proc (this: RootRef) {.nimcall.} | |
type | |
Animal = Interface[InterfaceVTableAnimal] | |
proc initVTable(t: var InterfaceVTableAnimal; TIfaceUnpackedThis#: typedesc) = | |
mixin say | |
mixin test2 | |
t.`<0>say` = proc (this: RootRef): string = | |
var ifaceUnpackedThis#: TIfaceUnpackedThis# | |
unpackObj(this, ifaceUnpackedThis#) | |
forceReturnValue(string, | |
checkRequiredMethod(say(ifaceUnpackedThis#), Animal)) | |
t.`<1>test2` = proc (this: RootRef) = | |
var ifaceUnpackedThis#: TIfaceUnpackedThis# | |
unpackObj(this, ifaceUnpackedThis#) | |
forceReturnValue(void, | |
checkRequiredMethod(test2(ifaceUnpackedThis#), Animal)) | |
proc say(this: Animal): string {.inline, stackTrace: off.} = | |
this.private_vTable.`<0>say`(this.private_obj) | |
proc test2(this: Animal) {.inline, stackTrace: off.} = | |
this.private_vTable.`<1>test2`(this.private_obj) | |
converter toAnimal[T: ref](a`gensym4: T): Animal {.inline.} = | |
to(a`gensym4, Animal) | |
registerInterfaceDecl(Animal): | |
proc say(): string | |
proc test2() | |
do: | |
t.`<0>say` = proc (this: RootRef): string = | |
var ifaceUnpackedThis#: TIfaceUnpackedThis# | |
unpackObj(this, ifaceUnpackedThis#) | |
forceReturnValue(string, | |
checkRequiredMethod(say(ifaceUnpackedThis#), Animal)) | |
t.`<1>test2` = proc (this: RootRef) = | |
var ifaceUnpackedThis#: TIfaceUnpackedThis# | |
unpackObj(this, ifaceUnpackedThis#) | |
forceReturnValue(void, | |
checkRequiredMethod(test2(ifaceUnpackedThis#), Animal)) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment