init
This commit is contained in:
31
wcmtools/s2/tests/Arithmetic.s2
Executable file
31
wcmtools/s2/tests/Arithmetic.s2
Executable file
@@ -0,0 +1,31 @@
|
||||
|
||||
layerinfo "type" = "core";
|
||||
layerinfo "majorversion" = "1";
|
||||
|
||||
function main() {
|
||||
var int first = 7;
|
||||
var int second = 5;
|
||||
println "$first + $second = " + ($first + $second);
|
||||
println "$first - $second = " + ($first - $second);
|
||||
println "$second - $first = " + ($second - $first);
|
||||
println "$first * $second = " + ($first * $second);
|
||||
println "$first / $second = " + ($first / $second);
|
||||
println "$first % $second = " + ($first % $second);
|
||||
|
||||
var int third = 8;
|
||||
$first = $second = $third;
|
||||
println "All eight: $first $second $third";
|
||||
if ($third == 8 and $first == 8 and $second == 8) {
|
||||
println("t1");
|
||||
}
|
||||
if ($third == 4 or $first == 2 or $second == 8) {
|
||||
println("t2");
|
||||
}
|
||||
|
||||
$third = $first * $second * $second;
|
||||
println "512 = $third";
|
||||
|
||||
$third = 3 * $first + 5 * $second;
|
||||
println "64 = $third";
|
||||
|
||||
}
|
||||
11
wcmtools/s2/tests/Arithmetic.s2.out
Executable file
11
wcmtools/s2/tests/Arithmetic.s2.out
Executable file
@@ -0,0 +1,11 @@
|
||||
7 + 5 = 12
|
||||
7 - 5 = 2
|
||||
5 - 7 = -2
|
||||
7 * 5 = 35
|
||||
7 / 5 = 1
|
||||
7 % 5 = 2
|
||||
All eight: 8 8 8
|
||||
t1
|
||||
t2
|
||||
512 = 512
|
||||
64 = 64
|
||||
42
wcmtools/s2/tests/Classes_1.s2
Executable file
42
wcmtools/s2/tests/Classes_1.s2
Executable file
@@ -0,0 +1,42 @@
|
||||
#-*-c++-*-
|
||||
|
||||
layerinfo "type" = "core";
|
||||
layerinfo "majorversion" = 0;
|
||||
|
||||
property string blah;
|
||||
set "blah" = "foo";
|
||||
|
||||
class Dog
|
||||
{
|
||||
var string name;
|
||||
function out;
|
||||
}
|
||||
|
||||
class KillerDog extends Dog
|
||||
{
|
||||
var int weight;
|
||||
}
|
||||
|
||||
class Page
|
||||
{
|
||||
var KillerDog d;
|
||||
function foo (int c);
|
||||
}
|
||||
|
||||
|
||||
function Dog::out {
|
||||
println "I'm a dog named \"$.name\".";
|
||||
}
|
||||
|
||||
function KillerDog::out {
|
||||
println "I'm a killer dog named \"$.name\" with weight $.weight";
|
||||
}
|
||||
|
||||
function main ()
|
||||
{
|
||||
var KillerDog kd = new KillerDog;
|
||||
$kd.name = "Killer Dog";
|
||||
$kd.weight = 9999;
|
||||
$kd->out();
|
||||
}
|
||||
|
||||
1
wcmtools/s2/tests/Classes_1.s2.out
Executable file
1
wcmtools/s2/tests/Classes_1.s2.out
Executable file
@@ -0,0 +1 @@
|
||||
I'm a killer dog named "Killer Dog" with weight 9999
|
||||
44
wcmtools/s2/tests/Classes_2.s2
Executable file
44
wcmtools/s2/tests/Classes_2.s2
Executable file
@@ -0,0 +1,44 @@
|
||||
#-*-c++-*-
|
||||
|
||||
layerinfo "type" = "core";
|
||||
layerinfo "majorversion" = 0;
|
||||
|
||||
class A {
|
||||
function write(string s);
|
||||
}
|
||||
class B extends A { }
|
||||
|
||||
function A::write(string s) {
|
||||
println "A wrote: " + $s;
|
||||
}
|
||||
|
||||
function B::write(string s) {
|
||||
println "B wrote: " + $s;
|
||||
}
|
||||
|
||||
function getA (bool subclass) : A
|
||||
{
|
||||
var A v = new A;
|
||||
if ($subclass) {
|
||||
$v = new B;
|
||||
}
|
||||
return $v;
|
||||
}
|
||||
|
||||
function main ()
|
||||
{
|
||||
var B b = new B;
|
||||
var A a = new A;
|
||||
$a->write("A");
|
||||
$b->write("B");
|
||||
|
||||
$a = $b;
|
||||
$a->write("B from A");
|
||||
|
||||
var A fa;
|
||||
$fa = getA(false);
|
||||
$fa->write("should be A");
|
||||
$fa = getA(true);
|
||||
$fa->write("should be B");
|
||||
}
|
||||
|
||||
5
wcmtools/s2/tests/Classes_2.s2.out
Executable file
5
wcmtools/s2/tests/Classes_2.s2.out
Executable file
@@ -0,0 +1,5 @@
|
||||
A wrote: A
|
||||
B wrote: B
|
||||
B wrote: B from A
|
||||
A wrote: should be A
|
||||
B wrote: should be B
|
||||
31
wcmtools/s2/tests/Colors.s2
Executable file
31
wcmtools/s2/tests/Colors.s2
Executable file
@@ -0,0 +1,31 @@
|
||||
layerinfo type = core;
|
||||
layerinfo "majorversion" = 0;
|
||||
|
||||
class Color
|
||||
{
|
||||
var int r;
|
||||
var int g;
|
||||
var int b;
|
||||
function toString() : string;
|
||||
}
|
||||
|
||||
function builtin string(int i) : string;
|
||||
|
||||
function Color::toString : string
|
||||
{
|
||||
return "rgb(" +
|
||||
string($.r) + "," +
|
||||
string($.g) + "," +
|
||||
string($.b) + ")";
|
||||
}
|
||||
|
||||
function main()
|
||||
{
|
||||
var Color c = new Color;
|
||||
$c.r = 100;
|
||||
$c.g = 0;
|
||||
$c.b = 50;
|
||||
|
||||
"$c\n";
|
||||
"My color is $c\n";
|
||||
}
|
||||
2
wcmtools/s2/tests/Colors.s2.out
Executable file
2
wcmtools/s2/tests/Colors.s2.out
Executable file
@@ -0,0 +1,2 @@
|
||||
rgb(100,0,50)
|
||||
My color is rgb(100,0,50)
|
||||
62
wcmtools/s2/tests/Colors_2b.s2
Executable file
62
wcmtools/s2/tests/Colors_2b.s2
Executable file
@@ -0,0 +1,62 @@
|
||||
#-*-perl-*-
|
||||
|
||||
layerinfo type = core;
|
||||
layerinfo "majorversion" = 0;
|
||||
|
||||
class Color
|
||||
{
|
||||
var readonly int r;
|
||||
var readonly int g;
|
||||
var readonly int b;
|
||||
var string as_string;
|
||||
function builtin red(int r);
|
||||
function builtin red() : int;
|
||||
function builtin green(int g);
|
||||
function builtin green() : int;
|
||||
function builtin blue(int b);
|
||||
function builtin blue() : int;
|
||||
function builtin Color(string s) : Color;
|
||||
}
|
||||
|
||||
class string
|
||||
{
|
||||
function builtin substr(int start, int length) : string;
|
||||
}
|
||||
|
||||
function builtin string(int i) : string;
|
||||
function builtin int(string s) : int;
|
||||
|
||||
property Color bgcolor {
|
||||
des = "Background color";
|
||||
}
|
||||
set bgcolor = "#FF0000";
|
||||
|
||||
property int age {
|
||||
des = "Your age";
|
||||
}
|
||||
set age = 123;
|
||||
|
||||
property string name {
|
||||
des = "Your name";
|
||||
}
|
||||
set name = "foo";
|
||||
|
||||
function main()
|
||||
{
|
||||
println "Bgcolor_pre = $*bgcolor";
|
||||
$*name = "jack";
|
||||
$*age = 21;
|
||||
$*bgcolor = "#C0C0C0";
|
||||
|
||||
var Color c;
|
||||
$c = "#123456";
|
||||
|
||||
"$c\n";
|
||||
$c->blue($c->blue() + 1);
|
||||
"My color is now $c\n";
|
||||
|
||||
println "Age = $*age";
|
||||
println "Name = $*name";
|
||||
|
||||
println "Bgcolor_post = $*bgcolor";
|
||||
}
|
||||
6
wcmtools/s2/tests/Colors_2b.s2.out
Executable file
6
wcmtools/s2/tests/Colors_2b.s2.out
Executable file
@@ -0,0 +1,6 @@
|
||||
Bgcolor_pre = #ff0000
|
||||
#123456
|
||||
My color is now #123457
|
||||
Age = 21
|
||||
Name = jack
|
||||
Bgcolor_post = #c0c0c0
|
||||
21
wcmtools/s2/tests/Hello_World.s2
Executable file
21
wcmtools/s2/tests/Hello_World.s2
Executable file
@@ -0,0 +1,21 @@
|
||||
#-*-c++-*-
|
||||
|
||||
layerinfo "type" = "core";
|
||||
layerinfo "majorversion" = 0;
|
||||
|
||||
property string blah;
|
||||
set "blah" = "foo";
|
||||
|
||||
function main ()
|
||||
{
|
||||
"hi.\n";
|
||||
print "hi.\n";
|
||||
println "hi.";
|
||||
"""triple quote print\n""";
|
||||
print """triple quote print2\n""";
|
||||
"""<div id="comments">\n""";
|
||||
"""<div class="topiclinks">\n""";
|
||||
}
|
||||
|
||||
|
||||
|
||||
7
wcmtools/s2/tests/Hello_World.s2.out
Executable file
7
wcmtools/s2/tests/Hello_World.s2.out
Executable file
@@ -0,0 +1,7 @@
|
||||
hi.
|
||||
hi.
|
||||
hi.
|
||||
triple quote print
|
||||
triple quote print2
|
||||
<div id="comments">
|
||||
<div class="topiclinks">
|
||||
51
wcmtools/s2/tests/Obj_Interpolate.s2
Executable file
51
wcmtools/s2/tests/Obj_Interpolate.s2
Executable file
@@ -0,0 +1,51 @@
|
||||
#-*-perl-*-
|
||||
|
||||
layerinfo type = core;
|
||||
layerinfo "majorversion" = 0;
|
||||
|
||||
class BracketWrapper
|
||||
{
|
||||
var string text;
|
||||
function builtin as_string () : string;
|
||||
}
|
||||
|
||||
class BracketWrapper2
|
||||
{
|
||||
var string text;
|
||||
function builtin toString () : string;
|
||||
}
|
||||
|
||||
class Foo
|
||||
{
|
||||
var string text;
|
||||
function as_string() : string;
|
||||
}
|
||||
|
||||
function Foo::as_string() : string {
|
||||
return "_${.text}_";
|
||||
}
|
||||
|
||||
function main()
|
||||
{
|
||||
var BracketWrapper bw = new BracketWrapper;
|
||||
$bw.text = "as_string";
|
||||
print "Wrapped in brackets: $bw\n";
|
||||
|
||||
var BracketWrapper2 bw2 = new BracketWrapper2;
|
||||
$bw2.text = "toString";
|
||||
print "Wrapped in brackets: $bw2\n";
|
||||
|
||||
var BracketWrapper bnull;
|
||||
print "Null BracketWrapper (builtin): {$bnull}\n";
|
||||
|
||||
var Foo fcontent = new Foo;
|
||||
$fcontent.text = "underscores";
|
||||
print "Defined local as_string: {$fcontent}\n";
|
||||
|
||||
var Foo fnull;
|
||||
print "Null local as_string: {$fnull}\n";
|
||||
print "Empty lines:\n";
|
||||
println $fnull;
|
||||
println "$fnull";
|
||||
print "end.\n";
|
||||
}
|
||||
9
wcmtools/s2/tests/Obj_Interpolate.s2.out
Executable file
9
wcmtools/s2/tests/Obj_Interpolate.s2.out
Executable file
@@ -0,0 +1,9 @@
|
||||
Wrapped in brackets: [as_string]
|
||||
Wrapped in brackets: [toString]
|
||||
Null BracketWrapper (builtin): {}
|
||||
Defined local as_string: {_underscores_}
|
||||
Null local as_string: {}
|
||||
Empty lines:
|
||||
|
||||
|
||||
end.
|
||||
28
wcmtools/s2/tests/Reserved_Idents.s2
Executable file
28
wcmtools/s2/tests/Reserved_Idents.s2
Executable file
@@ -0,0 +1,28 @@
|
||||
#-*-c++-*-
|
||||
|
||||
layerinfo "type" = "core";
|
||||
layerinfo "majorversion" = 0;
|
||||
|
||||
property string blah;
|
||||
set "blah" = "foo";
|
||||
|
||||
function main ()
|
||||
{
|
||||
var string n;
|
||||
$n = "foo";
|
||||
|
||||
var int size;
|
||||
|
||||
var string[] a;
|
||||
$a[0] = "a";
|
||||
$a[1] = "b";
|
||||
$a[2] = "c";
|
||||
$a[3] = "d";
|
||||
|
||||
$size = size $a;
|
||||
|
||||
print "n=$n, size=$size\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
1
wcmtools/s2/tests/Reserved_Idents.s2.out
Executable file
1
wcmtools/s2/tests/Reserved_Idents.s2.out
Executable file
@@ -0,0 +1 @@
|
||||
n=foo, size=4
|
||||
24
wcmtools/s2/tests/String_Object.s2
Executable file
24
wcmtools/s2/tests/String_Object.s2
Executable file
@@ -0,0 +1,24 @@
|
||||
#-*-c++-*-
|
||||
|
||||
layerinfo "type" = "core";
|
||||
layerinfo "majorversion" = 0;
|
||||
|
||||
class string {
|
||||
function repeat () : string;
|
||||
}
|
||||
|
||||
function string::repeat () : string
|
||||
{
|
||||
return $this + $this;
|
||||
}
|
||||
|
||||
function main ()
|
||||
{
|
||||
var string b = "foo ";
|
||||
var string r = "";
|
||||
$r = $b->repeat();
|
||||
$r = $r->repeat();
|
||||
|
||||
println "repeated: $r";
|
||||
}
|
||||
|
||||
1
wcmtools/s2/tests/String_Object.s2.out
Executable file
1
wcmtools/s2/tests/String_Object.s2.out
Executable file
@@ -0,0 +1 @@
|
||||
repeated: foo foo foo foo
|
||||
47
wcmtools/s2/tests/arrayliterals.s2
Executable file
47
wcmtools/s2/tests/arrayliterals.s2
Executable file
@@ -0,0 +1,47 @@
|
||||
#-*-s2-*-
|
||||
|
||||
layerinfo type = core;
|
||||
layerinfo majorversion = 0;
|
||||
|
||||
class Color
|
||||
"Represent a color"
|
||||
{
|
||||
var readonly int r;
|
||||
var readonly int g;
|
||||
var readonly int b;
|
||||
var string as_string "HTML hex encoded: #rrggbb";
|
||||
function builtin Color(string s) : Color "Constructor for color class. Lets you make a Color object from a string of form #rrggbb";
|
||||
}
|
||||
|
||||
function builtin foo () : int;
|
||||
|
||||
property int foo;
|
||||
property hide foo;
|
||||
|
||||
set foo = 5 + 8;
|
||||
|
||||
property int[][] thematrix;
|
||||
set thematrix = [ [ 1, 2 ], [ 3, 4, 6-1 ] ];
|
||||
|
||||
property string[] bar;
|
||||
|
||||
set bar = [ "Jan", "Feb", "Mar", "Apr" ];
|
||||
|
||||
property Color bgcolor;
|
||||
set bgcolor = "#102030";
|
||||
|
||||
function main ()
|
||||
{
|
||||
var string[] empty = [];
|
||||
$empty = [];
|
||||
|
||||
var string[] s = [ "a", "b", "c" ];
|
||||
println "$s[0] $s[1] $s[2]";
|
||||
|
||||
var string{} h = { "1" => "one", "2" => "two" };
|
||||
println "$h{"1"} $h{2}";
|
||||
|
||||
println "$*thematrix[0][0] $*thematrix[0][1] $*thematrix[1][0] $*thematrix[1][1] $*thematrix[1][2]";
|
||||
|
||||
println "Color: $*bgcolor.r $*bgcolor.g $*bgcolor.b";
|
||||
}
|
||||
5
wcmtools/s2/tests/arrayliterals.s2.out
Executable file
5
wcmtools/s2/tests/arrayliterals.s2.out
Executable file
@@ -0,0 +1,5 @@
|
||||
a b c
|
||||
one two
|
||||
1 2 3 4 5
|
||||
Color: 16 32 48
|
||||
|
||||
87
wcmtools/s2/tests/conditions.s2
Executable file
87
wcmtools/s2/tests/conditions.s2
Executable file
@@ -0,0 +1,87 @@
|
||||
#-*-c++-*-
|
||||
|
||||
layerinfo "type" = "core";
|
||||
layerinfo "majorversion" = 1;
|
||||
|
||||
class Foo {
|
||||
var string member;
|
||||
}
|
||||
|
||||
property string blah;
|
||||
set "blah" = "foo";
|
||||
|
||||
function void {
|
||||
}
|
||||
|
||||
function side_effect : Foo {
|
||||
print "side-effect!\n";
|
||||
return new Foo;
|
||||
}
|
||||
|
||||
function main ()
|
||||
{
|
||||
# integers are boolable
|
||||
var int i = 5;
|
||||
println $i ? "pass" : "fail";
|
||||
if ($i) {
|
||||
println "pass.";
|
||||
} else {
|
||||
println "fail.";
|
||||
}
|
||||
if (0) {
|
||||
println "fail.";
|
||||
} elseif ($i) {
|
||||
println "pass.";
|
||||
}
|
||||
|
||||
# objs are boolable
|
||||
var Foo fd = new Foo;
|
||||
println $fd ? "pass" : "fail";
|
||||
if ($fd) {
|
||||
println "pass.";
|
||||
} else {
|
||||
println "fail.";
|
||||
}
|
||||
if (0) {
|
||||
println "fail.";
|
||||
} elseif ($fd) {
|
||||
println "pass.";
|
||||
}
|
||||
|
||||
# objs are boolable
|
||||
$fd = null Foo;
|
||||
println $fd ? "fail" : "pass";
|
||||
if ($fd) {
|
||||
println "fail.";
|
||||
} else {
|
||||
println "pass.";
|
||||
}
|
||||
if (0) {
|
||||
println "fail.";
|
||||
} elseif ($fd) {
|
||||
println "fail.";
|
||||
} else {
|
||||
println "pass.";
|
||||
}
|
||||
|
||||
var string[] arr;
|
||||
println $arr ? "fail." : "pass.";
|
||||
$arr[0] = "test";
|
||||
println $arr ? "pass." : "fail.";
|
||||
|
||||
var string{} hash;
|
||||
println $hash ? "fail." : "pass.";
|
||||
$hash{"bar"} = "foo";
|
||||
println $hash ? "pass." : "fail.";
|
||||
|
||||
#if (void()) {
|
||||
# print "FAIL.\n";
|
||||
#}
|
||||
|
||||
println side_effect() ? "pass." : "fail.";
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
15
wcmtools/s2/tests/conditions.s2.out
Executable file
15
wcmtools/s2/tests/conditions.s2.out
Executable file
@@ -0,0 +1,15 @@
|
||||
pass
|
||||
pass.
|
||||
pass.
|
||||
pass
|
||||
pass.
|
||||
pass.
|
||||
pass
|
||||
pass.
|
||||
pass.
|
||||
pass.
|
||||
pass.
|
||||
pass.
|
||||
pass.
|
||||
side-effect!
|
||||
pass.
|
||||
40
wcmtools/s2/tests/defined.s2
Executable file
40
wcmtools/s2/tests/defined.s2
Executable file
@@ -0,0 +1,40 @@
|
||||
#-*-c++-*-
|
||||
|
||||
layerinfo "type" = "core";
|
||||
layerinfo "majorversion" = 1;
|
||||
|
||||
class string {
|
||||
function repeat () : string;
|
||||
}
|
||||
|
||||
class Foo {
|
||||
var string foo;
|
||||
}
|
||||
|
||||
function main ()
|
||||
{
|
||||
var Foo f;
|
||||
if (defined $f) {
|
||||
print "fail.\n";
|
||||
} else {
|
||||
print "pass.\n";
|
||||
}
|
||||
|
||||
$f = new Foo;
|
||||
if (defined $f) {
|
||||
print "pass.\n";
|
||||
} else {
|
||||
print "fail.\n";
|
||||
}
|
||||
|
||||
$f = null Foo;
|
||||
if (defined $f) {
|
||||
print "fail.\n";
|
||||
} else {
|
||||
print "pass.\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
4
wcmtools/s2/tests/defined.s2.out
Executable file
4
wcmtools/s2/tests/defined.s2.out
Executable file
@@ -0,0 +1,4 @@
|
||||
pass.
|
||||
pass.
|
||||
pass.
|
||||
|
||||
12
wcmtools/s2/tests/fail-syntax.s2
Executable file
12
wcmtools/s2/tests/fail-syntax.s2
Executable file
@@ -0,0 +1,12 @@
|
||||
#-*-c++-*-
|
||||
|
||||
layerinfo "type" = "core";
|
||||
layerinfo "majorversion" = 0;
|
||||
|
||||
function main ()
|
||||
{
|
||||
"hi.\n"
|
||||
}
|
||||
|
||||
|
||||
|
||||
1
wcmtools/s2/tests/fail-syntax.s2.err
Executable file
1
wcmtools/s2/tests/fail-syntax.s2.err
Executable file
@@ -0,0 +1 @@
|
||||
line 9, column 1
|
||||
17
wcmtools/s2/tests/if-assign.s2
Executable file
17
wcmtools/s2/tests/if-assign.s2
Executable file
@@ -0,0 +1,17 @@
|
||||
#-*-c++-*-
|
||||
|
||||
layerinfo "type" = "core";
|
||||
layerinfo "majorversion" = 0;
|
||||
|
||||
function main ()
|
||||
{
|
||||
var int i = 5;
|
||||
if (($i = 5)) {
|
||||
print "i is 5.\n";
|
||||
} elseif ($i = 6) {
|
||||
print "i = 6\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
1
wcmtools/s2/tests/if-assign.s2.err
Executable file
1
wcmtools/s2/tests/if-assign.s2.err
Executable file
@@ -0,0 +1 @@
|
||||
Assignments not allowed
|
||||
22
wcmtools/s2/tests/null-dispatch.s2
Executable file
22
wcmtools/s2/tests/null-dispatch.s2
Executable file
@@ -0,0 +1,22 @@
|
||||
#-*-c++-*-
|
||||
|
||||
layerinfo "type" = "core";
|
||||
layerinfo "majorversion" = 0;
|
||||
|
||||
class Tree { function grow; }
|
||||
class Maple extends Tree { }
|
||||
class Oak extends Tree { }
|
||||
|
||||
function Tree::grow { "Tree grows.\n"; }
|
||||
function Maple::grow { "Maple grows.\n"; }
|
||||
|
||||
function main ()
|
||||
{
|
||||
var Tree t;
|
||||
$t = new Maple; $t->grow();
|
||||
$t = new Oak; $t->grow();
|
||||
var Tree notree;
|
||||
$notree->grow();
|
||||
}
|
||||
|
||||
|
||||
1
wcmtools/s2/tests/null-dispatch.s2.err
Executable file
1
wcmtools/s2/tests/null-dispatch.s2.err
Executable file
@@ -0,0 +1 @@
|
||||
Method called on null Tree object at layer #1, line 19.
|
||||
2
wcmtools/s2/tests/null-dispatch.s2.out
Executable file
2
wcmtools/s2/tests/null-dispatch.s2.out
Executable file
@@ -0,0 +1,2 @@
|
||||
Maple grows.
|
||||
Tree grows.
|
||||
27
wcmtools/s2/tests/null.s2
Executable file
27
wcmtools/s2/tests/null.s2
Executable file
@@ -0,0 +1,27 @@
|
||||
|
||||
layerinfo "type" = "core";
|
||||
layerinfo "majorversion" = "1";
|
||||
|
||||
function builtin string(int n) : string;
|
||||
|
||||
class TestClass {
|
||||
var string member;
|
||||
}
|
||||
|
||||
function returnThingy() : TestClass {
|
||||
return null TestClass;
|
||||
}
|
||||
|
||||
function main() {
|
||||
var TestClass test;
|
||||
var bool nullness = isnull $test;
|
||||
println ((isnull $test) ? "It's null" : "NOT A NULL!");
|
||||
if (isnull $test) {
|
||||
println "It's still null.";
|
||||
}
|
||||
if (isnull returnThingy()) {
|
||||
println "The function returned a null thingy";
|
||||
}
|
||||
$test = new TestClass;
|
||||
println "Member = \"$test.member\"";
|
||||
}
|
||||
4
wcmtools/s2/tests/null.s2.out
Executable file
4
wcmtools/s2/tests/null.s2.out
Executable file
@@ -0,0 +1,4 @@
|
||||
It's null
|
||||
It's still null.
|
||||
The function returned a null thingy
|
||||
Member = ""
|
||||
18
wcmtools/s2/tests/range.s2
Executable file
18
wcmtools/s2/tests/range.s2
Executable file
@@ -0,0 +1,18 @@
|
||||
#-*-c++-*-
|
||||
|
||||
layerinfo "type" = "core";
|
||||
layerinfo "majorversion" = 0;
|
||||
|
||||
function main ()
|
||||
{
|
||||
var int[] count = 1 .. 5;
|
||||
foreach var int i ($count) {
|
||||
println $i;
|
||||
}
|
||||
foreach var int i (true ? 5 .. 10 : 11 .. 20) {
|
||||
println $i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
11
wcmtools/s2/tests/range.s2.out
Executable file
11
wcmtools/s2/tests/range.s2.out
Executable file
@@ -0,0 +1,11 @@
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
20
wcmtools/s2/tests/readonly.s2
Executable file
20
wcmtools/s2/tests/readonly.s2
Executable file
@@ -0,0 +1,20 @@
|
||||
#-*-perl-*-
|
||||
|
||||
layerinfo type = core;
|
||||
layerinfo "majorversion" = 0;
|
||||
|
||||
class Foo
|
||||
{
|
||||
var readonly int a;
|
||||
var int b;
|
||||
}
|
||||
|
||||
property Foo f;
|
||||
|
||||
function main()
|
||||
{
|
||||
var Foo f;
|
||||
$f.b = 1;
|
||||
println "Foo.b = $f.b";
|
||||
# $f.a = 2;
|
||||
}
|
||||
1
wcmtools/s2/tests/readonly.s2.out
Executable file
1
wcmtools/s2/tests/readonly.s2.out
Executable file
@@ -0,0 +1 @@
|
||||
Foo.b = 1
|
||||
31
wcmtools/s2/tests/sizereverse.s2
Executable file
31
wcmtools/s2/tests/sizereverse.s2
Executable file
@@ -0,0 +1,31 @@
|
||||
#-*-perl-*-
|
||||
|
||||
layerinfo type = core;
|
||||
layerinfo "majorversion" = 0;
|
||||
|
||||
function builtin string(int i) : string;
|
||||
function builtin int(string s) : int;
|
||||
|
||||
function main ()
|
||||
{
|
||||
var int[] iarray;
|
||||
$iarray[0] = 0;
|
||||
$iarray[1] = 1;
|
||||
$iarray[2] = 2;
|
||||
$iarray[3] = 3;
|
||||
$iarray[4] = 4;
|
||||
$iarray[5] = 5;
|
||||
|
||||
$iarray = reverse $iarray;
|
||||
$iarray[0] = 0;
|
||||
$iarray[5] = 5;
|
||||
$iarray = reverse $iarray;
|
||||
|
||||
println "Size of array = " + string(size $iarray);
|
||||
println "Iterating over array:";
|
||||
foreach var int i ($iarray)
|
||||
{
|
||||
println $i;
|
||||
}
|
||||
println "Done.";
|
||||
}
|
||||
9
wcmtools/s2/tests/sizereverse.s2.out
Executable file
9
wcmtools/s2/tests/sizereverse.s2.out
Executable file
@@ -0,0 +1,9 @@
|
||||
Size of array = 6
|
||||
Iterating over array:
|
||||
5
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
0
|
||||
Done.
|
||||
37
wcmtools/s2/tests/super.s2
Executable file
37
wcmtools/s2/tests/super.s2
Executable file
@@ -0,0 +1,37 @@
|
||||
#-*-c++-*-
|
||||
|
||||
layerinfo "type" = "core";
|
||||
layerinfo "majorversion" = 0;
|
||||
|
||||
class Dog
|
||||
{
|
||||
var string name;
|
||||
function out;
|
||||
}
|
||||
|
||||
class KillerDog extends Dog
|
||||
{
|
||||
var int weight;
|
||||
}
|
||||
|
||||
function Dog::out {
|
||||
println "I'm a dog named \"$.name\".";
|
||||
}
|
||||
|
||||
function KillerDog::out {
|
||||
println "I'm a killer dog named \"$.name\" with weight $.weight";
|
||||
$super->out();
|
||||
}
|
||||
|
||||
function main ()
|
||||
{
|
||||
var KillerDog kd = new KillerDog;
|
||||
$kd.name = "Killer Dog";
|
||||
$kd.weight = 9999;
|
||||
$kd->out();
|
||||
|
||||
var Dog d = $kd;
|
||||
"And the same:\n";
|
||||
$d->out();
|
||||
}
|
||||
|
||||
5
wcmtools/s2/tests/super.s2.out
Executable file
5
wcmtools/s2/tests/super.s2.out
Executable file
@@ -0,0 +1,5 @@
|
||||
I'm a killer dog named "Killer Dog" with weight 9999
|
||||
I'm a dog named "Killer Dog".
|
||||
And the same:
|
||||
I'm a killer dog named "Killer Dog" with weight 9999
|
||||
I'm a dog named "Killer Dog".
|
||||
Reference in New Issue
Block a user