access to way-context vars from (no caching) node-context
This commit is contained in:
parent
313592ebd3
commit
2c4c21ad7c
3 changed files with 76 additions and 3 deletions
|
@ -64,7 +64,8 @@ public final class ProfileCache
|
|||
|
||||
BExpressionContextGlobal expctxGlobal = new BExpressionContextGlobal( meta );
|
||||
rc.expctxWay = new BExpressionContextWay( rc.memoryclass * 512, meta );
|
||||
rc.expctxNode = new BExpressionContextNode( rc.memoryclass * 128, meta );
|
||||
rc.expctxNode = new BExpressionContextNode( 0, meta );
|
||||
rc.expctxNode.setForeignContext( rc.expctxWay );
|
||||
|
||||
meta.readMetaData( new File( profileDir, "lookups.dat" ) );
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ final class BExpression
|
|||
private static final int LOOKUP_EXP = 32;
|
||||
private static final int NUMBER_EXP = 33;
|
||||
private static final int VARIABLE_EXP = 34;
|
||||
private static final int FOREIGN_VARIABLE_EXP = 35;
|
||||
|
||||
private int typ;
|
||||
private BExpression op1;
|
||||
|
@ -138,6 +139,8 @@ final class BExpression
|
|||
exp.typ = ASSIGN_EXP;
|
||||
String variable = ctx.parseToken();
|
||||
if ( variable == null ) throw new IllegalArgumentException( "unexpected end of file" );
|
||||
if ( variable.indexOf( '=' ) >= 0 ) throw new IllegalArgumentException( "variable name cannot contain '=': " + variable );
|
||||
if ( variable.indexOf( ':' ) >= 0 ) throw new IllegalArgumentException( "cannot assign context-prefixed variable: " + variable );
|
||||
exp.variableIdx = ctx.getVariableIdx( variable, true );
|
||||
if ( exp.variableIdx < ctx.getMinWriteIdx() ) throw new IllegalArgumentException( "cannot assign to readonly variable " + variable );
|
||||
}
|
||||
|
@ -175,6 +178,13 @@ final class BExpression
|
|||
}
|
||||
}
|
||||
}
|
||||
else if ( ( idx = operator.indexOf( ':' ) ) >= 0 )
|
||||
{
|
||||
String context = operator.substring( 0, idx );
|
||||
String varname = operator.substring( idx+1 );
|
||||
exp.typ = FOREIGN_VARIABLE_EXP;
|
||||
exp.variableIdx = ctx.getForeignVariableIdx( context, varname );
|
||||
}
|
||||
else if ( (idx = ctx.getVariableIdx( operator, false )) >= 0 )
|
||||
{
|
||||
exp.typ = VARIABLE_EXP;
|
||||
|
@ -257,6 +267,7 @@ final class BExpression
|
|||
case LOOKUP_EXP: return ctx.getLookupMatch( lookupNameIdx, lookupValueIdxArray );
|
||||
case NUMBER_EXP: return numberValue;
|
||||
case VARIABLE_EXP: return ctx.getVariableValue( variableIdx );
|
||||
case FOREIGN_VARIABLE_EXP: return ctx.getForeignVariableValue( variableIdx );
|
||||
case NOT_EXP: return op1.evaluate(ctx) == 0.f ? 1.f : 0.f;
|
||||
default: throw new IllegalArgumentException( "unknown op-code: " + typ );
|
||||
}
|
||||
|
|
|
@ -70,6 +70,8 @@ public abstract class BExpressionContext implements IByteArrayUnifier
|
|||
private float[] currentVars;
|
||||
private int currentVarOffset;
|
||||
|
||||
private BExpressionContext foreignContext;
|
||||
|
||||
protected void setInverseVars()
|
||||
{
|
||||
currentVarOffset = nBuildInVars;
|
||||
|
@ -108,8 +110,11 @@ public abstract class BExpressionContext implements IByteArrayUnifier
|
|||
if ( Boolean.getBoolean( "disableExpressionCache" ) ) hashSize = 1;
|
||||
|
||||
// create the expression cache
|
||||
cache = new LruMap( 4*hashSize, hashSize );
|
||||
resultVarCache = new LruMap( 4096, 4096 );
|
||||
if ( hashSize > 0 )
|
||||
{
|
||||
cache = new LruMap( 4*hashSize, hashSize );
|
||||
resultVarCache = new LruMap( 4096, 4096 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -347,6 +352,18 @@ public abstract class BExpressionContext implements IByteArrayUnifier
|
|||
{
|
||||
requests++;
|
||||
lookupDataValid = false; // this is an assertion for a nasty pifall
|
||||
|
||||
if ( cache == null )
|
||||
{
|
||||
decode( lookupData, inverseDirection, ab );
|
||||
if ( currentVars == null || currentVars.length != nBuildInVars )
|
||||
{
|
||||
currentVars = new float[nBuildInVars];
|
||||
}
|
||||
evaluateInto( currentVars, 0 );
|
||||
currentVarOffset = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
CacheNode cn;
|
||||
if ( lastCacheNode.ab == ab )
|
||||
|
@ -660,6 +677,50 @@ public abstract class BExpressionContext implements IByteArrayUnifier
|
|||
Integer num = lookupNumbers.get( name );
|
||||
return num != null && lookupData[num.intValue()] == 2;
|
||||
}
|
||||
|
||||
public int getOutputVariableIndex( String name )
|
||||
{
|
||||
int idx = getVariableIdx( name, false );
|
||||
if ( idx < 0 )
|
||||
{
|
||||
throw new IllegalArgumentException( "unknown variable: " + name );
|
||||
}
|
||||
if ( idx < minWriteIdx )
|
||||
{
|
||||
throw new IllegalArgumentException( "bad access to global variable: " + name );
|
||||
}
|
||||
for( int i=0; i<nBuildInVars; i++ )
|
||||
{
|
||||
if ( buildInVariableIdx[i] == idx )
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
int[] extended = new int[nBuildInVars + 1];
|
||||
System.arraycopy( buildInVariableIdx, 0, extended, 0, nBuildInVars );
|
||||
extended[nBuildInVars] = idx;
|
||||
buildInVariableIdx = extended;
|
||||
return nBuildInVars++;
|
||||
}
|
||||
|
||||
public void setForeignContext( BExpressionContext foreignContext )
|
||||
{
|
||||
this.foreignContext = foreignContext;
|
||||
}
|
||||
|
||||
public float getForeignVariableValue( int foreignIndex )
|
||||
{
|
||||
return foreignContext.getBuildInVariable( foreignIndex );
|
||||
}
|
||||
|
||||
public int getForeignVariableIdx( String context, String name )
|
||||
{
|
||||
if ( foreignContext == null || !context.equals( foreignContext.context ) )
|
||||
{
|
||||
throw new IllegalArgumentException( "unknown foreign context: " + context );
|
||||
}
|
||||
return foreignContext.getOutputVariableIndex( name );
|
||||
}
|
||||
|
||||
public void parseFile( File file, String readOnlyContext )
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue