if (ch == EOI) eofseen = 1;
else PushBack();
- *tag++ = '\0';
+ *tag = '\0';
+ if (*(tag - 1) == '_') {
+ lexerror("last character of an identifier may not be a '_'");
+ }
tk->TOK_IDF = id = str2idf(buf, 1);
return tk->tk_symb = id->id_reserved ? id->id_reserved : IDENT;
node.o: debug.h
node.o: debugcst.h
node.o: def.h
+node.o: main.h
node.o: nocross.h
node.o: node.h
node.o: target_sizes.h
-static char Version[] = "ACK Modula-2 compiler Version 0.36";
+static char Version[] = "ACK Modula-2 compiler Version 0.37";
done_before,
NodeCrash,
ChkExLinkOrName,
- NodeCrash
};
int (*DesigChkTable[])() = {
done_before,
NodeCrash,
ChkLinkOrName,
- NodeCrash
};
}
else C_lfr(sz);
}
- DoFilename(nd);
+ DoFilename();
+ DoLineno(nd);
}
CodeParameters(param, arg)
case S_ABS:
CodePExpr(left);
if (tp->tp_fund == T_INTEGER) {
- if (tp->tp_size == int_size) C_cal("_absi");
- else C_cal("_absl");
+ if (tp->tp_size == int_size) C_cal("absi");
+ else C_cal("absl");
}
else if (tp->tp_fund == T_REAL) {
- if (tp->tp_size == float_size) C_cal("_absf");
- else C_cal("_absd");
+ if (tp->tp_size == float_size) C_cal("absf");
+ else C_cal("absd");
}
C_asp(tp->tp_size);
C_lfr(tp->tp_size);
}
case S_HALT:
- C_cal("_halt");
+ C_cal("halt");
break;
case S_INCL:
}
else C_loc((arith) (eltype->enm_ncst - 1));
Operands(nd);
- C_cal("_LtoUset"); /* library routine to fill set */
+ C_cal("LtoUset"); /* library routine to fill set */
C_asp(5 * word_size);
}
else {
register t_desig *designator = new_desig();
- ChkForFOR(nd);
+ /* ChkForFOR(nd); ??? not quite: wrong for value conformant arrays,
+ where the parameter is the for-loop control variable
+ */
CodeDesig(nd, designator);
CodeAddress(designator);
free_desig(designator);
#include "Lpars.h"
#include "warning.h"
+STATIC
+internal(c)
+ register char *c;
+{
+ if (options['x']) {
+ C_exp(c);
+ }
+ else C_inp(c);
+}
+
STATIC
DefInFront(df)
register t_def *df;
df->for_name = id->id_text;
}
else {
- sprint(buf,"_%s_%s",CurrentScope->sc_name,id->id_text);
+ sprint(buf,"%s_%s",CurrentScope->sc_name,id->id_text);
df->for_name = Salloc(buf, (unsigned) (strlen(buf)+1));
}
if (CurrVis == Defined->mod_vis) {
df = define(id, CurrentScope, type);
sprint(buf,"_%d_%s",++nmcount,id->id_text);
name = Salloc(buf, (unsigned)(strlen(buf)+1));
- if (options['x']) {
- C_exp(buf);
- }
- else C_inp(buf);
+ internal(buf);
df->df_flags |= D_DEFINED;
}
open_scope(OPENSCOPE);
extern char *sprint();
extern int proclevel;
- sprint(buf, "_%d%s", ++modulecount, id->id_text);
+ sprint(buf, "_%d%s_", ++modulecount, id->id_text);
if (!df->mod_vis) {
/* We never saw the name of this module before. Create a
/* Generate code that indicates that the initialization procedure
for this module is local.
*/
- if (options['x']) {
- C_exp(buf);
- }
- else C_inp(buf);
-
+ internal(buf);
return df;
}
register t_node *n;
extern t_node *Modules;
- n = dot2leaf(Name);
- n->nd_IDF = id;
- n->nd_symb = IDENT;
+ n = dot2leaf(Def);
+ n->nd_def = CurrentScope->sc_definedby;
if (nd_end) nd_end->nd_left = n;
else Modules = n;
nd_end = n;
break;
case USE_LOAD_STORE:
sz = WA(tp->tp_size);
- if (ds->dsg_kind != DSG_PFIXED) {
+#ifndef SQUEEZE
+ if (ds->dsg_kind != DSG_PFIXED)
+#endif
+ {
arith tmp = NewPtr();
CodeAddress(ds);
LOL(tmp, pointer_size);
FreePtr(tmp);
}
+#ifndef SQUEEZE
else {
CodeConst(-sz, (int) pointer_size);
C_ass(pointer_size);
}
+#endif
CodeAddress(ds);
CodeConst(tp->tp_size, (int) pointer_size);
- C_cal("_load");
+ C_cal("load");
C_asp(pointer_size + pointer_size);
break;
}
break;
case USE_LOAD_STORE:
CodeConst(tp->tp_size, (int) pointer_size);
- C_cal("_store");
+ C_cal("store");
CodeConst(pointer_size + pointer_size + WA(tp->tp_size),
(int) pointer_size);
C_ass(pointer_size);
CodeAddress(lhs);
C_loc(rtp->tp_size);
C_loc(tp->tp_size);
- C_cal("_StringAssign");
+ C_cal("StringAssign");
C_asp(pointer_size + pointer_size + dword_size);
break;
}
case USE_LOAD_STORE:
case USE_LOI_STI:
CodeConst(tp->tp_size, (int) pointer_size);
- C_cal("_blockmove");
+ C_cal("blockmove");
C_asp(3 * pointer_size);
break;
}
those of an enclosing procedure, or it is global.
*/
register t_scope *sc = df->df_scope;
+ int difflevel;
/* Selections from a module are handled earlier, when identifying
the variable, so ...
return;
}
- if (sc->sc_level != proclevel) {
+ if ((difflevel = proclevel - sc->sc_level) != 0) {
/* the variable is local to a statically enclosing procedure.
*/
- assert(proclevel > sc->sc_level);
+ assert(difflevel > 0);
df->df_flags |= D_NOREG;
if (df->df_flags & (D_VARPAR|D_VALPAR)) {
/* value or var parameter
*/
- C_lxa((arith) (proclevel - sc->sc_level));
+ C_lxa((arith) difflevel);
if ((df->df_flags & D_VARPAR) ||
IsConformantArray(df->df_type)) {
/* var parameter or conformant array.
return;
}
}
- else C_lxl((arith) (proclevel - sc->sc_level));
+ else C_lxl((arith) difflevel);
ds->dsg_kind = DSG_PLOADED;
ds->dsg_offset = df->var_off;
return;
CodeDesig(nd->nd_left, ds);
CodeAddress(ds);
CodePExpr(nd->nd_right);
+ nd = nd->nd_left;
/* Now load address of descriptor
*/
- if (IsConformantArray(nd->nd_left->nd_type)) {
- assert(nd->nd_left->nd_class == Def);
+ if (IsConformantArray(nd->nd_type)) {
+ arith off;
+ assert(nd->nd_class == Def);
- df = nd->nd_left->nd_def;
+ df = nd->nd_def;
+ off = df->var_off + pointer_size;
if (proclevel > df->df_scope->sc_level) {
C_lxa((arith) (proclevel - df->df_scope->sc_level));
- C_adp(df->var_off + pointer_size);
+ C_adp(off);
}
- else C_lal(df->var_off + pointer_size);
+ else C_lal(off);
}
else {
- C_loc(nd->nd_left->nd_type->arr_low);
+ C_loc(nd->nd_type->arr_low);
C_sbu(int_size);
- c_lae_dlb(nd->nd_left->nd_type->arr_descr);
+ c_lae_dlb(nd->nd_type->arr_descr);
}
if (options['A']) {
C_cal("rcka");
case Arrow:
assert(nd->nd_symb == '^');
- CodeDesig(nd->nd_right, ds);
+ nd = nd->nd_right;
+ CodeDesig(nd, ds);
switch(ds->dsg_kind) {
case DSG_LOADED:
ds->dsg_kind = DSG_PLOADED;
case DSG_INDEXED:
case DSG_PLOADED:
case DSG_PFIXED:
- CodeValue(ds, nd->nd_right->nd_type);
+ CodeValue(ds, nd->nd_type);
ds->dsg_kind = DSG_PLOADED;
ds->dsg_offset = 0;
break;
df->var_name = df->df_idf->id_text;
}
else {
- sprint(buf,"_%s_%s", sc->sc_scope->sc_name,
+ sprint(buf,"%s_%s", sc->sc_scope->sc_name,
df->df_idf->id_text);
df->var_name = Salloc(buf,
(unsigned)(strlen(buf)+1));
int dummy;
extern t_idf *DefId;
extern int ForeignFlag;
+ extern char *sprint();
register t_scope *currscope = CurrentScope;
+ char buf[512];
} :
DEFINITION
MODULE IDENT { df = define(dot.TOK_IDF, GlobalScope, D_MODULE);
error("DEFINITION MODULE name is \"%s\", not \"%s\"",
df->df_idf->id_text, DefId->id_text);
}
- currscope->sc_name = df->df_idf->id_text;
+ sprint(buf, "_%s_", df->df_idf->id_text);
+ currscope->sc_name = Salloc(buf, (unsigned) strlen(buf) + 1);
df->mod_vis = CurrVis;
df->df_type = standard_type(T_RECORD, 1, (arith) 1);
df->df_type->rec_scope = currscope;
Defined = df = define(dot.TOK_IDF, GlobalScope, D_MODULE);
open_scope(CLOSEDSCOPE);
df->mod_vis = CurrVis;
- CurrentScope->sc_name = "_M2M";
+ CurrentScope->sc_name = "__M2M_";
CurrentScope->sc_definedby = df;
}
}
STATIC arith
NewTmp(plist, sz, al, regtype)
- struct tmpvar **plist;
+ register struct tmpvar **plist;
arith sz;
{
register arith offset;
}
CompatCheck(nd, tp, message, fc)
- t_node **nd;
+ register t_node **nd;
t_type *tp;
char *message;
int (*fc)();
WalkNode(nd, exit);
}
+static arith tmpprio;
+
STATIC
DoPriority()
{
/* For the time being (???), handle priorities by calls to
the runtime system
*/
- register t_node *pri = priority;
-
- if (pri) {
- C_loc(pri->nd_INT);
- C_cal("_stackprio");
+ if (priority) {
+ tmpprio = NewInt();
+ C_loc(priority->nd_INT);
+ C_cal("stackprio");
C_asp(word_size);
+ C_lfr(word_size);
+ C_stl(tmpprio);
}
}
EndPriority()
{
if (priority) {
- C_cal("_unstackprio");
+ C_lol(tmpprio);
+ C_cal("unstackprio");
+ C_asp(word_size);
+ FreeInt(tmpprio);
}
}
}
}
-DoFilename(nd)
- t_node *nd;
+DoFilename()
{
static label filename_label = 0;
}
C_fil_dlb((label) 1, (arith) 0);
-
- if (nd) DoLineno(nd);
}
}
TmpOpen(sc); /* Initialize for temporaries */
C_pro_narg(sc->sc_name);
DoPriority();
- DoFilename(module->mod_body);
if (module == Defined) {
/* Body of implementation or program module.
Call initialization routines of imported modules.
}
for (; nd; nd = nd->nd_left) {
- C_cal(nd->nd_IDF->id_text);
+ C_cal(nd->nd_def->mod_vis->sc_scope->sc_name);
}
+ DoFilename();
}
WalkDefList(sc->sc_def, MkCalls);
proclevel++;
*/
C_pro_narg(procscope->sc_name);
DoPriority();
- DoFilename(procedure->prc_body);
+ DoFilename(); /* ??? only when this procedure is exported? */
TmpOpen(procscope);
func_type = tp = RemoveEqual(ResultType(procedure->df_type));
}
/* First compute new stackpointer */
C_lal(param->par_def->var_off);
- C_cal("_new_stackptr");
+ C_cal("new_stackptr");
C_asp(pointer_size);
C_lfr(pointer_size);
C_str((arith) 1);
/* adjusted stack pointer */
LOL(param->par_def->var_off, pointer_size);
/* push source address */
- C_cal("_copy_array");
+ C_cal("copy_array");
/* copy */
C_asp(pointer_size);
}
assert(nd->nd_class == Stat);
DoLineno(nd);
- if (nd->nd_flags & ROPTION) options['R'] = 1;
- if (nd->nd_flags & AOPTION) options['A'] = 1;
+ options['R'] = (nd->nd_flags & ROPTION);
+ options['A'] = (nd->nd_flags & AOPTION);
switch(nd->nd_symb) {
case '(':
if (ChkCall(nd)) {
if (nd->nd_type != 0) {
- node_error(nd, "illegal function call");
+ node_error(nd, "procedure call expected instead of function call");
break;
}
CodeCall(nd);
case FOR:
{
arith tmp = NewInt();
- arith tmp2;
+ arith tmp2 = 0;
register t_node *fnd;
int good_forvar;
label l1 = ++text_label;
WalkNode(right, exit_label);
nd->nd_def->df_flags &= ~D_FORLOOP;
if (good_forvar) {
- if (! options['R']) {
+ if (tmp2 != 0) {
label x = ++text_label;
C_lol(tmp2);
ForLoopVarExpr(nd);