sandbox() public static method

public static sandbox ( )
Beispiel #1
0
 function testSandbox($scope = null)
 {
     if (is_null($scope)) {
         $scope = Lisphp_Environment::sandbox();
     }
     $this->assertType('Lisphp_Scope', $scope);
     $this->assertNull($scope['nil']);
     $this->assertTrue($scope['true']);
     $this->assertFalse($scope['false']);
     $this->assertTrue($scope['#t']);
     $this->assertFalse($scope['#f']);
     $this->assertType('Lisphp_Runtime_Eval', $scope['eval']);
     $this->assertType('Lisphp_Runtime_Quote', $scope['quote']);
     $this->assertType('Lisphp_Runtime_PHPFunction', $scope['symbol']);
     $this->assertEquals(array('Lisphp_Symbol', 'get'), $scope['symbol']->callback);
     $this->assertType('Lisphp_Runtime_Define', $scope['define']);
     $this->assertType('Lisphp_Runtime_Let', $scope['let']);
     $this->assertType('Lisphp_Runtime_Macro', $scope['macro']);
     $this->assertType('Lisphp_Runtime_Lambda', $scope['lambda']);
     $this->assertType('Lisphp_Runtime_Apply', $scope['apply']);
     $this->assertType('Lisphp_Runtime_Do', $scope['do']);
     $this->assertType('Lisphp_Runtime_Dict', $scope['dict']);
     $this->assertType('Lisphp_Runtime_Array', $scope['array']);
     $this->assertType('Lisphp_Runtime_List', $scope['list']);
     $this->assertType('Lisphp_Runtime_List_Car', $scope['car']);
     $this->assertType('Lisphp_Runtime_List_Cdr', $scope['cdr']);
     $this->assertType('Lisphp_Runtime_List_At', $scope['at']);
     $this->assertType('Lisphp_Runtime_List_SetAt', $scope['set-at!']);
     $this->assertType('Lisphp_Runtime_List_UnsetAt', $scope['unset-at!']);
     $this->assertType('Lisphp_Runtime_List_ExistsAt', $scope['exists-at?']);
     $this->assertType('Lisphp_Runtime_List_Count', $scope['count']);
     $this->assertType('Lisphp_Runtime_List_Map', $scope['map']);
     $this->assertType('Lisphp_Runtime_List_Filter', $scope['filter']);
     $this->assertType('Lisphp_Runtime_List_Fold', $scope['fold']);
     $this->assertType('Lisphp_Runtime_Predicate_Eq', $scope['==']);
     $this->assertType('Lisphp_Runtime_Predicate_Eq', $scope['eq']);
     $this->assertType('Lisphp_Runtime_Predicate_Eq', $scope['eq?']);
     $this->assertType('Lisphp_Runtime_Predicate_Equal', $scope['=']);
     $this->assertType('Lisphp_Runtime_Predicate_Equal', $scope['equal']);
     $this->assertType('Lisphp_Runtime_Predicate_Equal', $scope['equal?']);
     $this->assertType('Lisphp_Runtime_Predicate_NotEq', $scope['/==']);
     $this->assertType('Lisphp_Runtime_Predicate_NotEq', $scope['!==']);
     $this->assertType('Lisphp_Runtime_Predicate_NotEq', $scope['not-eq']);
     $this->assertType('Lisphp_Runtime_Predicate_NotEq', $scope['not-eq?']);
     $this->assertType('Lisphp_Runtime_Predicate_NotEqual', $scope['!=']);
     $this->assertType('Lisphp_Runtime_Predicate_NotEqual', $scope['/=']);
     $this->assertType('Lisphp_Runtime_Predicate_NotEqual', $scope['not-equal']);
     $this->assertType('Lisphp_Runtime_Predicate_NotEqual', $scope['not-equal?']);
     foreach (Lisphp_Runtime_Predicate_Type::$types as $type) {
         $this->assertType('Lisphp_Runtime_Predicate_Type', $scope["{$type}?"]);
         $this->assertEquals($type, $scope["{$type}?"]->type);
     }
     $this->assertType('Lisphp_Runtime_Predicate_Type', $scope['nil?']);
     $this->assertEquals('null', $scope['nil?']->type);
     $this->assertType('Lisphp_Runtime_Predicate_IsA', $scope['is-a?']);
     $this->assertType('Lisphp_Runtime_Predicate_IsA', $scope['isa?']);
     $this->assertType('Lisphp_Runtime_Arithmetic_Addition', $scope['+']);
     $this->assertType('Lisphp_Runtime_Arithmetic_Subtraction', $scope['-']);
     $this->assertType('Lisphp_Runtime_Arithmetic_Multiplication', $scope['*']);
     $this->assertType('Lisphp_Runtime_Arithmetic_Division', $scope['/']);
     $this->assertType('Lisphp_Runtime_Arithmetic_Modulus', $scope['%']);
     $this->assertType('Lisphp_Runtime_Arithmetic_Modulus', $scope['mod']);
     $this->assertType('Lisphp_Runtime_PHPFunction', $scope['string']);
     $this->assertEquals('strval', $scope['string']->callback);
     $this->assertType('Lisphp_Runtime_String_Concat', $scope['.']);
     $this->assertType('Lisphp_Runtime_String_Concat', $scope['concat']);
     $this->assertType('Lisphp_Runtime_String_StringJoin', $scope['string-join']);
     $this->assertType('Lisphp_Runtime_PHPFunction', $scope['substring']);
     $this->assertEquals('substr', $scope['substring']->callback);
     $this->assertType('Lisphp_Runtime_PHPFunction', $scope['string-upcase']);
     $this->assertEquals('strtoupper', $scope['string-upcase']->callback);
     $this->assertType('Lisphp_Runtime_PHPFunction', $scope['string-downcase']);
     $this->assertEquals('strtolower', $scope['string-downcase']->callback);
     $this->assertType('Lisphp_Runtime_Logical_Not', $scope['not']);
     $this->assertType('Lisphp_Runtime_Logical_And', $scope['and']);
     $this->assertType('Lisphp_Runtime_Logical_Or', $scope['or']);
     $this->assertType('Lisphp_Runtime_Logical_If', $scope['if']);
     $this->assertType('Lisphp_Runtime_Object_GetAttribute', $scope['->']);
 }
Beispiel #2
0
 function testFrom()
 {
     $from = new Lisphp_Runtime_From();
     $env = Lisphp_Environment::sandbox();
     $scope = new Lisphp_Scope($env);
     $values = $from->apply($scope, self::lst('Lisphp (<Symbol> <Program>)'));
     $this->assertEquals('Lisphp_Symbol', $values[0]->class->getName());
     $this->assertEquals('Lisphp_Symbol', $scope['<Symbol>']->class->getName());
     $this->assertEquals('Lisphp_Program', $values[1]->class->getName());
     $this->assertEquals('Lisphp_Program', $scope['<Program>']->class->getName());
 }
Beispiel #3
0
 public function testFrom()
 {
     $from = new Lisphp_Runtime_From();
     $env = Lisphp_Environment::sandbox();
     $scope = new Lisphp_Scope($env);
     $values = $from->apply($scope, self::lst('Foo (<Bar> <Baz>)'));
     $this->assertEquals('Foo\\Bar', $values[0]->class->getName());
     $this->assertEquals('Foo\\Bar', $scope['<Bar>']->class->getName());
     $this->assertEquals('Foo\\Baz', $values[1]->class->getName());
     $this->assertEquals('Foo\\Baz', $scope['<Baz>']->class->getName());
 }
Beispiel #4
0
    echo $lines[$e->getLisphpLine() - 1], "\n";
    echo str_repeat(' ', $e->getLisphpColumn() - 1), "^\n";
}
$options = getopt('hvsc:');
if (isset($options['h']) || isset($options['v'])) {
    echo 'Lisphp ' . LISPHP_VERSION . "\n";
    if (isset($options['v'])) {
        echo 'PHP-', PHP_VERSION, "\n", php_uname(), "\n";
    }
    if (isset($options['h'])) {
        echo "Usage: {$_SERVER['argv'][0]} [options] <file>\n\n";
        echo Lisphp_usage(), "\n";
    }
    exit;
}
$environment = isset($options['s']) ? Lisphp_Environment::sandbox() : Lisphp_Environment::full();
$scope = new Lisphp_Scope($environment);
$scope['echo'] = new Lisphp_Runtime_PHPFunction(create_function('', '
    $args = func_get_args();
    foreach ($args as $arg) echo $arg;
'));
class Lisphp_EnterREPL extends Exception
{
}
try {
    $file = end($_SERVER['argv']);
    if (isset($options['c'])) {
        $program = new Lisphp_Program($options['c']);
    } else {
        if (count($_SERVER['argv']) > 1 && $file != '-s') {
            $program = Lisphp_Program::load($file);