zilch-lang / nstar

The compiler for N⋆, a statically typed assembly language used as a compiler backend for Zilch
BSD 3-Clause "New" or "Revised" License
29 stars 2 forks source link

Introduce strings as syntactic sugar #44

Closed Mesabloo closed 3 years ago

Mesabloo commented 3 years ago

For the first version of N*, this will not be needed because strings are basically useless in it. However, in the second version, we might want to introduce strings as an easier way of writing arrays of characters. For example, going from [ 'h' 'e' 'l' 'l' 'o' ',' ' ' 'w' 'o' 'r' 'l' 'd' '!' '\0' ] (which is the current way of doing it) to "hello, world!\0" (or even without the trailing null character) is a huge code writing improvement, both in the time needed to write and in the time needed to understand what the string means when written in an array form. We will need to adapt the specification to introduce this change, and will need to decide whether or not the last null character is implicit or not.

Mesabloo commented 3 years ago

Implemented in 4ce3c40dcb09557dcca2fdee87bd3d1eddc697f5 as nothing more than a null-terminated array of characters ─ quickly desugared directly into the parser, see https://github.com/zilch-lang/nsc/blob/4ce3c40dcb09557dcca2fdee87bd3d1eddc697f5/lib/nsc-parser/src/Language/NStar/Syntax/Parser.hs#L336-L339