Skip to content

Commit

Permalink
fix Control-d (eof) problem and other cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
melsman committed Oct 31, 2023
1 parent cddad62 commit 33cea95
Show file tree
Hide file tree
Showing 8 changed files with 407 additions and 400 deletions.
4 changes: 3 additions & 1 deletion src/Common/ERROR_CODE.sml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
(*$ERROR_CODE*)

signature ERROR_CODE = (* Support for error testing. *)
sig
type ErrorCode and ErrorInfo
val from_ErrorInfo : ErrorInfo -> ErrorCode
val error_code_parse : ErrorCode
val error_code_eof : ErrorCode
val eq : ErrorCode * ErrorCode -> bool
val pr : ErrorCode -> string
end
3 changes: 2 additions & 1 deletion src/Common/ErrorInfo.sml
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,9 @@ structure ErrorInfo: ERROR_INFO =
| REGVAR_TY_ANNOTATE _ => "REGVAR_TY_ANNOTATE"

val error_code_parse = "PARSE"
val error_code_eof = "EOF"

fun eq(ec1 : ErrorCode, ec2: ErrorCode): bool = ec1=ec2
fun eq (ec1 : ErrorCode, ec2: ErrorCode): bool = ec1=ec2
fun pr (ec: ErrorCode) :string = ("ERR#" ^ ec)
end

Expand Down
1 change: 1 addition & 0 deletions src/Compiler/Lambda/COMPILER_ENV.sml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ signature COMPILER_ENV =
val set_compileTypeScheme : (TypeScheme -> tyvar list * Type) -> unit (* MEGA HACK *)
(* We should clean this *)
(* up at some point!! - Martin *)

val tynamesOfCEnv: CEnv -> TyName list
(* Return the list of tynames occurring in CEnv *)
val lvarsOfCEnv: CEnv -> lvar list
Expand Down
5 changes: 2 additions & 3 deletions src/Compiler/Lambda/COMPILE_DEC.sml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(* Main entry point to the compiler. compileStrdec compiles a list of
* structure declarations containing no functor applications to a
* lambda program, together with the environment _of this declaration
* only_.
* only_.
*)

signature COMPILE_DEC =
Expand All @@ -11,8 +11,7 @@ signature COMPILE_DEC =
type CEnv
type LambdaPgm

val compileStrdecs:
val compileStrdecs:
('a * ('a -> funid -> strid * Env * strexp * CEnv * 'a))
-> CEnv -> strdec list -> CEnv * LambdaPgm

end
760 changes: 380 additions & 380 deletions src/Compiler/Lambda/CompilerEnv.sml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Manager/ParseElab.sml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ structure ParseElab: PARSE_ELAB =
| NONE =>
(chat "[parsing end...]\n";
(NONE, FAILURE (Report.line ("Parse error - no input!"),
[ErrorCode.error_code_parse])))
[ErrorCode.error_code_eof])))
end handle Parse report =>
(chat "[parsing end...]\n";
(NONE, FAILURE (report, [ErrorCode.error_code_parse])))
Expand Down
27 changes: 15 additions & 12 deletions src/Manager/Repl.sml
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,12 @@ local
type TyName = TyName.TyName
type TypeScheme = tyvar list * Type

fun pp_TypeScheme (nil,t) = PP.flatten1 (LambdaExp.layoutType t)
fun pp_Type t = PP.flatten1 (LambdaExp.layoutType t)

fun pp_TypeScheme (nil,t) = pp_Type t
| pp_TypeScheme (tvs,t) =
"(" ^ String.concatWith "," (map LambdaExp.pr_tyvar tvs) ^ ")." ^
PP.flatten1 (LambdaExp.layoutType t)
pp_Type t

fun isArrow (_,t) =
case t of
Expand Down Expand Up @@ -552,8 +554,8 @@ local
\ | search s -- search for help about s\n\
\ | set flag [arg] -- set flag [maybe with arg]\n\
\ | unset flag -- unset the flag\n\n\
\Notice that more flags are available from the command-line\n\
\at REPL initialisation time.\n\
\Notice that more flags are available from the command-line at\n\
\REPL initialisation time.\n\
\")
fun menu_headings () =
Expand Down Expand Up @@ -827,14 +829,15 @@ fun repl (stepno, state, rp:rp, libs_acc, deps:dep list) : OS.Process.status =
libs_acc,
deps)
)
| (_, PE.FAILURE (report,errs)) => (* some syntax errors end here, so we shouldn't exit... *)
| (_, PE.FAILURE (report,errs)) => (* some syntax errors end here, so we shouldn't exit unless we have an eof... *)
( Report.print report
; repl (stepno+1,
PE.begin_stdin(), (* Clear the state *)
rp,
libs_acc,
deps)
; do_exit rp OS.Process.failure
; if List.exists (fn e => PE.ErrorCode.eq(e,PE.ErrorCode.error_code_eof)) errs then
do_exit rp OS.Process.failure
else repl (stepno+1,
PE.begin_stdin(), (* Clear the state *)
rp,
libs_acc,
deps)
)
| (NONE, PE.SUCCESS _) => die "repl - impossible"
end handle Quit => do_exit rp OS.Process.success
Expand Down Expand Up @@ -906,7 +909,7 @@ fun run () : OS.Process.status =
val (stepno,libs_acc,deps) = process_cmd stepno rp cmd libs_acc deps
in (stepno,state,rp,libs_acc,deps)
end
else ( print ("!Basis Library and Pretty Printing are not loaded!\n")
else ( print ("!Basis Library and Pretty Printing not loaded!\n")
; init )
in repl init
end
Expand Down
5 changes: 3 additions & 2 deletions test/repl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ runtime:

%-ri.out: %.sml Makefile
@echo "SML_LIB=../.. $(MLKIT) < $< | .. | > $@" >> complog.txt
@SML_LIB=../.. $(MLKIT) < $< \
@SML_LIB=../.. $(MLKIT) -no_basislib < $< \
| grep -v 'MLKit v' \
| grep -v 'Garbage collection disabled' \
| grep -v 'Basis Library and Pretty Printing not loaded' \
| grep -v 'Type :help;' \
| grep -v '. Exiting' > $@

Expand Down Expand Up @@ -47,7 +48,7 @@ test: prepare $(RESFILES)

.PHONY: prepare
prepare:
SML_LIB=../.. $(MLKIT) -no_gc ../../basis/repl.mlb
SML_LIB=../.. $(MLKIT) -no_gc -c ../../basis/repl.mlb

.PHONY: clean
clean:
Expand Down

0 comments on commit 33cea95

Please sign in to comment.