# Mapping basic SLang constructs to the JVM bytecode - Literature review
From [1] https://www.openhub.net we can get top most used languages in Open Source Projects:

And from [2] www.tiobe.com/tiobe-index

As we can see, both ratings contains C, Java, Python as one of their top languages. C is universal instrument for all developers, so Java and Python are more interesting to investigate.
### Java Programming Language Overview
Java programming language is a multiplatform language, which means it can run on any architecture that supports Virtual Machine. It was constructed in such a manner that developers can "write once, run anywhere (WORA)" [3] Mainly it is Object Oriented Programming language, but later versions also support other paradigms, such as lambda functions and generics. Within the compilation, it is first compiled to Java Bytecode, and then bytecode can run on JVM regardless of underlying computer architecture. The Authors of Java in their White Paper use these words to describe the language[4]:
1. Simple
2. Object-Oriented
3. Network-Savvy
4. Robust
5. Secure
6. Architecture-Neutral
7. Portable
8. Interpreted
9. High-Performance
10. Multithreaded
11. Dynamic
This language also works in web environment. The Java program that works in a browser is called applet. To work, it only needs a web-browser that supports Java.
#### Main constructions of the Java programing language
Java supports all common programming language constructions such as variable, loop and if-else statement. It has a C-like syntaxis.
Here are a few basic constructions:
To create a variable in java one has to explicitly set the type for it:
```
TypeA typeA = new TypeA()
```
There are three types of loops in Java:
'For' cycle, which is the most flexible one:
```
for (int i; i < n; i++){}
```
'While':
```
while(statement){}
```
'Do - While':
```
do{} while(statement)
```
Abstract notation of method is:
```
returnType methodName(ArgumentType argument){}
```
Everything in Java has to be stored in the scope of some classes ```class ClassName{}```. To access variables and methods in classes, one has to create an object - an instance of this class. Otherwise, the class can be static or abstract. The former type, all methods and variables are members of the type itself, but not of an object. In the latter - this class has to be inherited by other classes that will be used for object creation.
Interfaces are a particular case of a class that provides the "description" of a class for later use. It cannot implement any method, but it can set its name, return type and arguments. This way, the Object-Oriented Program paradigm is supported. [6]
Java also supports generics for type abstraction, but it is often criticized for its limitations.[7]
### Python Overview
Python is a high-level, general-purpose, interpreted programming language.
#### Python Interpreter
The Python Interpreter might be implemented as a C program, a set of Java classes, or something else, depending on the flavor of Python.[8] First, the Python program is compiled to "Byte Code," and then is routed to "Virtual Machine."
Slang tries to get the best of those two languages and at the same time, reinvent from scratch some concepts that the authors of Slang consider out-of-date.
### Slang Overview
Slang is composed as a machine-independent language. Its semantics has a high level, and it is not oriented to any specific software (such as OS) or hardware. The program on Slang is composed of independently stored and compiled blocks with a specific interface. The sequence and entry point of these blocks are stored in the config file.

Slang is a static typing language. It means that a type stays the same all the time for a specific object. The type might be explicitly stated by the developer, or it might be interfered with by the compiler.
Slang is a multiparadigm language. It might be used for different ways of programming, for instance, Object-Oriented Programming, generic and functional programming.
Slang supports the concept of type (class) with all its necessary components of it, such as inheritance, polymorphism, and name incapsulation. It is implemented with ```units```. It also supports abstract classes and multiple inheritances.
A Unit informally can be described as a simple aggregation of logically connected data and functions in one component. More strictly, it can be described as a set of attributes and sub-programs that can be parameterized with type or constant and can be used for making new types, creating new containers with inheritance mechanism, or for straightforward use of attributes and sub-programs of this container in other container and standalone programs.
Slang supports multiple inheritance. One unit can inherit several other units.
<!-- ADD ABOUT CONTRACTS. What is precondition, postcondition, invariants. -->
Slang supports parallel programming by providing a convenient set of methods for it. It also supports automatic parallelism.
### JVM
Java Virtual Machine is the abstract computer on which the Java program runs.
It uses both compilation and interpretation to achieve platform independence.
The overall flow for the compilation of java program:

During the compile time, the .java transforms into the .class bytecode. Then bytecode is run on specific JVM for the specific platform. It uses the Just-In-Time compiler to transform Java bytecode to the native code for the platform. The result native code runs on a specific computer.
<!-- ### Add About JIT compiler -->
#### The Lifetime of a Java Virtual Machine
For each application, a new JVM instance will be created. Then Virtual Machine calls the main() method of some initial class. Any class can be used as it if the one has the main() method. This method accepts the array of String arguments. The application starts in the initial thread.
There exist two types of threads: daemon and non-daemon. The initial thread is a non-daemon thread.
JVM, by itself, uses Daemon threads. For example, garbage collection. The application can mark any thread as a daemon.
<!-- (ADD: what is non-daemon thread) -->
The application terminates after all non-daemon threads are finished, or the exit() is called from the application.
Per each JVM, there is a class loader system and the execution engine. The classloader system is responsible for loading types (classes and interfaces) given names of it. The execution engine is a mechanism that is responsible for executing instructions from loaded classes.

The memory organization is specific for each platform. A virtual machine places an object from the class files onto the heap. It takes information about the type from the binary data contained in the class file. The stack stores information about method invocations for the thread, including its local variables, the parameters with which it was invoked, its return value, and intermediate calculation. The stack is composed of stack frames.
When the new method is invoked, the JVM puts a new frame to the stack. When the methods finish, Virtual Machine pops it from the stack.
<!-- ### .NET
-->
### Python Virtual Machine
Python Virtual machine takes care of running Opcode (python Bytecode) on a specific platform.

The abstract representation of the stack-based machine
All static information about the Python program is stored in PyCodeObject.
<!-- ### Problems of Mapping Slang to Java Bytecode
Slang is too wide in order to be able to implement mapping everything to Java Bytecode. I will implement only specific basic constractions:
#### Variables
TODO Slang notation -> Java notation
#### Loops
TODO Slang notation -> Java notation
#### Conditions
TODO Slang notation -> Java notation
TODO ask Eugene Zouev -->
<!-- https://www.ics.uci.edu/~brgallar/week9_3.html
http://jasonleaster.github.io/2016/02/21/architecture-of-python-virtual-machine/ -->
<!-- ### Задняя часть компиляции
Поискать статью
Кауфман
Штаркман
Кто то из них написал статью
Проекционный подход к созданию компиляторов
То что нужно делать
Mapping - проекция
Поискать эту тему
старая статья -->
<!-- ### В конце должно логически вытекать то что будет дальше
### Хорошо бы закончить словами о том
что на основании этого обзора мы формулируем нашу работу (цели, задачи) -->
### References
1) https://www.openhub.net
2) www.tiobe.com/tiobe-index
3) https://www.computerweekly.com/feature/Write-once-run-anywhere
4) https://www.oracle.com/technetwork/java/langenv-140151.html
5) Core Java Volume I Fundamentals 11th Edition - S. Hortsmann
6) JAVA AND OBJECT-ORIENTED PROGRAMMING PARADIGM DEBASISH JANA
7) https://web.archive.org/web/20071010002142/http://weblogs.java.net/blog/arnold/archive/2005/06/generics_consid_1.html
8) Learning Python
9) https://www.ics.uci.edu/~brgallar/week9_3.html
10) http://jasonleaster.github.io/2016/02/21/architecture-of-python-virtual-machine/
11) Кауфман
Штаркман
Проекционный подход к созданию компиляторов