From 16213b9bf973807b7b6d9014c5077e1a7b010f2c Mon Sep 17 00:00:00 2001 From: Suleyman Farajli Date: Wed, 25 Dec 2024 11:01:24 +0400 Subject: nested `if` implemented --- src/main.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main.go b/src/main.go index fe040c1..475e6a7 100644 --- a/src/main.go +++ b/src/main.go @@ -30,9 +30,8 @@ func readfile(path string) []string { return raw; } -var iflabel int; func compile(raw[]string) { - + var iflabels[] int; print(" section .text") print(" global _start") print("_start:") @@ -75,11 +74,13 @@ func compile(raw[]string) { print(" ;; IF") print(" pop r10") print(" cmp r10, 0") - fmt.Printf(" je .if%d\n",iflabel) + fmt.Printf(" je .if%d\n",i) + iflabels = append(iflabels, i) case "endif": - fmt.Printf(".if%d:\n",iflabel) - iflabel++ + fmt.Printf(".if%d:\n", iflabels[len(iflabels) - 1] ) + iflabels = iflabels[:len(iflabels) - 1] + default: panic("invalid word") } -- cgit v1.2.3