- the (ab)use of `eval` lets you do all sorts of sorcery, like instant evaluation
- the JS Redux library makes it easy to work with state, and I couldn't have implemented SCRIPT-8's time-traveling debugger without it
I love Lua's small footprint, and very early on I considered writing SCRIPT-8 in MoonScript, which compiles to Lua and has gorgeous syntax. Maybe some day.
And yes, my fantasy computer is definitely not the only open source project, there's several out there, and probably all of them are more stable than mine. Go check them out.
I know it's no longer considered hip these days, but why not support CoffeeScript?
It's easy to compile to JS on the client-side, so support should be much simpler than Lua or MoonScript. You could steal the trick TIC-80 uses to support MoonScript and say that starting a cassette with the string "use CoffeeScript" marks it as a CS file. Then it's "just" a matter of an if(String.startsWith("use CoffeeScript\n"))-check followed by an intermediate string-to-string compilation step, right?
Apart from https://github.com/usefulthink/coffeescript-from-hell/blob/m..., it takes the worst approach to spaces as syntax, because it doesn't enforce consistency, so with many devs you can end up with a file with two, four spaces, tabs all compiling but easily breaking. It has features their own syntax checker recommend not using, like defining objects without curly braces (which I think shouldn't even be a feature, but it was once so backwards compatibility)
Also, if our point of comparison is Lua and MoonScript, how do those compare?
EDIT: regarding TypeScript and PureScript, can those be compiled in the browser? By which I mean, I'm sure they can technically but do not-too-heavy implementations of such exist?
I can't answer about lua and moonscript, I'm completely unfamiliar with them.
About typescript and purescript being compiled in browser, I have never even looked into such approach, they feel unrealistic, because from the top of my head it would require a compilation tool written in JS, which is not particularly efficient for this kind of task that benefits from parallelization, specially if you are not doing deep checks, just translating code. Then there is the matter of what to do with the resulting code. Can we dump it into a file and load it programatticaly? I would be surprised if we could. Eval() the output? Not without some serious security checks that would further compromise performance.
So I believe there is no motivation in not pre-compiling and distributing the result dist code
Eh, not really: you could write the compiler in any language that compiles to JS, then use the compiled output as your compiler. In the case of TypeScript or PureScript you could basically write a self-hosting compiler this way.
> which is not particularly efficient for this kind of task that benefits from parallelization
Also, if we are talking about a somewhat modern browser that supports Web Workers parallelization is perfectly viable, no? Add Web Assembly and TextEncoder/TextDecoder in the mix and things could get even faster.
(The main performance issue I see is that due to SharedArrayBuffers being disabled (for now), each worker would need its own Uint8Array copy of the source input)
> Can we dump it into a file and load it programatticaly? I would be surprised if we could.
Saving a file is easy these days, just use a Blob.
> Eval() the output? Not without some serious security checks that would further compromise performance.
Creating Function object works. It just requires a string as input. I also don't see why this would be more insecure than compiling the same source string ahead of time - you end up running the same code. This isn't the typical user-context in which eval is dangerous.
> So I believe there is no motivation in not pre-compiling and distributing the result dist code.
You are arguing this from a technical point of view, which misses the entire point. Namely, that client-side compilation allows for browser-based apps, demos, and sharing. It greatly lowers the threshold to trying things out.
You may dislike CoffeeScript, but being able to try it out in the browser is quite a good sales pitch.
The aforementioned compiler for Walt can easily run in the browser, so last year I tried combining the two. It took me only a couple of hours to get it working.
Of course, you lose the benefit of a developer environment made for the language (but IIRC supporting compiles-to-JS languages is on the long-term Observable roadmap), but still: being able to quickly try out some simple WASM code without needing anything except a modern browser is quite powerful.
A lot of the cool features others mentioned seem like they would be overkill on a small codebase.
I started working on a bit similar project some years ago (I unfortunately abandonded it...) but I got one thing right: the ability to highlight the erroneous line. See http://write-a-game.herokuapp.com/ and try to call a non-existent function.
And JS is a great choice.
Something similar, in Lua: https://liko-12.github.io/
Others have noted that the use of JS is somewhat of a turn off, but even as a big Lua fan myself, it doesn't really bother me, I already have one (probably more than one) Lua fantasy console that covers my wishes. However, the author's comment here did mention adding MoonScript support, which would be something I would be very interested in.
For people complaining about JS vs Lua : go have a look at Amulet. This is not a fantasy console but also has an online editor and is perfectly suited for retro games. Just have a look at "Defender of the Weeping Quasar" in the example section :
It only looks a bit ~dusty due to the sepia pallet, should be good to have other choices like a neon hue, and even free custom selection. But hats off here, this is a great resource !
Not everything is about the ultimate performance.
This is so much fun, I did this last year, although initially it only ran inside Unreal Engine. Later on I did a "native" port to Linux. It can run CP/M 2.x and Wordstar (https://i.imgur.com/rIY1he8.png), it had a telnet+VT100+zmodem client for accessing BBS's (https://i.imgur.com/VszSPkB.png), and I even added a graphics mode later on (https://i.imgur.com/t3kreQM.png).
I'm working on a 68000 based one now as well. It's a really great learning experience.
When I get the time I’d love to replicate this in Go (since I’m trying to learn Go at the moment). Nice work!
Lua is a semantically cleaner alternative but it has relatively less mindshare and hence less third-party support.
That's not even remotely true. JS is only a common denominator for running code in a browser, but the lowest common denominator is still C/C++ and Java, even with native applications vs. Electron.
You keep using that word. I do not think it means what you think it means.