Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ lib/phake/builtins.php
lib/pharen/*.php
examples/*.php
test/*.php
test/tmp
ex
.DS_Store
170 changes: 85 additions & 85 deletions lang.php

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions test/tests/function_definition.phn
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@
1)
(check (one-expr) 1)

(local foo #one-expr)
(check ($foo) 1)

(fn one-arg (a)
(. "Argument is " a))
(check (one-arg "this") "Argument is this")

(local foo2 #one-arg)
(check ($foo2 "this") "Argument is this")

(fn add-two-args (a b)
(+ a b))
(check (add-two-args 133 123) 256)

(local foo3 #add-two-args)
(check ($foo3 133 123) 256)

(fn two-exprs (a b)
(one-arg a)
(one-arg b))
Expand Down
16 changes: 16 additions & 0 deletions test/tmp/bindings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
require_once('/Users/aarti/pharen/lang.php');
use Pharen\Lexical as Lexical;
use \Seq as Seq;
use \FastSeq as FastSeq;
Lexical::$scopes['_Users_aarti_pharen_test_tmpbindings'] = array();
$__scope_id = Lexical::init_closure("_Users_aarti_pharen_test_tmpbindings", 261);
$name = "Arthur Dent";
Lexical::bind_lexing("_Users_aarti_pharen_test_tmpbindings", 261, '$name', $name);
check($name, "Arthur Dent");
$job = "Jedi Masta";
check($job, "Jedi Masta");
$question = NULL;
$answer = (6 * 9);
check($question, NULL);
check($answer, 54);
9 changes: 9 additions & 0 deletions test/tmp/comments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
require_once('/Users/aarti/pharen/lang.php');
use Pharen\Lexical as Lexical;
use \Seq as Seq;
use \FastSeq as FastSeq;
Lexical::$scopes['_Users_aarti_pharen_test_tmpcomments'] = array();
check(1, 1);
check(1, 1);
check(1, 1);
46 changes: 46 additions & 0 deletions test/tmp/cond.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
require_once('/Users/aarti/pharen/lang.php');
use Pharen\Lexical as Lexical;
use \Seq as Seq;
use \FastSeq as FastSeq;
Lexical::$scopes['_Users_aarti_pharen_test_tmpcond'] = array();
$__scope_id = Lexical::init_closure("_Users_aarti_pharen_test_tmpcond", 264);
$num = 3;
Lexical::bind_lexing("_Users_aarti_pharen_test_tmpcond", 264, '$num', $num);
if(($num == 1)){
fail();
}
else if(($num == 2)){
fail();
}
else if(($num == 3)){
check(TRUE, TRUE);
}
else{
fail();
}
$s = "Hello, world!";
Lexical::bind_lexing("_Users_aarti_pharen_test_tmpcond", 264, '$s', $s);


$__condtmpvar5 = Null;
if(($s == "!dlrow, olleH")){
$__condtmpvar5 = "That's backwards!";
}
else if(($s == "Hello, world!")){
"Creative" . " much?";
$__condtmpvar5 = "Who is world anyway?";
}
check($__condtmpvar5, "Who is world anyway?");


$__condtmpvar6 = Null;
if((1 == 1)){
$__condtmpvar6 = "chicken";
}
else if((1 == 2)){
$__condtmpvar6 = "math broke again!";
}
$foo = $__condtmpvar6;
Lexical::bind_lexing("_Users_aarti_pharen_test_tmpcond", 264, '$foo', $foo);
check($foo, "chicken");
14 changes: 14 additions & 0 deletions test/tmp/func_calls.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
require_once('/Users/aarti/pharen/lang.php');
use Pharen\Lexical as Lexical;
use \Seq as Seq;
use \FastSeq as FastSeq;
Lexical::$scopes['_Users_aarti_pharen_test_tmpfunc_calls'] = array();
check(substr("abc", 1), "bc");
check((1 + 2 + 3.1), 6.1);
check(("hello, " . "world"), "hello, world");
check(substr(("foo" . "bar"), 3), "bar");
$__tmpfuncname4 = ("sub" . "str");
check($__tmpfuncname4("abc", 1), "bc");
$foo = "substr";
check($foo("abc", 1), "bc");
Empty file.
Empty file added test/tmp/hello.txt
Empty file.
56 changes: 56 additions & 0 deletions test/tmp/if.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
require_once('/Users/aarti/pharen/lang.php');
use Pharen\Lexical as Lexical;
use \Seq as Seq;
use \FastSeq as FastSeq;
Lexical::$scopes['_Users_aarti_pharen_test_tmpif'] = array();
$__scope_id = Lexical::init_closure("_Users_aarti_pharen_test_tmpif", 265);
$bool = TRUE;
Lexical::bind_lexing("_Users_aarti_pharen_test_tmpif", 265, '$bool', $bool);
if($bool){
check(TRUE, TRUE);
}
else{
check(TRUE, FALSE);
}

$__condtmpvar7 = Null;
if(TRUE){
$__condtmpvar7 = "This " . "works";
}
else{
$__condtmpvar7 = "Doesn't" . "work";
}
check($__condtmpvar7, "This works");

$__condtmpvar8 = Null;
if(FALSE){
$__condtmpvar8 = "Doesn't" . "work";
}
else{
$__condtmpvar8 = "This " . "works";
}
check($__condtmpvar8, "This works");

$__condtmpvar9 = Null;
if(TRUE){
$value = "True after all";
$__condtmpvar9 = Lexical::bind_lexing("_Users_aarti_pharen_test_tmpif", 265, '$value', $value);
}
else{
$value = "Shouldn't be here";
$__condtmpvar9 = Lexical::bind_lexing("_Users_aarti_pharen_test_tmpif", 265, '$value', $value);
}
$result = $__condtmpvar9;
Lexical::bind_lexing("_Users_aarti_pharen_test_tmpif", 265, '$result', $result);
check($result, "True after all");

$__condtmpvar10 = Null;
if(TRUE){
"Working";
$__condtmpvar10 = "Done!";
}
else{
$__condtmpvar10 = "Not working";
}
check($__condtmpvar10, "Done!");
75 changes: 75 additions & 0 deletions test/tmp/lambdas.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
require_once('/Users/aarti/pharen/lang.php');
use Pharen\Lexical as Lexical;
use \Seq as Seq;
use \FastSeq as FastSeq;
Lexical::$scopes['_Users_aarti_pharen_test_tmplambdas'] = array();
function _Users_aarti_pharen_test_tmplambdas__lambdafunc22($n, $__closure_id){
return ($n * 2);
}


check(arr(map(new \PharenLambda("\\_Users_aarti_pharen_test_tmplambdas__lambdafunc22", Lexical::get_closure_id("_Users_aarti_pharen_test_tmplambdas", Null)), \PharenVector::create_from_array(array(1, 2, 3)))), \PharenVector::create_from_array(array(2, 4, 6)));
function apply_test($f, $n){
$__scope_id = Lexical::init_closure("_Users_aarti_pharen_test_tmplambdas", 268);
Lexical::bind_lexing("_Users_aarti_pharen_test_tmplambdas", 268, '$f', $f);
return $f($n);
}

function _Users_aarti_pharen_test_tmplambdas__lambdafunc23($n, $__closure_id){
return ($n . " bar");
}


check(apply_test(new \PharenLambda("\\_Users_aarti_pharen_test_tmplambdas__lambdafunc23", Lexical::get_closure_id("_Users_aarti_pharen_test_tmplambdas", Null)), "foo"), "foo bar");
function _Users_aarti_pharen_test_tmplambdas__lambdafunc24($__closure_id){
$s = Lexical::get_lexical_binding('_Users_aarti_pharen_test_tmplambdas', 270, '$s', isset($__closure_id)?$__closure_id:0);;
return ("Hello " . $s . "!");
}

function greet_generator_test($s){
$__scope_id = Lexical::init_closure("_Users_aarti_pharen_test_tmplambdas", 270);
Lexical::bind_lexing("_Users_aarti_pharen_test_tmplambdas", 270, '$s', $s);
"line1";
return new \PharenLambda("\\_Users_aarti_pharen_test_tmplambdas__lambdafunc24", Lexical::get_closure_id("_Users_aarti_pharen_test_tmplambdas", $__scope_id));
}



$__tmpfuncname7 = greet_generator_test("Hammurabi");
check($__tmpfuncname7(), "Hello Hammurabi!");
function _Users_aarti_pharen_test_tmplambdas__lambdafunc25($__closure_id){
;
return "";
}

function _Users_aarti_pharen_test_tmplambdas__lambdafunc26($__closure_id){
;
return "foo";
}

function multi_lambdas(){


new \PharenLambda("\\_Users_aarti_pharen_test_tmplambdas__lambdafunc25", Lexical::get_closure_id("_Users_aarti_pharen_test_tmplambdas", Null));
return new \PharenLambda("\\_Users_aarti_pharen_test_tmplambdas__lambdafunc26", Lexical::get_closure_id("_Users_aarti_pharen_test_tmplambdas", Null));
}



$__tmpfuncname8 = multi_lambdas();
check($__tmpfuncname8(), "foo");
function _Users_aarti_pharen_test_tmplambdas__lambdafunc27($__closure_id){
return "foobar";
}

function multiple_calls_test(){
return new \PharenLambda("\\_Users_aarti_pharen_test_tmplambdas__lambdafunc27", Lexical::get_closure_id("_Users_aarti_pharen_test_tmplambdas", Null));
}



multiple_calls_test();
multiple_calls_test();
$__tmpfuncname9 = multiple_calls_test();
check($__tmpfuncname9(), "foobar");
Loading