-
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.
Added FunctionNode (no tests, no parser)
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package parse | ||
|
||
import ( | ||
"usm/source" | ||
) | ||
|
||
// TODO: add label support | ||
|
||
type BlockNode struct { | ||
source.UnmanagedSourceView | ||
Instructions []InstructionNode | ||
} | ||
|
||
func (n BlockNode) View() source.UnmanagedSourceView { | ||
return n.UnmanagedSourceView | ||
} | ||
|
||
func (n BlockNode) String(ctx source.SourceContext) (s string) { | ||
s = "{\n" | ||
for _, inst := range n.Instructions { | ||
s += "\t" + inst.String(ctx) + "\n" | ||
} | ||
s += "}\n" | ||
return s | ||
} |
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,18 @@ | ||
package parse | ||
|
||
import ( | ||
"usm/source" | ||
) | ||
|
||
type FunctionNode struct { | ||
Signature SignatureNode | ||
Block BlockNode | ||
} | ||
|
||
func (n FunctionNode) View() source.UnmanagedSourceView { | ||
return n.Signature.View().Merge(n.Block.View()) | ||
} | ||
|
||
func (n FunctionNode) String(ctx source.SourceContext) string { | ||
return n.Signature.String(ctx) + " " + n.Block.String(ctx) | ||
} |
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,29 @@ | ||
package parse | ||
|
||
import "usm/source" | ||
|
||
type SignatureNode struct { | ||
source.UnmanagedSourceView | ||
Identifier source.UnmanagedSourceView | ||
Arguments []CalleeArgumentNode | ||
Returns []TypeNode | ||
} | ||
|
||
func (n SignatureNode) View() source.UnmanagedSourceView { | ||
return n.UnmanagedSourceView | ||
} | ||
|
||
func (n SignatureNode) String(ctx source.SourceContext) string { | ||
s := "def " | ||
for _, ret := range n.Returns { | ||
s += ret.String(ctx) + " " | ||
} | ||
|
||
s += string(n.Identifier.Raw(ctx)) | ||
|
||
for _, arg := range n.Arguments { | ||
s += " " + arg.String(ctx) | ||
} | ||
|
||
return s | ||
} |