-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support corset pure functions (#404)
This adds support for `defpurefun` declarations. However, there are still a number of things outstanding to be done.
- Loading branch information
1 parent
5aeed0b
commit f1d3d94
Showing
23 changed files
with
781 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package corset | ||
|
||
import ( | ||
tr "github.com/consensys/go-corset/pkg/trace" | ||
) | ||
|
||
// Binding represents an association between a name, as found in a source file, | ||
// and concrete item (e.g. a column, function, etc). | ||
type Binding interface { | ||
// Returns the context associated with this binding. | ||
Context() tr.Context | ||
} | ||
|
||
// ColumnBinding represents something bound to a given column. | ||
type ColumnBinding struct { | ||
// For a column access, this identifies the enclosing context. | ||
context tr.Context | ||
// Identifies the variable or column index (as appropriate). | ||
index uint | ||
} | ||
|
||
// Context returns the enclosing context for this column access. | ||
func (p *ColumnBinding) Context() tr.Context { | ||
return p.context | ||
} | ||
|
||
// ColumnID returns the column identifier that this column access refers to. | ||
func (p *ColumnBinding) ColumnID() uint { | ||
return p.index | ||
} | ||
|
||
// ParameterBinding represents something bound to a given column. | ||
type ParameterBinding struct { | ||
// Identifies the variable or column index (as appropriate). | ||
index uint | ||
} | ||
|
||
// Context for a parameter is always void, as it does not correspond to a column | ||
// in given module. | ||
func (p *ParameterBinding) Context() tr.Context { | ||
return tr.VoidContext() | ||
} | ||
|
||
// FunctionBinding represents the binding of a function application to its | ||
// physical definition. | ||
type FunctionBinding struct { | ||
// arity determines the number of arguments this function takes. | ||
arity uint | ||
// body of the function in question. | ||
body Expr | ||
} | ||
|
||
// Context for a parameter is always void, as it does not correspond to a column | ||
// in given module. | ||
func (p *FunctionBinding) Context() tr.Context { | ||
return tr.VoidContext() | ||
} | ||
|
||
// Apply a given set of arguments to this function binding. | ||
func (p *FunctionBinding) Apply(args []Expr) Expr { | ||
return p.body.Substitute(args) | ||
} |
Oops, something went wrong.