Skip to content

Commit

Permalink
Basic colocation (explicitly passing x and y)
Browse files Browse the repository at this point in the history
  • Loading branch information
sagardmni committed May 7, 2017
1 parent 4e1d2de commit cb2ead0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
5 changes: 3 additions & 2 deletions codegen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions gridBasics.grid
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
34 changes: 19 additions & 15 deletions helloworld.grid
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ int checkGameEnd()
return 1;
}


Player
{
int x;
Expand All @@ -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;
Expand All @@ -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;



}
4 changes: 2 additions & 2 deletions preprocess.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scanner.mll
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down

0 comments on commit cb2ead0

Please sign in to comment.