Mercurial > repos > rhope
diff kernel.rhope @ 96:5a08705f7610
Semi-broken cleanup of Array implementation
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 02 Aug 2010 05:12:19 -0400 |
parents | e73a93fb5de1 |
children | a34a982ecd32 |
line wrap: on
line diff
--- a/kernel.rhope Mon Aug 02 01:55:56 2010 -0400 +++ b/kernel.rhope Mon Aug 02 05:12:19 2010 -0400 @@ -1,3 +1,4 @@ +Import array.rhope Import string.rhope Import list.rhope Import functional.rhope @@ -188,22 +189,8 @@ out <- [a]-[[[a]/[b]]*[b]] } - -Blueprint Array -{ - Eltype(Blueprint) - Length(Int32,Naked) - Storage(Int32,Naked) -} - Foreign C:runtime { - _internal_array_copyout[array(Array), index(Int32,Naked), dest(Any Type,Boxed,Mutable):dest] - _internal_array_copyin[array(Array,Boxed,Mutable), index(Int32,Naked), val:array] - _internal_array_getboxed[array(Array), index(Int32,Naked):out] - _internal_array_setboxed[array(Array,Boxed,Mutable), index(Int32,Naked), val:array] - _internal_array_allocboxed[size(Int32,Naked):out(Array)] - _internal_array_allocnaked[size(Int32,Naked),type(Blueprint):out(Array)] _internal_blueprint_eq[left(Blueprint),right(Blueprint):out(Int32,Naked)] _internal_worker_alloc[size(Int16,Naked):out(Worker)] _internal_worker_setinput[worker(Worker,Boxed,Mutable),num(Int16,Naked),val:worker] @@ -264,206 +251,6 @@ out <- [_internal_blueprint_eq[left,right]]!=[0] } -Array[:out(Array)] -{ - out <- [[_internal_array_allocboxed[0] - ]Length <<[0] - ]Storage <<[0] -} - -First@Array[array:out(Int32),empty] -{ - ,empty <- If[[array]Length >>] - { out <- 0 } -} - -Next@Array[array,current:out(Int32),empty] -{ - next <- [current]+[1] - ,empty <- If[[next] < [[array]Length >>]] - { - out <- Val[next] - } -} - -Last@Array[array:out(Int32),empty] -{ - ,empty <- If[[array]Length >>] - { out <- [[array]Length >>] - [1] } -} - -Append@Array[array,newval:out(Array)] -{ - out <- [array]Set[[array]Length >>, newval] -} - -Index@Array[array,index(Int32):out,notfound] -{ - ,notfound <- If[[index] >= [0]] - { - ,notfound <- If[[index] < [[array]Length >>]] - { - eltype <- [array]Eltype >> - If[[eltype] = [Any Type()]] - { - out <- _internal_array_getboxed[array, index] - }{ - out <- _internal_array_copyout[array, index, Build[eltype]] - } - } - } -} - -_Copy to Boxed[source,dest,current:out] -{ - ndest <- _internal_array_setboxed[dest, current, [source]Index[current]] - - [source]Next[current] - { - out <- _Copy to Boxed[source, ndest, ~] - }{ - out <- Val[ndest] - } -} - -_Copy Naked[source,dest,current:out] -{ - ndest <- _internal_array_copyin[dest, current, [source]Index[current]] - - [source]Next[current] - { - out <- _Copy Naked[source, ndest, ~] - }{ - out <- Val[ndest] - } -} - -Set@Array[array,index(Int32),val:out(Array)] -{ - If[[index] < [[array]Storage >>]] - { - If[[index] > [[array]Length >>]] - { - farray <- [[array]Set[[index]-[1], val]]Length <<[ [index]+[1] ] - }{ - If[[index] = [[array]Length >>]] - { - farray <- [array]Length <<[ [index]+[1] ] - }{ - farray <- Val[array] - } - } - eltype <- [array]Eltype >> - If[[eltype] = [Any Type()]] - { - out <- _internal_array_setboxed[farray, index, val] - }{ - If[[Blueprint Of[val]] = [eltype]] - { - out <- _internal_array_copyin[farray, index, val] - }{ - boxed <- _internal_array_allocboxed[[farray]Storage >>] - [farray]First - { - copied <- [_Copy to Boxed[farray, boxed, ~]]Length <<[ [farray]Length >> ] - }{ - Print["Uh oh, no First on Naked Array!"] - //I don't think this case should happen normally - copied <- Val[boxed] - } - out <- _internal_array_setboxed[copied, index, val] - } - } - }{ - If[[array]Length >>] - { - If[[index] < [4]] - { - new storage <- [index]+[index] - }{ - new storage <- [index]+[[index]RShift[1]] - } - - do boxed <- If[[[array]Eltype >>] = [Any Type()]] - { - copied <- _Copy to Boxed[array, _internal_array_allocboxed[new storage], 0] - }{ - bp <- Blueprint Of[val] - If[[[array]Eltype >>] = [bp]] - { - copied <- _Copy Naked[array, _internal_array_allocnaked[new storage, bp], 0] - }{ - copied <- _Copy to Boxed[array, _internal_array_allocboxed[new storage], 0] - } - } - out <- [[copied]Length <<[[array]Length >>]]Set[index,val] - }{ - len <- [index]+[1] - out <- [_internal_array_allocnaked[len, Blueprint Of[val]] - ]Set[index,val] - } - } -} - -Length@Array[arr:out] -{ - out <- [arr]Length >> -} - -Call@Array[arr(Array),index(Int32):out] -{ - out <- [arr]Index[index] -} - -_Copy Part Naked[source,dest,srcindex,destindex:out] -{ - ndest <- _internal_array_copyin[dest, destindex, [source]Index[srcindex]] - - [source]Next[srcindex] - { - out <- _Copy Part Naked[source, ndest, ~, [destindex]+[1]] - }{ - out <- Val[ndest] - } -} - -_Copy Part Boxed[source,dest,srcindex,destindex:out] -{ - ndest <- _internal_array_setboxed[dest, destindex, [source]Index[srcindex]] - - [source]Next[srcindex] - { - out <- _Copy Part Boxed[source, ndest, ~, [destindex]+[1]] - }{ - out <- Val[ndest] - } -} - -Slice@Array[arr,slicepoint(Int32):left,right] -{ - If[[slicepoint]<[[arr]Length]] - { - If[[slicepoint]>[0i32]] - { - eltype <- [arr]Eltype >> - If[[eltype] = [Any Type()]] - { - _Copy Part Boxed[arr, _internal_array_allocboxed[[[arr]Length]-[slicepoint]], slicepoint, 0] - }{ - _Copy Part Naked[arr, _internal_array_allocnaked[[[arr]Length]-[slicepoint], eltype], slicepoint, 0] - } - left <- [arr]Length <<[slicepoint] - }{ - right <- arr - left <- Array[] - } - }{ - left <- arr - right <- Array[] - } - -} - And[left,right:out] { ,out <- If[left]