@@ -53,6 +53,7 @@ public enum Expr: Trackable, Hashable {
53
53
case special( SpecialForm )
54
54
case env( Environment )
55
55
case port( Port )
56
+ case object( Reference )
56
57
indirect case tagged( Expr , Expr )
57
58
case error( RuntimeError )
58
59
indirect case syntax( SourcePosition , Expr )
@@ -114,8 +115,10 @@ public enum Expr: Trackable, Hashable {
114
115
return . envType
115
116
case . port( _) :
116
117
return . portType
118
+ case . object( _) :
119
+ return . objectType
117
120
case . tagged( _, _) :
118
- return . taggedType
121
+ return . taggedType
119
122
case . error( _) :
120
123
return . errorType
121
124
case . syntax( _, _) :
@@ -292,7 +295,7 @@ public enum Expr: Trackable, Hashable {
292
295
switch self {
293
296
case . undef, . void, . eof, . null, . true , . false , . uninit( _) , . symbol( _) ,
294
297
. fixnum( _) , . bignum( _) , . rational( _, _) , . flonum( _) , . complex( _) ,
295
- . char( _) , . string( _) , . bytes( _) , . env( _) , . port( _) :
298
+ . char( _) , . string( _) , . bytes( _) , . env( _) , . port( _) , . object ( _ ) :
296
299
return true
297
300
default :
298
301
return false
@@ -633,6 +636,13 @@ extension Expr {
633
636
}
634
637
return port
635
638
}
639
+
640
+ @inline ( __always) public func asObject( ) throws -> Reference {
641
+ guard case . object( let obj) = self else {
642
+ throw RuntimeError . type ( self , expected: [ . objectType] )
643
+ }
644
+ return obj
645
+ }
636
646
}
637
647
638
648
@@ -901,6 +911,8 @@ extension Expr: CustomStringConvertible {
901
911
return builder. description
902
912
case . port( let port) :
903
913
return " #< \( port. typeDescription) \( port. identDescription) > "
914
+ case . object( let obj) :
915
+ return " #< \( obj. typeDescription) \( obj. identityString) > "
904
916
case . tagged( . mpair( let tuple) , let expr) :
905
917
return " # \( stringReprOf ( tuple. fst) ) : \( stringReprOf ( expr) ) "
906
918
case . tagged( let tag, let expr) :
@@ -934,13 +946,11 @@ extension Expr: CustomStringConvertible {
934
946
}
935
947
return res
936
948
}
937
- }
938
-
939
- public func == ( lhs : Expr , rhs: Expr ) -> Bool {
940
- return equalExpr ( rhs , lhs )
949
+
950
+ public static func == ( lhs : Expr , rhs : Expr ) -> Bool {
951
+ return equalExpr ( rhs, lhs )
952
+ }
941
953
}
942
954
943
955
public typealias ByteVector = MutableBox < [ UInt8 ] >
944
- public typealias FixedRational = ImmutableBox < Rational < Int64 > >
945
- public typealias BigRational = ImmutableBox < Rational < BigInt > >
946
956
public typealias DoubleComplex = ImmutableBox < Complex < Double > >
0 commit comments