archives

Prototyping a new language with Haskell

Hi all!

I'm prototyping a new language with Haskell. Once I get the semantics right, I'll probably implement it more efficiently with straight C++ and LLVM. I hope to have something interactive soon. Here's the overview -

Luna is intended to expose functional, object-oriented, and most importantly, 'language-oriented' programming paradigms in one simple and machine-efficient language. It has optional dynamic binding. The 'language orientation' paradigm is what makes the optional dynamic binding so important. Luna is general purpose. It has two syntaxes - sexp and meta, with the latter being used by default and being translated to sexp for macro processing. Macro processing is what makes the direct translation to sexp so important.

----

Syntaxes -

Here's the sexp syntax (which is admittedly not super pretty) -

;; line comment

{function {fibFast n}
    {if {less n 2}
        n
        {fibUp n 2 1 0}}}

{function {fibUp max count x y}
    {if {equal max count}
        {add x y}
        {fibUp max {add count 1} {add x y} x}}}

{function {factorial n}
    {if {lessEqual n 1}
        1
        {mul n {factorial {subtr n 1}}}}}

{add 5 {mul 4 2}}
{mul 5 {add 4 2}}
{add 5 {abs {mul 4 2}}}
{add 1 {add v1 {dot v2 v3}}}
{assoc y x} ;; association list lookup
{tuple {1 2 3}}

Here's the meta syntax that maps one-to-one and is usable interchangeably with sexp syntax. It is column-sensitive once the colon is introduced. Meta syntax is transformed to sexp syntax before macro processing -

;; line comment

function: fibFast(n)
    if: n < 2
        n
        fibUp(n 2 1 0)

function: fibUp(max count x y)
    if: max = count
        x + y
        fibUp(max count + 1 x + y x)

function: factorial(n)
    if: n <= 1
        1
        n * factorial(n - 1)

4 * 2 + 5
+(4 2) * 5
abs(4 * 2) + 5
dot(v2 v3) + v1 + 1
x[y]
1; 2; 3

----

All symbol resolution in the lexical scope of 'static' will be resolved statically. All resolution in the 'dynamic' scope will be resolved dynamically. The default scope when none is specified is 'static'.

static:
    function: fibFast(n)
        if: n < 2
            n
            fibUp(n 2 1 0)

dynamic:
    function: fibUp(max count x y)
        if: max = count
            x + y
            fibUp(max count + 1 x + y x)

----

This is an overview of the definition functions -

[listed in order of likely implementation]

val: x(7) y(5) expression ;; bind immutable value(s) over an expression
var: x(7) y(5) expression ;; bind mutable variable(s) over an expression
vlz: x(1 + 1) expression ;; bind an expression to a name over another expression
function: fn(x y) expression ;; declare a function
lambda... ;; create a lambda
macro... ;; define a lisp-style macro
class... ;; class like in CLOS
data... ;; an algebraic data type
alias... ;; a type alias

----

Type inference - Types will be inferred where not specified. The type inference for the prototype will use the Hindley-Milner algorithm. Type inference algorithm will be the same for symbols resolved at compile-time with static binding as those resolved at run-time with dynamic binding.

----

Miscellanea -
meta: expression ;; specifies the enclosed expression may not use `{' or `}' sexp symbols. Prevents the two syntaxes from being used together unnecessarily.

----

So, anyways, that's the design so far. I ultimately hope I can get C-style programmers to consider using it.

Edit: Updated to current design.

Interesting Standard Libraries to Study

Lately, I've been perusing Plauger's "The Standard C Library" again with interest.

Well, it occurred to me that I'd like to examine the design of other language's standard libraries that might be particularly noteworthy for any variety of reasons: how the library might make interesting use of language (including module) features, what the libraries might include or exclude in a noteworthy manner, how the library chops up the world in terms of what is abstract and what is concrete, what is built-in to the language and what is relegated to a library routine, etc.

Needless to say, almost every programming language has a some library or another, far too many to profitably examine. So I'm looking for some particular exemplary samples, and samples of standard libraries, not samples of just nifty languages.

I'll throw in that due to the nature of the exercise, fairly stellar library documentation ranks pretty highly, if not an absolute prerequisite.

Thanks!

-Scott

Azul's Pauseless Garbage Collector

Here's Gil Tene on Azul's Pauseless Garbage Collector for the JVM.

One of the key techniques that we use is massive and rapid manipulation of virtual memory mappings. We will change mappings of virutal to physical memory at the rate of Java allocation.

And

The same read barrier I mentioned before will also intercept any attempt to read a reference to an object that has been relocated, and that allows us to lazily relocate references without needing a pause. We compact by moving an entire virtual page worth of objects, we kind of blow it up, moving all the live objects to other places and thereby compacting them. But we don't try and locate and find all the pointers to that page immediately.

The challenge seems to be that standard OSes don't currently have enough hooks for them to do this kind of thing so their runtime must live in either their custom hardware and OS or a virtual machine.