forked from MightyPork/crsn
buffer module, replacing stacks. TODO: docs, fix parsing of "numbers tuple" in mkbfv (consumed by the conditional branch parser)
This commit is contained in:
+14
-14
@@ -1,35 +1,35 @@
|
||||
(
|
||||
(stack r0)
|
||||
(mkbf r0)
|
||||
|
||||
(push @r0 1)
|
||||
(push @r0 2)
|
||||
(bfpush @r0 1)
|
||||
(bfpush @r0 2)
|
||||
|
||||
(pop r1 @r0)
|
||||
(bfpop r1 @r0)
|
||||
(cmp r1 2 (ne? (fault)))
|
||||
|
||||
(pop r1 @r0)
|
||||
(bfpop r1 @r0)
|
||||
(cmp r1 1 (ne? (fault)))
|
||||
|
||||
; test reverse push
|
||||
(push @r0 '🐈')
|
||||
(push @r0 7)
|
||||
(rpush @r0 8)
|
||||
(bfpush @r0 '🐈')
|
||||
(bfpush @r0 7)
|
||||
(bfrpush @r0 8)
|
||||
|
||||
(pop r1 @r0)
|
||||
(bfpop r1 @r0)
|
||||
(cmp r1 7 (ne? (fault)))
|
||||
|
||||
(pop r1 @r0)
|
||||
(bfpop r1 @r0)
|
||||
(cmp r1 '🐈' (ne? (fault)))
|
||||
|
||||
(pop r1 @r0)
|
||||
(bfpop r1 @r0)
|
||||
(cmp r1 8 (ne? (fault)))
|
||||
|
||||
; test reverse pop
|
||||
|
||||
(push @r0 1000)
|
||||
(push @r0 2000)
|
||||
(bfpush @r0 1000)
|
||||
(bfpush @r0 2000)
|
||||
|
||||
(rpop r1 @r0)
|
||||
(bfrpop r1 @r0)
|
||||
(cmp r1 1000 (ne? (fault)))
|
||||
|
||||
(del @r0)
|
||||
|
||||
+37
-17
@@ -1,27 +1,47 @@
|
||||
(
|
||||
; we don't have strings yet 👌
|
||||
(ld @stdout 'P') (ld @stdout 'r') (ld @stdout 'e') (ld @stdout 's') (ld @stdout 's') (ld @stdout ' ')
|
||||
(ld @stdout 'q') (ld @stdout ' ')
|
||||
(ld @stdout 't') (ld @stdout 'o') (ld @stdout ' ')
|
||||
(ld @stdout 'q') (ld @stdout 'u') (ld @stdout 'i') (ld @stdout 't')
|
||||
(ld @stdout '…') (ld @stdout ' ')
|
||||
; Create a table of strings
|
||||
(sym TXT r7)
|
||||
(def T_HELLO 0)
|
||||
(def T_UNK 1)
|
||||
(mkbf TXT)
|
||||
(mkbfv r0 "*** Type ascii to uppercase. Press q to quit. ***\n")
|
||||
(bfins @TXT T_HELLO r0)
|
||||
(mkbfv r0 "🐈")
|
||||
(bfins @TXT T_UNK r0)
|
||||
|
||||
; Print string from the table
|
||||
(bfrd r0 @TXT T_HELLO)
|
||||
(call print r0)
|
||||
|
||||
(proc print str
|
||||
; Print string from a buffer
|
||||
(sym ch r1) (sym pos r2)
|
||||
(ld pos 0)
|
||||
(:next)
|
||||
(bfrd ch @str pos)
|
||||
(ret.ov)
|
||||
(ld @stdout ch)
|
||||
(inc pos)
|
||||
(j :next)
|
||||
)
|
||||
|
||||
(:loop)
|
||||
(ld r0 @stdin)
|
||||
(ld r0 @stdin)
|
||||
|
||||
; exit by pressing 'q'
|
||||
(cmp r0 'q'
|
||||
(=? (ld @stdout '\n')
|
||||
(halt)))
|
||||
(cmp r0 'q'
|
||||
(eq? (ld @stdout '\n')
|
||||
(halt)))
|
||||
|
||||
; uppercase ASCII
|
||||
(cmp r0 'a' (<? (j :badchar)))
|
||||
(cmp r0 'z' (>? (j :badchar)))
|
||||
(sub r0 ' ')
|
||||
(ld @stdout r0)
|
||||
; uppercase ASCII
|
||||
(cmp r0 'a' (<? (j :badchar)))
|
||||
(cmp r0 'z' (>? (j :badchar)))
|
||||
(sub r0 ' ')
|
||||
(ld @stdout r0)
|
||||
(j :loop)
|
||||
|
||||
(:badchar)
|
||||
(ld @stdout '🐈') ; show a kitty if not ASCII
|
||||
(ld @stdout r0)
|
||||
(bfrd r0 @TXT T_UNK)
|
||||
(call print r0)
|
||||
(j :loop)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user