Class: JITBuffer
- Inherits:
-
Object
show all
- Defined in:
- ext/jit_buffer/jit_buffer.c,
lib/jit_buffer.rb
Defined Under Namespace
Modules: MMAP
Classes: Exception, OutOfBoundsException, ReadOnlyException
Constant Summary
collapse
- VERSION =
'1.0.1'
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(memory, size) ⇒ JITBuffer
Returns a new instance of JITBuffer.
60
61
62
63
64
65
|
# File 'lib/jit_buffer.rb', line 60
def initialize memory, size
@writeable = false
@memory = memory
@size = size
@pos = 0
end
|
Instance Attribute Details
#pos ⇒ Object
Returns the value of attribute pos.
58
59
60
|
# File 'lib/jit_buffer.rb', line 58
def pos
@pos
end
|
Instance Method Details
#getc ⇒ Object
81
82
83
84
85
86
|
# File 'lib/jit_buffer.rb', line 81
def getc
raise(OutOfBoundsException, "You've gone too far!") if pos >= @size
x = @memory[pos]
@pos += 1
x
end
|
#putc(byte) ⇒ Object
67
68
69
70
71
72
|
# File 'lib/jit_buffer.rb', line 67
def putc byte
raise(ReadOnlyException, "Buffer is read only!") unless @writeable
raise(OutOfBoundsException, "Buffer full! #{pos} - #{@size}") if pos >= @size
@memory[pos] = byte
@pos += 1
end
|
#read(len) ⇒ Object
88
89
90
91
92
93
|
# File 'lib/jit_buffer.rb', line 88
def read len
raise(OutOfBoundsException, "You've gone too far!") if pos + len >= @size
x = @memory[pos, pos + len]
@pos += len
x
end
|
#seek(pos, whence = IO::SEEK_SET) ⇒ Object
95
96
97
98
99
100
101
|
# File 'lib/jit_buffer.rb', line 95
def seek pos, whence = IO::SEEK_SET
raise NotImplementedError if whence != IO::SEEK_SET
raise OutOfBoundsException if pos >= @size
@pos = pos
self
end
|
#to_function(params, ret) ⇒ Object
114
115
116
|
# File 'lib/jit_buffer.rb', line 114
def to_function params, ret
Fiddle::Function.new @memory.to_i, params, ret
end
|
#to_i ⇒ Object
Get the address of the executable memory
119
120
121
|
# File 'lib/jit_buffer.rb', line 119
def to_i
@memory.to_i
end
|
#write(bytes) ⇒ Object
74
75
76
77
78
79
|
# File 'lib/jit_buffer.rb', line 74
def write bytes
raise(ReadOnlyException, "Buffer is read only!") unless @writeable
raise OutOfBoundsException if pos + bytes.bytesize >= @size
@memory[pos, bytes.length] = bytes
@pos += bytes.bytesize
end
|