diff src/nabble/naml/namespaces/IntegerNamespace.java @ 0:7ecd1a4ef557

add content
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 21 Mar 2019 19:15:52 -0600
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/nabble/naml/namespaces/IntegerNamespace.java	Thu Mar 21 19:15:52 2019 -0600
@@ -0,0 +1,76 @@
+package nabble.naml.namespaces;
+
+import nabble.naml.compiler.Command;
+import nabble.naml.compiler.CommandSpec;
+import nabble.naml.compiler.IPrintWriter;
+import nabble.naml.compiler.Interpreter;
+import nabble.naml.compiler.Namespace;
+import nabble.naml.compiler.Primitive;
+
+
+@Namespace (
+	name = "integer",
+	global = false,
+	transparent = true
+)
+public final class IntegerNamespace implements Primitive {
+	private int i;
+
+	public IntegerNamespace(int i) {
+		this.i = i;
+	}
+
+	public String toString() {
+		return Integer.toString(i);
+	}
+
+	private static final CommandSpec I = new CommandSpec.Builder()
+		.dotParameter("i")
+		.build()
+	;
+
+	public static final CommandSpec plus = I;
+
+	@Command public void plus(IPrintWriter out,Interpreter interp) {
+		out.print( i = i + interp.getArgAsInt("i") );
+	}
+
+	@Command public void value(IPrintWriter out,Interpreter interp) {
+		out.print(i);
+	}
+
+	public static final CommandSpec minus = I;
+
+	@Command public void minus(IPrintWriter out,Interpreter interp) {
+		out.print( i = i - interp.getArgAsInt("i") );
+	}
+
+	public static final CommandSpec is_greater_than = I;
+
+	@Command public void is_greater_than(IPrintWriter out,Interpreter interp) {
+		out.print( i > interp.getArgAsInt("i") );
+	}
+
+	public static final CommandSpec is_greater_than_or_equal_to = I;
+
+	@Command public void is_greater_than_or_equal_to(IPrintWriter out,Interpreter interp) {
+		out.print( i >= interp.getArgAsInt("i") );
+	}
+
+	public static final CommandSpec is_less_than = I;
+
+	@Command public void is_less_than(IPrintWriter out,Interpreter interp) {
+		out.print( i < interp.getArgAsInt("i") );
+	}
+
+	public static final CommandSpec is_less_than_or_equal_to = I;
+
+	@Command public void is_less_than_or_equal_to(IPrintWriter out,Interpreter interp) {
+		out.print( i <= interp.getArgAsInt("i") );
+	}
+
+	@Command public void one(IPrintWriter out,Interpreter interp) {
+		out.print( 1 );
+	}
+
+}