234 points · by marcobambini · 8y ago · 172 comments
I was surprised by these numbers so I checked, and this is highly misleading (or very much out of date). The parser alone (https://github.com/marcobambini/gravity/blob/master/src/comp...) is over 2K lines, and with the lexer and the AST definitions the frontend of the compiler is already comfortably above 3K lines. Also, the VM (https://github.com/marcobambini/gravity/blob/master/src/runt...) is about 2K lines, but then there is another 3K lines in another "runtime" file (https://github.com/marcobambini/gravity/blob/master/src/runt...).
Still, it's not a huge project, and it might be interesting as a point of study for people interested in compilers (to bytecode) or bytecode interpreters. The input syntax looks pretty as well.
Interestingly, https://github.com/marcobambini/gravity/blob/master/src/runt... also serves as a nice illustration of the fact that if tabs are allowed in source code, people will mix them with spaces, resulting in code that looks bad unless you have the exact same tab width preferences as the author.
This seems disingenuous, I could just as well point to a piece of code and say "if spaces are allowed in source code, people will mix them with tabs". People should get over themselves and accept some people prefer a single character to specify tabbed-space and other people want the exact number of spaces. I find space characters cumbersome to work with, so I use tabs myself.
Definitely something I'll be looking at for my embedded work; it may fill a gap in my toolchain. And boo-hiss tabs.
At the risk of starting a flame-war: boo-hiss not using a formatter.
The only reliable mechanism is spaces-only.
:p
Every bit of go code shows you are wrong. If a codebase uses tabs for indentation (which is the only place they should ever be allowed) then it's a mistake to use spaces for indentation. My first ever contribution to a free software project (when I was about 15) used the wrong whitespace for indentation. They made me fix the patch and that is how I learnt about whitespace. The example you've shown is just an example of bad code standards, not tabs being bad.
Go is actually one of the few exceptions in the world due to having had "go fix" baked into the compiler/ecosystem from the start. That makes a huge difference.
It's also quite a simple language and is pretty easy to auto-format reasonably. Few other languages are that easy to auto-format or have that kind of culture where auto-formatting is accepted as a matter of course.
"go fix" is a different tool. (Though "go fix" does also run the formatter.)
http://journal.stuffwithstuff.com/2015/09/08/the-hardest-pro...
$ rustup component add rustfmt-preview
$ cargo fmtEdit: Ah, no, there are some indentation problems too. But it's the alignment that I first noticed because it's so jarring.
This is a result of using 'elastic tabs' which GitHub is not able to display correctly (and also the reason people will use spaces for alignment in a tab-indented project).
[1] http://micropython.org/ https://github.com/micropython/micropython/
It seems those who already know Python want either the whole Python language, or not Python at all. I guess it's easier to learn a whole new language, than to use a language you already know but where some parts are suddenly off-limits?
Depends on whom you ask I guess. The subset implemented is fairly big imo. Maybe I just got lucky but I never really missed something, and looking at the list of differences [1] that might be because most of them are rather obscure/fancy features which I usually tend to avoid anyway or don't even know exist (multiple inheritance, attributes for functions just to name some) or else can be worked around.
[1] http://docs.micropython.org/en/latest/pyboard/genrst/index.h...
The issue is everyone has this “great idea” for an embedded language to replace C which means device headers in the Lang, and that’s way too much to support.
If the goal is to replace C imo it’s a waste of time. But there is a market IMO for an embedded lang that you can execute tests and scripts from C in a VM that can foreign function interface back to C functions.
There is on that uses JS called mJS but I found the one of the guys that supports it to be extremely rude and unhelpful. Documention is lacking. You basically need to be an expert in JS to get started. And then they doubled their ROM use age from 23k to ~50k. But it does seem to be the best out there for the goals I stated.
I’m still on the hunt.
The other target is trying to embed some interpreter in a larger application, which ends up being mostly constrained by how nice the language is as well as how nice the C API barrier ends up being.
C is certainly not going anywhere, but it is pretty cool that other options are being built to lower the barrier of entry for some application domains.
I've done some poking at various embedded JS frameworks like Duktape and it's pretty easy to trip on various memory leaks[1] that make it really hard to recommend it as a viable platform for memory constrained spaces.
[1] http://point.davidglasser.net/2013/06/27/surprising-javascri...
http://metasepi.org/doc/metasepi-icfp2015-arduino-ats.pdf
Chez Scheme used to run on 8-bit platform, too. Then there's Pascal and BASIC dialects for microcontrollers. Astrobe has Oberon dialect for ARM Cortex's. AVR-Ada lets you use Ada with AVR's. OcaPIC put Ocaml subset on PIC microcontrollers.
People are using C because most people already use C with the ecosystem benefits that follow. Although C and assembly are dominant, there are other options available if people think their pro's and con's line up with their needs.
But keep in mind that even MicroPy recommends 256k ROM, which is before your program at all, that excludes nearly all Cortex M series and 16 and 8 bit micros. So that’s what brought me to Pi in the first place.
This and JerryScript (https://github.com/jerryscript-project/jerryscript) are the two most active embedded JS engines.
eLua is famously used in the https://en.wikipedia.org/wiki/NodeMCU firmware for the ESP8266, a non-Arm based system.
[1] https://ziglang.org/But wren and Potion are much smaller. Wren added a nice work-stealing native-thread scheduler on top of potion.
Also, mruby has the benefit over most of these other languages of having had a recent thorough security audit[1].
The Lua implementation supports the creation of sandboxes to run untrusted scripts, but this is a feature that other embeddable languages (e.g. Wren, Python) don't seem to support.
I feel like this would be a basic requirement - or is it common to embed a scripting language without limiting what scripts are able to do?
Given that most of these things are volunteer projects and making strong claims about security is dangerous when you can't back it up, it's a tricky space most projects just don't want to touch.
mJS does the VM and FFI part OK, but I didn’t like some of the way it handled JS types coming back to C, it wasn’t clear for example that a C defined value passed in would return as a signed JS/NaN until converted.
Now it supports comments, file I/O, string-primitives, regular expression support and similar things:
https://github.com/skx/monkey/
Updating the lexer/parser/evaluator was nice and simple once you understand how the various parts hook together. The downside is that if you want to create a standard-library for your language you need to spend a lot of time on it.
https://github.com/FascinatedBox/lily https://news.ycombinator.com/item?id=12015158
(Interesting and very easy to modify, maybe not "production ready")
This is by far the most what the fuck language that I've seen in a long while. It displays an astonishing amount of creativity and novel (at least to me) ideas, most of which are probably bad and won't survive for long, but some of them are really cool! Things like "packed loops"
for i, j { println(list[i][j]) }
or using `return` as a variable without exiting return = 8
Really cool!Also found in the Nim language (no affiliation/loyalty, just in case anyone is curious to see an existing use of this)
https://nim-lang.org/0.18.0/tut1.html#procedures-result-vari...
A flexible/ergonomic dynamic type system is trivial in comparison. Soundness is handled at runtime when the exact value of each expression is known, and ease of use is almost a given.
https://github.com/perl11/Bla has typically the smallest and easiest to understand type inferencer and checker.
I suspect the lack of statically typed scripting languages is more of a historical accident than anything.
I generally appreciate the massive amount work that goes into something like this.
But when I want to work on a project, I am wary of using something new. I just know in my heart I'll set the wrong flag on the compiler and the binary will end up in a directory I can't find and it'll take me two days to figure out how to do it.
My question is this: if the main strength of this language is that uses Swift-like syntax, and lets you develop native apps in Android and iOS, why not just make an Android compiler for Swift?
Which ones, specifically?
It'll be a long time before anything knocks C down as #1 in the embedded space. Even as the definition of embedded stretches to include *nix variants (like Yocto), there will always be the squeeze to get rid of that and run bare metal with C.
The inheritance mechanism, implemented via interfaces, is interesting because it stresses conformance to behavior rather than explicit relationships between types. If your Circle struct type walks and talks like a Shape, then it is implicitly usable as a Shape. It's functionally identical to explicitly defined inheritance between types in other languages, but there's something about the _feel_ of developing with Go's interfaces. You begin to think more about the simple behaviors that each type should exhibit, rather than drawing hard lines in the sand about the hierarchy of relationships. Circles and Squares don't extend a base Shape type. Rather, a Circle can calculate its surface area. A Square can do the same. Conveniently, it just so happens that any type that can calculate its area is promoted to being usable anywhere a Shape is expected.
What's the reason for that, in your opinion?
Do you mean dev time or run time?
If it is dev time, I can understand it about Go vs. C and C++, not sure about JS, but vs. Python?
(I know some Go, but much more of Python.)
I know Go has a fast compiler and is somewhat fast to write and run too, sort of a cross between dev time of Python and run time of C (I've that heard from someone who used it for a startup, and others), but I would have thought Python may have somewhat of an edge (even if small) when it came to dev time, over Go, or at least that they would be about the same, all other things (like dev experience) being equal.
That's just a guess, though. Don't have data to back it up.
[1] https://github.com/anmonteiro/lumo [2] https://github.com/planck-repl/planck [3] https://github.com/nakkaya/ferret
>dynamic typing
>naked if-else bodies
I'm sorry, but I just don't see how this improves on anything. How will GravLang make me a better, more productive programmer? How will it make my programs more robust?
Don't get me wrong, as a hobby project it's fine, but as a "real" language it doesn't have any selling points to me.
Wren is another nice one:
I am all in for competition, but I can't see how both of these languages could improve over Lua.
Lua is pretty simple and elegant, but has its woes on being too flexible and wonky (especially with nil and global variables). It also doesn't support OOP syntax directly, so everyone started to create their own wonky class system, which broke easily because of Lua's wonkiness. Gravity seems like a good embedding language packaging a nice OOP syntax with a lot of syntactic sugar (such as properties and access specifiers), so I think some UI/game developers would choose this over Lua.
There is a difference here where 1/2 people something iphone can run, and the other half want something that would run on a small 32bit.
I want a scripting VM with an FFI. Lua while supposed to be able to do that just isn’t supported by anyone for that purpose.
For my own interest, do you have examples of the way other languages do it? I'm interested, and but I'm afraid to google that.
else
foo();
and writes else
foo();
bar();
which compiles, but doesn't do what you think it does. And I have seen this bug in actual projects.Secondly, along with gofmt, it prevents style wars.
If you really want to twist the knife... even Perl 5 gets this right. Even Perl 5 thinks that naked if/else bodies is too crazy and error prone.
But it is nice if the language enforces it. I would even go so far as to claim it is common sense.
Amusing how the language looks so much like Kotlin - a language released in 2011 and 3 years before Swift.
Besides Kotlin, other such modern C-like languages are Java, Dart, Go, and Groovy. But because Gravity is dynamically typed, a better peer language comparison would be Javascript, Groovy, Dart, and Swift. Each of those languages was designed for a specific platform, i.e:
* Javascript for the web in 1995
* Apache Groovy for the JVM in 2003 (still used for Gradle build scripts)
* Dart for the JVM and for Javascript (and more latterly for Fucshia, Android, and iOS) in 2011
* Swift for iOS in 2014
It's good to see modern dynamically typed languages reject Python's indentation and Ruby's `end` keyword, and settle around curly braces for scoping.Now I'm curious about the "embedded" part . Apple doesn't allow any VM or JIT to be embedded for iOS application. Either I'm missing something or else this tech is not compliant with Apple Security Guidelines.
Edit: so does "language documentation" link.
So, it looks like every other language designed in the last 40 years? This is good?
A lot of game developers attach a small scripting language to their game engines because C++ isn't a good language for rapid game logic prototyping, and takes ages to compile. The majority of them use Lua for this purpose. Lua is certainly simple and elegant, but has its shortcomings (no direct support for classes, 1-based indexing, indexing a wrong field returns nil, can accidentally declare global variables on assignment, lack of syntactic sugar...) I've looked at other languages such as Angelscript, Squirrel, Wren, etc..., to use for game development, but I think Gravity is the cleanest and has the most features so far. I'm still curious about the performance though (If it runs about the same as non-JIT Lua I'll call it a success, given how Lua is much simpler than Gravity)
Even if you aren't a game developer, scripting languages also has its use with UI development. The majority of UI developers use Javascript with a combination of web technologies, so that's one example. Even QT developers use a scripting language called Qt Quick (which also resembles Javascript a bit), because C++ can be too tedious for rapid prototyping. The author of Gravity have also developed this language for mobile UI Development, so it seems good for its intended usage.
The language isn't particularily shining on new concepts, but I think it will be very useful for some of us.
Anyone programing in Lua should be well versed in http://www.luafaq.org/gotchas.html
Gravity's class system is inflexible compared to Lua where it has Multiple Inheritance https://github.com/limadm/lua-oo Prototypical OO https://github.com/nusov/lua-object or anything else you desire.
As for extending syntax and semantics, http://lua-users.org/wiki/MetatableEvents provide a clean mechanism to do so.
Lua coroutines are more powerful than Gravity's fibers.
I was hoping that Gravity had pattern matching support, but it looks like it does not.
Given that Lua has more capabilities than Gravity could you substantiate
> Lua is much simpler than Gravity
In what ways?
The underlying problem with Lua is that it went too wild with the philosophy of "being the most expressive using the least amount of features" (so you can implement everything using only metatables). Although many would say that this is a good thing, for me it seems better for a language to have some kind of subset for which people can conform and rely on.
I have often wondered whether, rather than a new, very orthodox language, it would be more useful to have a lightweight implementation of (a subset of) an existing language?
However, my discussions about MicroPython have shown that many programmers would rather learn a new language than try to restrict themselves to a subset of one they already know. It's likely that programmers who don't know e.g. Python, would also rather learn a brand new language.
So, the number of lightweight, very orthodox languages continues to increase.
It looks a bit like Fuse Tools [2] , a tech designed for mobile designer that bypass OS Specific UI API to directly draw on the phone using the GPU , sort of similar to Flutter in core architecture.
EDIT: Do downvoters think I’m wrong? Mine isn’t really a contentious point of view—-Python and Ruby and PHP have a lot of features that make optimization difficult. Python pays my bills, so please don’t interpret my remarks as language smugness.
The main charge that python and ruby launch at each other is that the other is slow, then it doesn't matter because server costs are cheaper than human costs, then something about time to maintain and add features are the true costs and so on.
So when you mention anything about those languages being slow, and someone just walked out of a four day internet dispute on reddit...
Is it possible that mandating vectorised solutions and avoiding I/O were in fact design goals of the author?
Not disputing the comment. Looking for more details.
Could I use this on Windows and create small binary executables? Any examples of this?
From github: "Gravity has been developed from scratch for the Creo project in order to offer an easy way to write portable code for the iOS and Android platforms. It is written in portable C code that can be compiled on any platform using a C99 compiler. The VM code is about 2K lines long, the multipass compiler code is about 3K lines and the shared code is about 2K lines long. The compiler and virtual machine combined add less than 200KB to the executable on a 64 bit system."
Embedded to me means 8-32bit micros for real devices. Not PCs that happen to fit in your pocket.
200kB is out for even a fairly serious cortex M4.
If you wanted to create an app (maybe a text editor) with support for user-defined plugins, that's a good scenario for hosting an interpreter, or embedding it.