rubyx/lib/soml/parfait/word.soml
Torsten Ruger 4a8bb32039 serious bit fiddling, div10 using shift magic
forgot that arm has no division (or respectively only later models have)
many magic formulae out there, none seem to work 1000% on the
interpreter. some big 0 ending numbers are 1 off.
2015-11-13 20:46:27 +02:00

48 lines
946 B
Plaintext

class Word < Object
int char_at(int index)
int word_index = index - 1
word_index = word_index >> 2
word_index = word_index + 3
int rest = index - 1
rest = rest.mod4()
int char = get_internal(word_index)
int shifted = 8 * rest
shifted = char >> shifted
int ret = shifted & 255
return ret
end
int set_length(int i)
set_internal( 2 , i)
return i
end
Word push_char(int char)
int index = self.char_length + 1
self.set_length(index)
int word_index = index - 1
word_index = word_index >> 2
word_index = word_index + 3
int rest = index - 1
rest = rest.mod4()
int shifted = rest * 8
shifted = char << shifted
int was = get_internal( word_index )
int mask = rest * 8
mask = 255 << mask
mask = 4294967295 - mask
int masked = was & mask
int put = masked + shifted
set_internal( word_index , put )
return self
end
end