nim-general@lists.nim-lang.org

2024-07-16 Thread Charles
Got it, thank you.

nim-general@lists.nim-lang.org

2024-07-13 Thread Charles
I ended up refactoring the cpp to not use references but I'd still like to know if there is a way for future reference.

nim-general@lists.nim-lang.org

2024-07-13 Thread Charles
Hello again, I'm trying to wrap a c++ library, the function I want to call has the following prototype: `void UnpackGWDat( unsigned char *input, int insize, unsigned char *&output, int &outsize )` I tried the following wrapper: proc unpackWrapper(input: cstring, inputSize: cint,

NVIDIA uses Nim!

2024-04-01 Thread Charles
This is a roller-coaster of emotions.

How to use dynamic dispatch with inheritance without converting to the appropriate subtype by hand?

2024-04-01 Thread Charles
Can't believe I didn't think to do that :facepalm: The docs even had one like that but I assumed it wasn't needed for some reason. Thank you both.

How to use dynamic dispatch with inheritance without converting to the appropriate subtype by hand?

2024-04-01 Thread Charles
Hello again, I have the following situation, with a myFoo variable of type Foo that is instantiated as one of the foo subtypes: type Foo = ref object of RootObj x: string = "I'm Foo" Bar1 = ref object of Foo y: string = "I'm Bar1

Is it possible to encode constraints directly into a type, and enforce them at runtime?

2023-12-09 Thread Charles
@shirleyquick That's great, I didn't know about the `requiresInit` pragma, thanks! I looked for something like a private constructor on google but those were the wrong keywords. It's too bad about the casting, I wish there were a way to forbid it. @Arak I'm thinking of data science workflows I'

Is it possible to encode constraints directly into a type, and enforce them at runtime?

2023-12-07 Thread Charles
Most of the time I'm the unwitting adversarial user.

Is it possible to encode constraints directly into a type, and enforce them at runtime?

2023-12-07 Thread Charles
I ended up with a solution that uses strings only, with regards to the advent problem: import std/sequtils import std/strutils import std/enumerate import std/tables import std/algorithm var input: string hands, lines: seq[string] hand

Is it possible to encode constraints directly into a type, and enforce them at runtime?

2023-12-07 Thread Charles
Thank you, that's helpful! Indeed that's not as much boilerplate as I expected. I did solve today's problem already, I just didn't take advantage of the type system and got an error from it at some point that could have been avoided. I did: for line in lines("input.txt"): l

Is it possible to encode constraints directly into a type, and enforce them at runtime?

2023-12-07 Thread Charles
Hello again =)! I'm doing advent of code to improve my Nim and encountered a problem today trying to create a string type with specific constraints. I'd like to understand type constraints if they exist, not just for this problem but generally. Today's problem deals with hands of poker represe

re.findBounds doesn't return all matches

2023-12-03 Thread Charles
Oh I see that makes sense, thank you.

re.findBounds doesn't return all matches

2023-12-03 Thread Charles
That's not the same findBounds I'm talking about, sorry I should have specified, I'm talking about this one: It takes an array of strings as parameters that it says it will fill.

re.findBounds doesn't return all matches

2023-12-03 Thread Charles
Hello, I'm confused about the behaviour of findBounds from std/re. It seems to only ever return the first match in the matches parameter and leave the rest empty. Here is a minimal example: import std/re let temp = findAll("Hello World", re"(\w+)") echo temp v

Templates: How to gensym proc names, and inject variables in asm?

2023-11-21 Thread Charles
lmao that's one way to look at it.

Templates: How to gensym proc names, and inject variables in asm?

2023-11-21 Thread Charles
Thank you that's fantastic! But to be honest my first reaction after finishing writing the first macro was that I will forget what it does in 3 months and should have just written out the 32 asm procedures by hand :'D.

Templates: How to gensym proc names, and inject variables in asm?

2023-11-20 Thread Charles
Thanks for the hint, after a few hours breaking my teeth on it I got something working but it's really ugly: var interruptProcedures: array[32, uint64] macro interproc() = result = newStmtList() for iv in 0..<32: let wrapperName = if iv in erroring

Templates: How to gensym proc names, and inject variables in asm?

2023-11-19 Thread Charles
With this snippet: import macros ... macro interproc(interruptVector, name, wrapper) = quote do: proc `name`() {.exportc, asmNoStackFrame.} = asm """ pushq `interruptVector` jmp `wrapper` """ interruptProcedures[`interruptVector`

Templates: How to gensym proc names, and inject variables in asm?

2023-11-19 Thread Charles
Hello again, I'm trying to create a template that substitutes a proc in a loop, so I can create the same proc with minor variations. This is the relevant snippet: const erroringVectors = [8, 10, 11, 12, 13, 14, 17, 21, 29, 30] var interruptProcedures: array[32, uint64]

Error: expression 'x' is of type 'y' and has to be used (or discarded)

2023-11-03 Thread Charles
That's a syntax error, it doesn't tell you anything about what's returned, and ints don't implement __iadd__.

Error: expression 'x' is of type 'y' and has to be used (or discarded)

2023-11-03 Thread Charles
Oh I see, I understand better, it applies to all functions with a return value.

Error: expression 'x' is of type 'y' and has to be used (or discarded)

2023-11-03 Thread Charles
It does, although it also does the operation in place. I checked before writing it to be sure I wasn't misremembering. >From the docs: These methods are called to implement the augmented arithmetic >assignments (+=, -=, *=, @=, /=, //=, %=, **=, <<=, >>=, &=, ^=, |=). These >methods should atte

Error: expression 'x' is of type 'y' and has to be used (or discarded)

2023-11-03 Thread Charles
Oh I see, I expected all operators to return the result like they do in python. Thank you for the help, it works now!

Error: expression 'x' is of type 'y' and has to be used (or discarded)

2023-11-03 Thread Charles
Hello, I'm trying to create range types with redefined operators but encountering some issues. My program writes characters to a VGA buffer that has 80 columns and 25 lines. I figured I'd write range types for the columns and lines which I named VGACursor and VGALine respectively, and redefine

With what parameters does echo call fwrite? Trying to implement fwrite in Nim.

2023-11-02 Thread Charles
Thank you, that looks much cleaner.

With what parameters does echo call fwrite? Trying to implement fwrite in Nim.

2023-11-02 Thread Charles
Thank you for all your replies! I did increase both by one! I have no debugging facilities yet because I couldn't get gdb to run with QEMU so I figured I'd print a random character in a loop `size` times, then `nbitems` times and count them. So I did `for i in 0..size`... when I should have bee

With what parameters does echo call fwrite? Trying to implement fwrite in Nim.

2023-11-01 Thread Charles
Hello, I'm writing a kernel in Nim for fun and I'd like to be able to print things with echo. I added stubs for flockfile, funlockfile and fflush, as well as a full function for fwrite that adds characters to the framebuffer. I don't understand the parameters I'm receiving though. My fwrite pr