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

Support global = global initializers #3

Closed
lynn opened this issue Jun 9, 2023 · 1 comment
Closed

Support global = global initializers #3

lynn opened this issue Jun 9, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@lynn
Copy link
Owner

lynn commented Jun 9, 2023

These aren't supported:

int x[2] = {1, 1};
int *y = x;

// or more commonly...
char *message = "hi";

The compiler will complain unsupported label+addend.

chibicc writes

// Only the following expressions are allowed in an initializer:
//
//  1. A constant such as a number or a string literal
//  2. An address of another global variable with an optional addend
//
// It is obvious that we can embed (1) to an object file as static data.
// (2) may not be obvious why that can result in static data, but
// the linker supports an expression consisting of a label address
// plus/minus an addend, so (2) is allowed.

But uxnasm doesn't really support (2) so I stubbed it out with this unsupported label+addend error message.

Instead what you'd need to do in uxnasm is put another label on the same data…

@x
@y 
    0001
    0001

@message
@.L.data.0
    68
    69

Which hurts the single-pass-y-ness a little bit. And if we want to support the "addend" thing, something like

int x[5] = {1, 2, 3, 4, 5};
int *y = x + 2;

would have to be

@x
    0001
    0002
@y  
    0003
    0004
    0005

which is even trickier.

@hikari-no-yume
Copy link
Collaborator

hikari-no-yume commented Jun 12, 2023

Instead what you'd need to do in uxnasm is put another label on the same data…

@x
@y

Hmm I don't think that's right, the value of y isn't the same as x but rather its value is the address of x. I think we can do this with the “raw absolute addressing rune”:

@x
  =y

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants