comparison file.rhope @ 80:d78613686a38

Some progress on File
author Mike Pavone <pavone@retrodev.com>
date Wed, 21 Jul 2010 00:45:13 -0400
parents 80d8c9248f85
children dbe95bfec970
comparison
equal deleted inserted replaced
79:80d8c9248f85 80:d78613686a38
1 1
2 //This implementation will change quite a bit once the transaction system is working
3 //and I've finalized how File I/O will fit into that. This is just a very basic
4 //implementation to allow the compiler to be self-hosting.
5
6 Foreign C:libc
7 {
8 open[name(Array,Raw Pointer),flags(Int32,Naked):filedes(Int32,Naked)]
9 close[filedes(Int32,Naked):status(Int32,Naked)]
10 fsync[filedes(Int32,Naked):status(Int32,Naked)]
11 fstat[filedes(Int32,Naked),buf(Stat,Raw Pointer):err(Int32,Naked),buf]
12 }
2 13
3 Blueprint Stat 14 Blueprint Stat
4 { 15 {
5 16 Device(UInt64,Naked)
17 Inode(UInt64,Naked)
18 Link Count(UInt64,Naked)
19 Mode(UInt32,Naked)
20 Owner ID(UInt32,Naked)
21 Group ID(UInt32,Naked)
22 Pad0(Int32,Naked)
23 RDevice(UInt64,Naked)
24 Size(Int64,Naked)
25 Block Size(Int64,Naked)
26 Block Count(Int64,Naked)
27 Access Time(Int64,Naked)
28 Access Time Nano(UInt64,Naked)
29 Mod Time(Int64,Naked)
30 Mod Time Nano(UInt64,Naked)
31 Status Time(Int64,Naked)
32 Status Time Nano(UInt64,Naked)
33 Unused1(Int64,Naked)
34 Unused2(Int64,Naked)
35 Unused3(Int64,Naked)
36 }
37
38 Stat[fd:out]
39 {
40 err,out <- fstat[fd, Build[Stat()]]
6 } 41 }
7 42
8 Blueprint File 43 Blueprint File
9 { 44 {
10 Name 45 Name
13 Blueprint File Read 48 Blueprint File Read
14 { 49 {
15 Name 50 Name
16 Descriptor(Int32,Naked) 51 Descriptor(Int32,Naked)
17 Info 52 Info
18 Buffer
19 } 53 }
20 54
21 Blueprint File Write 55 Blueprint File Write
22 { 56 {
23 Name 57 Name
24 Descriptor(Int32,Naked) 58 Descriptor(Int32,Naked)
25 Info 59 Info
26 Buffer
27 } 60 }
28 61
29 Blueprint File ReadWrite 62 Blueprint File ReadWrite
30 { 63 {
31 Name 64 Name
32 Read Offset(Int64,Naked) 65 Read Offset(Int64,Naked)
33 Descriptor(Int32,Naked) 66 Descriptor(Int32,Naked)
34 Info 67 Info
35 Buffer
36 } 68 }
37 69
38 File[name:out] 70 File[name:out]
39 { 71 {
40 out <- [Build[File()]]Name <<[name] 72 out <- [Build[File()]]Name <<[name]
43 75
44 Open@File[file,mode:out,error] 76 Open@File[file,mode:out,error]
45 { 77 {
46 If[[mode]=["r"]] 78 If[[mode]=["r"]]
47 { 79 {
48 imode <- 80 imode <- 0i32
49 type <- File Read() 81 type <- File Read()
50 out <- Val[ofile] 82 out <- Val[ofile]
51 }{ 83 }{
52 If[[mode]=["w"]] 84 If[[mode]=["w"]]
53 { 85 {
54 imode <- 86 imode <- 65i32
55 type <- File Write() 87 type <- File Write()
56 out <- Val[ofile] 88 out <- Val[ofile]
57 }{ 89 }{
58 ,error <- If[[mode]=["rw"]] 90 ,error <- If[[mode]=["rw"]]
59 { 91 {
60 imode <- 92 imode <- 66i32
61 type <- File ReadWrite() 93 type <- File ReadWrite()
62 out <- [ofile]Read Offset <<[0i64] 94 out <- [ofile]Read Offset <<[0i64]
63 } 95 }
64 } 96 }
65 } 97 }
66 fd <- open[[file]Name >>] 98 fd <- open[[file]Name >>]
67 error <- If[[fd]=[-1i32]] {} 99 error <- If[[fd]=[-1i32]] {}
68 { 100 {
69 ofile <- [[[[Build[type] 101 ofile <- [[[Build[type]
70 ]Name <<[ [file]Name >> ] 102 ]Name <<[ [file]Name >> ]
71 ]Descriptor <<[fd] 103 ]Descriptor <<[fd]
72 ]Info <<[Stat[fd]] 104 ]Info <<[Stat[fd]]
73 ]Buffer <<[Array[]]
74 } 105 }
75 } 106 }
76 107
77 Read@File[file,bytes:data,outfile,error] 108 Read@File[file,bytes:data,outfile,error]
78 { 109 {
79 ,error <- [file]Open["r"] 110 ,error <- [file]Open["r"]
80 { 111 {
81 data,outfile,error <- [~]Read[bytes] 112 data,outfile,error <- [~]Read[bytes]
82 } 113 }
83 } 114 }
84 115 /*
85 Append@File[file,data:out,error] 116 Append@File[file,data:out,error]
86 { 117 {
87 ,error <- [file]Open["w"] 118 ,error <- [file]Open["w"]
88 { 119 {
89 out,error <- [~]Append[data] 120 out,error <- [~]Append[data]
90 } 121 }
91 } 122 }*/
92 123
93 String@File[file:out,error] 124 String@File[file:out,error]
94 { 125 {
95 ,error <- [file]Open["w"] 126 ,error <- [file]Open["w"]
96 { 127 {
98 } 129 }
99 } 130 }
100 131
101 Read@File Read[file,inbytes(Int32):data,outfile,error] 132 Read@File Read[file,inbytes(Int32):data,outfile,error]
102 { 133 {
134 readbytes, mdata <- read[[file]Descriptor >>, [Array[]]Set[inbytes, 0u8], Int64[inbytes]]
135 error <- If[[readbytes]<[0i64]] {}
136 {
137 outfile <- file
138 data <- [mdata]Length <<[ Trunc Int32[readbytes] ]
139 }
140 /*
141 //Skip buffering for now. Buffering approach may need to change later anyway
103 buflen <- [[file]Buffer >>]Length 142 buflen <- [[file]Buffer >>]Length
104 If[buflen] 143 If[buflen]
105 { 144 {
106 If[[inbytes]=[buflen]] 145 If[[inbytes]=[buflen]]
107 { 146 {
120 error <- If[[readbytes]<[0i64]] {} 159 error <- If[[readbytes]<[0i64]] {}
121 { 160 {
122 outfile <- file 161 outfile <- file
123 data <- [mdata]Length <<[ Trunc Int32[readbytes] ] 162 data <- [mdata]Length <<[ Trunc Int32[readbytes] ]
124 } 163 }
125 164 } */
126 }
127 } 165 }
128 166
167 Length@File Read[file:out]
168 {
169 out <- Trunc Int32[[[file]Info >>]Size >>]
170 }
171
172 Close@File Read[file:out]
173 {
174 close[[file]Descriptor >>]
175 out <- File[[file]Name >>]
176 }
177
178