Skip to content

Commit 5682c03

Browse files
committed
Complete rewrite of the error reporting and representation sub-system. More preparations for managing source locations.
1 parent 6c0566d commit 5682c03

32 files changed

+1832
-1474
lines changed

LispKit.xcodeproj/project.pbxproj

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,15 @@
145145
CC98B4581EBD43E500BCD049 /* NumberKit.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = CC5C713E1EBD3D3A00280CF4 /* NumberKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
146146
CC98B45A1EBD444400BCD049 /* NumberKit.framework.dSYM in Copy dSYM data */ = {isa = PBXBuildFile; fileRef = CC98B4591EBD444400BCD049 /* NumberKit.framework.dSYM */; };
147147
CC9EB1151F5C9DFF00697511 /* Topological.scm in Copy examples */ = {isa = PBXBuildFile; fileRef = CC9EB1141F5C9D4000697511 /* Topological.scm */; };
148+
CCA3127D204CB74A0026FF13 /* RuntimeError.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCA3127C204CB74A0026FF13 /* RuntimeError.swift */; };
149+
CCA3127F204CB7900026FF13 /* LexicalError.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCA3127E204CB7900026FF13 /* LexicalError.swift */; };
150+
CCA31281204CB7A60026FF13 /* SyntaxError.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCA31280204CB7A60026FF13 /* SyntaxError.swift */; };
151+
CCA31283204CB7CB0026FF13 /* EvalError.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCA31282204CB7CB0026FF13 /* EvalError.swift */; };
148152
CCA752F41DEF9E410098C34A /* Prelude.scm in Copy default prelude */ = {isa = PBXBuildFile; fileRef = CCAD52D51C48467D00DBD8EE /* Prelude.scm */; };
149153
CCAD52BE1C48403900DBD8EE /* LispKit.h in Headers */ = {isa = PBXBuildFile; fileRef = CCAD52BD1C48403900DBD8EE /* LispKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
150154
CCAD52C51C48403900DBD8EE /* LispKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CCAD52BA1C48403800DBD8EE /* LispKit.framework */; };
151155
CCAD52CA1C48403900DBD8EE /* SmallTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCAD52C91C48403900DBD8EE /* SmallTests.swift */; };
152156
CCAD52E01C48468F00DBD8EE /* Env.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCAD52D81C48468F00DBD8EE /* Env.swift */; };
153-
CCAD52E11C48468F00DBD8EE /* Errors.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCAD52D91C48468F00DBD8EE /* Errors.swift */; };
154157
CCAD52E21C48468F00DBD8EE /* Expr.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCAD52DA1C48468F00DBD8EE /* Expr.swift */; };
155158
CCAD52E31C48468F00DBD8EE /* Parser.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCAD52DB1C48468F00DBD8EE /* Parser.swift */; };
156159
CCAD52E41C48468F00DBD8EE /* Scanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCAD52DC1C48468F00DBD8EE /* Scanner.swift */; };
@@ -521,6 +524,10 @@
521524
CC97FA151CFA51520008596E /* Definitions.scm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Definitions.scm; sourceTree = "<group>"; };
522525
CC98B4591EBD444400BCD049 /* NumberKit.framework.dSYM */ = {isa = PBXFileReference; lastKnownFileType = wrapper.dsym; name = NumberKit.framework.dSYM; path = Carthage/Build/Mac/NumberKit.framework.dSYM; sourceTree = "<group>"; };
523526
CC9EB1141F5C9D4000697511 /* Topological.scm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Topological.scm; sourceTree = "<group>"; };
527+
CCA3127C204CB74A0026FF13 /* RuntimeError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuntimeError.swift; sourceTree = "<group>"; };
528+
CCA3127E204CB7900026FF13 /* LexicalError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LexicalError.swift; sourceTree = "<group>"; };
529+
CCA31280204CB7A60026FF13 /* SyntaxError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SyntaxError.swift; sourceTree = "<group>"; };
530+
CCA31282204CB7CB0026FF13 /* EvalError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EvalError.swift; sourceTree = "<group>"; };
524531
CCAD52BA1C48403800DBD8EE /* LispKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LispKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
525532
CCAD52BD1C48403900DBD8EE /* LispKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LispKit.h; sourceTree = "<group>"; };
526533
CCAD52BF1C48403900DBD8EE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -529,7 +536,6 @@
529536
CCAD52CB1C48403900DBD8EE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
530537
CCAD52D51C48467D00DBD8EE /* Prelude.scm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Prelude.scm; sourceTree = "<group>"; };
531538
CCAD52D81C48468F00DBD8EE /* Env.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = Env.swift; sourceTree = "<group>"; tabWidth = 2; };
532-
CCAD52D91C48468F00DBD8EE /* Errors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Errors.swift; sourceTree = "<group>"; };
533539
CCAD52DA1C48468F00DBD8EE /* Expr.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Expr.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
534540
CCAD52DB1C48468F00DBD8EE /* Parser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Parser.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
535541
CCAD52DC1C48468F00DBD8EE /* Scanner.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Scanner.swift; sourceTree = "<group>"; };
@@ -892,8 +898,11 @@
892898
CCAD52D81C48468F00DBD8EE /* Env.swift */,
893899
CC35FD0E1C711FEA00C8B992 /* BindingGroup.swift */,
894900
CC01903A1C89D02200DB8BF9 /* CaptureGroup.swift */,
895-
CCAD52D91C48468F00DBD8EE /* Errors.swift */,
896901
CCD81AD11CE75823009EB087 /* Checkpointer.swift */,
902+
CCA3127C204CB74A0026FF13 /* RuntimeError.swift */,
903+
CCA3127E204CB7900026FF13 /* LexicalError.swift */,
904+
CCA31280204CB7A60026FF13 /* SyntaxError.swift */,
905+
CCA31282204CB7CB0026FF13 /* EvalError.swift */,
897906
);
898907
path = Compiler;
899908
sourceTree = "<group>";
@@ -1164,22 +1173,24 @@
11641173
CC3C92441D84C0D800016C28 /* Library.swift in Sources */,
11651174
CCAD52E61C48468F00DBD8EE /* SyntaxRules.swift in Sources */,
11661175
CCE4AECE204212EC008BF7E8 /* SourceManager.swift in Sources */,
1167-
CCAD52E11C48468F00DBD8EE /* Errors.swift in Sources */,
11681176
CCAD52E71C48468F00DBD8EE /* Type.swift in Sources */,
11691177
CC5A47231C529D4A00EFCF76 /* BaseLibrary.swift in Sources */,
11701178
CCB480E21FA93C2200220328 /* BinaryInputSource.swift in Sources */,
11711179
CC90500B1D36F52F008CE60A /* DynamicControlLibrary.swift in Sources */,
1180+
CCA3127F204CB7900026FF13 /* LexicalError.swift in Sources */,
11721181
CCC531A01D18595500FAED6E /* TextOutputTarget.swift in Sources */,
11731182
CC14F4B01F939486000FB1E0 /* Features.swift in Sources */,
11741183
CC5A47211C5295E600EFCF76 /* NativeLibrary.swift in Sources */,
11751184
CC6A3B621C52ED7D00E962E2 /* CharacterLibrary.swift in Sources */,
1185+
CCA31283204CB7CB0026FF13 /* EvalError.swift in Sources */,
11761186
CC4E2D371D09691000D77159 /* PortLibrary.swift in Sources */,
11771187
CC6A3B6C1C53EE3200E962E2 /* Promise.swift in Sources */,
11781188
CC9065B51C5557E4004A88B7 /* ObjectPool.swift in Sources */,
11791189
CC6AB0871C5C28FE008E9460 /* Equality.swift in Sources */,
11801190
CCAD52E01C48468F00DBD8EE /* Env.swift in Sources */,
11811191
CC6A3B6E1C53F0F600E962E2 /* Collection.swift in Sources */,
11821192
CC6A3B5E1C52E8EF00E962E2 /* VectorLibrary.swift in Sources */,
1193+
CCA3127D204CB74A0026FF13 /* RuntimeError.swift in Sources */,
11831194
CC8EDE701D07265E004E0636 /* TextInput.swift in Sources */,
11841195
CC2D124F1DB40E7F009BDC72 /* LibraryManager.swift in Sources */,
11851196
CCAD52E51C48468F00DBD8EE /* Symbol.swift in Sources */,
@@ -1210,6 +1221,7 @@
12101221
CC882C921C9E93A600D20039 /* Timer.swift in Sources */,
12111222
CCAD52E21C48468F00DBD8EE /* Expr.swift in Sources */,
12121223
CC35FD0D1C6FA4B700C8B992 /* VirtualMachine.swift in Sources */,
1224+
CCA31281204CB7A60026FF13 /* SyntaxError.swift in Sources */,
12131225
CC5BBC7B1D52724800367E8F /* HashTableLibrary.swift in Sources */,
12141226
CC93A65F1D077766008350C8 /* BinaryOutput.swift in Sources */,
12151227
CC0BA16C1DFC843C0063B9DE /* SystemLibrary.swift in Sources */,

Sources/LispKit/Compiler/Compiler.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public final class Compiler {
262262
self.emit(.pushGlobal(locRef.location!))
263263
}
264264
case .macroExpansionRequired(_):
265-
throw EvalError.illegalKeywordUsage(.symbol(sym))
265+
throw RuntimeError.eval(.illegalKeywordUsage, .symbol(sym))
266266
}
267267
}
268268

@@ -393,7 +393,7 @@ public final class Compiler {
393393
.port(_), .tagged(_, _), .error(_):
394394
self.pushConstant(expr)
395395
case .special(_):
396-
throw EvalError.illegalKeywordUsage(expr)
396+
throw RuntimeError.eval(.illegalKeywordUsage, expr)
397397
case .values(_):
398398
preconditionFailure("cannot push multiple values onto stack")
399399
}
@@ -648,7 +648,7 @@ public final class Compiler {
648648
next = cdr
649649
}
650650
guard next.isNull else {
651-
throw EvalError.typeError(expr, [.properListType])
651+
throw RuntimeError.type(expr, expected: [.properListType])
652652
}
653653
return n
654654
}
@@ -687,7 +687,7 @@ public final class Compiler {
687687
}
688688
// Throw error if the sequence is not a proper list
689689
guard next.isNull else {
690-
throw EvalError.typeError(expr, [.properListType])
690+
throw RuntimeError.type(expr, expected: [.properListType])
691691
}
692692
// Identify internal definitions
693693
var i = 0
@@ -777,13 +777,13 @@ public final class Compiler {
777777
var prevIndex = -1
778778
while case .pair(let binding, let rest) = bindings {
779779
guard case .pair(.symbol(let sym), .pair(let expr, .null)) = binding else {
780-
throw EvalError.malformedBindings(binding, bindingList)
780+
throw RuntimeError.eval(.malformedBinding, binding, bindingList)
781781
}
782782
try self.compile(expr, in: env, inTailPos: false)
783783
self.patchMakeClosure(sym)
784784
let binding = group.allocBindingFor(sym)
785785
guard binding.index > prevIndex else {
786-
throw EvalError.duplicateBinding(sym, bindingList)
786+
throw RuntimeError.eval(.duplicateBinding, .symbol(sym), bindingList)
787787
}
788788
if postset {
789789
definitions.append(binding)
@@ -798,7 +798,7 @@ public final class Compiler {
798798
bindings = rest
799799
}
800800
guard bindings.isNull else {
801-
throw EvalError.malformedBindings(nil, bindingList)
801+
throw RuntimeError.eval(.malformedBindings, bindingList)
802802
}
803803
for binding in definitions.reversed() {
804804
if binding.isValue {
@@ -822,7 +822,7 @@ public final class Compiler {
822822
var prevIndex = -1
823823
while case .pair(let binding, let rest) = bindings {
824824
guard case .pair(let variables, .pair(let expr, .null)) = binding else {
825-
throw EvalError.malformedBindings(binding, bindingList)
825+
throw RuntimeError.eval(.malformedBinding, binding, bindingList)
826826
}
827827
try self.compile(expr, in: env, inTailPos: false)
828828
var vars = variables
@@ -844,12 +844,12 @@ public final class Compiler {
844844
}
845845
prevIndex = binding.index
846846
default:
847-
throw EvalError.malformedBindings(binding, bindingList)
847+
throw RuntimeError.eval(.malformedBinding, binding, bindingList)
848848
}
849849
for sym in syms.reversed() {
850850
let binding = group.allocBindingFor(sym)
851851
guard binding.index > prevIndex else {
852-
throw EvalError.duplicateBinding(sym, bindingList)
852+
throw RuntimeError.eval(.duplicateBinding, .symbol(sym), bindingList)
853853
}
854854
if binding.isValue {
855855
self.emit(.setLocal(binding.index))
@@ -861,7 +861,7 @@ public final class Compiler {
861861
bindings = rest
862862
}
863863
guard bindings.isNull else {
864-
throw EvalError.malformedBindings(nil, bindingList)
864+
throw RuntimeError.eval(.malformedBindings, bindingList)
865865
}
866866
return group
867867
}
@@ -893,22 +893,22 @@ public final class Compiler {
893893
var bindings = bindingList
894894
while case .pair(let binding, let rest) = bindings {
895895
guard case .pair(.symbol(let sym), .pair(let transformer, .null)) = binding else {
896-
throw EvalError.malformedBindings(binding, bindingList)
896+
throw RuntimeError.eval(.malformedBinding, binding, bindingList)
897897
}
898898
let procExpr = try self.context.machine.compileAndEval(expr: transformer,
899899
in: env.syntacticalEnv,
900900
usingRulesEnv: env)
901901
guard case .procedure(let proc) = procExpr else {
902-
throw EvalError.malformedTransformer(transformer) //FIXME: Find better error message
902+
throw RuntimeError.eval(.malformedTransformer, transformer) //FIXME: Find better error message
903903
}
904904
guard group.bindingFor(sym) == nil else {
905-
throw EvalError.duplicateBinding(sym, bindingList)
905+
throw RuntimeError.eval(.duplicateBinding, .symbol(sym), bindingList)
906906
}
907907
group.defineMacro(sym, proc: proc)
908908
bindings = rest
909909
}
910910
guard bindings.isNull else {
911-
throw EvalError.malformedBindings(nil, bindingList)
911+
throw RuntimeError.eval(.malformedBindings, bindingList)
912912
}
913913
return group
914914
}
@@ -933,7 +933,7 @@ public final class Compiler {
933933
closureCompiler.emit(.collectRest(arguments.count))
934934
arguments.allocBindingFor(sym)
935935
default:
936-
throw EvalError.malformedArgumentList(arglist)
936+
throw RuntimeError.eval(.malformedArgumentList, arglist)
937937
}
938938
closureCompiler.arguments = arguments
939939
closureCompiler.env = .local(arguments)
@@ -990,7 +990,7 @@ public final class Compiler {
990990
closureCompiler.emit(.collectRest(arguments.count))
991991
arguments.allocBindingFor(sym)
992992
default:
993-
throw EvalError.malformedArgumentList(args)
993+
throw RuntimeError.eval(.malformedArgumentList, args)
994994
}
995995
closureCompiler.arguments = arguments
996996
closureCompiler.env = .local(arguments)
@@ -1016,7 +1016,7 @@ public final class Compiler {
10161016
case .null:
10171017
closureCompiler.emit(.noMatchingArgCount)
10181018
default:
1019-
throw EvalError.malformedCaseLambda(current)
1019+
throw RuntimeError.eval(.malformedCaseLambda, current)
10201020
}
10211021
// Link compiled closure in the current compiler
10221022
let codeIndex = self.fragments.count

0 commit comments

Comments
 (0)