September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
41
Task/Classes/Component-Pascal/classes-1.component
Normal file
41
Task/Classes/Component-Pascal/classes-1.component
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
MODULE Point;
|
||||
IMPORT
|
||||
Strings;
|
||||
TYPE
|
||||
Instance* = POINTER TO LIMITED RECORD
|
||||
x-, y- : LONGINT; (* Instance variables *)
|
||||
END;
|
||||
|
||||
PROCEDURE (self: Instance) Initialize*(x,y: LONGINT), NEW;
|
||||
BEGIN
|
||||
self.x := x;
|
||||
self.y := y
|
||||
END Initialize;
|
||||
|
||||
(* constructor *)
|
||||
PROCEDURE New*(x, y: LONGINT): Instance;
|
||||
VAR
|
||||
point: Instance;
|
||||
BEGIN
|
||||
NEW(point);
|
||||
point.Initialize(x,y);
|
||||
RETURN point
|
||||
END New;
|
||||
|
||||
(* methods *)
|
||||
PROCEDURE (self: Instance) Add*(other: Instance): Instance, NEW;
|
||||
BEGIN
|
||||
RETURN New(self.x + other.x,self.y + other.y);
|
||||
END Add;
|
||||
|
||||
PROCEDURE (self: Instance) ToString*(): POINTER TO ARRAY OF CHAR, NEW;
|
||||
VAR
|
||||
xStr,yStr: ARRAY 64 OF CHAR;
|
||||
str: POINTER TO ARRAY OF CHAR;
|
||||
BEGIN
|
||||
Strings.IntToString(self.x,xStr);
|
||||
Strings.IntToString(self.y,yStr);
|
||||
NEW(str,128);str^ := "@(" +xStr$ + "," + yStr$ + ")";
|
||||
RETURN str
|
||||
END ToString;
|
||||
END Point.
|
||||
17
Task/Classes/Component-Pascal/classes-2.component
Normal file
17
Task/Classes/Component-Pascal/classes-2.component
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
MODULE DrivePoint;
|
||||
IMPORT
|
||||
Point,
|
||||
StdLog;
|
||||
|
||||
PROCEDURE Do*;
|
||||
VAR
|
||||
p,q: Point.Instance;
|
||||
BEGIN
|
||||
p := Point.New(1,2);
|
||||
q := Point.New(2,1);
|
||||
StdLog.String(p.ToString() + " + " + q.ToString() + " = " + p.Add(q).ToString());StdLog.Ln;
|
||||
StdLog.String("p.x:> ");StdLog.Int(p.x);StdLog.Ln;
|
||||
StdLog.String("p.y:> ");StdLog.Int(p.y);StdLog.Ln
|
||||
END Do;
|
||||
|
||||
END DrivePoint.
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
MODULE Graphics;
|
||||
IMPORT StdLog;
|
||||
TYPE
|
||||
(* class *)
|
||||
Point* = POINTER TO LIMITED RECORD
|
||||
x-,y-: INTEGER; (* Instance variables *)
|
||||
END;
|
||||
|
||||
(* method *)
|
||||
PROCEDURE (p: Point) Abs*(): INTEGER,NEW;
|
||||
BEGIN
|
||||
RETURN p.x
|
||||
END Abs;
|
||||
|
||||
(* method *)
|
||||
PROCEDURE (p: Point) Ord*(): INTEGER,NEW;
|
||||
BEGIN
|
||||
RETURN p.y
|
||||
END Ord;
|
||||
|
||||
(* method *)
|
||||
PROCEDURE (p: Point) Show*,NEW;
|
||||
BEGIN
|
||||
StdLog.String("Point(");StdLog.Int(p.x);StdLog.String(",");
|
||||
StdLog.Int(p.y);StdLog.String(");");StdLog.Ln
|
||||
END Show;
|
||||
|
||||
(* constructor *)
|
||||
PROCEDURE NewPoint*(x,y: INTEGER): Point;
|
||||
VAR
|
||||
p: Point;
|
||||
BEGIN
|
||||
NEW(p);p.x := x;p.y := y;
|
||||
RETURN p
|
||||
END NewPoint;
|
||||
|
||||
PROCEDURE TestPoint*;
|
||||
VAR
|
||||
p: Point;
|
||||
BEGIN
|
||||
p := NewPoint(10,20);
|
||||
p.Show();
|
||||
StdLog.String("Abs:> ");StdLog.Int(p.Abs());StdLog.Ln;
|
||||
StdLog.String("Ord:> ");StdLog.Int(p.Ord());StdLog.Ln
|
||||
END TestPoint;
|
||||
END Graphics.
|
||||
2
Task/Classes/Eiffel/classes-1.e
Normal file
2
Task/Classes/Eiffel/classes-1.e
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
class MY_CLASS
|
||||
end
|
||||
14
Task/Classes/Eiffel/classes-2.e
Normal file
14
Task/Classes/Eiffel/classes-2.e
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
class MY_CLASS
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
-- This is a creation procedure or "Constructor".
|
||||
do
|
||||
create my_string.make_empty
|
||||
end
|
||||
|
||||
end
|
||||
43
Task/Classes/Eiffel/classes-3.e
Normal file
43
Task/Classes/Eiffel/classes-3.e
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
class MY_CLASS
|
||||
|
||||
create -- Here we are declaring ...
|
||||
make, -- In the Feature group (below) we are coding
|
||||
make_this_way, -- each of these declared creation procedures.
|
||||
make_that_way, -- We can have as many constructors as we need.
|
||||
make_another_way,
|
||||
a_name_other_than_make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
-- This is a creation procedure or "Constructor".
|
||||
do
|
||||
-- Initialization code goes here ...
|
||||
end
|
||||
|
||||
make_this_way
|
||||
-- Make this way, rather than a plain ole "make".
|
||||
do
|
||||
-- Initialization code goes here ...
|
||||
end
|
||||
|
||||
make_that_way
|
||||
-- Create that way rather than this way (above).
|
||||
do
|
||||
-- Initialization code goes here ...
|
||||
end
|
||||
|
||||
make_another_way
|
||||
-- And still another way to create MY_CLASS.
|
||||
do
|
||||
-- Initialization code goes here ...
|
||||
end
|
||||
|
||||
a_name_other_than_make
|
||||
-- There is no requirement to use the word "make".
|
||||
-- The word "make" is just a naming convention.
|
||||
do
|
||||
-- Initialization code goes here ...
|
||||
end
|
||||
|
||||
end
|
||||
48
Task/Classes/Eiffel/classes-4.e
Normal file
48
Task/Classes/Eiffel/classes-4.e
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
class MY_CLASS
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
-- This is a creation procedure or "Constructor".
|
||||
do
|
||||
create my_string.make_empty
|
||||
end
|
||||
|
||||
feature -- Access (Properties)
|
||||
|
||||
my_string: STRING
|
||||
-- This is a comment about `my_string', which is a "Property".
|
||||
|
||||
my_integer: INTEGER
|
||||
-- Unlike `my_string' (above), the INTEGER type is an "Expanded Type".
|
||||
-- This means INTEGER objects know how to self-initialize.
|
||||
|
||||
my_date: DATE
|
||||
-- This attribute (or "Property") will need to be initialized.
|
||||
-- One way to do that is to make a self-initializing attribute, thus ...
|
||||
attribute
|
||||
create Result.make_now
|
||||
end
|
||||
|
||||
feature -- Basic Operations (Methods)
|
||||
|
||||
do_something
|
||||
-- Loop over and print the numbers 1 to 100 to the console.
|
||||
do
|
||||
across 1 |..| 100 as i loop print (i.out) end
|
||||
end
|
||||
|
||||
do_something_else
|
||||
-- Set a and b and print the result.
|
||||
local
|
||||
a, b, c: INTEGER
|
||||
do
|
||||
a := 1
|
||||
b := 2
|
||||
c := a + b
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,27 +1,27 @@
|
|||
import extensions.
|
||||
import extensions;
|
||||
|
||||
class MyClass
|
||||
{
|
||||
object prop Variable :: _variable.
|
||||
prop int Variable;
|
||||
|
||||
someMethod
|
||||
[
|
||||
_variable := 1.
|
||||
]
|
||||
someMethod()
|
||||
{
|
||||
Variable := 1
|
||||
}
|
||||
|
||||
constructor new
|
||||
[
|
||||
]
|
||||
constructor()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public program =
|
||||
[
|
||||
public program()
|
||||
{
|
||||
// instantiate the class
|
||||
var instance := MyClass new.
|
||||
var instance := new MyClass();
|
||||
|
||||
// invoke the method
|
||||
instance someMethod.
|
||||
instance.someMethod();
|
||||
|
||||
// get the variable
|
||||
console printLine("Variable=",instance Variable).
|
||||
].
|
||||
console.printLine("Variable=",instance.Variable)
|
||||
}
|
||||
|
|
|
|||
19
Task/Classes/GLSL/classes.glsl
Normal file
19
Task/Classes/GLSL/classes.glsl
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
struct Rectangle{
|
||||
float width;
|
||||
float height;
|
||||
};
|
||||
|
||||
Rectangle new(float width,float height){
|
||||
Rectangle self;
|
||||
self.width = width;
|
||||
self.height = height;
|
||||
return self;
|
||||
}
|
||||
|
||||
float area(Rectangle self){
|
||||
return self.width*self.height;
|
||||
}
|
||||
|
||||
float perimeter(Rectangle self){
|
||||
return (self.width+self.height)*2.0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue