示例#1
0
	Value eval_in_global_module(StringConstPtr _source) {
		std::string source;
		string_to_std_string(_source, source);
		if (!source.size()) return NULL;
		Value mod = get_global_module();
		Module* module = compile_module("<eval>", source, mod);
		if (module) {
			return object_get_instance_variable(mod, snow::sym("__module_value__"));
		} else {
			return NULL;
		}
	}
示例#2
0
	Value load_in_global_module(StringConstPtr _file) {
		std::string file;
		string_to_std_string(_file, file);
		std::string path;
		if (expand_load_path(file, path)) {
			ASSERT(get_module_type(path) == ModuleTypeSource); // only source modules are supported in load_in_global_module
			Value mod = get_global_module();
			if (compile_module(path, load_source(file), mod)) {
				return object_get_instance_variable(mod, snow::sym("__module_value__"));
			} else {
				fprintf(stderr, "ERROR: Could not compile module: %s\n", path.c_str());
				return NULL;
			}
		} else {
			throw_exception_with_description("File not found in any load path: %@", file.c_str());
			return NULL;
		}
	}
示例#3
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;} 
    } 
示例#4
0
int main(int argc, char * argv[]) {

  FILE * o;
  int i;
  char * o_name;
  char ** module_src;
  char ** module_obj;
  char * temp_1;
  char * temp_2;
  const unsigned int buffer_size = (1024 * 50); // Yes, I think that's enough...
  int num_module = 0;

  if (argc < 5) {
    for (i = 1; i < argc; i++) {
      fprintf(stderr, "arg %d = '%s'\n", i, argv[i]);
    }
    fprintf(stderr, "create_modules CPU HOST CC outfile.c module1.c [module2.c ...]\n");
    exit(1);
  }

  fprintf(stdout, "Creating module data with CPU = '%s' HOST = '%s' CC = '%s'\n", argv[1], argv[2], argv[3]);

  num_module = argc - 5;
  module_src = malloc(sizeof(char *) * num_module);
  module_obj = malloc(sizeof(char *) * num_module);

  temp_1 = malloc(buffer_size);
  temp_2 = malloc(buffer_size);
  for (i = 5; i < argc; i++) {
    module_src[i - 5] = argv[i];
    memset(temp_1, 0x00, buffer_size);
    sprintf(temp_1, "/tmp/module_XXXXXX");
    mkstemp(temp_1);
    sprintf(temp_1 + strlen(temp_1), ".o");
    module_obj[i - 5] = malloc(sizeof(char) * (strlen(temp_1) + 1));
    strcpy(module_obj[i - 5], temp_1);
  }

  for (i = 0; i < num_module; i++) {
    printf("Creating object code for '%s'.\n", module_src[i]);
  }

  /*
  ** Get working path and create the necessary include headers. Use the first
  ** given module source file as a reference.
  */

  memset(temp_1, 0x00, buffer_size);
  memcpy(temp_1, module_src[0], (unsigned int)(strrchr(module_src[0], '/') - module_src[0]));
  memset(temp_2, 0x00, buffer_size);
  memcpy(temp_2, temp_1, (unsigned int)(strrchr(temp_1, '/') - temp_1));
  memset(temp_1, 0x00, buffer_size);
  sprintf(temp_1, "-I%s/include -I%s/hal/cpu/%s/include -I%s/hal/host/%s/include", temp_2, temp_2, argv[1], temp_2, argv[2]);

  /*
  ** Compile all the module files.
  */

  for (i = 0; i < num_module; i++) {
    compile_module(argv[3], temp_1, module_src[i], module_obj[i]);
  }

  /*
  ** Generate the source header.
  */

  o_name = argv[4];
  o = fopen(o_name, "w");

  fprintf(o, "/*\n");
  fprintf(o, "** Object code of modules\n");
  for (i = 0; i < num_module; i++) {
    fprintf(o, "**   %s\n", module_src[i]);
  }
  fprintf(o, "*/\n\n");

  fprintf(o, "typedef struct Module {\n");
  fprintf(o, "  struct Module * next;\n");
  fprintf(o, "  const char * name;\n");
  fprintf(o, "  int size;\n");
  fprintf(o, "  unsigned char data[0];\n");
  fprintf(o, "} Module;\n");
  fprintf(o, "\n");

  for (i = num_module - 1; i >= 0; i--) {
    write_module(o, module_src[i], module_obj[i], i, i == (num_module - 1));
  }

  fprintf(o, "struct Module * first_Module = & Module_0;\n");

  fclose(o);
  
  free(temp_1);
  free(temp_2);
  for (i = 0; i < num_module; i++) {
    remove(module_obj[i]);
    free(module_obj[i]);
  }

  return 0;
  
}