about summary refs log tree commit diff stats
path: root/transect/compiler6
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-09-17 22:57:10 -0700
committerKartik Agaram <vc@akkartik.com>2018-09-17 22:57:58 -0700
commitf09280141f18fbe8cef0ed576cf932e12e315666 (patch)
treed00962b07cb013f89d4fdb2fcf19c392afb62b5c /transect/compiler6
parent0a7b03727a736f73c16d37b22afef8496c60d657 (diff)
downloadmu-f09280141f18fbe8cef0ed576cf932e12e315666.tar.gz
4548: start of a compiler for a new experimental low-level language
Diffstat (limited to 'transect/compiler6')
-rw-r--r--transect/compiler636
1 files changed, 36 insertions, 0 deletions
diff --git a/transect/compiler6 b/transect/compiler6
new file mode 100644
index 00000000..48a7030f
--- /dev/null
+++ b/transect/compiler6
@@ -0,0 +1,36 @@
+== Goal
+
+A memory-safe language with a simple translator to x86 that can be feasibly written in x86.
+
+== Definitions of terms
+
+Memory-safe: it should be impossible to:
+  a) create a pointer out of arbitrary data, or
+  b) to access heap memory after it's been freed.
+
+Simple: do all the work in a 2-pass translator:
+  Pass 1: check each instruction's types in isolation.
+  Pass 2: emit code for each instruction in isolation.
+
+== types
+
+int
+char
+(address _)
+(array _ n)
+(ref _)
+
+addresses can't be saved to stack or global,
+      or included in compound types
+      or used across a call (to eliminate possibility of free)
+
+<reg x> : (address T) <- advance <reg/mem> : (array T), <reg offset> : (index T)
+
+arrays require a size
+(ref array _) may not include a size
+
+== open questions
+Is argv an address?
+Global variables are easiest to map to addresses.
+Ideally we'd represent 'indirect' as a '*' and we could just count to make
+sure that an instruction never has more than one '*'.
/examples/ex3.subx.html?h=hlt&id=6033844884f18c9a6e6e186c79c36fd1dd2c9bb0'>60338448 ^
695f9bf8 ^
60338448 ^
695f9bf8 ^
ac07e589 ^

bb2b6ba7 ^















695f9bf8 ^
bb2b6ba7 ^















762107fd ^
bb2b6ba7 ^
14a38052 ^
c56d803c ^
60338448 ^
ee0e67b9 ^

c56d803c ^


bb2b6ba7 ^
a0d3cac4 ^
14a38052 ^


d1c9392a ^
695f9bf8 ^
33352536 ^



695f9bf8 ^


33352536 ^
6070c23e ^
695f9bf8 ^
33352536 ^
695f9bf8 ^
33352536 ^
695f9bf8 ^
86351aaf ^
695f9bf8 ^

a0d3cac4 ^



bb2b6ba7 ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98