第7章高水準プログラミング言語
Parallel Programming並列プログラミング
This paradigm refers to the computer’s ability to process multiple tasks at the same time, which is especially useful in modern multicore systems. However, a program may not be allowed to execute across multiple cores without proper synchronization. For example, the program in one core may need a result or data item that is being produced by the program in another core. Therefore, effective parallel programming must have the tools by which to synchronize processes. The Ada programming language introduced built-in support for concurrent programming using tasks and protected objects. Ada tasks are defined with the task keyword and have their own declarations and executable parts. While tasks help structure programs in concurrent flows, protected objects safeguard shared data, ensuring that only one task can access them at a time to avoid race conditions and deadlocks. Other examples of HLLs that support parallel programming include C++, Java, and C.
英語のヒント
このパラダイムは、コンピューターが複数のタスクを同時に処理する能力を指し、現代のマルチコアシステムで特に役立つ。しかし、適切な同期なしに、プログラムを複数のコアにまたがって実行することは認められない場合がある。たとえば、あるコアのプログラムが、別のコアのプログラムが生成している結果やデータ項目を必要とすることがある。そのため、有効な並列プログラミングには、プロセスを同期させる道具が必要である。Adaプログラミング言語は、タスクと保護オブジェクトを使い、並行プログラミングを支える機能を組み込んだ。Adaのタスクはtaskキーワードで定義し、独自の宣言と実行部分を持つ。タスクがプログラムを並行した流れへ構造化する一方で、保護オブジェクトは共有データを守り、一度に一つのタスクしかアクセスできないようにして、競合状態やデッドロックを防ぐ。並列プログラミングに対応するほかのHLLには、C++、Java、Cなどがある。
Implementation Approaches実装の方法
As we have learned, language implementations are commonly differentiated into those based on compilation and those based on interpretation. Many modern languages make use of a hybrid execution style.
英語のヒント
すでに学んだように、言語の実装は、一般に、コンパイルに基づくものと、解釈に基づくものに分けられる。現代の多くの言語は、両方を組み合わせた実行方式を使う。
Pure Compilation
純粋なコンパイル
In pure compilation, programs are translated directly into machine language. The compiler takes the entire high-level source code program and produces an equivalent object code. The compiler is not used in the actual execution of the program; the object program is launched by the operating system and executes on the underlying machine from start to finish as shown in Figure 7.7.
英語のヒント
純粋なコンパイルでは、プログラムを直接機械語へ翻訳する。コンパイラーは、高水準のソースコード全体を受け取り、等価なオブジェクトコードを生成する。実際にプログラムを動かすとき、コンパイラーは使わない。図7.7のように、OSがオブジェクトプログラムを起動し、土台となるマシン上で、最初から最後まで実行する。

attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license · CC BY 4.0 · Source出典
Figure 7.7 A sample C++ source program is compiled into machine language to run on a particular platform. (attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license)
図7.7 C++のサンプルソースプログラムを、特定のプラットフォームで動く機械語へコンパイルする。(出典:著作権 Rice University、OpenStax。CC BY 4.0ライセンス)
The advantages of pure compilation are better performance and better code analysis to detect source code typing errors. The disadvantage is that the compiled program is platform dependent and must be recompiled for other target machines. Examples of purely compiled languages include C and C++.
英語のヒント
純粋なコンパイルの利点は、性能がよいことと、ソースコードの型の誤りを検出するために、よりよくコードを解析できることである。欠点は、コンパイル済みのプログラムがプラットフォームに依存し、別の対象マシン向けには再コンパイルが必要なことだ。純粋にコンパイルする言語の例には、CとC++がある。
Pure Interpretation
純粋な解釈
In pure interpretation, programs are translated by another program known as an interpreter. The interpreter executes the program line by line. Because the interpreter executes the program, it is not platform dependent and is designed to execute code for the platform on which it resides. The disadvantages of interpretation are the slower execution speed due to having to both translate and run each line. Examples of purely interpreted languages are JavaScript, PHP, and Python.
英語のヒント
純粋な解釈では、インタープリターという別のプログラムが、プログラムを翻訳する。インタープリターは、プログラムを一行ずつ実行する。インタープリターが実行を担当するため、プログラムはプラットフォームに依存せず、インタープリターは、自分が置かれたプラットフォームでコードを実行するよう設計されている。解釈の欠点は、各行を翻訳して実行する必要があるため、実行速度が遅いことである。純粋に解釈する言語の例は、JavaScript、PHP、Pythonである。
Hybrid Implementation
混成実装
Some language implementation systems are a mix of compilers and interpreters which is known as hybrid implementation, a method of language translation which involves the use of both a compiler and an interpreter. The compiler first translates the HLL programs to an intermediate language, a language that is generated from programming source code, but that the CPU cannot typically execute directly. Some hybrid implementations allow easy interpretation during execution using just-in-time (JIT) translation, in which intermediate language is translated and executed exactly when needed. This method is much faster than pure interpretation.
英語のヒント
言語実装システムの中には、コンパイラーとインタープリターを組み合わせたものがあり、混成実装という。これは、両方を使う言語の翻訳方法である。まず、コンパイラーがHLLのプログラムを中間言語へ翻訳する。中間言語は、プログラムのソースコードから生成されるが、通常、CPUは直接実行できない。混成実装の中には、実行時に解釈しやすくするために、ジャストインタイム(JIT)翻訳を使うものがある。これは、必要になったその時点で中間言語を翻訳して実行する。この方法は、純粋な解釈より、はるかに速い。
Java is a good example of a hybrid implementation system, purposed to give the language platform independence. As illustrated in Figure 7.8, the compiler translates the HLL source code to intermediate bytecode, object code produced by Java compilation which is then interpreted by the Java virtual machine (JVM), the Java interpreter that translates bytecode into executable code. This enables the same source to be used on all platforms for which a JVM has been constructed.
英語のヒント
Javaは、言語をプラットフォームから独立させることを目的とする、混成実装システムの好例である。図7.8のように、コンパイラーはHLLのソースコードを、中間のバイトコードへ翻訳する。バイトコードは、Javaのコンパイルによって作るオブジェクトコードであり、次にJava仮想マシン(JVM)が解釈する。JVMは、バイトコードを実行可能コードへ翻訳する、Javaのインタープリターである。この仕組みによって、JVMが作られているすべてのプラットフォームで、同じソースを使える。

attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license · CC BY 4.0 · Source出典
Figure 7.8 A Java source program is compiled into an intermediate language then interpreted to produce and execute object code to run on a particular platform. (attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license)
図7.8 Javaのソースプログラムを中間言語へコンパイルし、次にそれを解釈して、特定のプラットフォームで動くオブジェクトコードを生成・実行する。(出典:著作権 Rice University、OpenStax。CC BY 4.0ライセンス)
C#, and the other .NET languages, are implemented with a different JIT system. The compiler produces managed code into which the .NET languages are translated. The runtime environment is known as the Common Language Runtime (CLR), which takes managed code and provides a JIT execution that allows all the languages to play nicely with each other. This hybrid implementation is purposed for cross-language in addition to cross-platform compatibility.
英語のヒント
C#とほかの.NET言語は、別のJITシステムで実装される。コンパイラーは、.NET言語を翻訳したマネージコードを生成する。実行環境は、Common Language Runtime(CLR、共通言語ランタイム)と呼ばれ、マネージコードを受け取り、すべての言語が互いにうまく連携できるJIT実行を提供する。この混成実装は、プラットフォーム間だけでなく、言語間の互換性も目的としている。