Beispiel #1
0
/* u2_bx_post(): export and reset the performance log.
**
**  zat: source position stack (on shed)
**  zof: programer action stack (on shed)
**  sap: number of steps
**  cop: number of words copied
**  det: number of identical nouns compared
**  jax: number of jet activations
**  use: number of user counts
**  wax: maximum depth of C stack
**  viq: words in wire allocated
**  zor: words in basket allocated
**  ums: number of milliseconds consumed
*/
u2_bean
u2_bx_post(u2_ray   wir_r,
           u2_noun* zat,
           u2_noun* zof, 
           c3_d*    sap_d,
           c3_d*    cop_d,
           c3_d*    det_d,
           c3_d*    jax_d,
           c3_d*    use_d,
           c3_w*    wax_w,
           c3_ws*   viq_ws,
           c3_ws*   zor_ws,
           c3_w*    ums_w)
{
  u2_ray bex_r;

  if ( 0 == (bex_r = u2_wire_bex_r(wir_r)) ) {
    return u2_no;
  } else {
    c3_w   sec_w, usc_w;

    *zat = u2_benx_at(bex_r, zat);
    *zof = u2_benx_at(bex_r, zof);

    *sap_d = u2_benx_be(bex_r, c3_d, sap_d);
    *cop_d = u2_benx_be(bex_r, c3_d, cop_d);
    *det_d = u2_benx_be(bex_r, c3_d, det_d);
    *jax_d = u2_benx_be(bex_r, c3_d, jax_d);
    *use_d = u2_benx_be(bex_r, c3_d, use_d);

    *wax_w = u2_benx_at(bex_r, wax_w);

    *viq_ws = u2_soup_liv_w(u2_rail_rut_r(wir_r)) - 
              u2_benx_be(bex_r, c3_w, lif_w);

    *zor_ws = u2_soup_liv_w(u2_rail_rut_r(u2_wire_bas_r(wir_r))) - 
              u2_benx_be(bex_r, c3_w, bos_w);

    sec_w = u2_benx_at(bex_r, sec_w);
    usc_w = u2_benx_at(bex_r, usc_w);
    u2_bx_boot(wir_r);

    /* Measure and return time change.
    */
    {
      c3_d old_d, new_d;

      old_d = sec_w;
      old_d *= 1000000ULL;
      old_d += usc_w;

      new_d = u2_benx_at(bex_r, sec_w);
      new_d *= 1000000ULL;
      new_d += u2_benx_at(bex_r, usc_w);

      *ums_w = (c3_w) (((new_d - old_d) + 999ULL) / 1000ULL);
    }
    return u2_yes;
  }
}
Beispiel #2
0
/* _hill_b_fire(): execute and print expression over pit C (with shoe B).
*/
static void                                                       //  produce
_hill_b_fire(u2_wire     wir_r,
             u2_noun     soa,                                     //  retain
             u2_noun     sob,                                     //  retain
             u2_noun     soc,                                     //  retain
             const c3_c* exp_c,                                   //  retain
             const c3_c* out_c)                                   //  retain
{
  u2_noun txt, gam, som;

  txt = u2_bn_string(wir_r, exp_c);
  gam = _hill_b_mint_txt(wir_r, soa, sob, u2_h(soc), c3__noun, txt);

  _hill_b_print_type(wir_r, soa, sob, 0, 0, u2_h(gam));

  if ( out_c && !strcmp("p", out_c) ) {
    u2_rz(wir_r, txt);
    u2_rz(wir_r, gam);
    return;
  }
  u2_bx_boot(wir_r);
  som = _hill_nock(wir_r, u2_t(soc), u2_t(gam));
  u2_bx_show(wir_r);

  if ( u2_none == som ) {
    fprintf(stderr, "{none}\n");
  }
  else {
    if ( !out_c ) {
      _hill_print_noun(wir_r, 0, 0, som);
    } else if ( !strcmp("w", out_c) ) {
      _hill_print_wall(wir_r, 0, 0, som);
    }
    else if ( !strcmp("t", out_c) ) {
      _hill_print_tape(wir_r, 0, som); printf("\n");
    }
    else if ( !strcmp("d", out_c) ) {
      _hill_print_delm(wir_r, 0, som); printf("\n");
    }
    else if ( !strcmp("e", out_c) ) {
      _hill_print_term(wir_r, 0, som); printf("\n");
    }
    else if ( !strcmp("y", out_c) ) {
      _hill_print_type(wir_r, 0, 0, som);
    }
  }
  u2_rz(wir_r, txt);
  u2_rz(wir_r, gam);
  u2_rz(wir_r, som);
}
Beispiel #3
0
/* zuse_boot(): create the zuse engine.
*/
struct zuse_state*
zuse_boot(const c3_c* src_c)
{
  struct zuse_state* fod_f = malloc(sizeof(struct zuse_state));
  u2_ray wir_r;

  u2_boot();
  wir_r = u2_wr_init(c3__rock, u2_ray_of(0, 0), u2_ray_of(1, 0));
  fod_f->wir_r = wir_r;

  {
    u2_ray jub_r = u2_bl_open(wir_r);

    fprintf(stderr, "boot: %s\n", src_c);
    if ( u2_bl_set(wir_r) ) {
      u2_bl_done(wir_r, jub_r);
      fprintf(stderr, "boot failed\n");

      free(fod_f);
      return 0;
    }
    else {
      u2_bx_boot(wir_r);

      if ( u2_yes == u2_ux_fresh(src_c, "watt", "noun") ) {
        _zuse_load_rock(fod_f, src_c);
      } else {
        _zuse_load_cold(fod_f, src_c);
      }
      _zuse_gates(fod_f);

      u2_bl_done(wir_r, jub_r);
      u2_bx_spot(wir_r, u2_nul);
      u2_bx_show(wir_r);

      return fod_f;
    }
  }
}
Beispiel #4
0
/* hill_line(): execute a hill command line.
*/
void
hill_line(struct hill_state* hil_h,
          const c3_c*        lin_c)
{
  u2_wire wir_r = hil_h->wir_r;
  hi_shoa soa   = hil_h->soa;
  hi_shoz sob   = hil_h->sob;
  hi_shob soc   = hil_h->soc;
  const c3_c* out_c = 0;

  u2_bx_boot(wir_r);
  u2_bx_spot(wir_r, u2_nul);

  //  XX - a heinous hack.
  //
#if 0
  if ( !strcmp(lin_c, "!") ) {
    FooBar = 1;
    {
      u2_ray  kit_r = u2_bl_open(wir_r);

      if ( u2_bl_set(wir_r) ) {
        u2_bl_done(wir_r, kit_r);
        fprintf(stderr, "{no boot, c}\n");
      }
      else {
        soc = _hill_b_boot(wir_r, soa, sob, FileC);
        fprintf(stderr, "{test boot: %s, with %s: %x}\n", FileC, FileB,
            u2_mug(soc));
        u2_bl_done(wir_r, kit_r);
      }
      LoomStop = 0;
      u2_bx_show(wir_r);
      return;
    }
  }
  else 
#endif
    if ( !strncmp(lin_c, "w ", 2) ) {
    lin_c += 2; out_c = "w";
  } else if ( !strncmp(lin_c, "t ", 2) ) {
    lin_c += 2; out_c = "t";
  } else if (  !strncmp(lin_c, "d ", 2) ) {
    lin_c += 2; out_c = "d";
  } else if (  !strncmp(lin_c, "e ", 2) ) {
    lin_c += 2; out_c = "e";
  } else if (  !strncmp(lin_c, "p ", 2) ) {
    lin_c += 2; out_c = "p";
  } else if (  !strncmp(lin_c, "y ", 2) ) {
    lin_c += 2; out_c = "y";
  }
  else out_c = 0;

  {
    u2_ray kit_r = u2_bl_open(wir_r);

    if ( u2_bl_set(wir_r) ) {
      u2_bl_done(wir_r, kit_r);
      fprintf(stderr, "{exit}\n");
    } else {
      _hill_a_fire(wir_r, soa, sob, lin_c, out_c);
      // _hill_b_fire(wir_r, soa, sob, soc, lin_c, out_c);

      u2_bl_done(wir_r, kit_r);
    }
  }

  LoomStop = 0;
}
Beispiel #5
0
/* hill_boot(): create the hill engine.
*/
struct hill_state*                                                //  produce
hill_boot(void)
{
  struct hill_state* hil_h = malloc(sizeof(struct hill_state));
  u2_ray wir_r;

  u2_boot();
  wir_r = u2_wr_init(c3__rock, u2_ray_of(0, 0), u2_ray_of(1, 0));

  Hill = hil_h;
  Hill->wir_r = wir_r;
  Hill->soa = u2_none;
  Hill->sob = u2_none;
  Hill->soc = u2_none;

  /* Mint the shoes.  Impeccable memory practices.
  */
  {
    u2_noun soa = u2_none;
    u2_noun sob = u2_none;
    u2_noun soc = u2_none;

    do {
      /* Boot shoe A.
      */
      if ( u2_no == u2_rl_leap(wir_r, c3__rock) ) {
        c3_assert(0);
      }
      u2_bx_boot(wir_r);
      {
        u2_ray  kit_r = u2_bl_open(wir_r);

        if ( u2_bl_set(wir_r) ) {
          u2_bl_done(wir_r, kit_r);
          u2_rl_fall(wir_r);
          fprintf(stderr, "{no boot, a}\n");
          break;
        }
        else {
          soa = _hill_z_boot(wir_r, FileA);
          u2_bl_done(wir_r, kit_r);
          u2_bx_spot(wir_r, u2_nul);
          u2_bx_show(wir_r);
        }
      }
      fprintf(stderr, "{cold boot: %s, with %s jets: %x}\n", 
          FileA, FileZ, u2_mug(soa));
      Hill->soa = u2_rl_take(u2_wire_bas_r(wir_r), soa);
      u2_rl_fall(wir_r);

      /* Boot shoe B.
      */
      if ( u2_no == u2_rl_leap(wir_r, c3__rock) ) {
        c3_assert(0);
      }
      u2_bx_boot(wir_r);
      {
        u2_ray  kit_r = u2_bl_open(wir_r);

        if ( u2_bl_set(wir_r) ) {
          u2_bl_done(wir_r, kit_r);
          u2_rl_fall(wir_r);
          fprintf(stderr, "{no boot, b}\n");
          break;
        }
        else {
          sob = _hill_a_boot(wir_r, soa, FileB);
          u2_bl_done(wir_r, kit_r);

          u2_bx_spot(wir_r, u2_nul);
          u2_bx_show(wir_r);
        }
      }
      fprintf(stderr, "{warm boot: %s, with %s: %x}\n", 
          FileB, FileA, u2_mug(sob));
      Hill->sob = u2_rl_take(u2_wire_bas_r(wir_r), sob);
      u2_rl_fall(wir_r);

      /* Boot shoe C.
      */
      if ( u2_no == u2_rl_leap(wir_r, c3__rock) ) {
        c3_assert(0);
      }
      u2_bx_boot(wir_r);
      {
        u2_ray  kit_r = u2_bl_open(wir_r);

        if ( u2_bl_set(wir_r) ) {
          u2_bl_done(wir_r, kit_r);
          u2_rl_fall(wir_r);
          fprintf(stderr, "{no boot, c}\n");
          u2_bx_show(wir_r);
          break;
        }
        else {
          soc = _hill_b_eyre(wir_r, soa, sob, FileC);
          u2_bl_done(wir_r, kit_r);

          u2_bx_spot(wir_r, u2_nul);
          u2_bx_show(wir_r);
        }
      }
      fprintf(stderr, "{last boot: %s, with %s: %x}\n", 
          FileC, FileB, u2_mug(soc));
      Hill->soc = u2_rl_take(u2_wire_bas_r(wir_r), soc);
      u2_rl_fall(wir_r);

      /* Testing basics of soc.
      */
      printf("testing eyre...\n");
      {
        u2_noun foo = u2_rl_string(wir_r, "|!(a=@ (dec a))");
        u2_noun bar = u2_nk_nock(wir_r, foo, Hill->soc);

        if ( u2_none == bar ) {
          printf("no bar\n");
        }
        else {
          u2_noun moo = u2_nk_nock(wir_r, _0, bar);
            
          if ( u2_none == moo ) {
            printf("no moo\n");
          } else {
            u2_noun zor = u2_nk_mung(wir_r, moo, 13);

            u2_err(wir_r, "zor", zor);
          }
        }
      }
      printf("tested.\n");

#if 1
      {
        u2_noun soa = Hill->soa;
        u2_noun sob = Hill->sob;
        u2_noun dat = Hill->soc;
        u2_noun pak, bag;

        fprintf(stderr, "jam test: jam\n");
        u2_bx_boot(wir_r);
        pak = _hill_b_jam(wir_r, soa, sob, dat);
        u2_bx_show(wir_r);

        fprintf(stderr, "jam test: %d bits\n", u2_met(0, pak));
        u2_ux_write(wir_r, pak, "watt/264", "noun");

        fprintf(stderr, "jam test: cue\n");
        u2_bx_boot(wir_r);
        bag = _hill_b_cue(wir_r, soa, sob, pak);
        u2_bx_show(wir_r);

        if ( u2_yes == u2_sing(bag, dat) ) {
          fprintf(stderr, "jam test: match\n");
        } else {
          fprintf(stderr, "jam test: NO MATCH\n");
        }
      }
#endif
      return Hill;
    } while (0);

    free(Hill);
    return 0;
  }
}
Beispiel #6
0
/* zuse_line(): execute a zuse line, as command and argument.
*/
void
zuse_line(struct zuse_state* fod_f,
          const c3_c*        cmd_c,
          const c3_c*        arg_c)
{
  u2_ray  wir_r = fod_f->wir_r;
  u2_ray  cap_r = u2_rail_cap_r(wir_r);

  LoomStop = 0;
  u2_bx_boot(wir_r);
  u2_rl_leap(wir_r, c3__rock);
  {
    u2_ray jub_r = u2_bl_open(wir_r);

    if ( u2_bl_set(wir_r) ) {
      u2_bl_done(wir_r, jub_r);
    }
    else {
      if ( !strcmp(cmd_c, "test") ) {
        // zuse_test(fod_f, "watt/t1-273");
        zuse_test3(fod_f, "watt/270", arg_c);
      }
      else if ( !strcmp(cmd_c, "next") ) {
        zuse_next4(fod_f, "watt/270", "watt/269", "watt/268", arg_c);
      }
      else {
#if 0
        u2_noun cmd = u2_bn_string(wir_r, cmd_c);
        u2_noun cor = u2_bn_mung(wir_r, fod_f->ryd, cmd);

        u2_burp(wir_r, 0, u2_fj_prep_noun(wir_r, cor));

        if ( arg_c ) {
          u2_noun arg = u2_bn_string(wir_r, arg_c);
          u2_noun sam = u2_bn_mung(wir_r, fod_f->ryd, arg);

          u2_burp(wir_r, 0, u2_fj_prep_noun(wir_r, sam));
        }
#else
        u2_noun gat, sam, pro;

        /* Construct gate from command.
        */
        gat = _zuse_from(fod_f, cmd_c);

        /* Construct sample from argument.
        */
        sam = _zuse_from(fod_f, arg_c);

        /* Construct product.
        */
        pro = u2_nk_mung(wir_r, gat, sam);

        /* Print, if applicable.
        */
        {
          if ( u2_none != pro ) {
            u2_prep pap = u2_fj_prep_noun(wir_r, pro);

            u2_burp(wir_r, 0, pap);
            u2_bx_spot(wir_r, u2_nul);
          }
        }
      }
#endif
    }
  }
  u2_nk_show(wir_r, stderr);

  u2_rl_fall(wir_r);
  u2_rail_cap_r(wir_r) = cap_r;

  u2_bx_show(wir_r);
}
Beispiel #7
0
/* u2_wr_init():
**
**   Install an empty wire within `hat_r` and `mat_r` in the loom,
**   with memory model `hip`.
**
**   Returns ray to wire, which always equalls the passed `mat_r`.
*/
u2_ray
u2_wr_init(c3_m   hip_m,
           u2_ray hat_r,
           u2_ray mat_r)
{
  u2_ray wir_r;

  wir_r = u2_rl_init(hip_m, hat_r, mat_r);
  u2_rail_hat_r(wir_r) += (c3_wiseof(u2_loom_wire) - c3_wiseof(u2_loom_rail));

#if 1
  u2_wire_bas_r(wir_r) = 0;
#endif

  u2_wire_kit_r(wir_r) = 0;

  u2_cs_init(u2_wire_des_r(wir_r));

  /* Trace stack, garbage.
  */
  {
    u2_wire_tax(wir_r) = u2_nul;
    u2_wire_lan(wir_r) = u2_yes;
  }

  /* Permanent basket = 1/16 of address space.
  */
  {
    u2_ray bas_r;

    bas_r = u2_rl_leap_part(wir_r, c3__sand, 1, 16, 0);
    u2_wire_bas_r(wir_r) = bas_r;

#if 0
    fprintf(stderr, "bas_r %d, hat %d, mat %d, cap %d, rut %d\n",
        bas_r >> LoomPageWords,
        u2_rail_hat_r(bas_r) >> LoomPageWords,
        u2_rail_mat_r(bas_r) >> LoomPageWords,
        u2_rail_cap_r(bas_r) >> LoomPageWords,
        u2_rail_rut_r(bas_r) >> LoomPageWords);

    fprintf(stderr, "wir_r %d, hat %d, mat %d, cap %d, rut %d\n",
        wir_r >> LoomPageWords,
        u2_rail_hat_r(wir_r) >> LoomPageWords,
        u2_rail_mat_r(wir_r) >> LoomPageWords,
        u2_rail_cap_r(wir_r) >> LoomPageWords,
        u2_rail_rut_r(wir_r) >> LoomPageWords);
#endif

    // u2_ba_init(wir_r, 0);
  }

#if 1
  /* Host control.
  */
  {
    u2_ho_push();
  }
#endif

  /* Basic performance tracking.
  */
  {
    u2_wire_bex_r(wir_r) = u2_rl_ralloc(wir_r, c3_wiseof(u2_loom_benx));

    u2_bx_boot(wir_r);
  }

  /* New performance tracking.
  */
  {
    u2_wire_rac_r(wir_r) = u2_tx_init(wir_r);
  }

  /* Global namespace.
  */
  {
    u2_wire_hev_r(wir_r) = u2_hv_init(wir_r);
  }

  /* OS kernel.
  */
  {
    u2_wire_arv_r(wir_r) = u2_rl_ralloc(wir_r, c3_wiseof(u2_reck));
  }

  return wir_r;
}