diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-01-01 17:04:37 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-01-01 17:04:37 -0800 |
commit | 2a4088119cf41175457414dfa59bd4064b8f0562 (patch) | |
tree | 64fe184e399f9870ebd481a90eec34d51e5dff68 /archive/2.transect/compiler7 | |
parent | 23fd294d85959c6b476bcdc35ed6ad508cc99b8f (diff) | |
download | mu-2a4088119cf41175457414dfa59bd4064b8f0562.tar.gz |
5852
Diffstat (limited to 'archive/2.transect/compiler7')
-rw-r--r-- | archive/2.transect/compiler7 | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/archive/2.transect/compiler7 b/archive/2.transect/compiler7 new file mode 100644 index 00000000..cf7d454f --- /dev/null +++ b/archive/2.transect/compiler7 @@ -0,0 +1,46 @@ +== 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 _ stack|heap|global) +(array _ n) # on stack or global +(ref _) +(ref array _) # by definition always on the heap + +addresses to global can be saved and manipulated as usual +addresses on stack can't be saved to heap +addresses on heap can't be saved to global (use ref) + +addresses to stack or heap can't be included in compound types + or used across a call + or used across a label + +<reg x> : (address T stack|global) <- advance <reg/mem> : (array T), <reg offset> : (index T) +<reg x> : (address T heap) <- advance *<mem> : (ref array T), <reg offset> : (index T) + +arrays require a size +(ref array _) may not include a size + +Arguments of type 'address' are required to be on the stack or global. Can't +be on the heap. + +So we need duplication for address and ref arguments? + +Argv has type (array (address (array char) global)) + +variables on stack, heap and global are references. The name points at the +address. Use '*' to get at the value. |