Example #1
0
void mexecute(u16 n, const char *name, int count, fncode fn)
/* Effects: Generates code to call function in variable n, with count
     arguments
*/
{
  struct string *mod;
  int status = module_vstatus(fnglobals(fn), n, &mod);

  if (!in_glist(n, definable) &&
      !in_glist(n, readable) && !in_glist(n, writable)) {
    if (status == var_module)
      {
	/* Implicitly import protected modules */
	if (module_status(fnglobals(fn), mod->str) != module_protected &&
	    !all_readable && imported(mod->str) == module_unloaded)
	  log_error("read of global %s (module %s)", name, mod->str);
      }
    else if (!all_readable)
      log_error("read of global %s", name);
  }

  if (count == 1)
    ins2(op_execute_global1, n, fn);
  else if (count == 2)
    ins2(op_execute_global2, n, fn);
  else
    {
      /* Could have an op_execute_global */
      ins2(op_recall + global_var, n, fn);
      ins1(op_execute, count, fn);
    }
}
bool testBase64()
{
    printf("######### Base64 Out ############\n");
    Inkscape::URI plainInUri(xmlpath);
    Inkscape::IO::UriInputStream ins1(plainInUri);

    Inkscape::URI b64OutUri("crystalegg.xml.b64");
    Inkscape::IO::UriOutputStream outs1(b64OutUri);
    Inkscape::IO::Base64OutputStream b64Outs(outs1);

    pipeStream(ins1, b64Outs);

    ins1.close();
    b64Outs.close();

    printf("######### Base64 In ############\n");
    Inkscape::URI b64InUri("crystalegg.xml.b64");
    Inkscape::IO::UriInputStream ins2(b64InUri);
    Inkscape::IO::Base64InputStream b64Ins(ins2);

    Inkscape::URI plainOutUri("crystalegg.xml.b64dec");
    Inkscape::IO::UriOutputStream outs2(plainOutUri);

    pipeStream(b64Ins, outs2);

    outs2.close();
    b64Ins.close();

    return true;
}
Example #3
0
void mrecall(u16 n, const char *name, fncode fn)
/* Effects: Generate code to recall variable n
*/
{
  struct string *mod;
  struct global_state *gstate = fnglobals(fn);
  int status = module_vstatus(gstate, n, &mod);

  if (!in_glist(n, definable) &&
      !in_glist(n, readable) && !in_glist(n, writable)) {
    if (status == var_module)
      {
	/* Implicitly import protected modules */
	if (module_status(gstate, mod->str) == module_protected)
	  {
	    if (immutablep(GVAR(gstate, n))) /* Use value */
	      {
		ins_constant(GVAR(gstate, n), fn);
		return;
	      }
	  }
	else if (!all_readable && imported(mod->str) == module_unloaded)
	  log_error("read of global %s (module %s)", name, mod->str);
      }
    else if (!all_readable)
      log_error("read of global %s", name);
  }

  ins2(op_recall + global_var, n, fn);
}
Example #4
0
int main ()
{
    // not used, must be zero-initialized and supplied to facet
    std::mbstate_t state = std::mbstate_t ();

    // three strings to use as buffers
    std::string ins ("\xfc \xcc \xcd \x61 \xe1 \xd9 \xc6 \xe6 \xf5");
    std::string ins2 (ins.size (), '.');
    std::string outs (ins.size () / ex_codecvt ().encoding (), '.');

    // Print initial contents of buffers
    std::cout << "Before:\n"
              << ins << '\n'
              << ins2 << '\n'
              << outs << '\n' << '\n';

    // Create a user defined codecvt fact
    // This facet converts from ISO Latin Alphabet No. 1 (ISO 8859-1)
    // to  U.S. ASCII code page 437.

    // Replace the default codecvt<char, char, mbstate_t>.
    std::locale loc (std::cout.getloc (), new ex_codecvt);

    // Retrieve the facet from the locale.
    typedef std::codecvt<char, char, std::mbstate_t> CodeCvt;
    const CodeCvt& cdcvt = std::use_facet<CodeCvt>(loc);

    // unused, must be provided to codecvt<>::in/out
    const char *const_out_next = 0;
    const char *const_in_next  = 0;
          char *in_next        = 0;
          char *out_next       = 0;

    // convert the buffer
    cdcvt.in (state, ins.c_str (), ins.c_str () + ins.length (), const_in_next,
              &outs [0], &outs [0] + outs.length (), out_next);

    std::cout << "After in:\n"
              << ins << '\n'
              << ins2 << '\n'
              << outs << "\n\n";

    // zero-initialize (unused) state object
    state = std::mbstate_t ();

    // Finally, convert back to the original codeset
    cdcvt.out (state, outs.c_str (), outs.c_str () + outs.length (),
               const_out_next, &ins [0], &ins [0] + ins.length (), in_next);

    std::cout << "After out:\n"
              << ins << '\n'
              << ins2 << '\n'
              << outs << '\n';

    return 0;
}
Example #5
0
void massign(u16 n, const char *name, fncode fn)
/* Effects: Generate code to assign to variable n
*/
{
  struct string *mod;
  int status = module_vstatus(fnglobals(fn), n, &mod);

  if (status == var_module)
    if (mod == this_module && fntoplevel(fn)) 
      /* defined here */
      ins2(op_define, n, fn);
    else
      log_error("write of global %s (module %s)", name, mod->str);
  else if (all_writable || in_glist(n, writable))
    {
      ins2(op_assign + global_var, n, fn);
      if (status != var_write)
	module_vset(fnglobals(fn), n, var_write, NULL);
    }
  else
    log_error("write of global %s", name);
}
Example #6
0
static void generate_component(component comp, fncode fn)
{
  clist args;

  set_lineno(comp->lineno, fn);

  switch (comp->vclass)
    {
    case c_assign:
      {
	ulong offset;
        bool is_static;
	variable_class vclass = env_lookup(comp->u.assign.symbol, &offset,
                                           false, true, &is_static);
	component val = comp->u.assign.value;

	if (val->vclass == c_closure)
	  {
	    /* Defining a function, give it a name */
	    if (vclass == global_var)
	      val->u.closure->varname = comp->u.assign.symbol;
	    else
	      {
		char *varname = allocate(fnmemory(fn), strlen(comp->u.assign.symbol) + 7);

		sprintf(varname, "local-%s", comp->u.assign.symbol);
		val->u.closure->varname = varname;
	      }
	  }

        if (is_static)
          {
            ins1(op_recall + vclass, offset, fn);
            generate_component(comp->u.assign.value, fn);
            mexecute(g_symbol_set, NULL, 2, fn);
            break;
          }

	generate_component(comp->u.assign.value, fn);

	set_lineno(comp->lineno, fn);

        if (vclass == global_var)
	  massign(offset, comp->u.assign.symbol, fn);
	else
	  ins1(op_assign + vclass, offset, fn);
	/* Note: varname becomes a dangling pointer when fnmemory(fn) is
	   deallocated, but it is never used again so this does not cause
	   a problem. */
	break;
      }
    case c_vref:
    case c_recall:
      {
        bool is_vref = comp->vclass == c_vref;
	ulong offset;
        bool is_static;
	variable_class vclass = env_lookup(comp->u.recall, &offset,
                                           true, is_vref, &is_static);

        if (is_static)
          {
            assert(vclass != global_var);
            ins1(op_recall + vclass, offset, fn);
            ulong gidx = is_vref ? g_make_symbol_ref : g_symbol_get;
            mexecute(gidx, NULL, 1, fn);
            break;
          }
	if (vclass != global_var)
          ins1((is_vref ? op_vref : op_recall) + vclass, offset, fn);
        else if (is_vref)
          {
            if (!mwritable(offset, comp->u.recall))
              return;
            ins_constant(makeint(offset), fn);
          }
        else
          mrecall(offset, comp->u.recall, fn);
        if (is_vref)
          mexecute(g_make_variable_ref, "make_variable_ref", 1, fn);
	break;
      }
    case c_constant:
      ins_constant(make_constant(comp->u.cst), fn);
      break;
    case c_closure:
      {
	uword idx;

	idx = add_constant(generate_function(comp->u.closure, false, fn), fn);
	if (idx < ARG1_MAX) ins1(op_closure_code1, idx, fn);
	else ins2(op_closure_code2, idx, fn);
	break;
      }
    case c_block:
      generate_block(comp->u.blk, fn);
      break;
    case c_labeled:
      start_block(comp->u.labeled.name, fn);
      generate_component(comp->u.labeled.expression, fn);
      end_block(fn);
      break;
    case c_exit:
      generate_component(comp->u.labeled.expression, fn);
      if (!exit_block(comp->u.labeled.name, fn)) {
	if (!comp->u.labeled.name)
	  log_error("no loop to exit from");
	else
	  log_error("no block labeled %s", comp->u.labeled.name);
      }
      break;
    case c_execute:
      {
	uword count;

	generate_args(comp->u.execute->next, fn, &count);
	set_lineno(comp->lineno, fn);
	generate_execute(comp->u.execute->c, count, fn);
	break;
      }
    case c_builtin:
      args = comp->u.builtin.args;

      switch (comp->u.builtin.fn)
	{
	case b_if: {
          block cb = new_codeblock(fnmemory(fn), NULL,
                                   new_clist(fnmemory(fn), args->next->c,
                                             new_clist(fnmemory(fn),
                                                       component_undefined,
                                                       NULL)),
                                   NULL, NULL, -1);
	  generate_if(args->c, new_component(fnmemory(fn),
                                             args->next->c->lineno,
                                             c_block, cb),
		      component_undefined, fn);
	  break;
        }
	case b_ifelse:
	  generate_if(args->c, args->next->c, args->next->next->c, fn);
	  break;
	case b_sc_and: case b_sc_or:
	  generate_if(comp, component_true, component_false, fn);
	  break;

	case b_while:
	  generate_while(args->c, args->next->c, fn);
	  break;

	case b_loop:
	  {
	    label loop = new_label(fn);

            env_start_loop();
	    set_label(loop, fn);
	    start_block(NULL, fn);
	    generate_component(args->c, fn);
	    branch(op_loop1, loop, fn);
	    end_block(fn);
            env_end_loop();
	    adjust_depth(1, fn);
	    break;
	  }

	case b_add: case b_subtract:
	case b_ref: case b_set:
	case b_bitor: case b_bitand:
	case b_not:
	case b_eq: case b_ne:
	case b_lt: case b_le: case b_ge: case b_gt:
	  {
	    uword count;

	    assert(comp->u.builtin.fn < last_builtin);
	    generate_args(args, fn, &count);
	    set_lineno(comp->lineno, fn);
	    ins0(builtin_ops[comp->u.builtin.fn], fn);
	    break;
	  }
	default:
	  {
	    uword count;

	    assert(comp->u.builtin.fn < last_builtin);
	    generate_args(args, fn, &count);
	    set_lineno(comp->lineno, fn);
	    mexecute(builtin_functions[comp->u.builtin.fn], NULL, count, fn);
	    break;
	  }
	}
      break;
    default: abort();
    }
}
void XMLScannerTest::run()
{
		//create a dummy map with a fakie f*****g modulewhateverinfo....
	std::vector<std::pair<std::string, std::string> > outs(1);
	std::vector<std::pair<std::string, std::string> > ins(0);
	std::pair<std::string, std::string> outpair("typ_string", "String");
	outs[0] = outpair;
	
	//Xpm dummy(dummyXpm, strlen(dummyXpm)+1);
	ModuleInfo* mi = new ModuleInfo("mod_stringModule", "String", 
								    ins, outs, true);

	
	std::vector<std::pair<std::string, std::string> > outs2(0);
	std::vector<std::pair<std::string, std::string> > ins2(1);
	std::pair<std::string, std::string> inpair("typ_framebuffer", "Bild");
	ins2[0] = inpair; 
	ModuleInfo* mi2 = new ModuleInfo("mod_glOutputModule", "GLoutput" , 
								    ins, outs, false);

	std::vector<std::pair<std::string, std::string> > outs3(1);
	std::vector<std::pair<std::string, std::string> > ins3(3);
	
	std::pair<std::string, std::string> inpair2("typ_number","Zahl");
	
	ins3[0] = inpair2; 
	ins3[1] = inpair2;
	ins3[2] = inpair;

	outs3[0] = inpair;

	ModuleInfo* mi3 = new ModuleInfo("mod_tunnelModule", "Tunnel" , 
								    ins, outs, false);

	
	std::map<int, ModuleInfo*> mi_map;
	mi_map[0] = mi;
	mi_map[1] = mi2;	
	mi_map[2] = mi3;

	//create storage room for the listener
	std::map<std::string, int> infos;
	std::map<std::string, std::pair<int,int> > nodes;
	std::map<int, std::string>  nodeIDs;
	std::map<std::string, std::pair<int,int> > controls;
	std::map<int, std::string> controlIDs;
	std::map<std::pair<int,int>, std::pair<int,int> > conns;
	std::map<std::pair<int,int>, std::pair<int,int> > ctrlconns;

	//create an xmlListener with that dummyinfo
	XMLTokenListener horcher(mi_map, infos, nodes, nodeIDs, controls, controlIDs, conns, ctrlconns);
	XMLFileScanner gucker(horcher);
	std::ifstream ifs("testCorrect.graph");
	if(ifs==0)
		std::cout<<"File not found \n";
	std::string testTextCorrect;	

	char tmp;
	while(ifs.get(tmp))
	{
		testTextCorrect += tmp;
	}

	gucker.scan(testTextCorrect);


	//eine datei ohne <model>
	//std::cout<<"Processing incorrect file 1...\n";
	std::ifstream ifs1("testInCorrect1.graph");
	if(ifs1==0)
		std::cout<<"File not found \n";
	std::string testTextInCorrect1;	
	while(ifs.get(tmp))
	{
		testTextInCorrect1 += tmp;
	}

	try
	{
		gucker.scan(testTextInCorrect1);
	}
	catch(std::runtime_error err)
	{
		//if(err.what() !=  "This is no Ge-Phex Graph file...go f**k your dog!!!")
		//	throw std::runtime_error(err.what());
		//std::cout<<err.what()<<std::endl;
		
	}


	//eine datei ohne </model>, ja, ich weiss, kreativ...
	//std::cout<<"Processing incorrect file 2...\n";
	std::ifstream ifs2("testInCorrect2.graph");
	if(ifs2==0)
		std::cout<<"File not found \n";
	std::string testTextInCorrect2;	
	while(ifs2.get(tmp))
	{
		testTextInCorrect2 += tmp;
	}

	try
	{
		gucker.scan(testTextInCorrect2);
	}
	catch(std::runtime_error err)
	{
		//if(err.what() !=  "File has a wrong finishing tag...wrong format")
		//	throw std::runtime_error(err.what());
		
		//std::cout<<err.what()<<std::endl;
	}

	//eine datei mit fehlender node section
	//std::cout<<"Processing incorrect file 3...\n";
	std::ifstream ifs3("testInCorrect3.graph");
	if(ifs3==0)
		std::cout<<"File not found \n";
	std::string testTextInCorrect3;	


	while(ifs3.get(tmp))
	{
		testTextInCorrect3 += tmp;
	}
	
	try
	{
		gucker.scan(testTextInCorrect3);	
	}
	catch(std::runtime_error err)
	{
		//if(err.what() !=  "File has wrong format...section nodes")
		//	throw std::runtime_error(err.what());
		
		//std::cout<<err.what()<<std::endl;
	}		
}