-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from GlowingScrewdriver/memory-and-pointers
Add support for contiguous memory allocation and pointers
- Loading branch information
Showing
22 changed files
with
379 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
8989898 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(brilisp | ||
(bril-define ((print int) (n int))) | ||
|
||
(bril-define ((main int)) | ||
(set (inc int) (const 1)) | ||
(set (v int) (const 4545454)) | ||
(set (max int) (const 8989898)) | ||
(set (p (ptr int)) (alloc v)) | ||
(set (count int) (const 0)) | ||
|
||
(label lbl) | ||
(set (count int) (add count inc)) | ||
(store p v) | ||
(set (val int) (load p)) | ||
(set (loop bool) (ge count max)) | ||
(br loop end lbl) | ||
|
||
(label end) | ||
(set (tmp int) (call print count)) | ||
(ret tmp))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
8989898 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
(brilisp | ||
(bril-define ((print int) (n int))) | ||
|
||
(bril-define ((main int)) | ||
(set (inc int) (const 1)) | ||
(set (v int) (const 4545454)) | ||
(set (max int) (const 8989898)) | ||
(set (arr (ptr int)) (alloc v)) | ||
(set (count int) (const 0)) | ||
|
||
(label lbl) | ||
(set (arr_i (ptr int)) (ptradd arr count)) | ||
(set (count int) (add count inc)) | ||
(store arr_i v) | ||
(set (val int) (load arr_i)) | ||
(set (loop bool) (ge count max)) | ||
(br loop end lbl) | ||
|
||
(label end) | ||
(set (tmp int) (call print count)) | ||
(ret tmp))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
8989898 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
(brilisp | ||
(bril-define ((print int) (n int))) | ||
|
||
(bril-define ((main int)) | ||
(set (inc int) (const 1)) | ||
(set (v int) (const 4545)) | ||
(set (max int) (const 8989898)) | ||
(set (p (ptr int)) (alloc v)) | ||
(set (arr (ptr (ptr int))) (alloc v)) | ||
(set (count int) (const 0)) | ||
|
||
(label lbl) | ||
(set (arr_i (ptr (ptr int))) (ptradd arr count)) | ||
(set (count int) (add count inc)) | ||
(store arr p) | ||
(set (val (ptr int)) (load arr_i)) | ||
(set (loop bool) (ge count max)) | ||
(br loop end lbl) | ||
|
||
(label end) | ||
(set (tmp int) (call print count)) | ||
(ret tmp))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(brilisp | ||
(bril-define ((print int) (n int))) | ||
|
||
(bril-define ((print_bool int) (b bool)) | ||
(set (T int) (const 1)) | ||
(set (F int) (const 0)) | ||
(br b print_true print_false) | ||
(label print_true) | ||
(set (tmp int) (call print T)) | ||
(ret tmp) | ||
(label print_false) | ||
(set (tmp int) (call print F)) | ||
(ret tmp)) | ||
|
||
(bril-define ((main int)) | ||
(set (v int) (const 4)) | ||
(set (o1 int) (const 1)) | ||
(set (bp (ptr bool)) (alloc v)) | ||
(set (bp2 (ptr bool)) (ptradd bp o1)) | ||
(set (b bool) (const true)) | ||
(store bp b) | ||
(store bp2 b) | ||
(set (b bool) (load bp2)) | ||
(set (tmp int) (call print_bool b)) | ||
(ret tmp))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
55 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
(brilisp | ||
(bril-define ((print int) (n int))) | ||
|
||
(bril-define ((main int)) | ||
(set (len int) (const 10)) | ||
(set (arr (ptr int)) (alloc len)) | ||
(set (sum int) (const 0)) | ||
(set (idx int) (const 0)) | ||
(set (one int) (const 1)) | ||
|
||
(label init) | ||
(set (arr_i (ptr int)) (ptradd arr idx)) | ||
(set (idx int) (add idx one)) | ||
(store arr_i idx) | ||
(set (loop bool) (lt idx len)) | ||
(br loop init calc) | ||
|
||
(label calc) | ||
(set (idx int) (sub idx one)) | ||
(set (arr_i (ptr int)) (ptradd arr idx)) | ||
(set (v int) (load arr_i)) | ||
(set (sum int) (add sum v)) | ||
(set (loop bool) (ge idx one)) | ||
(br loop calc out) | ||
|
||
(label out) | ||
(set (tmp int) (call print sum)) | ||
(ret tmp))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
34 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
(brilisp | ||
(bril-define ((print int) (n int))) | ||
|
||
(bril-define ((main int)) | ||
(set (one int) (const 1)) | ||
(set (i int) (const 2)) | ||
(set (i_m_1 int) (const 1)) | ||
(set (i_m_2 int) (const 0)) | ||
(set (n int) (const 10)) | ||
(set (seq (ptr int)) (alloc n)) | ||
|
||
(set (v int) (const 0)) | ||
(store seq v) | ||
(set (v int) (const 1)) | ||
(set (p (ptr int)) (ptradd seq i_m_1)) | ||
(store p v) | ||
|
||
(label calc_i) | ||
(set (p_m_2 (ptr int)) (ptradd seq i_m_2)) | ||
(set (p_m_1 (ptr int)) (ptradd seq i_m_1)) | ||
(set (v_m_2 int) (load p_m_2)) | ||
(set (v_m_1 int) (load p_m_1)) | ||
(set (v int) (add v_m_1 v_m_2)) | ||
(set (p (ptr int)) (ptradd seq i)) | ||
(store p v) | ||
(set (i_m_1 int) (add i_m_1 one)) | ||
(set (i_m_2 int) (add i_m_2 one)) | ||
(set (i int) (add i one)) | ||
(set (loop bool) (le i n)) | ||
(br loop calc_i out) | ||
|
||
(label out) | ||
(set (i int) (sub n one)) | ||
(set (p (ptr int)) (ptradd seq i)) | ||
(set (v int) (load p)) | ||
(set (tmp int) (call print v)) | ||
(ret tmp))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(brilisp | ||
(bril-define ((print int) (n int))) | ||
|
||
(bril-define ((main int)) | ||
(set (v int) (const 1)) | ||
(set (p (ptr int)) (alloc v)) | ||
(set (v int) (const 7)) | ||
(store p v) | ||
|
||
(set (p2 (ptr int)) (id p)) | ||
(set (v int) (load p)) | ||
(set (tmp int) (call print v)) | ||
(ret tmp))) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
(brilisp | ||
(bril-define ((funcA void) (p (ptr int))) | ||
(ret)) | ||
|
||
(bril-define ((main void)) | ||
(set (five int) (const 5)) | ||
(set (x (ptr int)) (alloc five)) | ||
(set (tmp void) (call funcA x)) | ||
(ret))) |
Empty file.
Oops, something went wrong.