インタプリタ

プログラミング言語で書かれたソースコードないし中間表現を逐次解釈しながら実行するプログラム
インタープリタから転送)

: interpreter[1]



(一)

(二)

(三)[1]



CPU

仕組み

編集

インタプリタは各仮想命令に紐づく命令ボディとディスパッチ機構をもち、ホストマシン上で実行可能になっている(例: x86マシンコードbinファイル)。仮想命令群からなるコードを引数としてインタプリタが実行されると、仮想命令に基づいて制御が移行され対応する命令ボディが実行される。これを繰り返すことでインタプリタはコードを実行する。

命令ボディ

編集

命令ボディ: instruction body、命令本体とも)は仮想命令をホスト言語でエミュレートするコードである[2]。命令ボディがホストマシンで実行されることで仮想命令が事実上実行される。すなわち命令ボディは仮想命令の実装である。例えば二項和仮想命令 ADD2 に対応してC言語で書かれた push(pop() + pop()) は命令ボディである。

ディスパッチ

編集

: dispatch[2][3]SwitchJumpJump

誤解

編集

2

1





1+#

1990





[2]

歴史

編集





EDSAC The Preparation of Programs for an Electronic Digital Computer  chapter 2  § 2-22 Interpretive subroutines [4]

 Lisp  IBM 704 Lisp [5][6][7]

1960Javap

長所と短所

編集

開発時に修正作業が容易

編集



REPLReadEvalPrintLoopBASIC

可搬性

編集

AOT

JITJITWebHTML

複雑性

編集

AOT1JIT

可読性

編集

JIT

速度

編集



1

×

CPU[8]2000CPU2010CPU: x86 Haswell[9]

 LISP  BASIC 1使PBASIC 516361018 BASIC 






バリエーション

編集

スレッデッドコード

編集

1

CALL[3]ForthForth

バイトコード

編集

Java  .NET Framework 使使

 Emacs Lisp LISP  C Open Firmware 使 Forth 使FP


抽象構文木

編集

1 (AST) 使[10]1AST[11]AST

AST[12]CRuby 1.81.9 YARV 

実行時コンパイル

編集

 (JIT) AST使1980 Smalltalk 使[13]

Java.NET FrameworkJavaScript  JIT 

トランスレータ方式

編集

他のインタプリタ言語に変換して、ターゲット言語のインタプリタ上で実行する方式。例えば CoffeeScriptJavaScript に変換されて、JavaScript インタプリタ上で実行される。

応用

編集

使

 LISP 

使

: 

デバッグ、教育用

編集

CCMS-DOSC-TerpC/C++CINTCh

パンチカード

編集

IBM 550 Numeric Interpreter (1930)  IBM 557 Alphabetic Interpreter (1954) 

プログラミング言語

編集

インタプリタとコンパイラ方式が併用のもの

編集

「共通言語ランタイム」のバイナリー・コードにコンパイルされるもの

編集

Erlang VM」(BEAM)のバイナリー・コードにコンパイルされるもの

編集

Java仮想機械」のバイナリー・コードにコンパイルされるもの

編集

JavaScript に変換されるもの

編集

Lua VM」のバイナリー・コードにコンパイルされるもの

編集

「Pコードマシン」のバイナリー・コードにコンパイルされるもの

編集

Parrot」のバイナリー・コードにコンパイルされるもの

編集

Smalltalk VM」のバイナリー・コードにコンパイルされるもの

編集

VBAのPコードにコンパイルされるもの

編集

脚注

編集

注釈

編集


(一)^ CPU

(二)^  / [?]2[]調

(三)^ 

出典

編集


(一)^ bit bit 199081519ISBN 4-320-02526-1 

(二)^ ab"An interpreter dispatches a virtual instruction body to emulate each virtual instruction in turn." Zaleski (2007). YETI: a GraduallY Extensible Trace Interpreter. University of Toronto.

(三)^ "we defined dispatch as the mechanism used by a high level language virtual machine to transfer control from the code to emulate one virtual instruction to the next." Zaleski (2007). YETI: a GraduallY Extensible Trace Interpreter. University of Toronto.

(四)^ 

(五)^ Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I 

(六)^ History of Lisp §3 S.R. Russell noticed that eval could serve as an interpreter for LISP, promptly hand coded it, and we now had a programming language with an interpreter. () The unexpected appearance of an interpreter ...()

(七)^ Hackers & Painters185 eval  eval  eval  IBM 704  LISP  LISP 

(八)^ "Conventional wisdom states that this indirect jump incurs a major performance degradation on deeply pipelined architectures because it is hardly predictable" Rohou, et al. (2015). Branch Prediction and the Performance of Interpreters - Dont Trust Folklore. International Symposium on Code Generation and Optimization, Feb 2015, Burlingame, United States.

(九)^ "we show that the accuracy of indirect branch prediction is no longer critical for interpreters." Rohou, et al. (2015). Branch Prediction and the Performance of Interpreters - Dont Trust Folklore. International Symposium on Code Generation and Optimization, Feb 2015, Burlingame, United States.

(十)^ AST intermediate representations  Lambda the Ultimate forum

(11)^ A Tree-Based Alternative to Java Byte-Codes  

(12)^ Annoucing SquirelFish

(13)^ L. A. Efficient implementation of the Smalltalk-80 systemProceedings of 11th POPL symposium1984

関連項目

編集

外部リンク

編集

この記事は2008年11月1日以前にFree On-line Dictionary of Computingから取得した項目の資料を元に、GFDL バージョン1.3以降の「RELICENSING」(再ライセンス) 条件に基づいて組み込まれている。