コード例 #1
0
ファイル: Compressor.cpp プロジェクト: jpotoniec/MagicStore
void Codes::MakeCode(const Node *root, uint32_t prefix, uint8_t len)
{
    assert(len<=30);
	if(root!=NULL)
	{
		if(!root->getLabel().empty())
            valToCode.insert(Map::value_type(trie.insert(root->getLabel()), prefix));
        uint32_t lcode(prefix);
        uint32_t rcode(prefix|(1<<len));
        MakeCode(root->getLeft(),lcode,len+1);
        MakeCode(root->getRight(),rcode,len+1);
	}
}
コード例 #2
0
ファイル: Compressor.cpp プロジェクト: jpotoniec/MagicStore
void Codes::load(std::ifstream& f)
{
    root=Node::load(f);
    MakeCode(root, 0);
    delete root;
    root=NULL;
    trie.compress();
}
コード例 #3
0
ファイル: quricol.cpp プロジェクト: stievie/Martis
void WINAPI GeneratePNGW(LPWSTR fileName, LPWSTR text, int margin, int size)
{
	if (text == NULL)
		return;

	QRcode* qrcode = MakeCode(text);
	if (qrcode == NULL)
		return;

	writePNG(qrcode, fileName, margin, size);

	QRcode_free(qrcode);
}
コード例 #4
0
void Menu()
{
     char level[SIZE];
     char levelBeg[]="beginner";
     char levelAdv[]="advance";
     char ch;      
     int i = 0,j = 0;
     int checkBeg = 0, checkAdv = 0;
     int levelSign = 0;
     
     printf("\nDo you want to play beginner or advance level (beginner/advance)? :");
     
     while ((ch = getchar()) !=  '\n')
     {
         level[i] = ch;
         i++;
     }
     level[i] = '\0';
     
     for (i = 0; i < SIZE; i++)
     { 
          if ( level[i] != levelBeg[i] )
              checkBeg = 1;
              

          if ( level[i] != levelAdv[i] )
              checkAdv = 1;
              
     }
     
     if (checkBeg == 0)
          levelSign = 3;
     if (checkAdv == 0)
          levelSign = 5;
     
     if (levelSign == 0)
     {
          printf("\a\nWARNING: You should enter \'beginner\' or \'advance\'\n");
          Menu();
     }    
     else
     {
          ClearColor();                      // Clearing all color
          PutButtons(levelSign);             // putting buttons according to the level
          MakeCode(levelSign);
     }
         
}
コード例 #5
0
ファイル: quricol.cpp プロジェクト: stievie/Martis
void WINAPI GetPNGW(LPWSTR text, int margin, int size, LPINT bufSize, __deref_opt_out void **ppvBits)
{
	if (text == NULL)
		return;

	QRcode* qrcode = MakeCode(text);
	if (qrcode == NULL)
		return;

	/* static */
	struct mem_encode state;

	/* initialise - put this before png_write_png() call */
	state.buffer = NULL;
	state.size = 0;

	generatePNG(qrcode, &state, margin, size);
	* bufSize = state.size;
	*ppvBits = (VOID *)state.buffer;

	QRcode_free(qrcode);
}
コード例 #6
0
ファイル: Compressor.cpp プロジェクト: jpotoniec/MagicStore
void Codes::compress()
{
	std::priority_queue<Node*,std::deque<Node*>,NodesOrder> nodes;
    for(auto i:input)
        nodes.push(i);
    input.clear();
	for(;;)
	{
        assert(!nodes.empty());
		Node *l=nodes.top();
		nodes.pop();        
		if(nodes.empty())
		{
			root=l;
			break;
		}        
		Node *r=nodes.top();
		nodes.pop();        
		nodes.push(new Node("",l->getOccurences()+r->getOccurences(),l,r));
    }
    MakeCode(root, 0);
}
コード例 #7
0
ファイル: x64Encoder.c プロジェクト: 453483289/cerberus
__INLINE__ __integer __INTERNAL_FUNC__ SetComplexCode(PASM_OBJ pAsmObj, __memory *pInstBufPoint, __memory pOpcodes, __integer iOpcodesCount, __byte bOpEx) {
	__integer iIndex = 0, iModRMSIB = 0;
	if (pAsmObj->bUseREX) {
		*(pInstBuf + iIndex) = GetREX(pAsmObj);
		iIndex++;
	}
	memcpy(pInstBuf + iIndex, pOpcodes, iOpcodesCount);
	iIndex += iOpcodesCount;
	iModeRMSIB = MakeCode(pAsmObj, bOpEx);
	if (iModeRMSIB == 1)
		*(pInstBuf + iIndex) = GetModRM(pAsmObj);
	else {
		*(pInstBuf + iIndex) = GetModRM(pAsmObj);
		*(pInstBuf + iIndex + 1) = GetSIB(pAsmObj);
	}
	iIndex += iModRMSIB;

	/*
	 * 设置偏移, 如果存在的话
	 */ 
	if (pAsmObj->bHasDisplacement) {
		__byte bIndex = pAsmObj->bDisplacementOwn;
		PASMER_OPERAND pCurrOpt = &(pAsmObj->Operand[bIndex]);
		if (pAsmObj->Operand[bIndex].OffsetBit == ASMER_8_BITS) {
			*(__byte *)(pInstBuf + iIndex) = pCurrOpt->Val.uByte;
			iIndex++;
		} else if (pAsmObj->Operand[bIndex].OffsetBit == ASMER_16_BITS) {
			*(__word *)(pInstBuf + iIndex) = pCurrOpt->Val.uWord;
			iIndex += 2;			
		} else if (pAsmObj->Operand[bIndex].offsetBit == ASMER_32_BITS) {
			*(__dword *)(pInstBuf + iIndex) = pCurrOpt->Val.uDword;
			iIndex += 4;
		}
	}
	
	(*pInstBufPoint) += iIndex;
	return iIndex;
}
コード例 #8
0
ファイル: restart.c プロジェクト: idunham/dtextra
void Restart ()
{
    Pixel
        fg,
        bg;

    register int
        i;

    XmString
        xmstr;

    Gcol1=0;
    Gcol2=0;
    Gcol3=0;
    Gcol4=0;
    GcurrentCol = 0;
    GcurrentRow = 0;
    G_rc_rip=0;
    G_rc_wrp=0;

    XtVaGetValues (GtoplevelW,
        XmNbackground, &bg,
        XmNforeground, &fg,
        NULL);

    for (i=0; i < Rows*Cols; i++)
    {
        XtVaSetValues (w_special[i],
            XmNbackground, bg,
            NULL);
    }

    xmstr = XmStringCreateSimple("??");

    for (i=0; i < Cols; i++)
    {
        XtVaSetValues (GhiddenCodeW[i],
            XmNbackground, bg,
            XmNforeground, BlackPixelOfScreen (XtScreen(GtoplevelW)),
            NULL);

        XtVaSetValues (GhiddenCodeW[i],
            XmNlabelString, xmstr,
            NULL);        
    }
    XmStringFree (xmstr);

    xmstr = XmStringCreateSimple("");
    for (i=0; i < Rows*2; i++)
        XtVaSetValues (GscoreLabW[i],
            XmNlabelString, xmstr,
            NULL);
    XmStringFree (xmstr);

    /*
    ** generate new code
    */

    MakeCode ();
}
コード例 #9
0
ファイル: quricol.cpp プロジェクト: stievie/Martis
HBITMAP WINAPI GetHBitmapW(LPWSTR text, int margin, int size)
{
	HBITMAP hbm = NULL;
    BITMAPINFO      bi;
    BYTE * pixelData;
	BYTE * p;
	BYTE * data;
	BYTE * row;
	BYTE * current;
	int width;
	int x, y, k;
	BOOL black;

	if (text == NULL)
		return NULL;

	QRcode* qrcode = MakeCode(text);
	if (qrcode == NULL)
		return NULL;

	width = (qrcode->width + margin * 2) * size;
	ZeroMemory(&bi.bmiHeader, sizeof(BITMAPINFOHEADER));
	bi.bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);
	bi.bmiHeader.biWidth      = width;
	bi.bmiHeader.biHeight      = -width;

	bi.bmiHeader.biPlanes      = 1;
	bi.bmiHeader.biBitCount    = 32;
	bi.bmiHeader.biCompression = BI_RGB;
    
	int memWidth = WIDTHBYTES(width * bi.bmiHeader.biBitCount);
	row = (BYTE*)malloc(memWidth);
	data = qrcode->data;
	hbm = CreateDIBSection(NULL, &bi, DIB_RGB_COLORS, (VOID **)&pixelData,  NULL, 0);
	if (hbm && pixelData)
	{
		memset(pixelData, 0xff, memWidth * width);
		p = pixelData + memWidth * margin * size;
		for (y = 0; y < qrcode->width; y++) 
		{
			memset(row, 0xff, memWidth);
			current = row + margin * size * 4;
			for(x=0; x < qrcode->width; x++) 
			{
				black = ( (*data & 1) == 1);
				for (int y = 0; y < size; y++)
				{
					if (black)
					{
						for (int i = 0; i < 3; i++)
						{
							*current = 0;
							current++;
						}
					}
					else
						current += 3;
					current++; 
				}
				data++;
			}
			for (k = 0; k < size; k++)
			{
				memcpy(p, row, memWidth);
				p += memWidth;
			}

		}

	}

	free(row);

	QRcode_free(qrcode);

	return hbm;
}
コード例 #10
0
ファイル: compiler.cpp プロジェクト: BlitzMaxModules/axe.mod
bool Compiler::CompileLazy(Handle<SharedFunctionInfo> shared,
                           int loop_nesting) {
  CompilationZoneScope zone_scope(DELETE_ON_EXIT);

  // The VM is in the COMPILER state until exiting this function.
  VMState state(COMPILER);

  // Make sure we have an initial stack limit.
  StackGuard guard;
  PostponeInterruptsScope postpone;

  // Compute name, source code and script data.
  Handle<String> name(String::cast(shared->name()));
  Handle<Script> script(Script::cast(shared->script()));

  int start_position = shared->start_position();
  int end_position = shared->end_position();
  bool is_expression = shared->is_expression();
  Counters::total_compile_size.Increment(end_position - start_position);

  // Generate the AST for the lazily compiled function. The AST may be
  // NULL in case of parser stack overflow.
  FunctionLiteral* lit = MakeLazyAST(script, name,
                                     start_position,
                                     end_position,
                                     is_expression);

  // Check for parse errors.
  if (lit == NULL) {
    ASSERT(Top::has_pending_exception());
    return false;
  }

  // Update the loop nesting in the function literal.
  lit->set_loop_nesting(loop_nesting);

  // Measure how long it takes to do the lazy compilation; only take
  // the rest of the function into account to avoid overlap with the
  // lazy parsing statistics.
  HistogramTimerScope timer(&Counters::compile_lazy);

  // Compile the code.
  Handle<Code> code = MakeCode(lit, script, Handle<Context>::null(), false);

  // Check for stack-overflow exception.
  if (code.is_null()) {
    Top::StackOverflow();
    return false;
  }

#if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT
  // Log the code generation. If source information is available include script
  // name and line number. Check explicit whether logging is enabled as finding
  // the line number is not for free.
  if (Logger::is_logging() || OProfileAgent::is_enabled()) {
    Handle<String> func_name(name->length() > 0 ?
                             *name : shared->inferred_name());
    if (script->name()->IsString()) {
      int line_num = GetScriptLineNumber(script, start_position) + 1;
      LOG(CodeCreateEvent(Logger::LAZY_COMPILE_TAG, *code, *func_name,
                          String::cast(script->name()), line_num));
      OProfileAgent::CreateNativeCodeRegion(*func_name,
                                            String::cast(script->name()),
                                            line_num,
                                            code->instruction_start(),
                                            code->instruction_size());
    } else {
      LOG(CodeCreateEvent(Logger::LAZY_COMPILE_TAG, *code, *func_name));
      OProfileAgent::CreateNativeCodeRegion(*func_name,
                                            code->instruction_start(),
                                            code->instruction_size());
    }
  }
#endif

  // Update the shared function info with the compiled code.
  shared->set_code(*code);

  // Set the expected number of properties for instances.
  SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count());

  // Set the optimication hints after performing lazy compilation, as these are
  // not set when the function is set up as a lazily compiled function.
  shared->SetThisPropertyAssignmentsInfo(
      lit->has_only_this_property_assignments(),
      lit->has_only_simple_this_property_assignments(),
      *lit->this_property_assignments());

  // Check the function has compiled code.
  ASSERT(shared->is_compiled());
  return true;
}
コード例 #11
0
ファイル: compiler.cpp プロジェクト: BlitzMaxModules/axe.mod
static Handle<JSFunction> MakeFunction(bool is_global,
                                       bool is_eval,
                                       Compiler::ValidationState validate,
                                       Handle<Script> script,
                                       Handle<Context> context,
                                       v8::Extension* extension,
                                       ScriptDataImpl* pre_data) {
  CompilationZoneScope zone_scope(DELETE_ON_EXIT);

  // Make sure we have an initial stack limit.
  StackGuard guard;
  PostponeInterruptsScope postpone;

  ASSERT(!i::Top::global_context().is_null());
  script->set_context_data((*i::Top::global_context())->data());

#ifdef ENABLE_DEBUGGER_SUPPORT
  bool is_json = (validate == Compiler::VALIDATE_JSON);
  if (is_eval || is_json) {
    script->set_compilation_type(
        is_json ? Smi::FromInt(Script::COMPILATION_TYPE_JSON) :
                               Smi::FromInt(Script::COMPILATION_TYPE_EVAL));
    // For eval scripts add information on the function from which eval was
    // called.
    if (is_eval) {
      JavaScriptFrameIterator it;
      script->set_eval_from_function(it.frame()->function());
      int offset = it.frame()->pc() - it.frame()->code()->instruction_start();
      script->set_eval_from_instructions_offset(Smi::FromInt(offset));
    }
  }

  // Notify debugger
  Debugger::OnBeforeCompile(script);
#endif

  // Only allow non-global compiles for eval.
  ASSERT(is_eval || is_global);

  // Build AST.
  FunctionLiteral* lit = MakeAST(is_global, script, extension, pre_data);

  // Check for parse errors.
  if (lit == NULL) {
    ASSERT(Top::has_pending_exception());
    return Handle<JSFunction>::null();
  }

  // When parsing JSON we do an ordinary parse and then afterwards
  // check the AST to ensure it was well-formed.  If not we give a
  // syntax error.
  if (validate == Compiler::VALIDATE_JSON && !IsValidJSON(lit)) {
    HandleScope scope;
    Handle<JSArray> args = Factory::NewJSArray(1);
    Handle<Object> source(script->source());
    SetElement(args, 0, source);
    Handle<Object> result = Factory::NewSyntaxError("invalid_json", args);
    Top::Throw(*result, NULL);
    return Handle<JSFunction>::null();
  }

  // Measure how long it takes to do the compilation; only take the
  // rest of the function into account to avoid overlap with the
  // parsing statistics.
  HistogramTimer* rate = is_eval
      ? &Counters::compile_eval
      : &Counters::compile;
  HistogramTimerScope timer(rate);

  // Compile the code.
  Handle<Code> code = MakeCode(lit, script, context, is_eval);

  // Check for stack-overflow exceptions.
  if (code.is_null()) {
    Top::StackOverflow();
    return Handle<JSFunction>::null();
  }

#if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT
  // Log the code generation for the script. Check explicit whether logging is
  // to avoid allocating when not required.
  if (Logger::is_logging() || OProfileAgent::is_enabled()) {
    if (script->name()->IsString()) {
      SmartPointer<char> data =
          String::cast(script->name())->ToCString(DISALLOW_NULLS);
      LOG(CodeCreateEvent(is_eval ? Logger::EVAL_TAG : Logger::SCRIPT_TAG,
                          *code, *data));
      OProfileAgent::CreateNativeCodeRegion(*data,
                                            code->instruction_start(),
                                            code->instruction_size());
    } else {
      LOG(CodeCreateEvent(is_eval ? Logger::EVAL_TAG : Logger::SCRIPT_TAG,
                          *code, ""));
      OProfileAgent::CreateNativeCodeRegion(is_eval ? "Eval" : "Script",
                                            code->instruction_start(),
                                            code->instruction_size());
    }
  }
#endif

  // Allocate function.
  Handle<JSFunction> fun =
      Factory::NewFunctionBoilerplate(lit->name(),
                                      lit->materialized_literal_count(),
                                      lit->contains_array_literal(),
                                      code);

  ASSERT_EQ(RelocInfo::kNoPosition, lit->function_token_position());
  CodeGenerator::SetFunctionInfo(fun, lit, true, script);

  // Hint to the runtime system used when allocating space for initial
  // property space by setting the expected number of properties for
  // the instances of the function.
  SetExpectedNofPropertiesFromEstimate(fun, lit->expected_property_count());

#ifdef ENABLE_DEBUGGER_SUPPORT
  // Notify debugger
  Debugger::OnAfterCompile(script, fun);
#endif

  return fun;
}