Example #1
0
// this is our main function (a simpler version of what is in main.cpp)
int main(int argc, char *argv[])
{int k = 1, i = 3, j = 3;
  printf("==== call main argc = %d, argv[1] = %s ==== \n",argc,argv[1]);
  if ((argc > 3) && (equal_string("-s",argv[1]) == CTRUE))
    { i = atoi(argv[2]); j = atoi(argv[3]);  k = 4;
      if ((i < 0) || (i > 10) || (j < 0) || (j > 10)) exit(1);
      printf("increasing memory size by 2^%d and 2^%d \n",i,j);}
 {int t1,t2;
  ClAlloc = new ClaireAllocation;
  ClAlloc->logList = 18 + i;
  ClAlloc->maxList = (1 << (18 + i));
  ClAlloc->maxSize = (2 << (18 + i));
  ClAlloc->maxGC = 20000 * (1 << j);
  ClAlloc->maxStack = 8000 * (1 << j);                   // <yc> 9/98 changed because of GC
  ClAlloc->maxHist = 10000 * (1 << j);
  ClAlloc->maxEnv = 400 * (1 << j);
  ClAlloc->maxHash = ((1 << (11 + i)) + 200);            // <yc> 7/98 Changed for claire3 !
  ClAlloc->hashMask = ((1 << (11 + i)) - 1);
  ClAlloc->stdOut = ClairePort::make(stdout);
  ClAlloc->stdIn = ClairePort::make(stdin);
  ClAlloc->stdErr = ClairePort::make(stdout);
  ClaireResource::run();
  ClEnv->params = C_to_Claire(argc,argv);
  call_main();
  CL_exit(2);
  return 1;}}
Example #2
0
// lookup: check if a string in a given module is represented by a symbol (returns NULL
// if no symbol is found - does NOT create a new symbol
// this method embodies the strategy for looking in upper modules (namespace inheritance)
symbol *module::lookup(char *name)
{int i = hash(name);
   while ((ClRes->sTable[i] != NULL) &&
          ((this != ClRes->sTable[i]->module_I) ||
           (equal_string(name,ClRes->sTable[i]->name) == CFALSE))) i++;
   if (i == ClAlloc->maxHash) Cerror(12,0,0);
   symbol *cur = ClRes->sTable[i];
   if (cur != NULL || this == claire.it) return cur;   // v3.2.38 - Thanks to FXJ !
   else return part_of->lookup(name); }
Example #3
0
// create a claire symbol from an internal C string and a status, represented by
// def, which is NULL for private symbols and the definition (owner) for other symbols
// 
symbol *symbol::make(char *name, module *ns, module *def)
{int i = ns->hash(name);
   while ((ClRes->sTable[i] != NULL) &&
          ((ns != ClRes->sTable[i]->module_I) ||
           (equal_string(name,ClRes->sTable[i]->name) == CFALSE))) i++;
   if (i >= ClAlloc->maxHash) Cerror(12,0,0);
   if (ClRes->sTable[i] == NULL)
      {symbol *s = (symbol *) ClAlloc->makeAny(4);
       s->isa = Kernel._symbol;
       s->name = name;
       s->module_I = ns;
       s->definition = def;                  // def = NULL means private
       s->value = CNULL;
       ClRes->sTable[i] = s;}
   return ClRes->sTable[i];}
Example #4
0
/* The c++ function for: main(lp:list[string]) [NEW_ALLOC+BAG_UPDATE+SLOT_UPDATE+STRING_UPDATE] */
void  main_list(list *lp)
{ GC_BIND;
  { ClaireBoolean * rCode = CTRUE;
    char * _Zcm = copy_string("");
    char * _Zcf = copy_string("");
    int  dblevel = 1;
    char * _Zout = copy_string("");
    char * _Zcj = copy_string("");
    int  slevel = 0;
    int  clevel = 1;
    ClaireBoolean * _Zinit_ask = CTRUE;
    int  vlevel = 2;
    list * l = ((list *) copy_bag(lp));
    { ClaireHandler c_handle = ClaireHandler();
      if ERROR_IN 
      { { (Reader._starfs_star->value= _string_(copy_string("\\")));
          (OBJECT(Generate_producer,Generate.PRODUCER->value)->extension = copy_string(".cpp"));
          update_property(Optimize.libraries_dir,
            Optimize.compiler,
            17,
            Kernel._object,
            _oid_(list::alloc(Kernel._any,3,_string_(copy_string("c:\\claire\\v3.3\\bin\\public\\ntv")),
              _string_(copy_string("c:\\claire\\v3.3\\bin\\debug\\ntv")),
              _string_(copy_string("c:\\claire\\v3.3\\bin\\public\\ntv")))));
          (Optimize.compiler->headers_dir = copy_string("c:\\claire\\v3.3\\bin\\include"));
          update_property(Optimize.options,
            Optimize.compiler,
            19,
            Kernel._object,
            _oid_(list::alloc(Kernel._any,3,_string_(copy_string("-c /O2 /Oi")),
              _string_(copy_string("-c /Zi")),
              _string_(copy_string("-c /Zi")))));
          (Optimize.compiler->env = copy_string("ntv"));
          (Optimize.claire_lib->value= _string_(copy_string("")));
          { while ((l->length != 0))
            { if ((equal((*(l))[1],_string_(copy_string("?"))) == CTRUE) || 
                  (equal((*(l))[1],_string_(copy_string("-help"))) == CTRUE))
               printHelp_void();
              else if (equal((*(l))[1],_string_(copy_string("-s"))) == CTRUE)
               { if (3 <= l->length)
                 l= skip_list(l,3);
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -s <s1> <s2>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-f"))) == CTRUE)
               { if (2 <= l->length)
                 { load_string(string_v((*(l))[2]));
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -f <filename>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-env"))) == CTRUE)
               { if (2 <= l->length)
                 { (Optimize.compiler->env = string_v((*(l))[2]));
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -env <OS name>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-m"))) == CTRUE)
               { if (2 <= l->length)
                 { if (_Zinit_ask == CTRUE)
                   { load_string(copy_string("init"));
                    _Zinit_ask= CFALSE;
                    } 
                  { module * m = string2module_string(string_v((*(l))[2]));
                    load_module(m);
                    begin_module(m);
                    l= skip_list(l,2);
                    (Optimize.claire_modules->value= _oid_(OBJECT(list,Optimize.claire_modules->value)->addFast(_oid_(m))));
                    } 
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -m <module>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-v"))) == CTRUE)
               { if (2 <= l->length)
                 { vlevel= (vlevel+integer_I_string(string_v((*(l))[2])));
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -v <integer>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-ld"))) == CTRUE)
               { if (2 <= l->length)
                 { (Optimize.claire_lib->value= (*(l))[2]);
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -od <directory>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-od"))) == CTRUE)
               { if (2 <= l->length)
                 { (Optimize.compiler->source = string_v((*(l))[2]));
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -od <directory>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-os"))) == CTRUE)
               { if (2 <= l->length)
                 { slevel= integer_I_string(string_v((*(l))[2]));
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -ol <int>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-S"))) == CTRUE)
               { if (2 <= l->length)
                 { (CLREAD(global_variable,new_class2(Core._global_variable,symbol_I_string2(string_v((*(l))[2]))),value) = Kernel.ctrue);
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -S <FLAG>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-o"))) == CTRUE)
               { if (2 <= l->length)
                 { _Zout= string_v((*(l))[2]);
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -o <name>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-p"))) == CTRUE)
               { (Optimize.OPT->profile_ask = CTRUE);
                dblevel= ((dblevel <= 1) ?
                  1 :
                  dblevel );
                l= skip_list(l,1);
                } 
              else if (equal((*(l))[1],_string_(copy_string("-D"))) == CTRUE)
               { dblevel= 0;
                l= skip_list(l,1);
                } 
              else if (equal((*(l))[1],_string_(copy_string("-safe"))) == CTRUE)
               { (Optimize.compiler->safety = ((dblevel == 0) ?
                  0 :
                  1 ));
                (Optimize.claire_lib->value= (*(Optimize.compiler->libraries_dir))[2]);
                (Optimize.claire_options->value= (*(Optimize.compiler->options))[2]);
                l= skip_list(l,1);
                } 
              else if (equal((*(l))[1],_string_(copy_string("-O"))) == CTRUE)
               { (Optimize.compiler->optimize_ask = CTRUE);
                dblevel= 2;
                l= skip_list(l,1);
                } 
              else if (equal((*(l))[1],_string_(copy_string("-l"))) == CTRUE)
               { if (2 <= l->length)
                 { Optimize.compiler->libraries->addFast((*(l))[2]);
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -l <library>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-cl"))) == CTRUE)
               { if (2 <= l->length)
                 { _Zcm= string_v((*(l))[2]);
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -cm <module>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-cc"))) == CTRUE)
               { if (2 <= l->length)
                 { clevel= 0;
                  _Zcm= string_v((*(l))[2]);
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -cc <module>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-cm"))) == CTRUE)
               { if (2 <= l->length)
                 { clevel= 2;
                  _Zcm= string_v((*(l))[2]);
                  l= skip_list(l,2);
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -cl <module>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-cj"))) == CTRUE)
               { if (2 <= l->length)
                 { _Zcj= string_v((*(l))[2]);
                  l= skip_list(l,2);
                  } 
                } 
              else if (equal((*(l))[1],_string_(copy_string("-cjx"))) == CTRUE)
               { if (2 <= l->length)
                 { _Zcj= string_v((*(l))[2]);
                  clevel= 0;
                  l= skip_list(l,2);
                  } 
                } 
              else if (equal((*(l))[1],_string_(copy_string("-cx"))) == CTRUE)
               { if (2 <= l->length)
                 { _Zcf= string_v((*(l))[2]);
                  l= skip_list(l,2);
                  clevel= 2;
                  } 
                else close_exception(((general_error *) (*Core._general_error)(_string_(copy_string("option: -cx <filename>")),
                    _oid_(Kernel.nil))));
                  } 
              else if (equal((*(l))[1],_string_(copy_string("-n"))) == CTRUE)
               { _Zinit_ask= CFALSE;
                l= skip_list(l,1);
                } 
              else { if (string_v((*(l))[1])[1 - 1] == '-')
                   { print_any((*(l))[1]);
                    princ_string(copy_string(" is an unvalid option\n"));
                    printHelp_void();
                    } 
                  rCode= CFALSE;
                  l= list::empty(Kernel._string);
                  } 
                } 
            } 
          if (equal_string(_Zout,copy_string("")) == CTRUE)
           { if (equal_string(_Zcm,copy_string("")) != CTRUE)
             _Zout= _Zcm;
            else if (equal_string(_Zcf,copy_string("")) != CTRUE)
             _Zout= _Zcf;
            } 
          if (_Zinit_ask == CTRUE)
           load_string(copy_string("init"));
          (Optimize.claire_options->value= (*(Optimize.compiler->options))[((dblevel == 0) ?
            2 :
            ((dblevel == 2) ?
              1 :
              3 ) )]);
          if (equal(Optimize.claire_lib->value,_string_(copy_string(""))) == CTRUE)
           (Optimize.claire_lib->value= (*(Optimize.compiler->libraries_dir))[((dblevel == 0) ?
            2 :
            ((dblevel == 2) ?
              1 :
              3 ) )]);
          (ClEnv->verbose = vlevel);
          if (slevel > 0)
           (Optimize.compiler->safety = slevel);
          if (equal_string(_Zcm,copy_string("")) != CTRUE)
           { module * m = string2module_string(_Zcm);
            (Optimize.compiler->active_ask = CTRUE);
            if (equal(_oid_(m->uses),_oid_(list::alloc(1,GC_OID((*(OBJECT(bag,Optimize.claire_modules->value)))[2])))) == CTRUE)
             { (Optimize.claire_modules->value= _oid_(shrink_list(OBJECT(bag,Optimize.claire_modules->value),2)));
              tformat_string(copy_string("=== Light Module ~S:~S -> use ~S=== "),0,list::alloc(3,_oid_(m),
                GC_OID(_oid_(m->uses)),
                GC_OID(Optimize.claire_modules->value)));
              } 
            (Optimize.claire_modules->value= _oid_(OBJECT(list,Optimize.claire_modules->value)->addFast(_oid_(m))));
            (*Reader.load)(value_string(copy_string("Compile")));
            if (equal_string(_Zout,copy_string("")) != CTRUE)
             (m->external = _Zout);
            load_module(m);
            if (dblevel < 1)
             { (Optimize.compiler->safety = ((Optimize.compiler->safety <= 4) ?
                Optimize.compiler->safety :
                4 ));
              Optimize.compiler->debug_ask->addFast(_oid_(m));
              } 
            compile_module(m);
            if (clevel == 1)
             { if (equal_string(_Zout,copy_string("")) != CTRUE)
               (m->external = _Zout);
              cmakefile_any(_oid_(m),copy_string(""));
              } 
            else if (clevel == 2)
             cmakefile_any(_oid_(m),_Zout);
            CL_exit(0);
            } 
          else if (equal_string(_Zcj,copy_string("")) != CTRUE)
           (*Core.call)(value_string(copy_string("jcmakefile")),
            _oid_(string2module_string(_Zcj)),
            _string_(_Zout),
            _oid_(equal(clevel,0)));
          else if (equal_string(_Zcf,copy_string("")) != CTRUE)
           { (Optimize.compiler->active_ask = CTRUE);
            (*Reader.load)(value_string(copy_string("Compile")));
            load_string(_Zcf);
            function_compile_string(_Zcf,_Zcf);
            cmakefile_any(_string_(_Zcf),_Zout);
            CL_exit(0);
            } 
          } 
        ClEnv->cHandle--;} 
      else if (belong_to(_oid_(ClEnv->exception_I),_oid_(Kernel._any)) == CTRUE)
      { c_handle.catchIt();{ restore_state_meta_reader(Reader.reader);
          debug_if_possible_void();
          } 
        } 
      else PREVIOUS_HANDLER;} 
    } 
Example #5
0
  }
  INFO("value was \"" << value.c_str() << "\"");
  return false;
}


TEST_CASE("test the operations of generated code","[MDRefreshSample_test]")
{
  debug_allocator alloc;
  test1::SampleInfo info(&alloc);
  REQUIRE((int)test1::SampleInfo::the_id ==                              1);
  REQUIRE(test1::SampleInfo::instruction()->id() ==                     1U);
  REQUIRE(test1::SampleInfo::instruction()->subinstructions().size() ==  4U);
  test1::SampleInfo_cref info_cref = info.cref();

  REQUIRE(equal_string(info_cref.get_BeginString(), "FIX4.4"));
  REQUIRE(info_cref.get_BeginString().instruction()->field_type() ==      mfast::field_type_ascii_string);
  REQUIRE(info_cref.get_BeginString().instruction()->id() ==                  8U);
  REQUIRE(info_cref.get_BeginString().instruction()->field_operator() ==  mfast::operator_constant);

  REQUIRE(equal_string(info_cref.get_MessageType(), "X"));
  REQUIRE(info_cref.get_MessageType().instruction()->field_type() ==           mfast::field_type_ascii_string);
  REQUIRE(info_cref.get_MessageType().instruction()->id() ==                      35U);
  REQUIRE(info_cref.get_MessageType().instruction()->field_operator() ==       mfast::operator_constant);

  REQUIRE(info_cref.get_SenderCompID().instruction()->field_type() ==          mfast::field_type_ascii_string);
  REQUIRE(info_cref.get_SenderCompID().instruction()->id() ==                     49U);
  REQUIRE(info_cref.get_SenderCompID().instruction()->field_operator() ==      mfast::operator_copy);

  REQUIRE(info_cref.get_MsgSeqNum().instruction()->field_type() ==             mfast::field_type_uint32);
  REQUIRE(info_cref.get_MsgSeqNum().instruction()->id() ==                        34U);