@@ -156,15 +156,33 @@ let get_grade
156156 match Filename. extension path with
157157 | ".mli" -> load_dependencies ((modname,content) :: signatures) fs
158158 | ".ml" ->
159+ let included,content =
160+ (* the first line of an .ml file can contain an annotation *)
161+ (* @included which denotes that this file has to be included *)
162+ (* directly in the toplevel environment, and not in an module. *)
163+ match String. index_opt content '\n' with
164+ | None -> (false ,content)
165+ | Some i ->
166+ (match String. trim (String. sub content 0 i) with
167+ | "@included" ->
168+ let content' = String. sub content i @@
169+ (String. length content - i)
170+ in (true ,content')
171+ | _ -> (false ,content))
172+ in
159173 (handle_error (internal_error [% i" while loading user dependencies" ]) @@
160- let use_mod =
161- Toploop_ext. use_mod_string ~print_outcome ~ppf_answer ~modname in
162- match List. assoc_opt modname signatures with
163- | Some sig_code -> use_mod ~sig_code content
164- | None -> use_mod content);
165- load_dependencies signatures fs
174+ match included with
175+ | true -> Toploop_ext. use_string ~print_outcome ~ppf_answer
176+ ~filename: (Filename. basename path) content
177+ | false ->
178+ let use_mod =
179+ Toploop_ext. use_mod_string ~print_outcome ~ppf_answer ~modname in
180+ match List. assoc_opt modname signatures with
181+ | Some sig_code -> use_mod ~sig_code content
182+ | None -> use_mod content);
183+ load_dependencies signatures fs
166184 | _ -> failwith (" uninterpreted dependency \" " ^ path ^
167- " \" . file extension expected : .ml or .mli" ) in
185+ " \" , file extension expected : .ml or .mli" ) in
168186 load_dependencies [] files
169187 in
170188
0 commit comments