It's fine to do another language but please don't call it Python unless it really is. One of the main reasons for higher level languages is portability and programmers should be confident that a program written in Python will be able to run on any system that supports Python with minimal changes. Internal differences such as numerical format don't matter too much to a high level programmer as long as the answers are consistent.michaelzinn wrote: ↑Fri Apr 12, 2019 2:16 pmHow would a full Python with Strings and all be usable on the DM15L? I'd probably not do an exact implementation of a language anyway, e.g. I'd use the native decimal numbers of the calculator instead of integers or IEEE floats.toml_12953 wrote: ↑Fri Apr 12, 2019 2:04 amI'd want a FULL Python, though. Not one of these "MicroPython" implementations.
It's interesting that Python is so popular. The syntax is not that easy to parse...
[POLL] Compiler for DM15L ?
-
- Posts: 795
- Joined: Wed May 03, 2017 7:46 pm
- Location: Malone, NY USA
Re: [POLL] Compiler for DM15L ?
Tom L
Some people call me inept but I'm as ept as anybody!
DM10L SN: 059/100
DM41X SN: 00023 (Beta)
DM41X SN: 00506 (Shipping)
DM42 SN: 00025 (Beta)
DM42 SN: 00221 (Shipping)
WP43 SN: 00025 (Prototype)
Some people call me inept but I'm as ept as anybody!
DM10L SN: 059/100
DM41X SN: 00023 (Beta)
DM41X SN: 00506 (Shipping)
DM42 SN: 00025 (Beta)
DM42 SN: 00221 (Shipping)
WP43 SN: 00025 (Prototype)
Re: [POLL] Compiler for DM15L ?
If possible, I'd go for Lua -- small and lean VM, JIT compilation is available for ARM CPUs and it is fast (even without that).
It's also a very simple but expressive language.
Pauli
It's also a very simple but expressive language.
Pauli
-
- Posts: 41
- Joined: Tue Apr 10, 2018 11:34 pm
Re: [POLL] Compiler for DM15L ?
Interesting, thank you for pointing that out! But that's not the goal here: I'd like to compile to the language of the calculator (is it called RPN?), not create an alternative firmware where you can run Lua on the exposed ARM CPU. If you want serious programming on a handheld device I think programming a smartphone app is a much more sensible approach.
My goal is to get a basic understanding of programming languages and compilers, and given that I already wrote some complex programs in RPN (interpreter, binary converter with lookup tables...) I think that I have a good enough understanding of the language to use it as a compiler target. In addition, it would be nice if it were also useful for other people (unlike the BF interpreted), hence this thread.
Also, the current status is that I now understand parser combinators and implemented them in Idris. I should be able to parse any language now, but I think old style BASIC with line numbers and gotos should be the choice with the best usefulness to difficulty quotient, given that I wouldn't need to think about complicated things like variable scopes and stack frames.
-
- Posts: 41
- Joined: Tue Apr 10, 2018 11:34 pm
Re: [POLL] Compiler for DM15L ?
I decided to go with CommodoreBASIC (C64), for these reasons:
- It is easier to compile than most other languages (only global variables, no stack frames etc.)
- It is something that people who use HP calculators might know, because it is from the same time
- You can compile old number based BASIC games and play them on your calculator, e.g. Hammurabi
I'll start with a useful subset, i.e. I want to be able to compile the Hammurabi game and run it on my calculator: http://vintage-basic.net/bcg/hammurabi.bas
The Hammurabi game uses 15 variables and 26 jump targets, so as a first version I'll compile variables to directly accessible registers (0-19) but jumps to line numbers instead of labels. More sophisticated features like functions or lists will come later when/if I need them or somebody asks for them.
Current state of the project is that it parses the whole program and compiles some expressions (ENTER insertion was tricky):
Do you have an idea for a name for this compiler? Maybe VoyagerBASIC or voyagerc?
- It is easier to compile than most other languages (only global variables, no stack frames etc.)
- It is something that people who use HP calculators might know, because it is from the same time
- You can compile old number based BASIC games and play them on your calculator, e.g. Hammurabi
I'll start with a useful subset, i.e. I want to be able to compile the Hammurabi game and run it on my calculator: http://vintage-basic.net/bcg/hammurabi.bas
The Hammurabi game uses 15 variables and 26 jump targets, so as a first version I'll compile variables to directly accessible registers (0-19) but jumps to line numbers instead of labels. More sophisticated features like functions or lists will come later when/if I need them or somebody asks for them.
Current state of the project is that it parses the whole program and compiles some expressions (ENTER insertion was tricky):
Code: Select all
((Z-1)*P1+D*100/P)/Z
RCL 0
1
-
RCL 1
*
RCL 2
1
0
0
*
RCL 3
/
+
RCL 0
/
Last edited by michaelzinn on Tue May 14, 2019 1:28 pm, edited 1 time in total.
-
- Posts: 41
- Joined: Tue Apr 10, 2018 11:34 pm
Re: [POLL] Compiler for DM15L ?
Compiling works now, but only for programs smaller than 448 lines because of viewtopic.php?f=11&t=2186.
I'll see if I can clean up the code and release it in the next days/weeks/when I have time.
I'll see if I can clean up the code and release it in the next days/weeks/when I have time.
-
- Posts: 41
- Joined: Tue Apr 10, 2018 11:34 pm
Re: [POLL] Compiler for DM15L ?
I won my first game of Hamurabi on the DM15L
I'll do a proper release when firmware V29 is public, but here's a sneak preview of the compiler output (there's a bug where some lines show up as comment lines)
I'll do a proper release when firmware V29 is public, but here's a sneak preview of the compiler output (there's a bug where some lines show up as comment lines)
Code: Select all
1 LBL 0
2 R/S
3 CF 8
4 RTN
5 LBL 1
6 GTO I
7 LBL B
10 PRINT TAB(32);"HAMURABI"..............................................8 SF 8
9 0
10 GSB 0
11 SF 8
12 1
13 GSB 0
20 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"............14 SF 8
15 0
16 GSB 0
17 SF 8
18 2
19 GSB 0
30 PRINT: PRINT: PRINT...................................................20 SF 8
21 3
22 GSB 0
90 PRINT "FOR A TEN-YEAR TERM OF OFFICE.": PRINT.........................23 SF 8
24 4
25 GSB 0
95 D1=0: P1=0............................................................26 0
27 STO 3
28 0
29 STO .0
100 Z=0: P=95: S=2800: H=3000: E=H-S.....................................30 0
31 STO .4
32 9
33 5
34 STO 9
35 2
36 8
37 0
38 0
39 STO .2
40 3
41 0
42 0
43 0
44 STO 5
45 RCL 5
46 RCL .2
47 -
48 STO 4
110 Y=3: A=H/Y: I=5: Q=1.................................................49 3
50 STO .3
51 RCL 5
52 RCL .3
53 /
54 STO 0
55 5
56 STO 6
57 1
58 STO .1
210 D=0..................................................................59 0
60 STO 2
215 PRINT: PRINT: PRINT "HAMURABI: I BEG TO REPORT TO YOU,": Z=Z+1......61 SF 8
62 5
63 GSB 0
64 RCL .4
65 1
66 +
67 STO .4
217 PRINT "IN YEAR";Z;",";D;"PEOPLE STARVED,";I;"CAME TO THE CITY,"......68 SF 8
69 6
70 GSB 0
71 RCL .4
72 GSB 0
73 SF 8
74 7
75 GSB 0
76 RCL 2
77 GSB 0
78 SF 8
79 8
80 GSB 0
81 RCL 6
82 GSB 0
83 SF 8
84 9
85 GSB 0
218 P=P+I................................................................86 RCL 9
87 RCL 6
88 +
89 STO 9
227 IF Q>0 THEN 230......................................................90 1
91 0
92 8
93 CHS
94 STO I
95 0
96 RCL .1
97 TEST 7
98 GTO I
228 P=INT(P/2)...........................................................99 RCL 9
100 2
101 /
102 INT
103 STO 9
229 PRINT "A HORRIBLE PLAGUE STRUCK! HALF THE PEOPLE DIED.".............104 SF 8
105 1
106 0
107 GSB 0
230 PRINT "POPULATION IS NOW";P..........................................108 SF 8
109 1
110 1
111 GSB 0
112 RCL 9
113 GSB 0
232 PRINT "THE CITY NOW OWNS";A;"ACRES.".................................114 SF 8
115 1
116 2
117 GSB 0
118 RCL 0
119 GSB 0
120 SF 8
121 1
122 3
123 GSB 0
235 PRINT "YOU HARVESTED";Y;"BUSHELS PER ACRE."..........................124 SF 8
125 1
126 4
127 GSB 0
128 RCL .3
129 GSB 0
130 SF 8
131 1
132 5
133 GSB 0
250 PRINT "RATS ATE";E;"BUSHELS."........................................134 SF 8
135 1
136 6
137 GSB 0
138 RCL 4
139 GSB 0
140 SF 8
141 1
142 7
143 GSB 0
260 PRINT "YOU NOW HAVE";S;"BUSHELS IN STORE.": PRINT....................144 SF 8
145 1
146 8
147 GSB 0
148 RCL .2
149 GSB 0
150 SF 8
151 1
152 9
153 GSB 0
270 IF Z=11 THEN 860.....................................................154 6
155 6
156 5
157 CHS
158 STO I
159 1
160 1
161 RCL .4
162 TEST 5
163 GTO I
310 C=INT(10*RND(1)): Y=C+17.............................................164 1
165 0
166 RAN#
167 *
168 INT
169 STO 1
170 RCL 1
171 1
172 7
173 +
174 STO .3
312 PRINT "LAND IS TRADING AT";Y;"BUSHELS PER ACRE.".....................175 SF 8
176 2
177 0
178 GSB 0
179 RCL .3
180 GSB 0
181 SF 8
182 1
183 5
184 GSB 0
320 PRINT "HOW MANY ACRES DO YOU WISH TO BUY";...........................185 SF 8
186 2
187 1
188 GSB 0
321 INPUT Q: IF Q<0 THEN 850.............................................189 SF 9
190 R/S
191 CF 9
192 STO .1
193 6
194 5
195 1
196 CHS
197 STO I
198 0
199 RCL .1
200 TEST 8
201 GTO I
322 IF Y*Q<=S THEN 330...................................................202 2
203 2
204 5
205 CHS
206 STO I
207 RCL .2
208 RCL .3
209 RCL .1
210 *
211 x<=y
212 GTO I
323 GOSUB 710............................................................213 6
214 2
215 1
216 CHS
217 STO I
218 GSB 1
324 GOTO 320.............................................................219 1
220 8
221 5
222 CHS
223 STO I
224 GTO I
330 IF Q=0 THEN 340......................................................225 2
226 5
227 2
228 CHS
229 STO I
230 0
231 RCL .1
232 TEST 5
233 GTO I
331 A=A+Q: S=S-Y*Q: C=0..................................................234 RCL 0
235 RCL .1
236 +
237 STO 0
238 RCL .2
239 RCL .3
240 RCL .1
241 *
242 -
243 STO .2
244 0
245 STO 1
334 GOTO 400.............................................................246 3
247 0
248 2
249 CHS
250 STO I
251 GTO I
340 PRINT "HOW MANY ACRES DO YOU WISH TO SELL";..........................252 SF 8
253 2
254 2
255 GSB 0
341 INPUT Q: IF Q<0 THEN 850.............................................256 SF 9
257 R/S
258 CF 9
259 STO .1
260 6
261 5
262 1
263 CHS
264 STO I
265 0
266 RCL .1
267 TEST 8
268 GTO I
342 IF Q<A THEN 350......................................................269 2
270 9
271 0
272 CHS
273 STO I
274 RCL 0
275 RCL .1
276 TEST 8
277 GTO I
343 GOSUB 720............................................................278 6
279 3
280 2
281 CHS
282 STO I
283 GSB 1
344 GOTO 340.............................................................284 2
285 5
286 2
287 CHS
288 STO I
289 GTO I
350 A=A-Q: S=S+Y*Q: C=0..................................................290 RCL 0
291 RCL .1
292 -
293 STO 0
294 RCL .2
295 RCL .3
296 RCL .1
297 *
298 +
299 STO .2
300 0
301 STO 1
400 PRINT................................................................302 SF 8
303 2
304 3
305 GSB 0
411 INPUT Q..............................................................306 SF 9
307 R/S
308 CF 9
309 STO .1
412 IF Q<0 THEN 850......................................................310 6
311 5
312 1
313 CHS
314 STO I
315 0
316 RCL .1
317 TEST 8
318 GTO I
418 REM *** TRYING TO USE MORE GRAIN THAN IS IN SILOS?...................319 3
320 4
321 0
322 CHS
323 STO I
324 RCL .2
325 RCL .1
326 x<=y
327 GTO I
421 GOSUB 710............................................................328 6
329 2
330 1
331 CHS
332 STO I
333 GSB 1
422 GOTO 410.............................................................334 3
335 0
336 2
337 CHS
338 STO I
339 GTO I
430 S=S-Q: C=1: PRINT....................................................340 RCL .2
341 RCL .1
342 -
343 STO .2
344 1
345 STO 1
440 PRINT "HOW MANY ACRES DO YOU WISH TO PLANT WITH SEED"................346 SF 8
347 2
348 4
349 GSB 0
441 INPUT D: IF D=0 THEN 511.............................................350 SF 9
351 R/S
352 CF 9
353 STO 2
354 4
355 5
356 2
357 CHS
358 STO I
359 0
360 RCL 2
361 TEST 5
362 GTO I
442 IF D<0 THEN 850......................................................363 6
364 5
365 1
366 CHS
367 STO I
368 0
369 RCL 2
370 TEST 8
371 GTO I
444 REM *** TRYING TO PLANT MORE ACRES THAN YOU OWN?.....................372 3
373 9
374 3
375 CHS
376 STO I
377 RCL 0
378 RCL 2
379 x<=y
380 GTO I
446 GOSUB 720............................................................381 6
382 3
383 2
384 CHS
385 STO I
386 GSB 1
447 GOTO 440.............................................................387 3
388 4
389 6
390 CHS
391 STO I
392 GTO I
449 REM *** ENOUGH GRAIN FOR SEED?.......................................393 4
394 1
395 7
396 CHS
397 STO I
398 RCL .2
399 RCL 2
400 2
401 /
402 INT
403 x<=y
404 GTO I
452 GOSUB 710............................................................405 6
406 2
407 1
408 CHS
409 STO I
410 GSB 1
453 GOTO 440.............................................................411 3
412 4
413 6
414 CHS
415 STO I
416 GTO I
454 REM *** ENOUGH PEOPLE TO TEND THE CROPS?.............................417 4
418 4
419 5
420 CHS
421 STO I
422 1
423 0
424 RCL 9
425 *
426 RCL 2
427 TEST 8
428 GTO I
460 PRINT "BUT YOU HAVE ONLY";P;"PEOPLE TO TEND THE FIELDS! NOW THEN,"..429 SF 8
430 2
431 5
432 GSB 0
433 RCL 9
434 GSB 0
435 SF 8
436 2
437 6
438 GSB 0
470 GOTO 440.............................................................439 3
440 4
441 6
442 CHS
443 STO I
444 GTO I
510 S=S-INT(D/2).........................................................445 RCL .2
446 RCL 2
447 2
448 /
449 INT
450 -
451 STO .2
511 GOSUB 800............................................................452 6
453 4
454 3
455 CHS
456 STO I
457 GSB 1
512 REM *** A BOUNTIFUL HARVEST!.........................................458 RCL 1
459 STO .3
460 RCL 2
461 RCL .3
462 *
463 STO 5
464 0
465 STO 4
521 GOSUB 800............................................................466 6
467 4
468 3
469 CHS
470 STO I
471 GSB 1
522 IF INT(C/2)<>C/2 THEN 530............................................472 4
473 9
474 1
475 CHS
476 STO I
477 RCL 1
478 2
479 /
480 RCL 1
481 2
482 /
483 INT
484 TEST 6
485 GTO I
523 REM *** RATS ARE RUNNING WILD........................................486 RCL .2
487 RCL 1
488 /
489 INT
490 STO 4
530 S=S-E+H..............................................................491 RCL .2
492 RCL 4
493 -
494 RCL 5
495 +
496 STO .2
531 GOSUB 800............................................................497 6
498 4
499 3
500 CHS
501 STO I
502 GSB 1
532 REM *** LET'S HAVE SOME BABIES.......................................503 RCL 1
504 2
505 0
506 RCL 0
507 *
508 RCL .2
509 +
510 *
511 RCL 9
512 /
513 1
514 0
515 0
516 /
517 1
518 +
519 INT
520 STO 6
539 REM *** HOW MANY PEOPLE HAD FULL TUMMIES?............................521 RCL .1
522 2
523 0
524 /
525 INT
526 STO 1
541 REM *** HORROR, A 15% CHANCE OF PLAGUE...............................527 1
528 0
529 ENTER
530 2
531 RAN#
532 *
533 .
534 3
535 -
536 *
537 INT
538 STO .1
550 IF P<C THEN 210......................................................539 0
540 5
541 9
542 CHS
543 STO I
544 RCL 1
545 RCL 9
546 TEST 8
547 GTO I
551 REM *** STARVE ENOUGH FOR IMPEACHMENT?...............................548 RCL 9
549 RCL 1
550 -
551 STO 2
552 5
553 9
554 3
555 CHS
556 STO I
557 .
558 4
559 5
560 RCL 9
561 *
562 RCL 2
563 TEST 7
564 GTO I
553 P1=((Z-1)*P1+D*100/P)/Z..............................................565 RCL .4
566 1
567 -
568 RCL .0
569 *
570 RCL 2
571 1
572 0
573 0
574 *
575 RCL 9
576 /
577 +
578 RCL .4
579 /
580 STO .0
555 P=C: D1=D1+D: GOTO 215...............................................581 RCL 1
582 STO 9
583 RCL 3
584 RCL 2
585 +
586 STO 3
587 0
588 6
589 1
590 CHS
591 STO I
592 GTO I
560 PRINT: PRINT "YOU STARVED";D;"PEOPLE IN ONE YEAR!!!".................593 SF 8
594 2
595 7
596 GSB 0
597 RCL 2
598 GSB 0
599 SF 8
600 2
601 8
602 GSB 0
565 PRINT "DUE TO THIS EXTREME MISMANAGEMENT YOU HAVE NOT ONLY"..........603 SF 8
604 2
605 9
606 GSB 0
566 PRINT "BEEN IMPEACHED AND THROWN OUT OF OFFICE BUT YOU HAVE".........607 SF 8
608 3
609 0
610 GSB 0
567 PRINT "ALSO BEEN DECLARED NATIONAL FINK!!!!": GOTO 990...............611 SF 8
612 3
613 1
614 GSB 0
615 8
616 1
617 6
618 CHS
619 STO I
620 GTO I
710 PRINT "HAMURABI: THINK AGAIN. YOU HAVE ONLY".......................621 SF 8
622 3
623 2
624 GSB 0
711 PRINT S;"BUSHELS OF GRAIN. NOW THEN,"...............................625 RCL .2
626 GSB 0
627 SF 8
628 3
629 3
630 GSB 0
712 RETURN...............................................................631 RTN
720 PRINT "HAMURABI: THINK AGAIN. YOU OWN ONLY";A;"ACRES. NOW THEN,"..632 SF 8
633 3
634 4
635 GSB 0
636 RCL 0
637 GSB 0
638 SF 8
639 3
640 5
641 GSB 0
730 RETURN...............................................................642 RTN
800 C=INT(RND(1)*5)+1....................................................643 RAN#
644 5
645 *
646 INT
647 1
648 +
649 STO 1
801 RETURN...............................................................650 RTN