package com.oblivm.backend.lang.inter; import com.oblivm.backend.circuits.arithmetic.IntegerLib; import com.oblivm.backend.flexsc.CompEnv; import com.oblivm.backend.flexsc.IWritable; import com.oblivm.backend.flexsc.Mode; public class NullableType> implements IWritable, T1> { public T1 isNull; public T2 value; public CompEnv env; public IntegerLib intLib; public NullableType(CompEnv env, T2 data, T1 isNull) { this.value = data; this.isNull = isNull; this.env = env; this.intLib = new IntegerLib(env); } @Override public int numBits() { return value.numBits() + 1; } @Override public T1[] getBits() throws Exception { T1[] ret = env.newTArray(numBits()); ret[0] = isNull; System.arraycopy(value.getBits(), 0, ret, 1, ret.length - 1); return ret; } @Override public NullableType newObj(T1[] data) throws Exception { T1[] ret = env.newTArray(data.length - 1); System.arraycopy(data, 1, ret, 0, ret.length); return new NullableType(env, value.newObj(ret), data[0]); } public NullableType mux(T1 is, NullableType obj) throws Exception { if (env.mode == Mode.COUNT) { intLib.mux(value.getBits(), obj.value.getBits(), is); intLib.mux(isNull, obj.isNull, is); return this; } return new NullableType(env, value.newObj(intLib.mux(value.getBits(), obj.getBits(), is)), intLib.mux(isNull, obj.isNull, is)); } public T2 muxFake() throws Exception { if (env.mode == Mode.COUNT) { intLib.mux(value.getBits(), getFake().getBits(), isNull); return value; } return value.newObj(intLib.mux(value.getBits(), getFake().getBits(), isNull)); } public T2 getFake() throws Exception { if (env.mode == Mode.COUNT) { return value; } return value.fake(); } }