Skip to content

Commit

Permalink
Merge pull request #11 from mr-hashemi/main-to-azinja
Browse files Browse the repository at this point in the history
Main to azinja
  • Loading branch information
Soroosh Sarabadani committed Dec 27, 2019
2 parents aaf1270 + bbc83ff commit 87fa1ee
Show file tree
Hide file tree
Showing 69 changed files with 111 additions and 101 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ We hope Mr. Hashemi get enough attention to make bilions of tomans out of this p

**example:**
```java
bebin main() {
bebin azinja() {
i = 0;
ta (i<1) bood {
bechap("adad bede");
Expand Down
4 changes: 2 additions & 2 deletions docs/_posts/2019-12-25-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ chmod +x hashem
ابتدا فایلی با نام `dorood-jahan.hashem` ایجاد کنید که حاوی کدی که در پایین آمده باشد.

{% highlight bash %}
bebin main() {
bebin azinja() {
bechap("Dorood Jahan");
}
{% endhighlight %}
Expand All @@ -39,4 +39,4 @@ hashem dorood-jahan.hashem

اگر در اجرای مراحل بالا مشکلی داشتید حتما برای آقای هاشمی
[ایشو](https://github.com/psycho-ir/mr-hashemi/issues)
بسازید تا بتونیم زودتر مشکلات رو حل کنیم.
بسازید تا بتونیم زودتر مشکلات رو حل کنیم.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected CallTarget parse(ParsingRequest request) throws Exception {
} else {
Source requestedSource = request.getSource();
StringBuilder sb = new StringBuilder();
sb.append("bebin main(");
sb.append("bebin azinja(");
String sep = "";
for (String argumentName : request.getArgumentNames()) {
sb.append(sep);
Expand All @@ -87,7 +87,7 @@ protected CallTarget parse(ParsingRequest request) throws Exception {
functions = HashemLanguageParser.parseHashemiLang(this, decoratedSource);
}

RootCallTarget main = functions.get("main");
RootCallTarget main = functions.get("azinja");
RootNode evalMain;
if (main != null) {
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
public class HashemDebugALot {

private final Source slCode = Source.create("hashemi", "bebin main() {\n" +
private final Source slCode = Source.create("hashemi", "bebin azinja() {\n" +
" n = 2;\n" +
" return types(n);\n" +
"}\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,25 @@ public void tearDown() {

@Test
public void testExceptions() {
assertException(true, "bebin main() { x = 1 / (1 == 1); }", "main");
assertException(true, "bebin foo() { bede 1 / \"foo\"; } bebin main() { foo(); }", "foo", "main");
assertException(true, "bebin foo() { bar(); } bebin bar() { bede 1 / \"foo\"; } bebin main() { foo(); }", "bar", "foo", "main");
assertException(true, "bebin foo() { bar1(); bar2(); } bebin bar1() { bede 1; } bebin bar2() { bede \"foo\" / 1; } bebin main() { foo(); }", "bar2", "foo", "main");
assertException(true, "bebin azinja() { x = 1 / (1 == 1); }", "azinja");
assertException(true, "bebin foo() { bede 1 / \"foo\"; } bebin azinja() { foo(); }", "foo", "azinja");
assertException(true, "bebin foo() { bar(); } bebin bar() { bede 1 / \"foo\"; } bebin azinja() { foo(); }", "bar", "foo", "azinja");
assertException(true, "bebin foo() { bar1(); bar2(); } bebin bar1() { bede 1; } bebin bar2() { bede \"foo\" / 1; } bebin azinja() { foo(); }", "bar2", "foo", "azinja");
}

@Test
public void testNonMain() {
assertException(false, "bebin foo(z) { x = 1 / (1==1); } bebin main() { bede foo; }", "foo");
assertException(false, "bebin foo(z) { x = 1 / (1==1); } bebin azinja() { bede foo; }", "foo");
}

@Test
public void testThroughProxy() {
assertException(false, "bebin bar() { x = 1 / (1==1); } bebin foo(z) { z(bar); } bebin main() { bede foo; }", "bar", null, null, "foo");
assertException(false, "bebin bar() { x = 1 / (1==1); } bebin foo(z) { z(bar); } bebin azinja() { bede foo; }", "bar", null, null, "foo");
}

@Test
public void testHostException() {
assertHostException("bebin foo(z) { z(1); } bebin main() { bede foo; }", null, "foo");
assertHostException("bebin foo(z) { z(1); } bebin azinja() { bede foo; }", null, "foo");
}

private void assertException(boolean failImmediately, String source, String... expectedFrames) {
Expand Down Expand Up @@ -126,7 +126,7 @@ public void testGuestLanguageError() {
try {
String source = "bebin bar() { x = 1 / \"asdf\"; }\n" +
"bebin foo() { bede bar(); }\n" +
"bebin main() { foo(); }";
"bebin azinja() { foo(); }";
ctx.eval(Source.newBuilder("hashemi", source, "script.hashemi").buildLiteral());
fail();
} catch (PolyglotException e) {
Expand All @@ -135,7 +135,7 @@ public void testGuestLanguageError() {
Iterator<StackFrame> frames = e.getPolyglotStackTrace().iterator();
assertGuestFrame(frames, "hashemi", "bar", "script.hashemi", 18, 28);
assertGuestFrame(frames, "hashemi", "foo", "script.hashemi", 51, 56);
assertGuestFrame(frames, "hashemi", "main", "script.hashemi", 75, 80);
assertGuestFrame(frames, "hashemi", "azinja", "script.hashemi", 77, 82);
assertHostFrame(frames, Context.class.getName(), "eval");
assertHostFrame(frames, HashemExceptionTest.class.getName(), "testGuestLanguageError");

Expand Down Expand Up @@ -177,7 +177,7 @@ public Object execute(Value... t) {

@Test
public void testProxyGuestLanguageStack() {
Value bar = ctx.eval("hashemi", "bebin foo(f) { f(); } bebin bar(f) { bede foo(f); } bebin main() { bede bar; }");
Value bar = ctx.eval("hashemi", "bebin foo(f) { f(); } bebin bar(f) { bede foo(f); } bebin azinja() { bede bar; }");

TestProxy proxy = new TestProxy(3, bar);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void testLexicalScopes() throws Exception {
" bechap(b);\n" +
" bechap(a);\n" + // 20
"}\n" +
"bebin main() {\n" +
"bebin azinja() {\n" +
" test(\"n_n\");\n" +
"}";
Source source = Source.newBuilder("hashemi", code, "testing").build();
Expand Down Expand Up @@ -377,7 +377,7 @@ private static void verifyLexicalScopes(Iterable<Scope> lexicalScopes, Iterable<
case 22:
case 23:
for (Scope ls : lexicalScopes) {
checkRootNode(ls, "main", frame);
checkRootNode(ls, "azinja", frame);
TruffleObject arguments = (TruffleObject) ls.getArguments();
checkVars(arguments);
TruffleObject variables = (TruffleObject) ls.getVariables();
Expand All @@ -387,7 +387,7 @@ private static void verifyLexicalScopes(Iterable<Scope> lexicalScopes, Iterable<
assertEquals("LexicalScope depth", 1, depth);
depth = 0;
for (Scope ls : dynamicScopes) {
checkRootNode(ls, "main", frame);
checkRootNode(ls, "azinja", frame);
TruffleObject arguments = (TruffleObject) ls.getArguments();
checkVars(arguments);
TruffleObject variables = (TruffleObject) ls.getVariables();
Expand Down Expand Up @@ -458,7 +458,7 @@ private static void checkVars(TruffleObject vars, Object... expected) {

@Test
public void testOutput() throws IOException {
String code = "bebin main() {\n" +
String code = "bebin azinja() {\n" +
" f = fac(5);\n" +
" bechap(f);\n" +
"}\n" +
Expand Down Expand Up @@ -548,7 +548,7 @@ String readLinesList(BufferedReader br) throws IOException {
*/
@Test
public void testRedoIO() throws Throwable {
String code = "bebin main() {\n" +
String code = "bebin azinja() {\n" +
" a = bekhoon();\n" +
" bede a;\n" +
"}\n";
Expand Down Expand Up @@ -649,7 +649,7 @@ public Object onUnwind(EventContext context, VirtualFrame frame, Object info) {
*/
@Test
public void testEarlyReturn() throws Exception {
String code = "bebin main() {\n" +
String code = "bebin azinja() {\n" +
" a = 10;\n" +
" b = a;\n" +
" // Let fce() warm up and specialize:\n" +
Expand Down Expand Up @@ -775,7 +775,7 @@ public Object onUnwind(EventContext context, VirtualFrame frame, Object info) {
// if (System.getProperty("java.vm.name").contains("Graal:graal-enterprise")) {
// return; // GR-16755
// }
// String code = "bebin main() {\n" +
// String code = "bebin azinja() {\n" +
// " a = jadid();\n" +
// " b = a.rp1;\n" +
// " return b;\n" +
Expand Down Expand Up @@ -897,7 +897,7 @@ Object readArrayElement(long index) throws InvalidArrayIndexException {
*/
@Test
public void testChangeArgumentsOnReenter() throws Exception {
String code = "bebin main() {\n" +
String code = "bebin azinja() {\n" +
" y = fce(0, 10000);\n" +
" bede y;\n" +
"}\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public void tearDown() {

@Test
public void testWhile() {
final Source src = Source.newBuilder("hashemi", "bebin testTa(a) {ta(a) bood {khob;}} bebin main() {bede testTa;}", "testTa.hashem").buildLiteral();
final Source src = Source.newBuilder("hashemi", "bebin testTa(a) {ta(a) bood {khob;}} bebin azinja() {bede testTa;}", "testTa.hashem").buildLiteral();
final Value fnc = context.eval(src);
Assert.assertTrue(fnc.canExecute());
fnc.execute(false);
}

@Test
public void testIf() {
final Source src = Source.newBuilder("hashemi", "bebin testIf(a) {age (a) bood {bede 1;} na? {bede 0;}} bebin main() {bede testIf;}", "testIf.hashem").buildLiteral();
final Source src = Source.newBuilder("hashemi", "bebin testIf(a) {age (a) bood {bede 1;} na? {bede 0;}} bebin azinja() {bede testIf;}", "testIf.hashem").buildLiteral();
final Value fnc = context.eval(src);
fnc.execute(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void tearDown() {

@Test
public void testObject() {
final Source src = Source.newBuilder("hashemi", "bebin main() {o = jadid(); o.a = 10; o.b = \"B\"; bede o;}", "testObject.hashem").buildLiteral();
final Source src = Source.newBuilder("hashemi", "bebin azinja() {o = jadid(); o.a = 10; o.b = \"B\"; bede o;}", "testObject.hashem").buildLiteral();
final Value obj = context.eval(src);
Assert.assertTrue(obj.hasMembers());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void tearDown() {

@Test
public void testAdd() {
final Source src = Source.newBuilder("hashemi", "bebin testAdd(a,b) {bede a + b;} bebin main() {bede testAdd;}", "testAdd.hashem").buildLiteral();
final Source src = Source.newBuilder("hashemi", "bebin testAdd(a,b) {bede a + b;} bebin azinja() {bede testAdd;}", "testAdd.hashem").buildLiteral();
final Value fnc = context.eval(src);
Assert.assertTrue(fnc.canExecute());
final Value res = fnc.execute(1, 2);
Expand All @@ -34,7 +34,7 @@ public void testAdd() {

@Test
public void testSub() {
final Source src = Source.newBuilder("hashemi", "bebin testSub(a,b) {bede a - b;} bebin main() {bede testSub;}", "testSub.hashem").buildLiteral();
final Source src = Source.newBuilder("hashemi", "bebin testSub(a,b) {bede a - b;} bebin azinja() {bede testSub;}", "testSub.hashem").buildLiteral();
final Value fnc = context.eval(src);
final Value res = fnc.execute(1, 2);
Assert.assertTrue(res.isNumber());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public void tearDown() {

@Test
public void testBoolean() {
final Source src = Source.newBuilder("hashemi", "bebin testBoolean(a,b) {bede a == b;} bebin main() {bede testBoolean;}", "testBoolean.hashem").buildLiteral();
final Source src = Source.newBuilder("hashemi", "bebin testBoolean(a,b) {bede a == b;} bebin azinja() {bede testBoolean;}", "testBoolean.hashem").buildLiteral();
final Value fnc = context.eval(src);
Assert.assertTrue(fnc.canExecute());
fnc.execute(true, false);
}

@Test
public void testChar() {
final Source src = Source.newBuilder("hashemi", "bebin testChar(a,b) {bede a == b;} bebin main() {bede testChar;}", "testChar.hashem").buildLiteral();
final Source src = Source.newBuilder("hashemi", "bebin testChar(a,b) {bede a == b;} bebin azinja() {bede testChar;}", "testChar.hashem").buildLiteral();
final Value fnc = context.eval(src);
Assert.assertTrue(fnc.canExecute());
fnc.execute('a', 'b');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void testParseErrorEmpty() {
@Test
public void testParseErrorEOF1() {
try {
final Source src = Source.newBuilder("hashemi", "bebin main", "testSyntaxErrorEOF1.hashem").buildLiteral();
final Source src = Source.newBuilder("hashemi", "bebin azinja", "testSyntaxErrorEOF1.hashem").buildLiteral();
context.eval(src);
Assert.assertTrue("Should not reach here.", false);
} catch (PolyglotException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void setUp() {
"obj1.number = 42;\n" +
"bede obj1;\n" +
"}\n" +
"bebin main() {\n" +
"bebin azinja() {\n" +
"bede createObject;\n" +
"}").execute();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void closeEngines() {
public void shareCodeUseDifferentOutputStreams() throws Exception {

String sayHello =
"bebin main() {\n" +
"bebin azinja() {\n" +
" bekhoon(\"Ahoj\" + import(\"extra\"));" +
"}";
// @formatter:on
Expand All @@ -79,7 +79,7 @@ public void instrumentsSeeOutputOfBoth() throws Exception {
ByteArrayOutputStream outConsumer = outInstr.lookup(ByteArrayOutputStream.class);
assertNotNull("Stream capturing is ready", outConsumer);

String sayHello = "bebin main() {\n" +
String sayHello = "bebin azinja() {\n" +
" bekhoon(\"Ahoj\" + import(\"extra\"));" +
"}";
// @formatter:on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private static Value eval(final Context context, final String fncDecl, final Str
return context.eval(ID,
fncDecl +
"\n" +
"bebin main() {\n" +
"bebin azinja() {\n" +
String.format(" return %s;\n", functionName) +
"}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public void prepareSystem() {
myObj = new MyObj();
context = Context.newBuilder().allowPolyglotAccess(PolyglotAccess.ALL).build();
context.getPolyglotBindings().putMember("myObj", myObj);
context.eval("hashemi", "bebin main() {\n" + " bede import(\"myObj\");\n" + "}\n");
myObjWrapped = context.getBindings("hashemi").getMember("main").execute();
context.eval("hashemi", "bebin azinja() {\n" + " bede import(\"myObj\");\n" + "}\n");
myObjWrapped = context.getBindings("hashemi").getMember("azinja").execute();
assertFalse(myObjWrapped.isNull());
myObjCall = myObjWrapped.as(CallWithValue.class);
}
Expand Down
2 changes: 1 addition & 1 deletion language/tests/Add.hashem
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bebin main() {
bebin azinja() {
bechap(3 + 4);
bechap(3 + "4");
bechap("3" + 4);
Expand Down
2 changes: 1 addition & 1 deletion language/tests/Arithmetic.hashem
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bebin main() {
bebin azinja() {
bechap(3 + 4 - 2);
bechap(3 - 4 + 2);
bechap(3 - 4 - 2);
Expand Down
2 changes: 1 addition & 1 deletion language/tests/Break.hashem
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bebin main() {
bebin azinja() {
i = 0;
ta (i < 1000) bood {
age (i >= 942) bood {
Expand Down
2 changes: 1 addition & 1 deletion language/tests/Builtins.hashem
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bebin main() {
bebin azinja() {
bechap("Hello World!");
nanoTime();
}
2 changes: 1 addition & 1 deletion language/tests/Call.hashem
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ bebin inc(a) { bede a + 1; }
bebin dec(a) { bede a - 1; }
bebin call(f, v) { bede f(v); }

bebin main() {
bebin azinja() {
bechap(ret(42));
bechap(dub(21));
bechap(inc(41));
Expand Down
2 changes: 1 addition & 1 deletion language/tests/Comparison.hashem
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bebin main() {
bebin azinja() {
bechap("<");
bechap(4 < 20);
bechap(40 < 2);
Expand Down
2 changes: 1 addition & 1 deletion language/tests/ControlFlow.hashem
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bebin foo() {}
bebin bar() {}

bebin main() {
bebin azinja() {
foo();
age (1 < 2) bood{
bar();
Expand Down
2 changes: 1 addition & 1 deletion language/tests/DefineFunction.hashem
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ bebin foo() {
bechap(test(40, 2));
}

bebin main() {
bebin azinja() {
defineFunction("bebin test(a, b) { bede a + b; }");
foo();

Expand Down
2 changes: 1 addition & 1 deletion language/tests/Div.hashem
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bebin main() {
bebin azinja() {
bechap(4 / 2);
bechap(4 / 4000000000000);
bechap(3000000000000 / 3);
Expand Down
2 changes: 1 addition & 1 deletion language/tests/Equal.hashem
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ bebin e(a, b) {
bede a == b;
}

bebin main() {
bebin azinja() {
bechap(e(4, 4));
bechap(e(3, "aaa"));
bechap(e(4, 4));
Expand Down
2 changes: 1 addition & 1 deletion language/tests/Eval.hashem
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bebin main() {
bebin azinja() {
eval("hashemi", "bebin foo() { bede 14 + 2; }");
bechap(foo());
}
2 changes: 1 addition & 1 deletion language/tests/Fibonacci.hashem
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ bebin fib(num) {
bede n2;
}

bebin main() {
bebin azinja() {
i = 1;
ta (i <= 10) bood {
bechap(i + ": " + fib(i));
Expand Down
2 changes: 1 addition & 1 deletion language/tests/FunctionLiteral.hashem
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bebin foo(f) {
bechap(f(40, 2));
}

bebin main() {
bebin azinja() {
foo(add);
foo(sub);
}

0 comments on commit 87fa1ee

Please sign in to comment.