Skip to content

Commit

Permalink
Enable checking guards are boolean
Browse files Browse the repository at this point in the history
This adds support for checking that guards have boolean semantics.  For
now, checking constraints have loobean semantics is implemented but not
enabled.  The problem is that it breaks a lot of the existing tests!
  • Loading branch information
DavePearce committed Dec 11, 2024
1 parent da264d6 commit 9d93f67
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
16 changes: 14 additions & 2 deletions pkg/corset/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,27 @@ func (r *resolver) finaliseDefConstInModule(enclosing Scope, decl *DefConst) []S
func (r *resolver) finaliseDefConstraintInModule(enclosing Scope, decl *DefConstraint) []SyntaxError {
var (
guard_errors []SyntaxError
guard_t Type
scope = NewLocalScope(enclosing, false, false)
)
// Resolve guard
if decl.Guard != nil {
// FIXME: check for boolean semantics!
_, guard_errors = r.finaliseExpressionInModule(scope, decl.Guard)
guard_t, guard_errors = r.finaliseExpressionInModule(scope, decl.Guard)
//
if guard_t != nil && !guard_t.HasBooleanSemantics() {
msg := fmt.Sprintf("expected boolean guard (found %s)", guard_t.String())
err := r.srcmap.SyntaxError(decl.Guard, msg)
guard_errors = append(guard_errors, *err)
}
}
// Resolve constraint body
_, errors := r.finaliseExpressionInModule(scope, decl.Constraint)
//
// if constraint_t != nil && !constraint_t.HasLoobeanSemantics() {
// msg := fmt.Sprintf("expected loobean constraint (found %s)", constraint_t.String())
// err := r.srcmap.SyntaxError(decl.Constraint, msg)
// errors = append(errors, *err)
// }
// Done
return append(guard_errors, errors...)
}
Expand Down
2 changes: 1 addition & 1 deletion testdata/basic_01.lisp
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
(defcolumns X)
(defcolumns (X :byte@loob))
(defconstraint heartbeat () X)
4 changes: 2 additions & 2 deletions testdata/type_06.accepts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
{ "BIT": [0,2], "X": [1,0] }
{ "BIT": [0,2], "X": [2,0] }
;;
{ "BIT": [1,1], "X": [1,1] }
{ "BIT": [2,2], "X": [1,1] }
{ "BIT": [1,1], "X": [0,0] }
{ "BIT": [2,2], "X": [0,0] }
2 changes: 1 addition & 1 deletion testdata/type_08.accepts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
{ "BIT": [0,1], "X": [1,0] }
{ "BIT": [0,1], "X": [2,0] }
;;
{ "BIT": [1,1], "X": [1,1] }
{ "BIT": [1,1], "X": [0,0] }

0 comments on commit 9d93f67

Please sign in to comment.