diff --git a/src/vm/fzl_vm.c b/src/vm/fzl_vm.c index f39b1cd..b3ab61c 100644 --- a/src/vm/fzl_vm.c +++ b/src/vm/fzl_vm.c @@ -208,7 +208,7 @@ void print_object(fzl_vm_object_t *obj) printf(""); } - printf(">\n"); + printf(">"); } void print_err_data(fzl_vm_t *vm) @@ -435,6 +435,7 @@ int fzl_vm_run(fzl_vm_t *vm) fzl_vm_object_t *obj = malloc(sizeof(fzl_vm_object_t)); obj->values = malloc(values_count * sizeof(fzl_value_t)); obj->values_count = values_count; + memset(obj->values, 0, values_count * sizeof(fzl_value_t)); fzl_vm_env_t *current_env = vm->estack[vm->etop - 1]; if (current_env->owned_objects_remainder <= @@ -858,7 +859,10 @@ int fzl_vm_run(fzl_vm_t *vm) else if (arg.type == FZL_TYPE_NULL) printf("\n"); else if (arg.type == FZL_TYPE_OBJECT) + { print_object(arg.as.obj); + printf("\n"); + } } else if (fn_id == FZL_BUILTIN_EXIT) { diff --git a/tests/programs/pos_while_not_null.fzs b/tests/programs/pos_while_not_null.fzs new file mode 100644 index 0000000..5100018 --- /dev/null +++ b/tests/programs/pos_while_not_null.fzs @@ -0,0 +1,28 @@ +class Some { + Some next; +} + +Some l4 = new Some; + +Some l3 = new Some; +l3.next = l4; + +Some l2 = new Some; +l2.next = l3; + +Some l1 = new Some; +l1.next = l2; + +Some root = new Some; +root.next = l1; + +Some obj = root; +while (obj != null) +{ + obj = obj.next; + printline("Now object is:"); + printline(obj); +} + +printline(obj); +