Unify entity.Statement and entity.Expression

This commit is contained in:
Sasha Koshka 2024-02-08 02:22:19 -05:00
parent f04bf32ce2
commit 93c9f42aab
2 changed files with 1 additions and 34 deletions

View File

@ -5,17 +5,10 @@ import "git.tebibyte.media/sashakoshka/fspl/errors"
// Expression is any construct that can be evaluated.
type Expression interface {
Statement
Type () Type
expression ()
}
// Statement is any construct that can be placed inside of a block expression.
type Statement interface {
statement()
}
// Variable specifies a named variable. It can be assigned to a type matching
// the variable declaration's type. Since it contains inherent type information,
// it may be directly assigned to an interface. A variable is always a valid
@ -29,7 +22,6 @@ type Variable struct {
Declaration *Declaration
}
func (*Variable) expression(){}
func (*Variable) statement(){}
func (this *Variable) Type () Type { return this.Declaration.Type() }
func (this *Variable) String () string {
return this.Name
@ -46,7 +38,6 @@ type Declaration struct {
Ty Type
}
func (*Declaration) expression(){}
func (*Declaration) statement(){}
func (this *Declaration) Type () Type { return this.Ty }
func (this *Declaration) String () string {
return fmt.Sprint(this.Name, ":", this.Ty)
@ -69,7 +60,6 @@ type Call struct {
Function *Function
}
func (*Call) expression(){}
func (*Call) statement(){}
func (this *Call) Type () Type { return this.Function.Signature.Return }
func (this *Call) String () string {
out := ""
@ -102,7 +92,6 @@ type MethodCall struct {
Ty Type
}
func (*MethodCall) expression(){}
func (*MethodCall) statement(){}
func (this *MethodCall) Type () Type {
if this.Method != nil {
return this.Method.Signature.Return
@ -133,7 +122,6 @@ type Subscript struct {
Ty Type
}
func (*Subscript) expression(){}
func (*Subscript) statement(){}
func (this *Subscript) Type () Type { return this.Ty }
func (this *Subscript) String () string {
return fmt.Sprint("[.", this.Slice, " ", this.Offset, "]")
@ -151,7 +139,6 @@ type Slice struct {
End Expression
}
func (*Slice) expression(){}
func (*Slice) statement(){}
func (this *Slice) Type () Type { return this.Slice.Type() }
func (this *Slice) String () string {
out := fmt.Sprint("[\\", this.Slice, " ")
@ -176,7 +163,6 @@ type Length struct {
Ty Type
}
func (*Length) expression(){}
func (*Length) statement(){}
func (this *Length) Type () Type { return this.Ty }
func (this *Length) String () string {
return fmt.Sprint("[#", this.Slice, "]")
@ -196,7 +182,6 @@ type Dereference struct {
Ty Type
}
func (*Dereference) expression(){}
func (*Dereference) statement(){}
func (this *Dereference) Type () Type { return this.Ty }
func (this *Dereference) String () string {
return fmt.Sprint("[.", this.Pointer, "]")
@ -218,7 +203,6 @@ type Reference struct {
Ty Type
}
func (*Reference) expression(){}
func (*Reference) statement(){}
func (this *Reference) Type () Type { return this.Ty }
func (this *Reference) String () string {
return fmt.Sprint("[@", this.Value, "]")
@ -233,7 +217,6 @@ type ValueCast struct {
Value Expression
}
func (*ValueCast) expression(){}
func (*ValueCast) statement(){}
func (this *ValueCast) Type () Type { return this.Ty }
func (this *ValueCast) String () string {
return fmt.Sprint("[~ ", this.Ty, this.Value, "]")
@ -249,7 +232,6 @@ type BitCast struct {
Value Expression
}
func (*BitCast) expression(){}
func (*BitCast) statement(){}
func (this *BitCast) Type () Type { return this.Ty }
func (this *BitCast) String () string {
return fmt.Sprint("[~~ ", this.Ty, this.Value, "]")
@ -269,7 +251,6 @@ type Operation struct {
Ty Type
}
func (*Operation) expression(){}
func (*Operation) statement(){}
func (this *Operation) Type () Type { return this.Ty }
func (this *Operation) String () string {
out := fmt.Sprint("[", this.Operator)
@ -287,14 +268,13 @@ func (this *Operation) String () string {
type Block struct {
// Syntax
Position errors.Position
Steps []Statement
Steps []Expression
// Semantics
Ty Type
Scope
}
func (*Block) expression(){}
func (*Block) statement(){}
func (this *Block) Type () Type { return this.Ty }
func (this *Block) String () string {
out := "{"
@ -321,7 +301,6 @@ type MemberAccess struct {
Ty Type
}
func (*MemberAccess) expression(){}
func (*MemberAccess) statement(){}
func (this *MemberAccess) Type () Type { return this.Ty }
func (this *MemberAccess) String () string {
return fmt.Sprint(this.Source, ".", this.Member)
@ -343,7 +322,6 @@ type IfElse struct {
Ty Type
}
func (*IfElse) expression(){}
func (*IfElse) statement(){}
func (this *IfElse) Type () Type { return this.Ty }
func (this *IfElse) String () string {
out := fmt.Sprint("if ", this.Condition, " then ", this.True)
@ -369,7 +347,6 @@ type Loop struct {
Ty Type
}
func (*Loop) expression(){}
func (*Loop) statement(){}
func (this *Loop) Type () Type { return this.Ty }
func (this *Loop) String () string {
return fmt.Sprint("loop ", this.Body)
@ -386,7 +363,6 @@ type Break struct {
Loop *Loop
}
func (*Break) expression(){}
func (*Break) statement(){}
func (this *Break) Type () Type { return nil }
func (this *Break) String () string {
if this.Value == nil {
@ -409,7 +385,6 @@ type Return struct {
Declaration TopLevel
}
func (*Return) expression(){}
func (*Return) statement(){}
func (this *Return) Type () Type { return nil }
func (this *Return) String () string {
if this.Value == nil {
@ -429,7 +404,6 @@ type Assignment struct {
Value Expression
}
func (*Assignment) expression(){}
func (*Assignment) statement(){}
func (this *Assignment) String () string {
return fmt.Sprint(this.Location, "=", this.Value)
}

View File

@ -18,7 +18,6 @@ type LiteralInt struct {
Ty Type
}
func (*LiteralInt) expression(){}
func (*LiteralInt) statement(){}
func (this *LiteralInt) Type () Type { return this.Ty }
func (this *LiteralInt) String () string {
return fmt.Sprint(this.Value)
@ -37,7 +36,6 @@ type LiteralFloat struct {
Ty Type
}
func (*LiteralFloat) expression(){}
func (*LiteralFloat) statement(){}
func (this *LiteralFloat) Type () Type { return this.Ty }
func (this *LiteralFloat) String () string {
return fmt.Sprint(this.Value)
@ -69,7 +67,6 @@ type LiteralString struct {
Ty Type
}
func (*LiteralString) expression(){}
func (*LiteralString) statement(){}
func (this *LiteralString) Type () Type { return this.Ty }
func (this *LiteralString) String () string {
out := "'"
@ -101,7 +98,6 @@ type LiteralArray struct {
Ty Type
}
func (*LiteralArray) expression(){}
func (*LiteralArray) statement(){}
func (this *LiteralArray) Type () Type { return this.Ty }
func (this *LiteralArray) String () string {
out := "(*"
@ -129,7 +125,6 @@ type LiteralStruct struct {
MemberMap map[string] *Member
}
func (*LiteralStruct) expression(){}
func (*LiteralStruct) statement(){}
func (this *LiteralStruct) Type () Type { return this.Ty }
func (this *LiteralStruct) String () string {
out := "(."
@ -152,7 +147,6 @@ type LiteralBoolean struct {
Ty Type
}
func (*LiteralBoolean) expression(){}
func (*LiteralBoolean) statement(){}
func (this *LiteralBoolean) Type () Type { return this.Ty }
func (this *LiteralBoolean) String () string {
if this.Value {
@ -170,6 +164,5 @@ type LiteralNil struct {
Ty Type
}
func (*LiteralNil) expression(){}
func (*LiteralNil) statement(){}
func (this *LiteralNil) Type () Type { return this.Ty }
func (this *LiteralNil) String () string { return "nil" }