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