Skip to content

Commit

Permalink
It works! Next up: primituves such as all()
Browse files Browse the repository at this point in the history
  • Loading branch information
Zef Hemel committed Mar 20, 2009
1 parent 66c1336 commit 10a86d8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gelly.pil
Expand Up @@ -12,7 +12,7 @@ void main(Array<String> args) {
//evalInit();
String input = null;
println("Welcome to gelly, type :q to quit.");
var s = new Strategy(new Map<String, StrategyDef>(), new Map<String, Term>());
var s = new Strategy(new Map<String, StrategyDef>(), new Map<String, ClosureStrategyDef>(), new Map<String, Term>());
if(s.evalString(":import \"test.g\"")) {
println(s.currentTerm.toIndentedString(0));
} else {
Expand Down
15 changes: 14 additions & 1 deletion rewrite.pil
Expand Up @@ -54,13 +54,26 @@ class gelly::rewrite::StrategyDef {
}
}

class gelly::rewrite::ClosureStrategyDef {
Term t = null;
Strategy parent = null;

new(Strategy parent, Term t) {
this.parent = parent;
this.t = t;
}
}

class gelly::rewrite::Strategy {
Term currentTerm = new EmptyTerm();
Map<String, Term> bindings = null;
Map<String, StrategyDef> strategies = null;
Map<String, ClosureStrategyDef> closureStrategies = null;
Strategy parent = null;

new(Map<String, StrategyDef> strategies, Map<String, Term> bindings) {
new(Map<String, StrategyDef> strategies, Map<String, ClosureStrategyDef> closureStrategies, Map<String, Term> bindings) {
this.strategies = strategies;
this.closureStrategies = closureStrategies;
this.bindings = bindings;
}

Expand Down
9 changes: 6 additions & 3 deletions test.g
Expand Up @@ -2,12 +2,15 @@ strategy simplify()[] {
?[ m_x * 1 ];
![ m_x ]
};
strategy simplify2()[] {
?[ m_x + 0 ];
![ m_x ]
};
strategy try(s)[] {
s <+ id
};
strategy repeat(s)[] {
debug;
try(s; repeat(s))
};
![ 8 * 3 * 1 * 1 * 1 * 1];
repeat(simplify)
![ 8 * 3 * 1 * 1 * 1 * 1 + 0];
repeat(simplify <+ simplify2)

0 comments on commit 10a86d8

Please sign in to comment.