Camto / calc

calc= is a small concatenative programming language for doing math in chats.
https://camto.github.io/calc
MIT License
13 stars 1 forks source link

Suggestion: possible room for use of Nim here for backend? #2

Closed unquietwiki closed 4 years ago

unquietwiki commented 4 years ago

I run r/altprog on Reddit, and saw this posted there. I see this is being done with a mix of JS and C, with some fits & starts. I was made aware the other day of https://nim-lang.org/ ; which has tie-ins and outputs to both. It might be useful here?

Camto commented 4 years ago

Actually the JS and the C halves are disconnected, the JS implementation is the old one, and I'm completely rewriting it in C because the goal was to make it as embeddable as possible. JS was chosen initially because I knew it well so it could at least be embedded in the website and in chat bots, but I prefer a C rewrite so I can embed it in other languages.

Edit; If Nim can compile to old c89 then maybe.

unquietwiki commented 4 years ago

@Camto Thanks for clarifying. https://nim-lang.org/docs/nimc.html#cross-compilation might resolve that.

Related to what you're attempting, https://github.com/marcobambini/gravity might be relevant.

Camto commented 4 years ago

calc= isn't meant to be compiled on its own, the core in fact hos no IO whatsoever. It's meant to be used like Lua, as a library. The idea is for any language to be able to run calc= via its own C FFI. If Nim can produce stuff Python and JS can easily hook into, that could be neat. I'm an absolute noob when it comes to FFIs, never done it before, so I have no clue.

ghost commented 4 years ago

@Camto well for Nim - Python there's https://github.com/yglukhov/nimpy

alxklk commented 4 years ago

Edit; If Nim can compile to old c89 then maybe.

Nim compiles to C code, but this code looks like a messy unreadable garbage.

ghost commented 4 years ago

Edit; If Nim can compile to old c89 then maybe.

Nim compiles to C code, but this code looks like a messy unreadable garbage.

well, I'm not sure what's the original reason for using Nim in this issue, but "unreadable garbage" isn't a reason to NOT use Nim - that C isn't supposed to be read by humans anyway, it's there for the C compiler. For Nim C is just a backend just like an LLVM IR might be (there's an unofficial backend for it - https://github.com/arnetheduck/nlvm) EDIT: Although I don't really know if Nim's C output is C89 compatible, sorry

Camto commented 4 years ago

For the current interpreter rewrite (same version of calc=), I'm just gonna stick with what I'm using. When I move on to calc= v2, then I'll start looking at other low level alternatives.