about summary refs log tree commit diff stats
path: root/prototypes/browse/24-bold/file-state.mu
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-10-01 20:40:22 -0700
committerKartik Agaram <vc@akkartik.com>2020-10-01 20:40:22 -0700
commitd75b71297426ee2d63d5630d1ef9469de48aca84 (patch)
tree0d4c517526770343822d4f409a8e9c1b7ac0e51e /prototypes/browse/24-bold/file-state.mu
parentf3ca0e3cb33d6c34dbe4c6941598d16d140be206 (diff)
downloadmu-d75b71297426ee2d63d5630d1ef9469de48aca84.tar.gz
6923
Diffstat (limited to 'prototypes/browse/24-bold/file-state.mu')
-rw-r--r--prototypes/browse/24-bold/file-state.mu45
1 files changed, 0 insertions, 45 deletions
diff --git a/prototypes/browse/24-bold/file-state.mu b/prototypes/browse/24-bold/file-state.mu
deleted file mode 100644
index d42bf8bf..00000000
--- a/prototypes/browse/24-bold/file-state.mu
+++ /dev/null
@@ -1,45 +0,0 @@
-type file-state {
-  source: (handle buffered-file)
-  eof?: boolean
-}
-
-fn init-file-state _self: (addr file-state), filename: (addr array byte) {
-  var self/eax: (addr file-state) <- copy _self
-  load-file self, filename
-  var eof/eax: (addr boolean) <- get self, eof?
-  copy-to *eof, 0  # false
-}
-
-fn load-file _self: (addr file-state), filename: (addr array byte) {
-  var self/eax: (addr file-state) <- copy _self
-  var out/esi: (addr handle buffered-file) <- get self, source
-  open filename, 0, out  # 0 = read mode
-}
-
-fn next-char _self: (addr file-state) -> result/eax: byte {
-  var self/ecx: (addr file-state) <- copy _self
-  var source/eax: (addr handle buffered-file) <- get self, source
-  var in/eax: (addr buffered-file) <- lookup *source
-  result <- read-byte-buffered in
-  # if result == EOF, set eof?
-  compare result, 0xffffffff  # EOF marker
-  {
-    var eof/ecx: (addr boolean) <- get self, eof?
-    copy-to *eof, 1  # true
-  }
-}
-
-fn done-reading? _self: (addr file-state) -> result/eax: boolean {
-  var self/eax: (addr file-state) <- copy _self
-  var eof/eax: (addr boolean) <- get self, eof?
-  result <- copy *eof
-}
-
-fn dump in: (addr buffered-file) {
-  var c/eax: byte <- read-byte-buffered in
-  compare c, 0xffffffff  # EOF marker
-  break-if-=
-  var g/eax: grapheme <- copy c
-  print-grapheme 0, g
-  loop
-}
{ color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
== 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 _ t), t ∋ {stack, heap, global}
(array _ t), t ∋ {stack, heap, global}

stack addresses can't be copied to heap or global
heap addresses can't be copied [1]
global addresses you're free to use anywhere

[1] (address _ heap) can't be copied or stored, can't be part of a type or
choice. Only thing you can do with it is access it from the register you wrote
it to. And even that not past a call instruction. Important detail: `free()`
is a call. So an address to something on the heap can never be invalid if the
program type-checks.

<reg x> : (address T m) <- advance <reg/mem> : (array T m), <reg offset> : (index T)