rewrite the stdio module to be less broken. also add sehbang support

This commit is contained in:
2020-10-10 18:46:32 +02:00
parent 982ba27ed3
commit ace92a6411
21 changed files with 357 additions and 171 deletions
+1 -1
View File
@@ -3,6 +3,6 @@
(sym buf r7)
(mkbf buf (r0 66 67 68 '\n'))
(bfrpop @stdout @buf)
(bfrpop @cout @buf)
(s.nem -1)
)
+5 -5
View File
@@ -20,27 +20,27 @@
(:next)
(bfrd ch @str pos)
(ret.ov)
(ld @stdout ch)
(ld @cout ch)
(inc pos)
(j :next)
)
(:loop)
(ld r0 @stdin)
(ld r0 @cin)
(cmp r0 'q'
(eq? (ld @stdout '\n')
(eq? (ld @cout '\n')
(halt)))
; uppercase ASCII
(cmp r0 'a' (<? (j :badchar)))
(cmp r0 'z' (>? (j :badchar)))
(sub r0 ' ')
(ld @stdout r0)
(ld @cout r0)
(j :loop)
(:badchar)
(ld @stdout r0)
(ld @cout r0)
(bfrd r0 @TXT T_UNK)
(call print r0)
(j :loop)
+3 -3
View File
@@ -1,9 +1,9 @@
(
(mkbf r7)
(:r)(ld r0 @stdin)
(:r)(ld r0 @cin)
(cmp r0 '\n' (eq? (j :q)))
(bfpush @r7 r0)
(j :r)
(:q)(bfpop @stdout @r7 (nem? (j :q)))
(ld @stdout '\n')
(:q)(bfpop @cout @r7 (nem? (j :q)))
(ld @cout '\n')
)
Regular → Executable
+5 -2
View File
@@ -1,6 +1,9 @@
#!/usr/bin/env crsn
(
(:again)
(ld r0 @stdin (inval? (halt)))
(ld r0 @cin
(eof? (halt))
(inval? (j :again)))
(rcmp r0 'A' 'Z'
(eq? (ld r1 'A'))
(ne? (rcmp r0 'a' 'z'
@@ -11,6 +14,6 @@
(mod r0 26)
(add r0 r1)
(:print)
(ld @stdout r0)
(ld @cout r0)
(j :again)
)