Skip to content

Commit 109fb02

Browse files
committed
تم إنهاء تعريف الخطية مع تحديث ملف ما الجديد
1 parent b9b3877 commit 109fb02

8 files changed

Lines changed: 111 additions & 76 deletions

File tree

documents/ما الجديد.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,23 @@
107107
انواع الأخطاء التي تمت إضافتها:
108108
خطأ_نوع | خطأ_قيمة | خطأ_نظام | خطأ_مسافة_بادئة | خطأ_نسق | خطأ_اثناء_التشغيل | خطأ_فائض | خطأ_مؤشر | خطأ_استيراد | خطأ_نظام_تشغيل | خطأ_خاصية | خطأ_توقف_التكرار
109109

110+
7- تمت إضافة تعريف الدالة الخطية, وهي دالة تكتب في سطر واحد ويتم إسنادها إلى متغير بشكل مباشر لأنها لا تمتلك إسم.
111+
```
112+
س = خطية س: س*3
113+
اطبع(س(99))
114+
# 297
115+
116+
# التعامل مع المصفوفات الضمنية
117+
ص = [خطية معامل=س: معامل * 10 لكل س في مدى(1, 5)]
118+
لكل ع في ص:
119+
اطبع(ع())
120+
121+
#
122+
10
123+
20
124+
30
125+
40
126+
```
110127

111128
- #### تصحيح الأخطاء:
112129

source/AlifCore/Include/Core/AlifCore_GlobalString.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class AlifGlobalStrings {
4141
public:
4242
STRUCT_FOR_USTR(_windowsConsoleIO, "طرفية_ويندوز")
4343
STRUCT_FOR_STR(AnonGenExpr, "<genexpr>")
44+
STRUCT_FOR_STR(AnonLambda, "<خطية>")
4445
STRUCT_FOR_STR(AnonListComp, "<listcomp>")
4546
STRUCT_FOR_USTR(AnonModule, "<وحدة>") //* alif
4647
STRUCT_FOR_STR(AnonString, "<string>")
@@ -58,6 +59,7 @@ class AlifGlobalStrings {
5859
STRUCT_FOR_STR(True, "صح") //* alif
5960
STRUCT_FOR_STR(False, "خطأ") //* alif
6061
STRUCT_FOR_STR(ListErr, "مؤشر المصفوفة خارج النطاق")
62+
STRUCT_FOR_STR(lambda, "خطية") //* alif
6163
STRUCT_FOR_STR(Mode, "mode") //* alif
6264
STRUCT_FOR_STR(Name, "name") //* alif
6365
STRUCT_FOR_STR(Obj, "obj") //* alif

source/AlifCore/Include/Core/AlifCore_RuntimeInit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@
681681
#define ALIF_STR_LITERALS_INIT { \
682682
INIT_USTR(_windowsConsoleIO, "طرفية_ويندوز"), \
683683
INIT_STR(AnonGenExpr, "<genexpr>"), \
684+
INIT_STR(AnonLambda, "<خطية>"), \
684685
INIT_STR(AnonListComp, "<listcomp>"), \
685686
INIT_USTR(AnonModule, "<وحدة>"), /* //* alif */ \
686687
INIT_STR(AnonString, "<string>"), \
@@ -698,6 +699,7 @@
698699
INIT_STR(True, "صح"), /* //* alif */ \
699700
INIT_STR(False, "خطأ"), /* //* alif */ \
700701
INIT_STR(ListErr, "مؤشر المصفوفة خارج النطاق"), /* //* alif */ \
702+
INIT_STR(lambda, "خطية"), /* //* alif */ \
701703
INIT_STR(Mode, "mode"), /* //* alif */ \
702704
INIT_STR(Name, "name"), /* //* alif */ \
703705
INIT_STR(Obj, "obj"), /* //* alif */ \

source/AlifCore/Objects/ASTOpt.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,10 @@ static AlifIntT astFold_expr(ExprTy _node,
690690
CALL(astFold_expr, ExprTy, _node->V.unaryOp.operand);
691691
CALL(fold_unaryOp, ExprTy, _node);
692692
break;
693+
case ExprK_::LambdaK:
694+
CALL(astFold_arguments, ArgumentsTy, _node->V.lambda.args);
695+
CALL(astFold_expr, ExprTy, _node->V.lambda.body);
696+
break;
693697
case ExprK_::IfExprK:
694698
CALL(astFold_expr, ExprTy, _node->V.ifExpr.condition);
695699
CALL(astFold_expr, ExprTy, _node->V.ifExpr.body);
@@ -706,15 +710,15 @@ static AlifIntT astFold_expr(ExprTy _node,
706710
CALL(astFold_expr, ExprTy, _node->V.listComp.elt);
707711
CALL_SEQ(astFold_comprehension, Comprehension, _node->V.listComp.generators);
708712
break;
709-
//case ExprK_::SetCompK:
710-
// CALL(astFold_expr, ExprTy, _node->V.setComp.elts);
711-
// CALL_SEQ(astFold_comprehension, Comprehension, _node->V.setComp.generators);
712-
// break;
713-
//case ExprK_::DictCompK:
714-
// CALL(astFold_expr, ExprTy, _node->V.dictComp.key);
715-
// CALL(astFold_expr, ExprTy, _node->V.dictComp.val);
716-
// CALL_SEQ(astFold_comprehension, Comprehension, _node->V.dictComp.generators);
717-
// break;
713+
case ExprK_::SetCompK:
714+
CALL(astFold_expr, ExprTy, _node->V.setComp.elts);
715+
CALL_SEQ(astFold_comprehension, Comprehension, _node->V.setComp.generators);
716+
break;
717+
case ExprK_::DictCompK:
718+
CALL(astFold_expr, ExprTy, _node->V.dictComp.key);
719+
CALL(astFold_expr, ExprTy, _node->V.dictComp.val);
720+
CALL_SEQ(astFold_comprehension, Comprehension, _node->V.dictComp.generators);
721+
break;
718722
case ExprK_::AwaitK:
719723
CALL(astFold_expr, ExprTy, _node->V.await.val);
720724
break;

source/AlifCore/Objects/ActionHelpers.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ const char* _alifParserEngine_getExprName(ExprTy _e) { // 1028
703703
case AttributeK:
704704
return "صفة";
705705
case SubScriptK:
706-
return "subscript";
706+
return "نص فرعي";
707707
case StarK:
708708
return "نجمي";
709709
case NameK:
@@ -712,8 +712,8 @@ const char* _alifParserEngine_getExprName(ExprTy _e) { // 1028
712712
return "مصفوفة";
713713
case TupleK:
714714
return "مترابطة";
715-
//case LambdaK:
716-
// return "lambda";
715+
case LambdaK:
716+
return "خطية";
717717
case CallK:
718718
return "استدعاء دالة";
719719
case BoolOpK:

source/AlifCore/Objects/Codegen.cpp

Lines changed: 54 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,50 +1868,46 @@ static AlifIntT codegen_ifExpr(AlifCompiler* _c, ExprTy _e) {
18681868

18691869

18701870

1871+
static AlifIntT codegen_lambda(AlifCompiler* _c, ExprTy _e) {
1872+
AlifCodeObject* co{};
1873+
AlifSizeT funcflags{};
1874+
ArgumentsTy args = _e->V.lambda.args;
18711875

1876+
Location loc = LOC(_e);
1877+
funcflags = codegen_defaultArguments(_c, loc, args);
1878+
RETURN_IF_ERROR(funcflags);
18721879

1880+
AlifCompileCodeUnitMetadata umd = {
1881+
.argCount = ASDL_SEQ_LEN(args->args),
1882+
.posOnlyArgCount = ASDL_SEQ_LEN(args->posOnlyArgs),
1883+
.kwOnlyArgCount = ASDL_SEQ_LEN(args->kwOnlyArgs),
1884+
};
1885+
ALIF_DECLARE_STR(anon_lambda, "<خطية>");
1886+
RETURN_IF_ERROR(
1887+
codegen_enterScope(_c, &ALIF_STR(AnonLambda), ScopeType_::Compiler_Scope_Lambda,
1888+
(void *)_e, _e->lineNo, nullptr, &umd));
18731889

1890+
RETURN_IF_ERROR(_alifCompiler_addConst(_c, ALIF_NONE));
18741891

1892+
VISIT_IN_SCOPE(_c, Expr, _e->V.lambda.body);
1893+
if (SYMTABLE_ENTRY(_c)->generator) {
1894+
co = _alifCompiler_optimizeAndAssemble(_c, 0);
1895+
}
1896+
else {
1897+
Location loc = LOC(_e->V.lambda.body);
1898+
ADDOP_IN_SCOPE(_c, loc, RETURN_VALUE);
1899+
co = _alifCompiler_optimizeAndAssemble(_c, 1);
1900+
}
1901+
_alifCompiler_exitScope(_c);
1902+
if (co == nullptr) {
1903+
return ERROR;
1904+
}
18751905

1876-
1877-
1878-
1879-
1880-
1881-
1882-
1883-
1884-
1885-
1886-
1887-
1888-
1889-
1890-
1891-
1892-
1893-
1894-
1895-
1896-
1897-
1898-
1899-
1900-
1901-
1902-
1903-
1904-
1905-
1906-
1907-
1908-
1909-
1910-
1911-
1912-
1913-
1914-
1906+
AlifIntT ret = codegen_makeClosure(_c, loc, co, funcflags);
1907+
ALIF_DECREF(co);
1908+
RETURN_IF_ERROR(ret);
1909+
return SUCCESS;
1910+
}
19151911

19161912

19171913

@@ -3493,10 +3489,10 @@ static AlifTypeObject* infer_type(ExprTy _e) {
34933489
case ExprK_::SetK:
34943490
case ExprK_::SetCompK:
34953491
return &_alifSetType_;
3496-
//case ExprK_::GeneratorExpK:
3497-
// return &_alifGenType_;
3498-
//case ExprK_::LambdaK:
3499-
// return &_alifFunctionType_;
3492+
case ExprK_::GeneratorExprK:
3493+
return &_alifGenType_;
3494+
case ExprK_::LambdaK:
3495+
return &_alifFunctionType_;
35003496
case ExprK_::JoinStrK:
35013497
case ExprK_::FormattedValK:
35023498
return &_alifUStrType_;
@@ -3519,7 +3515,7 @@ static AlifIntT check_caller(AlifCompiler* _c, ExprTy _e) {
35193515
case ExprK_::DictCompK:
35203516
case ExprK_::SetK:
35213517
case ExprK_::SetCompK:
3522-
//case GeneratorExpK:
3518+
case ExprK_::GeneratorExprK:
35233519
case ExprK_::JoinStrK:
35243520
case ExprK_::FormattedValK: {
35253521
Location loc = LOC(_e);
@@ -3547,9 +3543,9 @@ static AlifIntT check_subScripter(AlifCompiler* _c, ExprTy _e) {
35473543
}
35483544
ALIF_FALLTHROUGH;
35493545
case ExprK_::SetK:
3550-
case ExprK_::SetCompK: {
3551-
//case ExprK_::GeneratorExpK:
3552-
//case ExprK_::LambdaK: {
3546+
case ExprK_::SetCompK:
3547+
case ExprK_::GeneratorExprK:
3548+
case ExprK_::LambdaK: {
35533549
Location loc = LOC(_e);
35543550
//return _alifCompiler_warn(_c, loc, "'%.200s' object is not subscriptable; "
35553551
// "perhaps you missed a comma?",
@@ -4901,25 +4897,25 @@ static AlifIntT codegen_visitExpr(AlifCompiler* _c, ExprTy _e) {
49014897
ADDOP(_c, loc, unaryop(_e->V.unaryOp.op));
49024898
}
49034899
break;
4904-
//case ExprK_::LambdaK:
4905-
// return codegen_lambda(_c, _e);
4900+
case ExprK_::LambdaK:
4901+
return codegen_lambda(_c, _e);
49064902
case ExprK_::IfExprK:
49074903
return codegen_ifExpr(_c, _e);
49084904
case ExprK_::DictK:
49094905
return codegen_dict(_c, _e);
4910-
//case ExprK_::SetK:
4911-
// return codegen_set(_c, _e);
4906+
//case ExprK_::SetK:
4907+
// return codegen_set(_c, _e);
49124908
case ExprK_::GeneratorExprK:
49134909
return codegen_genExpr(_c, _e);
49144910
case ExprK_::ListCompK:
49154911
return codegen_listComp(_c, _e);
4916-
//case ExprK_::SetCompK:
4917-
// return codegen_setComp(_c, _e);
4918-
//case ExprK_::DictCompK:
4919-
//return codegen_dictComp(_c, _e);
4912+
//case ExprK_::SetCompK:
4913+
// return codegen_setComp(_c, _e);
4914+
//case ExprK_::DictCompK:
4915+
// return codegen_dictComp(_c, _e);
49204916
case ExprK_::YieldK:
49214917
if (!alifST_isFunctionLike(SYMTABLE_ENTRY(_c))) {
4922-
return _alifCompiler_error(_c, loc, "'yield' outside function");
4918+
return _alifCompiler_error(_c, loc, "'ولد' خارج الدالة");
49234919
}
49244920
if (_e->V.yield.val) {
49254921
VISIT(_c, Expr, _e->V.yield.val);
@@ -4931,10 +4927,10 @@ static AlifIntT codegen_visitExpr(AlifCompiler* _c, ExprTy _e) {
49314927
break;
49324928
case ExprK_::YieldFromK:
49334929
if (!alifST_isFunctionLike(SYMTABLE_ENTRY(_c))) {
4934-
return _alifCompiler_error(_c, loc, "'yield from' outside function");
4930+
return _alifCompiler_error(_c, loc, "'ولد من' خارج الدالة");
49354931
}
49364932
if (SCOPE_TYPE(_c) == ScopeType_::Compiler_Scope_Async_Function) {
4937-
return _alifCompiler_error(_c, loc, "'yield from' inside async function");
4933+
return _alifCompiler_error(_c, loc, "'ولد من' داخل دالة متزامنة");
49384934
}
49394935
VISIT(_c, Expr, _e->V.yieldFrom.val);
49404936
ADDOP(_c, loc, GET_YIELD_FROM_ITER);

source/AlifCore/Objects/FlowGraph.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ ALIF_LOCAL(AlifIntT) stack_effect(AlifIntT _opcode, AlifIntT _oparg, AlifIntT _j
576576
ALIF_LOCAL_INLINE(AlifIntT) stackDepth_push(BasicBlock*** _sp,
577577
BasicBlock* _b, AlifIntT _depth) { // 785
578578
if (!(_b->startDepth < 0 or _b->startDepth == _depth)) {
579-
//alifErr_format(_alifExcValueError_, "Invalid CFG, inconsistent stackdepth");
579+
alifErr_format(_alifExcValueError_, "مخطط التحكم بالتدفق غير صحيح, عمق المكدس غير متسق");
580580
return ERROR;
581581
}
582582
if (_b->startDepth < _depth and _b->startDepth < 100) {
@@ -621,7 +621,7 @@ static AlifIntT calculate_stackDepth(CFGBuilder* _g) { // 803
621621
AlifIntT newDepth = depth + effect;
622622
if (newDepth < 0) {
623623
alifErr_format(_alifExcValueError_,
624-
"رسم التحكم بالتدفق غير مناسب , قيمة المكدس منخفضة");
624+
"مخطط التحكم بالتدفق غير صحيح , قيمة المكدس منخفضة");
625625
goto error;
626626
}
627627
if (newDepth > maxDepth) {

source/AlifCore/Objects/SymTable.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ AlifSymTable* alifSymtable_build(ModuleTy _mod, AlifObject* _filename,
225225
AlifSymTable* st_ = symtable_new();
226226
ASDLStmtSeq* seq_{};
227227
AlifSizeT i_{};
228-
AlifThread* tstate{};
228+
AlifThread* thread{};
229229
AlifIntT startingRecursionDepth{};
230230

231231
if (st_ == nullptr)
@@ -237,12 +237,12 @@ AlifSymTable* alifSymtable_build(ModuleTy _mod, AlifObject* _filename,
237237
st_->fileName = ALIF_NEWREF(_filename);
238238
st_->future = _future;
239239

240-
tstate = _alifThread_get();
241-
if (!tstate) {
240+
thread = _alifThread_get();
241+
if (!thread) {
242242
alifSymtable_free(st_);
243243
return nullptr;
244244
}
245-
AlifIntT recursionDepth = ALIFCPP_RECURSION_LIMIT - tstate->cppRecursionRemaining;
245+
AlifIntT recursionDepth = ALIFCPP_RECURSION_LIMIT - thread->cppRecursionRemaining;
246246
startingRecursionDepth = recursionDepth;
247247
st_->recursionDepth = startingRecursionDepth;
248248
st_->recursionLimit = ALIFCPP_RECURSION_LIMIT;
@@ -1539,6 +1539,20 @@ static AlifIntT symtable_visitExpr(AlifSymTable* _st, ExprTy _e) { // 2334
15391539
case ExprK_::UnaryOpK:
15401540
VISIT(_st, Expr, _e->V.unaryOp.operand);
15411541
break;
1542+
case ExprK_::LambdaK:
1543+
if (_e->V.lambda.args->defaults)
1544+
VISIT_SEQ(_st, Expr, _e->V.lambda.args->defaults);
1545+
if (_e->V.lambda.args->kwDefaults)
1546+
VISIT_SEQ_WITH_NULL(_st, Expr, _e->V.lambda.args->kwDefaults);
1547+
if (!symtable_enterBlock(_st, &ALIF_STR(lambda),
1548+
BlockType_::Function_Block, (void*)_e, LOCATION(_e))) {
1549+
return 0;
1550+
}
1551+
VISIT(_st, Arguments, _e->V.lambda.args);
1552+
VISIT(_st, Expr, _e->V.lambda.body);
1553+
if (!symtable_exitBlock(_st))
1554+
return 0;
1555+
break;
15421556
case ExprK_::IfExprK:
15431557
VISIT(_st, Expr, _e->V.ifExpr.condition);
15441558
VISIT(_st, Expr, _e->V.ifExpr.body);

0 commit comments

Comments
 (0)