summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSuleyman Farajli <suleyman@farajli.net>2024-12-25 11:01:24 +0400
committerSuleyman Farajli <suleyman@farajli.net>2024-12-25 11:01:24 +0400
commit16213b9bf973807b7b6d9014c5077e1a7b010f2c (patch)
tree3af89973bbd36e64d5d4eef7c0debfd5663576f5 /src
parente99c6ed40d991b5cb14da758e75259865bd74bb0 (diff)
nested `if` implemented
Diffstat (limited to 'src')
-rw-r--r--src/main.go11
1 files changed, 6 insertions, 5 deletions
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")
}