Implemented return keyword
This commit is contained in:
parent
f13f7c2800
commit
f04e9d7a60
@ -34,6 +34,13 @@ func (f *Function) Compile() {
|
||||
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" {
|
||||
paramTokens := line[2 : len(line)-1]
|
||||
start := 0
|
||||
|
@ -38,8 +38,14 @@ func (a *Assembler) Finalize() ([]byte, []byte) {
|
||||
})
|
||||
}
|
||||
|
||||
case RETURN:
|
||||
code = x64.Return(code)
|
||||
|
||||
case SYSCALL:
|
||||
code = x64.Syscall(code)
|
||||
|
||||
default:
|
||||
panic("Unknown mnemonic: " + x.Mnemonic.String())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
func (a *Assembler) Syscall() {
|
||||
a.Instructions = append(a.Instructions, Instruction{Mnemonic: SYSCALL})
|
||||
|
@ -5,6 +5,7 @@ type Mnemonic uint8
|
||||
const (
|
||||
NONE Mnemonic = iota
|
||||
MOVE
|
||||
RETURN
|
||||
SYSCALL
|
||||
)
|
||||
|
||||
@ -14,6 +15,9 @@ func (m Mnemonic) String() string {
|
||||
case MOVE:
|
||||
return "move"
|
||||
|
||||
case RETURN:
|
||||
return "return"
|
||||
|
||||
case SYSCALL:
|
||||
return "syscall"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user