Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] numeric escape sequences in strings #962

Closed
JL2210 opened this issue Dec 21, 2021 · 4 comments
Closed

[Feature request] numeric escape sequences in strings #962

JL2210 opened this issue Dec 21, 2021 · 4 comments

Comments

@JL2210
Copy link
Contributor

JL2210 commented Dec 21, 2021

Numeric escape sequences in strings such as e.g. \000 \xff (in particular, the former) might be useful for automatic code generators so that they don't have to output an additional zero outside of the string.

Example:

  db "Hello, World!\x00"
@Rangi42
Copy link
Contributor

Rangi42 commented Dec 21, 2021

You can do charmap "$x00", 0 and then db "Hello, World!$x00". This avoids storing arbitrary bytes in strings during rgbasm processing (so they stay as valid UTF-8 encoding), and only does the charmap-to-byte conversion when inserting bytes into the ROM.

Actually storing arbitrary bytes in strings is a matter for #938.

@aaaaaa123456789
Copy link
Member

Octal strings are impossible to add: \1, \2, and so on are macro expansions.

That being said, there's a bigger underlying problem here: the source character set doesn't match the output character set. The existence of charmap means that you cannot be sure that db "abc" will be equivalent to db $61, $62, $63 unless you control the full source of the translation unit. Automatic code generators often cannot make that assumption in the first place.

And if you control the full source of the translation unit, you can define your own escape sequences (perhaps in an included file) and just use them anywhere. Backslashes aren't available, but you can use literally any other character:

  charmap "``", $60 ; first of all, have the backtick escape itself
  charmap "`n", $0a
  charmap "`t", $09
  charmap "`x00", $00
  charmap "`x01", $01
  ; ...and so on

@Rangi42
Copy link
Contributor

Rangi42 commented Dec 21, 2021

That can even be automated:

	charmap "``", $60
	for n, 256
		charmap "`x{02x:n}", n
	endr

@ISSOtm
Copy link
Member

ISSOtm commented Dec 22, 2021

Should this be closed, then?

@Rangi42 Rangi42 closed this as completed Dec 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants