Add TextWriter, IOException, per-VM module data and pre-load imports; Add console module with Console class
This commit is contained in:
+10
-9
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
class Program {
|
||||
|
||||
private string num2Roman(int $num) {
|
||||
@@ -17,15 +18,15 @@ class Program {
|
||||
}
|
||||
|
||||
public void main() {
|
||||
print(' 7 => ' + $this->num2Roman(7) + "\n");
|
||||
print(' 9 => ' + $this->num2Roman(9) + "\n");
|
||||
print(' 11 => ' + $this->num2Roman(11) + "\n");
|
||||
print(' 42 => ' + $this->num2Roman(42) + "\n");
|
||||
print(' 105 => ' + $this->num2Roman(105) + "\n");
|
||||
print('1984 => ' + $this->num2Roman(1984) + "\n");
|
||||
print('1999 => ' + $this->num2Roman(1999) + "\n");
|
||||
print('2018 => ' + $this->num2Roman(2018) + "\n");
|
||||
print('2144 => ' + $this->num2Roman(2144) + "\n");
|
||||
Console::Print(' 7 => ' + $this->num2Roman(7) + "\n");
|
||||
Console::Print(' 9 => ' + $this->num2Roman(9) + "\n");
|
||||
Console::Print(' 11 => ' + $this->num2Roman(11) + "\n");
|
||||
Console::Print(' 42 => ' + $this->num2Roman(42) + "\n");
|
||||
Console::Print(' 105 => ' + $this->num2Roman(105) + "\n");
|
||||
Console::Print('1984 => ' + $this->num2Roman(1984) + "\n");
|
||||
Console::Print('1999 => ' + $this->num2Roman(1999) + "\n");
|
||||
Console::Print('2018 => ' + $this->num2Roman(2018) + "\n");
|
||||
Console::Print('2144 => ' + $this->num2Roman(2144) + "\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
class Program {
|
||||
|
||||
void test_assert(mixed $param) {
|
||||
@@ -6,7 +7,7 @@ class Program {
|
||||
|
||||
public void main() {
|
||||
callback $assert_fail = void(string $file, int $line, string $code) {
|
||||
print("Assertion failed ...\n");
|
||||
Console::Print("Assertion failed ...\n");
|
||||
};
|
||||
assert_options(ASSERT_ACTIVE, true);
|
||||
assert_options(ASSERT_BAIL, false);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
class Brainfuck {
|
||||
private string $code;
|
||||
private int $code_pointer;
|
||||
@@ -18,7 +19,7 @@ class Brainfuck {
|
||||
$this->interpret($this->code[$this->code_pointer]);
|
||||
$this->code_pointer++;
|
||||
}
|
||||
print($this->output);
|
||||
Console::Print($this->output);
|
||||
}
|
||||
|
||||
private void interpret(string $command) {
|
||||
@@ -95,11 +96,11 @@ class Program {
|
||||
sort($files);
|
||||
unset($file);
|
||||
for(int $n = 0; $n < sizeof($files); $n++) {
|
||||
print('Executing "' + $files[$n] + '"' + "\n");
|
||||
Console::Print('Executing "' + $files[$n] + '"' + "\n");
|
||||
$code = file_get_contents('tests/data/brainfuck/' + $files[$n]);
|
||||
$bf = new Brainfuck($code, $input);
|
||||
$bf->run();
|
||||
print("\n");
|
||||
Console::Print("\n");
|
||||
}
|
||||
closedir($dir);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import 'console';
|
||||
class Program {
|
||||
|
||||
public void main(string[] $args) {
|
||||
callback $y = void() {
|
||||
callback $a = 'printf';
|
||||
callback $a = void(string $s) { Console::Print($s); };
|
||||
$a("I'm alive\n");
|
||||
var_dump($a);
|
||||
};
|
||||
@@ -10,6 +11,9 @@ class Program {
|
||||
var_dump($y);
|
||||
string $a = 'printf';
|
||||
var_dump($a);
|
||||
/* A string naming a builtin resolves as a callback value (C5). */
|
||||
callback $f = 'strtoupper';
|
||||
Console::PrintLine($f("builtin by name: " + "mixED"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
I'm alive
|
||||
callback(6 'printf')
|
||||
callback(11 '{closure_2}')
|
||||
callback(11 '{closure_1}')
|
||||
string(6 'printf')
|
||||
BUILTIN BY NAME: MIXED
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'math';
|
||||
import 'console';
|
||||
|
||||
class Program {
|
||||
|
||||
@@ -19,7 +20,7 @@ class Program {
|
||||
|
||||
public void main() {
|
||||
string $str = 'Example text';
|
||||
print($this->center_text($str));
|
||||
Console::Print($this->center_text($str));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
class Button {
|
||||
public callback $OnBeforeClick;
|
||||
public callback $OnAfterClick;
|
||||
@@ -9,7 +10,7 @@ class Button {
|
||||
|
||||
public void Click() {
|
||||
$this->DoBeforeClick();
|
||||
print('Click!');
|
||||
Console::Print('Click!');
|
||||
$this->DoAfterClick();
|
||||
}
|
||||
|
||||
@@ -33,8 +34,8 @@ class Program {
|
||||
|
||||
public void main() {
|
||||
object $MyWidget = new Button();
|
||||
$MyWidget->OnBeforeClick = void(object $Sender) { print($Sender->Name + ' (Before Click)'); };
|
||||
$MyWidget->OnAfterClick = void(object $Sender) { print($Sender->Name + ' (After Click)'); };
|
||||
$MyWidget->OnBeforeClick = void(object $Sender) { Console::Print($Sender->Name + ' (Before Click)'); };
|
||||
$MyWidget->OnAfterClick = void(object $Sender) { Console::Print($Sender->Name + ' (After Click)'); };
|
||||
$MyWidget->Click();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
class Operations {
|
||||
|
||||
public callback ops(int $x, int $y, string $op){
|
||||
@@ -26,11 +27,11 @@ class Program {
|
||||
callback $fn;
|
||||
object $op = new Operations();
|
||||
$fn = $op->ops(6, 7, 'ADD');
|
||||
print($fn() + "\n");
|
||||
Console::Print($fn() + "\n");
|
||||
$fn = $op->ops(6, 2, 'SUB');
|
||||
print($fn() + "\n");
|
||||
Console::Print($fn() + "\n");
|
||||
$fn = $op->ops(6, 7, 'MUL');
|
||||
print($fn() + "\n");
|
||||
Console::Print($fn() + "\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import 'console';
|
||||
class Program {
|
||||
private const MY_CONST = 12 ^ 0x3FD;
|
||||
private callback $callback_test = void(){ print("Welcome everyone!\n");};
|
||||
private callback $callback_test = void(){ Console::Print("Welcome everyone!\n");};
|
||||
private static int $value = 4 + 4 * 4;
|
||||
|
||||
void callable(callback $callback = void(){ print("Hello world!\n");}) {
|
||||
void callable(callback $callback = void(){ Console::Print("Hello world!\n");}) {
|
||||
$callback();
|
||||
}
|
||||
|
||||
void complexArgs(string $name = 'AerScript' + $this->someStr(), int $age = 10*2+5) {
|
||||
print("Name = $name\n");
|
||||
print("Age = $age\n");
|
||||
Console::Print("Name = $name\n");
|
||||
Console::Print("Age = $age\n");
|
||||
}
|
||||
|
||||
string someStr() {
|
||||
@@ -33,10 +34,10 @@ class Program {
|
||||
$this->complexArgs();
|
||||
$this->complexArgs('Me');
|
||||
$this->callable();
|
||||
$this->callable(void(){ print("Welcome guest!\n");});
|
||||
$this->callable(void(){ Console::Print("Welcome guest!\n");});
|
||||
$this->callable($this->callback_test);
|
||||
$this->someTrue() || print("someTrue() failed\n");
|
||||
$this->someFalse() || print("someFalse() failed\n");
|
||||
$this->someTrue() || Console::Print("someTrue() failed\n");
|
||||
$this->someFalse() || Console::Print("someFalse() failed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import 'console';
|
||||
class Program {
|
||||
|
||||
private void test(int $a = (int(int $a, int $b, int $c){return $a+$b+$c;})(14, 10+2, 15), int $b = 0, int $c = 98) {
|
||||
print($a + PHP_EOL);
|
||||
print($b + PHP_EOL);
|
||||
print($c + PHP_EOL);
|
||||
Console::Print($a + PHP_EOL);
|
||||
Console::Print($b + PHP_EOL);
|
||||
Console::Print($c + PHP_EOL);
|
||||
}
|
||||
|
||||
public void main() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class BaseClass {
|
||||
|
||||
protected void run() {
|
||||
printf('Test launched...');
|
||||
Console::Print('Test launched...');
|
||||
include 'data/includes/include_test.aer';
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
printf("OK!\n");
|
||||
Console::Print("OK!\n");
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
class Program {
|
||||
|
||||
public void main() {
|
||||
@@ -9,13 +10,13 @@ class Program {
|
||||
if(array_key_exists('args', $backtrace[0])) {
|
||||
var_export($backtrace[0]['args']);
|
||||
} else {
|
||||
print("Cannot aquire arguments\n");
|
||||
Console::Print("Cannot aquire arguments\n");
|
||||
}
|
||||
return $p;
|
||||
}
|
||||
|
||||
void b(string $p1, string $p2, string $p3) {
|
||||
print("$p1, $p2, $p3");
|
||||
Console::Print("$p1, $p2, $p3");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import 'console';
|
||||
class Test1 {
|
||||
|
||||
public void __construct() {
|
||||
print("Test1::__construct() called.\n");
|
||||
Console::Print("Test1::__construct() called.\n");
|
||||
}
|
||||
|
||||
public void __destruct() {
|
||||
print("Test1::__destruct() called.\n");
|
||||
Console::Print("Test1::__destruct() called.\n");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,12 +14,12 @@ class Test1 {
|
||||
class Test2 extends Test1 {
|
||||
|
||||
public void __construct() {
|
||||
print("Test2::__construct() called.\n");
|
||||
Console::Print("Test2::__construct() called.\n");
|
||||
$parent->__construct();
|
||||
}
|
||||
|
||||
public void __destruct() {
|
||||
print("Test2::__destruct() called.\n");
|
||||
Console::Print("Test2::__destruct() called.\n");
|
||||
$parent->__destruct();
|
||||
}
|
||||
|
||||
@@ -28,16 +29,16 @@ class Program {
|
||||
object $test;
|
||||
|
||||
public void __construct() {
|
||||
print("Program::__construct() called.\n");
|
||||
Console::Print("Program::__construct() called.\n");
|
||||
$this->test = new Test1();
|
||||
}
|
||||
|
||||
public void __destruct() {
|
||||
print("Program::__destruct() called.\n");
|
||||
Console::Print("Program::__destruct() called.\n");
|
||||
}
|
||||
|
||||
public void main() {
|
||||
print("Program::main() called.\n");
|
||||
Console::Print("Program::main() called.\n");
|
||||
object $test = new Test2();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
// A simple C program to calculate Euler's Totient Function
|
||||
class Program {
|
||||
|
||||
@@ -22,7 +23,7 @@ class Program {
|
||||
public int main() {
|
||||
int $n;
|
||||
for($n = 1; $n <= 10; $n++)
|
||||
printf("phi(%d) = %d\n", $n, $this->phi($n));
|
||||
Console::Print("phi(%d) = %d\n", $n, $this->phi($n));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import 'console';
|
||||
class ExceptionHandler {
|
||||
|
||||
public static void printException(Exception $e) {
|
||||
print('Uncaught ' + get_class($e) + ', code: ' + $e->getCode() + "\nMessage: " + htmlentities($e->getMessage()) + "\n");
|
||||
Console::Print('Uncaught ' + get_class($e) + ', code: ' + $e->getCode() + "\nMessage: " + htmlentities($e->getMessage()) + "\n");
|
||||
}
|
||||
|
||||
public static void handleException(Exception $e) {
|
||||
@@ -21,21 +22,21 @@ class Program {
|
||||
};
|
||||
set_exception_handler($handler);
|
||||
try {
|
||||
print("Called try block 0\n");
|
||||
Console::Print("Called try block 0\n");
|
||||
} finally {
|
||||
print("Called finally block 0\n");
|
||||
Console::Print("Called finally block 0\n");
|
||||
}
|
||||
try {
|
||||
throw new NewException("Catch me once", 1);
|
||||
} catch(Exception $e) {
|
||||
ExceptionHandler::handleException($e);
|
||||
} finally {
|
||||
print("Called finally block 1\n");
|
||||
Console::Print("Called finally block 1\n");
|
||||
}
|
||||
try {
|
||||
throw new NewException("Catch me twice", 2);
|
||||
} finally {
|
||||
print("Called finally block 2\n");
|
||||
Console::Print("Called finally block 2\n");
|
||||
}
|
||||
throw new Exception("Catch me thrice", 3);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'console';
|
||||
class Program {
|
||||
public void main() {
|
||||
bool $res = system("echo OK");
|
||||
print("Result: ", $res);
|
||||
Console::Print("Result: " + $res);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
class Dog {
|
||||
public string $name;
|
||||
public string $color;
|
||||
@@ -9,7 +10,7 @@ class Dog {
|
||||
|
||||
public callback greet(string $greeting) {
|
||||
return void() using ($greeting) {
|
||||
print("$greeting, I am a {$this->color} dog named {$this->name}\n");
|
||||
Console::Print("$greeting, I am a {$this->color} dog named {$this->name}\n");
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
class Program {
|
||||
|
||||
private int factorial(int $num) {
|
||||
@@ -9,7 +10,7 @@ class Program {
|
||||
|
||||
public void main() {
|
||||
int $num = 7;
|
||||
print('Factorial of ', $num, ' is ', $this->factorial($num), '.');
|
||||
Console::Print('Factorial of ' + $num + ' is ' + $this->factorial($num) + '.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import 'console';
|
||||
class Circle {
|
||||
public void draw() {
|
||||
print("Circle\n");
|
||||
Console::Print("Circle\n");
|
||||
}
|
||||
}
|
||||
|
||||
class Square {
|
||||
public void draw() {
|
||||
print("Square\n");
|
||||
Console::Print("Square\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
-10
@@ -1,30 +1,31 @@
|
||||
import 'console';
|
||||
class Test {
|
||||
|
||||
public void goto_test1() {
|
||||
int $i = 0;
|
||||
a:
|
||||
print("Foo $i\n");
|
||||
Console::Print("Foo $i\n");
|
||||
if($i > 5)
|
||||
goto b;
|
||||
$i++;
|
||||
goto a;
|
||||
b:
|
||||
print("Bar $i\n\n");
|
||||
Console::Print("Bar $i\n\n");
|
||||
}
|
||||
|
||||
public void goto_test2(int $a = 2) {
|
||||
switch($a) {
|
||||
case 1:
|
||||
print("\$a is 1\n\n");
|
||||
Console::Print("\$a is 1\n\n");
|
||||
goto out;
|
||||
case 2:
|
||||
print("\$a is 2\n\n");
|
||||
Console::Print("\$a is 2\n\n");
|
||||
goto out;
|
||||
case 3:
|
||||
print("\$a is 3\n\n");
|
||||
Console::Print("\$a is 3\n\n");
|
||||
goto out;
|
||||
case 4:
|
||||
print("\$a is 4\n\n");
|
||||
Console::Print("\$a is 4\n\n");
|
||||
goto out;
|
||||
}
|
||||
out:
|
||||
@@ -34,11 +35,11 @@ class Test {
|
||||
int $a = 10;
|
||||
a:
|
||||
$a--;
|
||||
print("$a\n");
|
||||
Console::Print("$a\n");
|
||||
if($a > 5) {
|
||||
goto a;
|
||||
}
|
||||
print("\n");
|
||||
Console::Print("\n");
|
||||
}
|
||||
|
||||
public void goto_test4() {
|
||||
@@ -47,9 +48,9 @@ class Test {
|
||||
int $c;
|
||||
hIterator: {
|
||||
$c = 0;
|
||||
print($headers[$pos], "\n");
|
||||
Console::Print($headers[$pos] + "\n");
|
||||
cIterator: {
|
||||
print(" ", $headers[$pos][$c], "\n");
|
||||
Console::Print(" " + $headers[$pos][$c] + "\n");
|
||||
if(strlen($headers[$pos]) <= ++$c) {
|
||||
goto cIteratorExit;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/local/bin/aer
|
||||
import 'console';
|
||||
class Program {
|
||||
|
||||
/*
|
||||
@@ -6,7 +7,7 @@ class Program {
|
||||
* It does not take any arguments.
|
||||
*/
|
||||
public void main() {
|
||||
print('Hello world!'); // single line comment
|
||||
Console::Print('Hello world!'); // single line comment
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
require 'data/includes/base_class.aer';
|
||||
require 'data/includes/test_class.aer';
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
interface iVehicle {
|
||||
|
||||
public void drive();
|
||||
@@ -8,11 +9,11 @@ interface iVehicle {
|
||||
class Car implements iVehicle {
|
||||
|
||||
public void drive() {
|
||||
print("Driving...\n");
|
||||
Console::Print("Driving...\n");
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
print("Stopping...\n");
|
||||
Console::Print("Stopping...\n");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,7 +21,7 @@ class Car implements iVehicle {
|
||||
class MyCar extends Car {
|
||||
|
||||
public void drive() {
|
||||
print("Driving my car...\n");
|
||||
Console::Print("Driving my car...\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
class Program {
|
||||
|
||||
string encode_ip(string $dotquad_ip) {
|
||||
@@ -12,11 +13,11 @@ class Program {
|
||||
|
||||
public void main() {
|
||||
string $localhost = $this->encode_ip('127.0.0.1');
|
||||
print("127.0.0.1 ==> $localhost\n");
|
||||
Console::Print("127.0.0.1 ==> $localhost\n");
|
||||
string $router = $this->encode_ip('192.168.2.1');
|
||||
print("192.168.2.1 ==> $router\n");
|
||||
print("$localhost ==> ", $this->decode_ip($localhost) + PHP_EOL);
|
||||
print("$router ==> ", $this->decode_ip($router) + PHP_EOL);
|
||||
Console::Print("192.168.2.1 ==> $router\n");
|
||||
Console::Print("$localhost ==> " + ($this->decode_ip($localhost) + PHP_EOL));
|
||||
Console::Print("$router ==> " + ($this->decode_ip($router) + PHP_EOL));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
class Program {
|
||||
|
||||
private int test() {
|
||||
@@ -15,9 +16,9 @@ class Program {
|
||||
} else if($z == 3) {
|
||||
break;
|
||||
}
|
||||
print("$z\n");
|
||||
Console::Print("$z\n");
|
||||
} while($a);
|
||||
print("$a\n");
|
||||
Console::Print("$a\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
class Program {
|
||||
|
||||
public void main() {
|
||||
@@ -11,10 +12,10 @@ class Program {
|
||||
if($b == 6) {
|
||||
break;
|
||||
}
|
||||
print("Hello variables: $a $b $c $d\n");
|
||||
Console::Print("Hello variables: $a $b $c $d\n");
|
||||
}
|
||||
}
|
||||
print("Variable \$c: $c\n");
|
||||
Console::Print("Variable \$c: $c\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
class Program {
|
||||
|
||||
public void main() {
|
||||
@@ -7,14 +8,14 @@ class Program {
|
||||
if($numeric == 6) {
|
||||
continue;
|
||||
}
|
||||
print("$key is $numeric\n");
|
||||
Console::Print("$key is $numeric\n");
|
||||
if($numeric == 8) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
print("\nA week has seven days:\n");
|
||||
Console::Print("\nA week has seven days:\n");
|
||||
foreach(string $day in $days) {
|
||||
print("$day\n");
|
||||
Console::Print("$day\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
class Program {
|
||||
|
||||
private int test() {
|
||||
@@ -15,9 +16,9 @@ class Program {
|
||||
} else if($b == 3) {
|
||||
break;
|
||||
}
|
||||
print("$b\n");
|
||||
Console::Print("$b\n");
|
||||
}
|
||||
print("$c\n");
|
||||
Console::Print("$c\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
class Luhn {
|
||||
private string $number;
|
||||
|
||||
@@ -33,9 +34,9 @@ class Program {
|
||||
while($i < $nums) {
|
||||
$luhn->setNumber($this->NUMBERS[$i]);
|
||||
if($luhn->validate()) {
|
||||
print('The number ' + $luhn->getNumber() + ' has passed the Luhn validation.' + "\n");
|
||||
Console::Print('The number ' + $luhn->getNumber() + ' has passed the Luhn validation.' + "\n");
|
||||
} else {
|
||||
print('The number ' + $luhn->getNumber() + ' has NOT passed the Luhn validation.' + "\n");
|
||||
Console::Print('The number ' + $luhn->getNumber() + ' has NOT passed the Luhn validation.' + "\n");
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import 'console';
|
||||
class Dog {
|
||||
|
||||
public void __invoke() {
|
||||
print("I am a dog!\n");
|
||||
Console::Print("I am a dog!\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
interface IntA {
|
||||
|
||||
public void test_a();
|
||||
@@ -13,7 +14,7 @@ interface IntB {
|
||||
class TestA {
|
||||
|
||||
public void test_a() {
|
||||
print("Hello world from TestA::test_a().\n");
|
||||
Console::Print("Hello world from TestA::test_a().\n");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,7 +22,7 @@ class TestA {
|
||||
class TestB {
|
||||
|
||||
public void test_b() {
|
||||
print("Hello world from TestB::test_b().\n");
|
||||
Console::Print("Hello world from TestB::test_b().\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +31,7 @@ class TestB {
|
||||
class TestC {
|
||||
|
||||
public void test_c() {
|
||||
print("Hello world from TestC::test_c().\n");
|
||||
Console::Print("Hello world from TestC::test_c().\n");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -38,7 +39,7 @@ class TestC {
|
||||
class TestD {
|
||||
|
||||
public void test_a() {
|
||||
print("Hello world from TestD::test_a().\n");
|
||||
Console::Print("Hello world from TestD::test_a().\n");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -46,7 +47,7 @@ class TestD {
|
||||
class TestE {
|
||||
|
||||
public void test_b() {
|
||||
print("Hello world from TestE::test_b().\n");
|
||||
Console::Print("Hello world from TestE::test_b().\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
class Program {
|
||||
|
||||
string[] testArray() {
|
||||
@@ -5,16 +6,18 @@ class Program {
|
||||
}
|
||||
|
||||
callback[] testCallback() {
|
||||
return {'callme' => void() { print("Hello world\n"); }};
|
||||
return {'callme' => void() { Console::Print("Hello world\n"); }};
|
||||
}
|
||||
|
||||
public void main() {
|
||||
callback[] $constr = {'print'};
|
||||
print($this->testArray()['Machine'] + "\n");
|
||||
callback[] $constr = { void(string $s) { Console::Print($s); } };
|
||||
Console::Print($this->testArray()['Machine'] + "\n");
|
||||
$this->testCallback()['callme']();
|
||||
print(true ? "TRUE\n" : false ? "true\n" : "false\n");
|
||||
(void(string $name) { print("This should work too - $name.\n");})('AerScript');
|
||||
Console::Print(true ? "TRUE\n" : false ? "true\n" : "false\n");
|
||||
(void(string $name) { Console::Print("This should work too - $name.\n");})('AerScript');
|
||||
$constr[0]('Test finished.' + "\n");
|
||||
callback[] $map = {'up' => 'strtoupper', 'low' => 'strtolower'};
|
||||
Console::Print("%s|%s\n", $map['up']("UPPER/lower"), $map['low']("UPPER/lower"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,3 +3,4 @@ Hello world
|
||||
TRUE
|
||||
This should work too - AerScript.
|
||||
Test finished.
|
||||
UPPER/LOWER|upper/lower
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import 'console';
|
||||
class Test {
|
||||
public void __construct(string $a) {
|
||||
print("$a\n");
|
||||
Console::Print("$a\n");
|
||||
}
|
||||
|
||||
public void __construct(int $a, int $b) {
|
||||
print("$a + $b = ", $a + $b, "\n");
|
||||
Console::Print("$a + $b = " + ($a + $b) + "\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import 'console';
|
||||
class Program {
|
||||
|
||||
public void count(int $a, int $b) {
|
||||
print("Counting 2 integers: $a + $b = ", $a + $b, "\n");
|
||||
Console::Print("Counting 2 integers: $a + $b = " + ($a + $b) + "\n");
|
||||
}
|
||||
|
||||
public void count(float $a, float $b) {
|
||||
print("Counting 2 floats: $a + $b = ", $a + $b, "\n");
|
||||
Console::Print("Counting 2 floats: $a + $b = " + ($a + $b) + "\n");
|
||||
}
|
||||
|
||||
public void main() {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
class Program {
|
||||
|
||||
private int fun(int $y) {
|
||||
@@ -13,12 +14,12 @@ class Program {
|
||||
int $y = 5;
|
||||
for(int $x = 0; $x < $y; $x++) {
|
||||
for($z = 0; $z <= ($y - $x - 2); $z++) {
|
||||
print(' ');
|
||||
Console::Print(' ');
|
||||
}
|
||||
for($z = 0; $z <= $x; $z++) {
|
||||
print($this->fun($x) / ($this->fun($z) * $this->fun($x - $z)), ' ');
|
||||
Console::Print(($this->fun($x) / ($this->fun($z) * $this->fun($x - $z))) + ' ');
|
||||
}
|
||||
print("\n");
|
||||
Console::Print("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+21
-20
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
class Program {
|
||||
private string $s = 'monkey';
|
||||
private string $t = 'many monkeys';
|
||||
@@ -11,29 +12,29 @@ class Program {
|
||||
}
|
||||
|
||||
private void testMonkey() {
|
||||
printf("[%s]\n", $this->s);
|
||||
printf("[%10s]\n", $this->s);
|
||||
printf("[%-10s]\n", $this->s);
|
||||
printf("[%010s]\n", $this->s);
|
||||
printf("[%'#10s]\n", $this->s);
|
||||
printf("[%10.10s]\n", $this->t);
|
||||
Console::Print("[%s]\n", $this->s);
|
||||
Console::Print("[%10s]\n", $this->s);
|
||||
Console::Print("[%-10s]\n", $this->s);
|
||||
Console::Print("[%010s]\n", $this->s);
|
||||
Console::Print("[%'#10s]\n", $this->s);
|
||||
Console::Print("[%10.10s]\n", $this->t);
|
||||
}
|
||||
|
||||
private void testNumbers() {
|
||||
printf("%%b = '%b'\n", $this->n);
|
||||
printf("%%c = '%c'\n", $this->c);
|
||||
printf("%%d = '%d'\n", $this->c);
|
||||
printf("%%d = '%d'\n", $this->n);
|
||||
printf("%%e = '%e'\n", $this->n);
|
||||
printf("%%u = '%u'\n", $this->n);
|
||||
printf("%%u = '%u'\n", $this->u);
|
||||
printf("%%f = '%f'\n", $this->n);
|
||||
printf("%%o = '%o'\n", $this->n);
|
||||
printf("%%s = '%s'\n", $this->n);
|
||||
printf("%%x = '%x'\n", $this->n);
|
||||
printf("%%X = '%X'\n", $this->n);
|
||||
printf("%%+d = '%+d'\n", $this->n);
|
||||
printf("%%+d = '%+d'\n", $this->u);
|
||||
Console::Print("%%b = '%b'\n", $this->n);
|
||||
Console::Print("%%c = '%c'\n", $this->c);
|
||||
Console::Print("%%d = '%d'\n", $this->c);
|
||||
Console::Print("%%d = '%d'\n", $this->n);
|
||||
Console::Print("%%e = '%e'\n", $this->n);
|
||||
Console::Print("%%u = '%u'\n", $this->n);
|
||||
Console::Print("%%u = '%u'\n", $this->u);
|
||||
Console::Print("%%f = '%f'\n", $this->n);
|
||||
Console::Print("%%o = '%o'\n", $this->n);
|
||||
Console::Print("%%s = '%s'\n", $this->n);
|
||||
Console::Print("%%x = '%x'\n", $this->n);
|
||||
Console::Print("%%X = '%X'\n", $this->n);
|
||||
Console::Print("%%+d = '%+d'\n", $this->n);
|
||||
Console::Print("%%+d = '%+d'\n", $this->u);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import 'console';
|
||||
final class Test {
|
||||
private int $value;
|
||||
|
||||
private void __construct() {
|
||||
print('Constructor called.' + "\n");
|
||||
Console::Print('Constructor called.' + "\n");
|
||||
}
|
||||
|
||||
private void __destruct() {
|
||||
print('Destructor called.' + "\n");
|
||||
Console::Print('Destructor called.' + "\n");
|
||||
}
|
||||
|
||||
/* This is singleton */
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'console';
|
||||
final virtual class Static {
|
||||
public static void test() {
|
||||
print('This method can be called statically...');
|
||||
Console::Print('This method can be called statically...');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
class Program {
|
||||
|
||||
private string cycle(char $a, char $b, int $i = 0) {
|
||||
@@ -11,11 +12,11 @@ class Program {
|
||||
|
||||
public void main() {
|
||||
for(int $i = 1; $i < 3; $i++) {
|
||||
print($i + $this->cycle('a', 'b') + PHP_EOL);
|
||||
Console::Print($i + $this->cycle('a', 'b') + PHP_EOL);
|
||||
for(int $j = 1; $j < 5; $j++) {
|
||||
print(' ' + $j + $this->cycle('a', 'b', 1) + PHP_EOL);
|
||||
Console::Print(' ' + $j + $this->cycle('a', 'b', 1) + PHP_EOL);
|
||||
for(int $k = 1; $k < 3; $k++) {
|
||||
print(' ' + $k + $this->cycle('c', 'd', 2) + PHP_EOL);
|
||||
Console::Print(' ' + $k + $this->cycle('c', 'd', 2) + PHP_EOL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'math';
|
||||
import 'console';
|
||||
|
||||
class Sudoku {
|
||||
public int[] $board;
|
||||
@@ -36,9 +37,9 @@ class Sudoku {
|
||||
public void print() {
|
||||
for(int $r = 0; $r < $this->size; $r++) {
|
||||
for(int $d = 0; $d < $this->size; $d++) {
|
||||
print($this->board[$r][$d] + " ");
|
||||
Console::Print($this->board[$r][$d] + " ");
|
||||
}
|
||||
print("\n");
|
||||
Console::Print("\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,11 +94,11 @@ class Program {
|
||||
};
|
||||
object $sudoku = new Sudoku($board);
|
||||
$sudoku->print();
|
||||
print("=================\n");
|
||||
Console::Print("=================\n");
|
||||
if($sudoku->solve()) {
|
||||
$sudoku->print();
|
||||
} else {
|
||||
print("No solution found\n");
|
||||
Console::Print("No solution found\n");
|
||||
$sudoku->print();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
import 'console';
|
||||
class Program {
|
||||
|
||||
public void main() {
|
||||
int $a = 1;
|
||||
switch($a) {
|
||||
case 0:
|
||||
print("very bad\n");
|
||||
Console::Print("very bad\n");
|
||||
break;
|
||||
case 1:
|
||||
print("very good\n");
|
||||
Console::Print("very good\n");
|
||||
case 2:
|
||||
print("good\n");
|
||||
Console::Print("good\n");
|
||||
break;
|
||||
default:
|
||||
print("bad");
|
||||
Console::Print("bad");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
class StringTokenizer {
|
||||
private string $token;
|
||||
private string $delim;
|
||||
@@ -28,7 +29,7 @@ class Program {
|
||||
string $delim = " !@:\t\n";
|
||||
object $st = new StringTokenizer($str, $delim);
|
||||
while ($st->hasMoreTokens()) {
|
||||
print($st->nextToken(), "\n");
|
||||
Console::Print($st->nextToken() + "\n");
|
||||
}
|
||||
unset($st);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import 'console';
|
||||
class Hanoi {
|
||||
|
||||
public void towerOfHanoi(int $diskCount, int $fromPole, int $toPole, int $viaPole) {
|
||||
if($diskCount == 1) {
|
||||
printf('Move disk from pole ' + $fromPole + ' to pole ' + $toPole + "\n");
|
||||
Console::Print('Move disk from pole ' + $fromPole + ' to pole ' + $toPole + "\n");
|
||||
} else {
|
||||
$this->towerOfHanoi($diskCount - 1, $fromPole, $viaPole, $toPole);
|
||||
$this->towerOfHanoi(1, $fromPole, $toPole, $viaPole);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'console';
|
||||
class Program {
|
||||
private string $概要 = "AerScript Interpreter";
|
||||
|
||||
@@ -9,7 +10,7 @@ class Program {
|
||||
}
|
||||
|
||||
private void ダウンロード(){
|
||||
print($this->概要 + "\n");
|
||||
Console::Print($this->概要 + "\n");
|
||||
}
|
||||
|
||||
private bool isUTF8(string $str) {
|
||||
|
||||
Reference in New Issue
Block a user