Skip to content

Commit

Permalink
feat: implement defconst (#419)
Browse files Browse the repository at this point in the history
* Add tests for `(defconst ...)` declarations

This adds a range of tests based on existing tests for the `(defconst
...)` declarartion.  They are all failing of course :)

* Update parser for defconst

This updates the parser to parse defconst declarations.  This also adds
a number of invalid tests as well.

* Constants are mostly working

Constants are now mostly working, but there are a few edge cases to work
through.

* Final Fixes

The final fixes are related to generalising exponentiation and shifting, as well as proper checking of identifiers during parsing.
  • Loading branch information
DavePearce authored Dec 9, 2024
1 parent 6c905cc commit 13af9a0
Show file tree
Hide file tree
Showing 63 changed files with 1,494 additions and 478 deletions.
644 changes: 530 additions & 114 deletions pkg/corset/ast.go

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions pkg/corset/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ type Binding interface {
IsFinalised() bool
}

// ============================================================================
// ColumnBinding
// ============================================================================

// ColumnBinding represents something bound to a given column.
type ColumnBinding struct {
// Column's allocated identifier
Expand Down Expand Up @@ -72,12 +76,41 @@ func (p *ColumnBinding) ColumnId() uint {
return p.cid
}

// ============================================================================
// ConstantBinding
// ============================================================================

// ConstantBinding represents a constant definition
type ConstantBinding struct {
// Constant expression which, when evaluated, produces a constant value.
value Expr
}

// IsFinalised checks whether this binding has been finalised yet or not.
func (p *ConstantBinding) IsFinalised() bool {
return true
}

// Context returns the of this constant, noting that constants (by definition)
// do not have a context.
func (p *ConstantBinding) Context() Context {
return tr.VoidContext[string]()
}

// ============================================================================
// ParameterBinding
// ============================================================================

// ParameterBinding represents something bound to a given column.
type ParameterBinding struct {
// Identifies the variable or column index (as appropriate).
index uint
}

// ============================================================================
// FunctionBinding
// ============================================================================

// IsFinalised checks whether this binding has been finalised yet or not.
func (p *ParameterBinding) IsFinalised() bool {
panic("")
Expand Down
Loading

0 comments on commit 13af9a0

Please sign in to comment.