car_fmw: route and debug fsm, translator: minor fixes
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
|
||||
enum class RouteType(val id: Int) {
|
||||
FORWARD(0),
|
||||
BACKWARD(1),
|
||||
LEFT(2),
|
||||
RIGHT(3);
|
||||
}
|
||||
|
||||
object Control {
|
||||
fun run() {
|
||||
Memory.setHeap(Memory.DYNAMIC_HEAP)
|
||||
while (true) {
|
||||
executeCommand()
|
||||
Memory.cleanDynamicHeap()
|
||||
}
|
||||
}
|
||||
|
||||
fun executeCommand() {
|
||||
val task = Reader.readTask()
|
||||
when (task.type.id) {
|
||||
TaskRequest.Type.DEBUG.id -> debugTask()
|
||||
TaskRequest.Type.ROUTE.id -> routeTask()
|
||||
}
|
||||
}
|
||||
|
||||
fun debugTask() {
|
||||
val request = Reader.readDebug()
|
||||
|
||||
when (request.type.id) {
|
||||
DebugRequest.Type.MEMORY_STATS.id -> sendMemoryStats()
|
||||
}
|
||||
}
|
||||
|
||||
fun routeTask() {
|
||||
val route = Reader.readRoute()
|
||||
|
||||
val times = route.times
|
||||
val directions = route.directions
|
||||
var j = 0
|
||||
|
||||
while (j < times.size) {
|
||||
val time = times[j]
|
||||
val direction = directions[j]
|
||||
|
||||
when (direction) {
|
||||
RouteType.FORWARD.id -> Engine.forward()
|
||||
RouteType.BACKWARD.id -> Engine.backward()
|
||||
RouteType.LEFT.id -> Engine.left()
|
||||
RouteType.RIGHT.id -> Engine.right()
|
||||
}
|
||||
|
||||
Time.wait(time)
|
||||
Engine.stop()
|
||||
j++
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun sendMemoryStats() {
|
||||
val stats = DebugResponseMemoryStats.BuilderDebugResponseMemoryStats(
|
||||
DebugInfo.getDynamicHeapTail(),
|
||||
DebugInfo.getStaticHeapTail(),
|
||||
DebugInfo.getDynamicHeapMaxSize(),
|
||||
DebugInfo.getDynamicHeapTotalBytes()
|
||||
).build()
|
||||
|
||||
Writer.writeMemoryStats(stats)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
object Reader {
|
||||
fun readRoute(): RouteRequest {
|
||||
val stream = getInputStream()
|
||||
return RouteRequest.BuilderRouteRequest(IntArray(0), IntArray(0)).parseFrom(stream).build()
|
||||
}
|
||||
|
||||
fun readTask(): TaskRequest {
|
||||
val stream = getInputStream()
|
||||
return TaskRequest.BuilderTaskRequest(TaskRequest.Type.DEBUG).parseFrom(stream).build()
|
||||
}
|
||||
|
||||
fun readDebug(): DebugRequest {
|
||||
val stream = getInputStream()
|
||||
return DebugRequest.BuilderDebugRequest(DebugRequest.Type.MEMORY_STATS).parseFrom(stream).build()
|
||||
}
|
||||
|
||||
fun getInputStream(): CodedInputStream {
|
||||
val buffer = Connection.receiveByteArray()
|
||||
return CodedInputStream(buffer)
|
||||
}
|
||||
}
|
||||
|
||||
object Writer {
|
||||
fun writeRoute(route: RouteRequest) {
|
||||
val stream = makeOutputStream(route.getSizeNoTag())
|
||||
route.writeTo(stream)
|
||||
Connection.sendByteArray(stream.buffer)
|
||||
}
|
||||
|
||||
fun writeMemoryStats(stats: DebugResponseMemoryStats) {
|
||||
val stream = makeOutputStream(stats.getSizeNoTag())
|
||||
stats.writeTo(stream)
|
||||
Connection.sendByteArray(stream.buffer)
|
||||
}
|
||||
|
||||
fun makeOutputStream(size: Int): CodedOutputStream {
|
||||
val buffer = ByteArray(size)
|
||||
return CodedOutputStream(buffer)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
object Debug {
|
||||
object Tests {
|
||||
var PROGRAM_DURATION = 1000
|
||||
|
||||
fun echoUsbTest() {
|
||||
@@ -1,32 +0,0 @@
|
||||
|
||||
fun echoProto() {
|
||||
|
||||
Memory.setHeap(Memory.DYNAMIC_HEAP)
|
||||
while (true) {
|
||||
val route = readRoute()
|
||||
Leds.blink()
|
||||
go(route)
|
||||
Leds.blink()
|
||||
Time.wait(1000)
|
||||
Memory.cleanDynamicHeap()
|
||||
}
|
||||
}
|
||||
|
||||
fun readRoute(): RouteRequest {
|
||||
val buffer = Connection.receiveByteArray()
|
||||
val stream = CodedInputStream(buffer)
|
||||
val result = RouteRequest.BuilderRouteRequest(IntArray(0), IntArray(0)).parseFrom(stream).build()
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
fun writeRoute(route: RouteRequest) {
|
||||
val size = route.getSizeNoTag()
|
||||
val buffer = ByteArray(size)
|
||||
val stream = CodedOutputStream(buffer)
|
||||
|
||||
route.writeTo(stream)
|
||||
|
||||
Connection.sendByteArray(buffer)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
external fun dynamic_heap_tail(): Int
|
||||
external fun static_heap_tail(): Int
|
||||
external fun dynamic_heap_max_bytes(): Int
|
||||
external fun dynamic_heap_total(): Int
|
||||
|
||||
object DebugInfo {
|
||||
fun getDynamicHeapTail(): Int = dynamic_heap_tail()
|
||||
fun getStaticHeapTail(): Int = static_heap_tail()
|
||||
fun getDynamicHeapMaxSize(): Int = dynamic_heap_max_bytes()
|
||||
fun getDynamicHeapTotalBytes(): Int = dynamic_heap_total()
|
||||
}
|
||||
+2
-2
@@ -6,6 +6,6 @@ fun main() {
|
||||
Leds.init()
|
||||
Connection.init()
|
||||
|
||||
/* run test */
|
||||
echoProto()
|
||||
/* car task */
|
||||
Control.run()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
syntax = "proto3";
|
||||
package carkot;
|
||||
|
||||
message DebugRequest {
|
||||
|
||||
Type type = 1;
|
||||
|
||||
enum Type {
|
||||
MEMORY_STATS = 0;
|
||||
}
|
||||
}
|
||||
|
||||
message DebugResponseMemoryStats {
|
||||
int32 heapDynamicTail = 1;
|
||||
int32 heapStaticTail = 2;
|
||||
int32 heapDynamicMaxBytes = 3;
|
||||
int32 heapDynamicTotalBytes = 4;
|
||||
}
|
||||
@@ -6,11 +6,11 @@ option java_outer_classname = "Direction";
|
||||
|
||||
message DirectionRequest {
|
||||
enum Command {
|
||||
stop = 0;
|
||||
forward = 1;
|
||||
backward = 2;
|
||||
left = 3;
|
||||
right = 4;
|
||||
STOP = 0;
|
||||
FORWARD = 1;
|
||||
BACKWARD = 2;
|
||||
LEFT = 3;
|
||||
RIGHT = 4;
|
||||
}
|
||||
Command command = 1;
|
||||
int32 sid = 2;
|
||||
|
||||
@@ -2,8 +2,8 @@ syntax = "proto3";
|
||||
package carkot;
|
||||
|
||||
message RouteRequest {
|
||||
repeated int32 distances = 1;
|
||||
repeated int32 angles = 2;
|
||||
repeated int32 times = 1;
|
||||
repeated int32 directions = 2;
|
||||
}
|
||||
|
||||
message RouteResponse {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
syntax = "proto3";
|
||||
package carkot;
|
||||
|
||||
message TaskRequest {
|
||||
|
||||
Type type = 1;
|
||||
|
||||
enum Type {
|
||||
DEBUG = 0;
|
||||
ROUTE = 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,388 @@
|
||||
class DebugRequest private constructor (var type: DebugRequest.Type) {
|
||||
//========== Properties ===========
|
||||
//enum type = 1
|
||||
|
||||
var errorCode: Int = 0
|
||||
|
||||
//========== Nested enums declarations ===========
|
||||
enum class Type(val id: Int) {
|
||||
MEMORY_STATS (0),
|
||||
Unexpected(1);
|
||||
|
||||
companion object {
|
||||
fun fromIntToType (ord: Int): Type {
|
||||
return when (ord) {
|
||||
0 -> Type.MEMORY_STATS
|
||||
else -> Unexpected
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//========== Serialization methods ===========
|
||||
fun writeTo (output: CodedOutputStream) {
|
||||
//enum type = 1
|
||||
if (type.id != DebugRequest.Type.fromIntToType(0).id) {
|
||||
output.writeEnum (1, type.id)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun mergeWith (other: DebugRequest) {
|
||||
type = other.type
|
||||
this.errorCode = other.errorCode
|
||||
}
|
||||
|
||||
fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) {
|
||||
val builder = DebugRequest.BuilderDebugRequest(DebugRequest.Type.fromIntToType(0))
|
||||
mergeWith(builder.parseFromWithSize(input, expectedSize).build())
|
||||
}
|
||||
|
||||
fun mergeFrom (input: CodedInputStream) {
|
||||
val builder = DebugRequest.BuilderDebugRequest(DebugRequest.Type.fromIntToType(0))
|
||||
mergeWith(builder.parseFrom(input).build())
|
||||
}
|
||||
|
||||
//========== Size-related methods ===========
|
||||
fun getSize(fieldNumber: Int): Int {
|
||||
var size = 0
|
||||
if (type != DebugRequest.Type.fromIntToType(0)) {
|
||||
size += WireFormat.getEnumSize(1, type.id)
|
||||
}
|
||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
||||
return size
|
||||
}
|
||||
|
||||
fun getSizeNoTag(): Int {
|
||||
var size = 0
|
||||
if (type != DebugRequest.Type.fromIntToType(0)) {
|
||||
size += WireFormat.getEnumSize(1, type.id)
|
||||
}
|
||||
return size
|
||||
}
|
||||
|
||||
//========== Builder ===========
|
||||
class BuilderDebugRequest constructor (var type: DebugRequest.Type) {
|
||||
//========== Properties ===========
|
||||
//enum type = 1
|
||||
fun setType(value: DebugRequest.Type): DebugRequest.BuilderDebugRequest {
|
||||
type = value
|
||||
return this
|
||||
}
|
||||
|
||||
var errorCode: Int = 0
|
||||
|
||||
//========== Serialization methods ===========
|
||||
fun writeTo (output: CodedOutputStream) {
|
||||
//enum type = 1
|
||||
if (type.id != DebugRequest.Type.fromIntToType(0).id) {
|
||||
output.writeEnum (1, type.id)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//========== Mutating methods ===========
|
||||
fun build(): DebugRequest {
|
||||
val res = DebugRequest(type)
|
||||
res.errorCode = errorCode
|
||||
return res
|
||||
}
|
||||
|
||||
fun parseFieldFrom(input: CodedInputStream): Boolean {
|
||||
if (input.isAtEnd()) { return false }
|
||||
val tag = input.readInt32NoTag()
|
||||
if (tag == 0) { return false }
|
||||
val fieldNumber = WireFormat.getTagFieldNumber(tag)
|
||||
val wireType = WireFormat.getTagWireType(tag)
|
||||
when(fieldNumber) {
|
||||
1 -> {
|
||||
if (wireType.id != WireType.VARINT.id) {
|
||||
errorCode = 1
|
||||
return false
|
||||
}
|
||||
type = DebugRequest.Type.fromIntToType(input.readEnumNoTag())
|
||||
}
|
||||
else -> errorCode = 4
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): DebugRequest.BuilderDebugRequest {
|
||||
while(getSizeNoTag() < expectedSize) {
|
||||
parseFieldFrom(input)
|
||||
}
|
||||
if (getSizeNoTag() > expectedSize) { errorCode = 2 }
|
||||
return this
|
||||
}
|
||||
|
||||
fun parseFrom(input: CodedInputStream): DebugRequest.BuilderDebugRequest {
|
||||
while(parseFieldFrom(input)) {}
|
||||
return this
|
||||
}
|
||||
|
||||
//========== Size-related methods ===========
|
||||
fun getSize(fieldNumber: Int): Int {
|
||||
var size = 0
|
||||
if (type != DebugRequest.Type.fromIntToType(0)) {
|
||||
size += WireFormat.getEnumSize(1, type.id)
|
||||
}
|
||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
||||
return size
|
||||
}
|
||||
|
||||
fun getSizeNoTag(): Int {
|
||||
var size = 0
|
||||
if (type != DebugRequest.Type.fromIntToType(0)) {
|
||||
size += WireFormat.getEnumSize(1, type.id)
|
||||
}
|
||||
return size
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class DebugResponseMemoryStats private constructor (var heapDynamicTail: Int, var heapStaticTail: Int, var heapDynamicMaxBytes: Int, var heapDynamicTotalBytes: Int) {
|
||||
//========== Properties ===========
|
||||
//int32 heapDynamicTail = 1
|
||||
|
||||
//int32 heapStaticTail = 2
|
||||
|
||||
//int32 heapDynamicMaxBytes = 3
|
||||
|
||||
//int32 heapDynamicTotalBytes = 4
|
||||
|
||||
var errorCode: Int = 0
|
||||
|
||||
//========== Serialization methods ===========
|
||||
fun writeTo (output: CodedOutputStream) {
|
||||
//int32 heapDynamicTail = 1
|
||||
if (heapDynamicTail != 0) {
|
||||
output.writeInt32 (1, heapDynamicTail)
|
||||
}
|
||||
|
||||
//int32 heapStaticTail = 2
|
||||
if (heapStaticTail != 0) {
|
||||
output.writeInt32 (2, heapStaticTail)
|
||||
}
|
||||
|
||||
//int32 heapDynamicMaxBytes = 3
|
||||
if (heapDynamicMaxBytes != 0) {
|
||||
output.writeInt32 (3, heapDynamicMaxBytes)
|
||||
}
|
||||
|
||||
//int32 heapDynamicTotalBytes = 4
|
||||
if (heapDynamicTotalBytes != 0) {
|
||||
output.writeInt32 (4, heapDynamicTotalBytes)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun mergeWith (other: DebugResponseMemoryStats) {
|
||||
heapDynamicTail = other.heapDynamicTail
|
||||
heapStaticTail = other.heapStaticTail
|
||||
heapDynamicMaxBytes = other.heapDynamicMaxBytes
|
||||
heapDynamicTotalBytes = other.heapDynamicTotalBytes
|
||||
this.errorCode = other.errorCode
|
||||
}
|
||||
|
||||
fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) {
|
||||
val builder = DebugResponseMemoryStats.BuilderDebugResponseMemoryStats(0, 0, 0, 0)
|
||||
mergeWith(builder.parseFromWithSize(input, expectedSize).build())
|
||||
}
|
||||
|
||||
fun mergeFrom (input: CodedInputStream) {
|
||||
val builder = DebugResponseMemoryStats.BuilderDebugResponseMemoryStats(0, 0, 0, 0)
|
||||
mergeWith(builder.parseFrom(input).build())
|
||||
}
|
||||
|
||||
//========== Size-related methods ===========
|
||||
fun getSize(fieldNumber: Int): Int {
|
||||
var size = 0
|
||||
if (heapDynamicTail != 0) {
|
||||
size += WireFormat.getInt32Size(1, heapDynamicTail)
|
||||
}
|
||||
if (heapStaticTail != 0) {
|
||||
size += WireFormat.getInt32Size(2, heapStaticTail)
|
||||
}
|
||||
if (heapDynamicMaxBytes != 0) {
|
||||
size += WireFormat.getInt32Size(3, heapDynamicMaxBytes)
|
||||
}
|
||||
if (heapDynamicTotalBytes != 0) {
|
||||
size += WireFormat.getInt32Size(4, heapDynamicTotalBytes)
|
||||
}
|
||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
||||
return size
|
||||
}
|
||||
|
||||
fun getSizeNoTag(): Int {
|
||||
var size = 0
|
||||
if (heapDynamicTail != 0) {
|
||||
size += WireFormat.getInt32Size(1, heapDynamicTail)
|
||||
}
|
||||
if (heapStaticTail != 0) {
|
||||
size += WireFormat.getInt32Size(2, heapStaticTail)
|
||||
}
|
||||
if (heapDynamicMaxBytes != 0) {
|
||||
size += WireFormat.getInt32Size(3, heapDynamicMaxBytes)
|
||||
}
|
||||
if (heapDynamicTotalBytes != 0) {
|
||||
size += WireFormat.getInt32Size(4, heapDynamicTotalBytes)
|
||||
}
|
||||
return size
|
||||
}
|
||||
|
||||
//========== Builder ===========
|
||||
class BuilderDebugResponseMemoryStats constructor (var heapDynamicTail: Int, var heapStaticTail: Int, var heapDynamicMaxBytes: Int, var heapDynamicTotalBytes: Int) {
|
||||
//========== Properties ===========
|
||||
//int32 heapDynamicTail = 1
|
||||
fun setHeapDynamicTail(value: Int): DebugResponseMemoryStats.BuilderDebugResponseMemoryStats {
|
||||
heapDynamicTail = value
|
||||
return this
|
||||
}
|
||||
|
||||
//int32 heapStaticTail = 2
|
||||
fun setHeapStaticTail(value: Int): DebugResponseMemoryStats.BuilderDebugResponseMemoryStats {
|
||||
heapStaticTail = value
|
||||
return this
|
||||
}
|
||||
|
||||
//int32 heapDynamicMaxBytes = 3
|
||||
fun setHeapDynamicMaxBytes(value: Int): DebugResponseMemoryStats.BuilderDebugResponseMemoryStats {
|
||||
heapDynamicMaxBytes = value
|
||||
return this
|
||||
}
|
||||
|
||||
//int32 heapDynamicTotalBytes = 4
|
||||
fun setHeapDynamicTotalBytes(value: Int): DebugResponseMemoryStats.BuilderDebugResponseMemoryStats {
|
||||
heapDynamicTotalBytes = value
|
||||
return this
|
||||
}
|
||||
|
||||
var errorCode: Int = 0
|
||||
|
||||
//========== Serialization methods ===========
|
||||
fun writeTo (output: CodedOutputStream) {
|
||||
//int32 heapDynamicTail = 1
|
||||
if (heapDynamicTail != 0) {
|
||||
output.writeInt32 (1, heapDynamicTail)
|
||||
}
|
||||
|
||||
//int32 heapStaticTail = 2
|
||||
if (heapStaticTail != 0) {
|
||||
output.writeInt32 (2, heapStaticTail)
|
||||
}
|
||||
|
||||
//int32 heapDynamicMaxBytes = 3
|
||||
if (heapDynamicMaxBytes != 0) {
|
||||
output.writeInt32 (3, heapDynamicMaxBytes)
|
||||
}
|
||||
|
||||
//int32 heapDynamicTotalBytes = 4
|
||||
if (heapDynamicTotalBytes != 0) {
|
||||
output.writeInt32 (4, heapDynamicTotalBytes)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//========== Mutating methods ===========
|
||||
fun build(): DebugResponseMemoryStats {
|
||||
val res = DebugResponseMemoryStats(heapDynamicTail, heapStaticTail, heapDynamicMaxBytes, heapDynamicTotalBytes)
|
||||
res.errorCode = errorCode
|
||||
return res
|
||||
}
|
||||
|
||||
fun parseFieldFrom(input: CodedInputStream): Boolean {
|
||||
if (input.isAtEnd()) { return false }
|
||||
val tag = input.readInt32NoTag()
|
||||
if (tag == 0) { return false }
|
||||
val fieldNumber = WireFormat.getTagFieldNumber(tag)
|
||||
val wireType = WireFormat.getTagWireType(tag)
|
||||
when(fieldNumber) {
|
||||
1 -> {
|
||||
if (wireType.id != WireType.VARINT.id) {
|
||||
errorCode = 1
|
||||
return false
|
||||
}
|
||||
heapDynamicTail = input.readInt32NoTag()
|
||||
}
|
||||
2 -> {
|
||||
if (wireType.id != WireType.VARINT.id) {
|
||||
errorCode = 1
|
||||
return false
|
||||
}
|
||||
heapStaticTail = input.readInt32NoTag()
|
||||
}
|
||||
3 -> {
|
||||
if (wireType.id != WireType.VARINT.id) {
|
||||
errorCode = 1
|
||||
return false
|
||||
}
|
||||
heapDynamicMaxBytes = input.readInt32NoTag()
|
||||
}
|
||||
4 -> {
|
||||
if (wireType.id != WireType.VARINT.id) {
|
||||
errorCode = 1
|
||||
return false
|
||||
}
|
||||
heapDynamicTotalBytes = input.readInt32NoTag()
|
||||
}
|
||||
else -> errorCode = 4
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): DebugResponseMemoryStats.BuilderDebugResponseMemoryStats {
|
||||
while(getSizeNoTag() < expectedSize) {
|
||||
parseFieldFrom(input)
|
||||
}
|
||||
if (getSizeNoTag() > expectedSize) { errorCode = 2 }
|
||||
return this
|
||||
}
|
||||
|
||||
fun parseFrom(input: CodedInputStream): DebugResponseMemoryStats.BuilderDebugResponseMemoryStats {
|
||||
while(parseFieldFrom(input)) {}
|
||||
return this
|
||||
}
|
||||
|
||||
//========== Size-related methods ===========
|
||||
fun getSize(fieldNumber: Int): Int {
|
||||
var size = 0
|
||||
if (heapDynamicTail != 0) {
|
||||
size += WireFormat.getInt32Size(1, heapDynamicTail)
|
||||
}
|
||||
if (heapStaticTail != 0) {
|
||||
size += WireFormat.getInt32Size(2, heapStaticTail)
|
||||
}
|
||||
if (heapDynamicMaxBytes != 0) {
|
||||
size += WireFormat.getInt32Size(3, heapDynamicMaxBytes)
|
||||
}
|
||||
if (heapDynamicTotalBytes != 0) {
|
||||
size += WireFormat.getInt32Size(4, heapDynamicTotalBytes)
|
||||
}
|
||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
||||
return size
|
||||
}
|
||||
|
||||
fun getSizeNoTag(): Int {
|
||||
var size = 0
|
||||
if (heapDynamicTail != 0) {
|
||||
size += WireFormat.getInt32Size(1, heapDynamicTail)
|
||||
}
|
||||
if (heapStaticTail != 0) {
|
||||
size += WireFormat.getInt32Size(2, heapStaticTail)
|
||||
}
|
||||
if (heapDynamicMaxBytes != 0) {
|
||||
size += WireFormat.getInt32Size(3, heapDynamicMaxBytes)
|
||||
}
|
||||
if (heapDynamicTotalBytes != 0) {
|
||||
size += WireFormat.getInt32Size(4, heapDynamicTotalBytes)
|
||||
}
|
||||
return size
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class DirectionRequest private constructor (var command: DirectionRequest.Command, var sid: Int) {
|
||||
//========== Properties ===========
|
||||
//enum command = 1
|
||||
@@ -9,21 +8,21 @@ class DirectionRequest private constructor (var command: DirectionRequest.Comman
|
||||
|
||||
//========== Nested enums declarations ===========
|
||||
enum class Command(val id: Int) {
|
||||
stop (0),
|
||||
forward (1),
|
||||
backward (2),
|
||||
left (3),
|
||||
right (4),
|
||||
STOP (0),
|
||||
FORWARD (1),
|
||||
BACKWARD (2),
|
||||
LEFT (3),
|
||||
RIGHT (4),
|
||||
Unexpected(5);
|
||||
|
||||
companion object {
|
||||
fun fromIntToCommand (ord: Int): Command {
|
||||
return when (ord) {
|
||||
0 -> Command.stop
|
||||
1 -> Command.forward
|
||||
2 -> Command.backward
|
||||
3 -> Command.left
|
||||
4 -> Command.right
|
||||
0 -> Command.STOP
|
||||
1 -> Command.FORWARD
|
||||
2 -> Command.BACKWARD
|
||||
3 -> Command.LEFT
|
||||
4 -> Command.RIGHT
|
||||
else -> Unexpected
|
||||
}
|
||||
}
|
||||
@@ -188,6 +187,7 @@ class DirectionRequest private constructor (var command: DirectionRequest.Comman
|
||||
|
||||
}
|
||||
|
||||
|
||||
class DirectionResponse private constructor (var code: Int) {
|
||||
//========== Properties ===========
|
||||
//int32 code = 1
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
|
||||
class RouteRequest private constructor (var distances: IntArray, var angles: IntArray) {
|
||||
class RouteRequest private constructor (var times: IntArray, var directions: IntArray) {
|
||||
//========== Properties ===========
|
||||
//repeated int32 distances = 1
|
||||
//repeated int32 times = 1
|
||||
|
||||
//repeated int32 angles = 2
|
||||
//repeated int32 directions = 2
|
||||
|
||||
var errorCode: Int = 0
|
||||
|
||||
//========== Serialization methods ===========
|
||||
fun writeTo (output: CodedOutputStream) {
|
||||
//repeated int32 distances = 1
|
||||
if (distances.size > 0) {
|
||||
//repeated int32 times = 1
|
||||
if (times.size > 0) {
|
||||
output.writeTag(1, WireType.LENGTH_DELIMITED)
|
||||
var arrayByteSize = 0
|
||||
|
||||
if (distances.size != 0) {
|
||||
if (times.size != 0) {
|
||||
do {
|
||||
var arraySize = 0
|
||||
var i = 0
|
||||
while (i < distances.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(distances[i])
|
||||
while (i < times.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(times[i])
|
||||
i += 1
|
||||
}
|
||||
arrayByteSize += arraySize
|
||||
@@ -29,24 +28,24 @@ class RouteRequest private constructor (var distances: IntArray, var angles: Int
|
||||
|
||||
do {
|
||||
var i = 0
|
||||
while (i < distances.size) {
|
||||
output.writeInt32NoTag (distances[i])
|
||||
while (i < times.size) {
|
||||
output.writeInt32NoTag (times[i])
|
||||
i += 1
|
||||
}
|
||||
} while(false)
|
||||
}
|
||||
|
||||
//repeated int32 angles = 2
|
||||
if (angles.size > 0) {
|
||||
//repeated int32 directions = 2
|
||||
if (directions.size > 0) {
|
||||
output.writeTag(2, WireType.LENGTH_DELIMITED)
|
||||
var arrayByteSize = 0
|
||||
|
||||
if (angles.size != 0) {
|
||||
if (directions.size != 0) {
|
||||
do {
|
||||
var arraySize = 0
|
||||
var i = 0
|
||||
while (i < angles.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(angles[i])
|
||||
while (i < directions.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(directions[i])
|
||||
i += 1
|
||||
}
|
||||
arrayByteSize += arraySize
|
||||
@@ -56,8 +55,8 @@ class RouteRequest private constructor (var distances: IntArray, var angles: Int
|
||||
|
||||
do {
|
||||
var i = 0
|
||||
while (i < angles.size) {
|
||||
output.writeInt32NoTag (angles[i])
|
||||
while (i < directions.size) {
|
||||
output.writeInt32NoTag (directions[i])
|
||||
i += 1
|
||||
}
|
||||
} while(false)
|
||||
@@ -66,8 +65,8 @@ class RouteRequest private constructor (var distances: IntArray, var angles: Int
|
||||
}
|
||||
|
||||
fun mergeWith (other: RouteRequest) {
|
||||
distances = distances.plus((other.distances))
|
||||
angles = angles.plus((other.angles))
|
||||
times = times.plus((other.times))
|
||||
directions = directions.plus((other.directions))
|
||||
this.errorCode = other.errorCode
|
||||
}
|
||||
|
||||
@@ -84,26 +83,26 @@ class RouteRequest private constructor (var distances: IntArray, var angles: Int
|
||||
//========== Size-related methods ===========
|
||||
fun getSize(fieldNumber: Int): Int {
|
||||
var size = 0
|
||||
if (distances.size != 0) {
|
||||
if (times.size != 0) {
|
||||
do {
|
||||
var arraySize = 0
|
||||
size += WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED)
|
||||
var i = 0
|
||||
while (i < distances.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(distances[i])
|
||||
while (i < times.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(times[i])
|
||||
i += 1
|
||||
}
|
||||
size += arraySize
|
||||
size += WireFormat.getInt32SizeNoTag(arraySize)
|
||||
} while(false)
|
||||
}
|
||||
if (angles.size != 0) {
|
||||
if (directions.size != 0) {
|
||||
do {
|
||||
var arraySize = 0
|
||||
size += WireFormat.getTagSize(2, WireType.LENGTH_DELIMITED)
|
||||
var i = 0
|
||||
while (i < angles.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(angles[i])
|
||||
while (i < directions.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(directions[i])
|
||||
i += 1
|
||||
}
|
||||
size += arraySize
|
||||
@@ -116,26 +115,26 @@ class RouteRequest private constructor (var distances: IntArray, var angles: Int
|
||||
|
||||
fun getSizeNoTag(): Int {
|
||||
var size = 0
|
||||
if (distances.size != 0) {
|
||||
if (times.size != 0) {
|
||||
do {
|
||||
var arraySize = 0
|
||||
size += WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED)
|
||||
var i = 0
|
||||
while (i < distances.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(distances[i])
|
||||
while (i < times.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(times[i])
|
||||
i += 1
|
||||
}
|
||||
size += arraySize
|
||||
size += WireFormat.getInt32SizeNoTag(arraySize)
|
||||
} while(false)
|
||||
}
|
||||
if (angles.size != 0) {
|
||||
if (directions.size != 0) {
|
||||
do {
|
||||
var arraySize = 0
|
||||
size += WireFormat.getTagSize(2, WireType.LENGTH_DELIMITED)
|
||||
var i = 0
|
||||
while (i < angles.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(angles[i])
|
||||
while (i < directions.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(directions[i])
|
||||
i += 1
|
||||
}
|
||||
size += arraySize
|
||||
@@ -146,25 +145,25 @@ class RouteRequest private constructor (var distances: IntArray, var angles: Int
|
||||
}
|
||||
|
||||
//========== Builder ===========
|
||||
class BuilderRouteRequest constructor (var distances: IntArray, var angles: IntArray) {
|
||||
class BuilderRouteRequest constructor (var times: IntArray, var directions: IntArray) {
|
||||
//========== Properties ===========
|
||||
//repeated int32 distances = 1
|
||||
fun setDistances(value: IntArray): RouteRequest.BuilderRouteRequest {
|
||||
distances = value
|
||||
//repeated int32 times = 1
|
||||
fun setTimes(value: IntArray): RouteRequest.BuilderRouteRequest {
|
||||
times = value
|
||||
return this
|
||||
}
|
||||
fun setdistancesByIndex(index: Int, value: Int): RouteRequest.BuilderRouteRequest {
|
||||
distances[index] = value
|
||||
fun settimesByIndex(index: Int, value: Int): RouteRequest.BuilderRouteRequest {
|
||||
times[index] = value
|
||||
return this
|
||||
}
|
||||
|
||||
//repeated int32 angles = 2
|
||||
fun setAngles(value: IntArray): RouteRequest.BuilderRouteRequest {
|
||||
angles = value
|
||||
//repeated int32 directions = 2
|
||||
fun setDirections(value: IntArray): RouteRequest.BuilderRouteRequest {
|
||||
directions = value
|
||||
return this
|
||||
}
|
||||
fun setanglesByIndex(index: Int, value: Int): RouteRequest.BuilderRouteRequest {
|
||||
angles[index] = value
|
||||
fun setdirectionsByIndex(index: Int, value: Int): RouteRequest.BuilderRouteRequest {
|
||||
directions[index] = value
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -172,17 +171,17 @@ class RouteRequest private constructor (var distances: IntArray, var angles: Int
|
||||
|
||||
//========== Serialization methods ===========
|
||||
fun writeTo (output: CodedOutputStream) {
|
||||
//repeated int32 distances = 1
|
||||
if (distances.size > 0) {
|
||||
//repeated int32 times = 1
|
||||
if (times.size > 0) {
|
||||
output.writeTag(1, WireType.LENGTH_DELIMITED)
|
||||
var arrayByteSize = 0
|
||||
|
||||
if (distances.size != 0) {
|
||||
if (times.size != 0) {
|
||||
do {
|
||||
var arraySize = 0
|
||||
var i = 0
|
||||
while (i < distances.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(distances[i])
|
||||
while (i < times.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(times[i])
|
||||
i += 1
|
||||
}
|
||||
arrayByteSize += arraySize
|
||||
@@ -192,24 +191,24 @@ class RouteRequest private constructor (var distances: IntArray, var angles: Int
|
||||
|
||||
do {
|
||||
var i = 0
|
||||
while (i < distances.size) {
|
||||
output.writeInt32NoTag (distances[i])
|
||||
while (i < times.size) {
|
||||
output.writeInt32NoTag (times[i])
|
||||
i += 1
|
||||
}
|
||||
} while(false)
|
||||
}
|
||||
|
||||
//repeated int32 angles = 2
|
||||
if (angles.size > 0) {
|
||||
//repeated int32 directions = 2
|
||||
if (directions.size > 0) {
|
||||
output.writeTag(2, WireType.LENGTH_DELIMITED)
|
||||
var arrayByteSize = 0
|
||||
|
||||
if (angles.size != 0) {
|
||||
if (directions.size != 0) {
|
||||
do {
|
||||
var arraySize = 0
|
||||
var i = 0
|
||||
while (i < angles.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(angles[i])
|
||||
while (i < directions.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(directions[i])
|
||||
i += 1
|
||||
}
|
||||
arrayByteSize += arraySize
|
||||
@@ -219,8 +218,8 @@ class RouteRequest private constructor (var distances: IntArray, var angles: Int
|
||||
|
||||
do {
|
||||
var i = 0
|
||||
while (i < angles.size) {
|
||||
output.writeInt32NoTag (angles[i])
|
||||
while (i < directions.size) {
|
||||
output.writeInt32NoTag (directions[i])
|
||||
i += 1
|
||||
}
|
||||
} while(false)
|
||||
@@ -230,7 +229,7 @@ class RouteRequest private constructor (var distances: IntArray, var angles: Int
|
||||
|
||||
//========== Mutating methods ===========
|
||||
fun build(): RouteRequest {
|
||||
val res = RouteRequest(distances, angles)
|
||||
val res = RouteRequest(times, directions)
|
||||
res.errorCode = errorCode
|
||||
return res
|
||||
}
|
||||
@@ -267,7 +266,7 @@ class RouteRequest private constructor (var distances: IntArray, var angles: Int
|
||||
while(i < arraySize) {
|
||||
newArray[i] = input.readInt32NoTag()
|
||||
i += 1}
|
||||
distances = newArray
|
||||
times = newArray
|
||||
} while (false)
|
||||
}
|
||||
2 -> {
|
||||
@@ -295,7 +294,7 @@ class RouteRequest private constructor (var distances: IntArray, var angles: Int
|
||||
while(i < arraySize) {
|
||||
newArray[i] = input.readInt32NoTag()
|
||||
i += 1}
|
||||
angles = newArray
|
||||
directions = newArray
|
||||
} while (false)
|
||||
}
|
||||
else -> errorCode = 4
|
||||
@@ -319,26 +318,26 @@ class RouteRequest private constructor (var distances: IntArray, var angles: Int
|
||||
//========== Size-related methods ===========
|
||||
fun getSize(fieldNumber: Int): Int {
|
||||
var size = 0
|
||||
if (distances.size != 0) {
|
||||
if (times.size != 0) {
|
||||
do {
|
||||
var arraySize = 0
|
||||
size += WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED)
|
||||
var i = 0
|
||||
while (i < distances.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(distances[i])
|
||||
while (i < times.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(times[i])
|
||||
i += 1
|
||||
}
|
||||
size += arraySize
|
||||
size += WireFormat.getInt32SizeNoTag(arraySize)
|
||||
} while(false)
|
||||
}
|
||||
if (angles.size != 0) {
|
||||
if (directions.size != 0) {
|
||||
do {
|
||||
var arraySize = 0
|
||||
size += WireFormat.getTagSize(2, WireType.LENGTH_DELIMITED)
|
||||
var i = 0
|
||||
while (i < angles.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(angles[i])
|
||||
while (i < directions.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(directions[i])
|
||||
i += 1
|
||||
}
|
||||
size += arraySize
|
||||
@@ -351,26 +350,26 @@ class RouteRequest private constructor (var distances: IntArray, var angles: Int
|
||||
|
||||
fun getSizeNoTag(): Int {
|
||||
var size = 0
|
||||
if (distances.size != 0) {
|
||||
if (times.size != 0) {
|
||||
do {
|
||||
var arraySize = 0
|
||||
size += WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED)
|
||||
var i = 0
|
||||
while (i < distances.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(distances[i])
|
||||
while (i < times.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(times[i])
|
||||
i += 1
|
||||
}
|
||||
size += arraySize
|
||||
size += WireFormat.getInt32SizeNoTag(arraySize)
|
||||
} while(false)
|
||||
}
|
||||
if (angles.size != 0) {
|
||||
if (directions.size != 0) {
|
||||
do {
|
||||
var arraySize = 0
|
||||
size += WireFormat.getTagSize(2, WireType.LENGTH_DELIMITED)
|
||||
var i = 0
|
||||
while (i < angles.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(angles[i])
|
||||
while (i < directions.size) {
|
||||
arraySize += WireFormat.getInt32SizeNoTag(directions[i])
|
||||
i += 1
|
||||
}
|
||||
size += arraySize
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
class TaskRequest private constructor (var type: TaskRequest.Type) {
|
||||
//========== Properties ===========
|
||||
//enum type = 1
|
||||
|
||||
var errorCode: Int = 0
|
||||
|
||||
//========== Nested enums declarations ===========
|
||||
enum class Type(val id: Int) {
|
||||
DEBUG (0),
|
||||
ROUTE (1),
|
||||
Unexpected(2);
|
||||
|
||||
companion object {
|
||||
fun fromIntToType (ord: Int): Type {
|
||||
return when (ord) {
|
||||
0 -> Type.DEBUG
|
||||
1 -> Type.ROUTE
|
||||
else -> Unexpected
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//========== Serialization methods ===========
|
||||
fun writeTo (output: CodedOutputStream) {
|
||||
//enum type = 1
|
||||
if (type.id != TaskRequest.Type.fromIntToType(0).id) {
|
||||
output.writeEnum (1, type.id)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun mergeWith (other: TaskRequest) {
|
||||
type = other.type
|
||||
this.errorCode = other.errorCode
|
||||
}
|
||||
|
||||
fun mergeFromWithSize (input: CodedInputStream, expectedSize: Int) {
|
||||
val builder = TaskRequest.BuilderTaskRequest(TaskRequest.Type.fromIntToType(0))
|
||||
mergeWith(builder.parseFromWithSize(input, expectedSize).build())
|
||||
}
|
||||
|
||||
fun mergeFrom (input: CodedInputStream) {
|
||||
val builder = TaskRequest.BuilderTaskRequest(TaskRequest.Type.fromIntToType(0))
|
||||
mergeWith(builder.parseFrom(input).build())
|
||||
}
|
||||
|
||||
//========== Size-related methods ===========
|
||||
fun getSize(fieldNumber: Int): Int {
|
||||
var size = 0
|
||||
if (type != TaskRequest.Type.fromIntToType(0)) {
|
||||
size += WireFormat.getEnumSize(1, type.id)
|
||||
}
|
||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
||||
return size
|
||||
}
|
||||
|
||||
fun getSizeNoTag(): Int {
|
||||
var size = 0
|
||||
if (type != TaskRequest.Type.fromIntToType(0)) {
|
||||
size += WireFormat.getEnumSize(1, type.id)
|
||||
}
|
||||
return size
|
||||
}
|
||||
|
||||
//========== Builder ===========
|
||||
class BuilderTaskRequest constructor (var type: TaskRequest.Type) {
|
||||
//========== Properties ===========
|
||||
//enum type = 1
|
||||
fun setType(value: TaskRequest.Type): TaskRequest.BuilderTaskRequest {
|
||||
type = value
|
||||
return this
|
||||
}
|
||||
|
||||
var errorCode: Int = 0
|
||||
|
||||
//========== Serialization methods ===========
|
||||
fun writeTo (output: CodedOutputStream) {
|
||||
//enum type = 1
|
||||
if (type.id != TaskRequest.Type.fromIntToType(0).id) {
|
||||
output.writeEnum (1, type.id)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//========== Mutating methods ===========
|
||||
fun build(): TaskRequest {
|
||||
val res = TaskRequest(type)
|
||||
res.errorCode = errorCode
|
||||
return res
|
||||
}
|
||||
|
||||
fun parseFieldFrom(input: CodedInputStream): Boolean {
|
||||
if (input.isAtEnd()) { return false }
|
||||
val tag = input.readInt32NoTag()
|
||||
if (tag == 0) { return false }
|
||||
val fieldNumber = WireFormat.getTagFieldNumber(tag)
|
||||
val wireType = WireFormat.getTagWireType(tag)
|
||||
when(fieldNumber) {
|
||||
1 -> {
|
||||
if (wireType.id != WireType.VARINT.id) {
|
||||
errorCode = 1
|
||||
return false
|
||||
}
|
||||
type = TaskRequest.Type.fromIntToType(input.readEnumNoTag())
|
||||
}
|
||||
else -> errorCode = 4
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): TaskRequest.BuilderTaskRequest {
|
||||
while(getSizeNoTag() < expectedSize) {
|
||||
parseFieldFrom(input)
|
||||
}
|
||||
if (getSizeNoTag() > expectedSize) { errorCode = 2 }
|
||||
return this
|
||||
}
|
||||
|
||||
fun parseFrom(input: CodedInputStream): TaskRequest.BuilderTaskRequest {
|
||||
while(parseFieldFrom(input)) {}
|
||||
return this
|
||||
}
|
||||
|
||||
//========== Size-related methods ===========
|
||||
fun getSize(fieldNumber: Int): Int {
|
||||
var size = 0
|
||||
if (type != TaskRequest.Type.fromIntToType(0)) {
|
||||
size += WireFormat.getEnumSize(1, type.id)
|
||||
}
|
||||
size += WireFormat.getVarint32Size(size) + WireFormat.getTagSize(fieldNumber, WireType.LENGTH_DELIMITED)
|
||||
return size
|
||||
}
|
||||
|
||||
fun getSizeNoTag(): Int {
|
||||
var size = 0
|
||||
if (type != TaskRequest.Type.fromIntToType(0)) {
|
||||
size += WireFormat.getEnumSize(1, type.id)
|
||||
}
|
||||
return size
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
|
||||
enum class RouteType(val id: Int) {
|
||||
FORWARD(0),
|
||||
BACKWARD(1),
|
||||
LEFT(2),
|
||||
RIGHT(3);
|
||||
}
|
||||
|
||||
fun go(request: RouteRequest) {
|
||||
val times = request.distances
|
||||
val actions = request.angles
|
||||
var j = 0
|
||||
|
||||
while (j < times.size) {
|
||||
val time = times[j]
|
||||
val action = actions[j]
|
||||
|
||||
when (action) {
|
||||
RouteType.FORWARD.id -> Engine.forward()
|
||||
RouteType.BACKWARD.id -> Engine.backward()
|
||||
RouteType.LEFT.id -> Engine.left()
|
||||
RouteType.RIGHT.id -> Engine.right()
|
||||
}
|
||||
|
||||
Time.wait(time)
|
||||
Engine.stop()
|
||||
j++
|
||||
}
|
||||
|
||||
}
|
||||
@@ -62,3 +62,21 @@ void clean_dynamic_heap() {
|
||||
heap_tails[DYNAMIC_HEAP] = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ARM
|
||||
int dynamic_heap_tail() {
|
||||
return heap_tails[DYNAMIC_HEAP];
|
||||
}
|
||||
|
||||
int static_heap_tail() {
|
||||
return heap_tails[STATIC_HEAP];
|
||||
}
|
||||
|
||||
int dynamic_heap_max_bytes() {
|
||||
return dynamic_heap_max;
|
||||
}
|
||||
|
||||
int dynamic_heap_total() {
|
||||
return dynamic_heap_consume;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -65,7 +65,7 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
||||
is KtBinaryExpression -> evaluateBinaryExpression(expr, scopeDepth)
|
||||
is KtCallExpression -> evaluateCallExpression(expr, scopeDepth)
|
||||
is KtDoWhileExpression -> evaluateDoWhileExpression(expr.firstChild, scopeDepth + 1)
|
||||
is KtBreakExpression -> evaluateBreakExpression(expr, breakLabel!!, scopeDepth + 1)
|
||||
is KtBreakExpression -> evaluateBreakExpression(breakLabel!!)
|
||||
is KtDotQualifiedExpression -> evaluateDotExpression(expr, scopeDepth)
|
||||
is KtWhenExpression -> evaluateWhenExpression(expr, scopeDepth)
|
||||
is PsiElement -> evaluateExpression(expr.firstChild, scopeDepth + 1)
|
||||
@@ -79,7 +79,7 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
||||
expressionWalker(expr.getNextSiblingIgnoringWhitespaceAndComments(), breakLabel, scopeDepth)
|
||||
}
|
||||
|
||||
private fun evaluateBreakExpression(expr: KtBreakExpression, breakLabel: LLVMLabel, scopeDepth: Int) {
|
||||
private fun evaluateBreakExpression(breakLabel: LLVMLabel) {
|
||||
codeBuilder.addUnconditionalJump(breakLabel)
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
||||
}
|
||||
}
|
||||
|
||||
val clazz = resolveCodegen(receiverExpr) ?: return evaluateExtensionExpression(receiverExpr, receiver, selectorExpr as KtCallExpression, scopeDepth)
|
||||
val clazz = resolveCodegen(receiverExpr) ?: return evaluateExtensionExpression(receiverExpr, receiver, selectorExpr as? KtCallExpression ?: throw UnexpectedException(selectorExpr.text), scopeDepth)
|
||||
return evaluateClassScopedDotExpression(clazz, selectorExpr, scopeDepth, receiver)
|
||||
}
|
||||
|
||||
@@ -442,26 +442,27 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
||||
}
|
||||
|
||||
val containingClass = resolveContainingClass(expr)
|
||||
if (containingClass != null) {
|
||||
val name = "${containingClass.fullName}.$function"
|
||||
val method = containingClass.methods[name]!!
|
||||
val args = mutableListOf<LLVMSingleValue>()
|
||||
val leftName = (expr.context as? KtDotQualifiedExpression)?.receiverExpression?.text
|
||||
|
||||
if (caller != null) {
|
||||
args.add(caller)
|
||||
} else if (variableManager[containingClass.fullName] != null) {
|
||||
args.add(variableManager[containingClass.fullName]!!)
|
||||
} else {
|
||||
args.add(variableManager["this"]!!)
|
||||
}
|
||||
|
||||
args.addAll(loadArgsIfRequired(names, method.args))
|
||||
|
||||
return evaluateFunctionCallExpression(LLVMVariable(method.fullName, method.returnType?.type ?: LLVMVoidType(), scope = LLVMVariableScope()), args)
|
||||
if (containingClass == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
return null
|
||||
val name = "${containingClass.fullName}.$function"
|
||||
val method = containingClass.methods[name]!!
|
||||
val args = mutableListOf<LLVMSingleValue>()
|
||||
val leftName = (expr.context as? KtDotQualifiedExpression)?.receiverExpression?.text
|
||||
|
||||
if (caller != null) {
|
||||
args.add(caller)
|
||||
} else if (variableManager[containingClass.fullName] != null) {
|
||||
args.add(variableManager[containingClass.fullName]!!)
|
||||
} else {
|
||||
args.add(variableManager["this"]!!)
|
||||
}
|
||||
|
||||
args.addAll(loadArgsIfRequired(names, method.args))
|
||||
|
||||
return evaluateFunctionCallExpression(LLVMVariable(method.fullName, method.returnType?.type ?: LLVMVoidType(), scope = LLVMVariableScope()), args)
|
||||
}
|
||||
|
||||
private fun resolveContainingClass(expr: KtElement): StructCodegen? {
|
||||
@@ -1076,9 +1077,6 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
||||
codeBuilder.addConstant(newVar, assignExpression)
|
||||
variableManager.addVariable(identifier, newVar, scopeDepth)
|
||||
}
|
||||
null -> {
|
||||
val xrptrz = 442
|
||||
}
|
||||
else -> {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user