Added types
This commit is contained in:
parent
7c5e0ae3a1
commit
baa2463b4b
19 changed files with 122 additions and 60 deletions
|
@ -1,7 +1,6 @@
|
|||
package scanner
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
|
@ -13,6 +12,7 @@ import (
|
|||
"git.akyoto.dev/cli/q/src/build/fs"
|
||||
"git.akyoto.dev/cli/q/src/build/scope"
|
||||
"git.akyoto.dev/cli/q/src/build/token"
|
||||
"git.akyoto.dev/cli/q/src/build/types"
|
||||
)
|
||||
|
||||
// scanFile scans a single file.
|
||||
|
@ -42,6 +42,8 @@ func (s *Scanner) scanFile(path string, pkg string) error {
|
|||
paramsStart = -1
|
||||
paramsEnd = -1
|
||||
bodyStart = -1
|
||||
typeStart = -1
|
||||
typeEnd = -1
|
||||
)
|
||||
|
||||
for {
|
||||
|
@ -156,9 +158,13 @@ func (s *Scanner) scanFile(path string, pkg string) error {
|
|||
|
||||
// Return type
|
||||
if i < len(tokens) && tokens[i].Kind == token.ReturnType {
|
||||
typeStart = i + 1
|
||||
|
||||
for i < len(tokens) && tokens[i].Kind != token.BlockStart {
|
||||
i++
|
||||
}
|
||||
|
||||
typeEnd = i
|
||||
}
|
||||
|
||||
// Function definition
|
||||
|
@ -221,6 +227,11 @@ func (s *Scanner) scanFile(path string, pkg string) error {
|
|||
name := tokens[nameStart].Text(contents)
|
||||
body := tokens[bodyStart:i]
|
||||
function := core.NewFunction(pkg, name, file, body)
|
||||
|
||||
if typeStart != -1 {
|
||||
function.ReturnTypes = append(function.ReturnTypes, types.New(tokens[typeStart:typeEnd]))
|
||||
}
|
||||
|
||||
parameters := tokens[paramsStart:paramsEnd]
|
||||
count := 0
|
||||
|
||||
|
@ -230,8 +241,7 @@ func (s *Scanner) scanFile(path string, pkg string) error {
|
|||
}
|
||||
|
||||
name := tokens[0].Text(contents)
|
||||
dataType := tokens[1].Text(contents)
|
||||
fmt.Println(dataType)
|
||||
dataType := types.New(tokens[1:])
|
||||
register := x64.CallRegisters[count]
|
||||
uses := token.Count(function.Body, contents, token.Identifier, name)
|
||||
|
||||
|
@ -241,10 +251,12 @@ func (s *Scanner) scanFile(path string, pkg string) error {
|
|||
|
||||
variable := &scope.Variable{
|
||||
Name: name,
|
||||
Type: dataType,
|
||||
Register: register,
|
||||
Alive: uses,
|
||||
}
|
||||
|
||||
function.Parameters = append(function.Parameters, variable)
|
||||
function.AddVariable(variable)
|
||||
count++
|
||||
return nil
|
||||
|
@ -258,6 +270,8 @@ func (s *Scanner) scanFile(path string, pkg string) error {
|
|||
nameStart = -1
|
||||
paramsStart = -1
|
||||
bodyStart = -1
|
||||
typeStart = -1
|
||||
typeEnd = -1
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue