## adl-raw-syntax-junk.pkg
# Compiled by:
#
src/lib/compiler/back/low/tools/sml-ast.libstipulate
package lem = lowhalf_error_message; # lowhalf_error_message is from
src/lib/compiler/back/low/control/lowhalf-error-message.pkg package raw = adl_raw_syntax_form; # adl_raw_syntax_form is from
src/lib/compiler/back/low/tools/adl-syntax/adl-raw-syntax-form.pkgherein
package adl_raw_syntax_junk
: (weak) Adl_Raw_Syntax_Junk # Adl_Raw_Syntax_Junk is from
src/lib/compiler/back/low/tools/adl-syntax/adl-raw-syntax-junk.api {
fun id' path id
=
raw::ID_IN_EXPRESSION (raw::IDENT(path, id));
fun id id
=
id' [] id;
fun app (f, e)
=
raw::APPLY_EXPRESSION (id f, e);
fun binop_exp (f, x, y)
=
app (f, raw::TUPLE_IN_EXPRESSION [x, y]);
fun plus (a, raw::LITERAL_IN_EXPRESSION (raw::INT_LIT 0)) => a;
plus (a, raw::LITERAL_IN_EXPRESSION (raw::UNT_LIT 0u0)) => a;
plus (a, raw::LITERAL_IN_EXPRESSION (raw::UNT1_LIT 0u0)) => a;
plus (raw::LITERAL_IN_EXPRESSION (raw::INT_LIT 0), a) => a;
plus (raw::LITERAL_IN_EXPRESSION (raw::UNT_LIT 0u0), a) => a;
plus (raw::LITERAL_IN_EXPRESSION (raw::UNT1_LIT 0u0), a) => a;
plus (a, b) => binop_exp("+", a, b);
end;
fun minus (a, raw::LITERAL_IN_EXPRESSION (raw::INT_LIT 0)) => a;
minus (a, raw::LITERAL_IN_EXPRESSION (raw::UNT_LIT 0u0)) => a;
minus (a, raw::LITERAL_IN_EXPRESSION (raw::UNT1_LIT 0u0)) => a;
#
minus (a, b) => binop_exp ("-", a, b);
end;
fun bitwise_and (a, b)
=
binop_exp("&&", a, b);
fun bitwise_or (a, b)
=
binop_exp("
||", a, b);
fun sll (a, raw::LITERAL_IN_EXPRESSION (raw::UNT_LIT 0u0)) => a; # "sll" == "shift logical left" -- bitwise shift.
sll (a, raw::LITERAL_IN_EXPRESSION (raw::UNT1_LIT 0u0)) => a;
sll (a, raw::LITERAL_IN_EXPRESSION (raw::INT_LIT 0)) => a;
#
sll (a, b) => binop_exp("<<", a, b);
end;
fun slr (a, raw::LITERAL_IN_EXPRESSION (raw::UNT_LIT 0u0)) => a; # "slr" == "shift logical right" -- bitwise shift shifting in zeros at high end.
slr (a, raw::LITERAL_IN_EXPRESSION (raw::UNT1_LIT 0u0)) => a;
slr (a, raw::LITERAL_IN_EXPRESSION (raw::INT_LIT 0)) => a;
#
slr (a, b) => binop_exp(">>", a, b);
end;
fun sar (a, raw::LITERAL_IN_EXPRESSION (raw::UNT_LIT 0u0)) => a; # "sar" == "shift arithmetic right" -- bitwise shift duplicating the sign bit at high end.
sar (a, raw::LITERAL_IN_EXPRESSION (raw::UNT1_LIT 0u0)) => a;
sar (a, raw::LITERAL_IN_EXPRESSION (raw::INT_LIT 0)) => a;
#
sar (a, b) => binop_exp(">>>", a, b);
end;
fun bool_exp x = raw::LITERAL_IN_EXPRESSION (raw::BOOL_LIT x);
fun string_constant_in_expression s = raw::LITERAL_IN_EXPRESSION (raw::STRING_LIT s);
fun integer_constant_in_expression x = raw::LITERAL_IN_EXPRESSION (raw::INT_LIT x);
#
fun int1expression x = raw::LITERAL_IN_EXPRESSION (raw::INT1_LIT x);
fun integerexp x = raw::LITERAL_IN_EXPRESSION (raw::INTEGER_LIT x);
#
fun character_constant_in_expression x = raw::LITERAL_IN_EXPRESSION (raw::CHAR_LIT x);
#
fun unt_constant_in_expression x = raw::LITERAL_IN_EXPRESSION (raw::UNT_LIT x);
fun unt1expression x = raw::LITERAL_IN_EXPRESSION (raw::UNT1_LIT x);
#
fun bool_pat x = raw::LITPAT (raw::BOOL_LIT x);
fun string_constant_in_pattern s = raw::LITPAT (raw::STRING_LIT s);
#
fun integer_constant_in_pattern x = raw::LITPAT (raw::INT_LIT x);
fun int1pattern x = raw::LITPAT (raw::INT1_LIT x);
fun integerpat x = raw::LITPAT (raw::INTEGER_LIT x);
#
fun character_constant_in_pattern x = raw::LITPAT (raw::CHAR_LIT x);
fun unt_constant_in_pattern x = raw::LITPAT (raw::UNT_LIT x);
fun unt1pattern x = raw::LITPAT (raw::UNT1_LIT x);
void = raw::TUPLE_IN_EXPRESSION [];
true = bool_exp TRUE;
false = bool_exp FALSE;
fun and_fn (raw::LITERAL_IN_EXPRESSION (raw::BOOL_LIT TRUE), x) => x;
and_fn (raw::LITERAL_IN_EXPRESSION (raw::BOOL_LIT FALSE), x) => false;
#
and_fn (x, raw::LITERAL_IN_EXPRESSION (raw::BOOL_LIT TRUE )) => x;
and_fn (x, raw::LITERAL_IN_EXPRESSION (raw::BOOL_LIT FALSE)) => false;
#
and_fn (x, y) => binop_exp("andalso", x, y);
end;
fun or_fn (raw::LITERAL_IN_EXPRESSION (raw::BOOL_LIT TRUE ), x) => true;
or_fn (raw::LITERAL_IN_EXPRESSION (raw::BOOL_LIT FALSE), x) => x;
#
or_fn (x, raw::LITERAL_IN_EXPRESSION (raw::BOOL_LIT TRUE )) => true;
or_fn (x, raw::LITERAL_IN_EXPRESSION (raw::BOOL_LIT FALSE)) => x;
#
or_fn (x, y) => binop_exp("or", x, y);
end;
nil_exp = raw::LIST_IN_EXPRESSION ([], NULL);
void_type = raw::IDTY (raw::IDENT([], "Void"));
bool_type = raw::IDTY (raw::IDENT([], "Bool"));
int_type = raw::IDTY (raw::IDENT([], "Int"));
register_type = raw::IDTY (raw::IDENT(["rkj"], "Codetemp_Info"));
register_list_type = raw::APPTY (raw::IDENT([], "List"), [register_type]);
int_list_type = raw::APPTY (raw::IDENT([], "List"), [int_type]);
string_type = raw::IDTY (raw::IDENT([], "String"));
unt1_type = raw::IDTY (raw::IDENT(["one_word_unt"], "Unt"));
unt_type = raw::IDTY (raw::IDENT(["unt"], "Unt"));
label_type = raw::IDTY (raw::IDENT(["label"], "Label"));
label_expression_type = raw::IDTY (raw::IDENT (["label_expression"], "Label_Expression"));
constant_type = raw::IDTY (raw::IDENT(["constant"], "Const"));
cell_kind_type = raw::IDTY (raw::IDENT(["rkj"], "Registerkind"));
cell_set_type = raw::IDTY (raw::IDENT([], "Codetemplists"));
fun sumtypefun (name, args, cbs)
=
raw::SUMTYPE { name, typevars=>args, mc=>NULL, asm=>FALSE, field'=>NULL, cbs };
fun cons (name, arg)
=
raw::CONSTRUCTOR
{ name, type=>arg, mc=>NULL, asm=>NULL, rtl=>NULL,
nop=>raw::FLAGOFF, nullified=>raw::FLAGOFF,
delayslot=>NULL,
delayslot_candidate=>NULL, sdi=>NULL, latency=>NULL,
pipeline=>NULL, loc=>line_number_database::dummy_loc
};
fun my_fn (id, e)
=
raw::VAL_DECL
[ raw::NAMED_VARIABLE
(
case id "_" => raw::WILDCARD_PATTERN;
_ => raw::IDPAT id;
esac,
e
)
];
fun fun_fn'(id, p, e) = raw::FUN (id, [raw::CLAUSE([p], NULL, e)]);
fun fun_fn (id, p, e) = raw::FUN_DECL [fun_fn'(id, p, e)];
fun let_fn ([], e) => e;
let_fn ( d, e) => raw::LET_EXPRESSION (d,[e]);
end;
fun error_fn text
=
raw::CLAUSE ([raw::WILDCARD_PATTERN], NULL, app("error", string_constant_in_expression text));
fun error_fun_fn name
=
raw::VERBATIM_CODE
[ "fun error msg",
" =",
" lem::error (\"" + name + "\", msg);"
];
fun dummy_fun name
=
raw::VERBATIM_CODE ["fun " + name + " _ = error \"" + name + "\";"];
fun bitslice (e, ranges)
=
{ temp = id "temp";
fun gen (tmp, [], pos, e)
=>
e;
gen (tmp, (a, b) ! slices, pos, e)
=>
{ width = b - a + 1;
mask = one_word_unt::(<<) (0u1, unt::from_int width) - 0u1;
field' = sll (tmp, unt1expression (one_word_unt::from_int a));
field' = bitwise_and (field', unt1expression mask);
gen (tmp, slices, pos+width,
plus (sll (field', unt1expression (one_word_unt::from_int pos)), e));
};
end;
fun emit (tmp)
=
gen (tmp, reverse ranges, 0, unt1expression 0u0);
case ranges
#
[_] => emit e;
_ => raw::LET_EXPRESSION( [raw::VAL_DECL [raw::NAMED_VARIABLE (raw::IDPAT "temp", e)]],
[emit (id "temp")]
);
esac;
};
# Add an entry:
#
fun cons' (x, raw::LIST_IN_EXPRESSION (a, b)) => raw::LIST_IN_EXPRESSION (x ! a, b);
cons' (x, y) => raw::LIST_IN_EXPRESSION ([x], THE y);
end;
# Append an entry:
#
fun append (x, raw::LIST_IN_EXPRESSION([], NULL)) => x;
append (x, y) => app("@", raw::TUPLE_IN_EXPRESSION [x, y]);
end;
fun compare_literal (x, y)
=
{ fun kind (raw::INT_LIT _) => 0;
kind (raw::BOOL_LIT _) => 1;
kind (raw::STRING_LIT _) => 2;
kind (raw::CHAR_LIT _) => 3;
kind (raw::UNT_LIT _) => 4;
kind (raw::UNT1_LIT _) => 5;
kind (raw::INTEGER_LIT _) => 6;
kind (raw::FLOAT_LIT _) => 7;
kind (raw::INT1_LIT _) => 8;
end;
case (x, y)
#
(raw::INT_LIT x, raw::INT_LIT y) => int::compare (x, y);
(raw::INT1_LIT x, raw::INT1_LIT y) => one_word_int::compare (x, y);
(raw::STRING_LIT x, raw::STRING_LIT y) => string::compare (x, y);
(raw::CHAR_LIT x, raw::CHAR_LIT y) => char::compare (x, y);
(raw::UNT_LIT x, raw::UNT_LIT y) => unt::compare (x, y);
(raw::UNT1_LIT x, raw::UNT1_LIT y) => one_word_unt::compare (x, y);
(raw::INTEGER_LIT x, raw::INTEGER_LIT y) => multiword_int::compare (x, y);
(raw::FLOAT_LIT x, raw::FLOAT_LIT y) => string::compare (x, y);
(raw::BOOL_LIT x, raw::BOOL_LIT y) => if (x == y ) EQUAL;
elif (x == FALSE ) LESS;
else GREATER;
fi;
(x, y) => int::compare (kind x, kind y);
esac;
};
}; # package adl_raw_syntax_junk
end; # stipulate