add type aliases, rework compiler, remove optimization
This commit is contained in:
parent
94b12f28ab
commit
d54249cffe
12 changed files with 869 additions and 1597 deletions
|
|
@ -16,7 +16,7 @@ type Node interface {
|
|||
Bounds() (Pos, Pos)
|
||||
}
|
||||
|
||||
type Boundary interface {
|
||||
type Bounded interface {
|
||||
Bounds() (Pos, Pos)
|
||||
}
|
||||
|
||||
|
|
@ -40,6 +40,8 @@ const (
|
|||
FunctionNodeType
|
||||
ReturnNodeType
|
||||
AccessNodeType
|
||||
AliasNodeType
|
||||
IndexNodeType
|
||||
BreakpointNodeType
|
||||
)
|
||||
|
||||
|
|
@ -68,7 +70,7 @@ func (n NodeType) String() string {
|
|||
case AssignNodeType:
|
||||
return "Assign"
|
||||
case InvokeNodeType:
|
||||
return "Call"
|
||||
return "Invoke"
|
||||
case FunctionNodeType:
|
||||
return "Function"
|
||||
case ReturnNodeType:
|
||||
|
|
@ -85,6 +87,10 @@ func (n NodeType) String() string {
|
|||
return "Unary"
|
||||
case CallNodeType:
|
||||
return "Call"
|
||||
case AliasNodeType:
|
||||
return "Alias"
|
||||
case IndexNodeType:
|
||||
return "Index"
|
||||
}
|
||||
return "Invalid Node Type"
|
||||
}
|
||||
|
|
@ -231,7 +237,7 @@ func (n TupleNode) Bounds() (Pos, Pos) {
|
|||
|
||||
type AccessNode struct {
|
||||
source Node
|
||||
property string
|
||||
property *Token
|
||||
|
||||
start Pos
|
||||
end Pos
|
||||
|
|
@ -242,7 +248,7 @@ func (n AccessNode) Type() NodeType {
|
|||
}
|
||||
|
||||
func (n AccessNode) String() string {
|
||||
return fmt.Sprintf("(%s from %s)", n.property, n.source)
|
||||
return fmt.Sprintf("(%s from %s)", n.property.Lexeme, n.source)
|
||||
}
|
||||
|
||||
func (n AccessNode) Bounds() (Pos, Pos) {
|
||||
|
|
@ -273,9 +279,9 @@ func (n BinaryOperation) String() string {
|
|||
return "less or equal"
|
||||
case BinaryGreaterEqual:
|
||||
return "greater or equal"
|
||||
case BinaryAnd:
|
||||
case BinaryBooleanAnd:
|
||||
return "and"
|
||||
case BinaryOr:
|
||||
case BinaryBooleanOr:
|
||||
return "or"
|
||||
}
|
||||
|
||||
|
|
@ -288,8 +294,8 @@ const (
|
|||
BinaryMultiplication
|
||||
BinaryDivision
|
||||
|
||||
BinaryAnd
|
||||
BinaryOr
|
||||
BinaryBooleanAnd
|
||||
BinaryBooleanOr
|
||||
|
||||
// Comparison
|
||||
BinaryEquality
|
||||
|
|
@ -322,9 +328,9 @@ func (n BinaryOperation) Symbol() string {
|
|||
return "<="
|
||||
case BinaryGreaterEqual:
|
||||
return ">="
|
||||
case BinaryAnd:
|
||||
case BinaryBooleanAnd:
|
||||
return "&&"
|
||||
case BinaryOr:
|
||||
case BinaryBooleanOr:
|
||||
return "||"
|
||||
}
|
||||
|
||||
|
|
@ -337,8 +343,9 @@ type BinaryNode struct {
|
|||
Left Node
|
||||
Right Node
|
||||
|
||||
start Pos
|
||||
end Pos
|
||||
operator *Token
|
||||
start Pos
|
||||
end Pos
|
||||
}
|
||||
|
||||
func (n BinaryNode) Type() NodeType {
|
||||
|
|
@ -386,8 +393,9 @@ type UnaryNode struct {
|
|||
UnaryOperation
|
||||
value Node
|
||||
|
||||
start Pos
|
||||
end Pos
|
||||
operator *Token
|
||||
start Pos
|
||||
end Pos
|
||||
}
|
||||
|
||||
func (n UnaryNode) Type() NodeType {
|
||||
|
|
@ -404,7 +412,7 @@ func (n UnaryNode) Bounds() (Pos, Pos) {
|
|||
|
||||
// BooleanNode boolean value
|
||||
type BooleanNode struct {
|
||||
value bool
|
||||
Boolean bool
|
||||
|
||||
start Pos
|
||||
end Pos
|
||||
|
|
@ -415,7 +423,7 @@ func (n BooleanNode) Type() NodeType {
|
|||
}
|
||||
|
||||
func (n BooleanNode) String() string {
|
||||
return strconv.FormatBool(n.value)
|
||||
return strconv.FormatBool(n.Boolean)
|
||||
}
|
||||
|
||||
func (n BooleanNode) Bounds() (Pos, Pos) {
|
||||
|
|
@ -560,7 +568,7 @@ func (n InvokeNode) Bounds() (Pos, Pos) {
|
|||
// CallNode call a function of a value
|
||||
type CallNode struct {
|
||||
source Node
|
||||
name Token
|
||||
name *Token
|
||||
args []Node
|
||||
|
||||
start Pos
|
||||
|
|
@ -607,6 +615,18 @@ func (n FunctionNode) Bounds() (Pos, Pos) {
|
|||
return n.start, n.end
|
||||
}
|
||||
|
||||
func (n FunctionNode) Signature() *FunctionSignature {
|
||||
args := make([]TypeSignature, len(n.parameters))
|
||||
for i, p := range n.parameters {
|
||||
args[i] = p.Signature
|
||||
}
|
||||
|
||||
return &FunctionSignature{
|
||||
args,
|
||||
n.yield,
|
||||
}
|
||||
}
|
||||
|
||||
// ReturnNode return a value out of this context
|
||||
type ReturnNode struct {
|
||||
value Node
|
||||
|
|
@ -627,6 +647,46 @@ func (n ReturnNode) Bounds() (Pos, Pos) {
|
|||
return n.start, n.end
|
||||
}
|
||||
|
||||
type AliasNode struct {
|
||||
name *Token
|
||||
signature TypeSignature
|
||||
|
||||
start Pos
|
||||
end Pos
|
||||
}
|
||||
|
||||
func (n AliasNode) Type() NodeType {
|
||||
return AliasNodeType
|
||||
}
|
||||
|
||||
func (n AliasNode) String() string {
|
||||
return fmt.Sprintf("alias %s to be %s", n.name, n.signature)
|
||||
}
|
||||
|
||||
func (n AliasNode) Bounds() (Pos, Pos) {
|
||||
return n.start, n.end
|
||||
}
|
||||
|
||||
type IndexNode struct {
|
||||
source Node
|
||||
index Node
|
||||
|
||||
start Pos
|
||||
end Pos
|
||||
}
|
||||
|
||||
func (n IndexNode) Type() NodeType {
|
||||
return IndexNodeType
|
||||
}
|
||||
|
||||
func (n IndexNode) String() string {
|
||||
return fmt.Sprintf("index %s of %s", n.source.String(), n.index)
|
||||
}
|
||||
|
||||
func (n IndexNode) Bounds() (Pos, Pos) {
|
||||
return n.start, n.end
|
||||
}
|
||||
|
||||
type BreakpointNode struct {
|
||||
start Pos
|
||||
end Pos
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue