src/Tools/Code/code_scala.ML
author haftmann
Fri Dec 05 19:35:36 2014 +0100 (2014-12-05)
changeset 59104 a14475f044b2
parent 58520 a4d1f8041af0
child 59323 468bd3aedfa1
permissions -rw-r--r--
allow multiple inheritance of targets
     1 (*  Title:      Tools/Code/code_scala.ML
     2     Author:     Florian Haftmann, TU Muenchen
     3 
     4 Serializer for Scala.
     5 *)
     6 
     7 signature CODE_SCALA =
     8 sig
     9   val target: string
    10   val case_insensitive: bool Config.T;
    11   val setup: theory -> theory
    12 end;
    13 
    14 structure Code_Scala : CODE_SCALA =
    15 struct
    16 
    17 val target = "Scala";
    18 
    19 open Basic_Code_Symbol;
    20 open Basic_Code_Thingol;
    21 open Code_Printer;
    22 
    23 infixr 5 @@;
    24 infixr 5 @|;
    25 
    26 (** preliminary: option to circumvent clashes on case-insensitive file systems **)
    27 
    28 val case_insensitive = Attrib.setup_config_bool @{binding "scala_case_insensitive"} (K false);
    29 
    30 
    31 (** Scala serializer **)
    32 
    33 fun print_scala_stmt tyco_syntax const_syntax reserved
    34     args_num is_constr (deresolve, deresolve_full) =
    35   let
    36     val deresolve_const = deresolve o Constant;
    37     val deresolve_tyco = deresolve o Type_Constructor;
    38     val deresolve_class = deresolve o Type_Class;
    39     fun lookup_tyvar tyvars = lookup_var tyvars o Name.enforce_case true;
    40     fun intro_tyvars vs = intro_vars (map (Name.enforce_case true o fst) vs);
    41     fun print_tyco_expr tyvars fxy (sym, tys) = applify "[" "]"
    42           (print_typ tyvars NOBR) fxy ((str o deresolve) sym) tys
    43     and print_typ tyvars fxy (tyco `%% tys) = (case tyco_syntax tyco
    44          of NONE => print_tyco_expr tyvars fxy (Type_Constructor tyco, tys)
    45           | SOME (_, print) => print (print_typ tyvars) fxy tys)
    46       | print_typ tyvars fxy (ITyVar v) = (str o lookup_tyvar tyvars) v;
    47     fun print_dicttyp tyvars (class, ty) = print_tyco_expr tyvars NOBR (Type_Class class, [ty]);
    48     fun print_tupled_typ tyvars ([], ty) =
    49           print_typ tyvars NOBR ty
    50       | print_tupled_typ tyvars ([ty1], ty2) =
    51           concat [print_typ tyvars BR ty1, str "=>", print_typ tyvars NOBR ty2]
    52       | print_tupled_typ tyvars (tys, ty) =
    53           concat [enum "," "(" ")" (map (print_typ tyvars NOBR) tys),
    54             str "=>", print_typ tyvars NOBR ty];
    55     fun constraint p1 p2 = Pretty.block [p1, str ":", Pretty.brk 1, p2];
    56     fun print_var vars NONE = str "_"
    57       | print_var vars (SOME v) = (str o lookup_var vars) v
    58     fun print_term tyvars is_pat some_thm vars fxy (IConst const) =
    59           print_app tyvars is_pat some_thm vars fxy (const, [])
    60       | print_term tyvars is_pat some_thm vars fxy (t as (t1 `$ t2)) =
    61           (case Code_Thingol.unfold_const_app t
    62            of SOME app => print_app tyvars is_pat some_thm vars fxy app
    63             | _ => applify "(" ")" (print_term tyvars is_pat some_thm vars NOBR) fxy
    64                 (print_term tyvars is_pat some_thm vars BR t1) [t2])
    65       | print_term tyvars is_pat some_thm vars fxy (IVar v) =
    66           print_var vars v
    67       | print_term tyvars is_pat some_thm vars fxy ((v, ty) `|=> t) =
    68           let
    69             val vars' = intro_vars (the_list v) vars;
    70           in
    71             concat [
    72               enclose "(" ")" [constraint (print_var vars' v) (print_typ tyvars NOBR ty)],
    73               str "=>",
    74               print_term tyvars false some_thm vars' NOBR t
    75             ]
    76           end
    77       | print_term tyvars is_pat some_thm vars fxy (ICase case_expr) =
    78           (case Code_Thingol.unfold_const_app (#primitive case_expr)
    79            of SOME (app as ({ sym = Constant const, ... }, _)) =>
    80                 if is_none (const_syntax const)
    81                 then print_case tyvars some_thm vars fxy case_expr
    82                 else print_app tyvars is_pat some_thm vars fxy app
    83             | NONE => print_case tyvars some_thm vars fxy case_expr)
    84     and print_app tyvars is_pat some_thm vars fxy
    85         (app as ({ sym, typargs, dom, ... }, ts)) =
    86       let
    87         val k = length ts;
    88         val typargs' = if is_pat then [] else typargs;
    89         val syntax = case sym of
    90             Constant const => const_syntax const
    91           | _ => NONE;
    92         val (l, print') = case syntax of
    93             NONE => (args_num sym, fn fxy => fn ts => gen_applify (is_constr sym) "(" ")"
    94               (print_term tyvars is_pat some_thm vars NOBR) fxy
    95                 (applify "[" "]" (print_typ tyvars NOBR)
    96                   NOBR ((str o deresolve) sym) typargs') ts)
    97           | SOME (k, Plain_printer s) => (k, fn fxy => fn ts => applify "(" ")"
    98               (print_term tyvars is_pat some_thm vars NOBR) fxy
    99                 (applify "[" "]" (print_typ tyvars NOBR)
   100                   NOBR (str s) typargs') ts)
   101           | SOME (k, Complex_printer print) =>
   102               (k, fn fxy => fn ts => print (print_term tyvars is_pat some_thm) some_thm vars fxy
   103                 (ts ~~ take k dom))
   104       in if k = l then print' fxy ts
   105       else if k < l then
   106         print_term tyvars is_pat some_thm vars fxy (Code_Thingol.eta_expand l app)
   107       else let
   108         val (ts1, ts23) = chop l ts;
   109       in
   110         Pretty.block (print' BR ts1 :: map (fn t => Pretty.block
   111           [str ".apply(", print_term tyvars is_pat some_thm vars NOBR t, str ")"]) ts23)
   112       end end
   113     and print_bind tyvars some_thm fxy p =
   114       gen_print_bind (print_term tyvars true) some_thm fxy p
   115     and print_case tyvars some_thm vars fxy { clauses = [], ... } =
   116           (brackify fxy o Pretty.breaks o map str) ["sys.error(\"empty case\")"]
   117       | print_case tyvars some_thm vars fxy (case_expr as { clauses = [_], ... }) =
   118           let
   119             val (bind :: binds, body) = Code_Thingol.unfold_let (ICase case_expr);
   120             fun print_match_val ((pat, ty), t) vars =
   121               vars
   122               |> print_bind tyvars some_thm BR pat
   123               |>> (fn p => (false, concat [str "val", constraint p (print_typ tyvars NOBR ty),
   124                   str "=", print_term tyvars false some_thm vars NOBR t]));
   125             fun print_match_seq t vars =
   126               ((true, print_term tyvars false some_thm vars NOBR t), vars);
   127             fun print_match is_first ((IVar NONE, ty), t) =
   128                   if Code_Thingol.is_IAbs t andalso is_first
   129                     then print_match_val ((IVar NONE, ty), t)
   130                     else print_match_seq t
   131               | print_match _ ((pat, ty), t) =
   132                   print_match_val ((pat, ty), t);
   133             val (seps_ps, vars') =
   134               vars |> print_match true bind ||>> fold_map (print_match false) binds |>> uncurry cons;
   135             val all_seps_ps = seps_ps @ [(true, print_term tyvars false some_thm vars' NOBR body)];
   136             fun insert_seps [(_, p)] = [p]
   137               | insert_seps ((_, p) :: (seps_ps as (sep, _) :: _)) =
   138                   (if sep then Pretty.block [p, str ";"] else p) :: insert_seps seps_ps
   139           in brackify_block fxy (str "{") (insert_seps all_seps_ps) (str "}") end
   140       | print_case tyvars some_thm vars fxy { term = t, typ = ty, clauses = clauses as _ :: _, ... } =
   141           let
   142             fun print_select (pat, body) =
   143               let
   144                 val (p_pat, vars') = print_bind tyvars some_thm NOBR pat vars;
   145                 val p_body = print_term tyvars false some_thm vars' NOBR body
   146               in concat [str "case", p_pat, str "=>", p_body] end;
   147           in
   148             map print_select clauses
   149             |> Pretty.block_enclose (concat [print_term tyvars false some_thm vars NOBR t, str "match", str "{"], str "}")
   150             |> single
   151             |> enclose "(" ")"
   152           end;
   153     fun print_context tyvars vs sym = applify "[" "]"
   154       (fn (v, sort) => (Pretty.block o map str)
   155         (lookup_tyvar tyvars v :: maps (fn class => [" : ", deresolve_class class]) sort))
   156           NOBR ((str o deresolve) sym) vs;
   157     fun print_defhead export tyvars vars const vs params tys ty =
   158       concat [str "def", constraint (applify "(" ")" (fn (param, ty) =>
   159         constraint ((str o lookup_var vars) param) (print_typ tyvars NOBR ty))
   160           NOBR (print_context tyvars vs (Constant const)) (params ~~ tys)) (print_typ tyvars NOBR ty),
   161             str "="];
   162     fun print_def export const (vs, ty) [] =
   163           let
   164             val (tys, ty') = Code_Thingol.unfold_fun ty;
   165             val params = Name.invent (snd reserved) "a" (length tys);
   166             val tyvars = intro_tyvars vs reserved;
   167             val vars = intro_vars params reserved;
   168           in
   169             concat [print_defhead export tyvars vars const vs params tys ty',
   170               str ("sys.error(\"" ^ const ^ "\")")]
   171           end
   172       | print_def export const (vs, ty) eqs =
   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
   178                    (is_none o tyco_syntax) deresolve_tyco tycos
   179               |> intro_tyvars vs;
   180             val simple = case eqs
   181              of [((ts, _), _)] => forall Code_Thingol.is_IVar ts
   182               | _ => false;
   183             val vars1 = reserved
   184               |> intro_base_names_for (is_none o const_syntax)
   185                    deresolve (map (snd o fst) eqs);
   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;
   191             fun tuplify [p] = p
   192               | tuplify ps = enum "," "(" ")" ps;
   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, _))) =
   196               let
   197                 val vars' = intro_vars ((fold o Code_Thingol.fold_varnames)
   198                   (insert (op =)) ts []) vars1;
   199               in
   200                 concat [str "case",
   201                   tuplify (map (print_term tyvars true some_thm vars' NOBR) ts),
   202                   str "=>", print_rhs vars' eq]
   203               end;
   204             val head = print_defhead export tyvars vars2 const vs params tys' ty';
   205           in if simple then
   206             concat [head, print_rhs vars2 (hd eqs)]
   207           else
   208             Pretty.block_enclose
   209               (concat [head, tuplify (map (str o lookup_var vars2) params),
   210                 str "match", str "{"], str "}")
   211               (map print_clause eqs)
   212           end;
   213     val print_method = str o Library.enclose "`" "`" o deresolve_full o Constant;
   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))) =
   217           let
   218             val tyvars = intro_tyvars (map (rpair []) vs) reserved;
   219             fun print_co ((co, vs_args), tys) =
   220               concat [Pretty.block ((applify "[" "]" (str o lookup_tyvar tyvars) NOBR
   221                 ((concat o map str) ["final", "case", "class", deresolve_const co]) vs_args)
   222                 @@ enum "," "(" ")" (map (fn (v, arg) => constraint (str v) (print_typ tyvars NOBR arg))
   223                   (Name.invent_names (snd reserved) "a" tys))),
   224                 str "extends",
   225                 applify "[" "]" (str o lookup_tyvar tyvars) NOBR
   226                   ((str o deresolve_tyco) tyco) vs
   227               ];
   228           in
   229             Pretty.chunks (applify "[" "]" (str o lookup_tyvar tyvars)
   230               NOBR ((concat o map str) ["abstract", "sealed", "class", deresolve_tyco tyco]) vs
   231                 :: map print_co cos)
   232           end
   233       | print_stmt (Type_Class class, (export, Code_Thingol.Class (v, (classrels, classparams)))) =
   234           let
   235             val tyvars = intro_tyvars [(v, [class])] reserved;
   236             fun add_typarg s = Pretty.block
   237               [str s, str "[", (str o lookup_tyvar tyvars) v, str "]"];
   238             fun print_super_classes [] = NONE
   239               | print_super_classes classrels = SOME (concat (str "extends"
   240                   :: separate (str "with") (map (add_typarg o deresolve_class o snd) classrels)));
   241             fun print_classparam_val (classparam, ty) =
   242               concat [str "val", constraint (print_method classparam)
   243                 ((print_tupled_typ tyvars o Code_Thingol.unfold_fun) ty)];
   244             fun print_classparam_def (classparam, ty) =
   245               let
   246                 val (tys, ty) = Code_Thingol.unfold_fun ty;
   247                 val [implicit_name] = Name.invent (snd reserved) (lookup_tyvar tyvars v) 1;
   248                 val proto_vars = intro_vars [implicit_name] reserved;
   249                 val auxs = Name.invent (snd proto_vars) "a" (length tys);
   250                 val vars = intro_vars auxs proto_vars;
   251               in
   252                 concat [str "def", constraint (Pretty.block [applify "(" ")"
   253                   (fn (aux, ty) => constraint ((str o lookup_var vars) aux)
   254                   (print_typ tyvars NOBR ty)) NOBR (add_typarg (deresolve_const classparam))
   255                   (auxs ~~ tys), str "(implicit ", str implicit_name, str ": ",
   256                   add_typarg (deresolve_class class), str ")"]) (print_typ tyvars NOBR ty), str "=",
   257                   applify "(" ")" (str o lookup_var vars) NOBR
   258                   (Pretty.block [str implicit_name, str ".", print_method classparam]) auxs]
   259               end;
   260           in
   261             Pretty.chunks (
   262               (Pretty.block_enclose
   263                 (concat ([str "trait", (add_typarg o deresolve_class) class]
   264                   @ the_list (print_super_classes classrels) @ [str "{"]), str "}")
   265                 (map print_classparam_val classparams))
   266               :: map print_classparam_def classparams
   267             )
   268           end
   269       | print_stmt (sym, (export, Code_Thingol.Classinst
   270           { class, tyco, vs, inst_params, superinst_params, ... })) =
   271           let
   272             val tyvars = intro_tyvars vs reserved;
   273             val classtyp = (class, tyco `%% map (ITyVar o fst) vs);
   274             fun print_classparam_instance ((classparam, (const as { dom, ... }, dom_length)), (thm, _)) =
   275               let
   276                 val aux_dom = Name.invent_names (snd reserved) "a" dom;
   277                 val auxs = map fst aux_dom;
   278                 val vars = intro_vars auxs reserved;
   279                 val (aux_dom1, aux_dom2) = chop dom_length aux_dom;
   280                 fun abstract_using [] = []
   281                   | abstract_using aux_dom = [enum "," "(" ")"
   282                       (map (fn (aux, ty) => constraint ((str o lookup_var vars) aux)
   283                       (print_typ tyvars NOBR ty)) aux_dom), str "=>"];
   284                 val aux_abstr1 = abstract_using aux_dom1;
   285                 val aux_abstr2 = abstract_using aux_dom2;
   286               in
   287                 concat ([str "val", print_method classparam, str "="]
   288                   @ aux_abstr1 @ aux_abstr2 @| print_app tyvars false (SOME thm) vars NOBR
   289                     (const, map (IVar o SOME) auxs))
   290               end;
   291           in
   292             Pretty.block_enclose (concat [str "implicit def",
   293               constraint (print_context tyvars vs sym) (print_dicttyp tyvars classtyp),
   294               str "=", str "new", print_dicttyp tyvars classtyp, str "{"], str "}")
   295                 (map print_classparam_instance (inst_params @ superinst_params))
   296           end;
   297   in print_stmt end;
   298 
   299 fun scala_program_of_program ctxt module_name reserved identifiers exports program =
   300   let
   301     val variant = if Config.get ctxt case_insensitive
   302       then Code_Namespace.variant_case_insensitive
   303       else Name.variant;
   304     fun namify_module name_fragment ((nsp_class, nsp_object), nsp_common) =
   305       let
   306         val declare = Name.declare name_fragment;
   307       in (name_fragment, ((declare nsp_class, declare nsp_object), declare nsp_common)) end;
   308     fun namify_class base ((nsp_class, nsp_object), nsp_common) =
   309       let
   310         val (base', nsp_class') = variant base nsp_class
   311       in (base', ((nsp_class', nsp_object), Name.declare base' nsp_common)) end;
   312     fun namify_object base ((nsp_class, nsp_object), nsp_common) =
   313       let
   314         val (base', nsp_object') = variant base nsp_object
   315       in (base', ((nsp_class, nsp_object'), Name.declare base' nsp_common)) end;
   316     fun namify_common base ((nsp_class, nsp_object), nsp_common) =
   317       let
   318         val (base', nsp_common') = variant base nsp_common
   319       in
   320         (base', ((Name.declare base' nsp_class, Name.declare base' nsp_object), nsp_common'))
   321       end;
   322     fun namify_stmt (Code_Thingol.Fun _) = namify_object
   323       | namify_stmt (Code_Thingol.Datatype _) = namify_class
   324       | namify_stmt (Code_Thingol.Datatypecons _) = namify_common
   325       | namify_stmt (Code_Thingol.Class _) = namify_class
   326       | namify_stmt (Code_Thingol.Classrel _) = namify_object
   327       | namify_stmt (Code_Thingol.Classparam _) = namify_object
   328       | namify_stmt (Code_Thingol.Classinst _) = namify_common;
   329     fun memorize_implicits sym =
   330       let
   331         fun is_classinst stmt = case stmt
   332          of Code_Thingol.Classinst _ => true
   333           | _ => false;
   334         val implicits = filter (is_classinst o Code_Symbol.Graph.get_node program)
   335           (Code_Symbol.Graph.immediate_succs program sym);
   336       in union (op =) implicits end;
   337     fun modify_stmt (_, (_, Code_Thingol.Fun (_, SOME _))) = NONE
   338       | modify_stmt (_, (_, Code_Thingol.Datatypecons _)) = NONE
   339       | modify_stmt (_, (_, Code_Thingol.Classrel _)) = NONE
   340       | modify_stmt (_, (_, Code_Thingol.Classparam _)) = NONE
   341       | modify_stmt (_, export_stmt) = SOME export_stmt;
   342   in
   343     Code_Namespace.hierarchical_program ctxt
   344       { module_name = module_name, reserved = reserved, identifiers = identifiers,
   345         empty_nsp = ((reserved, reserved), reserved), namify_module = namify_module,
   346         namify_stmt = namify_stmt, cyclic_modules = true,
   347         class_transitive = true, class_relation_public = false, empty_data = [],
   348         memorize_data = memorize_implicits, modify_stmts = map modify_stmt } exports program
   349   end;
   350 
   351 fun serialize_scala ctxt { module_name, reserved_syms, identifiers,
   352     includes, class_syntax, tyco_syntax, const_syntax } exports program =
   353   let
   354 
   355     (* build program *)
   356     val { deresolver, hierarchical_program = scala_program } =
   357       scala_program_of_program ctxt module_name (Name.make_context reserved_syms)
   358         identifiers exports program;
   359 
   360     (* print statements *)
   361     fun lookup_constr tyco constr = case Code_Symbol.Graph.get_node program (Type_Constructor tyco)
   362      of Code_Thingol.Datatype (_, constrs) =>
   363           the (AList.lookup (op = o apsnd fst) constrs constr);
   364     fun classparams_of_class class = case Code_Symbol.Graph.get_node program (Type_Class class)
   365      of Code_Thingol.Class (_, (_, classparams)) => classparams;
   366     fun args_num (sym as Constant const) = case Code_Symbol.Graph.get_node program sym
   367      of Code_Thingol.Fun (((_, ty), []), _) =>
   368           (length o fst o Code_Thingol.unfold_fun) ty
   369       | Code_Thingol.Fun ((_, ((ts, _), _) :: _), _) => length ts
   370       | Code_Thingol.Datatypecons tyco => length (lookup_constr tyco const)
   371       | Code_Thingol.Classparam class =>
   372           (length o fst o Code_Thingol.unfold_fun o the o AList.lookup (op =)
   373             (classparams_of_class class)) const;
   374     fun print_stmt prefix_fragments = print_scala_stmt
   375       tyco_syntax const_syntax (make_vars reserved_syms) args_num
   376       (Code_Thingol.is_constr program) (deresolver prefix_fragments, deresolver []);
   377 
   378     (* print modules *)
   379     fun print_implicit prefix_fragments implicit =
   380       let
   381         val s = deresolver prefix_fragments implicit;
   382       in if length (Long_Name.explode s) = 1 then NONE else SOME (str s) end;
   383     fun print_module prefix_fragments base implicits ps = Pretty.chunks2
   384       ([str ("object " ^ base ^ " {")]
   385         @ (case map_filter (print_implicit prefix_fragments) implicits
   386             of [] => [] | implicit_ps => (single o Pretty.block)
   387             (str "import /*implicits*/" :: Pretty.brk 1 :: commas implicit_ps))
   388         @ ps @ [str ("} /* object " ^ base ^ " */")]);
   389 
   390     (* serialization *)
   391     val p = Pretty.chunks2 (map snd includes
   392       @ Code_Namespace.print_hierarchical {
   393         print_module = print_module, print_stmt = print_stmt,
   394         lift_markup = I } scala_program);
   395     fun write width NONE = writeln o format [] width
   396       | write width (SOME p) = File.write p o format [] width;
   397     fun prepare syms width p = ([("", format syms width p)], try (deresolver []));
   398   in
   399     Code_Target.serialization write prepare p
   400   end;
   401 
   402 val serializer : Code_Target.serializer =
   403   Code_Target.parse_args (Scan.succeed ()) #> K serialize_scala;
   404 
   405 val literals = let
   406   fun char_scala c = if c = "'" then "\\'"
   407     else if c = "\"" then "\\\""
   408     else if c = "\\" then "\\\\"
   409     else let val k = ord c
   410     in if k < 32 orelse k > 126 then "\\" ^ radixstring (8, "0", k) else c end
   411   fun numeral_scala k =
   412     if ~2147483647 < k andalso k <= 2147483647
   413     then signed_string_of_int k
   414     else quote (signed_string_of_int k)
   415 in Literals {
   416   literal_char = Library.enclose "'" "'" o char_scala,
   417   literal_string = quote o translate_string char_scala,
   418   literal_numeral = fn k => "BigInt(" ^ numeral_scala k ^ ")",
   419   literal_list = fn [] => str "Nil" | ps => Pretty.block [str "List", enum "," "(" ")" ps],
   420   infix_cons = (6, "::")
   421 } end;
   422 
   423 
   424 (** Isar setup **)
   425 
   426 val setup =
   427   Code_Target.add_language
   428     (target, { serializer = serializer, literals = literals,
   429       check = { env_var = "SCALA_HOME",
   430         make_destination = fn p => Path.append p (Path.explode "ROOT.scala"),
   431         make_command = fn _ =>
   432           "env JAVA_OPTS='-Xms128m -Xmx512m -Xss2m' \"$SCALA_HOME/bin/scalac\" ROOT.scala" } })
   433   #> Code_Target.set_printings (Type_Constructor ("fun",
   434     [(target, SOME (2, fn print_typ => fn fxy => fn [ty1, ty2] =>
   435       brackify_infix (1, R) fxy (
   436         print_typ BR ty1 (*product type vs. tupled arguments!*),
   437         str "=>",
   438         print_typ (INFX (1, R)) ty2
   439       )))]))
   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",
   445       "true", "type", "val", "var", "while", "with", "yield"
   446     ]
   447   #> fold (Code_Target.add_reserved target) [
   448       "apply", "sys", "scala", "BigInt", "Nil", "List"
   449     ];
   450 
   451 end; (*struct*)