|
| 1 | +package com.falsepattern.jfunge.interpreter.instructions.fingerprints; |
| 2 | + |
| 3 | +import com.falsepattern.jfunge.interpreter.ExecutionContext; |
| 4 | +import com.falsepattern.jfunge.interpreter.instructions.Fingerprint; |
| 5 | +import com.falsepattern.jfunge.util.MemoryStack; |
| 6 | +import lombok.AccessLevel; |
| 7 | +import lombok.Cleanup; |
| 8 | +import lombok.NoArgsConstructor; |
| 9 | +import lombok.val; |
| 10 | + |
| 11 | +@NoArgsConstructor(access = AccessLevel.PRIVATE) |
| 12 | +public class JSTR implements Fingerprint { |
| 13 | + public static final JSTR INSTANCE = new JSTR(); |
| 14 | + @Override |
| 15 | + public int code() { |
| 16 | + return 0x4a535452; |
| 17 | + } |
| 18 | + |
| 19 | + @Instr('P') |
| 20 | + public static void putString(ExecutionContext ctx) { |
| 21 | + val stack = ctx.stack(); |
| 22 | + val ip = ctx.IP(); |
| 23 | + val fs = ctx.fungeSpace(); |
| 24 | + @Cleanup val mStack = MemoryStack.stackPush(); |
| 25 | + val position = mStack.vec3i(); |
| 26 | + val delta = mStack.vec3i(); |
| 27 | + |
| 28 | + val count = stack.pop(); |
| 29 | + stack.popVecDimProof(ctx.dimensions(), position); |
| 30 | + stack.popVecDimProof(ctx.dimensions(), delta); |
| 31 | + |
| 32 | + position.add(ip.storageOffset()); |
| 33 | + for (int i = 0; i < count; i++) { |
| 34 | + fs.set(position, stack.pop()); |
| 35 | + position.add(delta); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + @Instr('G') |
| 40 | + public static void getString(ExecutionContext ctx) { |
| 41 | + val stack = ctx.stack(); |
| 42 | + val ip = ctx.IP(); |
| 43 | + val fs = ctx.fungeSpace(); |
| 44 | + @Cleanup val mStack = MemoryStack.stackPush(); |
| 45 | + val position = mStack.vec3i(); |
| 46 | + val delta = mStack.vec3i(); |
| 47 | + |
| 48 | + val count = stack.pop(); |
| 49 | + stack.popVecDimProof(ctx.dimensions(), position); |
| 50 | + stack.popVecDimProof(ctx.dimensions(), delta); |
| 51 | + |
| 52 | + position.add(ip.storageOffset()); |
| 53 | + stack.push(0); |
| 54 | + for (int i = 0; i < count; i++) { |
| 55 | + stack.push(fs.get(position)); |
| 56 | + position.add(delta); |
| 57 | + } |
| 58 | + } |
| 59 | +} |
0 commit comments