Skip to content

Commit

Permalink
Fix Launch and add TypeOf call
Browse files Browse the repository at this point in the history
  • Loading branch information
Moocow9m committed Jan 23, 2022
1 parent 5cac1f6 commit 0cb57f0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/main/kotlin/tech/poder/ir/api/MethodBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,15 @@ data class MethodBuilder(
addOp(PTIR.Op.AWAIT, job)
}

fun typeOf(store: Variable, type: Any) {
addOp(PTIR.Op.TYPE_OF, store, type)
}

fun launch(codeFile: CodeFile, method: UInt, store: Variable? = null, vararg args: Any) {
if (codeFile.name == parent.name) {
addOp(PTIR.Op.INVOKE, store, "", method, *args)
addOp(PTIR.Op.LAUNCH, store, "", method, *args)
} else {
addOp(PTIR.Op.INVOKE, store, codeFile.name, method, *args)
addOp(PTIR.Op.LAUNCH, store, codeFile.name, method, *args)
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/tech/poder/ir/machine/amd64/CPUWriter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ value class CPUWriter (val out: BitOutputStream) {
out.writeBit(true)
out.writeBit(true)
}
RegisterName.RAX_HIGH -> TODO()
RegisterName.RBX_HIGH -> TODO()
RegisterName.RCX_HIGH -> TODO()
RegisterName.RDX_HIGH -> TODO()
}
}

Expand Down
11 changes: 6 additions & 5 deletions src/main/kotlin/tech/poder/ir/machine/x86/RegisterSize.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package tech.poder.ir.machine.x86

enum class RegisterSize {
M8,
M16,
M32,
M64,
M128,
I8,
I16,
I32,
I64,
I128,
I256,
}
33 changes: 33 additions & 0 deletions src/main/kotlin/tech/poder/ir/vm/VirtualMachine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,39 @@ object VirtualMachine {
val b = safeGetDataType(op.args[2], local)
setDataType(op.args[0] as PTIR.Variable, xor(a, b), local)
}
PTIR.Op.TYPE_OF -> {
val res = when (val type = safeGetDataType(op.args[1], local)) {
is UInt -> {
0u
}
is Int -> {
1u
}
is Byte -> {
3u
}
is UByte -> {
4u
}
is Long -> {
5u
}
is ULong -> {
6u
}
is Short -> {
7u
}
is UShort -> {
8u
}
is List<*> -> { //May be Struct or Normal List!
9u
}
else -> error("Type not recognized: ${type::class.java.name}")
}
setDataType(op.args[0] as PTIR.Variable, res, local)
}
PTIR.Op.LAUNCH -> {
val a = op.args[0]
val returnTo = if (a is PTIR.Variable) {
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/tech/poder/ptir/PTIR.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ object PTIR {
SAR,
SAL,
XOR,
TYPE_OF,
INVOKE,
LAUNCH,
AWAIT,
Expand Down

0 comments on commit 0cb57f0

Please sign in to comment.