Implemented return keyword
This commit is contained in:
parent
f13f7c2800
commit
f04e9d7a60
@ -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
|
||||||
|
@ -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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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})
|
||||||
|
@ -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"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user