Implemented return keyword

This commit is contained in:
Eduard Urbach 2024-06-14 10:46:45 +02:00
parent f13f7c2800
commit f04e9d7a60
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
4 changed files with 22 additions and 0 deletions

View File

@ -34,6 +34,13 @@ func (f *Function) Compile() {
continue continue
} }
if line[0].Kind == token.Keyword {
switch line[0].Text() {
case "return":
f.Assembler.Return()
}
}
if line[0].Kind == token.Identifier && line[0].Text() == "syscall" { if line[0].Kind == token.Identifier && line[0].Text() == "syscall" {
paramTokens := line[2 : len(line)-1] paramTokens := line[2 : len(line)-1]
start := 0 start := 0

View File

@ -38,8 +38,14 @@ func (a *Assembler) Finalize() ([]byte, []byte) {
}) })
} }
case RETURN:
code = x64.Return(code)
case SYSCALL: case SYSCALL:
code = x64.Syscall(code) code = x64.Syscall(code)
default:
panic("Unknown mnemonic: " + x.Mnemonic.String())
} }
} }

View File

@ -26,6 +26,11 @@ func (a *Assembler) MoveRegisterAddress(reg cpu.Register, address Address) {
}) })
} }
// Return returns back to the caller.
func (a *Assembler) Return() {
a.Instructions = append(a.Instructions, Instruction{Mnemonic: RETURN})
}
// Syscall executes a kernel function. // Syscall executes a kernel function.
func (a *Assembler) Syscall() { func (a *Assembler) Syscall() {
a.Instructions = append(a.Instructions, Instruction{Mnemonic: SYSCALL}) a.Instructions = append(a.Instructions, Instruction{Mnemonic: SYSCALL})

View File

@ -5,6 +5,7 @@ type Mnemonic uint8
const ( const (
NONE Mnemonic = iota NONE Mnemonic = iota
MOVE MOVE
RETURN
SYSCALL SYSCALL
) )
@ -14,6 +15,9 @@ func (m Mnemonic) String() string {
case MOVE: case MOVE:
return "move" return "move"
case RETURN:
return "return"
case SYSCALL: case SYSCALL:
return "syscall" return "syscall"
} }