Merge branch 'DontBreakDev' into FunctionCalls
This commit is contained in:
9
tests/given/test/entry.definition.alpha
Normal file
9
tests/given/test/entry.definition.alpha
Normal file
@ -0,0 +1,9 @@
|
||||
(* TEST: [-asc -tc] *)
|
||||
(* type string : 1 -> character *)
|
||||
type M : string -> integer
|
||||
|
||||
function entry : M
|
||||
|
||||
entry(s) := {
|
||||
return 0;
|
||||
}
|
12
tests/given/test/entry.duplicateDifferent.alpha
Normal file
12
tests/given/test/entry.duplicateDifferent.alpha
Normal file
@ -0,0 +1,12 @@
|
||||
(* TEST: [-asc -tc] *)
|
||||
type M : string -> integer
|
||||
|
||||
function entry : M
|
||||
|
||||
entry(s) := {
|
||||
[
|
||||
integer: x;
|
||||
character: x
|
||||
]
|
||||
return x;
|
||||
}
|
10
tests/given/test/entry.duplicateSame.alpha
Normal file
10
tests/given/test/entry.duplicateSame.alpha
Normal file
@ -0,0 +1,10 @@
|
||||
(* TEST: [-asc -tc] *)
|
||||
type M : string -> integer
|
||||
function entry : M
|
||||
|
||||
entry(s) := {
|
||||
[
|
||||
integer: x; integer: x
|
||||
]
|
||||
return x;
|
||||
}
|
12
tests/given/test/entry.local.alpha
Normal file
12
tests/given/test/entry.local.alpha
Normal file
@ -0,0 +1,12 @@
|
||||
(* TEST: [-asc -tc] *)
|
||||
type M : string -> integer
|
||||
|
||||
function entry : M
|
||||
|
||||
entry(s) := {
|
||||
[
|
||||
integer: x
|
||||
]
|
||||
x := 0;
|
||||
return x;
|
||||
}
|
11
tests/given/test/error.entry.undeclaredType.alpha
Normal file
11
tests/given/test/error.entry.undeclaredType.alpha
Normal file
@ -0,0 +1,11 @@
|
||||
(* TEST: [-asc -tc] *)
|
||||
type M : string -> integer
|
||||
|
||||
function foo : M
|
||||
|
||||
foo (s) := {
|
||||
[
|
||||
int: x
|
||||
]
|
||||
return 0;
|
||||
}
|
8
tests/given/test/error.entry.undeclaredVar.alpha
Normal file
8
tests/given/test/error.entry.undeclaredVar.alpha
Normal file
@ -0,0 +1,8 @@
|
||||
(* TEST: [-asc -tc] *)
|
||||
type M : string -> integer
|
||||
|
||||
function entry : M
|
||||
|
||||
entry(s) := {
|
||||
return x;
|
||||
}
|
15
tests/given/test/error.none.alpha
Normal file
15
tests/given/test/error.none.alpha
Normal file
@ -0,0 +1,15 @@
|
||||
(* TEST: [-asc -tc] *)
|
||||
type string2int: string -> integer
|
||||
|
||||
function entry : string2int
|
||||
|
||||
entry(arg) := {
|
||||
[ integer: i ; integer: sum ]
|
||||
sum := 0;
|
||||
i := 0 ;
|
||||
while (i < 10) {
|
||||
sum := sum + i;
|
||||
i := i + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
15
tests/given/test/error.operator.alpha
Normal file
15
tests/given/test/error.operator.alpha
Normal file
@ -0,0 +1,15 @@
|
||||
(* TEST: [-asc -tc] *)
|
||||
type string2int: string -> integer
|
||||
|
||||
function entry : string2int
|
||||
|
||||
entry(arg) := {
|
||||
[ integer: i; integer: sum ]
|
||||
sum := 0;
|
||||
i := 0;
|
||||
while (i < 10) {
|
||||
sum = sum + i;
|
||||
i := i + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
4
tests/given/test/function.declaration.alpha
Normal file
4
tests/given/test/function.declaration.alpha
Normal file
@ -0,0 +1,4 @@
|
||||
(* TEST: [-asc -tc] *)
|
||||
type M : integer -> integer
|
||||
|
||||
function f : M
|
8
tests/given/test/function.definition.alpha
Normal file
8
tests/given/test/function.definition.alpha
Normal file
@ -0,0 +1,8 @@
|
||||
(* TEST: [-asc -tc] *)
|
||||
type M : integer -> integer
|
||||
|
||||
function f : M
|
||||
|
||||
f(x) := {
|
||||
return x;
|
||||
}
|
75
tests/given/test/functionValue.alpha
Normal file
75
tests/given/test/functionValue.alpha
Normal file
@ -0,0 +1,75 @@
|
||||
(* TEST: [-asc -tc] *)
|
||||
(* Type definitions *)
|
||||
|
||||
(* mapping type *)
|
||||
type string2int: string -> integer
|
||||
|
||||
(* array of functions *)
|
||||
type funArray: 1 -> string2int
|
||||
|
||||
(* record of functions *)
|
||||
type funRec: [ string2int: f; string2int: g ]
|
||||
|
||||
(* function returning function *)
|
||||
type integer_2_string2int: integer -> string2int
|
||||
|
||||
(* function returning function *)
|
||||
type string2int_2_integer: string2int -> integer
|
||||
|
||||
|
||||
type iXiXc: [integer: a; integer: b; character: c]
|
||||
|
||||
type iic2b: iXiXc -> Boolean
|
||||
|
||||
(* Function declarations using the above type definitions *)
|
||||
function a: string2int
|
||||
function b: integer_2_string2int
|
||||
function c: string2int_2_integer
|
||||
|
||||
function d: iic2b
|
||||
|
||||
d(x,y,z) := {
|
||||
[string: s]
|
||||
return 0;
|
||||
}
|
||||
|
||||
function entry: string2int
|
||||
|
||||
a(x) := {
|
||||
[string : s]
|
||||
s := x;
|
||||
return 0;
|
||||
}
|
||||
|
||||
b(x) := {
|
||||
[integer: i]
|
||||
i := x;
|
||||
return a;
|
||||
}
|
||||
|
||||
c(x) := {
|
||||
[string: s]
|
||||
s := "Hi!";
|
||||
return x(s);
|
||||
}
|
||||
|
||||
|
||||
(* Function definition
|
||||
entry is the first function called
|
||||
*)
|
||||
entry(arg) := {
|
||||
[integer: result; string2int: f; integer: temp]
|
||||
temp := a("Hello");
|
||||
f := b(temp);
|
||||
result := c(f);
|
||||
if (d(1,2,'c'))
|
||||
then {
|
||||
result := 0;
|
||||
}
|
||||
else {
|
||||
[ Boolean : b]
|
||||
result := entry("hello");
|
||||
}
|
||||
result := c(f);
|
||||
return result;
|
||||
}
|
30
tests/given/test/sample.good.alpha
Normal file
30
tests/given/test/sample.good.alpha
Normal file
@ -0,0 +1,30 @@
|
||||
(* TEST: [-asc -tc] *)
|
||||
|
||||
(* Type definitions *)
|
||||
type int2int: integer -> integer
|
||||
type string2int: string -> integer
|
||||
|
||||
(* Function declarations
|
||||
They use the above type definitions
|
||||
*)
|
||||
function square : int2int
|
||||
function entry : string2int
|
||||
|
||||
(* Function definition
|
||||
Functions must be declared before they are defined
|
||||
*)
|
||||
square(x) := {
|
||||
return x * x;
|
||||
}
|
||||
|
||||
(* Function definition
|
||||
entry is the first function called
|
||||
*)
|
||||
entry(arg) := {
|
||||
[ integer: input ; integer: expected ; integer: actual ; Boolean: result ]
|
||||
input := 7;
|
||||
expected := 49;
|
||||
actual := square(input);
|
||||
result := expected = actual;
|
||||
return 0;
|
||||
}
|
69
tests/given/test/selectionSort.alpha
Normal file
69
tests/given/test/selectionSort.alpha
Normal file
@ -0,0 +1,69 @@
|
||||
(* TEST: [-asc -tc] *)
|
||||
(* Type definitions *)
|
||||
|
||||
type string2int: string -> integer
|
||||
type intArray: 1 -> integer
|
||||
type intArrayXinteger: [ intArray: data; integer: index ]
|
||||
type intArrayXinteger2integer: intArrayXinteger -> integer
|
||||
type intArray2Boolean: intArray -> Boolean
|
||||
|
||||
|
||||
(* Function declarations
|
||||
They use the above type definitions
|
||||
*)
|
||||
function indexOfSmallest: intArrayXinteger2integer
|
||||
function selectionSort: intArray2Boolean
|
||||
function entry : string2int
|
||||
|
||||
(* indexOfSmallest *)
|
||||
indexOfSmallest (* as *) (data, startingIndex) := {
|
||||
[ integer: indexOfSmallestSoFar; integer: i ]
|
||||
indexOfSmallestSoFar := startingIndex;
|
||||
i := 0 ;
|
||||
while (i < data._1 ) {
|
||||
if ( data(i) < data(indexOfSmallestSoFar) )
|
||||
then {
|
||||
indexOfSmallestSoFar := i;
|
||||
}
|
||||
else {
|
||||
i := i;
|
||||
}
|
||||
i := i + 1;
|
||||
}
|
||||
return indexOfSmallestSoFar;
|
||||
}
|
||||
|
||||
|
||||
(* selectionSort *)
|
||||
selectionSort(data) := {
|
||||
[ integer: i ]
|
||||
i := 0 ;
|
||||
while (i < data._1 ) {
|
||||
[ integer: index; integer: temp ]
|
||||
index := indexOfSmallest(data,i);
|
||||
temp := data(index);
|
||||
data(index) := data(i);
|
||||
data(i) := temp;
|
||||
i := i + 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
(* Function definition
|
||||
entry is the first function called
|
||||
*)
|
||||
entry(arg) := {
|
||||
[ intArray: data; Boolean: _ ]
|
||||
data := reserve data(8);
|
||||
data(0) := 60;
|
||||
data(1) := 80;
|
||||
data(2) := 10;
|
||||
data(3) := 50;
|
||||
data(4) := 30;
|
||||
data(5) := 40;
|
||||
data(6) := 20;
|
||||
data(7) := 70;
|
||||
_ := selectionSort(data);
|
||||
return 0;
|
||||
}
|
2
tests/given/test/type.array.alpha
Normal file
2
tests/given/test/type.array.alpha
Normal file
@ -0,0 +1,2 @@
|
||||
(* TEST: [-asc -tc] *)
|
||||
type A : 1 -> integer
|
3
tests/given/test/type.mapping.alpha
Normal file
3
tests/given/test/type.mapping.alpha
Normal file
@ -0,0 +1,3 @@
|
||||
(* TEST: [-asc -tc] *)
|
||||
type M : integer -> character
|
||||
|
2
tests/given/test/type.record.alpha
Normal file
2
tests/given/test/type.record.alpha
Normal file
@ -0,0 +1,2 @@
|
||||
(* TEST: [-asc -tc] *)
|
||||
type R : [ integer : i ; character : c ]
|
76
tests/given/test/types.alpha
Normal file
76
tests/given/test/types.alpha
Normal file
@ -0,0 +1,76 @@
|
||||
(* TEST: [-asc -tc] *)
|
||||
(*
|
||||
|
||||
At compiler start-up your program should
|
||||
create symbol table entries for the following
|
||||
built-in types:
|
||||
|
||||
Boolean (1 byte)
|
||||
character (1 byte)
|
||||
integer (4 bytes)
|
||||
address (8 bytes)
|
||||
|
||||
and the following privileged type (it has literals):
|
||||
|
||||
type string: 1 -> character
|
||||
|
||||
Your compiler can define other types during
|
||||
its start-up routine as well, if it is helpful
|
||||
to do so.
|
||||
|
||||
*)
|
||||
|
||||
|
||||
|
||||
type BooleanXBoolean: [Boolean: x; Boolean: y]
|
||||
type characterXcharacter: [character: x; character: y]
|
||||
type integerXinteger: [integer: x; integer: y]
|
||||
|
||||
type Boolean2Boolean: Boolean -> Boolean
|
||||
type integer2integer: integer -> integer
|
||||
|
||||
type character2integer: character -> integer
|
||||
type Boolean2integer: Boolean -> integer
|
||||
type string2integer: string -> integer
|
||||
|
||||
type integerXinteger2integer: integerXinteger -> integer
|
||||
|
||||
type integerXinteger2Boolean: integerXinteger -> Boolean
|
||||
type characterXcharacter2Boolean: characterXcharacter -> Boolean
|
||||
type BooleanXBoolean2Boolean: BooleanXBoolean -> Boolean
|
||||
|
||||
|
||||
type integer2address: integer -> address
|
||||
type address2integer: address -> integer
|
||||
|
||||
|
||||
(* The alpha library functions
|
||||
You will be provided with x86-64 assembly
|
||||
code implementations of these.
|
||||
*)
|
||||
|
||||
external function printInteger: integer2integer
|
||||
external function printCharacter: character2integer
|
||||
external function printBoolean: Boolean2integer
|
||||
|
||||
(*
|
||||
A declaration of the entry point function for your program
|
||||
|
||||
You may assume that when starting this function will behave as if
|
||||
it had been called from the C language main function like this:
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
if (argc == 1) {
|
||||
return entry(NULL);
|
||||
}
|
||||
else {
|
||||
return entry(makeAlphaString(argv[1]));
|
||||
}
|
||||
}
|
||||
|
||||
for some suitable definition of makeAlphaString which creates
|
||||
an alpha string representation of its argument C string in memory
|
||||
and returns a pointer to that alpha string.
|
||||
*)
|
||||
|
||||
function entry: string2integer
|
Reference in New Issue
Block a user