Created
October 30, 2011 23:47
-
-
Save doublec/1326600 to your computer and use it in GitHub Desktop.
Structures and linear resources
This file contains hidden or 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
| %{^ | |
| typedef struct resource { | |
| void* data; | |
| int x; | |
| } resource; | |
| %} | |
| absviewtype data_vt (l:addr) | |
| extern fun data_vt_make (): [l:agz] (data_vt l ) = "mac#data_make" | |
| extern fun data_vt_free {l:addr} (r: data_vt l): void = "mac#data_free" | |
| viewtypedef resource = $extype_struct "resource" of { | |
| data= [l:addr] data_vt l, | |
| x= int | |
| } | |
| implement main () = { | |
| val d = data_vt_make() | |
| var !p_r with pf_r = @[resource?][1]() | |
| prval (pf_x, pf_xs) = array_v_uncons {resource?} (pf_r) | |
| val () = !p_r.data := d | |
| val () = !p_r.x := 0 | |
| prval () = array_v_unnil {resource?} (pf_xs) | |
| prval () = pf_xs := array_v_nil {resource} () | |
| prval () = pf_r := array_v_cons (pf_x, pf_xs) | |
| prval (pf_x, pf_xs) = array_v_uncons {resource} (pf_r) | |
| val () = data_vt_free(!p_r.data) | |
| prval () = array_v_unnil {resource} (pf_xs) | |
| prval () = pf_xs := array_v_nil {resource?} () | |
| prval () = pf_r := array_v_cons (pf_x, pf_xs) | |
| } | |
| (* atscc -tc test.dats *) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment