Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

print arrays nicely

  • Loading branch information...
commit d4bcee54489955c1e5882b57d39bb6c2198a6ce9 1 parent fd4843f
@txus authored
View
2  compiler/examples/vectors.rb
@@ -1,2 +1,2 @@
a = ['hello world',2,3]
-puts a[0]
+puts a
View
11 examples/vectors.tvm
@@ -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
17 src/terror/value.c
@@ -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
2  src/terror/value.h
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.