| 8 | EM_JS_DEPS(deps, "$stackSave,$stackAlloc"); |
| 9 | |
| 10 | int main() { |
| 11 | EM_ASM({ |
| 12 | var size = 128; |
| 13 | var before; |
| 14 | before = stackSave(); |
| 15 | var x = stackAlloc(size); |
| 16 | var y = stackAlloc(size); |
| 17 | var direction = y > x ? 1 : -1; |
| 18 | assert(x % 16 == 0, "allocation must have 16-byte alignment"); |
| 19 | assert(x == Math.min(before, before + direction*size), "allocation must return the start of the range allocated"); |
| 20 | var z = stackAlloc(size); |
| 21 | assert(x != y && y != z && x != z, "allocations must be unique"); |
| 22 | assert((y - x)*(z - y) > 0, "allocations must be in the same direction"); |
| 23 | // no overlaps |
| 24 | function notInRange(value, begin, end) { |
| 25 | function errormsg() { return value + " must not be in the range (" + begin + ", " + end + "]"; } |
| 26 | if (begin < end) assert(!(value >= begin && value < end), errormsg()); |
| 27 | else assert(!(value <= begin && value > end), errormsg()); |
| 28 | } |
| 29 | notInRange(x, y, y + direction*size); |
| 30 | notInRange(x, z, z + direction*size); |
| 31 | notInRange(y, x, x + direction*size); |
| 32 | notInRange(y, z, z + direction*size); |
| 33 | notInRange(z, x, x + direction*size); |
| 34 | notInRange(z, y, y + direction*size); |
| 35 | out('ok.'); |
| 36 | }); |
| 37 | } |