Skip to content

Commit

Permalink
went back to unqual, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-87 committed Sep 16, 2023
1 parent 80eef34 commit fe5d9c5
Show file tree
Hide file tree
Showing 24 changed files with 535 additions and 173 deletions.
3 changes: 1 addition & 2 deletions lib/backend/add_new.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
open Khagm
open Middleend
(* Gives the lambda lifted things names *)
(** Gives the lambda lifted things names *)

let rec add_new top nms =
match top with
Expand Down
9 changes: 4 additions & 5 deletions lib/backend/emit_c.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
open Khagm
open Add_new
open Helpers
open Exp
open KhasmUTF

Expand All @@ -16,7 +15,7 @@ let mangler id =
"_" ^ string_of_int asint ^ "_"

let mangle_top nms id =
let (Some nm) = Middleend.Kir.get_bind_id nms id in
let (Some nm) = Kir.get_bind_id nms id in
let nm = snd nm in
match nm with "main" -> "main_____Khasm" | _ -> utf8_map mangler nm

Expand Down Expand Up @@ -46,7 +45,7 @@ let function_name name argnum =
^ ", " ^ string_of_int argnum ^ ", " ^ args ^ ") {\n"

let is_toplevel id tbl =
match Middleend.Kir.get_bind_id tbl id with Some _ -> true | None -> false
match Kir.get_bind_id tbl id with Some _ -> true | None -> false

let lookup x (tbl : (khagmid * string) list) =
match List.assoc_opt x tbl with
Expand All @@ -65,8 +64,8 @@ let adds_default () = [ "IFELSETEMP" ]
let adds = ref [ "IFELSETEMP" ]

let emit_ptr tbl name =
let (Some (_, nm')) = Middleend.Kir.get_bind_id tbl name in
match Middleend.Kir.get_constr tbl nm' with
let (Some (_, nm')) = Kir.get_bind_id tbl name in
match Kir.get_constr tbl nm' with
| Some (_, arity, _) ->
if arity = 0 then
mangle_top tbl name ^ "()"
Expand Down
4 changes: 2 additions & 2 deletions lib/backend/khagm.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Helpers.Exp
open Exp

type khagmid = int [@@deriving show { with_path = false }]

Expand Down Expand Up @@ -28,5 +28,5 @@ type khagmtop =
| Noop
[@@deriving show { with_path = false }]

type khagm = khagmtop list * Middleend.Kir.kir_table
type khagm = khagmtop list * Kir.kir_table
[@@deriving show { with_path = false }]
4 changes: 2 additions & 2 deletions lib/backend/native.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Helpers.Exp
open Exp
open Args

let gen_main () =
Expand Down Expand Up @@ -29,7 +29,7 @@ let prelude () =
|}

let flags =
Helpers.KhasmUTF.utf8_map
KhasmUTF.utf8_map
(fun x ->
if x = "\n" then
""
Expand Down
2 changes: 1 addition & 1 deletion lib/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(include_subdirs qualified)
(include_subdirs unqualified)

(ocamllex lexer)

Expand Down
12 changes: 5 additions & 7 deletions lib/front_to_middle/translateftm.ml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
open Helpers.Exp
open Frontend
open Middleend
open Helpers

open Exp
open Either

open ListHelpers
(** Converts between the frontend IR and the middleend IR. *)

let rec fold_tup_flat f s l =
Expand Down Expand Up @@ -123,12 +121,12 @@ and push_bind_into_expr tbl ident kirexpr kexpr =

and split_on head body outputs =
let open Ast in
let open ListHelpers in
let open List in
let comp i (pat, expr) =
match List.hd pat with
| MPApp (q, _) ->
if i = q then
True
ListHelpers.True
else
False
| _ -> Both
Expand Down
2 changes: 1 addition & 1 deletion lib/frontend/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type info = {
}
[@@deriving show { with_path = false }]

let dummy_info () = { id = -1; complex = -2 }
let dummyinfo = { id = 0; complex = 0 }
let idgen = ref 0

let getid () =
Expand Down
2 changes: 1 addition & 1 deletion lib/frontend/complexity.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
open Ast
open Helpers.Exp
open Exp

(* Computes a complexity for each node. Not currently used. *)

Expand Down
26 changes: 17 additions & 9 deletions lib/frontend/elim_modules.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open Ast
open Helpers.Exp
open Exp

open Helpers.ListHelpers
open ListHelpers
(** Elimintates modules from a list of programs, reducing them to a
flat file structure with fully resolved names *)

Expand Down Expand Up @@ -403,13 +403,13 @@ let%test "Elim modules all" =
[
TopAssign
( ("d", TSBase "int"),
("d", [], Base (mkinfo (), Int "1")) );
("d", [], Base (dummyinfo, Int "1")) );
] );
] );
] );
TopAssign
( ("one", TSBase "int"),
("one", [], ModAccess (mkinfo (), [ "a"; "b"; "c" ], "d")) );
("one", [], ModAccess (dummyinfo, [ "a"; "b"; "c" ], "d")) );
]
in
match elim [ prog ] with
Expand All @@ -419,16 +419,24 @@ let%test "Elim modules all" =
[
TopAssign
( ("khasm.a.b.c.d", TSBase "int"),
("khasm.a.b.c.d", [], Base ({ id = 1; complex = -1 }, Int "1"))
("khasm.a.b.c.d", [], Base (dummyinfo, Int "1"))
);
TopAssign
( ("khasm.one", TSBase "int"),
( "khasm.one",
[],
Base
( { id = 0; complex = -1 },
Ident ({ id = 0; complex = -1 }, "khasm.a.b.c.d") ) ) );
(dummyinfo,
Ident (dummyinfo, "khasm.a.b.c.d") ) ) );
]
in
after = should
| _ -> false
if after = should then
true
else
begin
print_endline (show_program after);
print_endline (show_program should);
false
end
| _ ->
false
13 changes: 8 additions & 5 deletions lib/frontend/parser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ type token =
| RPAREN
| EMPTY
| ANY
| UNDERSCORE
[@@deriving show { with_path = false }]

exception ParseError

open Ast
open Helpers.ListHelpers
open ListHelpers

module Lexing = struct
include Lexing
Expand Down Expand Up @@ -122,7 +123,7 @@ let parse_error lines (offsets : Lexing.position) actual follow_set =
print_endline @@ "Expected ["
^ delim ", " (List.map show_token follow_set)
^ "]"
with Invalid_argument _ ->
with Invalid_argument _ | Failure _ ->
print_endline @@ "Error in file " ^ offsets.pos_fname ^ " line "
^ string_of_int offsets.pos_lnum;
print_endline @@ "Got " ^ show_token actual;
Expand Down Expand Up @@ -197,7 +198,7 @@ module ParserState = struct
end

open ParserState
open Helpers.Exp
open Exp

let rec id_list state =
match peek state 1 with
Expand Down Expand Up @@ -415,6 +416,9 @@ and parse_match_list state =
| T_IDENT t ->
toss state;
MPId t :: parse_match_list state
| UNDERSCORE ->
toss state;
MPWild :: parse_match_list state
| LPAREN -> (
toss state;
match peek state 1 with
Expand All @@ -434,6 +438,7 @@ and parse_match_pattern state =
MPApp (t, [])
| T_IDENT t -> (
match parse_match_list state with [] -> MPId t | xs -> MPApp (t, xs))
| UNDERSCORE -> MPWild
| LPAREN -> (
match peek state 1 with
| RPAREN ->
Expand Down Expand Up @@ -726,9 +731,7 @@ and parse_module state =
SimplModule (name, top)

and parse_bind state =
expect state LPAREN;
let op = get_binop state in
expect state RPAREN;
(match pop state with EQ_OP "=" -> () | x -> error state x [ EQ_OP "=" ]);
let name = get_ident state in
Bind (op, [], name)
Expand Down
Loading

0 comments on commit fe5d9c5

Please sign in to comment.