Removed dead code

This commit is contained in:
Eduard Urbach 2025-03-04 13:35:55 +01:00
parent df6f7d5a57
commit e5f0123eea
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
14 changed files with 54 additions and 63 deletions

View File

@ -1,6 +1,15 @@
import core
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 {
vm 0x100
fs 0x200
@ -9,13 +18,4 @@ const clone {
parent 0x8000
thread 0x10000
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)
}

View File

@ -1,7 +1,7 @@
extern kernel32 {
CreateThread(attributes int, stackSize int, address *any, parameter int) -> int
}
create(func *any) -> int {
return kernel32.CreateThread(0, 4096, func, 0)
}
extern kernel32 {
CreateThread(attributes int, stackSize int, address *any, parameter int) -> int
}

View File

@ -7,12 +7,11 @@ import (
"git.urbach.dev/cli/q/src/asm"
"git.urbach.dev/cli/q/src/cpu"
"git.urbach.dev/cli/q/src/expression"
"git.urbach.dev/cli/q/src/types"
"git.urbach.dev/cli/q/src/x86"
)
// 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)
var pushedRegisters []cpu.Register
@ -50,5 +49,5 @@ func (f *Function) CallExtern(fn *Function, parameters []*expression.Expression)
f.Register(asm.POP, register)
}
return fn.OutputTypes, nil
return fn.Output, nil
}

View File

@ -13,20 +13,35 @@ import (
// 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.
// 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 {
name := root.Children[0].Token.Text(f.File.Bytes)
switch name {
case "len":
return _len.OutputTypes, f.CompileLen(root)
case "syscall":
return nil, f.CompileSyscall(root)
case "len":
output := []*Parameter{{
name: "length",
typ: types.AnyInt,
}}
return output, f.CompileLen(root)
case "new":
typ, err := f.CompileNew(root)
return []types.Type{typ}, err
output := []*Parameter{{
name: "address",
typ: typ,
}}
return output, err
case "delete":
return nil, f.CompileDelete(root)
case "store":
return nil, f.CompileMemoryStore(root)
}
@ -62,7 +77,7 @@ func (f *Function) CompileCall(root *expression.Expression) ([]types.Type, error
f.BeforeCall()
f.Label(asm.CALL, value.Label)
f.AfterCall(registers)
return fn.OutputTypes, nil
return fn.Output, nil
case *eval.Register:
err := f.ExpressionsToRegisters(parameters, registers, nil, true)

View File

@ -11,8 +11,6 @@ import (
"git.urbach.dev/cli/q/src/types"
)
var _len = Function{OutputTypes: []types.Type{types.AnyInt}}
// CompileLen returns the length of a slice.
func (f *Function) CompileLen(root *expression.Expression) error {
value, err := f.Evaluate(root.Children[1])

View File

@ -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 {
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]}
if len(typ) > 0 {
value.Typ = typ[0]
if len(output) > 0 {
value.Typ = output[0].typ
}
return value, nil

View File

@ -2,6 +2,7 @@ package core
import (
"encoding/binary"
"fmt"
"git.urbach.dev/cli/q/src/errors"
"git.urbach.dev/cli/q/src/eval"
@ -33,14 +34,17 @@ func (f *Function) EvaluateToken(t token.Token) (eval.Value, error) {
return value, nil
}
variable, function := f.Identifier(name)
variable := f.VariableByName(name)
if variable != nil {
f.UseVariable(variable)
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)
value := &eval.Label{

View File

@ -5,10 +5,9 @@ import (
"git.urbach.dev/cli/q/src/fs"
"git.urbach.dev/cli/q/src/register"
"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 {
register.Machine
Package string
@ -19,7 +18,6 @@ type Function struct {
Body token.List
Input []*Parameter
Output []*Parameter
OutputTypes []types.Type
Dependencies []*Function
DLLs dll.List
Err error

View File

@ -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
}

View File

@ -8,7 +8,7 @@ import (
// MultiDefine defines multiple variables at once.
func (f *Function) MultiDefine(left *expression.Expression, right *expression.Expression) error {
count := 0
types, err := f.CompileCall(right)
output, err := f.CompileCall(right)
if err != nil {
return err
@ -21,8 +21,8 @@ func (f *Function) MultiDefine(left *expression.Expression, right *expression.Ex
return err
}
if count < len(types) {
variable.Value.Typ = types[count]
if count < len(output) {
variable.Value.Typ = output[count].typ
}
f.RegisterRegister(asm.MOVE, variable.Value.Register, f.CPU.Output[count])

View File

@ -5,20 +5,24 @@ import (
"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
}

View File

@ -47,8 +47,6 @@ func (f *Function) ResolveTypes() error {
if param.typ == nil {
return errors.New(&errors.UnknownType{Name: typeName}, f.File, param.tokens[0].Position)
}
f.OutputTypes = append(f.OutputTypes, param.typ)
}
return nil

View File

@ -1 +0,0 @@
package core

View File

@ -14,7 +14,8 @@ func (f *Function) UsesRegister(expr *expression.Expression, register cpu.Regist
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 {
return false