Implemented struct pointer types
This commit is contained in:
@ -4,10 +4,7 @@ import (
|
||||
"git.akyoto.dev/cli/q/src/core"
|
||||
"git.akyoto.dev/cli/q/src/errors"
|
||||
"git.akyoto.dev/cli/q/src/fs"
|
||||
"git.akyoto.dev/cli/q/src/scope"
|
||||
"git.akyoto.dev/cli/q/src/token"
|
||||
"git.akyoto.dev/cli/q/src/types"
|
||||
"git.akyoto.dev/cli/q/src/x64"
|
||||
)
|
||||
|
||||
// scanFunction scans a function.
|
||||
@ -157,11 +154,19 @@ func (s *Scanner) scanFunction(file *fs.File, tokens token.List, i int) (int, er
|
||||
typeEnd--
|
||||
}
|
||||
|
||||
function.ReturnTypes = types.ParseList(tokens[typeStart:typeEnd], file.Bytes)
|
||||
outputTokens := tokens[typeStart:typeEnd]
|
||||
|
||||
err := outputTokens.Split(func(tokens token.List) error {
|
||||
function.Output = append(function.Output, core.NewOutput(tokens))
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return i, err
|
||||
}
|
||||
}
|
||||
|
||||
parameters := tokens[paramsStart:paramsEnd]
|
||||
count := 0
|
||||
|
||||
err := parameters.Split(func(tokens token.List) error {
|
||||
if len(tokens) == 0 {
|
||||
@ -172,25 +177,7 @@ func (s *Scanner) scanFunction(file *fs.File, tokens token.List, i int) (int, er
|
||||
return errors.New(errors.MissingType, file, tokens[0].End())
|
||||
}
|
||||
|
||||
name := tokens[0].Text(file.Bytes)
|
||||
dataType := types.Parse(tokens[1:].Text(file.Bytes))
|
||||
register := x64.InputRegisters[count]
|
||||
uses := token.Count(function.Body, file.Bytes, token.Identifier, name)
|
||||
|
||||
if uses == 0 && name != "_" {
|
||||
return errors.New(&errors.UnusedVariable{Name: name}, file, tokens[0].Position)
|
||||
}
|
||||
|
||||
variable := &scope.Variable{
|
||||
Name: name,
|
||||
Type: dataType,
|
||||
Register: register,
|
||||
Alive: uses,
|
||||
}
|
||||
|
||||
function.Parameters = append(function.Parameters, variable)
|
||||
function.AddVariable(variable)
|
||||
count++
|
||||
function.Input = append(function.Input, core.NewInput(tokens))
|
||||
return nil
|
||||
})
|
||||
|
||||
|
@ -33,7 +33,12 @@ func (s *Scanner) scanStruct(file *fs.File, tokens token.List, i int) (int, erro
|
||||
fieldName := tokens[i].Text(file.Bytes)
|
||||
i++
|
||||
fieldTypeName := tokens[i].Text(file.Bytes)
|
||||
fieldType := types.Parse(fieldTypeName)
|
||||
fieldType := types.Int
|
||||
|
||||
if fieldTypeName != "Int" {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
i++
|
||||
|
||||
structure.AddField(&types.Field{
|
||||
|
Reference in New Issue
Block a user