Simon Génier pushed to branch gambit-compile-pervasives at Stefan / Typer
Commits:
17519ff3 by Simon Génier at 2022-09-22T14:55:27-04:00
Compile (a trimmed-down version of) the pervasives to Scheme.
- - - - -
17 changed files:
- + btl/pervasive-light.typer
- debug_util.ml
- samples/nat.typer
- src/REPL.ml
- + src/array.ml
- src/builtin.ml
- src/debruijn.ml
- src/debug.ml
- src/elab.ml
- src/elexp.ml
- src/env.ml
- src/eval.ml
- src/fmt.ml
- src/gambit.ml
- src/instargs.ml
- src/inverse_subst.ml
- src/lexer.ml
The diff was not included because it is too large.
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/17519ff310d3c13fb3b10bcb873b2a800…
--
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/17519ff310d3c13fb3b10bcb873b2a800…
You're receiving this email because of your account on gitlab.com.
Simon Génier pushed to branch gambit-compile-pervasives at Stefan / Typer
Commits:
0382e776 by Simon Génier at 2022-09-22T04:21:39-04:00
Compile (a trimmed-down version of) the pervasives to Scheme.
- - - - -
18 changed files:
- + btl/pervasive-light.typer
- debug_util.ml
- samples/nat.typer
- src/REPL.ml
- + src/array.ml
- src/builtin.ml
- src/debruijn.ml
- src/debug.ml
- src/elab.ml
- src/elexp.ml
- src/env.ml
- src/eval.ml
- src/fmt.ml
- src/gambit.ml
- src/heap.ml
- src/instargs.ml
- src/inverse_subst.ml
- src/lexer.ml
The diff was not included because it is too large.
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/0382e776a37a8f83c7d824fddc8f15658…
--
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/0382e776a37a8f83c7d824fddc8f15658…
You're receiving this email because of your account on gitlab.com.
Simon Génier pushed to branch gambit-compile-pervasives at Stefan / Typer
Commits:
071738ae by Simon Génier at 2022-09-21T10:07:25-04:00
Compile (a trimmed-down version of) the pervasives to Scheme.
- - - - -
20 changed files:
- + btl/pervasive-light.typer
- debug_util.ml
- samples/nat.typer
- src/REPL.ml
- + src/array.ml
- src/builtin.ml
- src/debruijn.ml
- src/debug.ml
- src/elab.ml
- src/elexp.ml
- src/env.ml
- src/eval.ml
- src/fmt.ml
- src/gambit.ml
- src/heap.ml
- src/instargs.ml
- src/inverse_subst.ml
- src/lexer.ml
- src/lexp.ml
- src/listx.ml → src/list.ml
The diff was not included because it is too large.
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/071738ae521309d943ca11ed2065d0b17…
--
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/071738ae521309d943ca11ed2065d0b17…
You're receiving this email because of your account on gitlab.com.
Simon Génier pushed to branch gambit-compile-pervasives at Stefan / Typer
Commits:
24c7c74b by Simon Génier at 2022-09-18T12:32:40-04:00
Compile (a trimmed-down version of) the pervasives to Scheme.
- - - - -
5 changed files:
- + btl/pervasive-light.typer
- src/elab.ml
- src/gambit.ml
- src/prelexer.ml
- typer.ml
Changes:
=====================================
btl/pervasive-light.typer
=====================================
@@ -0,0 +1,36 @@
+%%% pervasive-light --- Always available definitions, trimmed-down version.
+
+%% Copyright (C) 2011-2022 Free Software Foundation, Inc.
+%%
+%% Author: Pierre Delaunay <pierre.delaunay(a)hec.ca>
+%% Keywords: languages, lisp, dependent types.
+%%
+%% This file is part of Typer.
+%%
+%% Typer is free software; you can redistribute it and/or modify it under the
+%% terms of the GNU General Public License as published by the Free Software
+%% Foundation, either version 3 of the License, or (at your option) any
+%% later version.
+%%
+%% Typer is distributed in the hope that it will be useful, but WITHOUT ANY
+%% WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+%% FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+%% more details.
+%%
+%% You should have received a copy of the GNU General Public License along
+%% with this program. If not, see <http://www.gnu.org/licenses/>.
+
+%%% This file is a trimmed-down version of pervasive.typer. The goal is to have
+%%% some basic definitions so we can compile Typer programs with the Gambit
+%%% backend, which is much less sophisticated than the interpreter.
+
+Unit = typecons Unit unit;
+unit = datacons Unit unit;
+
+%% Void = typecons Void;
+
+%% Eq/refl : (x : ?t) ≡> Eq x x;
+%% Eq/refl = Built-in "Eq.refl";
+
+%% Eq/cast : (x : ?) ≡> (y : ?) ≡> (f : ? -> ?) ≡> f x -> f y;
+%% Eq/cast = Built-in "Eq.cast";
=====================================
src/elab.ml
=====================================
@@ -78,9 +78,12 @@ let display_lexp_details lexp channel _ =
let display_value_details value channel _ =
fprintf channel "\t > %s : %s\n" (value_name value) (value_string value)
+let {trace_debug; trace_info; _} : Log.Trace.trace_functions =
+ Log.Trace.make_trace_functions "ELAB"
+
let {diagnostic_fatal; diagnostic_error; diagnostic_warning; diagnostic_info; _}
: Log.Diagnostics.diagnostic_functions =
- Log.Diagnostics.make_diagnostic_functions "EVAL"
+ Log.Diagnostics.make_diagnostic_functions "ELAB"
let {diagnostic_info = macro_diagnostic_info; _}
: Log.Diagnostics.diagnostic_functions =
@@ -598,7 +601,8 @@ let elab_p_id ((l,name) : symbol) : vname =
(Symbol (l, name), match name with "_" -> None | _ -> Some name)
(* Infer or check, as the case may be. *)
-let rec elaborate ctx se ot =
+let rec elaborate (ctx : elab_context) (se : sexp) (ot : ltype option) =
+ trace_debug __POS__ "Elaborating: %a" Sexp.output se;
let (e, res_t) = match se with
(* Rewrite SYM to `typer-identifier SYM`. *)
| Symbol ((loc, name) as _id)
@@ -1334,7 +1338,7 @@ and infer_and_generalize_type (ctx : elab_context) se name =
-> mkArrow (Symbol(l,""), Aerasable, name, t, e))
t
-and infer_and_generalize_def (ctx : elab_context) se =
+and infer_and_generalize_def (ctx : elab_context) (se : sexp) =
let nctx = ectx_new_scope ctx in
let (e,t) = infer se nctx in
let g = resolve_instances_and_generalize nctx e in
@@ -1428,6 +1432,7 @@ and lexp_decls_1
-> assert (pending_defs == []);
(* Used to be true before we added define-operator. *)
(* assert (ectx == nctx); *)
+ trace_debug __POS__ "processing definition of “%s”" vname;
let (lexp, ltp) = infer_and_generalize_def nctx sexp in
let var = (thesexp, Some vname) in
(* Lexp decls are always recursive, so we have to shift by 1 to
@@ -2173,11 +2178,16 @@ let process_file
(path : string)
: elab_context =
+ trace_info __POS__ "processing file at path: %s" path;
try
let source = Source.of_path path in
let pretokens = prelex source in
let tokens = lex Grammar.default_stt pretokens in
let ldecls, ectx' = lexp_p_decls [] tokens ectx in
+ trace_info
+ __POS__
+ "found %d declarations in file: %s"
+ (List.length ldecls) path;
List.iter backend#process_decls ldecls;
ectx'
with
=====================================
src/gambit.ml
=====================================
@@ -380,7 +380,9 @@ class gambit_compiler lctx output = object
sctx <- sctx';
lctx <- lctx';
List.iter
- (fun sdecl -> sdecl |> pretty_printer#pp |> output_string output)
+ (fun sdecl
+ -> sdecl |> pretty_printer#pp |> output_string output;
+ flush output)
sdecls
method stop =
=====================================
src/prelexer.ml
=====================================
@@ -44,6 +44,16 @@ module Pretoken = struct
| Preblock (_, l_inner), Preblock (_, r_inner)
-> List.equal equal l_inner r_inner
| _ -> false
+
+ let rec pp (f : Format.formatter) (pretoken : t) : unit =
+ let open Format in
+ match pretoken with
+ | Pretoken (_, name) -> pp_print_string f name
+ | Prestring (_, text) -> fprintf f "%S" text
+ | Preblock (_, pretokens)
+ -> pp_print_char f '{';
+ pp_print_list ~pp_sep:pp_print_space pp f pretokens;
+ pp_print_char f '}'
end
(*************** The Pre-Lexer phase *********************)
=====================================
typer.ml
=====================================
@@ -31,7 +31,9 @@ let add_input_file, list_input_files =
let files = ref [] in
(fun file -> files := file :: !files), (fun () -> List.rev !files)
-let arg_defs =
+let preload_pervasives : bool ref = ref true
+
+let generic_arg_spec =
[("--verbosity",
Arg.String (fun s -> Log.Diagnostics.Config.level := Log.Level.parse s),
"Set the logging level");
@@ -48,17 +50,27 @@ let arg_defs =
"Print the full lexp context on error");
]
-let parse_args argv usage =
- try Arg.parse_argv argv arg_defs add_input_file usage with
+let compile_arg_spec =
+ ("--no-pervasives",
+ Arg.Clear preload_pervasives,
+ "Do not load the pervasives.")
+ :: generic_arg_spec
+
+let parse_args spec argv usage =
+ try Arg.parse_argv argv spec add_input_file usage with
| Arg.Help (message) ->
print_string message;
exit 0
let compile_main argv =
let usage = Sys.executable_name ^ " compile [options] <file> …" in
- parse_args argv usage;
+ parse_args compile_arg_spec argv usage;
- let ectx = Elab.default_ectx in
+ let ectx =
+ if !preload_pervasives
+ then Elab.default_ectx
+ else Debruijn.empty_elab_context
+ in
let backend = new Gambit.gambit_compiler (ectx_to_lctx ectx) stdout in
let _ =
@@ -71,7 +83,7 @@ let compile_main argv =
let repl_main argv =
let usage = Sys.executable_name ^ " repl [options] [<file>] …" in
- parse_args argv usage;
+ parse_args generic_arg_spec argv usage;
print_string (Fmt.make_title " TYPER REPL ");
print_endline " Typer 0.0.0 - Interpreter - (c) 2016-2021";
@@ -94,7 +106,7 @@ let repl_main argv =
let run_main argv =
let usage = Sys.executable_name ^ " run [options] <file> …" in
- parse_args argv usage;
+ parse_args generic_arg_spec argv usage;
let ectx = Elab.default_ectx in
let backend = new Eval.ast_interpreter (ectx_to_lctx ectx) in
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/24c7c74bd31922c87c01b6718549adbc2…
--
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/24c7c74bd31922c87c01b6718549adbc2…
You're receiving this email because of your account on gitlab.com.
Stefan pushed to branch report/hmdup at Stefan / Typer
Commits:
4cce113f by Stefan Monnier at 2022-09-16T23:31:21-04:00
-
- - - - -
1 changed file:
- paper.tex
Changes:
=====================================
paper.tex
=====================================
@@ -1191,6 +1191,10 @@ our language is extended as follows:
\cite{Odersky96} %System-F inference via type annotations
+%% Apparently uses a "worklist" approach, like I'd like to use for
+%% Typer.
+\cite{Zhao19} %Jinxu Zhao, Bruno C. d. S. Oliveira, and Tom Schrijvers. 2019. A Mechanical Formalization of Higher-ranked Polymorphic Type Inference. Proc. ACM Program. Lang. 3, ICFP, Article 112 (July 2019), 29 pages. https://doi.org/10.1145/3341716
+
\section{Conclusion}
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/4cce113f1602169d73ab0e6dec9ea645d…
--
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/4cce113f1602169d73ab0e6dec9ea645d…
You're receiving this email because of your account on gitlab.com.
Simon Génier pushed to branch trace-vs-diagnose at Stefan / Typer
Commits:
6b99004e by Simon Génier at 2022-09-16T15:48:52-04:00
Logging overhaul.
This changeset splits logging into two different concepts.
- Diagnostics are meant for users of the compiler working on Typer code.
- Tracing are meant for developers of the compiles working on Ocaml code.
(I know the Venn diagram of these two kinds of people is a perfect circle… for
now.)
The practical difference between the two is that tracing does not expect the
compiler to finish. Messages are printed right away and the channel is flushed
after every message. It can also be enabled on per module basis so you don't get
the full firehose. For example, setting TYPER_TRACE="TC=debug,EVAL=info,error"
will show only error trace messages, except for EVAL where info messages will be
shown too and TC where messages down to the debug level will be.
Diagnostics are similar to the logs we had: they are collected and printed at
the end. Their presence can make the compilation fail.
- - - - -
28 changed files:
- samples/nat.typer
- src/REPL.ml
- + src/array.ml
- src/builtin.ml
- src/debruijn.ml
- src/debug.ml
- src/elab.ml
- src/env.ml
- src/eval.ml
- src/fmt.ml
- src/gambit.ml
- src/heap.ml
- src/instargs.ml
- src/inverse_subst.ml
- src/lexer.ml
- src/lexp.ml
- src/listx.ml → src/list.ml
- src/log.ml
- src/opslexp.ml
- src/pexp.ml
- src/prelexer.ml
- src/sexp.ml
- src/source.ml
- + src/string.ml
- src/unification.ml
- tests/dune
- tests/eval_test.ml
- tests/instargs_test.ml
The diff was not included because it is too large.
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/6b99004eccd5947105d22213bb716dfdf…
--
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/6b99004eccd5947105d22213bb716dfdf…
You're receiving this email because of your account on gitlab.com.
Simon Génier pushed to branch trace-vs-diagnose at Stefan / Typer
Commits:
a1c5194c by Simon Génier at 2022-09-16T09:56:24-04:00
Logging overhaul.
This changeset splits logging into two different concepts.
- Diagnostics are meant for users of the compiler working on Typer code.
- Tracing are meant for developers of the compiles working on Ocaml code.
(I know the Venn diagram of these two kinds of people is a perfect circle… for
now.)
The practical difference between the two is that tracing does not expect the
compiler to finish. Messages are printed right away and the channel is flushed
after every message. It can also be enabled on per module basis so you don't get
the full firehose. For example, setting TYPER_TRACE="TC=debug,EVAL=info,error"
will show only error trace messages, except for EVAL where info messages will be
shown too and TC where messages down to the debug level will be.
Diagnostics are similar to the logs we had: they are collected and printed at
the end. Their presence can make the compilation fail.
- - - - -
30 changed files:
- samples/nat.typer
- src/REPL.ml
- + src/array.ml
- src/builtin.ml
- src/debruijn.ml
- src/debug.ml
- src/elab.ml
- src/env.ml
- src/eval.ml
- src/fmt.ml
- src/gambit.ml
- src/heap.ml
- src/instargs.ml
- src/inverse_subst.ml
- src/lexer.ml
- src/lexp.ml
- src/listx.ml → src/list.ml
- src/log.ml
- src/opslexp.ml
- src/pexp.ml
- src/prelexer.ml
- src/sexp.ml
- src/source.ml
- + src/string.ml
- src/unification.ml
- tests/dune
- tests/eval_test.ml
- tests/instargs_test.ml
- tests/lexer_test.ml
- tests/samples_test.ml
The diff was not included because it is too large.
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/a1c5194c7cbc9f5b9fb3fc64e8cdd3b1a…
--
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/a1c5194c7cbc9f5b9fb3fc64e8cdd3b1a…
You're receiving this email because of your account on gitlab.com.