Skip to content

Instantly share code, notes, and snippets.

@bowbahdoe
Last active May 22, 2016 14:53
Show Gist options
  • Select an option

  • Save bowbahdoe/5bbdf95874bfc30f0b9fae1ab42cb7cb to your computer and use it in GitHub Desktop.

Select an option

Save bowbahdoe/5bbdf95874bfc30f0b9fae1ab42cb7cb to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
import os
filename = sys.argv[1]
output_name = 'emoji'
c_code ='''
#define cell_size 1000
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main(){
char data[cell_size][cell_size] = {0};
srand(time(NULL));
int x = 0;
int y = 0;
%s
return 0;
}
'''
#small superset of bf also supported
code_equivalance = {
'+': '(data[x][y])++;\n',
'-': '(data[x][y])--;\n',
'>': 'x++;\n',
'<': 'x--;\n',
',': 'data[x][y] = getchar();\n',
'.': 'putchar(data[x][y]);\n',
'*': 'printf(\"%d\", (int) data[x][y] );\n',
'!': 'printf("\\n");\n',
'[': 'while(data[x][y]){\n',
']': '}\n',
#Happy emojis add one to the value at the location,
#sad emojis subtract
'๐Ÿ˜ƒ': '(data[x][y])++;\n',
'โ˜น': '(data[x][y])--;\n',
#right and left pointing move right and left
'๐Ÿ‘‰': 'x++;\n',
'๐Ÿ‘ˆ': 'x--;\n',
#middle finger moves up,
'๐Ÿ–•': 'y++;\n',
#pointing finger up moves up
'โ˜': 'y++;\n',
'๐Ÿ‘†': 'y++;\n',
'๐Ÿ‘': 'y++;\n',
#pointing down goes down
'๐Ÿ‘‡': 'y--;\n',
'๐Ÿ‘Ž': 'y--;\n',
#upleft arrow goes upleft
'โ†–': 'y++;x--;\n'
#upright arrow goes upright
'โ†—': 'y++;x++;\n'
#downright goes downright
'โ†˜': 'y--;x++;\n'
#downleft goes downleft
'โ†™': 'y--;x--;\n'
#doubleup arrow goes two up
'โซ': 'y+=2;\n'
#doubledown arrow goes down two
'โฌ': 'y-=2;\n'
#sleepy face waits for input then stores it in the cell
'๐Ÿ˜ช': 'data[x][y] = getchar();\n',
#kissy face prints out the value as ASCII
'๐Ÿ˜˜': 'putchar(data[x][y]);\n',
#sun and full moon w/ face start and close loops
#where it loops if the value at the end is not zero
'๐ŸŒž': 'while(data[x][y]){\n',
'โ˜€': 'while(data[x][y]){\n',
'๐ŸŒ': '}',
#winky face prints a newline
'๐Ÿ˜‰': 'printf("\\n");\n',
#open mouth suprised face waits for one char of input
'๐Ÿ˜ฎ': 'data[x][y] = getchar();\n',
#poop emoji dumps the entire stack, not pretty, dont use
'๐Ÿ’ฉ': 'for (int i = 0; i<cell_size;i++){\n \
for(int e = 0; e<cell_size;e++){\n \
printf("%d",(int) data[i][e]);\
}\
printf("\\n");\
}',
#Die emoji puts a random value between 1 and 6 in the cell
'๐ŸŽฒ': 'data[x][y] = (char)(rand() % 6) + 1;',
#nerd face prints out the value in the cell as a number
#because nerds and numbers amiright
'๐Ÿค“': 'printf(\"%d\", (int) data[x][y] );\n'
}
def loadbf(filename):
data = ''
with open(filename) as bffile:
for line in bffile:
data += line
data = [char for char in data if char in code_equivalance.keys()]
code=''
for i in data:
code+=i
return code
symbols = loadbf(filename)
code = ''
#print(symbols)
for symbol in symbols:
code += code_equivalance[symbol]
c_code = c_code % code
print(c_code)
with open("c_code.c", "w") as code_file:
code_file.write(c_code)
os.system("gcc -std=c99 c_code.c -o bf")
os.system("rm c_code.c")
๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ
๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ
๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ
๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ
๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ
๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ
๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ
๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ
๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ
๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ Stores h in the first cell
๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ
๐Ÿ˜˜
โ˜นโ˜นโ˜น e
๐Ÿ˜˜
๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ l
๐Ÿ˜˜๐Ÿ˜˜
๐Ÿ˜ƒ๐Ÿ˜ƒ๐Ÿ˜ƒ o
๐Ÿ˜˜ ๐Ÿ˜‰
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment