Wasp 🐝

a programming language for extremely concise web assembly modules

warning: this compiler is very alpha and error messages aren't the best, but it works and language is simple!

clojure ; main.w (extern console_log [message]) (pub defn main [] (console_log "Hello World!"))

Features

Quickstart

Wasp depends on git and rust. Make sure you have them installed before beginning.

console cargo install wasp wasp init myproject cd myproject wasp build python3 -m http.server Open up http://localhost:8000 and look in console. At this point we will have a web assembly module that has access to the standard libraries functions. More to come in this area!

If you don't have need for the standard library (or want to write your own!). This is also an option.

console wasp init myproject --no-std

At this point we will have a web assembly module with a single exported main function and nothing else.

If you think your standard library is out of date, just run wasp vendor

Simple Data Structures

Wasp is an extremely basic language and standard library. Everything is a linked list.

Linked List

clojure (cons 42 nil) ; returns the memory location of cons clojure (head (cons 42 nil) ; return the head value 42 clojure (tail (cons 42 nil) ; returns the memory location of tail

clojure (cons 1 (cons 2 (cons 3 nil)) ; returns a linked list

clojure (# cons 1 2 3) ; short hand for (cons 1 (cons 2 (cons 3 nil)))

Drawing

Using web-dom we can easily draw something to screen. Loops in wasp work differently than other languages, bbserve how this example uses recursion to rebind variables.

```clojure (extern globalgetwindow []) (extern windowgetdocument [window]) (extern documentqueryselector [document query]) (extern htmlcanvasgetcontext [element context]) (extern drawingsetfillstyle [canvas color]) (extern drawingfill_rect [canvas x y w h])

(def colors ("black" "grey" "red"))

(pub defn main [] (let [window (globalgetwindow) document (windowgetdocument window) canvas (documentqueryselector document "#screen") ctx (htmlcanvasgetcontext canvas "2d")] (loop [x 0] (if (< x 3) (do (drawingsetfillstyle ctx (memnum (+ colors (* sizenum x)))) (drawingfill_rect ctx (* x 10) (* x 10) 50 50 ) (recur [x (+ x 1)])))))) ```

See it working here

Mutable Global Data

It's often important for a web assembly modules to have some sort of global data that can be changed. For instance in a game we might have a high score.

```clojure (def high_score (0) )

(defn runmygame ... (memnum highscore (+ (memnum highscore) 100)
...) ```

Project Management

warning: this may change but it works Code dependencies are kept in a special folder called vendor which is populated by specific checkouts of git repositories.

For example a project.wasp containing:

bar git@github.com:richardanaya/bar.git@specific-bar

would result in these commands (roughly)

rm -rf vendor mkdir vendor git clone git@github.com:richardanaya/bar.git@specific-bar vendor/bar

when wasp vendor is called

Now, when wasp compiles your code, it does a few things.

Please try to use non conflicting names in meantime while this is fleshed out.

Technical Details

Types

It's easiest to think that everything is a f64 number in wasp.

Globals

Functions

Common Operators

These oprators work pretty much how you'd expect if you've used C

Testing

clojure (deftest addition (is (= 4 (+ 2 2)) "2 + 2 should be 4") (is (= 7 (+ 3 4)) "3 + 4 should be 7"))

See it working here

Why so few functions?

Wasp prefers to keep as little in the core functionality as possible, letting the standard library evolve faster and more independent community driven manner. This project currently follows a principle that if a feature can be implemented with our primitive functions, don't include it in the core compiled language and let the standard library implement it. Also that no heap based concepts be added to the core language.

Notes