// File: ArashPartow[P]exprtk/exprtk_simple_example_18.cpp
// Function: void file_io<double>()
void file_io()
{
   typedef exprtk::symbol_table<T> symbol_table_t;
   typedef exprtk::expression<T>   expression_t;
   typedef exprtk::parser<T>       parser_t;

   const std::string fileio_program =
      " var file_name := 'file.txt';                          "
      " var stream    := null;                                "
      "                                                       "
      " if (stream := open(file_name,'w'))                    "
      "    println('Successfully opened file: ' + file_name); "
      " else                                                  "
      " {                                                     "
      "    println('Failed to open file: ' + file_name);      "
      "    return [false];                                    "
      " };                                                    "
      "                                                       "
      " var s := 'Hello world...\n';                          "
      "                                                       "
      " for (var i := 0; i < 10; i += 1)                      "
      " {                                                     "
      "    write(stream,s);                                   "
      " };                                                    "
      "                                                       "
      " if (close(stream))                                    "
      "    println('Sucessfully closed file: ' + file_name);  "
      " else                                                  "
      " {                                                     "
      "    println('Failed to close file: ' + file_name);     "
      "    return [false];                                    "
      " }                                                     ";

   exprtk::rtl::io::file::package<T> fileio_package;
   exprtk::rtl::io::println<T>       println;

   symbol_table_t symbol_table;
   symbol_table.add_function("println",println);
   symbol_table.add_package (fileio_package   );

   expression_t expression;
   expression.register_symbol_table(symbol_table);

   parser_t parser;
   parser.compile(fileio_program,expression);

   printf("Result %10.3f\n",expression.value());
}

// Assembly:
subq $0xd28, %rsp            # imm = 0xD28
leaq 0xd07(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x1126f0
movq 0x20(%rsp), %rdx
leaq 0x334c70(%rip), %rsi    # 0x44e565
leaq 0xd08(%rsp), %rdi
callq 0x119810
jmp 0x119904
leaq 0xd07(%rsp), %rdi
callq 0x112830
leaq 0xb80(%rsp), %rdi
callq 0x119f50
jmp 0x119920
leaq 0xaf7(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x1126f0
movq 0x18(%rsp), %rdx
leaq 0x335186(%rip), %rsi    # 0x44eac4
leaq 0xaf8(%rsp), %rdi
callq 0x119810
jmp 0x11994d
leaq 0xb18(%rsp), %rdi
leaq 0xaf8(%rsp), %rsi
callq 0x11a070
jmp 0x119964
leaq 0xaf8(%rsp), %rdi
callq 0x112848
leaq 0xaf7(%rsp), %rdi
callq 0x112830
leaq 0xae8(%rsp), %rdi
movl $0x1, %esi
callq 0x11a180
jmp 0x119992
leaq 0xac7(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x1126f0
movq 0x10(%rsp), %rdx
leaq 0x33511b(%rip), %rsi    # 0x44eacb
leaq 0xac8(%rsp), %rdi
callq 0x119810
jmp 0x1199bf
leaq 0xae8(%rsp), %rdi
leaq 0xac8(%rsp), %rsi
leaq 0xb18(%rsp), %rdx
callq 0x11a1c0
jmp 0x1199de
leaq 0xac8(%rsp), %rdi
callq 0x112848
leaq 0xac7(%rsp), %rdi
callq 0x112830
leaq 0xae8(%rsp), %rdi
leaq 0xb80(%rsp), %rsi
callq 0x11a3c0
jmp 0x119a0f
leaq 0xaa0(%rsp), %rdi
callq 0x11a3f0
jmp 0x119a1e
leaq 0xaa0(%rsp), %rdi
leaq 0xae8(%rsp), %rsi
callq 0x11a4a0
jmp 0x119a35
leaq 0x28(%rsp), %rdi
movl $0x7f, %esi
callq 0x11a550
jmp 0x119a46
leaq 0x178(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x11a680
jmp 0x119a5a
leaq 0x28(%rsp), %rdi
callq 0x11aeb0
leaq 0x178(%rsp), %rdi
leaq 0xd08(%rsp), %rsi
leaq 0xaa0(%rsp), %rdx
callq 0x11af20
jmp 0x119a83
leaq 0xaa0(%rsp), %rdi
callq 0x11b7b0
movsd %xmm0, 0x8(%rsp)
jmp 0x119a98
movsd 0x8(%rsp), %xmm0
leaq 0x33502e(%rip), %rdi    # 0x44ead3
movb $0x1, %al
callq 0x1120a0
jmp 0x119aae
leaq 0x178(%rsp), %rdi
callq 0x11b7d0
leaq 0xaa0(%rsp), %rdi
callq 0x11b9d0
leaq 0xae8(%rsp), %rdi
callq 0x11ba10
leaq 0xb18(%rsp), %rdi
callq 0x11ba90
leaq 0xb80(%rsp), %rdi
callq 0x11bac0
leaq 0xd08(%rsp), %rdi
callq 0x112848
addq $0xd28, %rsp            # imm = 0xD28
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcf8(%rsp)
movl %eax, 0xcf4(%rsp)
leaq 0xd07(%rsp), %rdi
callq 0x112830
jmp 0x119c99
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcf8(%rsp)
movl %eax, 0xcf4(%rsp)
jmp 0x119c8c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcf8(%rsp)
movl %eax, 0xcf4(%rsp)
jmp 0x119b7a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcf8(%rsp)
movl %eax, 0xcf4(%rsp)
leaq 0xaf8(%rsp), %rdi
callq 0x112848
leaq 0xaf7(%rsp), %rdi
callq 0x112830
jmp 0x119c7f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcf8(%rsp)
movl %eax, 0xcf4(%rsp)
jmp 0x119c72
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcf8(%rsp)
movl %eax, 0xcf4(%rsp)
jmp 0x119bdc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcf8(%rsp)
movl %eax, 0xcf4(%rsp)
leaq 0xac8(%rsp), %rdi
callq 0x112848
leaq 0xac7(%rsp), %rdi
callq 0x112830
jmp 0x119c65
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcf8(%rsp)
movl %eax, 0xcf4(%rsp)
jmp 0x119c65
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcf8(%rsp)
movl %eax, 0xcf4(%rsp)
jmp 0x119c58
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcf8(%rsp)
movl %eax, 0xcf4(%rsp)
leaq 0x28(%rsp), %rdi
callq 0x11aeb0
jmp 0x119c58
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcf8(%rsp)
movl %eax, 0xcf4(%rsp)
leaq 0x178(%rsp), %rdi
callq 0x11b7d0
leaq 0xaa0(%rsp), %rdi
callq 0x11b9d0
leaq 0xae8(%rsp), %rdi
callq 0x11ba10
leaq 0xb18(%rsp), %rdi
callq 0x11ba90
leaq 0xb80(%rsp), %rdi
callq 0x11bac0
leaq 0xd08(%rsp), %rdi
callq 0x112848
movq 0xcf8(%rsp), %rdi
callq 0x1124e0
nopw %cs:(%rax,%rax)