Repository navigation
Description
...I'm just thinking from the syntax side, but not being experienced in compiler. I will just discuss on the syntax side.
I made a video to demonstrate the main ideas behind Cirru:
https://www.youtube.com/watch?v=1ShYO_A8g-0 (14mins)
Short version:
- Cirru is trying to build a syntax tree that we can edit directly
- that syntax tree has a text syntax, with parser and formatter
- that text syntax is based on indentations
- I've been thinking about it for several years and have been using it for months
For Cirru code like this:
defn add2 (x y) (+ x y)it is equivalent to a piece of data in JSON:
["defn", "add2", ["x", "y"], ["+", "x", "y"]]once you get JSON you are free to make an DOM editor or simply render to HTML/CSS:

and also it can be turned back to Cirru code as you want.
Check these links if you need details.
http://cirru.org/
https://github.com/Cirru/
https://twitter.com/cirrulang
https://github.com/Cirru/cirru-wasm-ast (mostly based on @indutny 's work)
https://github.com/Cirru/cirru-wasm-cli
From my side I got some experience using Cirru:
Pros
- Preciously we are programming by manipulating text files, we all say it's about AST, which is a tree, but we need the help of text syntax to do it. Some languages pushed syntax even further and it becomes hard for newcomers to pick up. Cirru is giving more possibilities. I mean we can manipulate the syntax tree directly now.
- Cirru syntax is simple. It's based on indentations and reduced the usage of parentheses a lot.
- Cirru syntax is flexible. When recovered from binary files, it can be turned into serveral styles of text form, such as "smart folding look like human wrote it", "expression unfolded for the purpose of add break points", "tree view for a better user interface", etc.
- I've been generating my JavaScript code and ClojureScript code in Cirru for many months, the syntax is quite handy now.
Cons
- People hate to learn one more syntax, what's worse, it's different from C, Java or Python.
- String syntax in Cirru can be confusing according to my experience introducing Cirru to others. Because Cirru was originally designed as a tree editor and people does not quote marks in a tree editor.
- After Cirru code is parsed into a tree, we need another step to turn that tree into an AST. I'm not quite clear about how compilers will handle this. So I'm not sure it's good or bad.
- I think we don't have very much experience programming with a tree rather than a text file. Our toolchains are mostly based on text files.
Even if we don't want the graphical part of CIrru, we can still try its text syntax. It's basic Lisp in indentations(with string syntax a bit strange):
https://gist.github.com/jiyinyiyong/0fc58e2ed7c641973d9b
module
export :even $even
export "odd" $odd
func $even (param $n i32) (result i32)
if (i32.eq (get_local $n) (i32.const 0))
i32.const 1
call $odd (i32.sub (get_local $n) (i32.const 1))
func $odd (param $n i32) (result i32)
store_global $scratch (get_local $n)
if (i32.eq (get_local $n) (i32.const 0))
i32.const 0
call $even (i32.sub (get_local $n) (i32.const 1))
global $scratch i32I'm a big fan of Lisp(mainly Clojure), but dislike the parentheses in Lisp. So this is my idea to fix it and that in WebAssembly.
Activity
qwertie commentedon Mar 19, 2016
You have some competition.... from me.
I made LES (LESv2), a language inspired by LISP but syntactically based on Javascript and C#. Its relationship to JSON is somewhat different - LES is a superset of JSON, rather than being convertible to JSON (one could define such a reverse mapping, of course, I just haven't done so, and if JSON code is treated as LES code and then converted with any reasonable mapping back to JSON, it would probably have to expand in size). Edit: LES is probably a more sophisticated language than Wasm needs, so I was going to propose a subset of LES to the Wasm CG, I just haven't got around to defining it yet. And I was considering other refinements.
Hmm... given that, in Cirru, an
identbecomes"ident"in JSON, what about a string like"ident"in Cirru? Are strings and identifiers exactly equivalent? And what about the dollar sign in the above code? The documentation says$ as a function to fold code, see Haskell, but I suppose that's not what's happening here.tiye commentedon Mar 19, 2016
I'm looking into the "Cirru problems" first,
For
ident, my video covered it. Yes I realise this problem as soon as I began to use it. There are already examples on solving this. It's like'something-quotedin Scheme, and:a-keywordin Clojure. My solution is to prefix that with one character, for JavaScript"str"is written in:str, and in Clojure I use|str.For
$, in Haskell it's an infix function which evaluatesxbeforefis calling in:Yeah, it's internally different in Cirru since Cirru Parser is doing syntax tree transformation at the end of parsing. I want to say the meaning is learnt from Haskell.
f $ a bis evaluated likef (a b).Back to LES... personally I don't like writing brackets, but I have to say LES is far more mature than Cirru is and Cirru is hardly a competitor as an idea at this moment(well, I suppose Scheme syntax is by now the best). But I'm still glad Scheme is not our only option to write WebAssembly :D
By the way even people don't like Cirru, I can still compile Cirru to WebAssembly by some ways..
qwertie commentedon Mar 19, 2016
How old is Cirru, by the way? It seems to me that if the CG decided they just wanted an s-expression parser, they could go with Sweet Expressions, which appear to be
2.5 years3.5 years old. I heard about sweet-expressions (a.k.a. Readable Lisp S-expressions) a couple of years ago, and I don't even use LISP. So.... I wonder, did you know about sweet expressions already when you started Cirru? Personally I think infix operators are a key to readability; sweet exprs have them but I don't see them in Cirru. Heck, if it weren't for the fact that everybody still writes LISP in s-exprs instead of sweet-exprs, I'm sure I would use a language in the LISP family by now (the real problem is that I can't learn LISP with sweet exprs: no one is teaching it that way.)Uhh, did you really mean to say that? Cirru is older than
LESLESv2 (LESv1 is 2.7 years old), it has its own domain name, and it has parsers written in a whole bunch of languages. LES is great if we want a Javascript-style syntax, but Cirru (and sweet expressions) appear to be mature.About the
$, I was referring to the code you wrote earlier like(param $n i32)- this means(param (n 132))?Edit added corrections after you replied
tiye commentedon Mar 20, 2016
Cirru was started in the middle 2012 but only as a tree editor, and later got a text syntax by the end of the year, according to my git commits and tweets at weibo. It was only a toy before I can actually compile it to JavaScript in 2015. I saw Sweet before, but I don't know how to use it or where to find its interpreter. So, I did it before Sweet.
The way I came to Cirru, I was making an AST editor after learning http://norvig.com/lispy2.html but failed to make it handy back that time with raw JavaScript. There was not React at that time, I built my first version of tree editor in canvas and it's hardly an editor I can use. So I realised I need a text syntax which looks very similar to Cirru Editor.
Clojure is OK for me, Polish notation, so prefix syntax, it feels good to me. Ever since I built my own "lispy" interpreter I found it very nice, which JavaScript syntax bothered me a lot. I mean I think Lisp is still readable comparing to C-style syntax since the later one has much more syntax rules.
Yes, I think LES is more mature in the part of WebAssembly. Well, you got a spec. Cirru does not have a spec, it only contains some special functions to help transforming code to JavaScript or Clojure, also some WebAssembly. So it's more like a code generator at this moment. However, I would say Cirru is more advanced as "an AST tree exploring project". :)
qwertie commentedon Mar 20, 2016
Edit corrected my earlier post.
LES has a spec, but it's not complete, and if the CG considers LES as the Wasm text format, I will pretty much change it according to the whims of the "important" members like @lukewagner and @jfbastien. Heck, I could even stop calling it "my" idea - if that's the price :)
The most important thing is that Wasm should choose a parser that isn't solely dedicated to Wasm itself - like s-expressions, it should be a syntax that lends itself to many different use cases. Why? Look, none of the "friendly" languages for representing syntax trees - sweet expressions, LES, Cirru - are popular. People don't use them because they aren't popular, and they aren't popular because people don't use them. Chicken and egg. I just talked to a prominent member of the C# community; he said he wouldn't use the Enhanced C# language I created, not because of anything wrong with it, but simply because "hardly anyone else knows" it.
That means WebAssembly CG has a huge opportunity that they shouldn't squander. Whatever they pick automatically becomes popular. I hope that they will choose a variation of LES, because Javacript/C syntax is by far the most popular syntactic style, and as far as I know, LES is the only language that parses a language resembling Javacript et al into a simple data structure.
Fun fact: originally LES had a Python-style mode where it was indentation-sensitive. I took that out in favor of just C/JS-style, because I think people will warm up to that more than the Python style. I don't really care one way or the other - I quite like Python's indentation-as-structure, but the important thing is to bring those LISP ideas of "syntax independent of semantics" and "code is data" over to the mainstream.
I have difficulty understanding this perspective. I mean, I've been coding for over 20 years, and in that time I have spent far, far more time learning about library APIs than syntax. More time learning semantics than syntax. Etc. C/C++ syntax is definitely confusing in some ways, but Javascript? It's a lot easier. Also, infix operators are present in natural language ("five plus four"), the order of operations is taught before high school ("1 + 2 × 3 < 9" vs "< (+ 1 (× 2 3)) 9"), and some other parts of the syntax are popular in mathematics as well as programming languages (e.g.
(tuple, of, things)and[list, of, things]).tiye commentedon Mar 20, 2016
That's far more than I have thought. Popularity matters a lot in language choosing I think. WebAssembly is still new as a compiling target so choosing a popular syntax may benefit from existing toolchains. S-expression is nice since it's simple to built from scratch and people already explored it enough to bypass the potential problems. And in my point, Cirru is just a simple version of S-expression and better designed for the future, which is enabling graphical tool in programming.
So in short, Cirru is not the best choice at this moment. But if people want 1) a cleaner version of S-expression(by using indentations), 2) build graphical tools for WebAssembly, then Cirru might be a good start to the future plans.
I've been learning programming for about 4 years, maybe 5, only. And from the day I began to learn, CoffeeScript is becoming popular and lots of ideas are making to choose an efficient way of writing code, like making less mistakes, bringing less confusions. That's why I'm exploring a new one trying to get more by using a graphical way. JavaScript syntax, in my view is tedious to write and modify. I can bear using it in large projects that enhance stability and team work, but not in all my projects that I want to code fast.
shaunlebron commentedon Mar 20, 2016
For anyone wanting quick context on this discussion: WebAssembly will be a binary format but there are some cases in which a Text Format is also desired. An official text format hasn't been decided, but S-expressions are currently used for the sake of simplicity in the spec. Hence, the discussion here on what the official text format should be by looking at alternative syntaxes explicitly designed to represent ASTs.
A way to evaluate
I want to offer that choosing a syntax may be an optimization problem of the following things:
* I think familiarity is set by community defaults, for which WebAssembly has carte blanche, as @qwertie said.
Evaluating: S-expressions
Evaluating: Cirru and LES
I like what I've seen from both, but I can't fully evaluate these for lack of experience, so I will leave it to their authors...
My thoughts
I would place less weight on familiarity and more weight on simplicity and
flexibility because that will contribute the most to future-proofing how we
express the AST of the web, which will probably be around for a while! ;)
qwertie commentedon Mar 21, 2016
@JSStats LES actually has an unlimited number of operators (sequences of punctuation marks), with precedence chosen by a set of rules based on operators from several languages, especially C/C++/Java/C#/Javascript. There is also a
backquotepseudo-operator, which lets you treat any identifier as an operator. For instance, the s-expressioncould be directly transliterated to LES in prefix notation...
or with "superexpressions"
or with a
i32.addand a superexpression...or even (worst of all) a backquote fest:
These are all equivalent, due to the equivalence of operators and "calls()". They are also ugly and not recommended; I'm just showing the different ways LES allows you to express the same thing. (Note that the
@in@int32.addis needed because the identifieri32.addcontains a dot character and we probably don't want.to be considered a binary operator.)Quite right. However, I do think it would make a lot of sense to include operators like
+in the text format, requiring the "assembler" to infer whether it'si32.addori64.add. There are other things we can readily do to make the text format more friendly. Let's consider this adder:(Incidentally, one extra
@sign makes this into valid LES code.)It could look something like this in LES:
That's if we decide users can access locals unqualified (or we could use
#xor$xor whatever); similarly we could use simply123fori32.const 123and123Lfori64.const 123. . The structure of this expression (expressed as an LES-compatible s-expression) isThe fixed set of rules is designed to reflect the existing consensus of many different programming languages. I think the existing rule set would serve Wasm quite well - but it's not a finalized spec, and if the CG wants changes, then changes there will be. Even better would be if eyeballs outside the Wasm community deliberated on it, but I'm not sure how to make that happen.
qwertie commentedon Mar 21, 2016
@JSStats The 'add' example doesn't seem familiar? It looks like Rust and Swift. Since the text format isn't used directly on the web, I was assuming a one-pass compiler wouldn't be necessary for it (and certainly one could do multiple passes over individual functions), so some conveniences can be added, so
+could be used for adding even if there is no single opcode for it. Heck, even if one really wanted to optimize the parser, that feature is still possible (given forward declarations for all functions).qwertie commentedon Mar 22, 2016
On the LES page, you'll LES code that looks like Javascript, but since Wasm is statically typed it couldn't/shouldn't look quite like JS, hence the Rust/Swift style. I haven't made a LES-to-Wasm (or vice versa) converter yet, and I've been puzzling over which language I should write a parser in... JS? C++? OCaml? Currently it's just C# which presumably doesn't interest folks here.
data-ux commentedon Apr 8, 2016
I have just published a WASM playground that can also render the code in different text formats. This way it is easy to compare the pros and cons of different formats:
http://ast.run/
I'm planning to add next rendering to Sweet-expression like format. Cirru would be interesting, too.
22 remaining items
dead-claudia commentedon Jul 23, 2016
@jiyinyiyong To be fair, I didn't actually verify the code samples. And I know Cirru is far from perfect (it can be pretty awkward IMHO). I just wanted to put out a more representative sample. 😄
(Oh, and I fixed the error, BTW.)
yurydelendik commentedon Jul 25, 2016
@isiahmeadows can you remove or change
// LESfrom your examples above? The experimental text format has no such abbreviation. I think you are mistaken the name with counterproposal's one.dead-claudia commentedon Jul 26, 2016
@yurydelendik I was referring to the raw expression syntax itself used by the two proposals to differentiate them (LES-based and Cirru-based syntaxes), not the actual syntax of the text format (which there isn't actually any ATM beyond the s-expressions used by the WASM reference interpreter and most current experimental implementations). So if I were to be technically correct, I'd make the comments
LES-basedandCirru-basedinstead, but I thought thatLESandCirruwould be sufficient given the context.To be fair, someone could theoretically invent their own syntax for it for another completely proposal (which I've considered doing so myself, but just haven't had the time to sketch it out). The ideas are pretty much limitless right now.
yurydelendik commentedon Jul 26, 2016
The @sunfishcode's strawman proposal is not LES-based (at least not yet) that's why I don't really understand why this is mentioned in the examples comments.
dead-claudia commentedon Jul 26, 2016
@yurydelendik Well...you're correct in a sense:
At this point I feel we're arguing semantics. I feel the intent was sufficient enough (although I'll add a note above explaining the technicality).
qwertie commentedon Jul 26, 2016
@isiahmeadows, my LES proposal is derived from @sunfishcode's and not the other way around (although LES itself was developed before WebAssembly, just as s-expressions were.)
dead-claudia commentedon Jul 26, 2016
@qwertie Where did I imply that? If I was, I'm sorry, and I'll fix it. (I tried to speak of theirs as purely independent, and I didn't think I referenced yours.)
qwertie commentedon Jul 26, 2016
@isiahmeadows your comment 3 days ago, which discusses "sunfishcode's LES-based proposal". (There's only one LES proposal - mine. Unless you count this second one which is also mine)
dead-claudia commentedon Jul 26, 2016
@qwertie That was part of the associated edit with this comment stemming from this discussion. I'll fix it.
dead-claudia commentedon Jul 26, 2016
@yurydelendik I'm sorry...I didn't fully differentiate the PR from the actual strawman. I apologize.
flagxor commentedon Jul 30, 2016
After some communication between implementers, we've decided to focus on having all browsers be able to display linear opcodes for the MVP timeframe. Moving to Discussion.
jfbastien commentedon May 11, 2017
Text format proposal. Closing this in favor of the proposal.