Giter Site home page Giter Site logo

ironbefunge's Introduction

IronBefunge

IronBefunge is an interpreter (written in .NET) for Befunge programs. Currently it (kind of) supports Befunge-93, but the intent is to support Funge-98 for a 2-dimensional space in the near future (see http://catseye.tc/view/funge-98/doc/funge98.markdown for details on the specification).

ironbefunge's People

Contributors

jasonbock avatar logiclrd avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

logiclrd

ironbefunge's Issues

Implement Jump Forward Instruction

From the spec:

The j "Jump Forward" instruction pops a value off the stack, and jumps over that many spaces. If there is a 1 on the stack, j will work like # does. e.g. 2j789. would print 9 and leave an empty stack. Negative values are legal arguments for j, such that 04-j@ is an infinite loop.

Implement Compare Instruction

From the spec:

The w "Compare" instruction pops a value b off the stack, then pops a value a, then compares them. (a is called a because it was the first of the two values to be pushed onto the stack.) If the a is smaller, w acts like [, and turns left. If the a is greater, w acts like ], and turns right. If a and b are equal, w does not affect the IP's delta. This instruction is not available in Befunge-93, nor Unefunge.

Updating to .NET 7 Affects New Lines

I'm not sure why, but when I upgraded to .NET 7, doing 52*, - i.e. add a line feed - doesn't quite work anymore. I updated Collatz.b98 to use d,a, and that seems to work. This also seems to affect Gasket.b98 and 99Bottles.b98, but offhand I can't figure out how to modify them so they output correctly. @logiclrd if you have any ideas let me know :).

Implement System Retrieval Instruction

From the spec:

The y "Get SysInfo" instruction, only available in Funge-98, pops one value off the stack. If the value is zero or negative, y tells you far more than you ever really want to know about the underlying Funge interpreter, operating system, and computer (and is thus usually followed soon after by a n instruction).

Note that there's far more to y than this, see the spec for details.

Implement Execution Instruction

From the spec:

The = "Execute" instruction pops a string off the stack, and attempts to execute it. How it executes it is implementation dependent. However, an implementation may support one of several standardized ways of interpreting the string, and which routine it uses can be determined by querying y. Typically methods include treating it as a C system() call would, or on a platform such as MacOS, for example, treating the string as AppleScript would be in order.

After execution, a failure value is pushed onto the stack. If this value is zero, everything went as expected. If the value is non-zero, it may be the return-code of the program that was executed; at any rate it means that the attempt to execute the program, or the program itself, did not succeed.

Note that for IronBefunge an appropriate choice would be C# :). Maybe using the Compiler API Scripting API...

Add "Dumper"

It would be nice to have some insight into the execution of a Befunge program - i.e. a list of all the instructions run, the state of the stack at those times, if an "unimplemented" was encountered, etc. Come up with a scheme to yield this kind of "insight".

Create a C# Generator

Trying to read Befunge code can be daunting. The PI program I copied from somewhere....I look at it, and it makes no sense on how it actually calculates 100 digits of PI. The idea is to translate the Befunge instructions into a C# program. I'm not sure how to do this right now, but it's an idea that I at least wanted to capture here.

Optimize Move()

Right now the Move() method in ExecutionContext is horrible. It goes through the FungeSpace one cell at a time, so if the next instruction is 1000 points away ... well, that sucks. Need to come up with a way to not only find out the next valid cell in the current direction, but also cache those values as cell references to remove the need for more lookups.

Implement Absolute Vector Instruction

From the spec:

The x "Absolute Vector" instruction pops a vector off the stack, and sets the IP delta to that vector. A vector on the stack is stored bottom-to-top, so that in Befunge, x (and all other vector-popping instructions) pops a value it calls dy, then pops a value it calls dx, then sets the delta to (dx, dy).

Implement Reverse Instruction

From the spec:

The r "Reverse" instruction multiplies the IP's delta by -1. In two dimensions, this is the equivalent of reflecting the delta of the IP about the z-axis.

Create Implicit Conversion From (int, int) to Point

This should allow code that looks like this:

new Cell(new Point(1, 0), '3')

to this:

new Cell((1, 0), '3')

The target-type new feature that's been proposed for C#.future may also make this:

new Cell(new (1, 0), '3');

Not sure about that.

Consider Making the Stack `BigInteger`

Right now the stack is typed as Stack<int>. If I wanted to calculate huge numbers for my Collatz program, it would eventually overflow the space an int can hold. While it would be slower-ish, using a Stack<BigInteger> would essentially eliminate that issue. I should do this as long as doing that doesn't break how characters are processed.

Resolve Unimplemented Instructions

The Befunge-98 spec says that if an instruction is hit that is "not understood", it should act like "r" (Reverse) (and also report this as a warning in the "dumper"). Implement this.

Is X and Y Wrong?

I'm thinking the way I have the x and y coordinates are completely wrong - they're flipped around, which means the entire code base has to be evaluated. At least the Parser and ExecutionContext. Since the programs that I have work, I think once I address this, the handlers and everything else should still work.

Implement Store Character Instruction

From the spec:

s "Store Character" is the mirror image of the ' instruction: this instead pops a value off the stack and writes it into (position + delta).

Implement Swap Instruction

From the spec:

The \ "Swap" instruction pops two cells off the stack, then pushes the first cell back on, then the second cell, in effect swapping the top two cells on the stack.

Add Tests for Executor

My tests currently just look for null arguments to the constructor. Need more than that, like testing the "end program" condition inside and outside of "string mode".

Write My Own Befunge Program

I've only ever run existing programs. I think I should try to create my own program.

I'll create something that asks for a number, and generates the Collatz sequence from it. Hopefully that's simple enough :).

Fix Output to be Cleaner

I found this site: https://www.bedroomlan.org/tools/befunge-playground, and when I run some of the examples with my interpreter the results are different (and are probably wrong). Namely:

99 Bottles of Beer - I don't have the right whitespace. For example, I output:

99bottlesof beeron the wall,
99bottlesof beer,
Take one down, pass it around,
98bottlesof beeron the wall.

It should be:

99 bottles of beer on the wall,
99 bottles of beer,
Take one down, pass it around,
98 bottles of beer on the wall.

Gasket - Should print out a Serinsipinski (sp?) gasket, but mine looks like garbage.

Implement Clear Stack Instruction

From the spec:

The n "Clear Stack" instruction (not available in Befunge-93) completely wipes the stack (popping and discarding elements until it is empty.)

Implement Iterate Instruction

From the spec:

The k "Iterate" instruction pops a value n off the stack. Then it finds the next instruction in Funge-space in the path of the IP (note that this cannot be a marker such as space or ;), treats it as an instruction, executing it n times. This takes only one tick with respect to concurrent operation.

Note that some instructions don't make much sense within the context of k unless you include zero as one of the possibilities for how many times the instruction is repeated. For example, no matter how many times after the first time k execute ^, the result is the same. However, you may pass a zero count to k, and the ^ instruction will not be executed; this can be a valuable behaviour.

Also, note k will never, ever actually execute instruction #32, space, or ;.

Implement Fetch Character Instruction

From the spec:

There is also a ' "Fetch Character" instruction in Funge-98. This pushes the Funge character value of the next encountered cell (position + delta) onto the stack, then adds the delta to the position (like #), skipping over the character (in no ticks). For example, the following two snippets perform the same function, printing a Q:

"Q",

'Q,

Implement Jump Over Instruction

From the spec:

The ; "Jump Over" marker causes the IP to jump over all subsequent instructions until the next ; marker. Like space, this takes zero ticks to execute, so that subroutines, comments, and satellite code can be insulated by surrounding it with ; markers, with no effect on multithreading. ; is truly ethereal; like space, it cannot ever be truly executed, in the sense of it taking up a tick and doing something.

Make the Stack a "Stack-Stack"

In Funge98, the stack should actually be a Stack<Stack<int>>. Change the Values property on ExecutionContext to reflect this (well, actually should be an ImmutableStack<ImmutableStack<int>>).

Implement Quit Instruction

From the spec:

The q "Quit" instruction, only in Funge-98, ends the entire program immediately (regardless of the number of IPs active in Concurrent Funge). It also pops a cell off the stack and uses that value as the return value of the Funge interpreter to the operating system.

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.