Added more tests

This commit is contained in:
Eduard Urbach 2024-07-05 17:11:30 +02:00
parent d771708693
commit cc66b02bf8
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
7 changed files with 17 additions and 4 deletions

View File

@ -61,7 +61,7 @@ func toASTNode(tokens token.List) (Node, error) {
switch {
case IsVariableDefinition(expr):
if len(expr.Children) < 2 {
return nil, errors.New(errors.MissingAssignValue, nil, expr.Token.End())
return nil, errors.New(errors.MissingOperand, nil, expr.Token.End())
}
name := expr.Children[0].Token
@ -70,7 +70,7 @@ func toASTNode(tokens token.List) (Node, error) {
case IsAssignment(expr):
if len(expr.Children) < 2 {
return nil, errors.New(errors.MissingAssignValue, nil, expr.Token.End())
return nil, errors.New(errors.MissingOperand, nil, expr.Token.End())
}
name := expr.Children[0].Token

View File

@ -4,6 +4,7 @@ import (
"git.akyoto.dev/cli/q/src/build/asm"
"git.akyoto.dev/cli/q/src/build/ast"
"git.akyoto.dev/cli/q/src/build/cpu"
"git.akyoto.dev/cli/q/src/build/errors"
"git.akyoto.dev/cli/q/src/build/expression"
)
@ -23,6 +24,10 @@ func (f *Function) ExpressionToRegister(node *expression.Expression, register cp
return err
}
if len(node.Children) < 2 {
return errors.New(errors.MissingOperand, f.File, node.Token.End())
}
left := node.Children[0]
right := node.Children[1]
final := register

View File

@ -3,7 +3,7 @@ package errors
var (
InvalidStatement = &Base{"Invalid statement"}
InvalidExpression = &Base{"Invalid expression"}
MissingAssignValue = &Base{"Missing assignment value"}
MissingOperand = &Base{"Missing operand"}
MissingMainFunction = &Base{"Missing main function"}
NotImplemented = &Base{"Not implemented"}
)

View File

@ -0,0 +1,3 @@
main() {
2+3
}

View File

@ -0,0 +1,3 @@
main() {
syscall(2+)
}

View File

@ -19,17 +19,19 @@ var errs = []struct {
{"ExpectedFunctionParameters.q", errors.ExpectedFunctionParameters},
{"InvalidInstructionIdentifier.q", &errors.InvalidInstruction{Instruction: "abc"}},
{"InvalidInstructionNumber.q", &errors.InvalidInstruction{Instruction: "123"}},
{"InvalidInstructionExpression.q", &errors.InvalidInstruction{Instruction: "+"}},
{"InvalidExpression.q", errors.InvalidExpression},
{"InvalidOperator.q", &errors.InvalidOperator{Operator: "+++"}},
{"InvalidCharacter.q", &errors.InvalidCharacter{Character: "@"}},
{"InvalidCharacter2.q", &errors.InvalidCharacter{Character: "@"}},
{"InvalidCharacter3.q", &errors.InvalidCharacter{Character: "@"}},
{"MissingAssignValue.q", errors.MissingAssignValue},
{"MissingBlockEnd.q", errors.MissingBlockEnd},
{"MissingBlockStart.q", errors.MissingBlockStart},
{"MissingGroupEnd.q", errors.MissingGroupEnd},
{"MissingGroupStart.q", errors.MissingGroupStart},
{"MissingMainFunction.q", errors.MissingMainFunction},
{"MissingOperand.q", errors.MissingOperand},
{"MissingOperand2.q", errors.MissingOperand},
{"VariableAlreadyExists.q", &errors.VariableAlreadyExists{Name: "x"}},
{"UnknownIdentifier.q", &errors.UnknownIdentifier{Name: "x"}},
{"UnknownIdentifier2.q", &errors.UnknownIdentifier{Name: "x"}},