summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2022-08-04 20:42:12 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2022-08-04 20:42:12 -0300
commitbdf71faad059ba7deb44a983598ad63de43a5e67 (patch)
tree43bc8777e406f5e74a263eacd08de38c825e565a
parentadbc4248120e245fb68f8658bb765fe04c6ecdab (diff)
downloadstk-bdf71faad059ba7deb44a983598ad63de43a5e67.tar.gz
stk-bdf71faad059ba7deb44a983598ad63de43a5e67.zip
Decided on less cryptic keywords
-rw-r--r--input.stk3
-rw-r--r--main.py24
2 files changed, 14 insertions, 13 deletions
diff --git a/input.stk b/input.stk
index 8b4f68f..c392c0e 100644
--- a/input.stk
+++ b/input.stk
@@ -1,3 +1,2 @@
-Loops ten times asking for user input. If the input is 0 or nothing, print 69420, else print back the number from the input.
-10 [ 0 1 , [ ~ . ! -- ] [ 69420 . ! ] -- ]
+10 [ 0 1 read_number [ dup print_number newline pop -- ] [ 69420 print_number newline pop ] -- ]
diff --git a/main.py b/main.py
index 6c177d0..0395be5 100644
--- a/main.py
+++ b/main.py
@@ -57,18 +57,13 @@ code.append('mov rdi, 1')
code.append('lea rsi, [int_buffer + rcx]')
code.append('mov rdx, rbx')
code.append('syscall')
-code.append('mov [int_buffer], 10')
-code.append('mov rax, 1')
-code.append('mov rdi, 1')
-code.append('mov rsi, int_buffer')
-code.append('mov rdx, 1')
-code.append('syscall')
code.append('mov rbx, [rsp - 8]')
code.append('ret')
code.append('start:')
loop_stack = []
loop_index = -1
+
with open('input.stk', 'r') as f:
text = f.read()
words = text.replace('\n', ' ').strip().split(' ')
@@ -96,20 +91,27 @@ with open('input.stk', 'r') as f:
elif word == '*':
code.append('pop rax')
code.append('pop rdi')
- code.append('mul rdi')
+ code.append('imul rdi')
code.append('push rax')
- elif word == '!':
+ elif word == 'pop':
code.append('pop rax')
- elif word == '~':
+ elif word == 'dup':
code.append('pop rax')
code.append('push rax')
code.append('push rax')
- elif word == '.':
+ elif word == 'print_number':
code.append('call print')
code.append('pop rax')
- elif word == ',':
+ elif word == 'read_number':
code.append('call read')
code.append('push rax')
+ elif word == 'newline':
+ code.append('mov [int_buffer], 10')
+ code.append('mov rax, 1')
+ code.append('mov rdi, 1')
+ code.append('mov rsi, int_buffer')
+ code.append('mov rdx, 1')
+ code.append('syscall')
elif word == '[':
loop_index += 1
loop_stack.append(loop_index)