Skip to content

Commit

Permalink
Update Chapter20Test.java
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffclick committed Feb 16, 2025
1 parent c175e76 commit 92094eb
Showing 1 changed file with 36 additions and 41 deletions.
77 changes: 36 additions & 41 deletions chapter20/src/test/java/com/seaofnodes/simple/Chapter20Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,48 +71,44 @@ public void testArray1() {

@Test
public void testArray2() {
CodeGen code = new CodeGen(
"""
struct String {
u8[] cs;
int _hashCode;
};
val equals = { String self, String s ->
if( self == s ) return true;
if( self.cs# != s.cs# ) return false;
for( int i=0; i< self.cs#; i++ )
if( self.cs[i] != s.cs[i] )
return false;
return true;
};
val hashCode = { String self ->
self._hashCode
? self._hashCode
: (self._hashCode = _hashCodeString(self));
};
val _hashCodeString = { String self ->
int hash=0;
if( self.cs ) {
for( int i=0; i< self.cs#; i++ )
hash = hash*31 + self.cs[i];
}
if( !hash ) hash = 123456789;
return hash;
};
String !s = new String { cs = new u8[17]; };
s.cs[0] = 67; // C
s.cs[1] = 108; // l
hashCode(s);"""
);
CodeGen code = new CodeGen("""
struct String {
u8[] cs;
int _hashCode;
};
val equals = { String self, String s ->
if( self == s ) return true;
if( self.cs# != s.cs# ) return false;
for( int i=0; i< self.cs#; i++ )
if( self.cs[i] != s.cs[i] )
return false;
return true;
};
val hashCode = { String self ->
self._hashCode
? self._hashCode
: (self._hashCode = _hashCodeString(self));
};
val _hashCodeString = { String self ->
int hash=0;
if( self.cs ) {
for( int i=0; i< self.cs#; i++ )
hash = hash*31 + self.cs[i];
}
if( !hash ) hash = 123456789;
return hash;
};
String !s = new String { cs = new u8[17]; };
s.cs[0] = 67; // C
s.cs[1] = 108; // l
hashCode(s);
""");
code.parse().opto().typeCheck().instSelect("x86_64_v2", "SystemV").GCM().localSched();
assertEquals("Stop[ return Phi(Region,123456789,Phi(Loop,0,.[])); return Phi(Region,1,0,0,1); ]", code.print());
SB sb = new SB();
ASMPrinter.print(sb, code);
System.out.print(sb);
}

@Test
Expand All @@ -126,7 +122,6 @@ public void testCast() {
);
code.parse().opto().typeCheck().instSelect("x86_64_v2", "SystemV").GCM().localSched();
assertEquals("return Phi(Region,(lea, ---,.x),-1);", code.print());
code.print();
}

}

0 comments on commit 92094eb

Please sign in to comment.