danlm / QNial7

The NIAL language environment
GNU General Public License v3.0
111 stars 15 forks source link

toraw/fromraw string processing error #1

Closed m-lohmann closed 4 years ago

m-lohmann commented 5 years ago

There are some issues with the string processing of toraw. I don’t exactly know what’s going on, and the error is different for both the 32-bit and 64-bit versions of Q'Nial:

Results with nial32.exe:

      toraw 'abc'
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|o|o|o|o|o|o|o|o|o|l|l|o|o|o|l|l|o|l|l|o|o|o|l|o|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

The output should be

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|o|l|l|o|o|o|o|l|o|l|l|o|o|o|l|o|o|l|l|o|o|o|l|l|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

but instead we get

      fromraw `a ooooooooollooollollooolo
+--------+--+--+
|(char 0)|`b|`c|
+--------+--+--+

Surprisingly, toraw, directly followed by fromraw, produces the expected result:

      fromraw `a (toraw 'abc')
+--+--+--+
|`a|`b|`c|
+--+--+--+

There seems to be some discrepancy between internal and external representation.

For the 64-bit version, the error looks different:

Results with nial64.exe:

     toraw 'abc'
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Which would represent:

     fromraw `a ooooooooollooollollooolo
+--------+--------+--------+
|(char 0)|(char 0)|(char 0)|
+--------+--------+--------+

However, direct conversion back and forth produces the proper result, like in the 32-bit version:

     fromraw `a (toraw 'abc')
+--+--+--+
|`a|`b|`c|
+--+--+--+
gibbonsja commented 5 years ago

Hi Manuel,

Thanks for the problem report.

It relates to the little endian nature of the intel architecture and how we pack bits for boolean arrays. Not sure why we didnt see this before.

The problem is only there for char arrays, phrases and faults.

I will fix the problem and update the repo asap.

John

gibbonsja commented 5 years ago

This bug has now been fixed. Binaries will be added asap

m-lohmann commented 5 years ago

Awesome! Thanks a lot!

gibbonsja commented 5 years ago

There are now 64 bit binaries for windows and Linux on the repository.

The Linux binary was compiled on Ubuntu 18.04

The Windows binary was cross compiled on Ubuntu with the Mingw toolchain