Tue Jan 7 11:52:37 CET 2020

Capture subset of C in s-expressions

;; Varible declarations.  All variables are typed and explicitly
;; initialized.  Const is default.  Non const is mut.  It's an
;; expression language with statements inside let blocks.  A let block
;; returns the value of the last expression.

(let ((:: (uint32_t)     a) 123)
     ((:: (mut uint32_t) b) 456)
  (set! b (+ a b))

;; There is no goto.  We'll implement tail calls instead.  That leaves
;; just loop and conditionals.

(while <cond> <expr> ...)

(if <cond> <e_true> <e_false>)

;; The language allows the usual abstraction/application, with some
;; restrictions on closures that cannot be implemented statically.
;; Function calls that do not block are treated as primitives.  Any
;; other applications will cause creation of continuations.

;; Continuations are represented using nested C structs/unions
;; following the sm.h model.  It seems important to keep continuations
;; explicit to allow for exact memory allocation, e.g. not using
;; stacks.  This restricts control flow but in practice is likely not
;; an issue.

;; It appears that most of this language is trivial apart from the
;; representation of continuations, so start there.  Ignoring type
;; annotation, the simplest blocking program would be a copy process
;; like:

(while $t
   (let ((line (read-line)))
     (print line)))

;; where read-line is the blocking function, and optionally print is
;; treated as rendez-vous, but for now we can just assume buffered
;; channels.