-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathhello_world_vmi.cpp
More file actions
executable file
·47 lines (36 loc) · 1.21 KB
/
hello_world_vmi.cpp
File metadata and controls
executable file
·47 lines (36 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//usr/bin/env g++ -Based -std=c++23 -O2 -o - "$0" -DLANGUAGE="$1" "${@:2}"; exit
#include "gil/gil.hpp"
using namespace gil;
enum Language {
English,
Français,
中文,
};
enum {
name,
index,
};
template <auto string>
using Puts = Block<
Set<index, val<0>>,
While<(var<index> < len<string>),
Block<Put<string[var<index>]>, Set<index, var<index> + val<1>>>>>;
template <Language = English> struct SayGreeting;
template <> struct SayGreeting<English> {
template <auto name> using To = Puts<str<"Hello, "> + name + str<"!">>;
};
template <> struct SayGreeting<Français> {
template <auto name> using To = Puts<str<"Bonjour, "> + name + str<" !">>;
};
template <> struct SayGreeting<中文> {
template <auto name> using To = Puts<name + str<"好。">>;
};
using SkipWhitespace =
While<peek<> == val<' '> || peek<> == val<'\n'> || peek<> == val<'\t'>,
Advance<>>;
template <auto dst>
using Reads = Block<Set<dst, str<"">>,
While<peek<> != val<'\n'> && peek<> != none,
Block<Set<dst, var<dst> + peek<>>, Advance<>>>>;
auto run = start<SkipWhitespace, Reads<name>,
SayGreeting<LANGUAGE>::template To<var<name>>, Put<val<'\n'>>>;