# How to reduce the local temp variables on the flash platform

**URL:** <https://community.haxe.org/t/how-to-reduce-the-local-temp-variables-on-the-flash-platform/422>\
**Category:** Haxe\
**Tags:** haxe-swf\
**Created:** [February 13, 2018, 3:42pm UTC](https://community.haxe.org/t/how-to-reduce-the-local-temp-variables-on-the-flash-platform/422 "2018-02-13T15:42:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![R32](https://community.haxe.org/user_avatar/community.haxe.org/r32/32/2123_2.png) [@R32](https://community.haxe.org/u/R32)\
**Post date:** [February 13, 2018, 3:42pm UTC](https://community.haxe.org/t/how-to-reduce-the-local-temp-variables-on-the-flash-platform/422/1 "2018-02-13T15:42:35Z")

</div>

ni men hao!

I want to make PR for [#6727](https://github.com/HaxeFoundation/haxe/issues/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 😅).

- 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?

---

<div class="post-metadata">

**Author:** ![nadako](https://community.haxe.org/user_avatar/community.haxe.org/nadako/32/5_2.png) [@nadako](https://community.haxe.org/u/nadako)\
**Post date:** [February 13, 2018, 10:11pm UTC](https://community.haxe.org/t/how-to-reduce-the-local-temp-variables-on-the-flash-platform/422/2 "2018-02-13T22:11:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![R32](https://community.haxe.org/user_avatar/community.haxe.org/r32/32/2123_2.png) [@R32](https://community.haxe.org/u/R32)\
**Post date:** [February 14, 2018, 5:18am UTC](https://community.haxe.org/t/how-to-reduce-the-local-temp-variables-on-the-flash-platform/422/3 "2018-02-14T05:18:13Z")

</div>

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

```haxe
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:

```haxe
@: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);
		};
	}
}

```

---

<div class="post-metadata">

**Author:** ![R32](https://community.haxe.org/user_avatar/community.haxe.org/r32/32/2123_2.png) [@R32](https://community.haxe.org/u/R32)\
**Post date:** [February 14, 2018, 3:44pm UTC](https://community.haxe.org/t/how-to-reduce-the-local-temp-variables-on-the-flash-platform/422/4 "2018-02-14T15:44:51Z")

</div>

well. I have made a [PR#6850](https://github.com/HaxeFoundation/haxe/pull/6850). I should close this post.
