Skip to content

Commit

Permalink
Merge pull request #1391 from hylo-lang/int64
Browse files Browse the repository at this point in the history
Implement `Int64` and `UInt64`
  • Loading branch information
kyouko-taiga authored Mar 22, 2024
2 parents bcd26ad + 503e577 commit 349ac56
Show file tree
Hide file tree
Showing 6 changed files with 679 additions and 10 deletions.
8 changes: 6 additions & 2 deletions Sources/IR/Emitter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1777,16 +1777,20 @@ struct Emitter {
switch literalType {
case ast.coreType("Int")!:
emitStore(integer: literal, signed: true, bitWidth: 64, to: storage)
case ast.coreType("Int32")!:
emitStore(integer: literal, signed: true, bitWidth: 32, to: storage)
case ast.coreType("Int8")!:
emitStore(integer: literal, signed: true, bitWidth: 8, to: storage)
case ast.coreType("Int32")!:
emitStore(integer: literal, signed: true, bitWidth: 32, to: storage)
case ast.coreType("Int64")!:
emitStore(integer: literal, signed: true, bitWidth: 64, to: storage)
case ast.coreType("UInt")!:
emitStore(integer: literal, signed: false, bitWidth: 64, to: storage)
case ast.coreType("UInt8")!:
emitStore(integer: literal, signed: false, bitWidth: 8, to: storage)
case ast.coreType("UInt32")!:
emitStore(integer: literal, signed: false, bitWidth: 32, to: storage)
case ast.coreType("UInt64")!:
emitStore(integer: literal, signed: false, bitWidth: 64, to: storage)
case ast.coreType("Float64")!:
emitStore(floatingPoint: literal, to: storage, evaluatedBy: FloatingPointConstant.float64(_:))
case ast.coreType("Float32")!:
Expand Down
14 changes: 14 additions & 0 deletions StandardLibrary/Sources/Core/Hasher.hylo
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ public type Hasher {
&hash = hash &* FNV.prime
}

/// Adds `i32` to the hash value computed by `self`.
public fun combine(i32: Int32) inout {
&combine(byte: Int8(truncating_or_extending: i32))
&combine(byte: Int8(truncating_or_extending: i32 >> 8))
&combine(byte: Int8(truncating_or_extending: i32 >> 16))
&combine(byte: Int8(truncating_or_extending: i32 >> 24))
}

/// Adds `i64` to the hash value computed by `self`.
public fun combine(i64: Int64) inout {
&combine(i32: Int32(truncating_or_extending: i64))
&combine(i32: Int32(truncating_or_extending: i64 >> 32))
}

/// Adds `bytes` to the hash value computed by `self`.
public fun unsafe_combine(bytes: PointerToBuffer<Int8>) inout {
var i = 0
Expand Down
5 changes: 1 addition & 4 deletions StandardLibrary/Sources/Core/Numbers/Integers/Int32.hylo
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ public conformance Int32: Equatable {
public conformance Int32: Hashable {

public fun hash(into hasher: inout Hasher) {
&hasher.combine(byte: Int8(truncating_or_extending: self))
&hasher.combine(byte: Int8(truncating_or_extending: self >> 8))
&hasher.combine(byte: Int8(truncating_or_extending: self >> 16))
&hasher.combine(byte: Int8(truncating_or_extending: self >> 24))
&hasher.combine(i32: self)
}

}
Expand Down
Loading

0 comments on commit 349ac56

Please sign in to comment.