Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ Although the primary focus of this repo is F# for Windows and the Visual Studio
###Get In Touch

Keep up with the Visual F# Team and the development of the Visual F# Tools by following us [@VisualFSharp](https://twitter.com/VisualFSharp) or subscribing to our [team blog](http://blogs.msdn.com/b/fsharpteam/).

51 changes: 23 additions & 28 deletions src/absil/il.fs
Original file line number Diff line number Diff line change
Expand Up @@ -215,22 +215,18 @@ module SHA1 =
else k60to79


type chan = SHABytes of byte[]
type sha_instream =
{ stream: chan;
type SHAStream =
{ stream: byte[];
mutable pos: int;
mutable eof: bool; }

let rot_left32 x n = (x <<< n) ||| (x >>>& (32-n))
let rotLeft32 x n = (x <<< n) ||| (x >>>& (32-n))

let inline sha_eof sha = sha.eof

(* padding and length (in bits!) recorded at end *)
let sha_after_eof sha =

// padding and length (in bits!) recorded at end
let shaAfterEof sha =
let n = sha.pos
let len =
(match sha.stream with
| SHABytes s -> s.Length)
let len = sha.stream.Length
if n = len then 0x80
else
let padded_len = (((len + 9 + 63) / 64) * 64) - 8
Expand All @@ -245,22 +241,21 @@ module SHA1 =
elif (n &&& 63) = 63 then (sha.eof <- true; int32 (int64 len * int64 8) &&& 0xff)
else 0x0

let sha_read8 sha =
let b =
match sha.stream with
| SHABytes s -> if sha.pos >= s.Length then sha_after_eof sha else int32 s.[sha.pos]
sha.pos <- sha.pos + 1;
let shaRead8 sha =
let s = sha.stream
let b = if sha.pos >= s.Length then shaAfterEof sha else int32 s.[sha.pos]
sha.pos <- sha.pos + 1
b

let sha_read32 sha =
let b0 = sha_read8 sha
let b1 = sha_read8 sha
let b2 = sha_read8 sha
let b3 = sha_read8 sha
let shaRead32 sha =
let b0 = shaRead8 sha
let b1 = shaRead8 sha
let b2 = shaRead8 sha
let b3 = shaRead8 sha
let res = (b0 <<< 24) ||| (b1 <<< 16) ||| (b2 <<< 8) ||| b3
res

let sha1_hash sha =
let sha1Hash sha =
let mutable h0 = 0x67452301
let mutable h1 = 0xEFCDAB89
let mutable h2 = 0x98BADCFE
Expand All @@ -272,21 +267,21 @@ module SHA1 =
let mutable d = 0
let mutable e = 0
let w = Array.create 80 0x00
while (not (sha_eof sha)) do
while (not sha.eof) do
for i = 0 to 15 do
w.[i] <- sha_read32 sha
w.[i] <- shaRead32 sha
for t = 16 to 79 do
w.[t] <- rot_left32 (w.[t-3] ^^^ w.[t-8] ^^^ w.[t-14] ^^^ w.[t-16]) 1
w.[t] <- rotLeft32 (w.[t-3] ^^^ w.[t-8] ^^^ w.[t-14] ^^^ w.[t-16]) 1
a <- h0
b <- h1
c <- h2
d <- h3
e <- h4
for t = 0 to 79 do
let temp = (rot_left32 a 5) + f(t,b,c,d) + e + w.[t] + k(t)
let temp = (rotLeft32 a 5) + f(t,b,c,d) + e + w.[t] + k(t)
e <- d
d <- c
c <- rot_left32 b 30
c <- rotLeft32 b 30
b <- a
a <- temp
h0 <- h0 + a
Expand All @@ -297,7 +292,7 @@ module SHA1 =
h0,h1,h2,h3,h4

let sha1HashBytes s =
let (_h0,_h1,_h2,h3,h4) = sha1_hash { stream = SHABytes s; pos = 0; eof = false } // the result of the SHA algorithm is stored in registers 3 and 4
let (_h0,_h1,_h2,h3,h4) = sha1Hash { stream = s; pos = 0; eof = false } // the result of the SHA algorithm is stored in registers 3 and 4
Array.map byte [| b0 h4; b1 h4; b2 h4; b3 h4; b0 h3; b1 h3; b2 h3; b3 h3; |]


Expand Down
2 changes: 1 addition & 1 deletion src/absil/ilascii.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ open Microsoft.FSharp.Compiler.AbstractIL.Diagnostics
open Microsoft.FSharp.Compiler.AbstractIL.Extensions.ILX.Types
open Microsoft.FSharp.Compiler.AbstractIL.IL

// set to the proper value at build.fs (BuildFrameworkTcImports)
// set to the proper value at CompileOps.fs (BuildFrameworkTcImports)
let parseILGlobals = ref EcmaILGlobals

// --------------------------------------------------------------------
Expand Down
23 changes: 23 additions & 0 deletions src/absil/illib.fs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ module Dictionary =

// FUTURE CLEANUP: remove this adhoc collection
type Hashset<'T> = Dictionary<'T,int>

[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module Hashset =
let create (n:int) = new Hashset<'T>(n, HashIdentity.Structural)
Expand Down Expand Up @@ -498,6 +499,28 @@ type ResultOrException<'TResult> =
| Result of 'TResult
| Exception of System.Exception

[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module ResultOrException =

let success a = Result a
let raze (b:exn) = Exception b

// map
let (|?>) res f =
match res with
| Result x -> Result(f x )
| Exception err -> Exception err

let ForceRaise res =
match res with
| Result x -> x
| Exception err -> raise err

let otherwise f x =
match x with
| Result x -> success x
| Exception _err -> f()


//-------------------------------------------------------------------------
// Library: extensions to flat list (immutable arrays)
Expand Down
Loading