author | haftmann |
Sun, 23 Feb 2014 10:33:43 +0100 | |
changeset 55684 | ee49b4f7edc8 |
parent 55683 | 5732a55b9232 |
child 55776 | 7dd1971b39c1 |
permissions | -rw-r--r-- |
37745
6315b6426200
checking generated code for various target languages
haftmann
parents:
37669
diff
changeset
|
1 |
(* Title: Tools/Code/code_scala.ML |
6315b6426200
checking generated code for various target languages
haftmann
parents:
37669
diff
changeset
|
2 |
Author: Florian Haftmann, TU Muenchen |
34294 | 3 |
|
4 |
Serializer for Scala. |
|
5 |
*) |
|
6 |
||
7 |
signature CODE_SCALA = |
|
8 |
sig |
|
37745
6315b6426200
checking generated code for various target languages
haftmann
parents:
37669
diff
changeset
|
9 |
val target: string |
34294 | 10 |
val setup: theory -> theory |
11 |
end; |
|
12 |
||
13 |
structure Code_Scala : CODE_SCALA = |
|
14 |
struct |
|
15 |
||
16 |
val target = "Scala"; |
|
17 |
||
55150 | 18 |
open Basic_Code_Symbol; |
34294 | 19 |
open Basic_Code_Thingol; |
20 |
open Code_Printer; |
|
21 |
||
22 |
infixr 5 @@; |
|
23 |
infixr 5 @|; |
|
24 |
||
25 |
||
26 |
(** Scala serializer **) |
|
27 |
||
47609 | 28 |
fun print_scala_stmt tyco_syntax const_syntax reserved |
50626
e21485358c56
uniform parentheses for constructor -- necessary to accomodate scala 10
haftmann
parents:
48568
diff
changeset
|
29 |
args_num is_constr (deresolve, deresolve_full) = |
34294 | 30 |
let |
55150 | 31 |
val deresolve_const = deresolve o Constant; |
32 |
val deresolve_tyco = deresolve o Type_Constructor; |
|
33 |
val deresolve_class = deresolve o Type_Class; |
|
37639 | 34 |
fun lookup_tyvar tyvars = lookup_var tyvars o first_upper; |
35 |
fun intro_tyvars vs = intro_vars (map (first_upper o fst) vs); |
|
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
36 |
fun print_tyco_expr tyvars fxy (sym, tys) = applify "[" "]" |
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
37 |
(print_typ tyvars NOBR) fxy ((str o deresolve) sym) tys |
38923 | 38 |
and print_typ tyvars fxy (tyco `%% tys) = (case tyco_syntax tyco |
55150 | 39 |
of NONE => print_tyco_expr tyvars fxy (Type_Constructor tyco, tys) |
47609 | 40 |
| SOME (_, print) => print (print_typ tyvars) fxy tys) |
37243
6e2ac5358d6e
capitalized type variables; added yield as keyword
haftmann
parents:
37224
diff
changeset
|
41 |
| print_typ tyvars fxy (ITyVar v) = (str o lookup_tyvar tyvars) v; |
55150 | 42 |
fun print_dicttyp tyvars (class, ty) = print_tyco_expr tyvars NOBR (Type_Class class, [ty]); |
37639 | 43 |
fun print_tupled_typ tyvars ([], ty) = |
44 |
print_typ tyvars NOBR ty |
|
45 |
| print_tupled_typ tyvars ([ty1], ty2) = |
|
46 |
concat [print_typ tyvars BR ty1, str "=>", print_typ tyvars NOBR ty2] |
|
47 |
| print_tupled_typ tyvars (tys, ty) = |
|
48 |
concat [enum "," "(" ")" (map (print_typ tyvars NOBR) tys), |
|
49 |
str "=>", print_typ tyvars NOBR ty]; |
|
50 |
fun constraint p1 p2 = Pretty.block [p1, str ":", Pretty.brk 1, p2]; |
|
34294 | 51 |
fun print_var vars NONE = str "_" |
52 |
| print_var vars (SOME v) = (str o lookup_var vars) v |
|
48072
ace701efe203
prefer records with speaking labels over deeply nested tuples
haftmann
parents:
48003
diff
changeset
|
53 |
fun print_term tyvars is_pat some_thm vars fxy (IConst const) = |
ace701efe203
prefer records with speaking labels over deeply nested tuples
haftmann
parents:
48003
diff
changeset
|
54 |
print_app tyvars is_pat some_thm vars fxy (const, []) |
35228 | 55 |
| print_term tyvars is_pat some_thm vars fxy (t as (t1 `$ t2)) = |
34294 | 56 |
(case Code_Thingol.unfold_const_app t |
35228 | 57 |
of SOME app => print_app tyvars is_pat some_thm vars fxy app |
37639 | 58 |
| _ => applify "(" ")" (print_term tyvars is_pat some_thm vars NOBR) fxy |
59 |
(print_term tyvars is_pat some_thm vars BR t1) [t2]) |
|
35228 | 60 |
| print_term tyvars is_pat some_thm vars fxy (IVar v) = |
34294 | 61 |
print_var vars v |
35228 | 62 |
| print_term tyvars is_pat some_thm vars fxy ((v, ty) `|=> t) = |
34294 | 63 |
let |
64 |
val vars' = intro_vars (the_list v) vars; |
|
65 |
in |
|
66 |
concat [ |
|
37639 | 67 |
enclose "(" ")" [constraint (print_var vars' v) (print_typ tyvars NOBR ty)], |
34294 | 68 |
str "=>", |
35228 | 69 |
print_term tyvars false some_thm vars' NOBR t |
34294 | 70 |
] |
41939 | 71 |
end |
48072
ace701efe203
prefer records with speaking labels over deeply nested tuples
haftmann
parents:
48003
diff
changeset
|
72 |
| print_term tyvars is_pat some_thm vars fxy (ICase case_expr) = |
ace701efe203
prefer records with speaking labels over deeply nested tuples
haftmann
parents:
48003
diff
changeset
|
73 |
(case Code_Thingol.unfold_const_app (#primitive case_expr) |
55150 | 74 |
of SOME (app as ({ sym = Constant const, ... }, _)) => |
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
75 |
if is_none (const_syntax const) |
48072
ace701efe203
prefer records with speaking labels over deeply nested tuples
haftmann
parents:
48003
diff
changeset
|
76 |
then print_case tyvars some_thm vars fxy case_expr |
ace701efe203
prefer records with speaking labels over deeply nested tuples
haftmann
parents:
48003
diff
changeset
|
77 |
else print_app tyvars is_pat some_thm vars fxy app |
ace701efe203
prefer records with speaking labels over deeply nested tuples
haftmann
parents:
48003
diff
changeset
|
78 |
| NONE => print_case tyvars some_thm vars fxy case_expr) |
37464 | 79 |
and print_app tyvars is_pat some_thm vars fxy |
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
80 |
(app as ({ sym, typargs, dom, ... }, ts)) = |
34294 | 81 |
let |
82 |
val k = length ts; |
|
50626
e21485358c56
uniform parentheses for constructor -- necessary to accomodate scala 10
haftmann
parents:
48568
diff
changeset
|
83 |
val typargs' = if is_pat then [] else typargs; |
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
84 |
val syntax = case sym of |
55150 | 85 |
Constant const => const_syntax const |
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
86 |
| _ => NONE; |
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
87 |
val (l, print') = case syntax of |
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
88 |
NONE => (args_num sym, fn fxy => fn ts => gen_applify (is_constr sym) "(" ")" |
37639 | 89 |
(print_term tyvars is_pat some_thm vars NOBR) fxy |
90 |
(applify "[" "]" (print_typ tyvars NOBR) |
|
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
91 |
NOBR ((str o deresolve) sym) typargs') ts) |
55153
eedd549de3ef
more suitable names, without any notion of "activating"
haftmann
parents:
55150
diff
changeset
|
92 |
| SOME (k, Plain_printer s) => (k, fn fxy => fn ts => applify "(" ")" |
37881 | 93 |
(print_term tyvars is_pat some_thm vars NOBR) fxy |
94 |
(applify "[" "]" (print_typ tyvars NOBR) |
|
48072
ace701efe203
prefer records with speaking labels over deeply nested tuples
haftmann
parents:
48003
diff
changeset
|
95 |
NOBR (str s) typargs') ts) |
55153
eedd549de3ef
more suitable names, without any notion of "activating"
haftmann
parents:
55150
diff
changeset
|
96 |
| SOME (k, Complex_printer print) => |
38059 | 97 |
(k, fn fxy => fn ts => print (print_term tyvars is_pat some_thm) some_thm vars fxy |
48072
ace701efe203
prefer records with speaking labels over deeply nested tuples
haftmann
parents:
48003
diff
changeset
|
98 |
(ts ~~ take k dom)) |
38059 | 99 |
in if k = l then print' fxy ts |
34294 | 100 |
else if k < l then |
35228 | 101 |
print_term tyvars is_pat some_thm vars fxy (Code_Thingol.eta_expand l app) |
34294 | 102 |
else let |
103 |
val (ts1, ts23) = chop l ts; |
|
104 |
in |
|
38059 | 105 |
Pretty.block (print' BR ts1 :: map (fn t => Pretty.block |
35228 | 106 |
[str ".apply(", print_term tyvars is_pat some_thm vars NOBR t, str ")"]) ts23) |
34294 | 107 |
end end |
37464 | 108 |
and print_bind tyvars some_thm fxy p = |
109 |
gen_print_bind (print_term tyvars true) some_thm fxy p |
|
48072
ace701efe203
prefer records with speaking labels over deeply nested tuples
haftmann
parents:
48003
diff
changeset
|
110 |
and print_case tyvars some_thm vars fxy { clauses = [], ... } = |
48073
1b609a7837ef
prefer sys.error over plain error in Scala to avoid deprecation warning
haftmann
parents:
48072
diff
changeset
|
111 |
(brackify fxy o Pretty.breaks o map str) ["sys.error(\"empty case\")"] |
48072
ace701efe203
prefer records with speaking labels over deeply nested tuples
haftmann
parents:
48003
diff
changeset
|
112 |
| print_case tyvars some_thm vars fxy (case_expr as { clauses = [_], ... }) = |
34294 | 113 |
let |
48072
ace701efe203
prefer records with speaking labels over deeply nested tuples
haftmann
parents:
48003
diff
changeset
|
114 |
val (bind :: binds, body) = Code_Thingol.unfold_let (ICase case_expr); |
41781
32a7726d2136
more idiomatic printing of let cascades and type variable constraints
haftmann
parents:
41687
diff
changeset
|
115 |
fun print_match_val ((pat, ty), t) vars = |
32a7726d2136
more idiomatic printing of let cascades and type variable constraints
haftmann
parents:
41687
diff
changeset
|
116 |
vars |
32a7726d2136
more idiomatic printing of let cascades and type variable constraints
haftmann
parents:
41687
diff
changeset
|
117 |
|> print_bind tyvars some_thm BR pat |
32a7726d2136
more idiomatic printing of let cascades and type variable constraints
haftmann
parents:
41687
diff
changeset
|
118 |
|>> (fn p => (false, concat [str "val", constraint p (print_typ tyvars NOBR ty), |
32a7726d2136
more idiomatic printing of let cascades and type variable constraints
haftmann
parents:
41687
diff
changeset
|
119 |
str "=", print_term tyvars false some_thm vars NOBR t])); |
32a7726d2136
more idiomatic printing of let cascades and type variable constraints
haftmann
parents:
41687
diff
changeset
|
120 |
fun print_match_seq t vars = |
32a7726d2136
more idiomatic printing of let cascades and type variable constraints
haftmann
parents:
41687
diff
changeset
|
121 |
((true, print_term tyvars false some_thm vars NOBR t), vars); |
32a7726d2136
more idiomatic printing of let cascades and type variable constraints
haftmann
parents:
41687
diff
changeset
|
122 |
fun print_match is_first ((IVar NONE, ty), t) = |
41784 | 123 |
if Code_Thingol.is_IAbs t andalso is_first |
41781
32a7726d2136
more idiomatic printing of let cascades and type variable constraints
haftmann
parents:
41687
diff
changeset
|
124 |
then print_match_val ((IVar NONE, ty), t) |
32a7726d2136
more idiomatic printing of let cascades and type variable constraints
haftmann
parents:
41687
diff
changeset
|
125 |
else print_match_seq t |
32a7726d2136
more idiomatic printing of let cascades and type variable constraints
haftmann
parents:
41687
diff
changeset
|
126 |
| print_match _ ((pat, ty), t) = |
32a7726d2136
more idiomatic printing of let cascades and type variable constraints
haftmann
parents:
41687
diff
changeset
|
127 |
print_match_val ((pat, ty), t); |
32a7726d2136
more idiomatic printing of let cascades and type variable constraints
haftmann
parents:
41687
diff
changeset
|
128 |
val (seps_ps, vars') = |
32a7726d2136
more idiomatic printing of let cascades and type variable constraints
haftmann
parents:
41687
diff
changeset
|
129 |
vars |> print_match true bind ||>> fold_map (print_match false) binds |>> uncurry cons; |
38059 | 130 |
val all_seps_ps = seps_ps @ [(true, print_term tyvars false some_thm vars' NOBR body)]; |
131 |
fun insert_seps [(_, p)] = [p] |
|
132 |
| insert_seps ((_, p) :: (seps_ps as (sep, _) :: _)) = |
|
133 |
(if sep then Pretty.block [p, str ";"] else p) :: insert_seps seps_ps |
|
41781
32a7726d2136
more idiomatic printing of let cascades and type variable constraints
haftmann
parents:
41687
diff
changeset
|
134 |
in brackify_block fxy (str "{") (insert_seps all_seps_ps) (str "}") end |
48072
ace701efe203
prefer records with speaking labels over deeply nested tuples
haftmann
parents:
48003
diff
changeset
|
135 |
| print_case tyvars some_thm vars fxy { term = t, typ = ty, clauses = clauses as _ :: _, ... } = |
34294 | 136 |
let |
137 |
fun print_select (pat, body) = |
|
138 |
let |
|
37464 | 139 |
val (p_pat, vars') = print_bind tyvars some_thm NOBR pat vars; |
140 |
val p_body = print_term tyvars false some_thm vars' NOBR body |
|
141 |
in concat [str "case", p_pat, str "=>", p_body] end; |
|
46850 | 142 |
in |
143 |
map print_select clauses |
|
144 |
|> Pretty.block_enclose (concat [print_term tyvars false some_thm vars NOBR t, str "match", str "{"], str "}") |
|
145 |
|> single |
|
146 |
|> enclose "(" ")" |
|
48072
ace701efe203
prefer records with speaking labels over deeply nested tuples
haftmann
parents:
48003
diff
changeset
|
147 |
end; |
55681 | 148 |
fun privatize Code_Namespace.Public = concat |
149 |
| privatize _ = concat o cons (str "private"); |
|
150 |
fun privatize' Code_Namespace.Public = concat |
|
151 |
| privatize' Code_Namespace.Opaque = concat |
|
152 |
| privatize' _ = concat o cons (str "private"); |
|
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
153 |
fun print_context tyvars vs sym = applify "[" "]" |
37639 | 154 |
(fn (v, sort) => (Pretty.block o map str) |
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
155 |
(lookup_tyvar tyvars v :: maps (fn class => [" : ", deresolve_class class]) sort)) |
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
156 |
NOBR ((str o deresolve) sym) vs; |
55679 | 157 |
fun print_defhead export tyvars vars const vs params tys ty = |
158 |
privatize export [str "def", constraint (applify "(" ")" (fn (param, ty) => |
|
37639 | 159 |
constraint ((str o lookup_var vars) param) (print_typ tyvars NOBR ty)) |
55150 | 160 |
NOBR (print_context tyvars vs (Constant const)) (params ~~ tys)) (print_typ tyvars NOBR ty), |
55679 | 161 |
str "="]; |
162 |
fun print_def export const (vs, ty) [] = |
|
37639 | 163 |
let |
164 |
val (tys, ty') = Code_Thingol.unfold_fun ty; |
|
43329
84472e198515
tuned signature: Name.invent and Name.invent_names;
wenzelm
parents:
43326
diff
changeset
|
165 |
val params = Name.invent (snd reserved) "a" (length tys); |
37639 | 166 |
val tyvars = intro_tyvars vs reserved; |
167 |
val vars = intro_vars params reserved; |
|
168 |
in |
|
55679 | 169 |
concat [print_defhead export tyvars vars const vs params tys ty', |
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
170 |
str ("sys.error(\"" ^ const ^ "\")")] |
37639 | 171 |
end |
55679 | 172 |
| print_def export const (vs, ty) eqs = |
37639 | 173 |
let |
174 |
val tycos = fold (fn ((ts, t), _) => |
|
175 |
fold Code_Thingol.add_tyconames (t :: ts)) eqs []; |
|
176 |
val tyvars = reserved |
|
177 |
|> intro_base_names |
|
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
178 |
(is_none o tyco_syntax) deresolve_tyco tycos |
37639 | 179 |
|> intro_tyvars vs; |
180 |
val simple = case eqs |
|
181 |
of [((ts, _), _)] => forall Code_Thingol.is_IVar ts |
|
182 |
| _ => false; |
|
183 |
val vars1 = reserved |
|
55145
2bb3cd36bcf7
more abstract declaration of unqualified constant names in code printing context
haftmann
parents:
52520
diff
changeset
|
184 |
|> intro_base_names_for (is_none o const_syntax) |
2bb3cd36bcf7
more abstract declaration of unqualified constant names in code printing context
haftmann
parents:
52520
diff
changeset
|
185 |
deresolve (map (snd o fst) eqs); |
37639 | 186 |
val params = if simple |
187 |
then (map (fn IVar (SOME x) => x) o fst o fst o hd) eqs |
|
188 |
else aux_params vars1 (map (fst o fst) eqs); |
|
189 |
val vars2 = intro_vars params vars1; |
|
190 |
val (tys', ty') = Code_Thingol.unfold_fun_n (length params) ty; |
|
38922 | 191 |
fun tuplify [p] = p |
192 |
| tuplify ps = enum "," "(" ")" ps; |
|
37639 | 193 |
fun print_rhs vars' ((_, t), (some_thm, _)) = |
194 |
print_term tyvars false some_thm vars' NOBR t; |
|
195 |
fun print_clause (eq as ((ts, _), (some_thm, _))) = |
|
34294 | 196 |
let |
37639 | 197 |
val vars' = intro_vars ((fold o Code_Thingol.fold_varnames) |
198 |
(insert (op =)) ts []) vars1; |
|
199 |
in |
|
200 |
concat [str "case", |
|
38922 | 201 |
tuplify (map (print_term tyvars true some_thm vars' NOBR) ts), |
37639 | 202 |
str "=>", print_rhs vars' eq] |
203 |
end; |
|
55679 | 204 |
val head = print_defhead export tyvars vars2 const vs params tys' ty'; |
37639 | 205 |
in if simple then |
206 |
concat [head, print_rhs vars2 (hd eqs)] |
|
207 |
else |
|
208 |
Pretty.block_enclose |
|
38922 | 209 |
(concat [head, tuplify (map (str o lookup_var vars2) params), |
37639 | 210 |
str "match", str "{"], str "}") |
211 |
(map print_clause eqs) |
|
212 |
end; |
|
55150 | 213 |
val print_method = str o Library.enclose "`" "`" o deresolve_full o Constant; |
55679 | 214 |
fun print_stmt (Constant const, (export, Code_Thingol.Fun (((vs, ty), raw_eqs), _))) = |
215 |
print_def export const (vs, ty) (filter (snd o snd) raw_eqs) |
|
216 |
| print_stmt (Type_Constructor tyco, (export, Code_Thingol.Datatype (vs, cos))) = |
|
34294 | 217 |
let |
48003
1d11af40b106
dropped sort constraints on datatype specifications
haftmann
parents:
47609
diff
changeset
|
218 |
val tyvars = intro_tyvars (map (rpair []) vs) reserved; |
50626
e21485358c56
uniform parentheses for constructor -- necessary to accomodate scala 10
haftmann
parents:
48568
diff
changeset
|
219 |
fun print_co ((co, vs_args), tys) = |
e21485358c56
uniform parentheses for constructor -- necessary to accomodate scala 10
haftmann
parents:
48568
diff
changeset
|
220 |
concat [Pretty.block ((applify "[" "]" (str o lookup_tyvar tyvars) NOBR |
55679 | 221 |
((privatize export o map str) ["final", "case", "class", deresolve_const co]) vs_args) |
50626
e21485358c56
uniform parentheses for constructor -- necessary to accomodate scala 10
haftmann
parents:
48568
diff
changeset
|
222 |
@@ enum "," "(" ")" (map (fn (v, arg) => constraint (str v) (print_typ tyvars NOBR arg)) |
e21485358c56
uniform parentheses for constructor -- necessary to accomodate scala 10
haftmann
parents:
48568
diff
changeset
|
223 |
(Name.invent_names (snd reserved) "a" tys))), |
e21485358c56
uniform parentheses for constructor -- necessary to accomodate scala 10
haftmann
parents:
48568
diff
changeset
|
224 |
str "extends", |
e21485358c56
uniform parentheses for constructor -- necessary to accomodate scala 10
haftmann
parents:
48568
diff
changeset
|
225 |
applify "[" "]" (str o lookup_tyvar tyvars) NOBR |
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
226 |
((str o deresolve_tyco) tyco) vs |
50626
e21485358c56
uniform parentheses for constructor -- necessary to accomodate scala 10
haftmann
parents:
48568
diff
changeset
|
227 |
]; |
34294 | 228 |
in |
50626
e21485358c56
uniform parentheses for constructor -- necessary to accomodate scala 10
haftmann
parents:
48568
diff
changeset
|
229 |
Pretty.chunks (applify "[" "]" (str o lookup_tyvar tyvars) |
55681 | 230 |
NOBR ((privatize' export o map str) ["abstract", "sealed", "class", deresolve_tyco tyco]) vs |
37639 | 231 |
:: map print_co cos) |
34294 | 232 |
end |
55679 | 233 |
| print_stmt (Type_Class class, (export, Code_Thingol.Class (v, (classrels, classparams)))) = |
34294 | 234 |
let |
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
235 |
val tyvars = intro_tyvars [(v, [class])] reserved; |
37639 | 236 |
fun add_typarg s = Pretty.block |
237 |
[str s, str "[", (str o lookup_tyvar tyvars) v, str "]"]; |
|
37384
5aba26803073
more consistent naming aroud type classes and instances
haftmann
parents:
37337
diff
changeset
|
238 |
fun print_super_classes [] = NONE |
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
239 |
| print_super_classes classrels = SOME (concat (str "extends" |
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
240 |
:: separate (str "with") (map (add_typarg o deresolve_class o snd) classrels))); |
34294 | 241 |
fun print_classparam_val (classparam, ty) = |
37639 | 242 |
concat [str "val", constraint (print_method classparam) |
243 |
((print_tupled_typ tyvars o Code_Thingol.unfold_fun) ty)]; |
|
34294 | 244 |
fun print_classparam_def (classparam, ty) = |
245 |
let |
|
246 |
val (tys, ty) = Code_Thingol.unfold_fun ty; |
|
43329
84472e198515
tuned signature: Name.invent and Name.invent_names;
wenzelm
parents:
43326
diff
changeset
|
247 |
val [implicit_name] = Name.invent (snd reserved) (lookup_tyvar tyvars v) 1; |
37639 | 248 |
val proto_vars = intro_vars [implicit_name] reserved; |
43329
84472e198515
tuned signature: Name.invent and Name.invent_names;
wenzelm
parents:
43326
diff
changeset
|
249 |
val auxs = Name.invent (snd proto_vars) "a" (length tys); |
37639 | 250 |
val vars = intro_vars auxs proto_vars; |
34294 | 251 |
in |
55684
ee49b4f7edc8
keep only identifiers public which are explicitly requested or demanded by dependencies
haftmann
parents:
55683
diff
changeset
|
252 |
privatize' export [str "def", constraint (Pretty.block [applify "(" ")" |
37639 | 253 |
(fn (aux, ty) => constraint ((str o lookup_var vars) aux) |
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
254 |
(print_typ tyvars NOBR ty)) NOBR (add_typarg (deresolve_const classparam)) |
37639 | 255 |
(auxs ~~ tys), str "(implicit ", str implicit_name, str ": ", |
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
256 |
add_typarg (deresolve_class class), str ")"]) (print_typ tyvars NOBR ty), str "=", |
37639 | 257 |
applify "(" ")" (str o lookup_var vars) NOBR |
258 |
(Pretty.block [str implicit_name, str ".", print_method classparam]) auxs] |
|
34294 | 259 |
end; |
260 |
in |
|
261 |
Pretty.chunks ( |
|
262 |
(Pretty.block_enclose |
|
55681 | 263 |
(privatize' export ([str "trait", (add_typarg o deresolve_class) class] |
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
264 |
@ the_list (print_super_classes classrels) @ [str "{"]), str "}") |
34294 | 265 |
(map print_classparam_val classparams)) |
266 |
:: map print_classparam_def classparams |
|
267 |
) |
|
268 |
end |
|
55679 | 269 |
| print_stmt (sym, (export, Code_Thingol.Classinst |
270 |
{ class, tyco, vs, inst_params, superinst_params, ... })) = |
|
34294 | 271 |
let |
37639 | 272 |
val tyvars = intro_tyvars vs reserved; |
273 |
val classtyp = (class, tyco `%% map (ITyVar o fst) vs); |
|
52520
4a884366b0d8
consider explicit hint for domain of class parameters when printing instance statements
haftmann
parents:
52519
diff
changeset
|
274 |
fun print_classparam_instance ((classparam, (const as { dom, ... }, dom_length)), (thm, _)) = |
37450 | 275 |
let |
48072
ace701efe203
prefer records with speaking labels over deeply nested tuples
haftmann
parents:
48003
diff
changeset
|
276 |
val aux_dom = Name.invent_names (snd reserved) "a" dom; |
ace701efe203
prefer records with speaking labels over deeply nested tuples
haftmann
parents:
48003
diff
changeset
|
277 |
val auxs = map fst aux_dom; |
37450 | 278 |
val vars = intro_vars auxs reserved; |
52520
4a884366b0d8
consider explicit hint for domain of class parameters when printing instance statements
haftmann
parents:
52519
diff
changeset
|
279 |
val (aux_dom1, aux_dom2) = chop dom_length aux_dom; |
4a884366b0d8
consider explicit hint for domain of class parameters when printing instance statements
haftmann
parents:
52519
diff
changeset
|
280 |
fun abstract_using [] = [] |
4a884366b0d8
consider explicit hint for domain of class parameters when printing instance statements
haftmann
parents:
52519
diff
changeset
|
281 |
| abstract_using aux_dom = [enum "," "(" ")" |
4a884366b0d8
consider explicit hint for domain of class parameters when printing instance statements
haftmann
parents:
52519
diff
changeset
|
282 |
(map (fn (aux, ty) => constraint ((str o lookup_var vars) aux) |
4a884366b0d8
consider explicit hint for domain of class parameters when printing instance statements
haftmann
parents:
52519
diff
changeset
|
283 |
(print_typ tyvars NOBR ty)) aux_dom), str "=>"]; |
4a884366b0d8
consider explicit hint for domain of class parameters when printing instance statements
haftmann
parents:
52519
diff
changeset
|
284 |
val aux_abstr1 = abstract_using aux_dom1; |
4a884366b0d8
consider explicit hint for domain of class parameters when printing instance statements
haftmann
parents:
52519
diff
changeset
|
285 |
val aux_abstr2 = abstract_using aux_dom2; |
41939 | 286 |
in |
55684
ee49b4f7edc8
keep only identifiers public which are explicitly requested or demanded by dependencies
haftmann
parents:
55683
diff
changeset
|
287 |
concat ([str "val", print_method classparam, str "="] |
52520
4a884366b0d8
consider explicit hint for domain of class parameters when printing instance statements
haftmann
parents:
52519
diff
changeset
|
288 |
@ aux_abstr1 @ aux_abstr2 @| print_app tyvars false (SOME thm) vars NOBR |
37639 | 289 |
(const, map (IVar o SOME) auxs)) |
37450 | 290 |
end; |
37639 | 291 |
in |
55679 | 292 |
Pretty.block_enclose (privatize export [str "implicit def", |
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
293 |
constraint (print_context tyvars vs sym) (print_dicttyp tyvars classtyp), |
37639 | 294 |
str "=", str "new", print_dicttyp tyvars classtyp, str "{"], str "}") |
48072
ace701efe203
prefer records with speaking labels over deeply nested tuples
haftmann
parents:
48003
diff
changeset
|
295 |
(map print_classparam_instance (inst_params @ superinst_params)) |
37639 | 296 |
end; |
34294 | 297 |
in print_stmt end; |
298 |
||
55683 | 299 |
fun scala_program_of_program ctxt module_name reserved identifiers exports program = |
34294 | 300 |
let |
38809
7dc73a208722
proper namespace administration for hierarchical modules
haftmann
parents:
38782
diff
changeset
|
301 |
fun namify_module name_fragment ((nsp_class, nsp_object), nsp_common) = |
7dc73a208722
proper namespace administration for hierarchical modules
haftmann
parents:
38782
diff
changeset
|
302 |
let |
7dc73a208722
proper namespace administration for hierarchical modules
haftmann
parents:
38782
diff
changeset
|
303 |
val declare = Name.declare name_fragment; |
7dc73a208722
proper namespace administration for hierarchical modules
haftmann
parents:
38782
diff
changeset
|
304 |
in (name_fragment, ((declare nsp_class, declare nsp_object), declare nsp_common)) end; |
38769
317e64c886d2
preliminary implementation of hierarchical module name space
haftmann
parents:
38059
diff
changeset
|
305 |
fun namify_class base ((nsp_class, nsp_object), nsp_common) = |
317e64c886d2
preliminary implementation of hierarchical module name space
haftmann
parents:
38059
diff
changeset
|
306 |
let |
43326
47cf4bc789aa
simplified Name.variant -- discontinued builtin fold_map;
wenzelm
parents:
41940
diff
changeset
|
307 |
val (base', nsp_class') = Name.variant base nsp_class |
38769
317e64c886d2
preliminary implementation of hierarchical module name space
haftmann
parents:
38059
diff
changeset
|
308 |
in (base', ((nsp_class', nsp_object), Name.declare base' nsp_common)) end; |
317e64c886d2
preliminary implementation of hierarchical module name space
haftmann
parents:
38059
diff
changeset
|
309 |
fun namify_object base ((nsp_class, nsp_object), nsp_common) = |
317e64c886d2
preliminary implementation of hierarchical module name space
haftmann
parents:
38059
diff
changeset
|
310 |
let |
43326
47cf4bc789aa
simplified Name.variant -- discontinued builtin fold_map;
wenzelm
parents:
41940
diff
changeset
|
311 |
val (base', nsp_object') = Name.variant base nsp_object |
38769
317e64c886d2
preliminary implementation of hierarchical module name space
haftmann
parents:
38059
diff
changeset
|
312 |
in (base', ((nsp_class, nsp_object'), Name.declare base' nsp_common)) end; |
317e64c886d2
preliminary implementation of hierarchical module name space
haftmann
parents:
38059
diff
changeset
|
313 |
fun namify_common upper base ((nsp_class, nsp_object), nsp_common) = |
317e64c886d2
preliminary implementation of hierarchical module name space
haftmann
parents:
38059
diff
changeset
|
314 |
let |
317e64c886d2
preliminary implementation of hierarchical module name space
haftmann
parents:
38059
diff
changeset
|
315 |
val (base', nsp_common') = |
43326
47cf4bc789aa
simplified Name.variant -- discontinued builtin fold_map;
wenzelm
parents:
41940
diff
changeset
|
316 |
Name.variant (if upper then first_upper base else base) nsp_common |
38769
317e64c886d2
preliminary implementation of hierarchical module name space
haftmann
parents:
38059
diff
changeset
|
317 |
in |
317e64c886d2
preliminary implementation of hierarchical module name space
haftmann
parents:
38059
diff
changeset
|
318 |
(base', |
317e64c886d2
preliminary implementation of hierarchical module name space
haftmann
parents:
38059
diff
changeset
|
319 |
((Name.declare base' nsp_class, Name.declare base' nsp_object), nsp_common')) |
317e64c886d2
preliminary implementation of hierarchical module name space
haftmann
parents:
38059
diff
changeset
|
320 |
end; |
38809
7dc73a208722
proper namespace administration for hierarchical modules
haftmann
parents:
38782
diff
changeset
|
321 |
fun namify_stmt (Code_Thingol.Fun _) = namify_object |
7dc73a208722
proper namespace administration for hierarchical modules
haftmann
parents:
38782
diff
changeset
|
322 |
| namify_stmt (Code_Thingol.Datatype _) = namify_class |
7dc73a208722
proper namespace administration for hierarchical modules
haftmann
parents:
38782
diff
changeset
|
323 |
| namify_stmt (Code_Thingol.Datatypecons _) = namify_common true |
7dc73a208722
proper namespace administration for hierarchical modules
haftmann
parents:
38782
diff
changeset
|
324 |
| namify_stmt (Code_Thingol.Class _) = namify_class |
7dc73a208722
proper namespace administration for hierarchical modules
haftmann
parents:
38782
diff
changeset
|
325 |
| namify_stmt (Code_Thingol.Classrel _) = namify_object |
7dc73a208722
proper namespace administration for hierarchical modules
haftmann
parents:
38782
diff
changeset
|
326 |
| namify_stmt (Code_Thingol.Classparam _) = namify_object |
7dc73a208722
proper namespace administration for hierarchical modules
haftmann
parents:
38782
diff
changeset
|
327 |
| namify_stmt (Code_Thingol.Classinst _) = namify_common false; |
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
328 |
fun memorize_implicits sym = |
38769
317e64c886d2
preliminary implementation of hierarchical module name space
haftmann
parents:
38059
diff
changeset
|
329 |
let |
38970
53d1ee3d98b8
factored out generic part of Scala serializer into code_namespace.ML
haftmann
parents:
38966
diff
changeset
|
330 |
fun is_classinst stmt = case stmt |
53d1ee3d98b8
factored out generic part of Scala serializer into code_namespace.ML
haftmann
parents:
38966
diff
changeset
|
331 |
of Code_Thingol.Classinst _ => true |
53d1ee3d98b8
factored out generic part of Scala serializer into code_namespace.ML
haftmann
parents:
38966
diff
changeset
|
332 |
| _ => false; |
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
333 |
val implicits = filter (is_classinst o Code_Symbol.Graph.get_node program) |
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
334 |
(Code_Symbol.Graph.immediate_succs program sym); |
38970
53d1ee3d98b8
factored out generic part of Scala serializer into code_namespace.ML
haftmann
parents:
38966
diff
changeset
|
335 |
in union (op =) implicits end; |
55684
ee49b4f7edc8
keep only identifiers public which are explicitly requested or demanded by dependencies
haftmann
parents:
55683
diff
changeset
|
336 |
fun modify_stmt (_, (_, Code_Thingol.Fun (_, SOME _))) = NONE |
ee49b4f7edc8
keep only identifiers public which are explicitly requested or demanded by dependencies
haftmann
parents:
55683
diff
changeset
|
337 |
| modify_stmt (_, (_, Code_Thingol.Datatypecons _)) = NONE |
ee49b4f7edc8
keep only identifiers public which are explicitly requested or demanded by dependencies
haftmann
parents:
55683
diff
changeset
|
338 |
| modify_stmt (_, (_, Code_Thingol.Classrel _)) = NONE |
ee49b4f7edc8
keep only identifiers public which are explicitly requested or demanded by dependencies
haftmann
parents:
55683
diff
changeset
|
339 |
| modify_stmt (_, (_, Code_Thingol.Classparam _)) = NONE |
ee49b4f7edc8
keep only identifiers public which are explicitly requested or demanded by dependencies
haftmann
parents:
55683
diff
changeset
|
340 |
| modify_stmt (_, export_stmt) = SOME export_stmt; |
38970
53d1ee3d98b8
factored out generic part of Scala serializer into code_namespace.ML
haftmann
parents:
38966
diff
changeset
|
341 |
in |
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
342 |
Code_Namespace.hierarchical_program ctxt |
52138
e21426f244aa
bookkeeping and input syntax for exact specification of names of symbols in generated code
haftmann
parents:
51143
diff
changeset
|
343 |
{ module_name = module_name, reserved = reserved, identifiers = identifiers, |
41939 | 344 |
empty_nsp = ((reserved, reserved), reserved), namify_module = namify_module, |
55684
ee49b4f7edc8
keep only identifiers public which are explicitly requested or demanded by dependencies
haftmann
parents:
55683
diff
changeset
|
345 |
namify_stmt = namify_stmt, cyclic_modules = true, |
ee49b4f7edc8
keep only identifiers public which are explicitly requested or demanded by dependencies
haftmann
parents:
55683
diff
changeset
|
346 |
class_transitive = true, class_relation_public = false, empty_data = [], |
55683 | 347 |
memorize_data = memorize_implicits, modify_stmts = map modify_stmt } exports program |
38970
53d1ee3d98b8
factored out generic part of Scala serializer into code_namespace.ML
haftmann
parents:
38966
diff
changeset
|
348 |
end; |
34294 | 349 |
|
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
350 |
fun serialize_scala ctxt { module_name, reserved_syms, identifiers, |
55683 | 351 |
includes, class_syntax, tyco_syntax, const_syntax } exports program = |
34294 | 352 |
let |
38769
317e64c886d2
preliminary implementation of hierarchical module name space
haftmann
parents:
38059
diff
changeset
|
353 |
|
38809
7dc73a208722
proper namespace administration for hierarchical modules
haftmann
parents:
38782
diff
changeset
|
354 |
(* build program *) |
39147 | 355 |
val { deresolver, hierarchical_program = scala_program } = |
55681 | 356 |
scala_program_of_program ctxt module_name (Name.make_context reserved_syms) |
55683 | 357 |
identifiers exports program; |
38769
317e64c886d2
preliminary implementation of hierarchical module name space
haftmann
parents:
38059
diff
changeset
|
358 |
|
317e64c886d2
preliminary implementation of hierarchical module name space
haftmann
parents:
38059
diff
changeset
|
359 |
(* print statements *) |
55150 | 360 |
fun lookup_constr tyco constr = case Code_Symbol.Graph.get_node program (Type_Constructor tyco) |
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
361 |
of Code_Thingol.Datatype (_, constrs) => |
37639 | 362 |
the (AList.lookup (op = o apsnd fst) constrs constr); |
55150 | 363 |
fun classparams_of_class class = case Code_Symbol.Graph.get_node program (Type_Class class) |
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
364 |
of Code_Thingol.Class (_, (_, classparams)) => classparams; |
55150 | 365 |
fun args_num (sym as Constant const) = case Code_Symbol.Graph.get_node program sym |
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
366 |
of Code_Thingol.Fun (((_, ty), []), _) => |
37464 | 367 |
(length o fst o Code_Thingol.unfold_fun) ty |
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
368 |
| Code_Thingol.Fun ((_, ((ts, _), _) :: _), _) => length ts |
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
369 |
| Code_Thingol.Datatypecons tyco => length (lookup_constr tyco const) |
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
370 |
| Code_Thingol.Classparam class => |
37639 | 371 |
(length o fst o Code_Thingol.unfold_fun o the o AList.lookup (op =) |
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
372 |
(classparams_of_class class)) const; |
47609 | 373 |
fun print_stmt prefix_fragments = print_scala_stmt |
39147 | 374 |
tyco_syntax const_syntax (make_vars reserved_syms) args_num |
50626
e21485358c56
uniform parentheses for constructor -- necessary to accomodate scala 10
haftmann
parents:
48568
diff
changeset
|
375 |
(Code_Thingol.is_constr program) (deresolver prefix_fragments, deresolver []); |
38769
317e64c886d2
preliminary implementation of hierarchical module name space
haftmann
parents:
38059
diff
changeset
|
376 |
|
39147 | 377 |
(* print modules *) |
38809
7dc73a208722
proper namespace administration for hierarchical modules
haftmann
parents:
38782
diff
changeset
|
378 |
fun print_implicit prefix_fragments implicit = |
38782 | 379 |
let |
38809
7dc73a208722
proper namespace administration for hierarchical modules
haftmann
parents:
38782
diff
changeset
|
380 |
val s = deresolver prefix_fragments implicit; |
38782 | 381 |
in if length (Long_Name.explode s) = 1 then NONE else SOME (str s) end; |
39147 | 382 |
fun print_module prefix_fragments base implicits ps = Pretty.chunks2 |
383 |
([str ("object " ^ base ^ " {")] |
|
384 |
@ (case map_filter (print_implicit prefix_fragments) implicits |
|
385 |
of [] => [] | implicit_ps => (single o Pretty.block) |
|
386 |
(str "import /*implicits*/" :: Pretty.brk 1 :: commas implicit_ps)) |
|
387 |
@ ps @ [str ("} /* object " ^ base ^ " */")]); |
|
38769
317e64c886d2
preliminary implementation of hierarchical module name space
haftmann
parents:
38059
diff
changeset
|
388 |
|
317e64c886d2
preliminary implementation of hierarchical module name space
haftmann
parents:
38059
diff
changeset
|
389 |
(* serialization *) |
39147 | 390 |
val p = Pretty.chunks2 (map snd includes |
391 |
@ Code_Namespace.print_hierarchical { |
|
392 |
print_module = print_module, print_stmt = print_stmt, |
|
393 |
lift_markup = I } scala_program); |
|
39056 | 394 |
fun write width NONE = writeln o format [] width |
395 |
| write width (SOME p) = File.write p o format [] width; |
|
55147
bce3dbc11f95
prefer explicit code symbol type over ad-hoc name mangling
haftmann
parents:
55145
diff
changeset
|
396 |
fun prepare syms width p = ([("", format syms width p)], try (deresolver [])); |
34294 | 397 |
in |
48568 | 398 |
Code_Target.serialization write prepare p |
34294 | 399 |
end; |
400 |
||
38966 | 401 |
val serializer : Code_Target.serializer = |
402 |
Code_Target.parse_args (Scan.succeed ()) #> K serialize_scala; |
|
403 |
||
34294 | 404 |
val literals = let |
37224 | 405 |
fun char_scala c = if c = "'" then "\\'" |
406 |
else if c = "\"" then "\\\"" |
|
407 |
else if c = "\\" then "\\\\" |
|
408 |
else let val k = ord c |
|
409 |
in if k < 32 orelse k > 126 then "\\" ^ radixstring (8, "0", k) else c end |
|
34944
970e1466028d
code literals: distinguish numeral classes by different entries
haftmann
parents:
34900
diff
changeset
|
410 |
fun numeral_scala k = if k < 0 |
37958
9728342bcd56
another refinement chapter in the neverending numeral story
haftmann
parents:
37932
diff
changeset
|
411 |
then if k > ~ 2147483647 then "- " ^ string_of_int (~ k) |
52229
13171b27eaca
space between minus sign and number for large negative number literals causes NumberFormatException at run-time
Andreas Lochbihler
parents:
52138
diff
changeset
|
412 |
else quote ("-" ^ string_of_int (~ k)) |
34944
970e1466028d
code literals: distinguish numeral classes by different entries
haftmann
parents:
34900
diff
changeset
|
413 |
else if k <= 2147483647 then string_of_int k |
970e1466028d
code literals: distinguish numeral classes by different entries
haftmann
parents:
34900
diff
changeset
|
414 |
else quote (string_of_int k) |
34294 | 415 |
in Literals { |
416 |
literal_char = Library.enclose "'" "'" o char_scala, |
|
417 |
literal_string = quote o translate_string char_scala, |
|
34944
970e1466028d
code literals: distinguish numeral classes by different entries
haftmann
parents:
34900
diff
changeset
|
418 |
literal_numeral = fn k => "BigInt(" ^ numeral_scala k ^ ")", |
34888 | 419 |
literal_list = fn [] => str "Nil" | ps => Pretty.block [str "List", enum "," "(" ")" ps], |
34294 | 420 |
infix_cons = (6, "::") |
421 |
} end; |
|
422 |
||
423 |
||
424 |
(** Isar setup **) |
|
425 |
||
426 |
val setup = |
|
37821 | 427 |
Code_Target.add_target |
38966 | 428 |
(target, { serializer = serializer, literals = literals, |
41939 | 429 |
check = { env_var = "SCALA_HOME", |
430 |
make_destination = fn p => Path.append p (Path.explode "ROOT.scala"), |
|
41940 | 431 |
make_command = fn _ => |
432 |
"env JAVA_OPTS='-Xms128m -Xmx512m -Xss2m' \"$SCALA_HOME/bin/scalac\" ROOT.scala" } }) |
|
55150 | 433 |
#> Code_Target.set_printings (Type_Constructor ("fun", |
52435
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents:
52229
diff
changeset
|
434 |
[(target, SOME (2, fn print_typ => fn fxy => fn [ty1, ty2] => |
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents:
52229
diff
changeset
|
435 |
brackify_infix (1, R) fxy ( |
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents:
52229
diff
changeset
|
436 |
print_typ BR ty1 (*product type vs. tupled arguments!*), |
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents:
52229
diff
changeset
|
437 |
str "=>", |
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents:
52229
diff
changeset
|
438 |
print_typ (INFX (1, R)) ty2 |
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
haftmann
parents:
52229
diff
changeset
|
439 |
)))])) |
34294 | 440 |
#> fold (Code_Target.add_reserved target) [ |
441 |
"abstract", "case", "catch", "class", "def", "do", "else", "extends", "false", |
|
442 |
"final", "finally", "for", "forSome", "if", "implicit", "import", "lazy", |
|
443 |
"match", "new", "null", "object", "override", "package", "private", "protected", |
|
444 |
"requires", "return", "sealed", "super", "this", "throw", "trait", "try", |
|
37243
6e2ac5358d6e
capitalized type variables; added yield as keyword
haftmann
parents:
37224
diff
changeset
|
445 |
"true", "type", "val", "var", "while", "with", "yield" |
34294 | 446 |
] |
447 |
#> fold (Code_Target.add_reserved target) [ |
|
48073
1b609a7837ef
prefer sys.error over plain error in Scala to avoid deprecation warning
haftmann
parents:
48072
diff
changeset
|
448 |
"apply", "sys", "scala", "BigInt", "Nil", "List" |
34294 | 449 |
]; |
450 |
||
451 |
end; (*struct*) |