Coder Social home page Coder Social logo

esolangs's People

Contributors

meiao avatar

Watchers

 avatar  avatar

esolangs's Issues

Brainfuck optimization - allow instructions to have a value and remove obsolete commands

Adding values to some instruction will allow multiple commands to be executed in a single pass.
Eg. instead of incrementing the data 5 times, the data can be increased by 5.

This will also allow for some instructions to be removed. As subtraction can be made by adding a negative number.

This feature by itself will make no difference in the code execution, but sets up for other optimizations.

Brainfuck optimization - create noop instruction

The noop instruction will be temporarily added during optimization and should be later be removed.
The final bytecode after all optimizations should not contain any noops, but the VM should handle them gracefully, in case any is left.

Brainfuck optimization - remove noops

Removing noops will require that the start and end of blocks' values be changed.

The function shall receive the optimized IR instructions in a vector (source).
Keep a counter for the noops and create another vector for the new instruction list.
Then for each instruction in the source vector, if it is a:

  • Noop, then increment the noop counter
  • a start or end block, create another start/end block instruction with the value of the instruction just read, decreased by the noop counter and add it to the new vector.
  • another operation, clone that operation into the new vector.

Brainfuck optimization - group together multiple invocations of the same command

To decrease the number of instructions when multiple similar commands are grouped, these can be grouped as in the example:

For example:

IncDataPointer(1)
IncDataPointer(1)
IncDataPointer(1)
IncDataPointer(-1)

can become:

IncDataPointer(2)
Noop
Noop
Noop

This optimization can be done to IncDataPointer and IncData. But all the commands must be of the same type and must be sequentially in the code.

The Noops are added so the blocks' start_block_instr and end_block_instr are not changed by this optimization.
They shall be removed by a later optimization.

Note:

IncDataPointer(1)
IncDataPointer(-1)

should become:

Noop
Noop

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.