Created
October 23, 2020 02:43
-
-
Save nikki93/cce678c486af52f4b0e85fc8a8ba8995 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import options | |
type | |
Thingy = object | |
name: string | |
age: int | |
proc maybeMake(should: bool, name: sink string, age: int): Option[Thingy] = | |
if should: | |
result = some(Thingy(name: name, age: age)) | |
import os | |
let should = paramCount() >= 1 | |
let maybeMade = maybeMake(should, "Woah", 23) | |
if maybeMade.isSome: | |
echo("made: ", maybeMade.get()) | |
else: | |
echo("didn't make anything!") |
This file contains hidden or 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
/* These are excerpts...*/ | |
static N_INLINE(void, some__O9bbcKdkor9cIJlk9czMJJMIQoptions)(tyObject_Thingy__Gz2LnULflieca9c3QEsF4og val, tyObject_Option__BQzPjiARVLTXHzzQLjuaSw* Result) { | |
unsureAsgnRef((void**)&(*Result).val.name, NIM_NIL); | |
(*Result).val.age = 0; | |
(*Result).has = 0; | |
(*Result).has = NIM_TRUE; | |
unsureAsgnRef((void**) (&(*Result).val.name), copyString(val.name)); | |
(*Result).val.age = val.age; | |
} | |
N_LIB_PRIVATE N_NIMCALL(void, maybeMake__iCMtBODpIX49bGSCfnP6d4A)(NIM_BOOL should, NimStringDesc* name, NI age, tyObject_Option__BQzPjiARVLTXHzzQLjuaSw* Result) { | |
unsureAsgnRef((void**)&(*Result).val.name, NIM_NIL); | |
(*Result).val.age = 0; | |
(*Result).has = 0; | |
{ | |
tyObject_Thingy__Gz2LnULflieca9c3QEsF4og T5_; | |
if (!should) goto LA3_; | |
nimZeroMem((void*)(&T5_), sizeof(tyObject_Thingy__Gz2LnULflieca9c3QEsF4og)); | |
nimZeroMem((void*)(&T5_), sizeof(tyObject_Thingy__Gz2LnULflieca9c3QEsF4og)); | |
T5_.name = copyString(name); | |
T5_.age = age; | |
some__O9bbcKdkor9cIJlk9czMJJMIQoptions(T5_, Result); | |
} | |
LA3_: ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment