Added token tests

This commit is contained in:
Eduard Urbach 2024-06-06 21:35:14 +02:00
parent c0f399df7f
commit 18993e0855
Signed by: eduard
GPG key ID: 49226B848C78F6C8
7 changed files with 241 additions and 75 deletions

View file

@ -18,7 +18,7 @@ type Function struct {
// Compile turns a function into machine code.
func (f *Function) Compile() {
for i, t := range f.Body {
if t.Kind == token.Identifier && t.String() == "print" {
if t.Kind == token.Identifier && t.Text() == "print" {
message := f.Body[i+2].Bytes
f.Assembler.MoveRegisterNumber(x64.SyscallNumber, linux.Write)
f.Assembler.MoveRegisterNumber(x64.SyscallArgs[0], 1)

View file

@ -95,7 +95,7 @@ func scanFile(path string, functions chan<- *Function) error {
if blockLevel == 0 {
function := &Function{
Name: tokens[headerStart].String(),
Name: tokens[headerStart].Text(),
Head: tokens[headerStart:bodyStart],
Body: tokens[bodyStart : i+1],
}