Ejemplo n.º 1
0
int main(int argc, char *argv[])
{ 
  ATerm in_term, out_term;
  int i;

  /* ATfprintf(stderr, "This is %s\n", argv[0]); */

  ATinit(argc, argv, &in_term);

  ATprotectArray(term_stack,   TSIZE);
  ATprotectArray(environment,  ESIZE);

  in_term = ATmake("Nil");
  for(i = argc - 1; i >= 0; i--)
    {
      /* ATfprintf(stderr, " %s", argv[i]); */
      in_term = App2("Cons", ATmakeString(argv[i]), in_term);
    }

  /* ATfprintf(stderr, "\n", argv[i]); */

  out_term = doit(in_term);
  ATfprintf(stderr, "**** rewriting terminated abnormally\n");
  exit(3);
}
Ejemplo n.º 2
0
/**
 * Note: mandatory in C89 and C99
 */
ATerm SSL_getenv(ATerm name)
{
  char *value;

  if(!t_is_string(name)) _fail(name);

  value = getenv(ATgetName(ATgetSymbol(name)));

  if(value == NULL) _fail(name);

  return (ATerm)ATmakeString(value);
}
Ejemplo n.º 3
0
ATerm SSL_int_to_string(ATerm x)
{ int k;
  double r;
  char buf[32];
  if(ATmatch(x, "<int>", &k)) 
    ;
  else if(ATmatch(x, "<real>", &r))
    k = r;
  else
    _fail(x);

  sprintf(buf, "%d", k);
  return((ATerm) ATmakeString(buf));
}
Ejemplo n.º 4
0
ATerm SSL_write_term_to_string(ATerm term) {
    ATerm result_term;

    /* result points to some internal buffer of the ATerm lib */
    char* result = ATwriteToString(term);

    if(result == NULL) {
        perror("SRTS/write_term_to_string");
        _fail(term);
    }

    result_term = ATmakeString(result);
    return result_term;
}
Ejemplo n.º 5
0
/**
 * Parse a stream.
 *
 * sort is allowed to be None.
 */
ATerm STRSGLR_parse_stream_pt(StrCL onfail, ATerm stream_term, ATerm tbl_term, ATerm start_term, ATerm path_term)
{
    char* text;
    ATerm result;

    FILE* stream = stream_from_term(stream_term);
    if(stream == NULL)
        return NULL;

    text = read_text_from_stream(stream);
    if(text == NULL)
        return NULL;

    result = parse_string_pt(text, tbl_term, start_term, path_term);
    if(result == NULL)
    {
        cl_fun(onfail)(cl_sl(onfail), ATmakeString(text));
    }
    free(text);
    return result;
}
Ejemplo n.º 6
0
ATerm SSL_readdir(ATerm t) 
{
  DIR *dir = NULL;
  ATermList entries = ATempty;
  struct dirent *entry = NULL;

  if(!t_is_string(t))
    _fail(t);

  dir = opendir(ATgetName(ATgetSymbol(t)));

  if(dir == NULL)
    _fail(t);

  while((entry = readdir(dir)) != NULL) 
    {
      entries = ATinsert(entries, ATmakeString(entry->d_name));
    }

  closedir(dir);

  return (ATerm) entries;
}
Ejemplo n.º 7
0
PROCDECL(_stratego_y_22);
PROCDECL(_stratego_z_22);
PROCDECL(_stratego_a_23);
PROCDECL(_stratego_b_23);
PROCDECL(_stratego_c_23);

PROC(_stratego_init_afuns)
  MOVE(k_5,ATmakeAFun("H",2,0));
  MOVE(e_2,ATmakeAFun("Nil",0,0));
  MOVE(q_1,ATmakeAFun("Cons",2,0));
  MOVE(b_1,ATmakeAFun("TNil",0,0));
  MOVE(y_0,ATmakeAFun("TCons",2,0));
ENDPROC

PROC(_stratego_main)
  Tset(ATmakeString("list-set-test"));
  Tdupl();
  Epushd(0,1);
  MoveTop(0,1);
  NotNULLd(0,1);
  Tset(App2("TCons",App0("stderr"),App2("TCons",App2("Cons",ATmakeString("test suite: "),App2("Cons",Egetd(0,1),App0("Nil"))),App0("TNil"))));
  Ccall(_stratego_d_22);
  Epopd(0,1);
  Tpop();
  Ccall(_stratego_e_22);
  Tdupl();
  Tset(ATmakeString("test1"));
  Ccall(_stratego_n_22);
  Tpop();
  Cpush(b_0);
  Tdupl();
Ejemplo n.º 8
0
PROCDECL(_stratego_b_6);
PROCDECL(_stratego_c_6);
PROCDECL(_stratego_d_6);
PROCDECL(_stratego_e_6);
PROCDECL(_stratego_f_6);
PROCDECL(_stratego_g_6);
PROCDECL(_stratego_h_6);
PROCDECL(_stratego_i_6);

PROC(_stratego_init_afuns)
  MOVE(d_0,ATmakeAFun("TNil",0,0));
  MOVE(a_0,ATmakeAFun("TCons",2,0));
ENDPROC

PROC(_stratego_main)
  Tset(ATmakeString("number-test"));
  Tdupl();
  Epushd(0,1);
  MoveTop(0,1);
  NotNULLd(0,1);
  Tset(App2("TCons",App0("stderr"),App2("TCons",App2("Cons",ATmakeString("test suite: "),App2("Cons",Egetd(0,1),App0("Nil"))),App0("TNil"))));
  Ccall(_stratego_s_5);
  Epopd(0,1);
  Tpop();
  Ccall(_stratego_t_5);
  Ccall(_stratego_y_5);
  Ccall(_stratego_e_6);
  Ccall(_stratego_f_6);
  Ccall(_stratego_h_6);
  Ccall(_stratego_i_6);
  Ccall(_stratego_u_5);
Ejemplo n.º 9
0
  MOVE(g_0,ATmakeAFun("F",2,0));
ENDPROC

PROCDECL(_stratego_main);
PROCDECL(_stratego_i_0);
PROCDECL(_stratego_j_0);
PROCDECL(_stratego_k_0);

PROC(_stratego_main)
  Tset(App2("F",App0("B"),App2("G",App0("A"),App0("C"))));
  Ccall(_stratego_i_0);
  Tset(App2("F",App0("B"),App2("G",App0("C"),App0("A"))));
  Ccall(_stratego_i_0);
  Tset(App2("F",App0("D"),App2("G",App0("D"),App0("A"))));
  Ccall(_stratego_i_0);
  Tset(App2("G",MakeInt(1),ATmakeString("a")));
  Ccall(_stratego_i_0);
ENDPROC

PROC(_stratego_i_0)
  Epushd(0,5);
  Ccall(_stratego_j_0);
  MoveTop(0,3);
  goto p_0;
  p_0 :
  TestFunFC(g_0,&&f_0,Egetd(0,3));
  MoveArg(0,4,0,3,0);
  MoveArg(0,5,0,3,1);
  goto q_0;
  q_0 :
  TestFunFC(h_0,&&fail,Egetd(0,5));