making parfait (both) use the new byte functions

This commit is contained in:
Torsten Ruger 2015-11-19 10:09:24 +02:00
parent dffa3fbf42
commit ac5a7ac4ca
3 changed files with 28 additions and 42 deletions

View File

@ -119,6 +119,8 @@ end
require_relative "instructions/set_slot" require_relative "instructions/set_slot"
require_relative "instructions/get_slot" require_relative "instructions/get_slot"
require_relative "instructions/set_byte"
require_relative "instructions/get_byte"
require_relative "instructions/load_constant" require_relative "instructions/load_constant"
require_relative "instructions/syscall" require_relative "instructions/syscall"
require_relative "instructions/function_call" require_relative "instructions/function_call"

View File

@ -20,7 +20,7 @@ module Parfait
2 # 2 is the amount of attributes, layout and char_length. the offset after which chars start 2 # 2 is the amount of attributes, layout and char_length. the offset after which chars start
end end
def self.get_indexed i def self.get_indexed i
i + get_length_index i + get_length_index * 4
end end
# initialize with length. For now we try to keep all non-parfait (including String) out # initialize with length. For now we try to keep all non-parfait (including String) out
# String will contain spaces for non-zero length # String will contain spaces for non-zero length
@ -89,7 +89,11 @@ module Parfait
def set_char at , char def set_char at , char
raise "char not fixnum #{char.class}" unless char.kind_of? Fixnum raise "char not fixnum #{char.class}" unless char.kind_of? Fixnum
index = range_correct_index(at) index = range_correct_index(at)
word_index = (index - 1) / 4 + 1 + Word.get_length_index set_internal_byte( index , char)
end
def set_internal_byte index , char
word_index = (index - 1) / 4 + 1
rest = ((index - 1) % 4) rest = ((index - 1) % 4)
shifted = char << (rest * 8) shifted = char << (rest * 8)
was = get_internal_word( word_index ) was = get_internal_word( word_index )
@ -112,7 +116,12 @@ module Parfait
#the return "character" is an integer #the return "character" is an integer
def get_char at def get_char at
index = range_correct_index(at) index = range_correct_index(at)
word_index = (index - 1 ) / 4 + 1 + Word.get_length_index get_internal_byte(index)
end
def get_internal_byte( index )
word_index = (index - 1 ) / 4 + 1
rest = ((index - 1) % 4) rest = ((index - 1) % 4)
char = get_internal_word(word_index) char = get_internal_word(word_index)
char = 0 unless char.is_a?(Numeric) char = 0 unless char.is_a?(Numeric)
@ -130,7 +139,7 @@ module Parfait
index = self.length + at if at < 0 index = self.length + at if at < 0
raise "index must be positive , not #{at}" if (index <= 0) raise "index must be positive , not #{at}" if (index <= 0)
raise "index too large #{at} > #{self.length}" if (index > self.length ) raise "index too large #{at} > #{self.length}" if (index > self.length )
return index return index + Word.get_length_index * 4
end end
# compare the word to another # compare the word to another

View File

@ -1,16 +1,12 @@
class Word < Object class Word < Object
int correct_index(int index)
return index + 8
end
int char_at(int index) int char_at(int index)
int word_index = index - 1 index = correct_index(index)
word_index = word_index >> 2 return get_internal_byte(index)
word_index = word_index + 3
int rest = index - 1
rest = rest.mod4()
int char = get_internal_word(word_index)
int shifted = 8 * rest
shifted = char >> shifted
int ret = shifted & 255
return ret
end end
int set_length(int i) int set_length(int i)
@ -18,37 +14,16 @@ class Word < Object
return i return i
end end
int set_char_at( int index , int val)
index = correct_index(index)
return set_internal_byte(index , val)
end
Word push_char(int char) Word push_char(int char)
int index = self.char_length + 1 int index = self.char_length + 1
self.set_length(index) self.set_length(index)
int word_index = index - 1 set_char_at(index , char)
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( word_index )
int mask = rest * 8
int const = 255 << 8
const = const + 255
const = const << 8
const = const + 255
const = const << 8
const = const + 255
mask = 255 << mask
mask = const - mask
int masked = was & mask
int put = masked + shifted
set_internal_word( word_index , put )
return self return self
end end
end end