Removed dead code
This commit is contained in:
parent
df6f7d5a57
commit
e5f0123eea
@ -1,6 +1,15 @@
|
|||||||
import core
|
import core
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
create(func *any) -> int {
|
||||||
|
stack := sys.mmap(0, 4096, 0x1|0x2, 0x02|0x20|0x100)
|
||||||
|
stack += 4096 - 8
|
||||||
|
store(stack, 8, core.exit)
|
||||||
|
stack -= 8
|
||||||
|
store(stack, 8, func)
|
||||||
|
return sys.clone(clone.vm|clone.fs|clone.files|clone.sighand|clone.parent|clone.thread|clone.io, stack, 0, 0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
const clone {
|
const clone {
|
||||||
vm 0x100
|
vm 0x100
|
||||||
fs 0x200
|
fs 0x200
|
||||||
@ -9,13 +18,4 @@ const clone {
|
|||||||
parent 0x8000
|
parent 0x8000
|
||||||
thread 0x10000
|
thread 0x10000
|
||||||
io 0x80000000
|
io 0x80000000
|
||||||
}
|
|
||||||
|
|
||||||
create(func *any) -> int {
|
|
||||||
stack := sys.mmap(0, 4096, 0x1|0x2, 0x02|0x20|0x100)
|
|
||||||
stack += 4096 - 8
|
|
||||||
store(stack, 8, core.exit)
|
|
||||||
stack -= 8
|
|
||||||
store(stack, 8, func)
|
|
||||||
return sys.clone(clone.vm|clone.fs|clone.files|clone.sighand|clone.parent|clone.thread|clone.io, stack, 0, 0, 0)
|
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
extern kernel32 {
|
|
||||||
CreateThread(attributes int, stackSize int, address *any, parameter int) -> int
|
|
||||||
}
|
|
||||||
|
|
||||||
create(func *any) -> int {
|
create(func *any) -> int {
|
||||||
return kernel32.CreateThread(0, 4096, func, 0)
|
return kernel32.CreateThread(0, 4096, func, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
extern kernel32 {
|
||||||
|
CreateThread(attributes int, stackSize int, address *any, parameter int) -> int
|
||||||
}
|
}
|
@ -7,12 +7,11 @@ import (
|
|||||||
"git.urbach.dev/cli/q/src/asm"
|
"git.urbach.dev/cli/q/src/asm"
|
||||||
"git.urbach.dev/cli/q/src/cpu"
|
"git.urbach.dev/cli/q/src/cpu"
|
||||||
"git.urbach.dev/cli/q/src/expression"
|
"git.urbach.dev/cli/q/src/expression"
|
||||||
"git.urbach.dev/cli/q/src/types"
|
|
||||||
"git.urbach.dev/cli/q/src/x86"
|
"git.urbach.dev/cli/q/src/x86"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CallExtern calls an external function.
|
// CallExtern calls an external function.
|
||||||
func (f *Function) CallExtern(fn *Function, parameters []*expression.Expression) ([]types.Type, error) {
|
func (f *Function) CallExtern(fn *Function, parameters []*expression.Expression) ([]*Parameter, error) {
|
||||||
f.DLLs = f.DLLs.Append(fn.Package, fn.Name)
|
f.DLLs = f.DLLs.Append(fn.Package, fn.Name)
|
||||||
|
|
||||||
var pushedRegisters []cpu.Register
|
var pushedRegisters []cpu.Register
|
||||||
@ -50,5 +49,5 @@ func (f *Function) CallExtern(fn *Function, parameters []*expression.Expression)
|
|||||||
f.Register(asm.POP, register)
|
f.Register(asm.POP, register)
|
||||||
}
|
}
|
||||||
|
|
||||||
return fn.OutputTypes, nil
|
return fn.Output, nil
|
||||||
}
|
}
|
||||||
|
@ -13,20 +13,35 @@ import (
|
|||||||
// All call registers must hold the correct parameter values before the function invocation.
|
// All call registers must hold the correct parameter values before the function invocation.
|
||||||
// Registers that are in use must be saved if they are modified by the function.
|
// Registers that are in use must be saved if they are modified by the function.
|
||||||
// After the function call, they must be restored in reverse order.
|
// After the function call, they must be restored in reverse order.
|
||||||
func (f *Function) CompileCall(root *expression.Expression) ([]types.Type, error) {
|
func (f *Function) CompileCall(root *expression.Expression) ([]*Parameter, error) {
|
||||||
if root.Children[0].Token.Kind == token.Identifier {
|
if root.Children[0].Token.Kind == token.Identifier {
|
||||||
name := root.Children[0].Token.Text(f.File.Bytes)
|
name := root.Children[0].Token.Text(f.File.Bytes)
|
||||||
|
|
||||||
switch name {
|
switch name {
|
||||||
case "len":
|
|
||||||
return _len.OutputTypes, f.CompileLen(root)
|
|
||||||
case "syscall":
|
case "syscall":
|
||||||
return nil, f.CompileSyscall(root)
|
return nil, f.CompileSyscall(root)
|
||||||
|
|
||||||
|
case "len":
|
||||||
|
output := []*Parameter{{
|
||||||
|
name: "length",
|
||||||
|
typ: types.AnyInt,
|
||||||
|
}}
|
||||||
|
|
||||||
|
return output, f.CompileLen(root)
|
||||||
|
|
||||||
case "new":
|
case "new":
|
||||||
typ, err := f.CompileNew(root)
|
typ, err := f.CompileNew(root)
|
||||||
return []types.Type{typ}, err
|
|
||||||
|
output := []*Parameter{{
|
||||||
|
name: "address",
|
||||||
|
typ: typ,
|
||||||
|
}}
|
||||||
|
|
||||||
|
return output, err
|
||||||
|
|
||||||
case "delete":
|
case "delete":
|
||||||
return nil, f.CompileDelete(root)
|
return nil, f.CompileDelete(root)
|
||||||
|
|
||||||
case "store":
|
case "store":
|
||||||
return nil, f.CompileMemoryStore(root)
|
return nil, f.CompileMemoryStore(root)
|
||||||
}
|
}
|
||||||
@ -62,7 +77,7 @@ func (f *Function) CompileCall(root *expression.Expression) ([]types.Type, error
|
|||||||
f.BeforeCall()
|
f.BeforeCall()
|
||||||
f.Label(asm.CALL, value.Label)
|
f.Label(asm.CALL, value.Label)
|
||||||
f.AfterCall(registers)
|
f.AfterCall(registers)
|
||||||
return fn.OutputTypes, nil
|
return fn.Output, nil
|
||||||
|
|
||||||
case *eval.Register:
|
case *eval.Register:
|
||||||
err := f.ExpressionsToRegisters(parameters, registers, nil, true)
|
err := f.ExpressionsToRegisters(parameters, registers, nil, true)
|
||||||
|
@ -11,8 +11,6 @@ import (
|
|||||||
"git.urbach.dev/cli/q/src/types"
|
"git.urbach.dev/cli/q/src/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _len = Function{OutputTypes: []types.Type{types.AnyInt}}
|
|
||||||
|
|
||||||
// CompileLen returns the length of a slice.
|
// CompileLen returns the length of a slice.
|
||||||
func (f *Function) CompileLen(root *expression.Expression) error {
|
func (f *Function) CompileLen(root *expression.Expression) error {
|
||||||
value, err := f.Evaluate(root.Children[1])
|
value, err := f.Evaluate(root.Children[1])
|
||||||
|
@ -51,7 +51,7 @@ func (f *Function) EvaluateCall(expr *expression.Expression) (eval.Value, error)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typ, err := f.CompileCall(expr)
|
output, err := f.CompileCall(expr)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -59,8 +59,8 @@ func (f *Function) EvaluateCall(expr *expression.Expression) (eval.Value, error)
|
|||||||
|
|
||||||
value := &eval.Register{Register: f.CPU.Output[0]}
|
value := &eval.Register{Register: f.CPU.Output[0]}
|
||||||
|
|
||||||
if len(typ) > 0 {
|
if len(output) > 0 {
|
||||||
value.Typ = typ[0]
|
value.Typ = output[0].typ
|
||||||
}
|
}
|
||||||
|
|
||||||
return value, nil
|
return value, nil
|
||||||
|
@ -2,6 +2,7 @@ package core
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"git.urbach.dev/cli/q/src/errors"
|
"git.urbach.dev/cli/q/src/errors"
|
||||||
"git.urbach.dev/cli/q/src/eval"
|
"git.urbach.dev/cli/q/src/eval"
|
||||||
@ -33,14 +34,17 @@ func (f *Function) EvaluateToken(t token.Token) (eval.Value, error) {
|
|||||||
return value, nil
|
return value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
variable, function := f.Identifier(name)
|
variable := f.VariableByName(name)
|
||||||
|
|
||||||
if variable != nil {
|
if variable != nil {
|
||||||
f.UseVariable(variable)
|
f.UseVariable(variable)
|
||||||
return &variable.Value, nil
|
return &variable.Value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if function != nil {
|
uniqueName := fmt.Sprintf("%s.%s", f.Package, name)
|
||||||
|
function, exists := f.All.Functions[uniqueName]
|
||||||
|
|
||||||
|
if exists {
|
||||||
f.Dependencies = append(f.Dependencies, function)
|
f.Dependencies = append(f.Dependencies, function)
|
||||||
|
|
||||||
value := &eval.Label{
|
value := &eval.Label{
|
||||||
|
@ -5,10 +5,9 @@ import (
|
|||||||
"git.urbach.dev/cli/q/src/fs"
|
"git.urbach.dev/cli/q/src/fs"
|
||||||
"git.urbach.dev/cli/q/src/register"
|
"git.urbach.dev/cli/q/src/register"
|
||||||
"git.urbach.dev/cli/q/src/token"
|
"git.urbach.dev/cli/q/src/token"
|
||||||
"git.urbach.dev/cli/q/src/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Function represents the smallest unit of code.
|
// Function is the smallest unit of code.
|
||||||
type Function struct {
|
type Function struct {
|
||||||
register.Machine
|
register.Machine
|
||||||
Package string
|
Package string
|
||||||
@ -19,7 +18,6 @@ type Function struct {
|
|||||||
Body token.List
|
Body token.List
|
||||||
Input []*Parameter
|
Input []*Parameter
|
||||||
Output []*Parameter
|
Output []*Parameter
|
||||||
OutputTypes []types.Type
|
|
||||||
Dependencies []*Function
|
Dependencies []*Function
|
||||||
DLLs dll.List
|
DLLs dll.List
|
||||||
Err error
|
Err error
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
package core
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"git.urbach.dev/cli/q/src/scope"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Identifier looks up an identifier which can be a variable or a function.
|
|
||||||
func (f *Function) Identifier(name string) (*scope.Variable, *Function) {
|
|
||||||
variable := f.VariableByName(name)
|
|
||||||
|
|
||||||
if variable != nil {
|
|
||||||
return variable, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
uniqueName := fmt.Sprintf("%s.%s", f.Package, name)
|
|
||||||
function, exists := f.All.Functions[uniqueName]
|
|
||||||
|
|
||||||
if exists {
|
|
||||||
return nil, function
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
@ -8,7 +8,7 @@ import (
|
|||||||
// MultiDefine defines multiple variables at once.
|
// MultiDefine defines multiple variables at once.
|
||||||
func (f *Function) MultiDefine(left *expression.Expression, right *expression.Expression) error {
|
func (f *Function) MultiDefine(left *expression.Expression, right *expression.Expression) error {
|
||||||
count := 0
|
count := 0
|
||||||
types, err := f.CompileCall(right)
|
output, err := f.CompileCall(right)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -21,8 +21,8 @@ func (f *Function) MultiDefine(left *expression.Expression, right *expression.Ex
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if count < len(types) {
|
if count < len(output) {
|
||||||
variable.Value.Typ = types[count]
|
variable.Value.Typ = output[count].typ
|
||||||
}
|
}
|
||||||
|
|
||||||
f.RegisterRegister(asm.MOVE, variable.Value.Register, f.CPU.Output[count])
|
f.RegisterRegister(asm.MOVE, variable.Value.Register, f.CPU.Output[count])
|
||||||
|
@ -5,20 +5,24 @@ import (
|
|||||||
"git.urbach.dev/cli/q/src/types"
|
"git.urbach.dev/cli/q/src/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Parameter is an input or output parameter in a function.
|
||||||
type Parameter struct {
|
type Parameter struct {
|
||||||
name string
|
name string
|
||||||
typ types.Type
|
typ types.Type
|
||||||
tokens token.List
|
tokens token.List
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewParameter creates a new parameter with the given list of tokens.
|
||||||
func NewParameter(tokens token.List) *Parameter {
|
func NewParameter(tokens token.List) *Parameter {
|
||||||
return &Parameter{tokens: tokens}
|
return &Parameter{tokens: tokens}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Name returns the name of the parameter.
|
||||||
func (p *Parameter) Name() string {
|
func (p *Parameter) Name() string {
|
||||||
return p.name
|
return p.name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Type returns the type of the parameter.
|
||||||
func (p *Parameter) Type() types.Type {
|
func (p *Parameter) Type() types.Type {
|
||||||
return p.typ
|
return p.typ
|
||||||
}
|
}
|
||||||
|
@ -47,8 +47,6 @@ func (f *Function) ResolveTypes() error {
|
|||||||
if param.typ == nil {
|
if param.typ == nil {
|
||||||
return errors.New(&errors.UnknownType{Name: typeName}, f.File, param.tokens[0].Position)
|
return errors.New(&errors.UnknownType{Name: typeName}, f.File, param.tokens[0].Position)
|
||||||
}
|
}
|
||||||
|
|
||||||
f.OutputTypes = append(f.OutputTypes, param.typ)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -1 +0,0 @@
|
|||||||
package core
|
|
@ -14,7 +14,8 @@ func (f *Function) UsesRegister(expr *expression.Expression, register cpu.Regist
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
variable := f.VariableByName(expr.Token.Text(f.File.Bytes))
|
name := expr.Token.Text(f.File.Bytes)
|
||||||
|
variable := f.VariableByName(name)
|
||||||
|
|
||||||
if variable == nil || variable.Value.Register != register {
|
if variable == nil || variable.Value.Register != register {
|
||||||
return false
|
return false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user