Mercurial > repos > rhope
comparison kernel.rhope @ 92:e73a93fb5de1
Beginning of port of compiler to itself, some bugfixes and a refcount optimization
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 02 Aug 2010 00:58:55 -0400 |
parents | 27bb051d631c |
children | 5a08705f7610 |
comparison
equal
deleted
inserted
replaced
91:bcdc326b3d6e | 92:e73a93fb5de1 |
---|---|
1 Import string.rhope | 1 Import string.rhope |
2 Import list.rhope | 2 Import list.rhope |
3 Import functional.rhope | 3 Import functional.rhope |
4 Import file.rhope | 4 Import file.rhope |
5 Import dict.rhope | 5 Import dict.rhope |
6 Import range.rhope | |
6 | 7 |
7 Val[in:out] | 8 Val[in:out] |
8 { | 9 { |
9 out <- in | 10 out <- in |
10 } | 11 } |
44 { | 45 { |
45 write[filedes(Int32,Naked),buf(Array,Raw Pointer),nbyte(Int64,Naked):written(Int32,Naked)] | 46 write[filedes(Int32,Naked),buf(Array,Raw Pointer),nbyte(Int64,Naked):written(Int32,Naked)] |
46 read[filedes(Int32,Naked),buf(Array,Raw Pointer,Mutable),nbyte(Int64,Naked):read(Int64,Naked),buf] | 47 read[filedes(Int32,Naked),buf(Array,Raw Pointer,Mutable),nbyte(Int64,Naked):read(Int64,Naked),buf] |
47 } | 48 } |
48 | 49 |
49 _Print Int32[n,buf:out] | 50 _String 32[n,buf:out] |
50 { | 51 { |
51 If[[n] < [10i32]] | 52 If[[n] < [10u32]] |
52 { | 53 { |
53 byte <- [[n]Trunc Int8] + [48i8] | 54 byte <- [[n]Trunc UInt8] + [48u8] |
54 out <- [buf]Append[byte] | 55 out <- [buf]Append[byte] |
55 }{ | 56 }{ |
56 next <- [n]/[10i32] | 57 next <- [n]/[10u32] |
57 | 58 |
58 byte <- [[[n]-[[next]*[10i32]]]Trunc Int8] + [48i8] | 59 byte <- [[[n]-[[next]*[10u32]]]Trunc UInt8] + [48u8] |
59 out <- [_Print Int32[next, buf]]Append[byte] | 60 out <- [_String 32[next, buf]]Append[byte] |
60 } | 61 } |
62 } | |
63 | |
64 _String Int32[n:out] | |
65 { | |
66 If[[n] < [0i32]] | |
67 { | |
68 buf <- [Array[]]Append[45u8] | |
69 }{ | |
70 buf <- Array[] | |
71 } | |
72 val <- Abs UInt[n] | |
73 out <- _String 32[val, buf] | |
74 } | |
75 | |
76 String@Int32[n:out] | |
77 { | |
78 out <- String[_String Int32[n]] | |
61 } | 79 } |
62 | 80 |
63 Print@Int32[n:out] | 81 Print@Int32[n:out] |
64 { | 82 { |
65 If[[n] < [0i32]] | 83 fbuf <- [_String Int32[n]]Append[10u8] |
66 { | |
67 val <- [0i32]-[n] | |
68 buf <- [Array[]]Append[45i8] | |
69 }{ | |
70 val <- Val[n] | |
71 buf <- Array[] | |
72 } | |
73 fbuf <- [_Print Int32[val, buf]]Append[10i8] | |
74 out <- write[1i32, fbuf, Int64[[fbuf]Length >>]] | 84 out <- write[1i32, fbuf, Int64[[fbuf]Length >>]] |
75 } | 85 } |
76 | 86 |
87 String@UInt32[n:out] | |
88 { | |
89 out <- String[_String 32[n, Array[]]] | |
90 } | |
91 | |
92 Print@UInt32[n:out] | |
93 { | |
94 fbuf <- [_String 32[n, Array[]]]Append[10u8] | |
95 out <- write[1i32, fbuf, Int64[[fbuf]Length >>]] | |
96 } | |
97 | |
77 Blueprint Int16 | 98 Blueprint Int16 |
78 { | 99 { |
79 Num(Int16,Naked) | 100 Num(Int16,Naked) |
80 } | 101 } |
81 | 102 |
130 } | 151 } |
131 | 152 |
132 If@UInt8[num:yes,no] | 153 If@UInt8[num:yes,no] |
133 { | 154 { |
134 yes,no <- If[[num]!=[0u8]] | 155 yes,no <- If[[num]!=[0u8]] |
156 } | |
157 | |
158 Abs@Int64[num:out] | |
159 { | |
160 If[[num]<[0i64]] | |
161 { out <- [0i64]-[num] } | |
162 { out <- num } | |
163 } | |
164 | |
165 Abs@Int32[num:out] | |
166 { | |
167 If[[num]<[0i32]] | |
168 { out <- [0i32]-[num] } | |
169 { out <- num } | |
170 } | |
171 | |
172 Abs@Int16[num:out] | |
173 { | |
174 If[[num]<[0i16]] | |
175 { out <- [0i16]-[num] } | |
176 { out <- num } | |
177 } | |
178 | |
179 Abs@Int8[num:out] | |
180 { | |
181 If[[num]<[0i8]] | |
182 { out <- [0i8]-[num] } | |
183 { out <- num } | |
184 } | |
185 | |
186 Mod[a,b:out] | |
187 { | |
188 out <- [a]-[[[a]/[b]]*[b]] | |
135 } | 189 } |
136 | 190 |
137 | 191 |
138 Blueprint Array | 192 Blueprint Array |
139 { | 193 { |
175 | 229 |
176 _Copy Params[source(Worker),dest(Worker),cur(Int16):out(Worker)] | 230 _Copy Params[source(Worker),dest(Worker),cur(Int16):out(Worker)] |
177 { | 231 { |
178 If[[cur]<[[source]Size >>]] | 232 If[[cur]<[[source]Size >>]] |
179 { | 233 { |
180 [source]Get Input[cur] | 234 [source]Get Input[Int32[cur]] |
181 { | 235 { |
182 next <- _internal_worker_setinput[dest, cur, ~] | 236 next <- _internal_worker_setinput[dest, cur, ~] |
183 }{ | 237 }{ |
184 next <- Val[dest] | 238 next <- Val[dest] |
185 } | 239 } |
307 If[[Blueprint Of[val]] = [eltype]] | 361 If[[Blueprint Of[val]] = [eltype]] |
308 { | 362 { |
309 out <- _internal_array_copyin[farray, index, val] | 363 out <- _internal_array_copyin[farray, index, val] |
310 }{ | 364 }{ |
311 boxed <- _internal_array_allocboxed[[farray]Storage >>] | 365 boxed <- _internal_array_allocboxed[[farray]Storage >>] |
312 [array]First | 366 [farray]First |
313 { | 367 { |
314 copied <- _Copy to Boxed[farray, boxed, ~] | 368 copied <- [_Copy to Boxed[farray, boxed, ~]]Length <<[ [farray]Length >> ] |
315 }{ | 369 }{ |
370 Print["Uh oh, no First on Naked Array!"] | |
316 //I don't think this case should happen normally | 371 //I don't think this case should happen normally |
317 copied <- Val[boxed] | 372 copied <- Val[boxed] |
318 } | 373 } |
319 out <- _internal_array_setboxed[copied, index, val] | 374 out <- _internal_array_setboxed[copied, index, val] |
320 } | 375 } |