• Home
  • Raw
  • Download

Lines Matching +full:turing +full:- +full:complete

12 LLVM <index.html>`_" tutorial. Chapters 1-3 described the implementation
111 to make complete decisions about what optimizations to use, in which
117 program). It also supports and includes "per-function" passes which just
127 to run a few per-function optimizations as the user types the function
132 In order to get per-function optimizations going, we need to set up a
133 `Llvm.PassManager <../WritingAnLLVMPass.html#what-passmanager-does>`_ to hold and
137 .. code-block:: ocaml
147 (* Do simple "peephole" optimizations and bit-twiddling optzn. *)
181 .. code-block:: ocaml
220 passes <../Passes.html>`_ is available, but it isn't very complete.
226 Now that we have reasonable code coming out of our front-end, lets talk
241 function bodies as they do now, but immediately evaluate the top-level
249 .. code-block:: ocaml
269 can change the code that parses a top-level expression to look like
272 .. code-block:: ocaml
274 (* Evaluate a top-level expression into an anonymous function. *)
276 print_endline "parsed a top-level expr";
288 Recall that we compile top-level expressions into a self-contained LLVM
337 for all non-JIT'd functions transitively called from the anonymous
344 powerful capabilities - check this out (I removed the dump of the
397 .. code-block:: c++
399 /* putchard - putchar that takes a double and returns 0. */
413 tutorial. At this point, we can compile a non-Turing-complete
414 programming language, optimize and JIT compile it in a user-driven way.
422 Here is the complete code listing for our running example, enhanced with
425 .. code-block:: bash
443 .. code-block:: ocaml
453 flag ["link"; "ocaml"; "g++"] (S[A"-cc"; A"g++"]);;
457 .. code-block:: ocaml
459 (*===----------------------------------------------------------------------===
461 *===----------------------------------------------------------------------===*)
476 .. code-block:: ocaml
478 (*===----------------------------------------------------------------------===
480 *===----------------------------------------------------------------------===*)
484 | [< ' (' ' | '\n' | '\r' | '\t'); stream >] -> lex stream
486 (* identifier: [a-zA-Z][a-zA-Z0-9] *)
487 | [< ' ('A' .. 'Z' | 'a' .. 'z' as c); stream >] ->
492 (* number: [0-9.]+ *)
493 | [< ' ('0' .. '9' as c); stream >] ->
499 | [< ' ('#'); stream >] ->
503 | [< 'c; stream >] ->
507 | [< >] -> [< >]
510 | [< ' ('0' .. '9' | '.' as c); stream >] ->
513 | [< stream=lex >] ->
517 | [< ' ('A' .. 'Z' | 'a' .. 'z' | '0' .. '9' as c); stream >] ->
520 | [< stream=lex >] ->
522 | "def" -> [< 'Token.Def; stream >]
523 | "extern" -> [< 'Token.Extern; stream >]
524 | id -> [< 'Token.Ident id; stream >]
527 | [< ' ('\n'); stream=lex >] -> stream
528 | [< 'c; e=lex_comment >] -> e
529 | [< >] -> [< >]
532 .. code-block:: ocaml
534 (*===----------------------------------------------------------------------===
536 *===----------------------------------------------------------------------===*)
538 (* expr - Base type for all expression nodes. *)
552 (* proto - This type represents the "prototype" for a function, which captures
557 (* func - This type represents a function definition itself. *)
561 .. code-block:: ocaml
563 (*===---------------------------------------------------------------------===
565 *===---------------------------------------------------------------------===*)
567 (* binop_precedence - This holds the precedence for each binary operator that is
571 (* precedence - Get the precedence of the pending binary operator token. *)
572 let precedence c = try Hashtbl.find binop_precedence c with Not_found -> -1
580 | [< 'Token.Number n >] -> Ast.Number n
583 | [< 'Token.Kwd '('; e=parse_expr; 'Token.Kwd ')' ?? "expected ')'" >] -> e
588 | [< 'Token.Ident id; stream >] ->
590 | [< e=parse_expr; stream >] ->
592 | [< 'Token.Kwd ','; e=parse_args (e :: accumulator) >] -> e
593 | [< >] -> e :: accumulator
595 | [< >] -> accumulator
601 'Token.Kwd ')' ?? "expected ')'">] ->
605 | [< >] -> Ast.Variable id
609 | [< >] -> raise (Stream.Error "unknown token when expecting an expression.")
616 | Some (Token.Kwd c) when Hashtbl.mem binop_precedence c ->
631 | Some (Token.Kwd c2) ->
638 | _ -> rhs
645 | _ -> lhs
650 | [< lhs=parse_primary; stream >] -> parse_bin_rhs 0 lhs stream
656 | [< 'Token.Ident id; e=parse_args (id::accumulator) >] -> e
657 | [< >] -> accumulator
664 'Token.Kwd ')' ?? "expected ')' in prototype" >] ->
668 | [< >] ->
673 | [< 'Token.Def; p=parse_prototype; e=parse_expr >] ->
678 | [< e=parse_expr >] ->
684 | [< 'Token.Extern; e=parse_prototype >] -> e
687 .. code-block:: ocaml
689 (*===----------------------------------------------------------------------===
691 *===----------------------------------------------------------------------===*)
704 | Ast.Number n -> const_float double_type n
705 | Ast.Variable name ->
707 | Not_found -> raise (Error "unknown variable name"))
708 | Ast.Binary (op, lhs, rhs) ->
713 | '+' -> build_add lhs_val rhs_val "addtmp" builder
714 | '-' -> build_sub lhs_val rhs_val "subtmp" builder
715 | '*' -> build_mul lhs_val rhs_val "multmp" builder
716 | '<' ->
720 | _ -> raise (Error "invalid binary operator")
722 | Ast.Call (callee, args) ->
726 | Some callee -> callee
727 | None -> raise (Error "unknown function referenced")
738 | Ast.Prototype (name, args) ->
744 | None -> declare_function name ft the_module
748 | Some f ->
760 Array.iteri (fun i a ->
768 | Ast.Function (proto, body) ->
789 with e ->
794 .. code-block:: ocaml
796 (*===----------------------------------------------------------------------===
797 * Top-Level parsing and JIT Driver
798 *===----------------------------------------------------------------------===*)
806 | None -> ()
808 (* ignore top-level semicolons. *)
809 | Some (Token.Kwd ';') ->
813 | Some token ->
816 | Token.Def ->
820 | Token.Extern ->
824 | _ ->
825 (* Evaluate a top-level expression into an anonymous function. *)
827 print_endline "parsed a top-level expr";
838 with Stream.Error s | Codegen.Error s ->
847 .. code-block:: ocaml
849 (*===----------------------------------------------------------------------===
851 *===----------------------------------------------------------------------===*)
865 Hashtbl.add Parser.binop_precedence '-' 20;
880 (* Do simple "peephole" optimizations and bit-twiddling optzn. *)
904 .. code-block:: c
908 /* putchard - putchar that takes a double and returns 0. */