-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #250 from FStarLang/afromher_steel
Native extraction of Steel loops
- Loading branch information
Showing
3 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module SteelLoops | ||
|
||
open Steel.Effect.Atomic | ||
open Steel.Effect | ||
open Steel.Reference | ||
open Steel.Loops | ||
|
||
let sum_to_n_for (r:ref UInt32.t) : SteelT unit (vptr r) (fun _ -> vptr r) = | ||
for_loop | ||
0ul | ||
10ul | ||
(fun _ -> vptr r) | ||
(fun _ -> let x = read r in write r (x `FStar.UInt32.add_mod` 1ul)) | ||
|
||
let sum_to_n_while (r:ref UInt32.t) : SteelT unit (vptr r) (fun _ -> vptr r) = | ||
intro_exists (Ghost.hide true) (fun _ -> vptr r); | ||
while_loop | ||
(fun _ -> vptr r) | ||
(fun _ -> | ||
let _ = witness_exists () in | ||
let n = read r in | ||
FStar.UInt32.lt n 10ul | ||
) | ||
(fun _ -> | ||
let n = read r in | ||
write r (n `FStar.UInt32.add_mod` 1ul); | ||
intro_exists (Ghost.hide true) (fun _ -> vptr r) | ||
) | ||
|
||
let main () : SteelT Int32.t emp (fun _ -> emp) = | ||
let r = malloc 0ul in | ||
sum_to_n_for r; | ||
sum_to_n_while r; | ||
free r; | ||
return 0l |