/* (C) 2000-2001 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
/* Change SC in case it was register */
SC = (SC & ~SC_REGISTER) | SC_AUTO;
- if (curtok == TOK_ASSIGN) {
+ if (CurTok.Tok == TOK_ASSIGN) {
- struct expent lval;
+ ExprDesc lval;
/* Allocate previously reserved local space */
AllocLocalSpace (CurrentFunc);
- /* Switch to the code segment. */
- g_usecode ();
-
/* Skip the '=' */
NextToken ();
}
/* Push the value */
- g_push (flags | TypeOf (Decl.Type), lval.e_const);
+ g_push (flags | TypeOf (Decl.Type), lval.ConstVal);
/* Mark the variable as referenced */
SC |= SC_REF;
g_usebss ();
/* Define the variable label */
- SymData = GetLabel ();
- g_defloclabel (SymData);
+ SymData = GetLocalLabel ();
+ g_defdatalabel (SymData);
/* Reserve space for the data */
g_res (Size);
/* Allow assignments */
- if (curtok == TOK_ASSIGN) {
-
- struct expent lval;
+ if (CurTok.Tok == TOK_ASSIGN) {
- /* Switch to the code segment. */
- g_usecode ();
+ ExprDesc lval;
/* Skip the '=' */
NextToken ();
- /* Get the expression into the primary */
- expression1 (&lval);
-
- /* Make type adjustments if needed */
- assignadjust (Decl.Type, &lval);
-
/* Setup the type flags for the assignment */
- flags = TypeOf (Decl.Type);
- if (Size == 1) {
- flags |= CF_FORCECHAR;
+ flags = Size == 1? CF_FORCECHAR : CF_NONE;
+
+ /* Get the expression into the primary */
+ if (evalexpr (flags, hie1, &lval) == 0) {
+ /* Constant expression. Adjust the types */
+ assignadjust (Decl.Type, &lval);
+ flags |= CF_CONST;
+ /* Load it into the primary */
+ exprhs (flags, 0, &lval);
+ } else {
+ /* Expression is not constant and in the primary */
+ assignadjust (Decl.Type, &lval);
}
/* Store the value into the variable */
- g_putstatic (flags, SymData, 0);
+ g_putstatic (flags | TypeOf (Decl.Type), SymData, 0);
/* Mark the variable as referenced */
SC |= SC_REF;
} else if ((SC & SC_STATIC) == SC_STATIC) {
/* Static data */
- if (curtok == TOK_ASSIGN) {
+ if (CurTok.Tok == TOK_ASSIGN) {
/* Initialization ahead, switch to data segment */
if (IsQualConst (Decl.Type)) {
}
/* Define the variable label */
- SymData = GetLabel ();
- g_defloclabel (SymData);
+ SymData = GetLocalLabel ();
+ g_defdatalabel (SymData);
/* Skip the '=' */
NextToken ();
g_usebss ();
/* Define the variable label */
- SymData = GetLabel ();
- g_defloclabel (SymData);
+ SymData = GetLocalLabel ();
+ g_defdatalabel (SymData);
/* Reserve space for the data */
g_res (Size);
}
/* Accept type only declarations */
- if (curtok == TOK_SEMI) {
+ if (CurTok.Tok == TOK_SEMI) {
/* Type declaration only */
CheckEmptyDecl (&Spec);
NextToken ();
ParseOneDecl (&Spec);
/* Check if there is more */
- if (curtok == TOK_COMMA) {
+ if (CurTok.Tok == TOK_COMMA) {
/* More to come */
NextToken ();
} else {
/* Be sure to allocate any reserved space for locals */
AllocLocalSpace (CurrentFunc);
- /* In case we switched away from code segment, switch back now */
- g_usecode ();
-
/* In case we've allocated local variables in this block, emit a call to
* the stack checking routine if stack checks are enabled.
*/