116116use crate :: {
117117 align:: MAX_ALIGN ,
118118 interner:: { InternedIdentifier , InternedModuleId } ,
119- types:: { display_type_list, InternedTypeList } ,
119+ types:: { display_type , display_type_list, InternedType , InternedTypeList } ,
120120 FunctionPtr ,
121121} ;
122122use std:: fmt;
@@ -796,6 +796,57 @@ pub enum MicroOp {
796796 /// Unconditionally trigger a garbage collection cycle.
797797 /// Useful for testing GC correctness.
798798 ForceGC ,
799+
800+ /// Stores a boolean value at destination offset if resource of the given
801+ /// type exists at the given address.
802+ Exists {
803+ addr : FrameOffset ,
804+ ty : InternedType ,
805+ dst : FrameOffset ,
806+ } ,
807+ /// Stores a reference to the destination offset pointing to the resource
808+ /// of the given type exists at the given address. Aborts if resource does
809+ /// not exist.
810+ BorrowGlobal {
811+ addr : FrameOffset ,
812+ ty : InternedType ,
813+ dst : FrameOffset ,
814+ } ,
815+ /// Stores a reference to the destination offset pointing to the resource
816+ /// of the given type exists at the given address. The reference points to
817+ /// the object owned by the current transaction's heap. Aborts if resource
818+ /// does not exist.
819+ ///
820+ /// May trigger GC.
821+ BorrowGlobalMut {
822+ addr : FrameOffset ,
823+ ty : InternedType ,
824+ dst : FrameOffset ,
825+ } ,
826+ /// Stores a reference to the destination offset pointing to the resource
827+ /// of the given type exists at the given address. The resource is then
828+ /// treated as "moved" from the global storage. The reference points to
829+ /// the object owned by the current transaction's heap. Aborts if resource
830+ /// does not exist.
831+ ///
832+ /// May trigger GC.
833+ MoveFrom {
834+ addr : FrameOffset ,
835+ ty : InternedType ,
836+ dst : FrameOffset ,
837+ } ,
838+ /// Stores a reference from the source offset to the global storage for the
839+ /// resource of the given type at the given address. The resource is then
840+ /// treated as "moved" to the global storage. Aborts if resource already
841+ /// exists.
842+ MoveTo {
843+ // TODO(correctness):
844+ // Move requires this to be a signer, using address for simplicity for now.
845+ addr : FrameOffset ,
846+ ty : InternedType ,
847+ src : FrameOffset ,
848+ } ,
849+
799850 //======================================================================
800851 // Missing instructions
801852 //======================================================================
@@ -804,7 +855,6 @@ pub enum MicroOp {
804855 // - **Casting**: truncation and widening between integer types,
805856 // including signed casts.
806857 // - **Boolean**: logical Not, And, Or (distinct from bitwise).
807- // - **Global storage**: MoveTo, MoveFrom, BorrowGlobal, Exists.
808858 // - **Runtime instrumentation**: tracing, profiling, coverage hooks.
809859 //======================================================================
810860
@@ -1189,6 +1239,35 @@ impl fmt::Display for MicroOp {
11891239 }
11901240 write ! ( f, "]" )
11911241 } ,
1242+ MicroOp :: Exists { addr, ty, dst } => {
1243+ write ! ( f, "Exists<" ) ?;
1244+ display_type ( f, * ty) ?;
1245+ write ! ( f, "> [{}] <- addr=[{}], ty=" , dst. 0 , addr. 0 )
1246+ } ,
1247+ MicroOp :: BorrowGlobal { addr, ty, dst } => {
1248+ write ! ( f, "BorrowGlobal<" ) ?;
1249+ display_type ( f, * ty) ?;
1250+ write ! ( f, "> [{}] <- addr=[{}], ty=" , dst. 0 , addr. 0 )
1251+ } ,
1252+ MicroOp :: BorrowGlobalMut { addr, ty, dst } => {
1253+ write ! ( f, "BorrowGlobalMut<" ) ?;
1254+ display_type ( f, * ty) ?;
1255+ write ! ( f, "> [{}] <- addr=[{}], ty=" , dst. 0 , addr. 0 )
1256+ } ,
1257+ MicroOp :: MoveFrom { addr, ty, dst } => {
1258+ write ! ( f, "MoveFrom<" ) ?;
1259+ display_type ( f, * ty) ?;
1260+ write ! ( f, "> [{}] <- addr=[{}], ty=" , dst. 0 , addr. 0 )
1261+ } ,
1262+ MicroOp :: MoveTo {
1263+ addr,
1264+ ty,
1265+ src,
1266+ } => {
1267+ write ! ( f, "MoveTo<" ) ?;
1268+ display_type ( f, * ty) ?;
1269+ write ! ( f, "> addr=[{}], src=[{}]" , addr. 0 , src. 0 )
1270+ } ,
11921271 }
11931272 }
11941273}
@@ -1308,6 +1387,8 @@ impl MicroOp {
13081387 MicroOp :: HeapNew { .. }
13091388 | MicroOp :: VecPushBack { .. }
13101389 | MicroOp :: PackClosure ( _)
1390+ | MicroOp :: BorrowGlobalMut { .. }
1391+ | MicroOp :: MoveFrom { .. }
13111392 | MicroOp :: ForceGC => true ,
13121393
13131394 // Non-allocating.
@@ -1372,7 +1453,10 @@ impl MicroOp {
13721453 | MicroOp :: IntBitXor ( _)
13731454 | MicroOp :: IntShl ( _)
13741455 | MicroOp :: IntShr ( _)
1375- | MicroOp :: IntNegate ( _) => false ,
1456+ | MicroOp :: IntNegate ( _)
1457+ | MicroOp :: Exists { .. }
1458+ | MicroOp :: BorrowGlobal { .. }
1459+ | MicroOp :: MoveTo { .. } => false ,
13761460 }
13771461 }
13781462
0 commit comments