Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nddrylliog
committed
May 14, 2010
1 parent
da478e7
commit 0f325fc
Showing
12 changed files
with
254 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import structs/ArrayList | ||
|
||
Operation: class { | ||
|
||
types := ["+", "-", "/", "*"] as ArrayList<String> | ||
staticTypes := static ["%", "**", "^", "!"] as ArrayList<String> | ||
|
||
} | ||
|
||
main: func { | ||
|
||
op := Operation new() | ||
|
||
//blah := op types | ||
//printf("blah is of type %s\n", blah class name) | ||
|
||
//for(i in 0..op types size()) { | ||
// op types[i] println() | ||
//} | ||
|
||
//for(i in 0..Operation staticTypes size()) { | ||
// Operation staticTypes[i] println() | ||
//} | ||
|
||
//localTypes := ["$", "&", "|", "@"] as ArrayList<String> | ||
|
||
//for(i in 0..localTypes size()) { | ||
// localTypes[i] println() | ||
//} | ||
|
||
} |
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,24 @@ | ||
import structs/ArrayList | ||
|
||
/** | ||
* Literals, type inferred, implicit degradation to raw C arrays. | ||
*/ | ||
main: func { | ||
|
||
print(["Jo" + "hn", "Doe"]) | ||
printRaw(["Jo" + "hn", "Doe"]) | ||
printArrayList(["Jo" + "hn", "Doe"]) | ||
|
||
} | ||
|
||
print: func (array: String[]) { | ||
"First name: %s, Last name: %s" format(array[0], array[1]) println() | ||
} | ||
|
||
printRaw: func (array: String*) { | ||
"First name: %s, Last name: %s" format(array[0], array[1]) println() | ||
} | ||
|
||
printArrayList: func (array: ArrayList<String>) { | ||
"First name: %s, Last name: %s" format(array[0], array[1]) println() | ||
} |
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,29 @@ | ||
|
||
|
||
Operation: class { | ||
|
||
types := ["+", "-", "/", "*"] | ||
|
||
staticTypes := static ["%", "**", "^", "!"] | ||
|
||
} | ||
|
||
main: func { | ||
|
||
op := Operation new() | ||
|
||
for(i in 0..op types length) { | ||
op types[i] println() | ||
} | ||
|
||
for(i in 0..Operation staticTypes length) { | ||
Operation staticTypes[i] println() | ||
} | ||
|
||
localTypes := ["$", "&", "|", "@"] | ||
|
||
for(i in 0..localTypes length) { | ||
localTypes[i] println() | ||
} | ||
|
||
} |
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,18 @@ | ||
|
||
/** | ||
* Pure 1D declaration + allocation, printing. | ||
*/ | ||
main: func { | ||
|
||
array := Int[3] new() | ||
|
||
for(i in 0..array length) { | ||
array[i] = i + 1 | ||
} | ||
|
||
for(i in 0..array length) { | ||
printf("%d ", array[i]) | ||
} | ||
println() | ||
|
||
} |
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 @@ | ||
|
||
/** | ||
* Pure 2D declaration + allocation, printing. | ||
*/ | ||
main: func { | ||
|
||
array := Int[2][3] new() | ||
|
||
for(i in 0..array length) { | ||
for(j in 0..array[i] length) { | ||
array[i][j] = i * array length + j | ||
} | ||
} | ||
|
||
for(i in 0..array length) { | ||
for(j in 0..array[i] length) { | ||
printf("%d ", array[i][j]) | ||
} | ||
println() | ||
} | ||
|
||
} |
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,14 @@ | ||
|
||
/** | ||
* Raw array literal, type inferred via declaration, printing. | ||
*/ | ||
main: func { | ||
|
||
array := [13, 14, 15] | ||
|
||
for(i in 0..array length) { | ||
printf("%d ", array[i]) | ||
} | ||
println() | ||
|
||
} |
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,14 @@ | ||
|
||
/** | ||
* Raw array literal, type inferred via cast, printing. | ||
*/ | ||
main: func { | ||
|
||
pointer := [1, 2, 3] as Int* | ||
|
||
for(i in 0..3) { | ||
printf("%d ", pointer[i]) | ||
} | ||
println() | ||
|
||
} |
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,19 @@ | ||
|
||
|
||
/** | ||
* Raw 1D declaration + allocation, printing. | ||
*/ | ||
main: func { | ||
|
||
array: Int[3] | ||
|
||
for(i in 0..3) { | ||
array[i] = i + 1 | ||
} | ||
|
||
for(i in 0..3) { | ||
printf("%d ", array[i]) | ||
} | ||
println() | ||
|
||
} |
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,14 @@ | ||
|
||
/** | ||
* Raw array literal, type inferred via declaration, printing. | ||
*/ | ||
main: func { | ||
|
||
pointer : Int* = [4, 5, 6] | ||
|
||
for(i in 0..3) { | ||
printf("%d ", pointer[i]) | ||
} | ||
println() | ||
|
||
} |
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,15 @@ | ||
|
||
/** | ||
* Converting from a raw C array to an ooc array by casting | ||
*/ | ||
main: func { | ||
|
||
pointer := [10, 11, 12] as Int* | ||
array := pointer as Int[3] | ||
|
||
for(i in 0..array length) { | ||
printf("%d ", array[i]) | ||
} | ||
println() | ||
|
||
} |
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,17 @@ | ||
|
||
/** | ||
* Manually converting from a raw C array to an ooc array | ||
*/ | ||
main: func { | ||
|
||
pointer := [7, 8, 9] as Int* | ||
|
||
array := Int[3] new() | ||
memcpy(array data, pointer, array length * Int size) | ||
|
||
for(i in 0..array length) { | ||
printf("%d ", array[i]) | ||
} | ||
println() | ||
|
||
} |
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 @@ | ||
import os/Time | ||
|
||
/** | ||
* A small three-dimensional array | ||
*/ | ||
main: func { | ||
|
||
array := Int[3][5][4] new() | ||
|
||
for(x in 0..array length) { | ||
for(y in 0..array[x] length) { | ||
for(z in 0..array[x][y] length) { | ||
array[x][y][z] = Time microsec() % 10 | ||
} | ||
} | ||
} | ||
|
||
print(array) | ||
|
||
printf("Got a %dx%dx%d array\n", array length, array[0] length, array[0][0] length) | ||
|
||
} | ||
|
||
print: func (array: Int[][][]) { | ||
|
||
for(x in 0..array length) { | ||
for(y in 0..array[x] length) { | ||
for(z in 0..array[x][y] length) { | ||
printf("%d ", array[x][y][z]) | ||
} | ||
println() | ||
} | ||
println() | ||
println() | ||
} | ||
|
||
} |