This commit is contained in:
Scarlett
2025-05-03 19:25:55 -04:00
parent fbd08c634a
commit ea7c284665
64 changed files with 121 additions and 995 deletions

View File

@ -0,0 +1,9 @@
$$ TEST: [-asc -tc]
(* type string : 1 -> character *)
type M : string -> integer
function entry : M
entry(s) := {
return 0;
}

View File

@ -0,0 +1,12 @@
$$ TEST: [-asc -tc]
type M : string -> integer
function entry : M
entry(s) := {
[
integer: x;
character: x
]
return x;
}

View File

@ -0,0 +1,10 @@
$$ TEST: [-asc -tc]
type M : string -> integer
function entry : M
entry(s) := {
[
integer: x; integer: x
]
return x;
}

View File

@ -0,0 +1,12 @@
$$ TEST: [-asc -tc]
type M : string -> integer
function entry : M
entry(s) := {
[
integer: x
]
x := 0;
return x;
}

View 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;
}

View File

@ -0,0 +1,4 @@
$$ TEST: [-asc -tc]
type M : integer -> integer
function f : M

View File

@ -0,0 +1,8 @@
$$ TEST: [-asc -tc]
type M : integer -> integer
function f : M
f(x) := {
return x;
}

View 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;integer: s]
return (x < y & z < 'm');
}
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; character: char]
temp := a("Hello");
f := b(temp);
result := c(f);
if (d(1,2,char))
then {
result := 0;
}
else {
[ Boolean : b]
result := entry("hello");
}
result := c(f);
return result;
}

View File

@ -0,0 +1,29 @@
$$ 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;
}

View 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;
}

View File

@ -0,0 +1,2 @@
$$ TEST: [-asc -tc]
type A : 1 -> integer

View File

@ -0,0 +1,3 @@
$$ TEST: [-asc -tc]
type M : integer -> character

View File

@ -0,0 +1,2 @@
$$ TEST: [-asc -tc]
type R : [ integer : i ; character : c ]

View 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