Permalink
Browse files

Check to see if the first argument is "kittens"

The algorithm is simple and makes some assumptions, but it works.
  • Loading branch information...
nbrown committed Apr 9, 2012
1 parent d18445f commit a738f9128c0ce7f6e489754c66791f3aec90337c
Showing with 24 additions and 1 deletion.
  1. +24 −1 t/m0/integration/m0_args.m0
@@ -8,6 +8,7 @@
4 "ok 2 - arg contents: first argument was 'kittens'\n"
5 "not ok 2 - arg contents: first argument was 'kittens' # TODO M0 doesn't support this yet \n"
6 " arguments)\n"
+7 "kittens"
.metadata
.bytecode
@@ -51,7 +52,29 @@ argv_test:
set_imm I1, 0, 1
set_imm S0, 0, ARGV
deref S0, INTERP, S0
- deref S0, S0, I1
+ set_imm I2, 0, 1
+ get_word S0, S0, I2
+
+ set_imm S1, 0, 7
+ deref S1, CONSTS, S1
+
+ # I2 = number of bytes in string
+ get_word I2, S1, I0
+ sub_i I2, I2, I1
+
+string_cmp_loop:
+ sub_i I2, I2, I1
+ get_byte I3, S0, I2
+
+ set_imm I5, 0, 8
+ add_i I5, I2, I5
+ get_byte I4, S1, I5
+
+ sub_i I3, I3, I4
+ goto_if argv_nok, I3
+
+ goto_if string_cmp_loop, I2
+ goto argv_ok, x
# TODO: test S0 eq 'kittens'

0 comments on commit a738f91

Please sign in to comment.