diff --git a/codegen.ml b/codegen.ml index 3ebf1c2..9c37d8a 100644 --- a/codegen.ml +++ b/codegen.ml @@ -459,7 +459,7 @@ let translate (globals, functions, structs) = |A.Dotop (e1, field) -> let e' = expr builder e1 in (match e1 with - A.Id s -> + A.Id s -> let e1typ = (match s with "newNode" -> A.StructType ("listNode") @@ -504,7 +504,8 @@ let translate (globals, functions, structs) = | _ -> raise (Failure("StructType not found.")) ) - |_ as e1_expr -> let e1'_llvalue = llvalue_expr_getter builder e1_expr in + |_ as e1_expr -> + let e1'_llvalue = llvalue_expr_getter builder e1_expr in let loaded_e1' = expr builder e1_expr in let e1'_lltype = L.type_of loaded_e1' in let e1'_struct_name_string_option = L.struct_name e1'_lltype in diff --git a/gridBasics.grid b/gridBasics.grid index 63a3335..41951f1 100644 --- a/gridBasics.grid +++ b/gridBasics.grid @@ -2,6 +2,8 @@ void addToGrid(int x, int y, Item listNode p_n){ *Item listNode iterator; Item listNode p_deref; + p_n.loc.x = x; + p_n.loc.y = y; if(GridNew[x][y] == None){ GridNew[x][y] = &p_n; @@ -11,13 +13,10 @@ void addToGrid(int x, int y, Item listNode p_n){ } else{ iterator = GridNew[x][y]; + colocation(x,y,p_n, iterator); while(iterator.next != None){ iterator = iterator.next; - if(iterator == &p_n){ - print("Item already on grid coordinate"); - return; - } - + colocation(x,y,p_n, iterator); } iterator.next = &p_n; iterator = iterator.next; diff --git a/helloworld.grid b/helloworld.grid index 0a18123..6d2bbb1 100644 --- a/helloworld.grid +++ b/helloworld.grid @@ -5,7 +5,6 @@ int checkGameEnd() return 1; } - Player { int x; @@ -14,10 +13,19 @@ Player Item horse hor; } +Item location +{ + int x; + int y; + int rule(coordinate c1, coordinate c2) { + return 1; + } +} Item horse{ int x; string s; + Item location loc; *Item horse next; int rule(coordinate c1, coordinate c2) { return 1; @@ -33,29 +41,25 @@ Item bishop{ } } +int colocation(int x, int y, Item listNode i1, Item listNode i2) +{ + print("Inside colocation"); + print(i2.nametag); + deleteFromGrid(x,y,i2.nametag); +} Grid_Init<2,2> grid; int gameloop(){ Player p1; Player p2; - Player myown; + Player p3; Item listNode headnode; Item horse h1; - Item horse h2; - Item horse h3; - Item horse h4; - Item bishop b4; - p2.x = 79; - print(p1.x); + h1.loc.x = 1; + p1.x = 79; + Grid <1,0> <-- p1.hor; Grid <1,0> <-- p2.hor; printGrid(); - - headnode = getHead(1,0); - myown = *(headnode.owner); - print(myown.x); return 0; - - - } diff --git a/preprocess.ml b/preprocess.ml index a640b21..089b40e 100644 --- a/preprocess.ml +++ b/preprocess.ml @@ -16,7 +16,7 @@ let process_files filename1 = try ignore (Str.search_forward re s1 0); true with Not_found -> false in - let defaultPlayerStructFormals = "coordinate pos;\n" ^ "bool win;\n" ^ "string displayString;\n" ^ "bool exists;\n" + let defaultPlayerStructFormals = "bool win;\n" ^ "string displayString;\n" ^ "bool exists;\n" in let playerStruct = "Player {\n" ^ defaultPlayerStructFormals ^ "}\n" @@ -122,7 +122,7 @@ let process_files filename1 = List.rev (lines) in let concat = List.fold_left (fun a x -> a ^ x) "" in - let temp = !listNode ^ "string type;\n*Item listNode next;\nstring nametag;\nstring tagname;\n*Player owner;\nint rule(coordinate c1, coordinate c2) {\nreturn 1;\n}\n}\n" ^ concat (read_all_lines filename1) in + let temp = !listNode ^ "Item location loc;\nstring type;\n*Item listNode next;\nstring nametag;\nstring tagname;\n*Player owner;\nint rule(coordinate c1, coordinate c2) {\nreturn 1;\n}\n}\n" ^ concat (read_all_lines filename1) in if (!tempImportFile = "") then begin if(!playerStuctFound = false) then diff --git a/scanner.mll b/scanner.mll index 1303b1e..0176d8d 100644 --- a/scanner.mll +++ b/scanner.mll @@ -47,7 +47,7 @@ rule token = parse | "Grid_Init" { GRIDINIT } | "Grid" { GRID } | "Player" { PLAYER } -| "Item" { ITEM } (*Hacky. Since both Player and Item are just structs, we can avoid code duplication by having PLAYER as token for both*) +| "Item" { ITEM } | ['0'-'9']+ as lxm { LITERAL(int_of_string lxm) } | ['a'-'z' 'A'-'Z']['a'-'z' 'A'-'Z' '0'-'9' '_']* as lxm { ID(lxm) } | '"'([^'"']* as lxm)'"' { STRING_LIT(lxm) }