import { memory: Memory, assert: Assert } from 'env';

type String = {
  length: i32,
  chars: i32[]
};
type Assert = (String, i32, i32) => void;

const array: i32[] = ['<', 'a', 'b'];
const farray: f32[] = [1.2, 3.0, 5.4];

export function run() {
  assert("memory size, baseline value", memory.size(), 1);
  // FIXME: this is a semi-bug. Memory.grow() returns a value so that is why we
  // assign it to something, otherwise there will be a dangling value on the
  // stack and run() returns zero values. So WASM compilining will fail
  //
  // statements which return values but don't assign to anything lhs should probably
  // be compiled to an operation + drop opcode pair.
  const previous: i32 = memory.grow(1);
  assert("memory grow, returns previous", previous, 1);
  assert("memory size, grown", memory.size(), 2);
  assert("floats in data", farray[2] == 5.4, true);
  assert("ints in data", array[2], 'b');
}

export function testStringsInsideReturn(): i32 {
  return "Hello World!";
}

export function emptyReturn() {
  return;
}

