@@ -53,6 +53,7 @@ public enum Expr: Trackable, Hashable {
5353 case special( SpecialForm )
5454 case env( Environment )
5555 case port( Port )
56+ case object( Reference )
5657 indirect case tagged( Expr , Expr )
5758 case error( RuntimeError )
5859 indirect case syntax( SourcePosition , Expr )
@@ -114,8 +115,10 @@ public enum Expr: Trackable, Hashable {
114115 return . envType
115116 case . port( _) :
116117 return . portType
118+ case . object( _) :
119+ return . objectType
117120 case . tagged( _, _) :
118- return . taggedType
121+ return . taggedType
119122 case . error( _) :
120123 return . errorType
121124 case . syntax( _, _) :
@@ -292,7 +295,7 @@ public enum Expr: Trackable, Hashable {
292295 switch self {
293296 case . undef, . void, . eof, . null, . true , . false , . uninit( _) , . symbol( _) ,
294297 . fixnum( _) , . bignum( _) , . rational( _, _) , . flonum( _) , . complex( _) ,
295- . char( _) , . string( _) , . bytes( _) , . env( _) , . port( _) :
298+ . char( _) , . string( _) , . bytes( _) , . env( _) , . port( _) , . object ( _ ) :
296299 return true
297300 default :
298301 return false
@@ -633,6 +636,13 @@ extension Expr {
633636 }
634637 return port
635638 }
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+ }
636646}
637647
638648
@@ -901,6 +911,8 @@ extension Expr: CustomStringConvertible {
901911 return builder. description
902912 case . port( let port) :
903913 return " #< \( port. typeDescription) \( port. identDescription) > "
914+ case . object( let obj) :
915+ return " #< \( obj. typeDescription) \( obj. identityString) > "
904916 case . tagged( . mpair( let tuple) , let expr) :
905917 return " # \( stringReprOf ( tuple. fst) ) : \( stringReprOf ( expr) ) "
906918 case . tagged( let tag, let expr) :
@@ -934,13 +946,11 @@ extension Expr: CustomStringConvertible {
934946 }
935947 return res
936948 }
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+ }
941953}
942954
943955public typealias ByteVector = MutableBox < [ UInt8 ] >
944- public typealias FixedRational = ImmutableBox < Rational < Int64 > >
945- public typealias BigRational = ImmutableBox < Rational < BigInt > >
946956public typealias DoubleComplex = ImmutableBox < Complex < Double > >
0 commit comments