Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ps 4 #107

Merged
merged 59 commits into from
Oct 24, 2011
Merged

Ps 4 #107

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
3ee676d
Initial commit
awatanabe Oct 14, 2011
f237fe0
Merge branch 'master' of github.com:spartango/CS153 into ps_4
awatanabe Oct 14, 2011
b8df54f
Added ps3 compile code to ps4
awatanabe Oct 14, 2011
ab66aba
Added utility file.
awatanabe Oct 14, 2011
2e4acd4
Allows compilation with old compile code
awatanabe Oct 14, 2011
e622b93
Implemented load and store
awatanabe Oct 14, 2011
fef3576
Implemented load and store
awatanabe Oct 14, 2011
a9761fd
minor changes
spartango Oct 14, 2011
2aa6ed6
unmessed up merging lol
spartango Oct 14, 2011
966adb6
Merge branch 'ps_4' of github.com:spartango/CS153 into ps_4
awatanabe Oct 19, 2011
4ce5010
added description of env
spartango Oct 19, 2011
96db18c
Pulling env into its own nice file
spartango Oct 19, 2011
35ef913
moving things around to create a coherent flow in the logic
spartango Oct 19, 2011
8f94119
moving stuff around still...adding lookup
spartango Oct 19, 2011
12cfff8
moving to a mode where i dont build asts by hand, cause that sucks
spartango Oct 19, 2011
5f33b4e
adding env push
spartango Oct 19, 2011
233c2ff
fixed up stuff so it actually compiles
spartango Oct 19, 2011
be74062
starting to fill in compile unit
spartango Oct 22, 2011
6e9db33
added real stubs
spartango Oct 22, 2011
0e680d4
Added int compile
awatanabe Oct 22, 2011
85c95a5
added virtual stack for code gen
spartango Oct 22, 2011
1a20699
Merge branch 'ps_4_env' of github.com:spartango/CS153 into ps_4_call
awatanabe Oct 22, 2011
cfda67e
minor change
spartango Oct 22, 2011
558be9c
Updated changes from ps_4_env
awatanabe Oct 22, 2011
71de648
Re-implemented int
awatanabe Oct 22, 2011
efea561
pseudocode
spartango Oct 22, 2011
cda0f97
Added lookup calls
spartango Oct 22, 2011
4d6bfba
Put in integer junk
spartango Oct 22, 2011
240e2eb
moving toward proper stack use, intermediate commit
spartango Oct 22, 2011
9d6c452
moivng toward closure
spartango Oct 22, 2011
448b7b9
implemented closure
spartango Oct 22, 2011
a88d5bc
Helpers for PrimApp
awatanabe Oct 22, 2011
8744e26
Put in if code, untested
spartango Oct 22, 2011
0d65816
Fixed int
awatanabe Oct 22, 2011
32c5fec
Merge branch 'ps_4_call' of github.com:spartango/CS153 into ps_4_env
spartango Oct 22, 2011
37ee24c
merge effects
spartango Oct 22, 2011
eabde1c
compiles
spartango Oct 22, 2011
caa3ab5
Implementation of Cons
awatanabe Oct 22, 2011
dd4c79e
Fixed bugs in PrimApp code to allow for compile
awatanabe Oct 22, 2011
56e956b
Compling code and works for single integers
awatanabe Oct 23, 2011
5119b6f
Allowing for binop compilation
awatanabe Oct 23, 2011
388368d
Gave temps and function their own counters
awatanabe Oct 23, 2011
41a9b50
Binops compiling and running
awatanabe Oct 23, 2011
111c536
Continued code cleanup
awatanabe Oct 23, 2011
a635e02
Fixed stack overflow for closure creation
awatanabe Oct 23, 2011
cee8652
Changed compile_exp so main is appended onto function list
awatanabe Oct 23, 2011
7743f93
Changed implementation of init_env/result
awatanabe Oct 23, 2011
2f1c69d
Reorganized location of some functions
awatanabe Oct 23, 2011
cfaa121
Compiles and runs correctly
awatanabe Oct 23, 2011
dd27273
cleaned up code in compile
awatanabe Oct 23, 2011
0fb04db
Added some comments
awatanabe Oct 23, 2011
c10bf8e
fixed a cons bug and added tests
spartango Oct 24, 2011
d54bb01
Fixed error in access_mem
awatanabe Oct 24, 2011
234ab57
Merge branch 'ps_4_call' of github.com:spartango/CS153 into ps_4_call
awatanabe Oct 24, 2011
93d7733
added a fancier test
spartango Oct 24, 2011
3c228cc
Added guard for length of exps list for primaps
awatanabe Oct 24, 2011
fc0fde9
Merge branch 'ps_4_call' of github.com:spartango/CS153 into ps_4_call
awatanabe Oct 24, 2011
dd6602e
minor test stuff
spartango Oct 24, 2011
643a119
Merge pull request #106 from spartango/ps_4_call
spartango Oct 24, 2011
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added guard for length of exps list for primaps
  • Loading branch information
awatanabe committed Oct 24, 2011
commit 3c228ccc12c8bac3a82ff4d975954ecea5be890d
14 changes: 10 additions & 4 deletions ps4/scish_compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ let rec compile_exp_r ( t_expr : Scish_ast.exp )

| PrimApp(op, exps) ->
let binop (oper: string) : func list * var list * Cish_ast.stmt =
(* Verify that expression list is only length 2 *)
let _ = verify_length exps 2 in
(* Compile expression and store result in temp1 *)
let (temp1, (f_list1, scope1, stmt1)) = compile_store (List.hd exps) f_list scope in
(* Compile second expression, storing result in result *)
Expand All @@ -51,8 +53,10 @@ let rec compile_exp_r ( t_expr : Scish_ast.exp )
(* Concatinate statements using Seq *)
(f_list2, scope2, (init_var temp1 (seqs [stmt1; stmt2; end_stmt]))) in

(* Accesses the address ex in memory with an offset in bytes of offset *)
let access_mem (ex: Scish_ast.exp) (fs: func list) (s: var list) (offset: int) =
(* Accesses tuple at address ex in memory with an offset in bytes of offset *)
let access_tuple (ex: Scish_ast.exp) (fs: func list) (s: var list) (offset: int) =
(* Verify exps is one argument long for fst/snd *)
let _ = verify_length exps 1 in
(* Compiles ex, placing result in result *)
let(f_list1, scope1, stmt1) = compile_exp_r ex f_list scope in
(* Places value at (ex+offset) in result *)
Expand All @@ -65,6 +69,8 @@ let rec compile_exp_r ( t_expr : Scish_ast.exp )
| Times -> binop "*"
| Div -> binop "/"
| Cons ->
(* Verify that exps is length 2 *)
let _ = verify_length exps 2 in
let tuple_address = new_temp () in
(* Create space to store tuple *)
let init_stmt = cish_stmt_from_str (tuple_address ^ " = malloc(8);") in
Expand All @@ -79,8 +85,8 @@ let rec compile_exp_r ( t_expr : Scish_ast.exp )
let mv_result = cish_stmt_from_str (result_name^" = "^tuple_address^";") in
(f_list2, scope2, (init_var tuple_address (seqs [init_stmt; stmt1; store_stmt1; stmt2; store_stmt2; mv_result])))
(* create a pair *)
| Fst -> access_mem (List.hd exps) f_list scope 0
| Snd -> access_mem (List.hd exps) f_list scope 4
| Fst -> access_tuple (List.hd exps) f_list scope 0
| Snd -> access_tuple (List.hd exps) f_list scope 4
| Eq -> binop "=="
| Lt -> binop "<")

Expand Down
6 changes: 6 additions & 0 deletions ps4/utility.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ let null = Int(0);;

let result_name = "result";;

exception InvalidExpressionListLength
let verify_length (ls: 'a list) (expected: int): unit =
if (List.length ls) = expected
then ()
else raise InvalidExpressionListLength

(* Glues a list of statements together with Seq *)
let rec seqs (stmts : Cish_ast.stmt list) : Cish_ast.stmt =
match stmts with
Expand Down