Newbie Here! Can I have some feedback on my code?

2024-08-11 Thread dwhall256
@stoking: We independently came to very similar solutions. @Hallicon, I just did this last week; so this solution passes the unit tests. I like naming the variables in a way that explains their logic; this eliminates the need for comments. The if-expression is the procedure's final expression, w

generic type constraint to size

2024-07-20 Thread dwhall256
Does Nim have the ability to constrain a generic type to be of a certain size? For example, can I create MyObject[T] where T is any type that is 4 Bytes?

Atlas shrugged...

2024-07-08 Thread dwhall256
So, it's largely doing the same thing as git submodules, but with slightly fewer commands and more understandable naming. (I'm restating it to make sure my understanding is correct) This makes me want to suggest the following: 1. rename the `clone` command to something else (perhaps `depend`

Atlas shrugged...

2024-07-07 Thread dwhall256
Are atlas workspaces meant to be shared? That is, if I make a workspace, do I put it in my git repo for others developers to fetch so they can get all the dependencies (hopefully with one simple command)?

Upcoming "Nim for Pythonistas" talk at PyCon Italy

2024-07-03 Thread dwhall256
Thank you for showing how easy nimpy/nimporter can be. I wasn't aware of it until I saw your video.

What Araq thinks about HappyX?

2024-06-13 Thread dwhall256
Instead of a meet-up; how about a community code roast. Once a month, someone (the host/author) nominates a project they want help improving. The community all pitches in on ideas to make it better; it could be a quick write-up or a thorough PR.

cannot evaluate at compile time

2024-05-06 Thread dwhall256
Here's what I think you are trying to do. Notice I replaced `osq` with the implicit variable `result`.

I Have Created a Kinda Logging Solution :)

2024-05-03 Thread dwhall256
Your code is readable to the point of needing no explanation. Well done. I believe the up-to-date idiom for importing from the standard library is to make it explicit: `import std / [os, streams, strformat, times]` I'm less certain about which is idiomatic when it comes to `try/finally` versus

Compilation Problem: "Error: cannot open C:\..\..\..\lib\system.nim"

2024-04-27 Thread dwhall256
Does this seem related?

Resources for Learning Nim

2024-04-24 Thread dwhall256
How would you like to receive suggestions? PR on the repo link you provided? Message on this thread?

Fake Nim books an Amazon, which ones are real?

2024-04-22 Thread dwhall256
Next up: an AI generated video of Andreas extolling the virtues of a GIL.

Dear Araq, how do I create a programming language?

2024-04-18 Thread dwhall256
I recommend you not make your dream language as your first project. Instead, create a small and simple language as your first step. Perhaps a FORTH derivative. Learn from that. See where that learning takes you. Do you want to make a general purpose language? or one to formalize legal contracts?

Best way to pass many parameters to a function

2024-04-08 Thread dwhall256
In general, procedures with many arguments are awkward. Bob Martin's book, Clean Code, explains why. But there are always exceptions. Reading through your arguments, it seems like they could be grouped into categories, and you could create a struct per category. In my projects, I often have Sta

invoking a macro from a template?

2024-04-04 Thread dwhall256
Thank you. I got this to compile locally and I suspect it will work. My test project is not building for other reasons that I'm working on. So it will be a bit before I can claim full success and push to

invoking a macro from a template?

2024-04-02 Thread dwhall256
In the previous step, you guys helped me [make the declareEnum() macro](https://forum.nim-lang.org/t/11331) that generates an enum type. Now, I need to generate a proc that uses the enum type for a parameter. My first attempt employs a template: template declareFieldEnum*( pe

a template to declare an enum

2024-04-01 Thread dwhall256
Thank you both. For my needs, I must be able to specify the enum values; so I created the sequence of `nnkEnumFieldDef` to give to `newEnum()` which involved copying leaves of the `Asgn` node. For future me: `dumpTree` is your friend. For other learners, here is what I came up with. For curren

a template to declare an enum

2024-03-31 Thread dwhall256
I'm trying to do something like this: template declareEnum*(enumName: untyped, values: untyped) = type enumName = enum values declareEnum(Foo): Alpha = 0 Bravo = 1 let val: Foo = Alpha Run and the compiler gives me an `Illform

Challenge: Weak linking on Windows

2024-03-16 Thread dwhall256
Nevermind, I see that line was removed in a later commit.

Challenge: Weak linking on Windows

2024-03-16 Thread dwhall256
Does `header.add "NIM_GENERIC"` need a space in the string like the nearby lines with `header.add` ?

A template to emit ARM asm

2024-03-13 Thread dwhall256
When I turned all the templates into inline procs, then it no longer read from the register a second time. I also read the gcc's docs about the asm statement in greater detail and fixed one register modifier and discovered how to convert Nim static args to an assembly immediate operand. With the

A template to emit ARM asm

2024-03-13 Thread dwhall256
Good suggestion, Peter. It makes sense. I tried turning `AHB1ENR` to an inline proc. It resolved the error, but the procedure was called a second time after the `asm` statement, overwriting the modification to the variable. So a tried turning more of the templates into inline procs. I got someth

A template to emit ARM asm

2024-03-13 Thread dwhall256
No luck. It had the same error message, redeclaration of the variable. Here's the whole code for context. The other templates may be affecting the outcome of the one I quoted previously in this discussion. Solving this isn't critical. I have a working implementation in Nim. I am trying for an op

A template to emit ARM asm

2024-03-10 Thread dwhall256
This ugly construction has come very close to what I want: # chained field modify template GPIOAEN*(regVal: RCC_AHB1ENR_Val, fieldVal: uint32): RCC_AHB1ENR_Val = {.emit: ["asm (\"BFI %0, %1, #0, #1\"\n\t: \"=r\" (", regVal, ")\n\t: \"r\" (", fieldVal, "));\n"].} regV

Is there a plan to make Nim a language for normal businesses?

2024-03-10 Thread dwhall256
I think the best feature of Nim is that it is an easy-to-learn, type-safe replacement for C with great interop. . . but that's because I'm coming from C and wanted an easy-to-learn, type-safe replacement for C with great interop.

A template to emit ARM asm

2024-03-09 Thread dwhall256
Okay, thanks. From that tip I gather that Nim is doing little to no asm magic and that I need to follow the C compiler's asm interop.

A template to emit ARM asm

2024-03-09 Thread dwhall256
I'm trying to create a template that emits a single line of ARM assembly with two register args and two immediate args. The asm statement's triple-quotes was causing a problem when the template expanded its arguments, so I put the asm statement in a proc and call that proc from the template. Her

Calling compiler flags in file

2024-03-09 Thread dwhall256
Using info from here: I made this program: import std/compilesettings echo querySetting(commandLine) Run compiled with "\--threads:off" and got this output: c --colors:on --noNimblePath --threads:o

ANN: minisvd2nim generates a Nim lib to access ARM CortexM device and registers

2024-02-27 Thread dwhall256
The status is pre-alpha. The README explains the why and the how. I've used it with a recent STM32 SVD file. I imagine that other mfgrs' SVD files could cause issues. I welcome feedback.

type mismatch when static uint32 is given to the slice operator

2024-02-18 Thread dwhall256
Oh, here it is. I looked at the declaration of `toMask`: func toMask*[T: SomeInteger](slice: Slice[int]): T {.inline, since: (1, 3).} Run Previously, I speed-read the `SomeInteger` and thought I was safe to use unsigned. But now I see the Slice is constrained to use si

type mismatch when static uint32 is given to the slice operator

2024-02-18 Thread dwhall256
I have this code [(playground)](https://play.nim-lang.org/#pasty=zMlQDzeCBifR) which I want to build compile-time consts. I've eliminated unrelated operations to hone in on my problem. The error is that toMask expects a Slice, but got an HSlice because the types of `foo` and `baz` differ; `foo`

How to declare a string containing an untyped?

2024-02-08 Thread dwhall256
Yes, that worked like a charm. Thank you! (that one is not easy to find in the docs if you don't know what you're looking for)

How to declare a string containing an untyped?

2024-02-08 Thread dwhall256
I'm trying to make a template that will declare a string whose contents comes from the `untyped` argument. As you can see, I'm constructing the string's identifier using the untyped argument, too; so it must remain untyped. Any ideas on how to do this? Here's the closest I can get:

`nph` opinionated formatter v0.4

2024-02-05 Thread dwhall256
You are doing great and thoughtful work here. Thank you.

Help with a template

2024-01-29 Thread dwhall256
Done.

Help with a template

2024-01-28 Thread dwhall256
I've created a template and I'm getting an error from the compiler that I can't understand how to remedy. template declareFoo(fooName: untyped, value: uint) = const `fooName Value`* = value declareFoo(FOO, 0x7000) declareFoo(BAR, 0x8000) Run

Trying multiple compilation settings in parallel

2024-01-20 Thread dwhall256
Some malware programs offer a configuration setting for a directory that is excluded from malware scanning. I clone from trusted repos into a subdir of "code" my directory that is excluded from scanning. And I clone from public/github repos into "code_other" a normal directory that is scanned.

The nim installer for Windows contains malware

2024-01-02 Thread dwhall256
I had my IT dept submit a false-positive report last year. The immediate work-around was to install nim and write my nim source in our designated virus-scan-exclusion path. P.S. What's "the Leo world" ?

ccal: Calendar with local holidays via ip location

2024-01-02 Thread dwhall256
Country code is an ISO standard. [Wikipedia has a summary](https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes). There are two sizes of country codes: two-character and three-character.

Hello `nph`, an opinionated source code formatter for Nim

2023-12-12 Thread dwhall256
Name suggestion: [Dr. Horrible](https://drhorrible.fandom.com/wiki/Dr._Horrible) (drhorrible), one of NPH's top 5 characters. The tool doctors horrible formatting.

Object variant - returning different types

2023-12-05 Thread dwhall256
If you turn your variant variable into a const, you could get close to what you want using a template for the math operator. But this is probably not what you really want.: type MyVariant = object case kind: bool of true: intValue: int of fals

nim not finding cross-compiler in PATH on Win10

2023-11-29 Thread dwhall256
Solved! In the previous step, I learned that the **cross-compile arguments MUST be on the command line** , they cannot be in `nim.cfg`. Combine this with the following. The next clue in this puzzle was to try the arm_sandbox project on another Windows10 machine . . . and it worked. I narrowed

nim not finding cross-compiler in PATH on Win10

2023-11-28 Thread dwhall256
I've found a clue to this puzzle, but still can't find a solution. When I compile with my cross-compile arguments on the command line, I get a different result than if I compile with the cross-compiler .exe as the only command line argument and the remaining cross-compile args in the `nim.cfg`.

nim not finding cross-compiler in PATH on Win10

2023-11-15 Thread dwhall256
A solid guess, but that doesn't seem to be it. After copying the toolchain to a path without spaces and adding that to `PATH`: D:\code\nim\arm_sandbox> nim c --arm.standalone.gcc.exe=arm-none-eabi-gcc.exe .\src\before.nim Hint: used config file 'D:\code\nim-1.6.10\config\nim.cfg

nim not finding cross-compiler in PATH on Win10

2023-11-15 Thread dwhall256
Oh, wait. I only set `PATH` local to that command shell . . . I don't know if `mingw` will use the shell's `PATH` or the system `PATH`. Let me retry.

nim not finding cross-compiler in PATH on Win10

2023-11-15 Thread dwhall256
I have a [project](https://github.com/dwhall/arm_sandbox) that builds a very simple program via cross-compiling using the arm-none-eabi-gcc toolchain. Most cross-compile options given to nim are in the project's `nim.cfg` only the gcc binary is given on the command line. On a MacOS host, `nim` f

proc/func/method: syntax

2023-11-15 Thread dwhall256
I've been writing Python since 1998 and I had no trouble adapting to Nim's overall syntax in a matter of weeks, not just its syntax around return types. I much prefer `:` (two keystrokes, one key for each hand) to `->` (three keystrokes, two on the same hand and both requiring moving the hand aw

Array of type "proc" except I don't know what I'm doing

2023-11-04 Thread dwhall256
Came by to say I loved the title of the post. I'm learning nim, too.

What's stopping Nim from going mainstream? (And how to fix it?)

2023-11-02 Thread dwhall256
Disagree with the IDE comment. Most people use the editor/IDE of their choice. I'm not going to switch editor/IDE just for a new-to-me language. Any killer feature one editor/IDE has is usually replicated to other editor/IDEs in a matter of months. I would enjoy seeing a debugger because I work

How to get rid of "_ZL10nimZeroMemPvl" in an embedded target?

2023-10-30 Thread dwhall256
Thank you, @choltreppe. I got a chuckle (at my own expense) for trying to create "distinct generics". Once I realized the contradiction there and realized that creating subtypes of `Register[uint32, uint32]` would satisfy the type safety I'm seeking, the solution naturally fell out:

How to get rid of "_ZL10nimZeroMemPvl" in an embedded target?

2023-10-29 Thread dwhall256
Ignoring compiled ARM code size for the moment, here's a behavior from the nim compiler I don't understand: this gives an error: . Then remove the `#` on line 4 to see it build without error.

How to get rid of "_ZL10nimZeroMemPvl" in an embedded target?

2023-10-29 Thread dwhall256
Disregard. I replaced the calls to `write()` with direct calls to `volatileStore()` and the problem goes away. So I've located the problem and can likely solve it from here.

How to get rid of "_ZL10nimZeroMemPvl" in an embedded target?

2023-10-29 Thread dwhall256
Thank you @Araq, but I don't know where to apply it. Both arguments to `write()` are constants. I applied `{.noinit.}` to `main()` to no effect. The first argument to `_ZL10nimZeroMemPvl()` is an address four bytes after the `SP` (a ptr to a local variable?), but I don't believe I've declared a

How to get rid of "_ZL10nimZeroMemPvl" in an embedded target?

2023-10-28 Thread dwhall256
I wrote a small LED blink for a STM32 microcontroller a while back # code trimmed to the most relevant lines proc write*(reg: static GPIOA_BSRR_Type, val: GPIOA_BSRR_Fields) {.inline.} = volatileStore(cast[ptr GPIOA_BSRR_Fields](reg.loc), val) proc main() =

custom numeric literal

2023-10-20 Thread dwhall256
I love how nim lets me get away with so much at compile time. Today, I made a distinct datatype with a [custom numeric literal](https://nim-lang.org/docs/manual.html#numeric-literals-custom-numeric-literals). type Semicircle16* = distinct int16 proc `'sc16` *(s: string): Semicir

Why is building the community and ecosystem such a struggle?

2023-10-11 Thread dwhall256
Evan Czaplicki, the creator of the language elm, recently shared [his thoughts](https://www.youtube.com/watch?v=XZ3w_jec1v8) on this very topic

Quantum Leaps framework implementation /Miro Samek/

2023-07-14 Thread dwhall256
I worked at a place that used QP/C to make an impressive hard-real-time embedded system. The shoebox-sized device had three distinct boards, each serving a separate function and having a dissimilar processor: ATmega, ARM7TDMI and a TI DSP. Each board had serial connections to the other two board

regex find all w/captures

2023-06-23 Thread dwhall256
I'm hoping there is something more elegant than a simple generic: iterator genRegexCaptures[T](s: string, pattern: Regex): string = var captured: T ... Run yuck: for addr_str in genRegexCaptures[array[1, string]](file_contents, re" address='0x

regex find all w/captures

2023-06-23 Thread dwhall256
I'm trying to implement in Nim, the following line of Python `addr_strs = re.findall(" address='0x([0-9a-f]{8})' ", file_contents)` The `re.findAll()` in Nim doesn't seem to handle captures, so I am filling in this missing piece. I have code that works, but it has a bit of hard-coded badness:

nim merch

2023-06-22 Thread dwhall256
> Just buy my book. ;-) Already did. But your book sits on my shelf at home and doesn't make fellow software engineers wonder, "What is nim?" like a magnet or sticker would when they wander past my office.

nim merch

2023-06-21 Thread dwhall256
Is there a store that sells nim merchandise (stickers, t-shirts, etc.) for the benefit of the development team? I see redbubble, but that doesn't look like it benefits core developers.

A good word for idiomatic nim?

2023-06-21 Thread dwhall256
econimic: it's both idiomatic and efficient.

Embedded: svd2nim for read/write of ARM Cortex micros

2023-06-17 Thread dwhall256
**Progress!** I focused on the multi-line `modifyIt` proc and found that the `svd2nim` code generator passes a **variable** value to some `bitops`. I rewrote a proc by hand using **constant** values and the resulting assembly was much more compact. [Here's the writeup](https://github.com/dwhall

Embedded: svd2nim for read/write of ARM Cortex micros

2023-06-16 Thread dwhall256
> Are you compiling with -d:danger --opt:size? I tried them and did not see much difference, though I have not tried all Items from the analysis. My `nim.cfg` has `checks:off` which I find more calming than `d:danger`. I will leave `opt:size` in my nim.cfg. The case I want to fix first is Item

Embedded: svd2nim for read/write of ARM Cortex micros

2023-06-16 Thread dwhall256
I am not using those options. I will give them a try after this. I just created a repo, [nucleo_blink](https://github.com/dwhall/nucleo_blink), that might help you recreate my work. It's a VSCode project that will recommend the PlatformIO extension. Then there's also a `platformio.ini` file that

Embedded: svd2nim for read/write of ARM Cortex micros

2023-06-16 Thread dwhall256
I just added Item 5 to [the analysis](https://github.com/dwhall/nimbed/wiki/svd2nim-analysis) which shows that `modifyIt()` with more than one operation in its body results in bloated code and needs work.

Embedded: svd2nim for read/write of ARM Cortex micros

2023-06-16 Thread dwhall256
Special thanks to these projects, `nim-platformio` and `svd2nim`, I've been able to get an LED to blink on a ST Nucleo F446RE board ([details](https://github.com/dwhall/nimbed/wiki)). I've had a brief chat with @auxym regarding `svd2nim` since he's the most recent developer for `svd2nim`. But I

Reliably locating nimbase.h

2023-06-06 Thread dwhall256
I'm trying to make some improvements to [nim-platformio](https://github.com/markspanbroek/nim-platformio), a tool that makes it easy to cross-compile nim to microcontrollers. One of the needs is to have `nimbase.h` in the project's include path. The current solution keeps a copy of nimbase.h in

Why does this operator overload fail?

2023-05-30 Thread dwhall256
I am creating two data types that represent fractions of a circle (a.k.a. angles) as 16- or 32-bit fixed point integers. I have overloaded the equality operator `'=='*` for these datatypes. My first attempt at the operator overload fails to compile and I'd like to understand why the converter ro

Good Languages Borrow, Great Languages Nim

2023-05-05 Thread dwhall256
I think it will take me a few years before I develop enough familiarity with the language to develop an embeded project worthy of the name [nimbed](https://www.merriam-webster.com/dictionary/nimbed)

help cleaning up a complex type

2023-05-01 Thread dwhall256
@ElegantBeef to the rescue, once again, thank you. My incorrect assumption of a generic procedure was that the type `T` had to be used in the procedure's signature (i.e. somewhere between `proc` and the first `=`); it is good to have that corrected. One of my failed attempts to solve this was t

help cleaning up a complex type

2023-04-30 Thread dwhall256
I'm trying to create a type to represent a microcontroller register where the address of the register is part of the type. This is the closest I can get to what I want that will compile: type RegisterType* = uint8 | uint16 | uint32 RegisterPtr* = ptr RegisterType

.o files going missing before linking?

2023-03-16 Thread dwhall256
What is the nature of your R: drive? If R: is not local to your machine, can you recreate this issue when building on a local filesystem?

Can Nim do Type States?

2023-03-15 Thread dwhall256
> How do y'all handle failures, like say integer overflow or a sensor returning > erroneous date, or plain old bit flips? Integer overflow is a feature, not a failure . Floating point exceptions, now _those_ keep us up at night. Some groups prefer software floating point libraries over hardware

Can Nim do Type States?

2023-03-15 Thread dwhall256
> The DO-178 standard was mainly defined for the C language and I don't think > it is strictly applicable for other languages ​​like Nim. C, Ada and C++ are the three most prevalent languages used in aviation and the DO-178 standard is applied to those and any other who is willing to qualify the

Can Nim do Type States?

2023-03-15 Thread dwhall256
> malloc is very different from "meta programming" though, malloc is all about > runtime flexibility (allocation of unknown sizes with unknown lifetimes), > meta programming is about raising the level of abstraction so that programs > become shorter. Understood. I jumped ahead in my thoughts an

Can Nim do Type States?

2023-03-10 Thread dwhall256
> | My line of work prohibits metaprogramming > > What does this mean? I work in embedded, too, not like, misra-level or > anything but I've never come across any restrictions limiting the level of > abstraction. Wouldn't mplab/harmony/all those code configurators from > microchip count as meta

Can Nim do Type States?

2023-03-09 Thread dwhall256
Thank you for more great feedback. I see you've used options to reduce the number of hand-made type states. Compelling idea. I also see your use of bool and enum in the types; is that still zero-cost (no additional size for the object)? Also, I'm a little perplexed about the last three lines in

Can Nim do Type States?

2023-03-09 Thread dwhall256
Thank you for Nim and thank you for this tip; it helped improve my understanding of generics. My line of work prohibits metaprogramming. So I'm not headed in that direction, but I take your point. For now, I want to see if this style of Type States will cause any unwanted side effects (like code

Can Nim do Type States?

2023-03-09 Thread dwhall256
I'm an embedded developer 2 weeks into learning nim and I'm trying to see if Nim's type system can approach the "Type States" described in in [Chap 4 of The Embedded Rust Book](https://docs.rust-embedded.org/book/static-guarantees/index.html) (esp [section 4.4](https://docs.rust-embedded.org/b