Giter Site home page Giter Site logo

extremlapin / fast_brainfuck.lua Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 0.0 524 KB

High performance brainfuck transpiler/interpreter for Lua with FFI support. Very fast implementation with multiple optimization passes.

License: MIT License

Lua 63.94% Brainfuck 36.06%
luajit luajit-ffi brainfuck-compiler brainfuck performance optimization ffi-support lua

fast_brainfuck.lua's Introduction


fast_brainfuck.lua's People

Contributors

extremlapin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fast_brainfuck.lua's Issues

Ideas for improvement

After testing your transpiler i found a few limitations that you could remove:

  1. programs that rely on wrapping cells don't work
  2. moving the pointer to far left of cell 0 causes segmentation faults
  3. dead code is not eliminated, e.g. a loop directly after another loop

Support dynamic var folding with more than 1 assignation

Right now, it support for example :

	while data[i] ~= 0 do
		data[i] = data[i] - 1 (inc1)
		i = i + 9 (jmp1)
		data[i] = data[i] + 1 (inc2)
		i = i - 9 (jmp2, unused)
	end

To :

	data[i+jmp1] = data[i+jmp1] + (-(data[i]/inc1))*inc2
	data[i] = 0

	while data[i] ~= 0 do
		i = i - 1 (jmp1)
		data[i] = data[i] + 3 (inc1)
		i = i + 1 (jmp2)
		data[i] = data[i] - 1 (inc2)
	end
	data[i+jmp1] = data[i+jmp1] = (-(data[i]/inc2))*inc1
	data[i] = 0

jmp 1 = -jmp2



Would be nice to support :

			while data[i] ~= 0 do
				data[i] = data[i] - 1
				i = i - 1 (jmp1)
				data[i] = data[i] - 1
				i = i - 4 (jmp3)
				data[i] = data[i] + 1
				i = i + 5 (jmp3)
			end

jmp1 + jmp2 = -jmp3

Support more than 2^16 instructions

In LuaJIT, each function has an instruction limit of 2^16 because of how the bytecode register works.

I could do a final IR scan and find isolated loops and throw it in an external local function

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.