Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Map and True/False for Arabic #106

Merged
merged 4 commits into from
Mar 11, 2020
Merged
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
66 changes: 66 additions & 0 deletions Sources/Srt/Srl/Map.alusus
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import "Srl/Array.alusus";

@merge module Srl
{
type Map [T1: type, T2: type] {
use Srl;
def keys: Array[T1];
def values: Array[T2];

handler this~init() {};

handler this~init(map: ref[Map[T1, T2]]) {
this.keys = map.keys;
this.values = map.values;
};

handler this(key: T1): T2 {
@shared
def dummy: T2;
def arrInd: int = 0;
for , arrInd<this.keys.getLength(), arrInd++
if this.keys(arrInd) == key
return this.values(arrInd)
return dummy;
};
xlmnxp marked this conversation as resolved.
Show resolved Hide resolved

func set(key: T1, value: T2): ref[Map[T1, T2]] {
def arrInd: int = 0;
for , arrInd<this.keys.getLength(), arrInd++ {
if this.keys(arrInd) == key {
this.values(arrInd) = value
return this;
};
};

this.keys.add(key);
this.values.add(value);
return this;
};

func remove(key: T1): Bool {
def arrInd: int = 0;
for , arrInd<this.keys.getLength(), arrInd++
if this.keys(arrInd) == key
return this.remove(arrInd)
return false;
};

func remove(index: Int): Bool {
if index < 0 || index >= this.keys.getLength() return false;
this.keys.remove(index);
this.values.remove(index);
return true;
};
xlmnxp marked this conversation as resolved.
Show resolved Hide resolved

func clear(): Bool {
this.keys.clear();
this.values.clear();
return true;
};

func getLength(): Int {
return this.keys.getLength();
};
};
};
9 changes: 6 additions & 3 deletions Sources/Srt/عامة.أسس
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
عرّف فراغ: لقب Void؛
عرّف مؤشر: لقب ptr؛
عرّف مصفوفة: لقب array؛
عرف سند: لقب ref؛

عرف الـعملية: لقب Process؛
عرّف سند: لقب ref؛
عرّف صح: 1؛
عرّف خطا: 0؛
عرّف خطأ: 0؛
عرّف عدم: 0؛
عرّف الـعملية: لقب Process؛
@دمج عرف Process: وحدة
{
عرف عدد_المعطيات: لقب argCount؛
Expand Down
14 changes: 14 additions & 0 deletions Sources/Srt/مـتم/تـطبيق.أسس
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
اشمل "عامة.أسس"؛
اشمل "Srl/Map.alusus"؛

@دمج وحدة Srl {
عرّف تـطبيق: لقب Map؛
@دمج صنف Map {
عرف هات_الطول: لقب getLength؛
عرف حدد: لقب set؛
عرف أزل: لقب remove؛
عرف ازل: لقب remove؛
عرف فرّغ: لقب clear؛
عرف فرغ: لقب clear؛
20 changes: 20 additions & 0 deletions Sources/Tests/Srt/map.alusus
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import "Srl/Console.alusus";
import "Srl/Map.alusus";

func test {
def m1: Srl.Map[Int, Int];
m1.set(1, 100).set(100, 1);

Srl.Console.print("m1: 1 is %d and 100 is %d\n", m1(1), m1(100));
def m2: Srl.Map[Bool, Int];
m2.set(false, 1).set(true, 2);

Srl.Console.print("m2: false is %d and true is %d\n", m2(false), m2(true));

def m3: Srl.Map[Int, ptr[array[Char]]];
m3.set(0, "Hello").set(1, "World");

Srl.Console.print("m3: 0 is %s and 1 is %s\n", m3(0), m3(1));
};

test();
3 changes: 3 additions & 0 deletions Sources/Tests/Srt/map.alusus.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
m1: 1 is 100 and 100 is 1
m2: false is 1 and true is 2
m3: 0 is Hello and 1 is World
21 changes: 21 additions & 0 deletions Sources/Tests/Srt/تـطبيق.أسس
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
اشمل "مـتم/طـرفية.أسس"؛
اشمل "مـتم/تـطبيق.أسس"؛

دالة اختبر {
عرف م1: مـتم.تـطبيق[صـحيح, صـحيح]؛
م1.حدد(1, 100).حدد(100, 1)؛

مـتم.طـرفية.اطبع("م1: 1 هو %d و100 هو %d\n", م1(1), م1(100))؛
عرف م2: مـتم.تـطبيق[ثـنائي, صـحيح]؛
م2.حدد(خطا, 1).حدد(صح, 2)؛

مـتم.طـرفية.اطبع("م2: الخط هو %d والصح هو %d\n", م2(خطا), م2(صح))؛

عرف م3: مـتم.تـطبيق[صـحيح, مؤشر[مصفوفة[محرف]]]؛
م3.حدد(0, "مرحبا").حدد(1, "بالعالم")؛

مـتم.طـرفية.اطبع("م3: 0 هو %s و1 هو %s\n", م3(0), م3(1))؛

اختبر()؛

3 changes: 3 additions & 0 deletions Sources/Tests/Srt/تـطبيق.أسس.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
م1: 1 هو 100 و100 هو 1
م2: الخط هو 1 والصح هو 2
م3: 0 هو مرحبا و1 هو بالعالم