Commit e4fd0d13 authored by A. Borzov's avatar A. Borzov
Browse files

Перенес на android.

parents
Pipeline #90 failed with stages
in 1 minute and 26 seconds
package ru.nsu.fit.borzov.kotlin_cpp.edge.machine
import ru.nsu.fit.borzov.kotlin_cpp.edge.lang.Task
class TaskExecutor(val task: Task) {
var cursor = -1;
var constants = mutableListOf<MVariable>()
val realStack = mutableListOf<MVariable>()//MStack()
init {
task.constants.forEach { (k, v) ->
constants.add(- v - 1, MVariable(k))//здесь нужно записывать данные в память.
}
}
fun run() {
while (++cursor < task.operations.size) {
val row = task.operations[cursor];
val args = mutableListOf<MVariable>()
row.varIds.forEach {
if(it < 0) {
args.add(constants[- it - 1]);
}
if(it >= 0) {
args.add(realStack[it]);
}
}
when(row.opId) {
0->doublePlus(args)
1->doubleMinus(args)
2->ifJump(args)
3->doubleMoreThen(args)
4->printDouble(args)
5->jump(args)
6->Equals(args)
7->not(args)
8->popStack(args)
9->createDouble(args)
10->createInt(args)
11->createBool(args)
12->doubleLessThen(args)
//14->doubleArraySet(args)
//15->getDouble(args)
}
}
}
private fun doubleLessThen(args: MutableList<MVariable>) {
val result = args[0]
val a = args[1].d;
val b = args[2].d;
result.b = a < b
}
/*
private fun getDouble(args: MutableList<MVariable>) {
val a = args[0].data as LDouble
val arrAddress = (args[1].data as LDoubleArray).address
val index = args[2].i()
a.value = realStack[arrAddress + index * 8].d()
}
private fun doubleArraySet(args: MutableList<MVariable>) {
val a = args[0].data as LDoubleArray
val arrAddress = a.address
val index = args[1].i()
val valToSet = args[2].d()
//a.value = realStack[arrAddress + index * 8].d()
}*/
private fun intLessThen(args: MutableList<MVariable>) {
val result = args[0];
val a = args[1].i;
val b = args[2].i;
result.b = a < b
}
private fun createDoubleArray(args: MutableList<MVariable>) {
val size = args[0].i
for(i in 0 until size) {
createDouble(mutableListOf(MVariable(0.0)))
}
}
private fun createBool(args: MutableList<MVariable>) {
realStack.add(args[0]);
}
private fun createInt(args: MutableList<MVariable>) {
realStack.add(args[0]);
}
private fun createDouble(args: MutableList<MVariable>) {
realStack.add(args[0]);
}
private fun popStack(args: MutableList<MVariable>) {
val size = args[0].i;
realStack.peek(size)
}
private fun not(args: MutableList<MVariable>) {
val b = args[0]
b.b = !b.b
}
fun doublePlus(args: List<MVariable>) {
val a = args[0]
val b = args[1].d
a.d = a.d + b
}
fun doubleMinus(args: List<MVariable>) {
val a = args[0]
val b = args[1].d
a.d = a.d - b
}
fun jump(args: List<MVariable>) {
val a = args[0].i
cursor = a;
}
fun ifJump(args: List<MVariable>) {
val cond = args[0].b
val a = args[1].i;
if (cond) {
cursor = a;
}
}
fun doubleMoreThen(args: List<MVariable>) {
val result = args[0]
val a = args[1].d;
val b = args[2].d;
result.b = a > b
}
fun printDouble(args: List<MVariable>) {
val a = args[0].d;
println(a)
}
fun Equals(args: List<MVariable>) {
val result = args[0]
val a = args[1].d;
val b = args[2].d;
result.b = a == b
}
}
private fun <E> MutableList<E>.peek(newSize: Int) {
while (size > newSize) {
removeAt(size - 1)
}
}
\ No newline at end of file
package ru.nsu.fit.borzov.kotlin_cpp.edge.user
import ru.nsu.fit.borzov.kotlin_cpp.edge.lang.Task
import ru.nsu.fit.borzov.kotlin_cpp.edge.machine.TaskExecutor
fun main() {
while1()
}
fun while1(): Task {
val task = Task()
with(task) {
//val a = createDouble(1.0)
val i = createDouble(0.0)
While({ i.lessThan(10.0) }) {
If({ i.lessThan(5.0) }) {
printDouble(i)
}
printDouble(i)
i.plus(2.0)
}
}
return task
}
fun iff() {
val task = Task()
with(task) {
val b = createDouble(5.0)
val zero = createDouble(0.0)
If({ b.Equals(zero) }) {
printDouble(zero);
}
}
val ex = TaskExecutor(task);
ex.run();
}
\ No newline at end of file
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/sample_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
\ No newline at end of file
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Kotlin_cpp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>
\ No newline at end of file
<resources>
<string name="app_name">kotlin_cpp</string>
</resources>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment