Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memoization #295

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions TotalCrossVM/src/tcvm/tcvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ TC_API TValue executeMethod(Context context, Method method, ...)
int32 hashName,hashParams;
ThreadHandle thread;

printf("m: %s, %s\n", method->class_->name, method->name);

#ifdef DIRECT_JUMP // use a direct jump if supported
uint32 **address;
uint32 **addrMtdParam;
Expand Down Expand Up @@ -502,6 +504,10 @@ TC_API TValue executeMethod(Context context, Method method, ...)
{
newMethod = mac->m;
contCall:
if (xstrcmp(newMethod->name, "fibR") == 0) {
int a = 0;
a++;
}
regI = context->regI; // same of regI += method->iCount
regO = context->regO;
reg64 = context->reg64;
Expand Down Expand Up @@ -586,6 +592,10 @@ TC_API TValue executeMethod(Context context, Method method, ...)
if (--nparam == 0) // if no more parameters, continue. putting this here avoids another "if (nparam > 0)" after this block ends.
goto noMoreParams;
}
if (xstrcmp(newMethod->name, "fibR") == 0) {
int a = 0;
a++;
}
// The method's parameters are passed in the registers, in sequence.
params = (uint8*)(code+1);
for (; nparam-- > 0; params++, regs++)
Expand Down Expand Up @@ -622,13 +632,35 @@ TC_API TValue executeMethod(Context context, Method method, ...)
}
}
noMoreParams:

// OPCODE(RETURN_reg64) context->callStack -= 2; /*newMethod = (Method)context->callStack[0]; if (newMethod->flags.isSynchronized) unlockMutex(newMethod->flags.isStatic? (size_t)newMethod->class_ : (size_t)regO[-method->oCount]); */ if (((int32)(context->callStack-context->callStackStart)) >= callStackMethodEnd) {reg64 [((Code)context->callStack[-1])->mtd.retOr1stParam - ((Method)context->callStack[-2])->v64Count] = reg64[code->reg.reg]; goto resumePreviousMethod;} else {returnedValue.asInt64 = reg64[code->reg.reg]; goto finishMethod;}

if (!newMethod->flags.isNative)
{
// replace current variables by the new ones
class_ = newMethod->class_; // replace current's class
cp = class_->cp;
method = newMethod;
code = method->code;

if (xstrcmp(newMethod->name, "fibR") == 0) {
int a = 0;
a++;

// if argument in hash, set reg64 & XSELECT

switch (reg64[-(int32)method->v64Count]) {
case 0:reg64[code->reg.reg] = 1; XSELECT(address,RETURN_reg64);
case 1:reg64[code->reg.reg] = 1; XSELECT(address,RETURN_reg64);
case 2:reg64[code->reg.reg] = 2; XSELECT(address,RETURN_reg64);
case 3:reg64[code->reg.reg] = 3; XSELECT(address,RETURN_reg64);
case 4:reg64[code->reg.reg] = 5; XSELECT(address,RETURN_reg64);
case 5:reg64[code->reg.reg] = 8; XSELECT(address,RETURN_reg64);
case 6:reg64[code->reg.reg] = 13; XSELECT(address,RETURN_reg64);
case 7:reg64[code->reg.reg] = 21; XSELECT(address,RETURN_reg64);
case 8:reg64[code->reg.reg] = 34; XSELECT(address,RETURN_reg64);
}
}
NEXT_OP0
}
// no else here!
Expand Down Expand Up @@ -748,6 +780,11 @@ TC_API TValue executeMethod(Context context, Method method, ...)
hashName = cp->hashNames[code->mtd.sym];
hashParams = cp->hashParams[code->mtd.sym];
methodName = cp->mtdfld[sym[1]];
printf("m2: %s, %s\n", className, methodName);
if (xstrcmp(methodName, "fibR") == 0) {
int a = 10;
a++;
}
if (code->op.op == CALL_virtual)
{
c = OBJ_CLASS(regO[code->mtd.this_]); // search for the method starting on the class pointed by "this"
Expand Down Expand Up @@ -847,6 +884,10 @@ TC_API TValue executeMethod(Context context, Method method, ...)
if (((int32)(context->callStack-context->callStackStart)) >= callStackMethodEnd)
{
resumePreviousMethod:
// if (fibR) {
// // save argument -> result in hashmap
// }

code = ((Code)context->callStack[-1]) + method->paramSkip; // now that retReg was used, its safe to skip over the parameters
// pop the current method's stack frame
context->regI -= method->iCount;
Expand Down
2 changes: 2 additions & 0 deletions TotalCrossVM/src/util/posix/debug_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ static bool privateDebug(char* str)
fflush(fdebug);
fsync(fileno(fdebug));
}
} else {
printf("%s\n", str);
}
return err;
}
Expand Down