Coder Social home page Coder Social logo

ohadrau / quartz Goto Github PK

View Code? Open in Web Editor NEW
29.0 2.0 0.0 113 KB

The official compiler for the Quartz programming language

License: GNU General Public License v3.0

Prolog 4.25% Makefile 0.84% OCaml 57.13% Shell 0.16% C++ 37.63%
programming-language concurrency functional-programming object-oriented oop beam actor-model session-types static-typing type-safety

quartz's Introduction

Quartz

Quartz is a statically typed, concurrent programming language for the BEAM VM based on the actor model with a sleek, Ruby-based syntax and support for functional and object-oriented programming.

Features

  • Familiar Ruby-like syntax
  • First-class concurrency primitives
  • Actor model message passing ร  la Erlang
  • Static typing for messages based on multiparty session types
  • Duality checking
  • Structural subtyping
  • First-class functions

Roadmap

  • AST
  • Pretty Printing
  • Core Compiler
  • Lexer
  • Parser
  • FFI
  • Tuples
  • Instance Variables (Mutability)
  • Comparison, arithmetic operators
  • Module Compiler
  • Type.t
  • Type parser
  • Type Inference/Type Checking
  • Pattern Matching
  • Syntax Cleanup

Examples

# Server: forall c < ...!{Start ~> ...?{Ok ~> Eps, Err(String) ~> Eps}}.
#         rec self.
#         [client : c]
#         ?client{Start ~> !client{Ok ~> self, Err(String) ~> self}}
session Server
  on Start from sender
    case File.open("file.txt")
    when Success(f)
      sender!Ok
      File.read_into(f, |x| sender!Value(x) end)
    else
      sender!Err("Could not open file.txt!")
    end
  end
  loop
end

# Client: (target : Server) ->
#         !target{Start ~> ?target{Ok ~> Eps, Err(String) ~> Eps}}
session Client (target : Server)
  target!Start

  on Ok from target
    on Value(status) from target
      print(status)
    end
  or Err(e)
    print("Server-side error when opening file: " ++ e)
  end
  close # Closes by default, but can be provided explicitly. Can also use `loop`.
end

fun main
  let server = spawn Server
  spawn Client(server)
end

The above example compiles into the following Erlang output:

-export([server/1, client/1, main/1]).

server(unit) ->
  receive {start, Sender} ->
    io:format("Starting~n", []),
    case file:open("file.txt") of
    {success, F} ->
       Sender!{ok, self()},
       file:read_into(F)(fun(Value) -> Sender!{{value, Value}, self()} end);
    _ ->
        Sender!{err, self()}
    end
  end.

client(Target) ->
  io:format("Starting~n", []),
  Target!{start, self()},
  
  receive
    {ok, Sender} ->
      receive {{value, Status}, Sender} ->
        print(Status),
        close(unit)
      end;
    {err, Sender} ->
      print("Server-side error when opening file"),
      close(unit)
  end.

main(_) ->
  Server = spawn(ex, server, [unit]),
  spawn(ex, client, [Server]).

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.