History

Annotated the test further. Added more information to the string representation of Type objects. Fixed the order of the offsets in the string representation of offsets in double indirect operands. Updated the notes.

David Boddie committed 9 years ago

Commit a8c27d91 parent de9ef054 files · +63 −20Browse files

Unified · Split

4 files
  1. Tests/count.py +42 −16
  2. dis.py +2 −2
  3. docs/notes.txt +17 −0
  4. opcodes.py +2 −2
Tests/count.py+42−16
@@ -5,6 +5,7 @@ import sys · 4 unmodified lines
5import dis5import dis
6import opcodes6import opcodes
7from opcodes import Imm, LOfp, LOmp, NoOp, SOfp, SOmp, SOSOfp, SOSOmp7from opcodes import Imm, LOfp, LOmp, NoOp, SOfp, SOmp, SOSOfp, SOSOmp
8from utils import hash_signature
8 9
9if __name__ == "__main__":10if __name__ == "__main__":
10 11
@@ -19,28 +20,53 @@ if __name__ == "__main__": · 8 unmodified lines
19 d.entry_pc = 020 d.entry_pc = 0
20 d.entry_type = 2 # refers to Type 221 d.entry_type = 2 # refers to Type 2
21 22
23 # implement count;
24 #
25 # include "sys.m";
26 # include "draw.m";
27 #
28 # count: module
29 # {
30 # init: fn(ctxt: ref Draw->Context, args: list of string);
31 # };
32 #
33 # init(ctxt: ref Draw->Context, args: list of string)
34 # {
35 # sys := load Sys Sys->PATH;
36 # sys->print("Counting...\n");
37 # for (i := 0; i < 20; i++)
38 # sys->print("%d\n", i);
39 # }
40
22 d.code = [41 d.code = [
23 opcodes.load(LOmp(0), Imm(0), LOfp(44)),42 opcodes.load(LOmp(0), Imm(0), LOfp(44)), # "$Sys", ldt[0] -> module
24 opcodes.frame(Imm(1), LOfp(52)),43
25 opcodes.movp(LOmp(8), SOSOfp(52, 32)),44 opcodes.frame(Imm(1), LOfp(52)), # types[1] -> new_frame1 (ptr)
26 opcodes.lea(LOfp(48), SOSOfp(52, 16)),45 opcodes.movp(LOmp(8), SOSOfp(52, 32)), # "Counting..." ->
27 opcodes.mcall(LOfp(52), Imm(0), LOfp(44)),46 opcodes.lea(LOfp(48), SOSOfp(52, 16)), #
28 opcodes.movw(Imm(0), LOfp(40)),47 opcodes.mcall(LOfp(52), Imm(0), LOfp(44)), # new_frame1, ldt[0], module
29 opcodes.blew(Imm(0x14), SOfp(40), Imm(0xe)),48
30 opcodes.frame(Imm(1), LOfp(48)),49 opcodes.movw(Imm(0), LOfp(40)), # 0 -> i (int)
31 opcodes.movp(LOmp(4), SOSOfp(48, 32)),50 opcodes.blew(Imm(0x14), SOfp(40), Imm(0xe)),# 0x6: if 20 <= i branch to 0xe
51
52 opcodes.frame(Imm(1), LOfp(48)), # types[1] -> new_frame2 (ptr)
53 opcodes.movp(LOmp(4), SOSOfp(48, 32)), # "%d\n" ->
32 opcodes.movw(LOfp(40), SOSOfp(48, 36)),54 opcodes.movw(LOfp(40), SOSOfp(48, 36)),
33 opcodes.lea(LOfp(52), SOSOfp(48, 16)),55 opcodes.lea(LOfp(52), SOSOfp(48, 16)), # new_frame1 ->
34 opcodes.mcall(LOfp(48), Imm(0), LOfp(44)),56 opcodes.mcall(LOfp(48), Imm(0), LOfp(44)), # new_frame2, ldt[0]
35 opcodes.addw(Imm(1), NoOp(), LOfp(40)),57
36 opcodes.jmp(Imm(6)),58 opcodes.addw(Imm(1), NoOp(), LOfp(40)), # 1 + [i] -> i
37 opcodes.ret()59 opcodes.jmp(Imm(6)), # jump to 0x6
60 opcodes.ret() # 0xe: return
38 ]61 ]
39 62
40 d.types = [63 d.types = [
41 dis.Type(0, 16, 1, "\xf0"),64 dis.Type(0, 16, 1, "\xf0"),
42 dis.Type(1, 40, 2, "\x00\x80"),65 dis.Type(1, 40, 2, "\x00\x80"),
43 dis.Type(2, 56, 2, "\x00\xd0") # stack frame type, entry type66 # Type 2 is the stack frame type (see below), entry type (see above),
67 # 56 bytes (14 words) in size:
68 # pointer bitmap: 0 0 0 0 0 0 0 0 | 1 1 0 1 0 0 [0 0]
69 dis.Type(2, 56, 2, "\x00\xd0")
44 ]70 ]
45 71
46 d.data = {72 d.data = {
@@ -53,7 +79,7 @@ if __name__ == "__main__": · 6 unmodified lines
53 d.module_name = "count"79 d.module_name = "count"
54 d.link = [dis.Link(0, 2, 0x4244b354, "init")] # refers to Type 280 d.link = [dis.Link(0, 2, 0x4244b354, "init")] # refers to Type 2
55 d.initialised_globals = 181 d.initialised_globals = 1
56 d.ldt = [[dis.LDT(0xac849033, "print")]]82 d.ldt = [[dis.LDT(hash_signature("f*(s)i"), "print")]]
57 d.path = sys.argv[0]83 d.path = sys.argv[0]
58 84
59 d.write(open(sys.argv[1], "w"))85 d.write(open(sys.argv[1], "w"))
dis.py+2−2
@@ -349,8 +349,8 @@ class Type: · 348 unmodified lines
349 349
350 def __repr__(self):350 def __repr__(self):
351 351
352 return "Type(desc=%i, size=%i, ptrs=%i)" % (self.desc_number,352 return "Type(desc=%i, size=%i, ptrs=%i, array=%s)" % (self.desc_number,
353 self.size, self.number_ptrs)353 self.size, self.number_ptrs, repr(self.array))
354 354
355 def is_pointer(self, address):355 def is_pointer(self, address):
356 356
docs/notes.txt+17−0
@@ -1,7 +1,13 @@
1Opcode definitions
2------------------
3
1Opcodes are defined in include/isa.h, limbo/optab.c and libinterp/xec.c.4Opcodes are defined in include/isa.h, limbo/optab.c and libinterp/xec.c.
2 5
3consc is documented but does not exist in the opcode definitions.6consc is documented but does not exist in the opcode definitions.
4 7
8Function signatures
9-------------------
10
5Function signatures will be output by the Limbo compiler if you pass it the11Function signatures will be output by the Limbo compiler if you pass it the
6"-D S" debug option.12"-D S" debug option.
7 13
@@ -45,3 +51,14 @@ endianness of the resulting value: · 37 unmodified lines
45The rtsign and idsign functions in the limbo/types.c file are responsible for51The rtsign and idsign functions in the limbo/types.c file are responsible for
46creating a signature for a function. The sigkind array contains the characters52creating a signature for a function. The sigkind array contains the characters
47used for each type of object that will be serialised.53used for each type of object that will be serialised.
54
55Operands
56--------
57
58The double indirect operands SO(SO(fp)) and SO(SO(mp)) are represented by two
59offsets in the encoded instruction. The first represents the "inner" offset,
60the second the "outer" offset. For example:
61
62 10(20(fp)) is represented as 20, 10 in the instruction.
63
64This was discovered by running the Limbo compiler with the -S option.
opcodes.py+2−2
@@ -158,7 +158,7 @@ class Operand: · 157 unmodified lines
158 write_OP(f, self.value)158 write_OP(f, self.value)
159 159
160class Immediate(Operand):160class Immediate(Operand):
161 str_pattern = "$%x"161 str_pattern = "$0x%x"
162 middle_address_mode = 0x40162 middle_address_mode = 0x40
163 address_mode = 0x02163 address_mode = 0x02
164 164
@@ -193,7 +193,7 @@ class DoubleShortOffset(Operand): · 28 unmodified lines
193 self.annotation = annotation193 self.annotation = annotation
194 194
195 def __str__(self):195 def __str__(self):
196 return self.str_pattern % (self.offset0, self.offset1)196 return self.str_pattern % (self.offset1, self.offset0)
197 197
198 def write(self, f):198 def write(self, f):
199 write_OP(f, self.offset0 & 0xffff)199 write_OP(f, self.offset0 & 0xffff)