npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

brainfucc

v1.0.1

Published

A small brainfuck interpreter for node.

Downloads

25

Readme

Brainfucc

A small brainfuck interpreter for nodejs.

Introduction

Brainfuck is the most famous esoteric programming language, it's syntax consists of only 8 commands, represented by the following characters > < + - . , [ ].

| Command | Description | | - | -----------------| | > | Moves pointer to the right. | | < | Moves pointer to the left. | | + | Adds 1 to the memory cell under the pointer. | | - | Subtracts 1 from the memory cell under the pointer. | | . | Outputs the ASCII character represented by the value present in memory cell under the pointer. (Ex: 48 => 0) | | , | Input a character and stores it's value in the memory cell under the pointer. | | [ | Jump past the matching ] if the cell under the pointer is 0. | | > | Jump back to the matching [ if the cell under the pointer is nonzero.|

Installation

$ npm install brainfucc

Basic usage

const brainfucc = require('brainfucc')

// Call brainfucc function.
brainfucc('+[-[<<[+[--->]-[<<<]]]>>>-]>-.---.>..>.<<<<-.<+.>>>>>.>.<<.<-.')

The above code will output hello world in the console.

Features

Memory Structure

  • Brainfucc implements the memory as an array of 8-bit integers raging from 0 to 255.

  • This memory wraps, so if you decrement a 0 it becomes a 255 and if you increment a 255 it becomes a 0.

  • Memory by default has 30000 cells, initialized as 0.

Options

  • memory - Controls the number of memory cells available to the code (Default = 30000).
// Makes available 5 memory cells. The code bellow outputs '0'.
brainfucc('++++++[> ++++++++ < -] > .', { memory: 5 })

// Initializes
//  v
// [0,0,0,0,0]
  • delay - Controls the delay between the execution of each command, in milliseconds (Default = 0).
// Forces a 10 millisecond delay between each command execution.
brainfucc('+[-[<<[+[--->]-[<<<]]]>>>-]>-.---.>..>.<<<<-.<+.>>>>>.>.<<.<-.', { delay: 10 })
  • debug - Display before each command, the current code position, loop stack and memory condition (Default = false). OBS: Memory condition is only displayed if the memory parameter is set to a value smaller than 51.
// Displays information about the current state of the machine at each step.
// The code bellow outputs '0'.
brainfucc('++++++[> ++++++++ < -] > .', { debug: true, memory: 5, delay: 200 })

Comments and whitespaces

  • Brainfucc ignores every character except for the 8 brainfuck symbols > < + - . , [ ]. So comments can be made with any other characters.
// The code bellow will still output 'hello world'.
brainfucc('+[-[<<[+[--->]-[<<<]]]>>>-]>-.---.>..>.<<<<-.<+.>>>>>.>.<<.<-. returns a hello world!')

// Brainfucc also ignores spaces and newlines so
// the code bellow will still output 'hello world'.
brainfucc(`+[-[<<[+[--->]-
[<<<]]]>>>-]>-.---.>..>.<<<<-.
<+.>>>>>.>.<<.<-. 
returns a hello world!`)

Code validation and Runtime errors

  • Brainfucc checks the code before running for mismatched loop brackets. If any dangling brackets are encountered it throws an exception.
// The code bellow will throw an exception.
brainfucc('[[]')
  • If the code tries to access unavailable memory, Brainfucc throws an exception.
// The code bellow will throw an exception for 
// trying to access memory at the -1 position.
brainfucc('<')


// The code bellow will throw an exception for trying to 
// access memory greater than the number of cells alocated.
brainfucc('>>>', { memory: 3 })

Contributing

If you find a bug or think that something is hard to understand feel free to open an issue or contact me on twitter @cvmcosta, pull requests are also welcome :).


License

APACHE2 License