Homework 4 (B)
  • 難度:中
  • 改善 JIT compiler,加入若干 optimization techniques
  • 紀錄若干效能最佳化技巧帶來的提昇
  • 建立新的 Hackpad,列在「+作業區
  • 標注「開發紀錄(B)」
 
 

Brainfuck programing language

Created by Urban Mueller, Brainfuck is an eight instruction Turing-complete programming language. 
 
Why to learn Brainfuck: 
Understand how basic a turing-complete programming language can be.
Turing complete means that anything you can do in one language, you can do it in another.
 
A Turing machine consists of a tape with symbols on it and a machine with a set of rules for reading and manipulating those symbols. And a bell.
 
p.8
Brainfuck Instructions
>     指到下一個位置
<     指到前一個位置
+     將目前位置的值+1
-      將目前位置的值 - 1
.      印出目前位置的值 
,      輸入一個數值並將之存入目前位置
[      如果目前位置的值為零,跳到 ] 之後一道指令
]      無條件跳回到對應的 [ 後一道指令
 
p.9 
Brainfuck compiler
! /usr/bin/awk -f
The awk language is a small, C-style language designed for the processing of regularly formatted text.
 
Every awk program has three parts: a BEGIN block, which is executed once before any input is read; a main loop, which is executed for every line of input; and an END block, which is executed after all of the input is read.
 
 
裡面介紹了interpreter, compiler, jit的差別&寫法比較:
 
  • interpreter
A Brainfuck program operates on a 30,000 element byte array initialized to all zeros.
 It starts off with an instruction pointer, that initially points to the first element in the data array or “tape.”
// Initialize the tape with 30,000 zeroes.
unsigned char tape [30000] = { 0 };
// Set the pointer to point at the left most cell of the tape.
unsigned char* ptr = tape;