Major refactoring.

- Dropping and renewing API of Machine.
- Fixing type system bugs.
- Introduce new testcases and enhance testsuite.