Skip to content
Open
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
48 changes: 47 additions & 1 deletion src/analysis/typepal/ICollector.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,51 @@ data Collector
void (value l, value r, FailMessage fm) requireEqual,
void (value l, value r, FailMessage fm) requireComparable,
void (value l, value r, FailMessage fm) requireSubType,
void (value l, value r, FailMessage fm) requireUnify
void (value l, value r, FailMessage fm) requireUnify,

/* blocked short-hands for scope stack and info stack management (default kwparams) */

/* enter/leave */ void (Tree id, void () block) scope = (Tree id, void() block) {
enterScope(id);
try
block();
catch 22: ;
finally
leaveScope(id);
},
/* lub ent/leave */ void (Tree id, void () block) lubScope = (Tree id, void() block) {
enterLubScope(id);
try
block();
catch 22: ;
finally
leaveScope(id);
},
/* comp lub */ void (list[Tree] ids, void () block) compositeLubScope = (list[Tree] ids, void () block) {
enterCompositeLubScope(ids);
try
block();
catch 22: ;
finally
leaveCompositeScope(ids);
},
/* comp ent/leave*/ void (list[Tree] ids, void () block) compositeScope = (list[Tree] ids, void () block) {
enterCompositeScope(ids);
try
block();
catch 22: ;
finally
leaveCompositeScope(ids);

},
/* push/pop info*/ void (str key, value val, void () block) nestInfo = (str key, value val, void () block) {
push(key, val);
try {
block();
}
catch 22: ;
finally {
pop(key);
}
}
);
21 changes: 12 additions & 9 deletions src/examples/pico/Checker.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ str prettyAType(strType()) = "str";
// ---- Collect definitions, uses and requirements -----------------------

void collect(current: (Program) `begin <Declarations decls> <{Statement ";"}* body> end`, Collector c){
c.enterScope(current);
c.scope(current, () {
collect(decls, body, c);
c.leaveScope(current);
});
}

void collect(current: (Declarations) `declare <{Declaration ","}* decls> ;`, Collector c){
Expand Down Expand Up @@ -71,15 +71,18 @@ void collect(current: (Statement) `while <Expression cond> do <{Statement ";"}*

void collect(current: (Expression) `<Expression lhs> + <Expression rhs>`, Collector c){
c.calculate("addition", current, [lhs, rhs],
AType (Solver s) { switch([s.getType(lhs), s.getType(rhs)]){
case [intType(), intType()]: return intType();
case [strType(), strType()]: return strType();
default: {
AType (Solver s) {
switch(<s.getType(lhs), s.getType(rhs)>){
case <intType(), intType()>:
return intType();
case <strType(), strType()>:
return strType();
default: {
s.report(error(current, "Operator `+` cannot be applied to %t and %t", lhs, rhs));
return intType();
}
}
});
}
}
});
collect(lhs, rhs, c);
}

Expand Down