void GapStringBuffer::insert(const char *chars, size_t l)
{
	size_t gapPosInBuf = gapPos % bufferSize;
	if (l >= gapLen) { // we must ensure that gapLen is never 0, otherwise, we might end up with a NULL gapBuf pointer when moving the cursor to the end of the string
		// add first buf
		gc<Buffer *> buf = gcnew(Buffer);
		buf->prev = gapBuf;
		buf->next = gapBuf->next;
		memBarrier();
		gapBuf->next = buf;
		if (buf->next)
			buf->next->prev = buf;
		// copy chars if they were in the same buffer as the start of the gap
		size_t nextCharPos = gapPosInBuf + gapLen;
		if (nextCharPos < bufferSize)
			memcpy(buf->chars + nextCharPos, gapBuf->chars + nextCharPos, bufferSize - nextCharPos);
		// increase gapLen to reflect gap increasing
		gapLen += bufferSize;
		length += bufferSize;
		// now add additional buffers without copying, if required
		while (l >= gapLen) {
			buf = gcnew(Buffer);
			buf->prev = gapBuf;
			buf->next = gapBuf->next;
			memBarrier();
			gapBuf->next = buf;
			buf->next->prev = buf;
			gapLen += bufferSize;
			length += bufferSize;
		}
	}
	// now we have enough room, copy the characters
	while (l) {
		size_t w = bufferSize - gapPosInBuf;
		if (l >= w) {
			memcpy(gapBuf->chars + gapPosInBuf, chars, w);
			gapPosInBuf = 0;
			gapPos += w;
			gapLen -= w;
			gapBuf = gapBuf->next;
			l -= w;
			chars += w;
		}
		else {
			memcpy(gapBuf->chars + gapPosInBuf, chars, l);
			gapPosInBuf += l;
			gapPos += l;
			gapLen -= l;
			l = 0;
		}
	}
}
Ejemplo n.º 2
0
Frame::Access *
X86Frame::allocLocal(bool escape)
{
	Frame::Access *access = NULL;
	if (escape) {
		frameOffset += WORD_SIZE;
		DBG("frameOffset %d", frameOffset);
		access = gcnew(InFrame, (-frameOffset));
	} else {
		Temp *t = gcnew(Temp, ());
		access = gcnew(InReg, (t));
	}
	return access;
}
Ejemplo n.º 3
0
tree::Stm *
X86Frame::procEntryExit1(tree::Stm *body)
{
	if (!tree::isExistType(body, tree::Tree::CALL_T)) {
		//this is leaf function
		//TODO:
	}
	Label *fname = gcnew(Label, (name->name));
	tree::LABEL *l = _LABEL(fname);
	tree::SEQMaker sm;
	sm.add(l);
	/*
	int i = 0;
	int offset = 4;
	std::vector<Access*>::iterator it = formals.begin();
	while (it != formals.end()) {
		tree::CONST *offs = _CONST(offset);
		tree::TEMP *base = _TEMP(fp());
		tree::MEM *m = _MEM(_(base) + _(offs));
		tree::Exp *tmp = (*it)->exp(_TEMP(fp()));
		sm.add(_MOVE(tmp, m));
		offset += WORD_SIZE;
		
		++it;
		++i;
	}
	*/
	sm.add(body);
	return sm.make();
}
GapStringBuffer::GapStringBuffer(const String &string)
{
	size_t l = string.getLength();
	const char *chars = string.getChars();
	length = 0;
	first = NULL;
	gc<Buffer *> buf;
	Buffer *lastBuf = NULL;
	for (;;) {
		buf = gcnew(Buffer);
		buf->prev = lastBuf;
		buf->next = NULL;
		memBarrier();
		if (lastBuf)
			lastBuf->next = buf;
		if (!first)
			first = buf;
		lastBuf = buf;
		if (l < bufferSize) {
			memcpy(buf->chars, chars, l);
			gapBuf = buf;
			gapPos = length + l;
			gapLen = bufferSize - l;
			length += bufferSize;
			break;
		}
		else {
			memcpy(buf->chars, chars, bufferSize);
			l -= bufferSize;
			length += bufferSize;
		}
	}
}
Ejemplo n.º 5
0
gc<const CObject *> CReal::parseString(String::AbstractIterator &stri)
{
	double value = stringToDouble(stri);
	if (isnan(value))
		gcthrownew(EInvalidObjectValue(Message(InvalidRealValue)));
	return gcnew(CReal(value));
}
Ejemplo n.º 6
0
tree::Exp *
X86Frame::externalCall(const std::string &func, const tree::ExpList &args)
{
	Label *flabel = gcnew(Label, (func));
	tree::NAME *name = _NAME(flabel);
	tree::CALL *call = _CALL(name, args);
	return call;
}
Ejemplo n.º 7
0
extern Term *mkstr(char *str) {
	Term *term;
	Ref(char *, string, str);
	term = gcnew(Term);
        term->str = string;
	term->closure = NULL;
        RefEnd(string);
        return term;
}
Ejemplo n.º 8
0
static Var *mkvar(List *defn) {
	Ref(Var *, var, NULL);
	Ref(List *, lp, defn);
	var = gcnew(Var);
	var->env = NULL;
	var->defn = lp;
	var->flags = hasbindings(lp) ? var_hasbindings : 0;
	RefEnd(lp);
	RefReturn(var);
}
GapStringBuffer::GapStringBuffer()
{
	first = gcnew(Buffer);
	first->next = NULL;
	first->prev = NULL;
	length = bufferSize;
	gapBuf = first;
	gapPos = 0;
	gapLen = bufferSize;
}
Ejemplo n.º 10
0
static void *VarCopy(void *op) {
	void *np = gcnew(Var);
	memcpy(np, op, sizeof (Var));
	return np;
}
Ejemplo n.º 11
0
static void *TermCopy(void *op) {
	void *np = gcnew(Term);
	memcpy(np, op, sizeof (Term));
	return np;
}
Ejemplo n.º 12
0
gc<Kernel::SysThreadGroup *> createThreadGroup(ThreadGroup *userThreadGroup)
{
	return gcnew(SysThreadGroup(userThreadGroup));
}
Ejemplo n.º 13
0
gc<Kernel::SysThread *> createThread(Thread *userThread, size_t stackSize, int priority, bool privileged)
{
	if (stackSize == 0 || (privileged && !Kernel::getCurrentThread()->isPrivileged()))
		throw gcnew(EOperationNotPermitted);
	return gcnew(SysThread(userThread, stackSize, priority, privileged));
}
Ejemplo n.º 14
0
static void *ListCopy(void *op) {
    void *np = gcnew(List);
    memcpy(np, op, sizeof (List));
    return np;
}
Ejemplo n.º 15
0
gc<WaitableEvent *> createEvent(bool autoReset, bool wakeupAll, bool set)
{
	return gcnew(WaitableEvent(autoReset, wakeupAll, set));
}
Ejemplo n.º 16
0
gc<const CObject *> CReal::deserializeData(IO::InputStream *stream)
{
	double value;
	stream->read(&value, sizeof(value));
	return gcnew(CReal(value));
}
Ejemplo n.º 17
0
Frame *
Frame::newFrame(Symbol *name, const std::vector<int> &formals)
{
	return gcnew(X86Frame, (name, formals));
}
Ejemplo n.º 18
0
X86Frame::X86Frame(Symbol *n, const std::vector<int> &f)
	: frameOffset(0)
	, maxArgSize(0)
{
	Frame::name = n;
	std::string end = format("end_of_%s", name->name.c_str());
	Frame::endFuncLabel = gcnew(Label, (end));
	frameCount++;

	eax = gcnew(Temp, ("%eax"));
	ecx = gcnew(Temp, ("%ecx"));
	edx = gcnew(Temp, ("%edx"));
	ebx = gcnew(Temp, ("%ebx"));
	esi = gcnew(Temp, ("%esi"));
	edi = gcnew(Temp, ("%edi"));
	ebp = gcnew(Temp, ("%ebp"));
	esp = gcnew(Temp, ("%esp"));
	eip = gcnew(Temp, ("%eip"));
	regs.all.push_back(eax);
	regs.all.push_back(ecx);
	regs.all.push_back(edx);
	regs.all.push_back(ebx);
	regs.all.push_back(esi);
	regs.all.push_back(edi);
	regs.all.push_back(ebp);
	regs.all.push_back(esp);
	regs.all.push_back(eip);

	std::vector<int>::const_iterator it;
	it = f.begin();
	int argOffset = 8;//0 ... ebp, 4 ... return addr
	while (it != f.end()) {
		Access *acc = gcnew(InFrame, (argOffset));
		formals.push_back(acc);
		argOffset += WORD_SIZE;
		++it;
	}

	generator = new X86CodeGen(this);

	regs.callerSaves.push_back(eax);
	regs.callerSaves.push_back(ecx);
	regs.callerSaves.push_back(edx);

	regs.calleeSaves.push_back(ebx);
	regs.calleeSaves.push_back(esi);
	regs.calleeSaves.push_back(edi);
	
	regs.specials.push_back(ebp);
	regs.specials.push_back(esp);
	regs.specials.push_back(eip);
}