GithubHelp home page GithubHelp logo

wspace / wconrad-ruby Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 9 KB

Mirror of Wayne Conrad's Whitespace interpreter in Ruby

Home Page: https://web.archive.org/web/20120417161917/http://yagni.com/whitespace/index.html

HTML 34.68% Ruby 65.32%
whitespace-language interpreter

wconrad-ruby's Introduction

Whitespace

Whitespace is a strange language. Its tokens are space, line-feed, and tab โ€” everything else is comment. It's stack based, has console i/o, and an associative store. Yes, it's Turing complete. Yes, you'd be insane to use it. It belongs to the venerable tradition of languages like Brainf*ck, Shakespeare, and Unlambda.

Here's my Whitespace interpreter, written in Ruby. It's nothing to be proud of, but hey, what do you expect at 4 a.m.?

I stayed up for the better part of a night writing this. Why? Crazy, I guess.

Whitespace-asm

Here's my whitespace assembler, also written in Ruby.

This test program prints the alphabet: alphabet.wsa

To assemble it, run whitespace-asm like this:

./whitespace-asm alphabet.wsa

That should generate alphabet.ws.

Then run it:

./whitespace alphabet.ws
ABCDEFGHIJKLMNOPQRSTUVWXYZ

Syntax

Comments

A "#" anywhere on a line starts a comment. The rest of the line is ignored. Blank lines are ignored.

Labels

You can use this alternate syntax for a label if you wish:

unsigned-number:

Opcodes

Opcode Operand Description
Stack Manipulation push signed-number Push a number onto the stack
dup Push top of stack into the stack again
swap Swap two topmost numbers on stack
discard Pop & discard number on top of stack
Arithmetic add Pop two numbers, add, push result
sub Pop two numbers, subtract, push result
mul Pop two numbers, multiply, push result
div Pop two numbers, integer divide, push result
mod Pop two numbers, modulo, push result
Heap Access store Pop value and address; store value on heap at that address
retrieve Pop address; push onto stack the heap value at that address
Flow Control label unsigned-number Target for other flow-control ops
call unsigned-number Call subroutine
jump unsigned-number Unconditional jump
jz unsigned-number Pop top of stack; jump if it's zero
jn unsigned-number Pop top of stack; jump if it's negative
ret Return from subroutine
exit Exit interpreter
I/O outchar Pop top of stack; print it as ascii character
outnum Pop top of stack; print it as decimal number
readchar Read character from stdin & push it onto stack
readnum Read integer from stdin & push it onto stack

Whitespace-disassem

Here's my whitespace disassembler. It's nothing more than a cheap hack of my interpreter.

Yes, there's too much duplicated code between these three programs. No, I'm not going to fix it tonight. Maybe tomorrow.

Content of this site is ยฉ Wayne Conrad. All rights reserved.

wconrad-ruby's People

Contributors

nilset avatar thaliaarchi avatar wconrad avatar

Watchers

 avatar

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.