Nim (programming language) on the Atari

GFA, ASM, STOS, ...

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

czietz
Hardware Guru
Hardware Guru
Posts: 2080
Joined: Tue May 24, 2016 6:47 pm

Re: Nim (programming language) on the Atari

Post by czietz »

ThorstenOtto wrote: Thu Jan 07, 2021 4:22 pm Same thing in perl:
Does that Perl script compile into a single executable? How big is it, including all the required Perl modules?
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: Nim (programming language) on the Atari

Post by ThorstenOtto »

mikro wrote: Thu Jan 07, 2021 4:40 pm @ThorstenOtto but compare the installation effort and runtime requirements. As I understand it, Nim's .prg is in tens of kilobytes and doesn't need anything else, i.e. running on plain ST + networking stack.
I don't have any effort. Perl is already installed.

And compare that to the effort of learning a new language, instead of using Perl (or python, if someone prefers), which are already widely in use.
czietz wrote: Does that Perl script compile into a single executable?
I don't have all modules natively installed, to directly run it on atari. But i can compile it to C-code, and cross-compile the resulting source.

That does not mean that i want to say that the language is useless. But there are already existing ways to achieve the same results.
User avatar
christos
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2528
Joined: Tue Apr 13, 2004 8:24 pm
Location: Greece

Re: Nim (programming language) on the Atari

Post by christos »

Interesting language. There's something weird in the syntax. How do you close loops?

And how would you access an HTTPS service on the Atari?

I think i must read about it more..

Edit: read the tutorial. Basically loops and if statements are terminated with indentation. I am not sure how i feel about that choice...
czietz
Hardware Guru
Hardware Guru
Posts: 2080
Joined: Tue May 24, 2016 6:47 pm

Re: Nim (programming language) on the Atari

Post by czietz »

christos wrote: Fri Jan 08, 2021 9:54 pm And how would you access an HTTPS service on the Atari?
If compiled with -d:ssl -d:openssl10, Nim's HTTP client get HTTPS support. Then, it just:

let jsondata = client.getContent("https://api.weatherbit.io/v2.0/forecast/daily?key=YOU_WISH_YOU_KNEW&days=4&city=" & Location)

Fortunately, OpenSSL is available for MiNT and with the -dynlibOverrideAll you can tell the Nim compiler to statically link against the required libraries. I tested it, HTTPS works on my TT.

However, this is where the age of our computers starts to show. When used with the default SSL/TLS ciphers, many servers will timeout before the client/Atari has even finished doing the required crypto computations. In contrast, when you select older (and less computationally intense) ciphers, many server will reject the connection because they find the encryption too weak. Thus, it requires carefully tuning the ciphers list.

To make it very clear: this is not a Nim issue! Every application using the OpenSSL library (even if that application was written in C, assembler, Perl, ...) would face the same problem.
User avatar
christos
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2528
Joined: Tue Apr 13, 2004 8:24 pm
Location: Greece

Re: Nim (programming language) on the Atari

Post by christos »

czietz wrote: Sat Jan 09, 2021 2:11 pm
christos wrote: Fri Jan 08, 2021 9:54 pm And how would you access an HTTPS service on the Atari?
If compiled with -d:ssl -d:openssl10, Nim's HTTP client get HTTPS support. Then, it just:

let jsondata = client.getContent("https://api.weatherbit.io/v2.0/forecast/daily?key=YOU_WISH_YOU_KNEW&days=4&city=" & Location)

Fortunately, OpenSSL is available for MiNT and with the -dynlibOverrideAll you can tell the Nim compiler to statically link against the required libraries. I tested it, HTTPS works on my TT.

However, this is where the age of our computers starts to show. When used with the default SSL/TLS ciphers, many servers will timeout before the client/Atari has even finished doing the required crypto computations. In contrast, when you select older (and less computationally intense) ciphers, many server will reject the connection because they find the encryption too weak. Thus, it requires carefully tuning the ciphers list.

To make it very clear: this is not a Nim issue! Every application using the OpenSSL library (even if that application was written in C, assembler, Perl, ...) would face the same problem.
Well, it's hard to find plain http apis nowadays. I wonder if it would be possible to use PolarSSL to be able to use it under STING also. When all you have is 4MBs, MiNT is not a good option.

As for the speed, I understand exactly what you mean.

The more I read about the language the more interesting I find it. Apparently they are targeting IOT devices and Microcontrollers so it should be a good fit for Atari. And it has some nice modern features, even objects (though they don't like them very much). I am thinking of setting up an environment today.

Thanks for your work on this. Let's see if I can get something running.
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: Nim (programming language) on the Atari

Post by ThorstenOtto »

christos wrote: Sat Jan 09, 2021 4:11 pm I wonder if it would be possible to use PolarSSL
That might be possible, but it would not change much. Its not the library (openssl) that is so slow, but the encryption algorithms. And those are standardized; unless you have some x86 CPU with AES extensions, there is not much you can do to accelerate them. Even writing them completely in assembler would gain maybe 10-20% performance, but not much more. If you want, you can compare the actual sources for the encryption in both libraries; i would bet that they are nearly identical.

And the polarssl.ldg was based on an older version of a library which is now named Mbed TLS, so it might not even support newer protocols which some sites request.
User avatar
christos
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2528
Joined: Tue Apr 13, 2004 8:24 pm
Location: Greece

Re: Nim (programming language) on the Atari

Post by christos »

czietz wrote: Mon Jan 04, 2021 2:12 pm Maybe I got someone interested in Nim, too.
So I just wrote my first line of code in Nim... basically I compiled your cookie jar program and added

Code: Select all

echo "Is this correct? (y/n)"
let answer = readLine(stdin)

if answer=="y":
    echo "yey"
else:
    echo "oh something is wrong"
Because it ended too quickly to see the output.

I find it a very strange language (but I work with PHP and some JS and use GFA on the Atari) so anything that is not C or BASIC like is strange. I think I'll look into it more.
Thanks again.

@ThorstenOtto I understand that. But openssl requires MiNT. PolarSSL no. I guess only Aranym can solve the speed issue.
User avatar
christos
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2528
Joined: Tue Apr 13, 2004 8:24 pm
Location: Greece

Re: Nim (programming language) on the Atari

Post by christos »

So the first problem.. when I try to compile your program

Code: Select all

import httpclient
var client = newHttpClient()
echo client.getContent("http://www.chzsoft.de/site/")
I get this nice error:

/snap/nim-lang/1158/lib/pure/os.nim(76, 10) Error: OS module not ported to your operating system!

(Yes I used snap to get the latest version)

The code compiles for the native system, so I guess something is missing elserwhere...
czietz
Hardware Guru
Hardware Guru
Posts: 2080
Joined: Tue May 24, 2016 6:47 pm

Re: Nim (programming language) on the Atari

Post by czietz »

christos wrote: Sun Jan 10, 2021 9:18 pm The code compiles for the native system, so I guess something is missing elserwhere...
You either have to compile do my initial patches/hacks and compile with -d:posix (as described in https://www.atari-forum.com/viewtopic.p ... 78#p410378) or preferrably you use my fork at https://github.com/czietz/Nim/commits/Atari_TOS_support and compile with --os:Atari (see https://www.atari-forum.com/viewtopic.p ... 89#p410489).
User avatar
christos
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2528
Joined: Tue Apr 13, 2004 8:24 pm
Location: Greece

Re: Nim (programming language) on the Atari

Post by christos »

czietz wrote: Sun Jan 10, 2021 9:32 pm
christos wrote: Sun Jan 10, 2021 9:18 pm The code compiles for the native system, so I guess something is missing elserwhere...
You either have to compile do my initial patches/hacks and compile with -d:posix (as described in https://www.atari-forum.com/viewtopic.p ... 78#p410378) or preferrably you use my fork at https://github.com/czietz/Nim/commits/Atari_TOS_support and compile with --os:Atari (see https://www.atari-forum.com/viewtopic.p ... 89#p410489).
OK, I feel silly now.. do you know how many times I read and reread your instructions but managed to miss everything?

Testing...
User avatar
christos
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2528
Joined: Tue Apr 13, 2004 8:24 pm
Location: Greece

Re: Nim (programming language) on the Atari

Post by christos »

So, I cloned your repository and built Nim. Compilation works with your Nim when compiling for the host OS.

When compiling for Atari I get this:

Code: Select all

Executing task: /home/user/Nim/bin/nim c --cpu:m68k --os:Atari -o:weatherapp.tos weatherapp.nim; cp weatherapp.tos ../Aranym/drive_c/ <

Hint: used config file '/home/user/Nim/config/nim.cfg' [Conf]
Hint: used config file '/home/user/Nim/config/config.nims' [Conf]
Hint: used config file '/home/user/Atari/Nim/nim.cfg' [Conf]
...............................................
/home/user/Nim/lib/pure/httpcore.nim(169, 25) Hint: passing 'headers.table[toCaseInsensitive(headers, key)]' to a sink parameter introduces an implicit copy; if possible, rearrange your program's control flow to prevent it [Performance]
/home/user/Nim/lib/pure/httpclient.nim(1074, 46) Hint: passing 'resp.status' to a sink parameter introduces an implicit copy; if possible, rearrange your program's control flow to prevent it [Performance]
CC: stdlib_assertions.nim
CC: stdlib_dollars.nim
CC: stdlib_io.nim
CC: stdlib_system.nim
In file included from /home/user/.cache/nim/weatherapp_d/stdlib_io.nim.c:9:
/home/user/Nim/lib/nimbase.h:271:35: error: static assertion failed: ""
  271 | #define NIM_STATIC_ASSERT(x, msg) _Static_assert((x), msg)
      |                                   ^~~~~~~~~~~~~~
/home/user/Nim/lib/nimbase.h:542:1: note: in expansion of macro ‘NIM_STATIC_ASSERT’
  542 | NIM_STATIC_ASSERT(sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8, "");
      | ^~~~~~~~~~~~~~~~~
In file included from /home/user/.cache/nim/weatherapp_d/stdlib_system.nim.c:9:
/home/user/Nim/lib/nimbase.h:271:35: error: static assertion failed: ""
  271 | #define NIM_STATIC_ASSERT(x, msg) _Static_assert((x), msg)
      |                                   ^~~~~~~~~~~~~~
/home/user/Nim/lib/nimbase.h:542:1: note: in expansion of macro ‘NIM_STATIC_ASSERT’
  542 | NIM_STATIC_ASSERT(sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8, "");
      | ^~~~~~~~~~~~~~~~~
In file included from /home/user/.cache/nim/weatherapp_d/stdlib_assertions.nim.c:9:
/home/user/Nim/lib/nimbase.h:271:35: error: static assertion failed: ""
  271 | #define NIM_STATIC_ASSERT(x, msg) _Static_assert((x), msg)
      |                                   ^~~~~~~~~~~~~~
/home/user/Nim/lib/nimbase.h:542:1: note: in expansion of macro ‘NIM_STATIC_ASSERT’
  542 | NIM_STATIC_ASSERT(sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8, "");
      | ^~~~~~~~~~~~~~~~~
In file included from /home/user/.cache/nim/weatherapp_d/stdlib_dollars.nim.c:9:
/home/user/Nim/lib/nimbase.h:271:35: error: static assertion failed: ""
  271 | #define NIM_STATIC_ASSERT(x, msg) _Static_assert((x), msg)
      |                                   ^~~~~~~~~~~~~~
/home/user/Nim/lib/nimbase.h:542:1: note: in expansion of macro ‘NIM_STATIC_ASSERT’
  542 | NIM_STATIC_ASSERT(sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8, "");
      | ^~~~~~~~~~~~~~~~~
Error: execution of an external compiler program 'gcc -c  -w -fmax-errors=3   -I/home/user/Nim/lib -I/home/user/Atari/Nim -o /home/user/.cache/nim/weatherapp_d/stdlib_assertions.nim.c.o /home/user/.cache/nim/weatherapp_d/stdlib_assertions.nim.c' failed with exit code: 1


Terminal will be reused by tasks, press any key to close it.
User avatar
mfro
Atari God
Atari God
Posts: 1167
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: Nim (programming language) on the Atari

Post by mfro »

this is when you checkout the master branch instead of the "Atari_TOS_support" branch like you are supposed to.

Guess how I know ;)
User avatar
christos
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2528
Joined: Tue Apr 13, 2004 8:24 pm
Location: Greece

Re: Nim (programming language) on the Atari

Post by christos »

Got it... Thanks mfro
User avatar
mfro
Atari God
Atari God
Posts: 1167
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: Nim (programming language) on the Atari

Post by mfro »

Hint (I'm talking Nim'ish already, obviously): if you want to compile ColdFire native code, you just have to add the following to your nim command line:

Code: Select all

-t:mcpu=547x -l:-mcpu=547x
User avatar
mfro
Atari God
Atari God
Posts: 1167
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: Nim (programming language) on the Atari

Post by mfro »

... Nim can do GEM as well:
snap005.png

Code: Select all

proc appl_init():int16 {.header: "<gem.h>".}
proc appl_exit():int16 {.header: "<gem.h>".}
proc form_alert(button : int16, str : cstring):int16 {.header: "<gem.h>".}

let ap_id = appl_init()
let but = form_alert(1, "[1][Hello from Nim][OK]")
discard appl_exit()

Code: Select all

nim --cpu:m68k -t:-mcpu=547x -l:-mcpu=547x -l:-lgem --os:Atari -o:gem.prg c gem.nim
(for ColdFire)
You do not have the required permissions to view the files attached to this post.
czietz
Hardware Guru
Hardware Guru
Posts: 2080
Joined: Tue May 24, 2016 6:47 pm

Re: Nim (programming language) on the Atari

Post by czietz »

mfro wrote: Mon Jan 11, 2021 7:20 am ... Nim can do GEM as well:
Cool!

BTW: I've made it easier to use libcmini (instead of the default MiNTLib). When using my fork/branch, just compile with "-d:libcmini". Note that (like everything here) libcmini support is work in progress, i.e., things might fail compiling. For some programs this is expected (e.g., no sockets/network support in libcmini); for others, the Nim library might have to be adapted.

EDIT: I forgot: You have to define the LIBCMINI environment variable, too, e.g.:

Code: Select all

export LIBCMINI=/home/czietz/libcmini-experimental/
.
Last edited by czietz on Mon Jan 11, 2021 10:31 am, edited 1 time in total.
User avatar
mfro
Atari God
Atari God
Posts: 1167
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: Nim (programming language) on the Atari

Post by mfro »

czietz wrote: Mon Jan 11, 2021 7:33 am BTW: I've made it easier to use libcmini (instead of the default MiNTLib). When using my fork/branch, just compile with "-d:libcmini".
I've seen that already, thanks. It needs a little tweaking when compiling for ColdFire (or other m68k incarnations), however.

Not Nim's fault, caused by gcc's somehow broken multilib feature that only picks the correct architecture library subdir if the library is located within the syslib path (which isn't the case usually for libcmini). The same applies to other sub-architectures (like -mcpu=68020, for example).
Last edited by mfro on Mon Jan 11, 2021 8:04 am, edited 1 time in total.
User avatar
mfro
Atari God
Atari God
Posts: 1167
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: Nim (programming language) on the Atari

Post by mfro »

czietz wrote: Mon Jan 11, 2021 7:33 am... just compile with "-d:libcmini". Note that (like everything here) libcmini support is work in progress, i.e., things might fail compiling. For some programs this is expected (e.g., no sockets/network support in libcmini) ...
wouldn't that require STING support (for plain TOS) anyway?

If you need something specific (and if it's not too involved, it's supposed to stay as "mini" as possible) in libcmini, let me know. Maybe there is a chance that it gets implemented.
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: Nim (programming language) on the Atari

Post by ThorstenOtto »

mfro wrote: Mon Jan 11, 2021 8:02 am wouldn't that require STING support (for plain TOS) anyway?

I don't think that any program using the C-libraries send()/recv() functions will expect them to support STING stacks on plain TOS. The only way for this is running mint with gluestik. Handling that in the library might be possible, but will add considerable amount of code.
User avatar
mfro
Atari God
Atari God
Posts: 1167
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: Nim (programming language) on the Atari

Post by mfro »

ThorstenOtto wrote: Mon Jan 11, 2021 10:50 am
mfro wrote: Mon Jan 11, 2021 8:02 am wouldn't that require STING support (for plain TOS) anyway?

I don't think that any program using the C-libraries send()/recv() functions will expect them to support STING stacks on plain TOS. The only way for this is running mint with gluestik. Handling that in the library might be possible, but will add considerable amount of code.
That's what I think on second thought as well. Probably best to implement the network calls in a separate library (that could then safely assume MiNT is available) and *not* in libcmini.a because of this (libminisocket.a ?).
User avatar
mfro
Atari God
Atari God
Posts: 1167
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: Nim (programming language) on the Atari

Post by mfro »

On third thought ;) - is such library required at all? If users use current MiNT (that implements "native" sockets) - which is advisable anyway - there's Fsocket(), Fbind(), Fsendto(), ... implemented in the kernel. That should make it possible to implement a very thin (maybe even preprocessor-based only) socket library?
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2367
Joined: Sun Aug 03, 2014 5:54 pm

Re: Nim (programming language) on the Atari

Post by ThorstenOtto »

If they use mint, then yes. But on plain TOS, you would need something that directs those calls to the STING stack. Either in the library, or through some resident program.

Edit: forget about my comments about Gluestik. It does the opposite, ie. maps STING calls to MintNet functions.
marcelschoen
Atari maniac
Atari maniac
Posts: 79
Joined: Sat Apr 26, 2008 7:17 am

Re: Nim (programming language) on the Atari

Post by marcelschoen »

czietz wrote: Mon Jan 04, 2021 2:12 pmWhat made it interesting to me was that it can use a C compiler as backend and -- with the proper configuration -- C code generated by the Nim compiler only depends on the standard C library. Also, it allows easy interfacing with C functions, e.g., to call operating system functions.
Interesting. Maybe it could be combined with the "Atari Game Tool" kit that is currently being built; it's C-based AFAIK. The AGT is in a somewhat incoherent state right now, but is being worked on, and it is basically a 2D game engine with many powerful functions for stuff like sprites, scrolling etc. Maybe with Nim the game logic could be written a bit simplified...
Post Reply

Return to “Coding”