package jazz.circuit;

///////////////////////////////////////////////////////////////////////////////
//
//                             Nets (i.e., circuit wires)
//
///////////////////////////////////////////////////////////////////////////////

public native final class Net implements BooleanAlgebra, Arith {
  // Register function
  public static native reg(x: Net): Net = "%reg";
  
  // The constant generator for nets
  public static native constant(c: rat): Net = "%net";
  
  // Conditional
  public static native mux(x: Net, y: Net, z: Net): Net = "%mux";
}

///////////////////////////////////////////////////////////////////////////////
//
//                               Implementation
//
///////////////////////////////////////////////////////////////////////////////

// Boolean algebra operators
final native Builtin.(&)(x@Net, y@Net) = "%binary_and";
final native Builtin.(|)(x@Net, y@Net) = "%binary_or";
final native Builtin.(^)(x@Net, y@Net) = "%binary_xor";
final native Builtin.(~)(x@Net) = "%binary_not";
final native Builtin.cond(x@Net, y@Net, z@Net) = "%mux";

// Numeric operators
final native Builtin.(*)(x@Net, y@Net) = "%mult";
final native Builtin.(+\2)(x@Net, y@Net) = "%add";
final native Builtin.(+\1)(x@Net) = "%plus";
final native Builtin.(-\2)(x@Net, y@Net) = "%sub";
final native Builtin.(-\1)(x@Net) = "%minus";