Created
June 8, 2012 11:14
-
-
Save alexnask/2895032 to your computer and use it in GitHub Desktop.
Slice them arrays!
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
| void array_range____OP_IDX_T__star_Range__T__star(uint8_t* __genericReturn1, lang_types__Class* T, uint8_t* data, lang_Numbers__Range range) { | |
| lang_Numbers__Int size = range.max - range.min; | |
| uint8_t* ret = ((uint8_t*) (lang_Memory__gc_malloc(size * T->size))); | |
| { | |
| lang_Numbers__Int i; | |
| for (i = 0; i < size; i++) { | |
| lang_Memory__memcpy(&(ret[i * T->size]), &(data[(range.min + i) * T->size]), T->size); | |
| } | |
| } | |
| if (__genericReturn1) { | |
| __genericReturn1 = ret; | |
| } | |
| return; | |
| } | |
| // Here is the call to it | |
| array_range____OP_IDX_T__star_Range__T__star((uint8_t*) &(array_range__data), (lang_types__Class*)lang_Numbers__Int_class(), (uint8_t*) array_range__list, lang_Numbers__Range_new(0, 3)); | |
| // ^ array_range_data should not be referenced >.< | |
| // With | |
| lang_Numbers__Int* array_range__data; | |
| lang_Numbers__Int* array_range__list; | |
| array_range__list = ((lang_Numbers__Int*) ((lang_Numbers__SSizeT[]) { 0, 1, 2, 3, 4 })); |
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
| operator [] <T> (data: T*, range: Range) -> T* { | |
| size := range max - range min | |
| ret := gc_malloc(size * T size) as T* | |
| for(i in 0 .. size) { | |
| ret[i] = data[(range min + i)] | |
| } | |
| ret | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment