diff options
-rw-r--r-- | stdlib.rip | 120 | ||||
-rw-r--r-- | stdlibtest.rip | 29 |
2 files changed, 115 insertions, 34 deletions
@@ -40,20 +40,108 @@ F<mkstr>[ P ] -0I[ - a b 256 - a b 256 256 - a 256 b 256 - a 256 256 b - a 256 256 b b - a 256 b b 256 - a 256 b b%ff - 256 b b%ff a - 256 b newa - newa 256 b - newa b 256 - newa b 256 256 - newa 256 b 256 - newa 256 newb - newa newb 256 + +0I[initialises variable store at beginning of stack (no args) (CALL ONLY ONCE)] +F<varinit>[ + 0lr 0lr 0lr 0I[guard] +] + +0I[INTERNAL FUNCTION + hauls variable by name in argument to top of stack; pushes 0 0 if non-existent] +F<varhaulup>[ + 00 0I[guard] + lRlR + SD3rW[ + 0I['s't'a'r't' 'w'h'i'l'e 9i 93a<mkstr><strprint>] + SD3r + 6R 0I[get target varname up] + D5r + EDI[P + 0I['e'q'u'a'l'! 9i 7<mkstr><strprint>] + D3r + 4RD5rW[ + 4r4rlrlr + 4RD5r] + 3RP3RP + 0 0I[to stop while loop] + 1 0I[to prevent taking of the else branch] + ] + nI[ + 0I['u'n'e'q'u'a'l'! 9i 9<mkstr><strprint>] + lRlR 0I[get next one] + SD3r 0I[get name up; if zero, then while loop should stop: end of var list] + ] + ] + 0I['d'o'n'e' 'w'i't'h' 'w'h'i'l'e 9i 79a<mkstr><strprint>] + SD3rnI[ + 0I['i's' 'z'e'r'o 9i 8<mkstr><strprint>] + lrlr3RP + SD3rW[ + lrlr + SD3r] + ] + 0I['d'o'n'e' 'w'i't'h' 'v'a'r'h'a'u'l'u'p 9i 99aii<mkstr><strprint>] +] + +0I[pushes whether specified variable exists in store] +F<varexists>[ + <varhaulup> + Pnn +] + +0I[deletes variable given by argument from store] +F<vardel>[ + 00 0I[guard] + lRlR + SD3rW[ + 0I['s't'a'r't' 'w'h'i'l'e 9i 93a<mkstr><strprint>] + SD3r + 6R 0I[get target varname up] + D5r + EDI[P + 0I['e'q'u'a'l'! 9i 7<mkstr><strprint>] + PPP + SD3rW[ + lrlr + SD3r] + PP + 1 0I[did find the thing] + 0 0I[to stop while loop] + 1 0I[to prevent taking of the else branch] + ] + nI[ + 0I['u'n'e'q'u'a'l'! 9i 9<mkstr><strprint>] + lRlR 0I[get next one] + SD3r 0I[get name up; if zero, then while loop should stop: end of var list] + ] + ] + 0I['d'o'n'e' 'w'i't'h' 'w'h'i'l'e 9i 79a<mkstr><strprint>] + nI[ + 0I['i's' 'z'e'r'o 9i 8<mkstr><strprint>] + 0lrlr3RP + SD3rW[ + lrlr + SD3r] + PP + ] + 0I['d'o'n'e' 'w'i't'h' 'v'a'r'd'e'l 9i 89a<mkstr><strprint>] +] + +0I[takes variable name (string) and value to store] +F<varstore>[ + 0I['s't'o'r'i'n'g' 8<mkstr><strprint> + O + ' 'i'n' 4<mkstr><strprint> + <strprint> + 9io + ] + + SD<vardel> + Slrlr +] + +0I[takes variable name (string) and pushes its value] +F<varget>[ + <varhaulup> + SP ] diff --git a/stdlibtest.rip b/stdlibtest.rip index c0926cd..6e2a8a1 100644 --- a/stdlibtest.rip +++ b/stdlibtest.rip @@ -1,21 +1,14 @@ #<stdlib.rip> -0 0I[empty string] -'a <strpush> -'b <strpush> -' <strpush> -'4 <strpush> -'2 <strpush> -9i <strpush> +<varinit> -0 -'a <strpush> -'b <strpush> -'c <strpush> -'d <strpush> -'e <strpush> -'f <strpush> -9i <strpush> -<strcat> -<strprint> +'a 'b 'c 'd 'x 'y 'z 7 <mkstr> 9i <strpush> <strprint> -'a 'b 'c 'd 'x 'y 'z 9i 8 <mkstr> <strprint> + +'h'o'i 3<mkstr> 67m <varstore> 0I[42] +'d'o'e'i 4<mkstr> 93a9iDmm75mda <varstore> 0I[1234] + +'d'o'e'i 4<mkstr> <varget> O 9io 0I[1234] +'h'o'i 3<mkstr> <varget> O 9io 0I[42] + +'h'o'i 3<mkstr> <vardel> +'d'o'e'i 4<mkstr> <vardel> |