This repository has been archived by the owner on Jul 6, 2023. It is now read-only.
forked from Bluefire2/xic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple test for inherited super class
- Loading branch information
1 parent
00af981
commit 94a27ee
Showing
3 changed files
with
65 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,26 @@ | ||
use io | ||
use conv | ||
use point | ||
|
||
class Color { | ||
r, g, b: int | ||
} | ||
|
||
class ColoredPoint extends Point { | ||
col: Color | ||
color(): Color { return col } | ||
|
||
initColoredPoint(x0: int, y0: int, c: Color): ColoredPoint { | ||
col = c | ||
_ = initPoint(x0, y0) | ||
return this | ||
} | ||
} | ||
|
||
main(args:int[][]) { | ||
c:Color = new Color | ||
c.r = 1; c.g = 2; c.b = 3; | ||
|
||
p:Point = new ColoredPoint | ||
_ = p.initPoint(1, 2) | ||
} |
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 @@ | ||
// A 2D Point with integer coordinates (x,y) | ||
class Point { | ||
move(dx: int, dy: int) | ||
add(p: Point): Point | ||
coords(): int, int | ||
clone(): Point | ||
|
||
// Initialize this to contain (x, y). | ||
// Returns: this | ||
initPoint(x: int, y: int): Point | ||
} | ||
|
||
// Create the point (x, y) | ||
createPoint(x: int, y:int): Point |
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 @@ | ||
class Point{ // a mutable point | ||
x, y: int | ||
|
||
move(dx: int, dy: int) { | ||
x = x + dx | ||
y = y + dy | ||
} | ||
coords(): int, int { | ||
return x, y | ||
} | ||
add(p: Point): Point { | ||
return createPoint(x + p.x, y + p.y) | ||
} | ||
initPoint(x0: int, y0: int): Point { | ||
x = x0 | ||
y = y0 | ||
return this | ||
} | ||
clone(): Point { return createPoint(x, y) } | ||
} | ||
|
||
createPoint(x: int, y:int): Point { | ||
return new Point.initPoint(x, y) | ||
} | ||
|