Skip to content

Commit

Permalink
many changes:
Browse files Browse the repository at this point in the history
1. use [...] for arrays and [:: ...] for lists again. apparently, we use arrays much more frequently than lists
2. vectors are now using 'vector [...]' notation
3. remove just introduced :. operator - the code with this operator does not look clean in practice
  • Loading branch information
vpisarev committed Mar 27, 2022
1 parent 0ec071a commit 46fd7f6
Show file tree
Hide file tree
Showing 96 changed files with 3,573 additions and 3,629 deletions.
42 changes: 21 additions & 21 deletions compiler/Ast.fx
Original file line number Diff line number Diff line change
Expand Up @@ -711,9 +711,9 @@ fun find_module(mname: id_t, mfname: string) =
}
val saved_modules = all_modules
all_modules =
[| for i <- 0:m_idx+1 {
[for i <- 0:m_idx+1 {
if i < m_idx { saved_modules[i] } else { newmodule }
} |]
}]
all_modules_hash.add(mfname, m_idx)
m_idx
}
Expand Down Expand Up @@ -1160,7 +1160,7 @@ fun get_unary_fname(uop: unary_t, loc: loc_t) =
f"for unary operation \"{uop}\" there is no corresponding function")
}

fun fname_always_import(): id_t list = [
fun fname_always_import(): id_t list = [::
fname_op_add(), fname_op_sub(), fname_op_mul(), fname_op_div(), fname_op_rdiv(),
fname_op_mod(), fname_op_pow(), fname_op_dot_add(), fname_op_dot_sub(),
fname_op_dot_mul(), fname_op_dot_div(), fname_op_dot_mod(), fname_op_dot_pow(),
Expand Down Expand Up @@ -1201,7 +1201,7 @@ fun get_cast_fname(t: typ_t, loc: loc_t) =
| _ => throw CompileError(loc, f"for type '{typ2str(t)}' there is no corresponding cast function")
}

val reserved_keywords = Set.from_list(String.cmp, ["fx_result", "fx_status", "fx_fv"])
val reserved_keywords = Set.from_list(String.cmp, [:: "fx_result", "fx_status", "fx_fv"])

fun get_builtin_exception(n0: id_t, loc: loc_t) =
match builtin_exceptions.find_opt(n0) {
Expand Down Expand Up @@ -1281,15 +1281,15 @@ fun typ2str(t: typ_t): string {
| TypTuple(tl) =>
val s = tl2str(tl)
match tl {
| x :. => "(" + s + ",)"
| [:: x] => "(" + s + ",)"
| _ => s
}
| TypRecord (ref (relems, _)) =>
join_embrace("{", "}", "; ",
[| for (flags, i, t, _) <- relems {
[for (flags, i, t, _) <- relems {
val prefix = if flags.val_flag_mutable { "var " } else {""}
f"{prefix}{i}: {typ2str(t)}"
} |])
}])
| TypArray(d, t) => f"{typ2str(t)} [{','*(d-1)}]"
| TypList(t) => f"{typ2str(t)} list"
| TypVector(t) => f"{typ2str(t)} vector"
Expand All @@ -1302,10 +1302,10 @@ fun typ2str(t: typ_t): string {

fun tl2str(tl: typ_t list): string {
val (begin, end) = match tl {
| x :. => ("", "")
| [:: x] => ("", "")
| _ => ("(", ")")
}
join_embrace(begin, end, ", ", [| for t <- tl { typ2str(t) } |])
join_embrace(begin, end, ", ", [for t <- tl { typ2str(t) }])
}

fun parse_pragmas(prl: (string, loc_t) list): pragmas_t {
Expand Down Expand Up @@ -1342,21 +1342,21 @@ fun check_n_walk_typ(t: typ_t, callb: ast_callb_t) =
| _ => walk_typ(t, callb)
}
fun check_n_walk_tlist(tlist: typ_t list, callb: ast_callb_t) =
[for t <- tlist {check_n_walk_typ(t, callb)}]
[:: for t <- tlist {check_n_walk_typ(t, callb)}]
fun check_n_walk_exp(e: exp_t, callb: ast_callb_t) =
match callb.ast_cb_exp {
| Some(f) => f(e, callb)
| _ => walk_exp(e, callb)
}
fun check_n_walk_elist(elist: exp_t list, callb: ast_callb_t): exp_t list =
[for e <- elist { check_n_walk_exp(e, callb) }]
[:: for e <- elist { check_n_walk_exp(e, callb) }]
fun check_n_walk_pat(p: pat_t, callb: ast_callb_t) =
match callb.ast_cb_pat {
| Some(f) => f(p, callb)
| _ => walk_pat(p, callb)
}
fun check_n_walk_plist(plist: pat_t list, callb: ast_callb_t) =
[for p <- plist { check_n_walk_pat(p, callb) }]
[:: for p <- plist { check_n_walk_pat(p, callb) }]

fun walk_typ(t: typ_t, callb: ast_callb_t) =
match t {
Expand All @@ -1380,7 +1380,7 @@ fun walk_typ(t: typ_t, callb: ast_callb_t) =
| TypVarArray(et) => TypVarArray(check_n_walk_typ(et, callb))
| TypVarRecord => t
| TypRecord((ref (relems, ordered)) as r) =>
val new_relems = [ for (flags, n, t, v) <- relems {
val new_relems = [:: for (flags, n, t, v) <- relems {
(flags, n, check_n_walk_typ(t, callb), check_n_walk_exp(v, callb))} ]
*r = (new_relems, ordered)
t
Expand All @@ -1398,9 +1398,9 @@ fun walk_exp(e: exp_t, callb: ast_callb_t) {
fun walk_elist_(el: exp_t list) = check_n_walk_elist(el, callb)
fun walk_pat_(p: pat_t) = check_n_walk_pat(p, callb)
fun walk_plist_(pl: pat_t list) = check_n_walk_plist(pl, callb)
fun walk_pe_l_(pe_l: (pat_t, exp_t) list) = [for (p, e) <- pe_l { (walk_pat_(p), walk_exp_(e)) }]
fun walk_ne_l_(ne_l: (id_t, exp_t) list) = [for (n, e) <- ne_l { (n, walk_exp_(e)) }]
fun walk_cases_(pe_l: (pat_t, exp_t) list) = [for (p, e) <- pe_l { (walk_pat_(p), walk_exp_(e)) }]
fun walk_pe_l_(pe_l: (pat_t, exp_t) list) = [:: for (p, e) <- pe_l { (walk_pat_(p), walk_exp_(e)) }]
fun walk_ne_l_(ne_l: (id_t, exp_t) list) = [:: for (n, e) <- ne_l { (n, walk_exp_(e)) }]
fun walk_cases_(pe_l: (pat_t, exp_t) list) = [:: for (p, e) <- pe_l { (walk_pat_(p), walk_exp_(e)) }]
fun walk_exp_opt_(e_opt: exp_t?) {
| Some(e) => Some(walk_exp_(e))
| _ => None
Expand All @@ -1421,7 +1421,7 @@ fun walk_exp(e: exp_t, callb: ast_callb_t) {
| ExpSeq(elist, ctx) => ExpSeq(walk_elist_(elist), walk_ctx_(ctx))
| ExpSync(n, e) => ExpSync(n, walk_exp_(e))
| ExpMkTuple(elist, ctx) => ExpMkTuple(walk_elist_(elist), walk_ctx_(ctx))
| ExpMkArray(ell, ctx) => ExpMkArray([for el <- ell {walk_elist_(el)}], walk_ctx_(ctx))
| ExpMkArray(ell, ctx) => ExpMkArray([::for el <- ell {walk_elist_(el)}], walk_ctx_(ctx))
| ExpMkVector(elist, ctx) => ExpMkVector(walk_elist_(elist), walk_ctx_(ctx))
| ExpMkRecord(e, ne_l, ctx) => ExpMkRecord(walk_exp_(e), walk_ne_l_(ne_l), walk_ctx_(ctx))
| ExpUpdateRecord(e, ne_l, ctx) => ExpUpdateRecord(walk_exp_(e), walk_ne_l_(ne_l), walk_ctx_(ctx))
Expand All @@ -1436,7 +1436,7 @@ fun walk_exp(e: exp_t, callb: ast_callb_t) {
| ExpFor(pe_l, idx_pat, body, flags, loc) =>
ExpFor(walk_pe_l_(pe_l), walk_pat_(idx_pat), walk_exp_(body), flags, loc)
| ExpMap(pew_ll, body, flags, ctx) =>
ExpMap([for (pe_l, idx_pat) <- pew_ll { (walk_pe_l_(pe_l), walk_pat_(idx_pat)) }],
ExpMap([::for (pe_l, idx_pat) <- pew_ll { (walk_pe_l_(pe_l), walk_pat_(idx_pat)) }],
walk_exp_(body), flags, walk_ctx_(ctx))
| ExpTryCatch(e, cases, ctx) => ExpTryCatch(walk_exp_(e), walk_cases_(cases), walk_ctx_(ctx))
| ExpMatch(e, cases, ctx) => ExpMatch(walk_exp_(e), walk_cases_(cases), walk_ctx_(ctx))
Expand Down Expand Up @@ -1468,7 +1468,7 @@ fun walk_exp(e: exp_t, callb: ast_callb_t) {
val {dvar_alias, dvar_cases} = *dvar
*dvar = dvar->{
dvar_alias=walk_typ_(dvar_alias),
dvar_cases=[ for (n, t) <- dvar_cases {(n, walk_typ_(t))} ]
dvar_cases=[:: for (n, t) <- dvar_cases {(n, walk_typ_(t))} ]
}
e
| DefInterface(di) => e
Expand All @@ -1490,7 +1490,7 @@ fun walk_pat(p: pat_t, callb: ast_callb_t) {
| PatTuple(pl, loc) => PatTuple(walk_pl_(pl), loc)
| PatVariant(n, args, loc) => PatVariant(n, walk_pl_(args), loc)
| PatRecord(n_opt, np_l, loc) => PatRecord(n_opt,
[for (n, p) <- np_l {(n, walk_pat_(p))}], loc)
[:: for (n, p) <- np_l {(n, walk_pat_(p))}], loc)
| PatCons(p1, p2, loc) => PatCons(walk_pat_(p1), walk_pat_(p2), loc)
| PatAs(p, n, loc) => PatAs(walk_pat_(p), n, loc)
| PatTyped(p, t, loc) => PatTyped(walk_pat_(p), walk_typ_(t), loc)
Expand All @@ -1506,7 +1506,7 @@ fun dup_typ_(t: typ_t, callb: ast_callb_t): typ_t =
| TypVar _ => TypVar(ref None)
| TypRecord(r) =>
val (relems, ordered) = *r
val new_relems = [for (flags, n, t, v) <- relems {(flags, n, dup_typ_(t, callb), dup_exp_(v, callb))}]
val new_relems = [:: for (flags, n, t, v) <- relems {(flags, n, dup_typ_(t, callb), dup_exp_(v, callb))}]
TypRecord(ref (new_relems, ordered))
| _ => walk_typ(t, callb)
}
Expand Down
26 changes: 13 additions & 13 deletions compiler/Ast_pp.fx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fun pprint_typ(pp: PP.t, t: typ_t, loc: loc_t, ~brief:bool=false)
pp.begin(); pp.str("(")
match tl {
| [] => pp.str("void")
| t1 :. => pptype_(t1, prec)
| [:: t1] => pptype_(t1, prec)
| _ => pptype_(TypTuple(tl), prec)
}
pp.space(); pp.str("->"); pp.space(); pptype_(t2, prec); pp.str(")")
Expand All @@ -118,7 +118,7 @@ fun pprint_typ(pp: PP.t, t: typ_t, loc: loc_t, ~brief:bool=false)
| TypVarArray(t1) => pptypsuf(t1, "[+]")
| TypVarRecord => pp.str("{...}")
| TypApp([], n) => ppid(pp, n)
| TypApp(t1 :., n) => pptypsuf(t1, ppid2str(n))
| TypApp([:: t1], n) => pptypsuf(t1, ppid2str(n))
| TypApp(tl, n) => pptypsuf(TypTuple(tl), ppid2str(n))
| TypTuple(tl) =>
pp.str("("); pp.cut(); pp.begin()
Expand Down Expand Up @@ -165,7 +165,7 @@ fun pprint_typ(pp: PP.t, t: typ_t, loc: loc_t, ~brief:bool=false)
fun pprint_templ_args(pp: PP.t, tt: id_t list) =
match tt {
| [] => {}
| t :. => ppid(pp, t)
| [:: t] => ppid(pp, t)
| _ =>
pp.str("(")
for t@i <- tt {
Expand Down Expand Up @@ -300,7 +300,7 @@ fun pprint_exp(pp: PP.t, e: exp_t): void
pp.end()
}
pp.str(" ="); pp.space()
val ctors = if dvar_ctors != [] { dvar_ctors } else { [for (n, t) <- dvar_cases {n}] }
val ctors = if dvar_ctors != [] { dvar_ctors } else { [:: for (n, t) <- dvar_cases {n}] }
for (_, t)@i <- dvar_cases, c <- ctors {
pp.begin(); pp.str("| ");
ppid(pp, c); pp.str(": "); pp.space();
Expand Down Expand Up @@ -446,7 +446,7 @@ fun pprint_exp(pp: PP.t, e: exp_t): void
ppexp(e)
}
match el {
| e :. => pp.str(",")
| [:: e] => pp.str(",")
| _ => {}
}
pp.str(")")
Expand All @@ -469,7 +469,7 @@ fun pprint_exp(pp: PP.t, e: exp_t): void
}
pp.end(); pp.str("}")
| ExpMkArray(arows, _) =>
pp.begin(); pp.str("[|")
pp.begin(); pp.str("[")
for acols@i <- arows {
if i > 0 { pp.str(";"); pp.space() }
pp.begin()
Expand All @@ -479,9 +479,9 @@ fun pprint_exp(pp: PP.t, e: exp_t): void
}
pp.end()
}
pp.str("|]"); pp.end()
pp.str("]"); pp.end()
| ExpMkVector(elems, _) =>
pp.begin(); pp.str("[")
pp.begin(); pp.str("vector [")
for e@i <- elems {
if i > 0 { pp.str(","); pp.space() }
ppexp(e)
Expand Down Expand Up @@ -537,10 +537,10 @@ fun pprint_exp(pp: PP.t, e: exp_t): void
pp.end(); pp.space(); pprint_exp_as_block(pp, for_body)
| ExpMap(map_cl, map_body, flags, _) =>
var (oparen, cparen) = match flags.for_flag_make {
| ForMakeList => ("[", "]")
| ForMakeVector => ("[", "]")
| ForMakeList => ("[::", "]")
| ForMakeVector => ("vector [", "]")
| ForMakeTuple => ("(", ")")
| _ => ("[|", "|]")
| _ => ("[", "]")
}
pp.begin(); pp.str(oparen); pp.str(" ");
for (pe_l, idx_pat)@j <- map_cl {
Expand Down Expand Up @@ -593,7 +593,7 @@ fun pprint_exp(pp: PP.t, e: exp_t): void
fun pprint_exp_as_block(pp: PP.t, e: exp_t) =
match e {
| ExpSeq(eseq, _) => pprint_expseq(pp, eseq, true)
| _ => pprint_expseq(pp, e :., true)
| _ => pprint_expseq(pp, [:: e], true)
}

fun pprint_exp_as_seq(pp: PP.t, e: exp_t) =
Expand Down Expand Up @@ -658,7 +658,7 @@ fun pprint_pat(pp: PP.t, p: pat_t)
pp.space(); pprint_exp(pp, e); pp.end()
| PatAlt(pl, _) =>
match pl {
| p :. => pppat(p)
| [:: p] => pppat(p)
| _ =>
pp.beginv(0); pp.str("(");
for p@i <- pl {
Expand Down
Loading

0 comments on commit 46fd7f6

Please sign in to comment.