Skip to content

Commit 6c0c24a

Browse files
committed
Fix last niggles to get self–hosting tests passing
Treat some exceptions as user exceptions as they can be triggered by user level inputs. Bumped the eval_count limit to handle self–hosting tests. Could probably be dropped at this point.
1 parent fb15224 commit 6c0c24a

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

kotlin/src/mal/reader.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private fun make_string(s: String) =
7575
if (s.last() == '"')
7676
MalString(s.dropLast(1).replace(readEscapes) { readEscapeMap.get(it.value) ?: it.value })
7777
else
78-
throw MalCoreEx("Unexpected end of input, unbalanced quote?")
78+
throw MalUserEx("Unexpected end of input, unbalanced quote?")
7979

8080
private fun make_with_meta(r: Reader, n: Int): MalType {
8181
val meta = read_form(r, n)
@@ -143,7 +143,7 @@ fun read_form(r: Reader, n: Int) : MalType {
143143
}
144144
}
145145
catch(e: IndexOutOfBoundsException) {
146-
throw MalCoreEx("Unexpected end of input, unbalanced paren/brace/bracket?")
146+
throw MalUserEx("Unexpected end of input, unbalanced paren/brace/bracket?")
147147
}
148148
}
149149

kotlin/src/mal/stepA_mal.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
fun READ(s: String) = read_str(s)
22

3-
fun eval_ast(ast: MalType, env: Env, depth: Int) : MalType {
4-
return when(ast) {
3+
fun eval_ast(ast: MalType, env: Env, depth: Int) =
4+
when(ast) {
55
is MalList -> MalList(ast.atoms.map { EVAL(it, env, depth + 1) }.toList())
66
is MalVector -> MalVector(ast.atoms.map { EVAL(it, env, depth + 1) }.toList())
77
is MalMap -> malMapOf(ast.pairs.map { (k,v) -> k to EVAL(v, env, depth + 1) })
88
is MalSymbol -> env.get(ast)
99
else -> ast
1010
}
11-
}
1211

1312
fun make_env(pairs: MalSeq, outer_env: Env, depth: Int) : Env {
1413
val new_env = Env(outer_env)
@@ -83,8 +82,8 @@ fun EVAL(cur_ast: MalType, cur_env: Env, depth: Int) : MalType {
8382
eval_loop@ while (true) {
8483
eval_count++
8584
// The depth check is low enough so as not to hit a terminal StackOverflow error.
86-
// But eval_count is just an arbitrary limit.
87-
if (depth > 1012 || eval_count > 654321) {
85+
// But eval_count is just an arbitrary limit, high enough for self–hosting tests to pass!
86+
if (depth > 1012 || eval_count > 7654321) {
8887
throw MalCoreEx("Recursion/eval limit hit: depth ${depth} / evalled ${eval_count}!")
8988
}
9089

@@ -262,7 +261,6 @@ fun main(args: Array<String>) {
262261
(fn* [v]
263262
(if v false true)))
264263
)""")
265-
rep("")
266264

267265
if(args.size > 0) {
268266
repl_env.set(malSym("*ARGV*"), malListOf(args.drop(1).map(::MalString)))
@@ -282,7 +280,11 @@ fun main(args: Array<String>) {
282280
}
283281
println(rep(line))
284282
}
285-
catch(e: Throwable) {
283+
catch(e: StackOverflowError) {
284+
println("Hit stack overflow at ${e.stackTrace.size}, top 15 frames were:")
285+
println(e.stackTrace.take(15).map{ "\t"+it }.joinToString("\n"))
286+
}
287+
catch(e: Exception) {
286288
println(
287289
when(e) {
288290
is MalUserEx -> "Exception raised: " + pr_str(e.src)

0 commit comments

Comments
 (0)