some minor changes and a fix in pointer arithmetic
This commit is contained in:
parent
c255ffeaaa
commit
c8a728969d
4 changed files with 59 additions and 49 deletions
lang/m2/comp
|
@ -1021,7 +1021,6 @@ ChkStandard(expp)
|
||||||
t_node *arg = expp;
|
t_node *arg = expp;
|
||||||
register t_node *left = expp->nd_left;
|
register t_node *left = expp->nd_left;
|
||||||
register t_def *edf = left->nd_def;
|
register t_def *edf = left->nd_def;
|
||||||
t_type *basetype;
|
|
||||||
int free_it = 0;
|
int free_it = 0;
|
||||||
|
|
||||||
assert(left->nd_class == Def);
|
assert(left->nd_class == Def);
|
||||||
|
@ -1030,17 +1029,19 @@ ChkStandard(expp)
|
||||||
switch(edf->df_value.df_stdname) {
|
switch(edf->df_value.df_stdname) {
|
||||||
case S_ABS:
|
case S_ABS:
|
||||||
if (!(left = getarg(&arg, T_NUMERIC, 0, edf))) return 0;
|
if (!(left = getarg(&arg, T_NUMERIC, 0, edf))) return 0;
|
||||||
basetype = BaseType(left->nd_type);
|
expp->nd_type = BaseType(left->nd_type);
|
||||||
MkCoercion(&(arg->nd_left), basetype);
|
MkCoercion(&(arg->nd_left), expp->nd_type);
|
||||||
left = arg->nd_left;
|
switch(expp->nd_type->tp_fund) {
|
||||||
expp->nd_type = left->nd_type;
|
case T_REAL:
|
||||||
if (left->nd_class == Value &&
|
break;
|
||||||
expp->nd_type->tp_fund != T_REAL) {
|
case T_INTEGER:
|
||||||
cstcall(expp, S_ABS);
|
if (arg->nd_left->nd_class == Value) {
|
||||||
}
|
cstcall(expp,S_ABS);
|
||||||
else if (basetype->tp_fund != T_INTEGER &&
|
}
|
||||||
basetype->tp_fund != T_REAL) {
|
break;
|
||||||
|
default:
|
||||||
free_it = 1;
|
free_it = 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1050,13 +1051,6 @@ ChkStandard(expp)
|
||||||
if (left->nd_class == Value) cstcall(expp, S_CAP);
|
if (left->nd_class == Value) cstcall(expp, S_CAP);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case S_CHR:
|
|
||||||
expp->nd_type = char_type;
|
|
||||||
if (!(left = getarg(&arg, T_INTORCARD, 0, edf))) return 0;
|
|
||||||
MkCoercion(&(arg->nd_left), char_type);
|
|
||||||
free_it = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case S_FLOATD:
|
case S_FLOATD:
|
||||||
case S_FLOAT:
|
case S_FLOAT:
|
||||||
if (! getarg(&arg, T_INTORCARD, 0, edf)) return 0;
|
if (! getarg(&arg, T_INTORCARD, 0, edf)) return 0;
|
||||||
|
@ -1152,9 +1146,13 @@ ChkStandard(expp)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case S_ORD:
|
case S_ORD:
|
||||||
if (! getarg(&arg, T_DISCRETE, 0, edf)) return 0;
|
if (! (left = getarg(&arg, T_NOSUB, 0, edf))) return 0;
|
||||||
MkCoercion(&(arg->nd_left), card_type);
|
MkCoercion(&(arg->nd_left), BaseType(left->nd_type));
|
||||||
free_it = 1;
|
expp->nd_type = card_type;
|
||||||
|
if (arg->nd_left->nd_class == Value) {
|
||||||
|
arg->nd_left->nd_type = card_type;
|
||||||
|
free_it = 1;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifndef STRICT_3RD_ED
|
#ifndef STRICT_3RD_ED
|
||||||
|
@ -1220,17 +1218,15 @@ ChkStandard(expp)
|
||||||
|
|
||||||
case S_TRUNCD:
|
case S_TRUNCD:
|
||||||
case S_TRUNC:
|
case S_TRUNC:
|
||||||
expp->nd_type = card_type;
|
|
||||||
if (edf->df_value.df_stdname == S_TRUNCD) {
|
|
||||||
expp->nd_type = longint_type;
|
|
||||||
}
|
|
||||||
if (! getarg(&arg, T_REAL, 0, edf)) return 0;
|
if (! getarg(&arg, T_REAL, 0, edf)) return 0;
|
||||||
MkCoercion(&(arg->nd_left), expp->nd_type);
|
MkCoercion(&(arg->nd_left),
|
||||||
|
edf->df_value.df_stdname == S_TRUNCD ?
|
||||||
|
longint_type : card_type);
|
||||||
free_it = 1;
|
free_it = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case S_VAL:
|
case S_VAL:
|
||||||
if (!(left = getname(&arg, D_ISTYPE, T_DISCRETE, edf))) {
|
if (!(left = getname(&arg, D_ISTYPE, T_NOSUB, edf))) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
expp->nd_type = left->nd_def->df_type;
|
expp->nd_type = left->nd_def->df_type;
|
||||||
|
@ -1238,9 +1234,16 @@ ChkStandard(expp)
|
||||||
arg->nd_right = 0;
|
arg->nd_right = 0;
|
||||||
FreeNode(arg);
|
FreeNode(arg);
|
||||||
arg = expp;
|
arg = expp;
|
||||||
if (!(left = getarg(&arg, T_INTORCARD, 0, edf))) return 0;
|
/* fall through */
|
||||||
MkCoercion(&(arg->nd_left), expp->nd_type);
|
case S_CHR:
|
||||||
free_it = 1;
|
if (! getarg(&arg, T_CARDINAL, 0, edf)) return 0;
|
||||||
|
if (edf->df_value.df_stdname == S_CHR) {
|
||||||
|
expp->nd_type = char_type;
|
||||||
|
}
|
||||||
|
if (expp->nd_type != int_type) {
|
||||||
|
MkCoercion(&(arg->nd_left), expp->nd_type);
|
||||||
|
free_it = 1;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case S_ADR:
|
case S_ADR:
|
||||||
|
@ -1344,10 +1347,16 @@ ChkCast(expp)
|
||||||
df);
|
df);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expp->nd_right->nd_left = 0;
|
||||||
|
FreeLR(expp);
|
||||||
if (arg->nd_class == Value) {
|
if (arg->nd_class == Value) {
|
||||||
expp->nd_right->nd_left = 0;
|
|
||||||
FreeLR(expp);
|
|
||||||
*expp = *arg;
|
*expp = *arg;
|
||||||
|
free_node(arg);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
expp->nd_symb = CAST;
|
||||||
|
expp->nd_class = Uoper;
|
||||||
|
expp->nd_right = arg;
|
||||||
}
|
}
|
||||||
expp->nd_type = lefttype;
|
expp->nd_type = lefttype;
|
||||||
|
|
||||||
|
|
|
@ -319,15 +319,6 @@ CodeCall(nd)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsCast(left)) {
|
|
||||||
/* it was just a cast. Simply ignore it
|
|
||||||
*/
|
|
||||||
CodePExpr(right->nd_left);
|
|
||||||
*nd = *(right->nd_left);
|
|
||||||
nd->nd_type = left->nd_def->df_type;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(IsProcCall(left));
|
assert(IsProcCall(left));
|
||||||
|
|
||||||
if (right) {
|
if (right) {
|
||||||
|
@ -501,6 +492,11 @@ CodeStd(nd)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(std) {
|
switch(std) {
|
||||||
|
case S_ORD:
|
||||||
|
case S_VAL:
|
||||||
|
CodePExpr(left);
|
||||||
|
break;
|
||||||
|
|
||||||
case S_ABS:
|
case S_ABS:
|
||||||
CodePExpr(left);
|
CodePExpr(left);
|
||||||
if (tp->tp_fund == T_INTEGER) {
|
if (tp->tp_fund == T_INTEGER) {
|
||||||
|
@ -517,8 +513,7 @@ CodeStd(nd)
|
||||||
|
|
||||||
case S_CAP:
|
case S_CAP:
|
||||||
CodePExpr(left);
|
CodePExpr(left);
|
||||||
c_loc(0137); /* ASCII assumed */
|
C_cal("cap");
|
||||||
C_and(word_size);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case S_HIGH:
|
case S_HIGH:
|
||||||
|
@ -706,15 +701,17 @@ CodeOper(expr, true_label, false_label)
|
||||||
case T_REAL:
|
case T_REAL:
|
||||||
C_sbf(tp->tp_size);
|
C_sbf(tp->tp_size);
|
||||||
break;
|
break;
|
||||||
case T_CARDINAL:
|
|
||||||
if (rightop->nd_type == address_type) {
|
|
||||||
C_sbs(pointer_size);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/* fall through */
|
|
||||||
case T_POINTER:
|
case T_POINTER:
|
||||||
case T_EQUAL:
|
case T_EQUAL:
|
||||||
|
if (rightop->nd_type == address_type) {
|
||||||
|
C_sbs(tp->tp_size);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
C_ngi(rightop->nd_type->tp_size);
|
||||||
|
C_ads(rightop->nd_type->tp_size);
|
||||||
|
break;
|
||||||
case T_INTORCARD:
|
case T_INTORCARD:
|
||||||
|
case T_CARDINAL:
|
||||||
subu(tp->tp_size);
|
subu(tp->tp_size);
|
||||||
break;
|
break;
|
||||||
case T_SET:
|
case T_SET:
|
||||||
|
@ -994,6 +991,8 @@ CodeUoper(nd)
|
||||||
CodeCoercion(nd->nd_right->nd_type, tp);
|
CodeCoercion(nd->nd_right->nd_type, tp);
|
||||||
RangeCheck(tp, nd->nd_right->nd_type);
|
RangeCheck(tp, nd->nd_right->nd_type);
|
||||||
break;
|
break;
|
||||||
|
case CAST:
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
crash("Bad unary operator");
|
crash("Bad unary operator");
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,7 @@ struct tokenname tkidf[] = { /* names of the identifier tokens */
|
||||||
struct tokenname tkinternal[] = { /* internal keywords */
|
struct tokenname tkinternal[] = { /* internal keywords */
|
||||||
{PROGRAM, ""},
|
{PROGRAM, ""},
|
||||||
{COERCION, ""},
|
{COERCION, ""},
|
||||||
|
{CAST, ""},
|
||||||
{0, "0"}
|
{0, "0"}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,7 @@ struct type {
|
||||||
#define T_ARRAY 0x2000
|
#define T_ARRAY 0x2000
|
||||||
#define T_STRING 0x4000
|
#define T_STRING 0x4000
|
||||||
#define T_INTORCARD (T_INTEGER|T_CARDINAL)
|
#define T_INTORCARD (T_INTEGER|T_CARDINAL)
|
||||||
|
#define T_NOSUB (T_INTORCARD|T_ENUMERATION|T_CHAR)
|
||||||
#define T_NUMERIC (T_INTORCARD|T_REAL)
|
#define T_NUMERIC (T_INTORCARD|T_REAL)
|
||||||
#define T_INDEX (T_ENUMERATION|T_CHAR|T_SUBRANGE)
|
#define T_INDEX (T_ENUMERATION|T_CHAR|T_SUBRANGE)
|
||||||
#define T_DISCRETE (T_INDEX|T_INTORCARD)
|
#define T_DISCRETE (T_INDEX|T_INTORCARD)
|
||||||
|
|
Loading…
Add table
Reference in a new issue