History

Moved the Instruction class into the opcodes module. Moved the read* functions into the new utils module. Created an Instruction subclass for each instruction, placing the corresponding opcode value inside it.

David Boddie committed 9 years ago

Commit b833c111 parent 48fa6014 files · +952 −354Browse files

Showing the changes to docs (1 of 4 files). Show all

Unified · Split

docs/notes.txt+43−0
@@ -0,0 +1,43 @@
1Function signatures will be output by the Limbo compiler if you pass it the
2"-D S" debug option.
3
4For example, the Sys->print function has this summary output for it:
5
6 signed Sys->print type fn(s: string, *): int len 6 sig 0xac849033
7
8The type "fn(s: string, *): int" is how the function is declared in the
9module/sys.m file.
10
11Function signatures are generated by the sign function in the limbo/types.c
12file. We add the debug code after the md5 function call:
13
14 md5(sig, sigend, md5sig, nil);
15 if(debug['S']) {
16 print("sign %D len %d\n", d, sigend);
17 print("%s\n", (char*)sig);
18 }
19
20This results in the following additional two debug lines:
21
22 sign Sys->print len 6
23 f*(s)i
24
25The "f*(s)i" string is the function signature that needs to be hashed using the
26MD5 algorithm. Additionally, the following code is used to reduce the hash
27value to four bytes:
28
29 for(i = 0; i < MD5dlen; i += 4)
30 t->sig ^= md5sig[i+0] | (md5sig[i+1]<<8) | (md5sig[i+2]<<16) | (md5sig[i+3]<<24);
31
32We can reproduce this in Python using the md5 module, obtaining the hash value
33then combining each eight digit segment of it using XOR, before reversing the
34endianness of the resulting value:
35
36 import md5
37 h = md5.md5("f*(s)i").hexdigest()
38 l = map(lambda x: int(h[x:x+2], 16), range(0, 32, 2))
39 hd = sum(map(lambda x: reduce(lambda y, z: y ^ z, l[x::4]) << (x * 8), range(4)))
40
41The rtsign and idsign functions in the limbo/types.c file are responsible for
42creating a signature for a function. The sigkind array contains the characters
43used for each type of object that will be serialised.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t