Improved file structure
This commit is contained in:
parent
b6400cd77e
commit
c0f399df7f
18 changed files with 106 additions and 378 deletions
|
@ -1,9 +1,9 @@
|
|||
package compiler
|
||||
|
||||
import (
|
||||
"git.akyoto.dev/cli/q/src/arch/x64"
|
||||
"git.akyoto.dev/cli/q/src/asm"
|
||||
"git.akyoto.dev/cli/q/src/linux"
|
||||
"git.akyoto.dev/cli/q/src/register"
|
||||
"git.akyoto.dev/cli/q/src/os/linux"
|
||||
)
|
||||
|
||||
// Finalize generates the final machine code.
|
||||
|
@ -14,8 +14,8 @@ func Finalize(functions map[string]*Function) ([]byte, []byte) {
|
|||
a.Merge(&f.Assembler)
|
||||
}
|
||||
|
||||
a.MoveRegisterNumber(register.Syscall0, linux.Exit)
|
||||
a.MoveRegisterNumber(register.Syscall1, 0)
|
||||
a.MoveRegisterNumber(x64.SyscallNumber, linux.Exit)
|
||||
a.MoveRegisterNumber(x64.SyscallArgs[0], 0)
|
||||
a.Syscall()
|
||||
|
||||
code, data := a.Finalize()
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package compiler
|
||||
|
||||
import (
|
||||
"git.akyoto.dev/cli/q/src/arch/x64"
|
||||
"git.akyoto.dev/cli/q/src/asm"
|
||||
"git.akyoto.dev/cli/q/src/linux"
|
||||
"git.akyoto.dev/cli/q/src/register"
|
||||
"git.akyoto.dev/cli/q/src/os/linux"
|
||||
"git.akyoto.dev/cli/q/src/token"
|
||||
)
|
||||
|
||||
|
@ -20,10 +20,10 @@ func (f *Function) Compile() {
|
|||
for i, t := range f.Body {
|
||||
if t.Kind == token.Identifier && t.String() == "print" {
|
||||
message := f.Body[i+2].Bytes
|
||||
f.Assembler.MoveRegisterNumber(register.Syscall0, linux.Write)
|
||||
f.Assembler.MoveRegisterNumber(register.Syscall1, 1)
|
||||
f.Assembler.MoveRegisterData(register.Syscall2, message)
|
||||
f.Assembler.MoveRegisterNumber(register.Syscall3, uint64(len(message)))
|
||||
f.Assembler.MoveRegisterNumber(x64.SyscallNumber, linux.Write)
|
||||
f.Assembler.MoveRegisterNumber(x64.SyscallArgs[0], 1)
|
||||
f.Assembler.MoveRegisterData(x64.SyscallArgs[1], message)
|
||||
f.Assembler.MoveRegisterNumber(x64.SyscallArgs[2], uint64(len(message)))
|
||||
f.Assembler.Syscall()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue