we in era3 boys; overhauled expression system, and variables are now in maps

This commit is contained in:
Neemek 2026-07-09 23:10:49 +02:00
parent bf29e6c3dd
commit 43e450c207
Signed by: neemek
GPG key ID: 84FFE4D7D40AB25E
14 changed files with 945 additions and 452 deletions

View file

@ -28,12 +28,14 @@ const (
BooleanNodeType
NilNodeType
ListNodeType
TupleNodeType
BinaryNodeType
UnaryNodeType
BlockNodeType
ConditionalNodeType
LoopNodeType
AssignNodeType
InvokeNodeType
CallNodeType
FunctionNodeType
ReturnNodeType
@ -65,7 +67,7 @@ func (n NodeType) String() string {
return "Loop"
case AssignNodeType:
return "Assign"
case CallNodeType:
case InvokeNodeType:
return "Call"
case FunctionNodeType:
return "Function"
@ -73,12 +75,16 @@ func (n NodeType) String() string {
return "Return"
case ListNodeType:
return "List"
case TupleNodeType:
return "Tuple"
case AccessNodeType:
return "Access"
case BreakpointNodeType:
return "Breakpoint"
case UnaryNodeType:
return "Unary"
case CallNodeType:
return "Call"
}
return "Invalid Node Type"
}
@ -192,6 +198,37 @@ func (n ListNode) Bounds() (Pos, Pos) {
return n.start, n.end
}
type TupleNode struct {
items []Node
start Pos
end Pos
}
func (n TupleNode) Type() NodeType {
return TupleNodeType
}
func (n TupleNode) String() string {
sb := strings.Builder{}
sb.WriteString("(")
for i, item := range n.items {
if i > 0 {
sb.WriteString(", ")
}
sb.WriteString(item.String())
}
sb.WriteString(")")
return sb.String()
}
func (n TupleNode) Bounds() (Pos, Pos) {
return n.start, n.end
}
type AccessNode struct {
source Node
property string
@ -281,14 +318,14 @@ func (n BinaryOperation) Symbol() string {
return "<"
case BinaryGreater:
return ">"
case BinaryAnd:
return "&&"
case BinaryOr:
return "||"
case BinaryLessEqual:
return "<="
case BinaryGreaterEqual:
return ">="
case BinaryAnd:
return "&&"
case BinaryOr:
return "||"
}
panic("unsupported binary operation to symbol conversion for " + n.String())
@ -479,7 +516,7 @@ func (n LoopNode) Bounds() (Pos, Pos) {
// AssignNode assignment
type AssignNode struct {
name string
dest Node
value Node
declare bool
@ -492,18 +529,39 @@ func (n AssignNode) Type() NodeType {
}
func (n AssignNode) String() string {
return fmt.Sprintf("set %s to %s", n.name, n.value)
return fmt.Sprintf("set %s to %s", n.dest, n.value)
}
func (n AssignNode) Bounds() (Pos, Pos) {
return n.start, n.end
}
// CallNode function call
type CallNode struct {
// InvokeNode function call
type InvokeNode struct {
source Node
args []Node
keep bool
start Pos
end Pos
}
func (n InvokeNode) Type() NodeType {
return InvokeNodeType
}
func (n InvokeNode) String() string {
return fmt.Sprintf("invoke %s with args (%s)", n.source.String(), n.args)
}
func (n InvokeNode) Bounds() (Pos, Pos) {
return n.start, n.end
}
// CallNode call a function of a value
type CallNode struct {
source Node
name Token
args []Node
start Pos
end Pos
@ -514,7 +572,7 @@ func (n CallNode) Type() NodeType {
}
func (n CallNode) String() string {
return fmt.Sprintf("call %s with args (%s)", n.source.String(), n.args)
return fmt.Sprintf("call %s on %s with args (%s)", n.name, n.source.String(), n.args)
}
func (n CallNode) Bounds() (Pos, Pos) {