How to reduce the local temp variables on the flash platform

ni men hao!

I want to make PR for #6727, but I don’t have much experience with functional programming(only for hss with nekoml. and I feel like I messed up the hss :sweat_smile:).

  • maybe do something like js.Syntax? but as simn said, it seems strange.

  • or define a reserved List and make all of its untyped elems become pure when Parsing. But I have no idea which ml files should I start?

  • or maybe there are other simpler ways…

Any suggestions?

I’m not familiar with the flash target, but it seems that __vmem_(g|s)et__ methods are represented well enough in the flash.Memory class properly typed methods. Is it about adding @:pure to get* methods?

Yes, but adding @:pure to untyped expr doesn’t seem to work.

abstract Ptr(Int) to Int {
	public inline function new(i: Int) this = i;
	@:arrayAccess inline function get(i: Int):Int return flash.Memory.getByte(this + i);
	@:arrayAccess inline function set(i: Int, v:Int):Void flash.Memory.setByte(this + i, v);
}

class App {
	static function main() {
		var ptr = new Ptr(0);
		var i = rand();
		ptr[i++] = rand();
		ptr[i++] = ptr[i] + rand();
	}
	static inline function rand() {
		return Std.int(Math.random() * 100);
	}
}

Compiling with -D dump=pretty -D analyzer-optimize, It will generate the following code:

@:keep @:used
class App {

	@:keep
	static function main() {
		var this1 = 0;
		var ptr = cast this1;
		var i = __int__(Math.random() * 100);
		{
			var i1 = i ++;
			var v = __int__(Math.random() * 100);
			__vmem_set__(0, cast ptr + i1, v);
		};
		{
			var i2 = i ++;
			var v1 = __vmem_get__(0, cast ptr + i) + __int__(Math.random() * 100);
			__vmem_set__(0, cast ptr + i2, v1);
		};
	}
}

well. I have made a PR#6850. I should close this post.