Skip to content

Commit b36b335

Browse files
committed
formated
1 parent 413a560 commit b36b335

File tree

6 files changed

+166
-121
lines changed

6 files changed

+166
-121
lines changed

src/main/kotlin/engine/execution/Execute.kt

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,182 +67,224 @@ class Execute(val vm: Vm) {
6767
"sleep" -> {
6868
vm.misc.sleep(args[0] as RegisterType)
6969
}
70+
7071
"ftoi" -> {
7172
vm.xFloats.ftoi(args[0] as RegisterType, args[1] as RegisterType)
7273
}
74+
7375
"itof" -> {
7476
vm.xFloats.itof(args[0] as RegisterType, args[1] as RegisterType)
7577
}
78+
7679
"xlit" -> {
7780
vm.xFloats.xLit(
7881
args[0] as RegisterType,
7982
(args[1] as String).toDoubleOrFloatBasedOnDataType(vm, args[0] as RegisterType)
8083
)
8184
}
85+
8286
"xpow" -> {
8387
vm.xFloats.xPow(args[0] as RegisterType, args[1] as RegisterType)
8488
}
89+
8590
"xsub" -> {
8691
vm.xFloats.xSub(args[0] as RegisterType, args[1] as RegisterType)
8792
}
93+
8894
"xmul" -> {
8995
vm.xFloats.xMul(args[0] as RegisterType, args[1] as RegisterType)
9096
}
97+
9198
"xdiv" -> {
9299
vm.xFloats.xDiv(args[0] as RegisterType, args[1] as RegisterType)
93100
}
101+
94102
"xadd" -> {
95103
vm.xFloats.xAdd(args[0] as RegisterType, args[1] as RegisterType)
96104
}
105+
97106
"settype" -> {
98107
vm.registers.registers[(args[0] as RegisterType)]!!.settype(args[1] as RegisterDataType)
99108
}
109+
100110
"dealloc" -> {
101111
vm.dataTransfer.dealloc(
102112
memAddress = args[0] as RegisterType
103113
)
104114
}
115+
105116
"pow" -> {
106117
vm.arithmetic.pow(
107118
registerA = args[0] as RegisterType, registerB = args[1] as RegisterType
108119
)
109120
}
121+
110122
"help" -> {
111123
vm.misc.help((args[0] as String))
112124
}
125+
113126
"ret" -> {
114127
return null
115128
}
129+
116130
"inr" -> {
117131
vm.dataTransfer.inr((args[0] as String).toRegisterType() ?: {
118132
vm.errors.InvalidRegisterException(args[0] as String)
119133
} as RegisterType)
120134
}
135+
121136
"call" -> {
122137
vm.libPc = vm.pc
123138
vm.libExecute.execute(args[0].toString())
124139
}
140+
125141
"emptyLine", "comment" -> {}
126142
"gt" -> {
127143
vm.arithmetic.gt(
128144
operand1 = args[0] as RegisterType, operand2 = args[1] as RegisterType
129145
)
130146
}
147+
131148
"lt" -> {
132-
// println(args.size)
133149
vm.arithmetic.lt(
134150
operand1 = args[0] as RegisterType, operand2 = args[1] as RegisterType
135151
)
136152
}
153+
137154
"str" -> {
138155
vm.strings.str(args[0].toString().toRegisterType() ?: {
139156
vm.errors.InvalidRegisterException(args[0] as String)
140157
} as RegisterType, args[1].toString())
141158
}
159+
142160
"swp" -> {
143161
vm.dataTransfer.swp(
144162
register1 = args[0] as RegisterType, register2 = args[1] as RegisterType
145163
)
146164
}
165+
147166
"add" -> {
148167
vm.arithmetic.add(
149168
registerA = args[0] as RegisterType, registerB = args[1] as RegisterType
150169
)
151170
}
171+
152172
"sub" -> {
153173
vm.arithmetic.sub(
154174
registerA = args[0] as RegisterType, registerB = args[1] as RegisterType
155175
)
156176
}
177+
157178
"mul" -> {
158179
vm.arithmetic.mul(
159180
registerA = args[0] as RegisterType, registerB = args[1] as RegisterType
160181
)
161182
}
183+
162184
"div" -> {
163185
vm.arithmetic.div(
164186
registerA = args[0] as RegisterType, registerB = args[1] as RegisterType
165187
)
166188
}
189+
167190
"mod" -> {
168191
vm.arithmetic.mod(
169192
registerA = args[0] as RegisterType, registerB = args[1] as RegisterType
170193
)
171194
}
195+
172196
"eq" -> {
173197
vm.arithmetic.eq(
174198
operand1 = args[0] as RegisterType, operand2 = args[1] as RegisterType
175199
)
176200
}
201+
177202
"lit" -> {
178203
vm.dataTransfer.lit(source = args[0] as RegisterType, value = args[1] as Long)
179204
}
205+
180206
"mov" -> {
181207
vm.dataTransfer.mov(
182208
source = args[0] as RegisterType, destination = args[1] as RegisterType
183209
)
184210
}
211+
185212
"jmp" -> {
186213
vm.controlFlow.jmp(targetAddress = args[0] as Long - 1L)
187214
}
215+
188216
"jz" -> {
189217
vm.controlFlow.jz(
190218
targetAddress = args[0] as Long - 1L
191219
)
192220
}
221+
193222
"jnz" -> {
194223
vm.controlFlow.jnz(
195224
targetAddress = args[0] as Long - 1L
196225
)
197226
}
227+
198228
"peek" -> {
199229
vm.stackOperations.peek(destination = args[0] as RegisterType)
200230
}
231+
201232
"pop" -> {
202233
vm.stackOperations.pop(destination = args[0] as RegisterType)
203234
}
235+
204236
"push" -> {
205237
vm.stackOperations.push(registerType = args[0] as RegisterType)
206238
}
239+
207240
"pushl" -> {
208241
vm.stackOperations.pushl(registerType = args[0] as Long)
209242
}
243+
210244
"store" -> {
211245
vm.memory.store(
212246
source = args[0] as RegisterType, destination = args[1] as RegisterType
213247
)
214248
}
249+
215250
"load" -> {
216251
vm.memory.load(
217252
memoryAddress = args[0] as RegisterType, destination = args[1] as RegisterType
218253
)
219254
}
255+
220256
"shl" -> {
221257
vm.bitwise.shl(
222258
operand1 = args[0] as RegisterType, operand2 = args[1] as RegisterType
223259
)
224260
}
261+
225262
"shr" -> {
226263
vm.bitwise.shr(
227264
operand1 = args[0] as RegisterType, operand2 = args[1] as RegisterType
228265
)
229266
}
267+
230268
"and" -> {
231269
vm.bitwise.and(
232270
operand1 = args[0] as RegisterType, operand2 = args[1] as RegisterType
233271
)
234272
}
273+
235274
"not" -> {
236275
vm.bitwise.not(operand = args[0] as RegisterType)
237276
}
277+
238278
"or" -> {
239279
vm.bitwise.or(operand1 = args[0] as RegisterType, operand2 = args[1] as RegisterType)
240280
}
281+
241282
"xor" -> {
242283
vm.bitwise.xor(
243284
operand1 = args[0] as RegisterType, operand2 = args[1] as RegisterType
244285
)
245286
}
287+
246288
"syscall" -> {
247289
vm.systemCall.execute(
248290
callId = args[0] as RegisterType,
@@ -251,12 +293,15 @@ class Execute(val vm: Vm) {
251293
s4 = args[3] as RegisterType
252294
)
253295
}
296+
254297
"prints" -> {
255298
vm.ioAbstractions.prints()
256299
}
300+
257301
"printr" -> {
258302
vm.ioAbstractions.printr(register = args[0] as RegisterType)
259303
}
304+
260305
else -> {
261306
vm.errors.InvalidInstructionException(name)
262307
}

src/main/kotlin/helpers/writeStringSpecInMemory.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ import data.memory.MemoryValue
1111
* @throws NotFreeMemoryException If the destination memory range is not free.
1212
*/
1313
fun Helpers.writeStringSpecInMemory(string: String, destinationAddress: MemoryAddress) {
14-
val allocMem = string.length
14+
val allocMem = string.length
1515

16-
for (i in (destinationAddress.address!! until (destinationAddress.address + allocMem))) {
17-
if (internalMemory.memory[MemoryAddress(i)] != MemoryValue(null)) {
18-
errors.NotFreeMemoryException(i.toString())
19-
}
20-
}
16+
for (i in (destinationAddress.address!! until (destinationAddress.address + allocMem))) {
17+
if (internalMemory.memory[MemoryAddress(i)] != MemoryValue(null)) {
18+
errors.NotFreeMemoryException(i.toString())
19+
}
20+
}
2121

22-
for ((index, i) in (destinationAddress.address until (destinationAddress.address + allocMem)).withIndex()) {
23-
internalMemory.memory[MemoryAddress(i)] = MemoryValue(string[index].code.toLong())
24-
}
25-
internalMemory.memory[MemoryAddress(destinationAddress.address + allocMem)] = MemoryValue(0)
22+
for ((index, i) in (destinationAddress.address until (destinationAddress.address + allocMem)).withIndex()) {
23+
internalMemory.memory[MemoryAddress(i)] = MemoryValue(string[index].code.toLong())
24+
}
25+
internalMemory.memory[MemoryAddress(destinationAddress.address + allocMem)] = MemoryValue(0)
2626
}

src/main/kotlin/internals/instructions/stackOperations/pop.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ import helpers.toLong
1212
* @throws GeneralStackOperationsException If an error occurs during the pop operation (e.g. stack underflow).
1313
*/
1414
fun StackOperations.pop(destination: RegisterType) = try {
15-
registers.write(
16-
intelNames[IntelRegisters.ENSF], true.toLong()
17-
) // Its above the next expr because the internal stack may throw its own errors
15+
registers.write(
16+
intelNames[IntelRegisters.ENSF], true.toLong()
17+
) // Its above the next expr because the internal stack may throw its own errors
1818

1919

20-
registers.write(
21-
register = destination, value = internalStack.peek()
22-
)
20+
registers.write(
21+
register = destination, value = internalStack.peek()
22+
)
2323
} catch (_: Exception) {
24-
errors.GeneralStackOperationsException("Pop")
24+
errors.GeneralStackOperationsException("Pop")
2525

2626
}

src/main/kotlin/internals/instructions/strings/strcpy.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import helpers.writeStringSpecInMemory
1818

1919
@Deprecated("Moved into stdlib functions")
2020
fun Strings.strcpy(source: RegisterType, destination: RegisterType): Unit = try {
21-
registers.write(intelNames[IntelRegisters.ENSF], true.toLong())
21+
registers.write(intelNames[IntelRegisters.ENSF], true.toLong())
2222

23-
val string: String = helpers.readRegisterString(register = source)
24-
val destinationAddress: Long = registers.read(register = destination)
25-
helpers.writeStringSpecInMemory(
26-
string = string, destinationAddress = MemoryAddress(address = destinationAddress)
27-
)
23+
val string: String = helpers.readRegisterString(register = source)
24+
val destinationAddress: Long = registers.read(register = destination)
25+
helpers.writeStringSpecInMemory(
26+
string = string, destinationAddress = MemoryAddress(address = destinationAddress)
27+
)
2828
} catch (_: Exception) {
29-
errors.GeneralStringException(message = "Strcpy")
29+
errors.GeneralStringException(message = "Strcpy")
3030
}

src/main/kotlin/internals/systemCalls/calls/exit.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ import kotlin.system.exitProcess
1313
*/
1414
@Suppress("RemoveExplicitTypeArguments")
1515
fun SystemCall.exit(s2: RegisterType) = call("exit") {
16-
val exitCode: Long = registers.read(register = s2)
17-
exitProcess(status = with<Long, Int>(receiver = exitCode) { return@with this.run<Long, Int>(block = Long::toInt) })
16+
val exitCode: Long = registers.read(register = s2)
17+
exitProcess(status = with<Long, Int>(receiver = exitCode) { return@with this.run<Long, Int>(block = Long::toInt) })
1818
}

0 commit comments

Comments
 (0)