[NTLK] NEWT/0 set-aref bug

Matej Horvat matej.horvat at guest.arnes.si
Mon Dec 15 15:33:43 EST 2014


I have discovered a bug in NEWT/0.

Suppose we have the following function:

func()
begin
	local A := [0, 0];
	A[0] := 1;
	A[1] := 2;
	Print("Hello world!");
end

NEWT/0 incorrectly compiles the array assignments. It generates:

get-var A
push-constant 0
push-constant 1
freq-func set-aref
get-var A
push-constant 1
push-constant 2
freq-func set-aref

There should be a pop instruction after each set-aref, because the result  
is not used.

When returning from the function, the stack pointer is in this case 2  
higher than it should be, which causes problems in NSM, which has a fixed  
size stack. I am not sure how the Newton OS reacts to this.

I have already informed Makoto Nukui of this. I am just reposting this  
here as a warning as DyneTK and tntk both use NEWT/0, so they are also  
affected (I can reproduce the bug in both).

A workaround may be to use a function like

func(Array, Pos, Value)
	ArrayMunger(Array, Pos, 1, [Value], 0, 1)

and a similar kludge involving StuffByte and Ord for strings, but that is  
of course inconvenient.

Matej Horvat
http://matejhorvat.si/



More information about the NewtonTalk mailing list