This commit is contained in:
parent
9b51680af5
commit
c2b8db238e
24 changed files with 624 additions and 232 deletions
4
src/core/Compile.go
Normal file
4
src/core/Compile.go
Normal file
|
@ -0,0 +1,4 @@
|
|||
package core
|
||||
|
||||
// Compile turns a function into machine code.
|
||||
func (f *Function) Compile() {}
|
11
src/core/Environment.go
Normal file
11
src/core/Environment.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"git.urbach.dev/cli/q/src/fs"
|
||||
)
|
||||
|
||||
// Environment holds information about the entire build.
|
||||
type Environment struct {
|
||||
Functions map[string]*Function
|
||||
Files []*fs.File
|
||||
}
|
44
src/core/Function.go
Normal file
44
src/core/Function.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.urbach.dev/cli/q/src/fs"
|
||||
"git.urbach.dev/cli/q/src/token"
|
||||
)
|
||||
|
||||
// Function is the smallest unit of code.
|
||||
type Function struct {
|
||||
name string
|
||||
file *fs.File
|
||||
Input []*Parameter
|
||||
Output []*Parameter
|
||||
Body token.List
|
||||
}
|
||||
|
||||
// NewFunction creates a new function.
|
||||
func NewFunction(name string, file *fs.File) *Function {
|
||||
return &Function{
|
||||
name: name,
|
||||
file: file,
|
||||
}
|
||||
}
|
||||
|
||||
// IsExtern returns true if the function has no body.
|
||||
func (f *Function) IsExtern() bool {
|
||||
return f.Body == nil
|
||||
}
|
||||
|
||||
// ResolveTypes parses the input and output types.
|
||||
func (f *Function) ResolveTypes() error {
|
||||
for _, param := range f.Input {
|
||||
param.name = param.tokens[0].String(f.file.Bytes)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// String returns the package and function name.
|
||||
func (f *Function) String() string {
|
||||
return fmt.Sprintf("%s.%s", f.file.Package, f.name)
|
||||
}
|
28
src/core/Parameter.go
Normal file
28
src/core/Parameter.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"git.urbach.dev/cli/q/src/token"
|
||||
"git.urbach.dev/cli/q/src/types"
|
||||
)
|
||||
|
||||
// Parameter is an input or output parameter in a function.
|
||||
type Parameter struct {
|
||||
name string
|
||||
typ types.Type
|
||||
tokens token.List
|
||||
}
|
||||
|
||||
// NewParameter creates a new parameter with the given list of tokens.
|
||||
func NewParameter(tokens token.List) *Parameter {
|
||||
return &Parameter{tokens: tokens}
|
||||
}
|
||||
|
||||
// Name returns the name of the parameter.
|
||||
func (p *Parameter) Name() string {
|
||||
return p.name
|
||||
}
|
||||
|
||||
// Type returns the type of the parameter.
|
||||
func (p *Parameter) Type() types.Type {
|
||||
return p.typ
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue