extends base

block head
  title c0db

  link(rel="stylesheet" href="/codemirror.css")


block nav
  +navbar("home")

block body
  .container
    .row
      .col-md-6
        form
          .form-group
            label(for="inputCode") Code
            button(onclick="compile()" type="button").btn.btn-default.btm-btn.pull-right Compile
            #codearea
            textarea.code.formControl.sh_c(rows="12" id="inputCode")
 
      .col-md-6
        p.lbl.
           Bytecode
        pre#bytecode.panel.panel-default.code.sh_c.
           &nbsp;
    .row
      .col-md-12
        p.lbl.
          Output
        button(type="button")#run.btn.btn-default.btm-btn.pull-right Run
        pre#output.panel.panel-default.code
          &nbsp;

  
block script
  script(type="text/javascript" src="codemirror-compressed.js")
  script(type="text/javascript" src="vm/vm.js")

  script(type='text/javascript').
    var cmCodeInput = CodeMirror.fromTextArea($("#inputCode"));

    function callback(data) {
      $("#bytecode").text(decodeURIComponent(data.data));
    }

    function compile() {
      var code = encodeURIComponent($("#inputCode").val());
      $.ajax({
              type: "GET",
              async: true,
              url: "http://www.contrib.andrew.cmu.edu/~amgutier/cc0.cgi",
              dataType: "jsonp",
              data: {
                data: code
              },
              jsonpCallback: "callback"
      });
    }
