Skip to content

Commit e435128

Browse files
committed
up
1 parent 6c92af8 commit e435128

File tree

6 files changed

+1713
-1
lines changed

6 files changed

+1713
-1
lines changed

public/salam-online.html

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
<!doctype html>
2+
<html dir="rtl" lang="fa-IR">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Salam Programming Language</title>
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
</head>
8+
<body>
9+
<textarea
10+
style="width: 100%; border: 1px solid black"
11+
dir="rtl"
12+
id="code"
13+
rows="20"
14+
cols="40"
15+
>
16+
صفحه:
17+
رنگ پس زمینه = «زرد»
18+
رنگ = «سیاه»
19+
محتوا = «سلام دنیا»
20+
21+
جهت = "راست به چپ"
22+
زبان = "فارسی"
23+
24+
پاراگراف:
25+
محتوا = «سلام این یک متن آزاد است و می تواند طویل باشد.»
26+
تمام
27+
28+
خط بعدی:
29+
تکرار = ۳
30+
تمام
31+
32+
جعبه:
33+
تکرار = ۴
34+
35+
رنگ پس زمینه = "زرد"
36+
37+
قطعه:
38+
محتوا = "این یک متن است"
39+
تمام
40+
41+
فهرست مرتب:
42+
مورد:
43+
محتوا = "این یک ایتم موردی است"
44+
تمام
45+
مورد:
46+
محتوا = "این یک ایتم موردی است"
47+
تمام
48+
مورد:
49+
محتوا = "این یک ایتم موردی است"
50+
تمام
51+
تمام
52+
تمام
53+
54+
قطعه:
55+
محتوا = "متن ازمایشی"
56+
تمام
57+
58+
خط بعدی:
59+
تکرار = ۳
60+
تمام
61+
62+
قطعه:
63+
محتوا = "پایان"
64+
تمام
65+
تمام
66+
</textarea
67+
>
68+
<br />
69+
<button id="execute" disabled="true">اجرا</button>
70+
<iframe
71+
style="margin-top: 10px; width: 100%; border: 1px solid black"
72+
width="100%"
73+
height="100%"
74+
></iframe>
75+
<pre id="error" style="width: 100%; color: red" dir="ltr"></pre>
76+
<pre id="output" style="width: 100%" dir="ltr"></pre>
77+
<script type="text/javascript">
78+
const iframe = document.querySelector('iframe');
79+
const outputPre = document.querySelector('#output');
80+
const errorPre = document.querySelector('#error');
81+
const codeTextArea = document.querySelector('#code');
82+
const executeButton = document.querySelector('#execute');
83+
84+
let isReady = false;
85+
let is_running = false;
86+
87+
var Module = {
88+
noInitialRun: true,
89+
onRuntimeInitialized: () => {
90+
console.log('Salam loaded successfully');
91+
isReady = true;
92+
executeButton.disabled = false;
93+
94+
if (codeTextArea.value.toString().trim() !== '') {
95+
runSalam();
96+
}
97+
},
98+
print: (text) => {
99+
customLogger(text, 'log');
100+
},
101+
printErr: (text) => {
102+
customLogger(text, 'error');
103+
},
104+
};
105+
106+
const customLogger = (text, type) => {
107+
if (type === 'error') {
108+
console.error(text);
109+
} else {
110+
console.log(text);
111+
}
112+
113+
const prefix = type === 'error' ? 'Error: ' : '';
114+
115+
if (prefix === '') {
116+
outputPre.textContent += prefix + text + '\n';
117+
} else {
118+
errorPre.textContent += prefix + text + '\n';
119+
}
120+
};
121+
122+
const runSalam = () => {
123+
console.log('Running Salam code...');
124+
const code = codeTextArea.value.toString().trim();
125+
if (!code) {
126+
alert('Code is empty! Please enter Salam code.');
127+
return;
128+
}
129+
130+
const args = ['code', code];
131+
console.log('Calling Salam with arguments:', args);
132+
133+
if (isReady) {
134+
captureOutput(args);
135+
} else {
136+
console.log('Salam runtime not ready. Please wait...');
137+
}
138+
};
139+
140+
const captureOutput = (arguments) => {
141+
outputPre.textContent = '';
142+
errorPre.textContent = '';
143+
144+
if (is_running) {
145+
return;
146+
}
147+
148+
try {
149+
is_running = true;
150+
151+
if (typeof callMain === 'function') {
152+
try {
153+
callMain(arguments);
154+
155+
const iframeDocument =
156+
iframe.contentDocument || iframe.contentWindow.document;
157+
158+
if (iframeDocument) {
159+
iframe.srcdoc = outputPre.textContent;
160+
}
161+
} catch (err) {
162+
Module.printErr('Runtime error: ' + err);
163+
}
164+
} else {
165+
Module.printErr(
166+
'callMain is not defined. Ensure NO_EXIT_RUNTIME is enabled.',
167+
);
168+
}
169+
} catch (err) {
170+
Module.printErr('خطای غیرمنتظره رخ داد. ' + err);
171+
} finally {
172+
is_running = false;
173+
}
174+
};
175+
176+
const reloadModule = () => {
177+
const script = document.createElement('script');
178+
script.src = 'salam-wa.js';
179+
script.onload = () => {
180+
console.log('Salam module reloaded.');
181+
};
182+
183+
document.body.appendChild(script);
184+
};
185+
186+
executeButton.addEventListener('click', () => {
187+
console.log('Button clicked!');
188+
189+
runSalam();
190+
});
191+
192+
codeTextArea.addEventListener('keydown', (e) => {
193+
if (e.key === 'Tab') {
194+
e.preventDefault();
195+
const start = codeTextArea.selectionStart;
196+
const end = codeTextArea.selectionEnd;
197+
codeTextArea.value =
198+
codeTextArea.value.substring(0, start) +
199+
' ' +
200+
codeTextArea.value.substring(end);
201+
codeTextArea.selectionStart = codeTextArea.selectionEnd = start + 4;
202+
}
203+
});
204+
205+
reloadModule();
206+
</script>
207+
</body>
208+
</html>

0 commit comments

Comments
 (0)