2323/// identity, a name, and a definition in the form of property `kind`. There are four kinds
2424/// of procedure definitions:
2525/// 1. Primitives: Built-in procedures
26- /// 2. Closures: User-defined procedures, e.g. via `lambda`
27- /// 3. Continuations: Continuations generated by `call-with-current-continuation`
28- /// 4 . Parameters: Parameter objects, which can be mutated for the duration of a
26+ /// 2. Closures: User-defined procedures, e.g. via `lambda`. Closure are either anonymous,
27+ /// they are named, or they are continuations
28+ /// 3 . Parameters: Parameter objects, which can be mutated for the duration of a
2929/// dynamic extent
30- /// 5. Transformers: User-defined macro transformers defined via `syntax-rules`
30+ /// 4. Transformers: User-defined macro transformers defined via `syntax-rules`
31+ /// 5. Raw continuations: Continuations generated by `call-with-current-continuation`
32+ /// are modeled as closures of closure type `continuation`. Internally, they use
33+ /// raw continuations for encapsulating the state of a virtual machine.
3134///
3235public final class Procedure : Reference , CustomStringConvertible {
3336
3437 /// There are four kinds of procedures:
3538 /// 1. Primitives: Built-in procedures
3639 /// 2. Closures: User-defined procedures, e.g. via `lambda`
37- /// 3. Continuations: Continuations generated by `call-with-current-continuation`
38- /// 4. Parameters: Parameter objects, which can be mutated for the duration of a
40+ /// 3. Parameters: Parameter objects, which can be mutated for the duration of a
3941 /// dynamic extent
40- /// 5. Transformers: User-defined macro transformers defined via `syntax-rules`
42+ /// 4. Transformers: User-defined macro transformers defined via `syntax-rules`
43+ /// 5. Raw continuations: Continuations generated by `call-with-current-continuation`
44+ /// are modeled as closures of closure type `continuation`. Internally, they use
45+ /// raw continuations for encapsulating the state of a virtual machine.
4146 public enum Kind {
4247 case primitive( String , Implementation , FormCompiler ? )
43- case closure( String ? , Exprs , Code )
44- case continuation( VirtualMachineState )
48+ case closure( ClosureType , Exprs , Code )
4549 case parameter( Tuple )
4650 case transformer( SyntaxRules )
51+ case rawContinuation( VirtualMachineState )
52+ }
53+
54+ /// There are three types of closures:
55+ /// 1. Anonymous closures: closures that are not named
56+ /// 2. Named closures: Closures that are given a name
57+ /// 3. Continuations: These are unnamed closures generated by `call-with-current-continuation`
58+ public enum ClosureType {
59+ case anonymous
60+ case named( String )
61+ case continuation
4762 }
4863
4964 /// There are three different types of primitive implementations:
@@ -219,13 +234,13 @@ public final class Procedure: Reference, CustomStringConvertible {
219234 }
220235
221236 /// Initializer for closures
222- public init ( _ name : String ? , _ captured: Exprs , _ code: Code ) {
223- self . kind = . closure( name , captured, code)
237+ public init ( _ type : ClosureType , _ captured: Exprs , _ code: Code ) {
238+ self . kind = . closure( type , captured, code)
224239 }
225240
226241 /// Initializer for closures
227242 public init ( _ code: Code ) {
228- self . kind = . closure( nil , [ ] , code)
243+ self . kind = . closure( . anonymous , [ ] , code)
229244 }
230245
231246 /// Initializer for parameters
@@ -240,7 +255,7 @@ public final class Procedure: Reference, CustomStringConvertible {
240255
241256 /// Initializer for continuations
242257 public init ( _ vmState: VirtualMachineState ) {
243- self . kind = . continuation ( vmState)
258+ self . kind = . rawContinuation ( vmState)
244259 }
245260
246261 /// Initializer for transformers
@@ -254,7 +269,7 @@ public final class Procedure: Reference, CustomStringConvertible {
254269 switch self . kind {
255270 case . primitive( let str, _, _) :
256271 return str
257- case . closure( . some ( let str) , _, _) :
272+ case . closure( . named ( let str) , _, _) :
258273 return " \( str) @ \( self . identityString) "
259274 default :
260275 return self . identityString
@@ -266,7 +281,7 @@ public final class Procedure: Reference, CustomStringConvertible {
266281 switch self . kind {
267282 case . primitive( let str, _, _) :
268283 return str
269- case . closure( . some ( let str) , _, _) :
284+ case . closure( . named ( let str) , _, _) :
270285 return str
271286 default :
272287 return nil
@@ -282,7 +297,7 @@ public final class Procedure: Reference, CustomStringConvertible {
282297 code. mark ( tag)
283298 case . parameter( let tuple) :
284299 tuple. mark ( tag)
285- case . continuation ( let state) :
300+ case . rawContinuation ( let state) :
286301 state. mark ( tag)
287302 default :
288303 break
0 commit comments