Skip to content

Commit

Permalink
Added FunctionNode (no tests, no parser)
Browse files Browse the repository at this point in the history
  • Loading branch information
RealA10N committed Aug 2, 2024
1 parent 1893059 commit 03a804b
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
25 changes: 25 additions & 0 deletions parse/block.go
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
}
18 changes: 18 additions & 0 deletions parse/function.go
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)
}
29 changes: 29 additions & 0 deletions parse/signature.go
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
}

0 comments on commit 03a804b

Please sign in to comment.