| /* |
| * Copyright 2017, NICTA |
| * |
| * This software may be distributed and modified according to the terms of |
| * the GNU General Public License version 2. Note that NO WARRANTY is provided. |
| * See "LICENSE_GPLv2.txt" for details. |
| * |
| * @TAG(NICTA_GPL) |
| */ |
| |
| /* |
| * The standard C headers need to be `escaped`, since Cogent's C parser |
| * can not parse all of the C standard. |
| */ |
| $esc:(#include <stdio.h>) |
| |
| /* |
| * `SysState` is the 'world', everything outside the Cogent program |
| * that is encapsulated into this variable. Essentially the state of |
| * the external world. |
| */ |
| typedef void *SysState; |
| |
| /* |
| * `generated.c` is the C file that Cogent generates after parsing |
| * the `HelloWorld.cogent` file (and any other cogent files that |
| * is included in `HelloWorld.cogent`. |
| */ |
| #include "generated.c" |
| |
| /* |
| * For every included cogent file in cogent, there is either a corresponding |
| * antiquoted C file(.ac file) in library or in our source repo, that contains |
| * the implementations of all the abstract data types and functions. |
| * |
| * XXX | Since we included `common.cogent` in `HelloWorld.cogent` we include the |
| * XXX | ac file here. Although, in our current program we don't use anything from |
| * XXX | common.cogent (except SysState, which we've defined in the begining of |
| * XXX | this file. |
| * |
| * REVISE: We don't include `common.ac` as it currently contains kernel-specific |
| * implementations (like printk, etc.). If we exclude this .ac file, there will |
| * be undefined C functions present in the final single .c file. As long as these |
| * functions are not used anywhere, it is safe to do so (although there might be |
| * warnings). |
| */ |
| //#include <gum/anti/common.ac> |
| |
| |
| /* |
| * print_string |
| */ |
| $ty:(SysState) print_string($ty:((SysState, String)) arg) |
| { |
| printf("%s\n", arg.p2); |
| return arg.p1; |
| } |
| |
| int main(void) |
| { |
| $ty:(SysState) st; |
| |
| /* helloworld() is defined in HelloWorld.cogent */ |
| st = $exp:helloworld(st); |
| |
| return 0; |
| } |