Mercurial > repos > rhope
diff arrayjs.rhope @ 136:fc3815b7462f
Javascript backend now produces working code for some simple examples, still more of the standard lib that needs to be ported.
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 14 Nov 2010 23:07:55 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/arrayjs.rhope Sun Nov 14 23:07:55 2010 -0500 @@ -0,0 +1,81 @@ + +Blueprint Array +{ + +} + +Foreign Javascript:runtime +{ + _internal_js_length[array:out(Int32,Naked)] + _internal_array_set[array(Array,Boxed,Mutable),index(Int32,Naked),val:array] + _internal_array_get[array(Array),index(Int32,Naked):out] +} + +Array[:out(Empty Array)] +{ + out <- Build[Array()] +} + +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] +{ + out <- [array]Set[[array]Length, newval] +} + +Index@Array[array,index(Int32):out,notfound] +{ + ,notfound <- If[[index] >= [0]] + { + ,notfound <- If[[index] < [[array]Length]] + { + out <- _internal_array_get[array, index] + } + } +} + +Set@Array[array,index(Int32),val:out,invalid] +{ + invalid <- If[[index]<[0]] {} + { + len <- [array]Length + If[[index]>[len]] + { + out <- [[array]Set[[index]-[1],val]]Set[index, val] + }{ + out <- _internal_array_set[array,index,val] + } + } +} + +Length@Array[arr:out] +{ + out <- _internal_js_length[arr] +} + +Call@Array[arr,index(Int32):out,not found] +{ + out,not found <- [arr]Index[index] +} +