Skip to content

Commit

Permalink
chore: complete rework
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasgeiler committed Nov 1, 2023
1 parent 532861a commit d521904
Show file tree
Hide file tree
Showing 146 changed files with 46,720 additions and 357 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Git ignore file
# See: https://git-scm.com/docs/gitignore

# OS
.DS_Store

# IDE
.idea
.vscode

# Composer
vendor
26 changes: 0 additions & 26 deletions Example-CellSize.bf

This file was deleted.

19 changes: 0 additions & 19 deletions Example-HelloWorld.bf

This file was deleted.

3 changes: 2 additions & 1 deletion LICENSE → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License
===========

Copyright (c) 2017 Skayo
Copyright (c) 2023 Jonas Geiler

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
29 changes: 7 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
# Brainfuck-Interpreter-PHP
A Brainfuck Interpreter written in PHP.
Look into the main.php file for help.
# brainfuck-php
A brainfuck interpreter written in PHP.

## Requirements
- PHP >= 7.0
- PHP >= 7.4

## Example usage
```php
<?php
include("path/to/main.php");

$file = "path/to/HelloWorldExample.bf";
$config = [
"cellsize" => 8/* bit */,
"infinitememory" => false,
"memorysize" => 30000,
"memoverflow" => 2, // 1 = nothing, 2 = wrap, 3 = abort
"inputmode" => "string" // "string" or "char"
];

$bfi = new BFI($config);
$bfi->readFile($file);
$bfi->run();
?>
## Usage
```bash
$ ./bin/bfi.php ./examples/hello.bf
Hello World!
```
49 changes: 49 additions & 0 deletions bin/bfi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env php
<?php declare(strict_types=1);

if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'UTC');
}

if (isset($GLOBALS['_composer_autoload_path'])) {
define('COMPOSER_AUTOLOAD_PATH', $GLOBALS['_composer_autoload_path']);

unset($GLOBALS['_composer_autoload_path']);
} else {
foreach (
[
__DIR__ . '/../../autoload.php',
__DIR__ . '/../vendor/autoload.php',
__DIR__ . '/vendor/autoload.php',
] as $file
) {
if (file_exists($file)) {
define('COMPOSER_AUTOLOAD_PATH', $file);

break;
}
}

unset($file);
}

if (!defined('COMPOSER_AUTOLOAD_PATH')) {
fwrite(
STDERR,
'You need to set up the project dependencies using Composer:'
. PHP_EOL
. PHP_EOL
. ' composer install'
. PHP_EOL
. PHP_EOL
. 'You can learn all about Composer on https://getcomposer.org/.'
. PHP_EOL,
);

die(1);
}

require COMPOSER_AUTOLOAD_PATH;

$fp = fopen($argv[1], 'r');
\Brainfuck\BrainfuckInterpreter::interpret($fp);
41 changes: 41 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "jonasgeiler/brainfuck",
"description": "A brainfuck interpreter written in PHP",
"type": "project",
"homepage": "https://github.com/skayo/brainfuck-php#readme",
"license": "MIT",
"authors": [
{
"name": "Jonas Geiler",
"email": "composer@jonasgeiler.com",
"homepage": "https://skayo.dev"
}
],
"support": {
"issues": "https://github.com/skayo/brainfuck-php/issues"
},
"require": {
"php": ">=7.4"
},
"require-dev": {
"phpunit/phpunit": "^9.6"
},
"autoload": {
"psr-4": {
"Brainfuck\\": "src/"
},
"files": [
"src/constants.php"
]
},
"bin": [
"bin/bfi.php"
],
"prefer-stable": true,
"keywords": [
"experiment",
"brainfuck",
"interpreter",
"brainfuck-interpreter"
]
}
Loading

0 comments on commit d521904

Please sign in to comment.