Git Product home page Git Product logo

w's Introduction

webassembly compiler  (github.com/ktye/w)

write wasm by hand, but more compact than wat
(source file has same size as wasm binary)

add:I:II{x+y}        /exported function
sum.I:I {x/x+:i;x}   /private function
mac:    {a:3;b:5}    /flat macro
0:      {add;sum}    /function table
sin:F:F {}           /imported function (from module "ext")
256!{010203ff}       /data section

types are I(i32) F(f64)
no preference    apl style x*a+b, but lhs is evaluted first: x a b + *
arguments        x,y,z,x3,x4,.. are typed in the function declaration f:R:XYZ..
locals           are detected at evaluation order (type is derived) r:x+y
memory/heap      C x;I x;F x (get from addr x)  x::y (write y to addr x), also x::C?y
a;b;c            sequence. c(last) returns a typed value all others must return null
x?y              if x then y
$[a;b;c;d;e]     if a then b elseif c then d else e
x/y              n-loop execute-y x-times (x evaluates to I, y must be null)
                 creates implicit local i, and n if x is an expression. no nesting.
x?/y             while x do y (y must have no type)
C?x I?x F?x I?'x type conversions ?'(signed)
sum x ; x add y  named function call, dyad(infix), names can be defined later
8:{f;g;h}        add f,g,h to function table starting at offset 8
(I.x+1)(a;b)     call indirect: return type I, function index x+1, args a b


build
$ go build w.go
$ ./w j.w > j.wasm


examples
 file   size(w)  size(wasm)  what            try online
 j.w       2642        2576  stack language  ktye.github.io/j
 k3.w     20803       20963  k interpreter   ktye.github.io/zoo/#kw


# a complete wasm module (11 bytes input / 50 bytes output):
$ echo "f:I:II{x+y}" | w | xxd
0000000: 0061 736d 0100 0000 0107 0160 027f 7f01  .asm.......`....
0000010: 7f03 0201 0005 0301 0001 070b 0203 6d65  ..............me
0000020: 6d02 0001 6600 000a 0901 0700 2000 2001  m...f....... . .
0000030: 6a0b                          ^^^^ ^^^^  j.
         ^^add(i32)                    locX locY
	 
see also
 github.com/ktye/wg (uses go subset as source instead of custom language)
 much easier to debug because the program runs as go as it is.
 but not as compact.

w's People

Contributors

ktye avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

promovicz julyip

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.