Giter Club home page Giter Club logo

webml's Introduction

WebML -- A Standard ML compiler for the Web

Build Status

WebML is to be a Standard ML (SML '97) Compiler that works on web browsers and generates WebAssembly binaries. WebAssembly binaries can be run on web browsers. This means you can run SML REPL on web browsers.

Status

Under very early stage of initial development. Compiles only minimal subset of SML codes. The garbage collector is not complete.

Links

Implemented features

Core

  • Declaration
    • val
      • basic (val ident = expr)
      • pattern (val pat = expr)
      • tyvar val 'a pat = expr
      • typed (val pat : ty = expr)
      • and (val pat = expr and pat = expr)
    • fun
      • basic (fun ident ident ... = expr)
      • pattern (fun ident pat ... = expr)
      • multi-clause (fun ident pat ... = expr | ident pat ... = expr)
      • op (fun op ident pat ... = expr)
      • tyvar (fun 'a ident pat ... = expr)
      • typed (fun ident pat ... : ty = expr)
      • and (fun ident pat ... = expr and ident pat ... = expr)
    • type (type ident = ty)
    • datatype
      • datatype ident = Con of ty | Con ...
        • basic (datatype ident = Con of ty | Con ...)
        • tyvar (datatype 'a ident = Con of ty | Con ...)
        • and (datatype ident = Con | ... and ident = Con | ...)
        • withtype (datatype ident = Con ... withtype ..)
      • datatype ident = datatype ident
    • abstype
    • exception
    • local ... in ... end
    • open ..
    • decl ; decl
      • decl decl
      • decl ; decl
    • infix
    • infixr
    • nonfix
  • Expressions
    • special constant
      • integer
      • real
        • 123.456
        • 123e456
        • 123E456
        • 123e~456
      • word
      • char
      • string
    • value identifier
    • op
    • record
      • basic ({ label = expr , ...})
      • tuple
      • 0-tuple
      • #label
    • list ([expr, ..., expr])
    • (expr; ...; expr)
    • paren ((expr))
    • let .. in .. end
      • basic (let decl ... in expr end)
      • derived (let decl ... in expr; ...; expr end)
    • function application
    • infix operator
      • L
      • R
    • typed (exp : ty)
    • exception
      • handle
      • raise
    • fn
      • basic (fn ident => expr)
      • pattern (fn pat => expr)
      • multi-clause fn pat => expr | pat => expr ...
    • andalso
    • orelse
    • if .. then .. else
    • while .. do ..
    • case .. of ..
  • Pattern
    • wildcard
    • special constant
      • integer
      • word
      • char
      • string
    • value identifier
    • op
    • record
      • basic ({ label = pat , ...})
      • wildcard (...)
      • label as variable ({ var (as pat), ...})
      • tuple
      • 0-tuple
    • list
    • paren
    • Constructor
    • infix
    • typed (pat : ty)
    • layerd (ident as pat)
  • Type
    • type variable
    • record
    • type construction
      • without param (ident)
      • with param (ty ident)
    • tuple
    • function
    • paren
  • Initial Basis
    • unit
    • bool
      • true
      • false
    • int
    • word
    • string
    • char
    • list
      • nil
      • ::
    • ref
      • ref
      • :=
    • exn
    • =
    • Match
    • Bind
  • Overloaded
    • +
    • -
    • *
    • div
    • mod
    • /
    • <
    • >
    • <=
    • >=
    • abs
    • ~

Module

not yet implemented

Program

  • Program
    • decl (decl decl ...)
    • expr (expr decl ...)
      • Note: toplevel expression expr should be treated as val it = expr

webml's People

Contributors

keens avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webml's Issues

Acculate closure conversion

Idea:
separate function-like, closure and function in type.
Then type driven closure conversion

val f: function-like = if xx then g:  function else h: closure

val f: closure = if xx then force-closure(g):  closure else h: closure

,

val f: function-like = if xx then g:  function else h: function

val f: function = if xx then g:  closure else h: function

support ;

  • declaration (decl ; decl)
  • expression ((expr; expr)
    • derived let (let ... in expr; ...; expr end)

change symbol representation

Current symbol is pub struct Symbol(pub String);. It is sufficient for representing AST, but after HIR, as they are renamed (alpha converted), they should contain versions too like pub struct Symbol(pub String, pub u64);

support polymorphic types

need to settle the direction of implementation.

  • void * style
  • template style

void * style is flexible, but may be buggy.

intrinsics

transparent webassembly api will be usefull

compiler context

Gather symbol table and ID generator to call it compiler context.

easy reductions

Perform some easy reductions to simplify intermediate representations. It helps debugging.

  • (fn x => body) arg -> let val x = arg in body end
  • let val y = x ... in ... end -> x -> y
    • let val (var1, ..., varn) = (expr1, .., exprn) in arm end -> let val var1 = expr1 ... val varn = exprn in arm end
    • let val Constructor pat = Constructor arg => arm -> let val pat = arg in arm end
  • case expr of pattern => arm -> let val pattern = expr in arm end

ml! macro

ml!(let val x = 1 in x end) => Expr::{ ty: (),inner: ExprKind::Let { ... }}

open problem: how to embed Rust values?

Document code

document "what this module (pass) do", "what is precondition, invariant, postcondition" for each items.

Split intermediate representations into for each normal form

currently we have only AST, HIR, MIR, LIR. However, AST have non typed phase and typed phase, and HIR has renamed (alpha converted) phase, flat_expr (K Normal) phase, flat_let (A Normal) phase.
Each phases should have its own representations

change closure format

At present, each captured variables are passed via argument, but it's hard to to compile so let it receive a pointer to the captured variables

JS FFI

object representation

Allocate JSValue buffer (assoc array) in JS and refer it via index(pointer).

calling convention

pass indices of JSValue (direct passing of i32, f32, f64 will be future work)

object mapping

JS Value <-> ML record via JSON?

On heap stack

Thougn WASM doesn't have function local stack-like storage, you can make it by allocating some space on the heap. This encourages for garbage collection to scan function local values.

Next Road Map

External

  • implement pattern match #26
    • in MVP, tuple pattern match
  • implement ADT #25

Internal

  • treat (user-facing) binops as usual functions in HIR. #27
    • perhaps it requires to prepare user-facing function and internal operators
  • write tests and run it on CI
    • parser
    • typecheck
    • exhausitiveness check of patterns
    • compile pass

external modules

say, _import "module" "function" (args) .
Aims to replace print with this feature for now

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.