@@ -27,8 +27,8 @@ public void execute(final SimpleStackMachine machine) {
2727 machine .checkTapeReserve (1 + Long .BYTES );
2828 machine .advanceInstructionPointer ();
2929
30- final long number =
31- machine .readNumberFromTape (machine .getInstructionPointer () );
30+ final int number =
31+ machine .readWordFromTape (machine .getInstructionPointer ());
3232
3333 machine .push (number );
3434 }
@@ -39,7 +39,7 @@ public static final class PopInstructionImplementation
3939
4040 @ Override
4141 public void execute (SimpleStackMachine machine ) {
42- machine .checkTapeReserve (1 );
42+ machine .checkTapeReserve (Integer . BYTES );
4343 machine .advanceInstructionPointer ();
4444 machine .pop ();
4545 }
@@ -50,13 +50,13 @@ public static final class LoadInstructionImplementation
5050
5151 @ Override
5252 public void execute (SimpleStackMachine machine ) {
53- machine .checkTapeReserve (1 + Long . BYTES );
53+ machine .checkTapeReserve (1 );
5454 machine .advanceInstructionPointer ();
5555
56- final long address =
57- machine .readNumberFromTape (machine .getInstructionPointer ());
56+ final int address =
57+ machine .readWordFromTape (machine .getInstructionPointer ());
5858
59- final long datum = machine .readNumberFromTape (( int ) address );
59+ final int datum = machine .readWordFromTape ( address );
6060
6161 machine .push (datum );
6262 }
@@ -67,18 +67,20 @@ public static final class StoreInstructionImplementation
6767
6868 @ Override
6969 public void execute (SimpleStackMachine machine ) {
70- machine .checkTapeReserve (1 + 2 * Long .BYTES );
70+ machine .requireStackSize (2 );
71+ machine .checkTapeReserve (2 * Integer .BYTES );
7172 machine .advanceInstructionPointer ();
7273
73- final long address =
74- machine .readNumberFromTape (machine .getInstructionPointer ());
74+ final int address =
75+ machine .readWordFromTape (machine .getInstructionPointer ());
7576
76- machine .advanceInstructionPointer (Long .BYTES );
77+ machine .advanceInstructionPointer (Integer .BYTES );
7778
78- final long datum = machine .readNumberFromTape (machine .getInstructionPointer ());
79+ final int datum = machine .readWordFromTape (
80+ machine .getInstructionPointer ());
7981
80- machine .writeNumberToTape (( int ) address , datum );
81- machine .advanceInstructionPointer (Long .BYTES );
82+ machine .writeWordToTape ( address , datum );
83+ machine .advanceInstructionPointer (Integer .BYTES );
8284 }
8385 }
8486
@@ -97,25 +99,27 @@ public void execute(SimpleStackMachine machine) {
9799 public static /*final*/ class BinaryArithmeticInstructionImplementation
98100 implements InstructionImplementation {
99101
100- private final BinaryOperator <Long > func ;
102+ private final BinaryOperator <Integer > func ;
101103
102104 public BinaryArithmeticInstructionImplementation (
103- final BinaryOperator <Long > func ) {
105+ final BinaryOperator <Integer > func ) {
104106 this .func = func ;
105107 }
106108
107109 @ Override
108- public void execute (SimpleStackMachine machine ) {
109- machine .checkTapeReserve (1 + 2 * Long . BYTES );
110+ public void execute (final SimpleStackMachine machine ) {
111+ machine .checkTapeReserve (1 );
110112 machine .requireStackSize (2 );
111113 machine .advanceInstructionPointer ();
112114
113- final long number1 =
114- machine .readNumberFromTape (machine .getInstructionPointer ());
115+ final int number1 =
116+ machine .readWordFromTape (machine .getInstructionPointer ());
117+
118+ machine .advanceInstructionPointer (Integer .BYTES );
115119
116- final long number2 =
117- machine .readNumberFromTape (
118- machine .getInstructionPointer () + Long . BYTES );
120+ final int number2 =
121+ machine .readWordFromTape (
122+ machine .getInstructionPointer ());
119123
120124 machine .pop ();
121125 machine .pop ();
@@ -201,8 +205,8 @@ public static final class SwapInstructionImplementation
201205 public void execute (final SimpleStackMachine machine ) {
202206 machine .checkTapeReserve (1 );
203207 machine .requireStackSize (2 );
204- final long number1 = machine .pop ();
205- final long number2 = machine .pop ();
208+ final int number1 = machine .pop ();
209+ final int number2 = machine .pop ();
206210 machine .push (number1 );
207211 machine .push (number2 );
208212 }
@@ -261,7 +265,7 @@ public void execute(final SimpleStackMachine machine) {
261265 machine .checkTapeReserve (1 + Long .BYTES );
262266 machine .advanceInstructionPointer ();
263267 final int jumpAddress =
264- (int ) machine .readNumberFromTape (
268+ (int ) machine .readWordFromTape (
265269 machine .getInstructionPointer ());
266270
267271 machine .checkTapeReserve (jumpAddress );
@@ -284,13 +288,15 @@ public static final class CallInstructionImplementation
284288
285289 @ Override
286290 public void execute (final SimpleStackMachine machine ) {
287- machine .checkTapeReserve (1 + Long .BYTES );
291+ machine .checkTapeReserve (1 + Integer .BYTES );
288292 machine .advanceInstructionPointer ();
289293
290- final long address = machine .readNumber ();
291- machine .advanceInstructionPointer (Long .BYTES );
294+ final int address =
295+ machine .readWordFromTape (machine .getInstructionPointer ());
296+
297+ machine .advanceInstructionPointer (Integer .BYTES );
292298 machine .push (machine .getInstructionPointer ());
293- machine .setInstructionPointer (( int ) address );
299+ machine .setInstructionPointer (address );
294300 }
295301 }
296302
@@ -302,8 +308,8 @@ public void execute(final SimpleStackMachine machine) {
302308 machine .checkTapeReserve (1 );
303309 machine .advanceInstructionPointer ();
304310
305- final long address = machine .pop ();
306- machine .setInstructionPointer (( int ) address );
311+ final int address = machine .pop ();
312+ machine .setInstructionPointer (address );
307313 }
308314 }
309315
@@ -312,12 +318,15 @@ public static final class JumpIfZeroInstructionImplementation
312318
313319 @ Override
314320 public void execute (final SimpleStackMachine machine ) {
315- machine .checkTapeReserve (1 + Long .BYTES );
321+ machine .checkTapeReserve (1 + Integer .BYTES );
316322 machine .advanceInstructionPointer ();
317323
318324 if (machine .flags ().zeroFlag ) {
319- final long address = machine .readNumber ();
320- machine .setInstructionPointer ((int ) address );
325+ final int address =
326+ machine .readWordFromTape (
327+ machine .getInstructionPointer ());
328+
329+ machine .setInstructionPointer (address );
321330 }
322331 }
323332 }
@@ -327,12 +336,15 @@ public static final class JumpIfNotZeroInstructionImplementation
327336
328337 @ Override
329338 public void execute (final SimpleStackMachine machine ) {
330- machine .checkTapeReserve (1 + Long .BYTES );
339+ machine .checkTapeReserve (1 + Integer .BYTES );
331340 machine .advanceInstructionPointer ();
332341
333342 if (machine .flags ().notZeroFlag ) {
334- final long address = machine .readNumber ();
335- machine .setInstructionPointer ((int ) address );
343+ final int address =
344+ machine .readWordFromTape (
345+ machine .getInstructionPointer ());
346+
347+ machine .setInstructionPointer (address );
336348 }
337349 }
338350 }
@@ -342,12 +354,15 @@ public static final class JumpIfBelowZeroInstructionImplementation
342354
343355 @ Override
344356 public void execute (final SimpleStackMachine machine ) {
345- machine .checkTapeReserve (1 + Long .BYTES );
357+ machine .checkTapeReserve (1 + Integer .BYTES );
346358 machine .advanceInstructionPointer ();
347359
348360 if (machine .flags ().belowZeroFlag ) {
349- final long address = machine .readNumber ();
350- machine .setInstructionPointer ((int ) address );
361+ final int address =
362+ machine .readWordFromTape (
363+ machine .getInstructionPointer ());
364+
365+ machine .setInstructionPointer (address );
351366 }
352367 }
353368 }
@@ -357,12 +372,15 @@ public static final class JumpIfAboveZeroInstructionImplementation
357372
358373 @ Override
359374 public void execute (final SimpleStackMachine machine ) {
360- machine .checkTapeReserve (1 + Long .BYTES );
375+ machine .checkTapeReserve (1 + Integer .BYTES );
361376 machine .advanceInstructionPointer ();
362377
363378 if (machine .flags ().aboveZeroFlag ) {
364- final long address = machine .readNumber ();
365- machine .setInstructionPointer ((int ) address );
379+ final int address =
380+ machine .readWordFromTape (
381+ machine .getInstructionPointer ());
382+
383+ machine .setInstructionPointer (address );
366384 }
367385 }
368386 }
@@ -372,12 +390,15 @@ public static final class JumpIfEqualInstructionImplementation
372390
373391 @ Override
374392 public void execute (final SimpleStackMachine machine ) {
375- machine .checkTapeReserve (1 + Long .BYTES );
393+ machine .checkTapeReserve (1 + Integer .BYTES );
376394 machine .advanceInstructionPointer ();
377395
378396 if (machine .flags ().equalFlag ) {
379- final long address = machine .readNumber ();
380- machine .setInstructionPointer ((int ) address );
397+ final int address =
398+ machine .readWordFromTape (
399+ machine .getInstructionPointer ());
400+
401+ machine .setInstructionPointer (address );
381402 }
382403 }
383404 }
@@ -387,12 +408,15 @@ public static final class JumpIfNotEqualInstructionImplementation
387408
388409 @ Override
389410 public void execute (final SimpleStackMachine machine ) {
390- machine .checkTapeReserve (1 + Long .BYTES );
411+ machine .checkTapeReserve (1 + Integer .BYTES );
391412 machine .advanceInstructionPointer ();
392413
393414 if (!machine .flags ().equalFlag ) {
394- final long address = machine .readNumber ();
395- machine .setInstructionPointer ((int ) address );
415+ final int address =
416+ machine .readWordFromTape (
417+ machine .getInstructionPointer ());
418+
419+ machine .setInstructionPointer (address );
396420 }
397421 }
398422 }
@@ -402,12 +426,15 @@ public static final class JumpIfAboveInstructionImplementation
402426
403427 @ Override
404428 public void execute (final SimpleStackMachine machine ) {
405- machine .checkTapeReserve (1 + Long .BYTES );
429+ machine .checkTapeReserve (1 + Integer .BYTES );
406430 machine .advanceInstructionPointer ();
407431
408432 if (machine .flags ().aboveFlag ) {
409- final long address = machine .readNumber ();
410- machine .setInstructionPointer ((int ) address );
433+ final int address =
434+ machine .readWordFromTape (
435+ machine .getInstructionPointer ());
436+
437+ machine .setInstructionPointer (address );
411438 }
412439 }
413440 }
@@ -417,12 +444,15 @@ public static final class JumpIfAboveOrEqualInstructionImplementation
417444
418445 @ Override
419446 public void execute (final SimpleStackMachine machine ) {
420- machine .checkTapeReserve (1 + Long .BYTES );
447+ machine .checkTapeReserve (1 + Integer .BYTES );
421448 machine .advanceInstructionPointer ();
422449
423450 if (machine .flags ().aboveFlag || machine .flags ().equalFlag ) {
424- final long address = machine .readNumber ();
425- machine .setInstructionPointer ((int ) address );
451+ final int address =
452+ machine .readWordFromTape (
453+ machine .getInstructionPointer ());
454+
455+ machine .setInstructionPointer (address );
426456 }
427457 }
428458 }
@@ -432,12 +462,15 @@ public static final class JumpIfBelowInstructionImplementation
432462
433463 @ Override
434464 public void execute (final SimpleStackMachine machine ) {
435- machine .checkTapeReserve (1 + Long .BYTES );
465+ machine .checkTapeReserve (1 + Integer .BYTES );
436466 machine .advanceInstructionPointer ();
437467
438468 if (machine .flags ().belowFlag ) {
439- final long address = machine .readNumber ();
440- machine .setInstructionPointer ((int ) address );
469+ final int address =
470+ machine .readWordFromTape (
471+ machine .getInstructionPointer ());
472+
473+ machine .setInstructionPointer (address );
441474 }
442475 }
443476 }
@@ -447,12 +480,15 @@ public static final class JumpIfBelowOrEqualInstructionImplementation
447480
448481 @ Override
449482 public void execute (final SimpleStackMachine machine ) {
450- machine .checkTapeReserve (1 + Long .BYTES );
483+ machine .checkTapeReserve (1 + Integer .BYTES );
451484 machine .advanceInstructionPointer ();
452485
453486 if (machine .flags ().belowFlag || machine .flags ().equalFlag ) {
454- final long address = machine .readNumber ();
455- machine .setInstructionPointer ((int ) address );
487+ final int address =
488+ machine .readWordFromTape (
489+ machine .getInstructionPointer ());
490+
491+ machine .setInstructionPointer (address );
456492 }
457493 }
458494 }
0 commit comments