BED-Con talk Convert PHP code Recent converter examples

Recent converter examples

1 This is before
2 <?php
3     print "Hello" . " " . "world";
4 ?>
5 This is after
1 trait hello_world extends JbjCodeUnit {
2 
3   def exec(implicit ctx: Context) {
4     
5     inline("This is before\n")
6     print(p("Hello") !! p(" ") !! p("world"))
7     inline("This is after\n")
8   }
9 }
 1 <?php
 2 $a = "Hello";
 3 $b = "world";
 4 $c = $a . " " . $b;
 5 
 6 echo $c;
 7 
 8 $d = $c + 42;
 9 
10 echo $d;
11 ?>
 1 trait hello_world2 extends JbjCodeUnit {
 2 
 3   def exec(implicit ctx: Context) {
 4     val a = lvar("a")
 5     val b = lvar("b")
 6     val c = lvar("c")
 7     val d = lvar("d")
 8     
 9     a := p("Hello")
10     b := p("world")
11     c := a !! p(" ") !! b
12     echo(c)
13     d := c + p(42L)
14     echo(d)
15   }
16 }
 1 <?php
 2     $a = array("Hello", "World", 42);
 3 
 4     for($i = 0; $i < count($a); $i++) {
 5         echo $a[$i];
 6         $a[$i] = ($i + 2) * $i + 1;
 7         echo "\n";
 8     }
 9 
10     for($i = 0; $i < count($a); $i++) {
11         echo $a[$i];
12         echo "\n";
13     }
14 ?>
 1 trait hello_world3 extends JbjCodeUnit {
 2 
 3   def exec(implicit ctx: Context) {
 4     val a = lvar("a")
 5     val i = lvar("i")
 6     
 7     a := array(p("Hello"), p("World"), p(42L))
 8     pFor(i := p(0L), i < p(count(a)), i.++) {
 9       echo(a.dim(i))
10       a.dim(i) := (i + p(2L)) * i + p(1L)
11       echo(p("\n"))
12     }
13     pFor(i := p(0L), i < p(count(a)), i.++) {
14       echo(a.dim(i))
15       echo(p("\n"))
16     }
17   }
18 }
 1 <?php
 2 
 3 function specialSum($a, $b) {
 4     if ($a < 10) {
 5         return 2 * $a + $b;
 6     } else {
 7         return $a + $b;
 8     }
 9 }
10 
11 echo specialSum(2, 3);
12 echo "\n";
13 echo specialSum(6, 7);
14 echo "\n";
15 echo specialSum(12, 13);
16 echo "\n";
17 ?>
 1 trait hello_world4 extends JbjCodeUnit {
 2 
 3   def specialSum(a: PVal, b: PVal)(implicit callerCtx: Context): PAny =
 4     functionCtx("specialSum",callerCtx) { ctx:Context =>
 5       _specialSum(lvar("a", a)(ctx), lvar("b", b)(ctx))(ctx)
 6     }
 7     
 8   def _specialSum(a: Reference, b: Reference)(implicit ctx: Context): PAny = {
 9     
10     if(a < p(10L)) {
11        p(2L) * a + b
12     } else { 
13        a + b
14     }
15   }
16   
17   def exec(implicit ctx: Context) {
18     
19     echo(p(specialSum(p(2L), p(3L))))
20     echo(p("\n"))
21     echo(p(specialSum(p(6L), p(7L))))
22     echo(p("\n"))
23     echo(p(specialSum(p(12L), p(13L))))
24     echo(p("\n"))
25   }
26 }