// File: bsegovia[P]boodew/tests.cpp
// Function: main
int main(int argc, const char *argv[]) {
  // global variable
  run("echo ($ some_global)");
  run("var f [echo (* ($ 0)($ 0))]; ($ f) 3");
  run("var x 1; var y 2; echo (+ ($ x))",true);

  // string substitution
  run("var i; echo [hop@($ i)]");
  run("var i 4; echo [hop@(int ($ i))]");
  run("var str [[bla @(.. [echo] [ 4])]]; echo ($ str)");
  run("var str [[bla @(.. [echo] [ 4])]]; (($ str))");

  // delayed string substitution
  run("var i 4; echo [hop@[($ i)]");
  run("var i 4; echo [hop@@($ i)]");
  run("var i 4; echo [[hop@($ i)]]");

  // loop + control flow
  run("loop i 16 [? (< ($ i) 8) [echo ($ i)] [break]]");
  run("loop i 16 [? (< ($ i) 8) [echo ($ i)] [continue]]");
  run("echo (do [loop i 16 [? (!= ($ i) 8) [echo ($ i)] [return (int (- ($ i) 1))]]])");

  // more conditionals
  run("var i 5; var hop salut; echo (? (< ($ i) 3) [do [return [@(echo ($ hop))]]])");
  run("var i 5; var hop salut; echo (? (> ($ i) 3) [do [return [@(echo ($ hop))]]])");

  // dynamic scoping
  run("var fn [echo ($ in_upper_scope)]; (var in_upper_scope bim); ($ fn)");

  // simple echo
  run("echo deded; echo er");

  // simple operator
  run("echo (+ 1 2)");

  // string concat
  run("echo (.. (.. a bb) (+ 1 2))");
  run("echo (.. (.. a bb) cc)");

  // storing a function in a variable
  run("var fn [echo ($ 0)]; ($ fn) boum\n($ fn) boum2");
  run("# [this is a comment]; var fn [echo ($ 0)]; ($ fn) boum\n($ fn) boum2");

  // function arguments currying
  run("var bind [do [return [[@@($ 0) @@($ 1) ($ 0)]]]]; echo ((($ bind) + 2) 3)");
  run("var bind [do [return [[@@($ 0) @@($ 1) ($ 0)]]]];"
      "var plus (($ bind) + 2);"
      "echo (int (do [return (($ plus) 3)]))");
  run("var bind [^ [[@@($ 0) @@($ 1) ($ 0)]]];"
      "var plus (($ bind) + 2);"
      "echo (int (do [return (($ plus) 3)]))");
  run("var bind [^ [[@@($ 0) @@($ 1) ($ 0)]]];"
      "var plus (($ bind) + 2);"
      "echo ((($ plus) 3))");
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq 0x17f5(%rip), %rdi      # 0x165e2
xorl %esi, %esi
callq 0x14f60
leaq 0x17fc(%rip), %rdi      # 0x165f7
xorl %esi, %esi
callq 0x14f60
leaq 0x1813(%rip), %rdi      # 0x1661c
movl $0x1, %esi
callq 0x14f60
leaq 0x1823(%rip), %rdi      # 0x1663d
xorl %esi, %esi
callq 0x14f60
leaq 0x182d(%rip), %rdi      # 0x16655
xorl %esi, %esi
callq 0x14f60
leaq 0x183f(%rip), %rdi      # 0x16675
xorl %esi, %esi
callq 0x14f60
leaq 0x1861(%rip), %rdi      # 0x166a5
xorl %esi, %esi
callq 0x14f60
leaq 0x1880(%rip), %rdi      # 0x166d2
xorl %esi, %esi
callq 0x14f60
leaq 0x188d(%rip), %rdi      # 0x166ed
xorl %esi, %esi
callq 0x14f60
leaq 0x189a(%rip), %rdi      # 0x16708
xorl %esi, %esi
callq 0x14f60
leaq 0x18a8(%rip), %rdi      # 0x16724
xorl %esi, %esi
callq 0x14f60
leaq 0x18c9(%rip), %rdi      # 0x16753
xorl %esi, %esi
callq 0x14f60
leaq 0x18ed(%rip), %rdi      # 0x16785
xorl %esi, %esi
callq 0x14f60
leaq 0x192e(%rip), %rdi      # 0x167d4
xorl %esi, %esi
callq 0x14f60
leaq 0x196d(%rip), %rdi      # 0x16821
xorl %esi, %esi
callq 0x14f60
leaq 0x19ac(%rip), %rdi      # 0x1686e
xorl %esi, %esi
callq 0x14f60
leaq 0x19e1(%rip), %rdi      # 0x168b1
xorl %esi, %esi
callq 0x14f60
leaq 0x19e7(%rip), %rdi      # 0x168c5
xorl %esi, %esi
callq 0x14f60
leaq 0x19e6(%rip), %rdi      # 0x168d2
xorl %esi, %esi
callq 0x14f60
leaq 0x19f4(%rip), %rdi      # 0x168ee
xorl %esi, %esi
callq 0x14f60
leaq 0x1a14(%rip), %rdi      # 0x1691c
xorl %esi, %esi
callq 0x14f60
leaq 0x19ef(%rip), %rdi      # 0x16905
xorl %esi, %esi
callq 0x14f60
leaq 0x1a26(%rip), %rdi      # 0x1694a
xorl %esi, %esi
callq 0x14f60
leaq 0x1a62(%rip), %rdi      # 0x16994
xorl %esi, %esi
callq 0x14f60
leaq 0x1ac3(%rip), %rdi      # 0x16a03
xorl %esi, %esi
callq 0x14f60
leaq 0x1b1a(%rip), %rdi      # 0x16a68
xorl %esi, %esi
callq 0x14f60
xorl %eax, %eax
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax)