Skip to content

Commit

Permalink
Make samples x2.1 to x2.5 run.
Browse files Browse the repository at this point in the history
git-svn-id: https://elmar.ips.cs.tu-bs.de/svn/arden2bytecode/trunk@19 20415b1c-3eea-de11-af57-000476a39db3
  • Loading branch information
dgrunwald committed Jan 24, 2010
1 parent 790f18f commit 0dd1923
Show file tree
Hide file tree
Showing 14 changed files with 561 additions and 64 deletions.
1 change: 1 addition & 0 deletions src/arden/compiler/ActionCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public static void compileIfStatement(CompilerContext context, PExpr expr, Switc
Label endLabel = new Label();
context.writer.jumpIfZero(falseLabel);
trueBlock.apply(blockCompiler);
context.writer.jump(endLabel);
context.writer.markForwardJumpsOnly(falseLabel);
falseBlock.apply(blockCompiler);
context.writer.markForwardJumpsOnly(endLabel);
Expand Down
6 changes: 6 additions & 0 deletions src/arden/compiler/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,17 @@ private void compileAction(CodeGenerator codeGen, PActionSlot actionSlot) {
}

private void compileUrgency(CodeGenerator codeGen, PUrgencySlot urgencySlot) {
// urgency_slot =
// {empty}
// | {urg} urgency urgency_val semicolons;
if (urgencySlot instanceof AUrgUrgencySlot) {
PUrgencyVal val = ((AUrgUrgencySlot) urgencySlot).getUrgencyVal();
CompilerContext context = codeGen.createUrgency();
if (enableDebugging)
context.writer.enableLineNumberTable();
// urgency_val =
// {num} P.number
// | {id} identifier;
if (val instanceof ANumUrgencyVal) {
context.writer.loadDoubleConstant(ParseHelpers
.getLiteralDoubleValue(((ANumUrgencyVal) val).getNumber()));
Expand Down
67 changes: 50 additions & 17 deletions src/arden/compiler/PhraseCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,29 @@ public void caseAReadReadPhrase(AReadReadPhrase node) {
public void caseAOfReadPhrase(AOfReadPhrase node) {
// read_phrase = {of} of_read_func_op read_where
node.getReadWhere().apply(this);
// TODO Auto-generated method stub
throw new RuntimeCompilerException("TODO");

// of_read_func_op =
// {avge} average
// | {avg} avg
// | {cnt} count
// | {ex} exist
// | {exs} exists
// | {sum} sum
// | {med} median;
if (node.getOfReadFuncOp() instanceof AAvgeOfReadFuncOp || node.getOfReadFuncOp() instanceof AAvgOfReadFuncOp) {
invokeSimpleAggregationOperator("average");
} else if (node.getOfReadFuncOp() instanceof ACntOfReadFuncOp) {
invokeSimpleAggregationOperator("count");
} else if (node.getOfReadFuncOp() instanceof AExOfReadFuncOp
|| node.getOfReadFuncOp() instanceof AExsOfReadFuncOp) {
invokeSimpleAggregationOperator("exist");
} else if (node.getOfReadFuncOp() instanceof ASumOfReadFuncOp) {
invokeSimpleAggregationOperator("sum");
} else if (node.getOfReadFuncOp() instanceof AMedOfReadFuncOp) {
invokeSimpleAggregationOperator("median");
} else {
throw new RuntimeException("unknown of_read_func_op");
}
}

@Override
Expand Down Expand Up @@ -143,7 +164,7 @@ public void caseAMappingFactor(AMappingFactor node) {

/** Adds the temporalCompOp to the DatabaseQuery on the evaluation stack */
private void handleTemporalCompOp(PTemporalCompOp pTemporalCompOp, final boolean negate) {
final ExpressionCompiler exprCompiler = new ExpressionCompiler(context);
final ExpressionCompiler expressionCompiler = new ExpressionCompiler(context);

pTemporalCompOp.apply(new VisitorBase() {
// temporal_comp_op =
Expand All @@ -166,13 +187,13 @@ public void caseAPrecTemporalCompOp(APrecTemporalCompOp node) {
private void caseAPrecTemporalCompOp(Switchable durationExpr, Switchable timeExpr) {
// within duration preceding time
// = within (duration before time) to time
exprCompiler.loadOperator(BinaryOperator.BEFORE);
durationExpr.apply(exprCompiler);
timeExpr.apply(exprCompiler);
expressionCompiler.loadOperator(BinaryOperator.BEFORE);
durationExpr.apply(expressionCompiler);
timeExpr.apply(expressionCompiler);
// stack: query, argument, BEFORE, dur, time
context.writer.dup_x2();
// stack: query, argument, time, BEFORE, dur, time
exprCompiler.invokeLoadedBinaryOperator();
expressionCompiler.invokeLoadedBinaryOperator();
// stack: query, argument, time, time2
context.writer.swap();
// stack: query, argument, time2, time
Expand All @@ -183,13 +204,13 @@ private void caseAPrecTemporalCompOp(Switchable durationExpr, Switchable timeExp
@Override
public void caseAFolTemporalCompOp(AFolTemporalCompOp node) {
// within [left]:expr_string following [right]:expr_string
exprCompiler.loadOperator(BinaryOperator.AFTER);
node.getLeft().apply(exprCompiler);
node.getRight().apply(exprCompiler);
expressionCompiler.loadOperator(BinaryOperator.AFTER);
node.getLeft().apply(expressionCompiler);
node.getRight().apply(expressionCompiler);
// stack: query, argument, AFTER, dur, time
context.writer.dup_x2();
// stack: query, argument, time, AFTER, dur, time
exprCompiler.invokeLoadedBinaryOperator();
expressionCompiler.invokeLoadedBinaryOperator();
// stack: query, argument, time, time2
invokeWithinTo();
// stack: newquery
Expand All @@ -205,8 +226,8 @@ public void caseASurTemporalCompOp(ASurTemporalCompOp node) {
@Override
public void caseAWithinTemporalCompOp(AWithinTemporalCompOp node) {
// within [lower]:expr_string to [upper]:expr_string
node.getLower().apply(new ExpressionCompiler(context));
node.getUpper().apply(new ExpressionCompiler(context));
node.getLower().apply(expressionCompiler);
node.getUpper().apply(expressionCompiler);
invokeWithinTo();
}

Expand Down Expand Up @@ -237,15 +258,27 @@ public void caseASameTemporalCompOp(ASameTemporalCompOp node) {
@Override
public void caseABefTemporalCompOp(ABefTemporalCompOp node) {
// before expr_string
// TODO Auto-generated method stub
throw new RuntimeCompilerException("TODO");
node.getExprString().apply(expressionCompiler);
if (negate) {
context.writer.invokeStatic(Compiler.getRuntimeHelper("constrainQueryNotBefore",
DatabaseQuery.class, ArdenValue.class));
} else {
context.writer.invokeStatic(Compiler.getRuntimeHelper("constrainQueryBefore", DatabaseQuery.class,
ArdenValue.class));
}
}

@Override
public void caseAAfterTemporalCompOp(AAfterTemporalCompOp node) {
// after expr_string
// TODO Auto-generated method stub
throw new RuntimeCompilerException("TODO");
node.getExprString().apply(expressionCompiler);
if (negate) {
context.writer.invokeStatic(Compiler.getRuntimeHelper("constrainQueryNotAfter",
DatabaseQuery.class, ArdenValue.class));
} else {
context.writer.invokeStatic(Compiler.getRuntimeHelper("constrainQueryAfter", DatabaseQuery.class,
ArdenValue.class));
}
}

@Override
Expand Down
Loading

0 comments on commit 0dd1923

Please sign in to comment.