yoob.js
Version 0.4. Everything subject to change.
yoob.js is the HTML5 counterpart to yoob.
Like yoob, yoob.js:
- provides a set of components for implementing visual interpreters for esoteric programming languages (esolangs).
- is written amateurishly.
- has an API that is not particularly good, finalized, or stable.
- will eventually ship with some public-domain implementations of some esolangs (but the approach is different from yoob's; see below.)
Unlike yoob, yoob.js:
- is written in Javascript which assumes HTML5 capabilities in the browser
(mainly
<canvas>elements.) - does not provide a single canonical overarching framework which "knows" how to interpret and display and run an esolang implementation. Instead, more fitting with the dynamic approach of the Javascript language, yoob.js provides the constituent parts, and it's up to the developer to string them together into an esolang interpreter (or whatever else) and to lay it out on a web page.
- is not limited to providing support for esolang interpreters; it might be better described as a set of components for implementing esolangs "and other bizarre things".
- does not support unbounded integer values (yet; see "Planned", below).
- provides components which are meant to be used as starting points for
further modification. (It's all public domain, so build on it!) For
example,
yoob.SexpParseris meant to be used as an example or basis for a specific grammar of your choice.
yoob.js will eventually:
-
extend the idea of "a component to help implement an esolang" to encompass esolang implementations themselves. So, for example, yoob.js might include an implementation of brainfuck, but this would not be provided solely as an "end implementation" but also as a component for implementing other brainfuck-derived esolangs, and other mashups.
This emphasizes a thing with yoob, which is that while the yoob distribution may contain implementations of various languages, it does not contain the reference implementation of any language; but the reference implementations of some languages may be written in yoob. yoob allows for this approach, but yoob.js hopes to accomodate it better than just allowing for it.
Other things you should know about yoob.js are that it:
- requires features from HTML5 and related "modern" web standards. It does not try to do any feature detection or polyfilling. If it doesn't work in your browser, it doesn't work in your browser. Try another browser.
- does not rely on jQuery (yet) (possibly to its detriment.)
- does not come minified or agglomerated or anything. I mean, this isn't
production web development, we're not trying to optimize page load time
here, we just want to run us some esolangs, right? You're free to do
this yourself. May we suggest
cat yoob/*.js > yoob.js? (Note: there may one day be a small script to do this sort of thing for you, more intelligently, respecting dependencies and whatnot. Especially if you write it and send a pull request.)
API
Each yoob.js class is defined in its own .js file, and each .js file
inserts the class it defines into the yoob namespace (which it will create
as a new, empty, global namespace if it has not already been defined.)
The classes are currently:
-
yoob.Playfield, inyoob/playfield.jsA two-dimensional Cartesian grid of values which dynamically expands as needed. Objects of this class are suitable for representing programs in two-dimensional esolangs such as Befunge, as well as cellular automata, and suitable for use as a backing store for a text-terminal simulator.
-
yoob.Cursor, inyoob/cursor.jsA pointer (position vector) into two-dimensional Cartesian space (typically a
yoob.Playfield) which also has a delta (direction vector) which need not necessarily be used. -
yoob.PlayfieldCanvasView, inyoob/playfield-canvas-view.jsA view (in the MVC sense) which associates a
yoob.Playfieldwith a<canvas>element in the DOM. The playfield will be depicted on the canvas, which can also dynamically expand as needed. -
yoob.PlayfieldHTMLView, inyoob/playfield-html-view.jsA view (in the MVC sense) which associates a
yoob.Playfieldwith any element which supportsinnerHTML, although typically a<pre>element. Compared to the canvas view, this view will allow text to be rendered more nicely in some browsers, be selected for copying/pasting in the browser, and so forth. As of 0.4, this is not yet complete. -
yoob.TextTerminal, inyoob/text-terminal.jsA crude simulation of a text-based addressable console, including some functions (which need not be used) which understand simple terminal control sequences, such as LF and backspace. Requires
yoob.Playfieldandyoob.Cursorand, if you actually want to render the terminal in a browser DOM,yoob.PlayfieldCanvasViewor a compatible playfield view class. -
yoob.LineInputBuffer, inyoob/line-input-buffer.jsA crude simulation of a buffer into which the user can type a line of text. Typically it is associated with a
yoob.TextTerminalobject, on which the text is displayed as the user types it. -
yoob.Tape, inyoob/tape.jsA (theoretically) unbounded tape, like you'd find on a Turing machine, optionally associated with a
<canvas>on which it is depicted. -
yoob.TapeHead, inyoob/tape-head.jsAn object representing a position on a Tape.
-
yoob.Stack, inyoob/stack.jsAn object implementing a push-down, first-in-first-out stack of values, optionally associated with a
<canvas>on which it is depicted. -
yoob.Tree, inyoob/tree.jsA multi-purpose, n-ary tree, with optional node name (String identifier) and payload (arbitrary value.) Children are indexed by integer, 0-based. It's meant to serve two main purposes:
- as an AST (Abstract Syntax Tree) for the (initial) intermediate representation(s) of a program in an interpreter or compiler, in which case the node name is the node type and the payload is anything that might be handy, such as what the tree evaluated to; and
- as terms, roughly as defined in the science of term rewriting. In
this case the node name is the "constructor" and the payload is
probably not used. For this purpose, the
tree.jsmodule should eventually include facilities for matching and unification.
Trees, with only two children, could also be used as lists a la Lisp. In this case the node name and payload would both go unused.
-
yoob.Scanner, inyoob/scanner.jsA simple, inefficient lexical analyzer, parameterized with a table of regexps. Can also serve as a starting point for writing your own, less simple, inefficient lexical analyzer.
-
yoob.SexpParser, inyoob/sexp-parser.jsA simple recursive-descent parser which parses S-expressions. Uses
yoob.Scannerto analyze the input string andyoob.ASTto create the parsed version. Can also serve as a starting point for writing your own recursive-descent parser for some other, more complex language. -
yoob.Controller, inyoob/controller.jsA controller for animating the evolution and animation of a state (such as an esolang program state or a cellular automaton configuration). Can be hooked up to DOM elements in the UI (typically buttons.)
-
yoob.Spriteandyoob.SpriteManager, inyoob/sprite-manager.jsA set of classes for (somewhat crudely) managing independent things which can be placed, moved, be clicked, and be dragged around a canvas.
Planned
-
yoob.EnvironmentA scoped associative structure, suitable for implementing a symbol table or an evaluation context.
-
yoob.TurtleFor Turtle Graphics. This should probably be a "model" and there should be a separate
yoob.TurtleViewwhich concerns itself with rendering the turtle (and its path) on a canvas. -
yoob.ErrorFor error handling. Scanning and Parsing should accumulate a list of these objects before choking and dying. They should be displayable nicely somehow.
-
unbounded integer support
Although yoob.js will likely not ship with an unbounded integer implementation (unless someone wants to contribute one), certain classes (Tape, Stack, Playfield) should probably, one day, have limited support for working with objects which conform to a subset of the API exposed by Matthew Crumley's Javascript BigInteger class, which is unastonishing.
Used in
yoob.js is currently used in the HTML5 implementations of:
- Gemooy
- noit o' mnain worb
- Super Wumpus Land
- REDGREEN
- Circute
- Braktif
- Jaccia and Jacciata
...and soon to be used in ALPACA and the various cellular automata defined therein.
Changelog
-
version 0.1
Initial release.
-
version 0.2
Added
yoob.Controllerclass.In
yoob.Playfield: made attributes camelCase added support fortransformerargument toloadadded support for default values (setDefault) addeddumpmethod addedputDirtyandrecalculateBoundsmethods addedmapmethod -
version 0.3
Added
embed-sourcestool.Added
yoob.SpriteManagerandyoob.Spriteclasses.Moved
yoob.ASTtoyoob.Tree, and addedequals,setValue,setVariable,match, andsubstmethods to it.Added support for
editandselectcontrols inyoob.Controller.Added
get(Max|Min)(X|Y)methods toyoob.Playfield, and fixed issue with drawing cursors at wrong offsets. -
version 0.4
Moved all-display related code from
yoob.Playfieldinto a new class,yoob.PlayfieldConsoleView; in MVC parlance,yoob.Playfieldis now a "model", and to actually display it in a browser, you will need a "view".yoob.PlayfieldConsoleViewhas adrawCellmethod instead of the olddrawElementwhich will try to calldrawon the value in the cell, if it has such a method, and will also takes (and will pass) the x and y co-ordinates of the cell in the playfield being drawn.Removed
yoob.TextConsole; useyoob.TextTerminaland don't callwrite(), just callwriteRaw(), if you want a console that doesn't understand terminal control codes.Refactored
yoob.TextTerminalto be a facade over ayoob.Playfieldand ayoob.Cursor. Thus, you can now read characters from any position in the terminal — however it has lost the ability to overstrike characters. Again, sinceyoob.Playfieldis now a "model",yoob.TextTerminalitself does not concern itself with displaying the terminal (although there is a helper method to create a canvas view.)yoob.LineInputBuffergenerally improved; it listens tokeydowninstead ofkeyupfor special keys, prevents the default action for them, and has been tested in Firefox, Chrome, and Internet Explorer (recent versions.)
Commit History
@rel_0_4
git clone https://git.catseye.tc/yoob.js/
- Updates for release of yoob.js 0.4. catseye 12 years ago
- Listen for keyup, not keydown. Keyboards aren't mouse buttons! Cat's Eye Technologies 12 years ago
- Handle key input in Chrome better, and preventDefault() plz thx. catseye 12 years ago
- PlayfieldCanvasView for a terminal shouldn't try to window around. catseye 12 years ago
- Don't allow backspace if no text entered. catseye 12 years ago
- Indent less badly. catseye 12 years ago
- Fix REPL demo. catseye 12 years ago
- drawElement -> drawCell (in PfCanView); keypress/keyup ordering! catseye 12 years ago
- Several only-marginally-helpful edits to yoob.TextTerminal. catseye 12 years ago
- TextConsole is no more. TextTerminal only, now. Bug fix pending. catseye 12 years ago