about summary refs log blame commit diff stats
path: root/archive/2.transect/compiler6
blob: 48a7030f654081d49a9ab00d7cffea9a02934456 (plain) (tree)





























== 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 '*'.
ver-full-screen 0 " is too large for array '" 3 0) # 3=cyan (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 *(ebp+0x18) 3 0) # 3=cyan (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 "'" 3 0) # 3=cyan { eb/jump loop/disp8 } # never gets here $__check-mu-array-bounds:end: # . restore registers 5a/pop-to-edx 59/pop-to-ecx 58/pop-to-eax # . epilogue 89/<- %esp 5/r32/ebp 5d/pop-to-ebp c3/return __check-mu-array-bounds:overflow: (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 "fn " 3 0) # 3=cyan (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 *(ebp+0x14) 3 0) # 3=cyan (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 ": offset to array '" 3 0) # 3=cyan (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 *(ebp+0x18) 3 0) # 3=cyan (draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 "' overflowed 32 bits" 3 0) # 3=cyan { eb/jump loop/disp8 } # never gets here __mu-abort-null-index-base-address: (abort "null address in 'index'") __mu-abort-null-get-base-address: (abort "null address in 'get'")