changeset 92:9cde0dc0699e default tip

fix README.md
author aka
date Wed, 27 Jun 2018 00:10:30 +0900
parents ee031a093708
children
files Example.ipynb Example.jpg README.md example-notebook.ipynb example-notebook.png
diffstat 5 files changed, 277 insertions(+), 158 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Example.ipynb	Wed Jun 27 00:10:30 2018 +0900
@@ -0,0 +1,256 @@
+{
+ "cells": [
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "# CbC kernel"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "## Hello CbC!"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "metadata": {
+    "scrolled": true
+   },
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Hello CbC!\n"
+     ]
+    },
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "[CbC kernel] Executable exited with code 11"
+     ]
+    }
+   ],
+   "source": [
+    "#define __environment _CbC_environment\n",
+    "#define __return _CbC_return\n",
+    "\n",
+    "extern int printf(const char*, ...);\n",
+    "\n",
+    "__code Hello_CbC();\n",
+    "\n",
+    "int main(int argc, char **argv){\n",
+    "    goto Hello_CbC();\n",
+    "    return 0;\n",
+    "}\n",
+    "\n",
+    "__code Hello_CbC(){\n",
+    "    printf(\"Hello CbC!\\n\");\n",
+    "    \n",
+    "}"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "## fizzbazz"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "https://gist.github.com/hanachin/3e2f9034e0fe382f019e55de4c6b016b"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "1\n",
+      "2\n",
+      "Fizz\n",
+      "4\n",
+      "Buzz\n",
+      "Fizz\n",
+      "7\n",
+      "8\n",
+      "Fizz\n",
+      "Buzz\n",
+      "11\n",
+      "Fizz\n",
+      "13\n",
+      "14\n",
+      "FizzBuzz\n",
+      "16\n",
+      "17\n",
+      "Fizz\n",
+      "19\n",
+      "Buzz\n",
+      "Fizz\n",
+      "22\n",
+      "23\n",
+      "Fizz\n",
+      "Buzz\n",
+      "26\n",
+      "Fizz\n",
+      "28\n",
+      "29\n",
+      "FizzBuzz\n",
+      "31\n",
+      "32\n",
+      "Fizz\n",
+      "34\n",
+      "Buzz\n",
+      "Fizz\n",
+      "37\n",
+      "38\n",
+      "Fizz\n",
+      "Buzz\n",
+      "41\n",
+      "Fizz\n",
+      "43\n",
+      "44\n",
+      "FizzBuzz\n",
+      "46\n",
+      "47\n",
+      "Fizz\n",
+      "49\n",
+      "Buzz\n",
+      "Fizz\n",
+      "52\n",
+      "53\n",
+      "Fizz\n",
+      "Buzz\n",
+      "56\n",
+      "Fizz\n",
+      "58\n",
+      "59\n",
+      "FizzBuzz\n",
+      "61\n",
+      "62\n",
+      "Fizz\n",
+      "64\n",
+      "Buzz\n",
+      "Fizz\n",
+      "67\n",
+      "68\n",
+      "Fizz\n",
+      "Buzz\n",
+      "71\n",
+      "Fizz\n",
+      "73\n",
+      "74\n",
+      "FizzBuzz\n",
+      "76\n",
+      "77\n",
+      "Fizz\n",
+      "79\n",
+      "Buzz\n",
+      "Fizz\n",
+      "82\n",
+      "83\n",
+      "Fizz\n",
+      "Buzz\n",
+      "86\n",
+      "Fizz\n",
+      "88\n",
+      "89\n",
+      "FizzBuzz\n",
+      "91\n",
+      "92\n",
+      "Fizz\n",
+      "94\n",
+      "Buzz\n",
+      "Fizz\n",
+      "97\n",
+      "98\n",
+      "Fizz\n",
+      "Buzz\n"
+     ]
+    }
+   ],
+   "source": [
+    "#define __environment _CbC_environment\n",
+    "#define __return _CbC_return\n",
+    "\n",
+    "#include <stdio.h>\n",
+    "\n",
+    "typedef __code(*main_ret_code_t)(int, void *env);\n",
+    "\n",
+    "__code fizzbuzz(int n, int max, main_ret_code_t ret, void *env);\n",
+    "__code fizz(int n, int max, main_ret_code_t ret, void *env);\n",
+    "__code buzz(int n, int max, const char *fizz, main_ret_code_t ret, void *env);\n",
+    "__code print_fizzbuzz(int n, int max, const char *fizz, const char *buzz, main_ret_code_t ret, void *env);\n",
+    "\n",
+    "int main(void){\n",
+    "  goto fizzbuzz(1, 100, __return, __environment);\n",
+    "}\n",
+    "\n",
+    "__code fizzbuzz(int n, int max, main_ret_code_t ret, void *env) {\n",
+    "  if (n > max) goto ret(0, env);\n",
+    "\n",
+    "  goto fizz(n, max, ret, env);\n",
+    "}\n",
+    "\n",
+    "__code fizz(int n, int max, main_ret_code_t ret, void *env) {\n",
+    "  if (n % 3 == 0) {\n",
+    "    goto buzz(n, max, \"Fizz\", ret, env);\n",
+    "  } else {\n",
+    "    goto buzz(n, max, \"\", ret, env);\n",
+    "  }\n",
+    "}\n",
+    "\n",
+    "__code buzz(int n, int max, const char *fizz, main_ret_code_t ret, void *env) {\n",
+    "  if (n % 5 == 0) {\n",
+    "    goto print_fizzbuzz(n, max, fizz, \"Buzz\", ret, env);\n",
+    "  } else {\n",
+    "    goto print_fizzbuzz(n, max, fizz, \"\", ret, env);\n",
+    "  }\n",
+    "}\n",
+    "\n",
+    "__code print_fizzbuzz(int n, int max, const char *fizz, const char *buzz, main_ret_code_t ret, void *env) {\n",
+    "  if (*fizz || *buzz) {\n",
+    "    printf(\"%s%s\\n\", fizz, buzz);\n",
+    "  } else {\n",
+    "    printf(\"%d\\n\", n);\n",
+    "  }\n",
+    "\n",
+    "  goto fizzbuzz(n + 1, max, ret, env);\n",
+    "}"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  }
+ ],
+ "metadata": {
+  "kernelspec": {
+   "display_name": "CbC",
+   "language": "CbC",
+   "name": "cbc"
+  },
+  "language_info": {
+   "file_extension": ".c",
+   "mimetype": "text/plain",
+   "name": "C"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
Binary file Example.jpg has changed
--- a/README.md	Tue Jun 26 14:47:51 2018 +0900
+++ b/README.md	Wed Jun 27 00:10:30 2018 +0900
@@ -7,11 +7,29 @@
 
 ### Local Jupyter
 
+
+
+CbC install
+```
+hg clone http://www.cr.ie.u-ryukyu.ac.jp/hg/CbC/CbC_gcc/
+mkdir build-gcc && cd build-gcc
+../CbC_gcc/configure CFLAGS="-g3 -O0" \
+             --prefix=/usr/ --disable-nls \
+             --disable-bootstrap --enable-languages=c \
+             --enable-checking=tree,rtl,assert,types 
+             
+make && make install
+```
+
+after, kernel install.
+
 ```
 hg clone http://www.cr.ie.u-ryukyu.ac.jp/hg/Members/aka/jupyter_CbC_kernel
-cd jupyter_CbC_kernel 
-pip install jupyter-CbC-kernel
-install_CbC_kernel
+cd jupyter_CbC_kernel
+pip3 install --upgrade pip jupyter ipykernel
+pip3 install .
+cd jupyter_CbC_kernel && install_CbC_kernel --user
+cd ..
 jupyter notebook
 ```
 
--- a/example-notebook.ipynb	Tue Jun 26 14:47:51 2018 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,155 +0,0 @@
-{
- "cells": [
-  {
-   "cell_type": "markdown",
-   "metadata": {},
-   "source": [
-    "# Valid code"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 1,
-   "metadata": {
-    "collapsed": false
-   },
-   "outputs": [
-    {
-     "name": "stderr",
-     "output_type": "stream",
-     "text": []
-    },
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "Hello world\n"
-     ]
-    }
-   ],
-   "source": [
-    "#include <stdio.h>\n",
-    "\n",
-    "int main() {\n",
-    "    printf(\"Hello world\\n\");\n",
-    "}"
-   ]
-  },
-  {
-   "cell_type": "markdown",
-   "metadata": {},
-   "source": [
-    "But the kernel will also display compilations warnings and errors if we have some. Let's try to remove the `#include <stdio.h>` statement, which if necessary for `printf` to work."
-   ]
-  },
-  {
-   "cell_type": "markdown",
-   "metadata": {},
-   "source": [
-    "# Code generating warnings during compilation"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 2,
-   "metadata": {
-    "collapsed": false
-   },
-   "outputs": [
-    {
-     "name": "stderr",
-     "output_type": "stream",
-     "text": [
-      "/var/folders/31/qct57s856n5f0b2r4tgbmn1c0000gn/T/tmp0Qan0v.c:2:5: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)' [-Wimplicit-function-declaration]\n",
-      "    printf(\"Hello world\\n\");\n",
-      "    ^\n",
-      "/var/folders/31/qct57s856n5f0b2r4tgbmn1c0000gn/T/tmp0Qan0v.c:2:5: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'\n",
-      "1 warning generated.\n"
-     ]
-    },
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "Hello world\n"
-     ]
-    }
-   ],
-   "source": [
-    "int main() {\n",
-    "    printf(\"Hello world\\n\");\n",
-    "}"
-   ]
-  },
-  {
-   "cell_type": "markdown",
-   "metadata": {},
-   "source": [
-    "You can see that the warning are displayed, but the code is still executed."
-   ]
-  },
-  {
-   "cell_type": "markdown",
-   "metadata": {},
-   "source": [
-    "# Code generating errors during compilation"
-   ]
-  },
-  {
-   "cell_type": "code",
-   "execution_count": 3,
-   "metadata": {
-    "collapsed": false
-   },
-   "outputs": [
-    {
-     "name": "stderr",
-     "output_type": "stream",
-     "text": [
-      "/var/folders/31/qct57s856n5f0b2r4tgbmn1c0000gn/T/tmpw4Kz3c.c:2:5: warning: implicitly declaring library function 'printf' with type 'int (const char *, ...)' [-Wimplicit-function-declaration]\n",
-      "    printf(\"Hello world\")\n",
-      "    ^\n",
-      "/var/folders/31/qct57s856n5f0b2r4tgbmn1c0000gn/T/tmpw4Kz3c.c:2:5: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'\n",
-      "/var/folders/31/qct57s856n5f0b2r4tgbmn1c0000gn/T/tmpw4Kz3c.c:2:26: error: expected ';' after expression\n",
-      "    printf(\"Hello world\")\n",
-      "                         ^\n",
-      "                         ;\n",
-      "1 warning and 1 error generated.\n",
-      "[C kernel] GCC exited with code 1, the executable will not be executed"
-     ]
-    },
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": []
-    }
-   ],
-   "source": [
-    "int main() {\n",
-    "    printf(\"Hello world\")\n",
-    "}"
-   ]
-  },
-  {
-   "cell_type": "markdown",
-   "metadata": {},
-   "source": [
-    "You can see that the errors and warnings are shown, but the code is not executed. The retcode is also added to the end of `stderr`"
-   ]
-  }
- ],
- "metadata": {
-  "kernelspec": {
-   "display_name": "C",
-   "language": "c",
-   "name": "c_kernel"
-  },
-  "language_info": {
-   "file_extension": "c",
-   "mimetype": "text/plain",
-   "name": "c"
-  }
- },
- "nbformat": 4,
- "nbformat_minor": 0
-}
Binary file example-notebook.png has changed