Permalink
Browse files

print arrays nicely

  • Loading branch information...
Josep M. Bach
Josep M. Bach committed Dec 30, 2012
1 parent fd4843f commit d4bcee54489955c1e5882b57d39bb6c2198a6ce9
Showing with 17 additions and 15 deletions.
  1. +1 −1 compiler/examples/vectors.rb
  2. +2 −9 examples/vectors.tvm
  3. +13 −4 src/terror/value.c
  4. +1 −1 src/terror/value.h
@@ -1,2 +1,2 @@
a = ['hello world',2,3]
-puts a[0]
+puts a
View
@@ -1,10 +1,8 @@
_main
-:6:23
+:4:18
3
2
"hello world
-0
-"[]
"puts
17 PUSH
0
@@ -19,13 +17,8 @@ _main
16 PUSHSELF
32 PUSHLOCAL
0
-17 PUSH
-3
128 SEND
-4
-1
-128 SEND
-5
+3
1
20 PUSHNIL
144 RET
View
@@ -70,7 +70,7 @@ __Value_print(VALUE o)
break;
}
case StringType: {
- printf("\"%s\"", VAL2STR(o));
+ printf("%s", VAL2STR(o));
break;
}
case TrueType: {
@@ -90,19 +90,28 @@ __Value_print(VALUE o)
break;
}
case VectorType: {
- printf("#<Vector %p>", o);
+ printf("[");
+ DArray *array = VAL2ARY(o);
+ int count = DArray_count(array);
+ for(int i=0; i < count; i++) {
+ Value_print((VALUE)DArray_at(array, i));
+ if(i+1 < count) {
+ printf(", ");
+ }
+ }
+ printf("]");
break;
}
case MapType: {
printf("{");
- Hashmap_traverse(o->table, Hashmap_print_cb);
+ Hashmap_traverse(VAL2HASH(o), Hashmap_print_cb);
printf("}");
break;
}
default: {
printf("#<Object %p ", o);
printf("{");
- Hashmap_traverse(o->table, Hashmap_print_cb);
+ Hashmap_traverse(VAL2HASH(o), Hashmap_print_cb);
printf("}>");
break;
}
View
@@ -42,7 +42,7 @@ VALUE Vector_new(DArray *array);
#define VAL2ARY(o) ((DArray*)(o->data.as_data))
VALUE Map_new(DArray *array);
-#define VAL2HASH(o) ((Hashmap*)(o->table))
+#define VAL2HASH(o) (o->table)
void Value_set(VALUE receiver, char *key, VALUE value);
VALUE Value_get(VALUE receiver, char *key);

0 comments on commit d4bcee5

Please sign in to comment.