Class: Lignite::Assembler
Overview
Assemble a complete RBF program file.
Constant Summary
collapse
- SIGNATURE =
"LEGO"
Instance Attribute Summary collapse
Instance Method Summary
collapse
#array8, #data16, #data32, #data8, #dataf, #datas
Methods included from Logger
default_logger, #logger
Methods included from Bytes
#f32, #hexdump, #u16, #u32, #u8, #unpack_f32, #unpack_u16, #unpack_u32, #unpack_u8
Instance Attribute Details
18
19
20
|
# File 'lib/lignite/assembler.rb', line 18
def globals
@globals
end
|
16
17
18
|
# File 'lib/lignite/assembler.rb', line 16
def objects
@objects
end
|
Instance Method Details
#assemble(rb_filename, rbf_filename, version: 109) ⇒ Object
Assemble a complete RBF program file. (it is OK to reuse an Assembler and call this several times in a sequence) TODO: redesign for Assembler.new(rb_filename).assemble(rbf_filename)?
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/lignite/assembler.rb', line 25
def assemble(rb_filename, rbf_filename, version: 109)
rb_text = File.read(rb_filename)
@objects = []
@globals = Variables.new
instance_eval(rb_text, rb_filename, 1)
File.open(rbf_filename, "w") do |f|
= (image_size:0, version: 0, object_count: 0, global_bytes: 0)
f.write()
@objects.each do |obj|
h = obj.(f.tell)
f.write(h)
f.write(obj.body)
end
size = f.tell
f.pos = 0
= (image_size: size,
version: version,
object_count: @objects.size,
global_bytes: @globals.bytesize)
f.write()
end
end
|
10
11
12
13
|
# File 'lib/lignite/assembler.rb', line 10
def (image_size:, version:, object_count:, global_bytes:)
SIGNATURE + u32(image_size) + u16(version) + u16(object_count) +
u32(global_bytes)
end
|
#variables ⇒ Object
51
52
53
|
# File 'lib/lignite/assembler.rb', line 51
def variables
globals
end
|
#vmthread(id, &body) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/lignite/assembler.rb', line 56
def vmthread(id, &body)
@locals = Variables.new
bodyc = BodyCompiler.new(@globals, @locals)
bodyc.instance_exec(&body)
bodyc.instance_exec { object_end }
logger.debug "VMTHREAD #{id}"
logger.debug " size #{bodyc.bytes.bytesize}"
logger.debug " " + hexdump(bodyc.bytes)
@objects << RbfObject.vmthread(body: bodyc.bytes, local_bytes: @locals.bytesize)
end
|