-
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.
Initial parser for
defpurefun
operational
The initial parser for pure function declarations is now almost operational. What's left is to handle signatures with return types, and parameters with explicit types. This introduces a proper notion of scope into the resolution process.
- Loading branch information
1 parent
3c5f3cb
commit 8656c86
Showing
16 changed files
with
770 additions
and
251 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.