udem-dlteam / pnut

🥜 A Self-Compiling C Transpiler Targeting Human-Readable POSIX Shell
https://pnut.sh
BSD 2-Clause "Simplified" License
425 stars 14 forks source link

Support byte strings and pointer arithmetic #11

Closed laurenthuberdeau closed 6 months ago

laurenthuberdeau commented 6 months ago

Context

The lack of byte strings is limiting and complicates the implementation of the fopen primitives (See https://github.com/udem-dlteam/pnut/pull/10). This PR adds support for pointer arithmetic (except subtraction between pointers), and coincidentally support for byte strings. This also unblocks support for structs, which will be implemented soon.

~There are still a few bugs, the main (🥁) one being that accesses to argv segfault. Also, the bootstrap on pnut.sh fails, but the bootstrap on gcc succeeds. To be investigated.~

monnier commented 6 months ago

The lack of byte strings is limiting and complicates the implementation of the fopen primitives (See https://github.com/udem-dlteam/pnut/pull/10). This PR adds support for pointer arithmetic (except subtraction between pointers), and coincidentally support for byte strings. This also unblocks support for structs, which will be implemented soon.

[ Pour les besoins de l'article (de même que pour le cas où on décide de révisiter certaines décisions), il est important de garder trace des raisons qui ont motivé les différents choix et des inter-dépendances entre les choix. Je te recommande d'avoir un fichier où tu notes tout ça (y compris les choix rejetés, et pourquoi). ]

IIUC le problème était pour les backend non-sh. Quand le target est sh, le word_size est toujours 1, non?

    Stefan
laurenthuberdeau commented 6 months ago

IIUC le problème était pour les backend non-sh. Quand le target est sh, le word_size est toujours 1, non?

While it's true that the changes were motivated by the work on the x86 backend primitives, if we end up adding support for structs to the Shell backend, we may have objects that occupy more than 1 word. But you're right that this PR only affects the exe backend.