You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
542 B

  1. class Value {
  2. }
  3. class Var : Value {
  4. }
  5. class Ctx {
  6. char *currentComponent;
  7. Var getParam(char *);
  8. Var getSignal(char *, ...);
  9. Var newVar(char *);
  10. }
  11. void Num2Bits::Num2Bits(ctx) {
  12. Var n = ctx.getParam("n");
  13. Var in = ctx.getSignal("in");
  14. Var out = ctx.getSignal("out");
  15. (Var lc1 = ctx.newVar()) = _0x0;
  16. for ((Var i = ctx.newVar()) = _0x0 ; i<n; i++ ) {
  17. out[i] = (in >> i) & _0x1;
  18. assert(out[i]*(out[i] - _0x1), _0x0);
  19. lc1 += out[i] * (2**i);
  20. }
  21. assert(lc1, in);
  22. }