Star

Created With

linkIntroduction

Introducing a project which I have only ambitions so far for is kind of difficult, although I have written a proof of concept in JavaScript. Here we go anyway.

linkExamples

Just to give you an idea of what you might be able to do with this project, I have written a standalone and module-like set of examples here.

Note that these examples currently do not work. There is no utility called cookiec or cookie available for installation yet or a cookie-lang npm package ready for download. It is currently being worked on here, so if you want come and contribute to speed along the process of writing a full blown compiler in C++, along with all of the utilities shown in action here.

The rest of this documentation is written like they already exist.

linkStandalone Application

This is an example application written in Cookie that prints the command line arguments it is given.

standalone.cookie
1linkimport void sys::print(const str);

2link

3linkexport i32 main(str[] argv) {

4link for(str arg : argv) {

5link sys::print(arg);

6link }

7link

8link return 0;

9link}

1link$cookiec standalone.cookie -o standalone.wasm

2link$cookie standalone.wasm "these are" "command arguments"

standalone.wasm these are command arguments [ Exited with code 0 ]

linkModule Application

This is an example application written in Cookie that gives JavaScript some basic math functions

math.cookie
1linkexport f64 square(f64 x) {

2link return x * x;

3link}

4link

5linkexport f64 add42(f64 x) {

6link return x + 42;

7link}

8link

9linkexport f64 sum(f64[] values) {

10link f64 result = 0;

11link

12link for(f64 x : values) {

13link result += x;

14link }

15link

16link return result;

17link}

18link

19linkexport f64 PI = 3.141592653589793; // Approximately...

math.js
1linkconst Cookie = require('cookie-lang');

2link

3linkasync function main() {

4link let math = await Cookie.load('math.wasm');

5link

6link console.log('Pi is approximately ' + math.PI);

7link console.log('Adding 42 to pi gives you ' + math.add42(math.PI);

8link console.log('The square of pi is approximately ' + math.square(math.PI));

9link}

10link

11linkmain();

1link$cookiec math.cookie -o math.wasm

2link$node math.js

Pi is approximately 3.141592653589793 Adding 42 to pi gives you 45.1415926535898 The square of pi is approximately 9.869604401089358

linkWhy do we need another language?

Being entirely honest, this project is more being done just for the experience. I have never written a complete compiler before, and would love to dive in deep with what WebAssembly has to offer in its capabilities.

On the other hand, though, I have always been just a little bit disappointed in the small number of tools available for WebAssembly development. Yes, Emscripten exists, and so do online exploration tools like WebAssembly Studio, but there is nothing that was designed from scratch to compile to WebAssembly. I was also a bit tired of dealing with complicated features of C like c-style strings and lack of memory management. That is where the idea of dedicated and builtin str objects and array (type[]) modifiers came from.

But to answer this question directly: not necessarily. If you don't feel like supporting it, then don't. I am just a developer with something I want to fix.

IntroductionExamplesStandalone ApplicationModule ApplicationWhy do we need another language?

Home Introduction

Using the Compilerchevron_right



This documentation is not yet complete. Please wait for a more complete version later on.