summaryrefslogtreecommitdiff
path: root/tiger-compiler/tcsh/python/tests/object.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'tiger-compiler/tcsh/python/tests/object.ipynb')
-rw-r--r--tiger-compiler/tcsh/python/tests/object.ipynb182
1 files changed, 182 insertions, 0 deletions
diff --git a/tiger-compiler/tcsh/python/tests/object.ipynb b/tiger-compiler/tcsh/python/tests/object.ipynb
new file mode 100644
index 0000000..69563e5
--- /dev/null
+++ b/tiger-compiler/tcsh/python/tests/object.ipynb
@@ -0,0 +1,182 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "id": "3f7f66b6",
+ "metadata": {},
+ "source": [
+ "# Import Tiger and Object"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "id": "9cb3bce5",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import tc"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "id": "be38c5fe",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "True"
+ ]
+ },
+ "execution_count": 2,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "tc.has(\"object\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "id": "9fe09a20",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "True"
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "import tiger_object\n",
+ "tiger_object == tc.object"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "c2ffa10b",
+ "metadata": {},
+ "source": [
+ "# Object functions"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "id": "37f1bbb8",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from typing import Callable\n",
+ "def function_annotations(fn: Callable) -> str:\n",
+ " ann = fn.__annotations__\n",
+ " ret = ann.get(\"return\")\n",
+ " args = \", \".join((\"{}: '{}'\".format(a, ann[a]) for a in ann if a != \"return\"))\n",
+ " name = fn.__module__ + '.' + fn.__qualname__\n",
+ " return \"<function {name}({args}) -> '{ret}'>\".format(name=name, args=args, ret=ret)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "id": "0ee4cd72",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "<function tiger_object.bind(tree: 'Ast') -> 'misc::error'>\n"
+ ]
+ }
+ ],
+ "source": [
+ "if tc.has(\"bind\"): # Wait TC3\n",
+ " print(function_annotations(tc.object.bind))\n",
+ "else:\n",
+ " def bind(tree: 'ast::Ast &') -> 'misc::error':\n",
+ " pass\n",
+ " bind.__module__ = \"tiger_object\"\n",
+ " print(function_annotations(bind))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "id": "bfba3cc3",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "<function tiger_object.types_check(tree: 'Ast') -> 'misc::error'>\n"
+ ]
+ }
+ ],
+ "source": [
+ "if tc.has(\"type\"): # Wait TC4\n",
+ " print(function_annotations(tc.object.types_check))\n",
+ "else:\n",
+ " def types_check(tree: 'ast::Ast &') -> 'misc::error':\n",
+ " pass\n",
+ " types_check.__module__ = \"tiger_object\"\n",
+ " print(function_annotations(types_check))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "id": "bd48ce57",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "<function tiger_object.rename(tree: 'Ast') -> 'object::class_names_type *'>\n"
+ ]
+ }
+ ],
+ "source": [
+ "if tc.has(\"desugar\"): # Wait TC4\n",
+ " print(function_annotations(tc.object.rename))\n",
+ "else:\n",
+ " def rename(tree: 'ast::Ast &') -> 'object::class_names_type *':\n",
+ " pass\n",
+ " rename.__module__ = \"tiger_object\"\n",
+ " print(function_annotations(rename))"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.10.2"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}