BosqueLanguage

The Bosque programming language is an experiment in regularized design for a machine assisted rapid and reliable software development lifecycle.

  • Owner: microsoft/BosqueLanguage
  • Platform:
  • License:: Other
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

Bosque Programming Language

Licensed under the MIT License
PR's Welcome
Build Status

The Bosque programming language is a Microsoft Research project on building the development platform for the future of Cloud and IoT application development. The key design features of the language provide ways to avoid accidental complexity in the language, provide semantics that can be easily reasoned about (with automated tools), and in a package that is approachable for developers. The result is improved developer productivity, increased software quality, and a range of new compilers and developer tooling experiences.

Small samples of code to give a sample flavor are below (Code Snippets). A rundown of notable and/or unique features in the Bosque language is provided in the language overview section 0.
For a look at how the language works and flows in the large please see the code for a simple tic-tac-toe program that supports updating the board with user supplied moves, making an automated computer move, and managing the various game state.

Note: This repository and code represent an alpha state. This means that the language is subject to revision, there are bugs and missing functionality, and the performance is limited. Thus, we do not recommend the use of the Bosque language for any production work and instead encourage experimentation only with small/experimental side projects at this point in time.

News

Dec 2019

We have forked off the original v1 version of the language and the master branch is now for the active development of an alpha version!

  1. The language semantics have undergone substantial revisions.
  2. An Ahead-of-Time compiler is now supported to produce native code (WASM support is planned).
  3. A symbolic-tester is provided to augment the use of unit-testing.

Documentation

Code Snippets

Add 2 numbers:

function add2(x: Int, y: Int): Int {
    return x + y;
}

add2(2, 3) //5

All odd check using rest parameters and lambda:

function allOdd(...args: List<Int>): Bool {
    return args->all(fn(x) => Math::mod(x, 2) == 1);
}

allOdd(1, 3, 4) //false

Bulk update properties on Record

function updatePoint(point: {x: Int, y: Int, z: Int}, value: Int): {x: Int, y: Int, z: Int} {
    return point->updatePoint(y=value, x=-point.x);
}

updatePoint({x=1, y=2, z=3}, 5) //{x=-1, y=5, z=3}

Noneable access on optional argument:

function tryGetProperty(r?: {f: Int, k: Int}): Int? {
    return r?.f;
}

tryGetProperty({f=2, k=1}) //2
tryGetProperty()           //none

Sign (with optional argument):

function sign(x?: Int): Int {
    var! y: Int;

    if(x == none, x == 0) {
        y = 0;
    }
    else {
        y = (x > 0) ? 1 : -1;
    }

    return y;
}

sign(5)    //1
sign(-5)   //-1
sign()     //0

Using the Bosque Language

The current focus of the Bosque project is core language design. As a result there is no support for packaging, deployment, lifecycle management, etc.

Requirements

In order to build the language the following are needed:

  • 64 bit Operating System
  • The LTS version of node.js ( According to your OS )
  • Typescript (install with: npm i typescript -g)
  • A C++ compiler -- by default clang on Windows and g++ on Linux/Mac

Build & Test

The ref_impl directory contains the reference implementation parser, type checker, interpreter, and command line runner. In this directory, build and test the Bosque reference implementation with:

npm install && npm test

Note: the Z3 theorem prover is provided as a binary dependency in the repo via git LFS. To ensure these are present you will need to have git LFS installed, run git lfs install to setup the needed hooks, and pull.

Executable Generation

Bosque supports the generation of standalone command-line executables via the ExeGen tool. Details on this tool can be found in the readme.

A simple example use is to create a file called "max.bsq" with the following code:

namespace NSMain;

entrypoint function main(x: Int, y: Int): Int {
    return (x > y) ? x : y;
}

Then run the following command to produce the max.exe (on Windows executable) which can then be invoked with:

> node ref_impl\bin\runtimes\exegen\exegen.js -o max.exe max.bsq

Which will create an executable named max.exe in the current directory.

Running this executable:

> max.exe 1 5

Will output 5.

Symbolic Testing

SymTest is a powerful command line tool for symbolically testing Bosque source code. Details on this symbolic checker can be found in the readme.

A sample application for a division command line calculator would be to create a file called division.bsq with the contents:

namespace NSMain;

entrypoint function main(x: Int, y: Int): Int 
    //requires y != 0;
{
    return x / y;
}

Then run the following command to check for errors:

> node bin\runtimes\symtest\symtest.js division.bsq

Which will report that an error is possible.

Re-running the symbolic tested with model generation on as follows:

> node bin\runtimes\symtest\symtest.js -m division.bsq

Will report that an error is possible when x == 0 and y == 0.

By un-commenting the requires line the tester will assume that the required condition is always satisfied and re-running the tester will now report that the code has been verified up to the bound.

Visual Studio Code Integration

This repository provides basic Visual Studio Code IDE support for the Bosque language (currently limited to syntax and brace highlighting). The installation requires manually copying the full bosque-language-tools/ folder into your user .vscode/extensions/ directory and restarting VSCode.

Contribute

This project welcomes community contributions.

This project has adopted the Microsoft Open Source Code of Conduct.
For more information see the Code of Conduct FAQ or
contact opencode@microsoft.com with any additional questions or comments.

Please refer to Contribution Guidelines for more details.

License

Code licensed under the MIT License.

Main metrics

Overview
Name With Ownermicrosoft/BosqueLanguage
Primary LanguageTypeScript
Program languageTypeScript (Language Count: 6)
Platform
License:Other
所有者活动
Created At2019-03-10 03:37:38
Pushed At2022-10-27 20:39:01
Last Commit At2022-10-27 13:39:01
Release Count0
用户参与
Stargazers Count5.2k
Watchers Count167
Fork Count291
Commits Count576
Has Issues Enabled
Issues Count210
Issue Open Count10
Pull Requests Count304
Pull Requests Open Count0
Pull Requests Close Count15
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private