Scope/InstructionObject: Change address and resolve type to expression.
M src/main/java/nl/grauw/glass/GlobalScope.java +2 -1
@@ 2,6 2,7 @@ package nl.grauw.glass;
 
 import nl.grauw.glass.expressions.Expression;
 import nl.grauw.glass.expressions.Instruction;
+import nl.grauw.glass.expressions.IntegerLiteral;
 import nl.grauw.glass.instructions.*;
 import nl.grauw.glass.instructions.Error;
 

          
@@ 9,7 10,7 @@ public class GlobalScope extends Scope {
 
 	public GlobalScope() {
 		super();
-		setAddress(0);
+		setAddress(IntegerLiteral.ZERO);
 
 		addBuiltInSymbol("adc", new Instruction(new Adc(), new Scope(this)));
 		addBuiltInSymbol("add", new Instruction(new Add(), new Scope(this)));

          
M src/main/java/nl/grauw/glass/Line.java +1 -1
@@ 95,7 95,7 @@ public class Line {
 		}
 	}
 
-	public int resolve(int address) {
+	public Expression resolve(Expression address) {
 		try {
 			instructionObject = getInstruction().createObject(scope, arguments);
 			return instructionObject.resolve(address);

          
M src/main/java/nl/grauw/glass/Scope.java +5 -7
@@ 15,10 15,9 @@ import nl.grauw.glass.expressions.Type;
 
 public class Scope implements Context {
 
-	private boolean set = false;
 	private final Scope parent;
 	private final Map<String, Expression> symbols = new HashMap<>();
-	private int address = 0;
+	private Expression address;
 
 	public Scope() {
 		this(null);

          
@@ 37,17 36,16 @@ public class Scope implements Context {
 	}
 
 	@Override
-	public int getAddress() {
-		if (!set)
+	public Expression getAddress() {
+		if (this.address == null)
 			throw new EvaluationException("Address not initialized.");
 		return address;
 	}
 
-	public void setAddress(int address) {
-		if (set)
+	public void setAddress(Expression address) {
+		if (this.address != null)
 			throw new AssemblyException("Address was already set.");
 		this.address = address;
-		this.set = true;
 	}
 
 	public void addSymbol(String name, Expression value) {

          
M src/main/java/nl/grauw/glass/Source.java +6 -3
@@ 6,6 6,9 @@ import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.List;
 
+import nl.grauw.glass.expressions.Expression;
+import nl.grauw.glass.expressions.IntegerLiteral;
+
 public class Source {
 
 	private final Scope scope;

          
@@ 75,11 78,11 @@ public class Source {
 			line.expand(newLines);
 	}
 
-	public int resolve() {
-		return resolve(0);
+	public Expression resolve() {
+		return resolve(IntegerLiteral.ZERO);
 	}
 
-	public int resolve(int address) {
+	public Expression resolve(Expression address) {
 		for (Line line : lines)
 			address = line.resolve(address);
 		return address;

          
M src/main/java/nl/grauw/glass/expressions/Context.java +1 -1
@@ 10,6 10,6 @@ public interface Context {
 
 	public boolean hasLocalSymbol(String name);
 
-	public int getAddress();
+	public Expression getAddress();
 
 }

          
M src/main/java/nl/grauw/glass/expressions/ContextLiteral.java +1 -1
@@ 28,7 28,7 @@ public class ContextLiteral extends Lite
 		if (type == Type.CONTEXT)
 			return this;
 		if (type == Type.INTEGER)
-			return IntegerLiteral.of(context.getAddress());
+			return context.getAddress();
 		return super.get(type);
 	}
 

          
M src/main/java/nl/grauw/glass/instructions/Djnz.java +1 -1
@@ 31,7 31,7 @@ public class Djnz extends InstructionFac
 
 		@Override
 		public byte[] getBytes() {
-			int offset = argument.getInteger() - (context.getAddress() + 2);
+			int offset = argument.getInteger() - (context.getAddress().getInteger() + getSize());
 			if (offset < -128 || offset > 127)
 				throw new ArgumentException("Jump offset out of range: " + offset);
 			return new byte[] { (byte)0x10, (byte)offset };

          
M src/main/java/nl/grauw/glass/instructions/Ds.java +2 -2
@@ 54,8 54,8 @@ public class Ds extends InstructionFacto
 		}
 
 		@Override
-		public int resolve(int address) {
-			int innerAddress = address;
+		public Expression resolve(Expression address) {
+			Expression innerAddress = address;
 			for (Section section : sections)
 				innerAddress = section.getSource().resolve(innerAddress);
 			return super.resolve(address);

          
M src/main/java/nl/grauw/glass/instructions/If.java +1 -1
@@ 48,7 48,7 @@ public class If extends InstructionFacto
 		}
 
 		@Override
-		public int resolve(int address) {
+		public Expression resolve(Expression address) {
 			context.setAddress(address);
 			if (argument.getInteger() != 0) {
 				return thenSource.resolve(address);

          
M src/main/java/nl/grauw/glass/instructions/InstructionObject.java +6 -2
@@ 1,7 1,11 @@ 
 package nl.grauw.glass.instructions;
 
 import nl.grauw.glass.Scope;
+import nl.grauw.glass.expressions.Add;
+import nl.grauw.glass.expressions.Expression;
+import nl.grauw.glass.expressions.IntegerLiteral;
 import nl.grauw.glass.expressions.Register;
+import nl.grauw.glass.expressions.Type;
 
 public abstract class InstructionObject {
 

          
@@ 11,9 15,9 @@ public abstract class InstructionObject 
 		this.context = context;
 	}
 
-	public int resolve(int address) {
+	public Expression resolve(Expression address) {
 		context.setAddress(address);
-		return address + getSize();
+		return new Add(IntegerLiteral.of(getSize()), address).get(Type.INTEGER);
 	}
 
 	public abstract int getSize();

          
M src/main/java/nl/grauw/glass/instructions/Jr.java +2 -2
@@ 33,7 33,7 @@ public class Jr extends InstructionFacto
 
 		@Override
 		public byte[] getBytes() {
-			int offset = argument.getInteger() - (context.getAddress() + 2);
+			int offset = argument.getInteger() - (context.getAddress().getInteger() + getSize());
 			if (offset < -128 || offset > 127)
 				throw new ArgumentException("Jump offset out of range: " + offset);
 			return new byte[] { (byte)0x18, (byte)offset };

          
@@ 63,7 63,7 @@ public class Jr extends InstructionFacto
 
 		@Override
 		public byte[] getBytes() {
-			int offset = argument2.getInteger() - (context.getAddress() + 2);
+			int offset = argument2.getInteger() - (context.getAddress().getInteger() + getSize());
 			if (offset < -128 || offset > 127)
 				throw new ArgumentException("Jump offset out of range: " + offset);
 			return new byte[] { (byte)(0x20 | argument1.getFlag().getCode() << 3), (byte)offset };

          
M src/main/java/nl/grauw/glass/instructions/Macro.java +2 -2
@@ 61,9 61,9 @@ public class Macro extends InstructionFa
 		}
 
 		@Override
-		public int resolve(int address) {
+		public Expression resolve(Expression address) {
 			try {
-				source.resolve(0);
+				source.resolve(IntegerLiteral.ZERO);
 			} catch (AssemblyException e) {
 				// ignore
 			}

          
M src/main/java/nl/grauw/glass/instructions/Org.java +2 -2
@@ 25,9 25,9 @@ public class Org extends InstructionFact
 		}
 
 		@Override
-		public int resolve(int address) {
+		public Expression resolve(Expression address) {
 			super.resolve(address);
-			return argument.getInteger();
+			return argument;
 		}
 
 	}

          
M src/test/java/nl/grauw/glass/instructions/InstructionTest.java +2 -1
@@ 8,6 8,7 @@ import nl.grauw.glass.Parser;
 import nl.grauw.glass.Scope;
 import nl.grauw.glass.SourceFile;
 import nl.grauw.glass.TestBase;
+import nl.grauw.glass.expressions.IntegerLiteral;
 
 import org.junit.jupiter.api.Test;
 

          
@@ 954,7 955,7 @@ public class InstructionTest extends Tes
 
 	public byte[] parse(String string) {
 		Line line = new Parser(new SourceFile(" " + string)).parse(new Scope(new GlobalScope()));
-		line.resolve(0x4321);
+		line.resolve(IntegerLiteral.of(0x4321));
 		byte[] bytes = line.getBytes();
 		assertEquals(bytes.length, line.getSize());
 		return bytes;