[Joypy-announce] joypy/Joypy: 3 new changesets

Back to archive index
scmno****@osdn***** scmno****@osdn*****
Tue Dec 3 07:21:17 JST 2019


changeset ce1ef1469eb2 in joypy/Joypy
details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=ce1ef1469eb2
user: Simon Forman <sform****@hushm*****>
date: Thu Nov 28 07:58:42 2019 -0800
description: Debugging this sucks.

Even with the RISC emu GUI.

Redesign vm?  Add more tooling?  Use MetaII?

Happy Thanksgiving!
changeset 4bcc3d7a1456 in joypy/Joypy
details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=4bcc3d7a1456
user: Simon Forman <sform****@hushm*****>
date: Mon Dec 02 14:13:50 2019 -0800
description: Minor docs update.
changeset 85903a959917 in joypy/Joypy
details: http://hg.osdn.jp/view/joypy/Joypy?cmd=changeset;node=85903a959917
user: Simon Forman <sform****@hushm*****>
date: Mon Dec 02 14:14:38 2019 -0800
description: Some helper scripts for windows.

diffstat:

 joy/joy.py              |   13 +-
 joy/parser.py           |   11 +-
 start.bat               |    1 +
 startREPL.bat           |    1 +
 startVUI.bat            |    1 +
 thun/compiler.markII.pl |   17 +-
 thun/joy_asmii.bin      |  Bin 
 thun/markII.rst         |  558 ++++++++++++++++++++++++++++++++++++++++++++++++
 thun/symbols.txt        |   31 ++-
 9 files changed, 612 insertions(+), 21 deletions(-)

diffs (truncated from 754 to 300 lines):

diff -r 59ac931ae32f -r 85903a959917 joy/joy.py
--- a/joy/joy.py	Wed Nov 13 21:15:33 2019 -0800
+++ b/joy/joy.py	Mon Dec 02 14:14:38 2019 -0800
@@ -35,12 +35,15 @@
 
 
 def joy(stack, expression, dictionary, viewer=None):
-  '''Evaluate the Joy expression on the stack.
+  '''Evaluate a Joy expression on a stack.
 
-  The basic joy() function is quite straightforward.  It iterates through a
-  sequence of terms which are either literals (strings, numbers, sequences)
-  or functions.  Literals are put onto the stack and functions are
-  executed.
+  This function iterates through a sequence of terms which are either
+  literals (strings, numbers, sequences of terms) or function symbols.
+  Literals are put onto the stack and functions are looked up in the
+  disctionary and executed.
+
+  The viewer is a function that is called with the stack and expression
+  on every iteration, its return value is ignored.
 
   :param stack stack: The stack.
   :param stack expression: The expression to evaluate.
diff -r 59ac931ae32f -r 85903a959917 joy/parser.py
--- a/joy/parser.py	Wed Nov 13 21:15:33 2019 -0800
+++ b/joy/parser.py	Mon Dec 02 14:14:38 2019 -0800
@@ -26,11 +26,14 @@
 
 A crude grammar::
 
-  joy = term*
-  term = int | float | string | '[' joy ']' | function
+    joy = term*
+    term = int | float | string | '[' joy ']' | symbol
 
-A Joy expression is a sequence of zero or more terms
-
+A Joy expression is a sequence of zero or more terms.  A term is a
+literal value (integer, float, string, or Joy expression) or a function
+symbol.  Function symbols are unquoted strings and cannot contain square
+brackets.   Terms must be separated by blanks, which can be omitted
+around square brackets.
 
 '''
 #TODO: explain the details of float lits and strings.
diff -r 59ac931ae32f -r 85903a959917 start.bat
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/start.bat	Mon Dec 02 14:14:38 2019 -0800
@@ -0,0 +1,1 @@
+python -m joy.gui
\ No newline at end of file
diff -r 59ac931ae32f -r 85903a959917 startREPL.bat
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/startREPL.bat	Mon Dec 02 14:14:38 2019 -0800
@@ -0,0 +1,1 @@
+python -m joy
\ No newline at end of file
diff -r 59ac931ae32f -r 85903a959917 startVUI.bat
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/startVUI.bat	Mon Dec 02 14:14:38 2019 -0800
@@ -0,0 +1,1 @@
+python -m joy.vui
\ No newline at end of file
diff -r 59ac931ae32f -r 85903a959917 thun/compiler.markII.pl
--- a/thun/compiler.markII.pl	Wed Nov 13 21:15:33 2019 -0800
+++ b/thun/compiler.markII.pl	Mon Dec 02 14:14:38 2019 -0800
@@ -19,6 +19,7 @@
 
 Mark II
 
+
 */
 :- use_module(library(assoc)).
 :- use_module(library(clpfd)).
@@ -120,6 +121,7 @@
         asm(mov_imm(TEMP3, 4)),  % Factored out of the loop.  Used for linking.
         repeat_until(if_zero(TEMP0), [  % TEMP0 = Address of the quoted program.
             load(TERM, TEMP0),
+            label(iball, _),
             unpack_pair(TERM, TEMP1, TEMP2, TEMP0),
             % TEMP1 is the address of head item, TEMP2 is the tail
             asm(mov(TEMP0, TEMP2)),  % update temp0 to point to rest of quoted program.
@@ -129,7 +131,7 @@
                 % TERM is the last item in the quoted program.
                 % The expr should point to a cell that has TEMP1 head and tail
                 % of the rest of the expression.
-                [merge_and_store(TEMP1, TEMP3, SP)]
+                [sub_base_from_offset(TEMP1, SP), merge_and_store(TEMP1, TEMP3, SP)]
                 % TERM has at least one more item after it.
                 % We know that we will be writing that item in a
                 % cell immediately after this one, so it has TEMP1
@@ -169,11 +171,14 @@
     merge_and_store(TEMP3, TEMP0, SP),  % Push second item onto stack.
     jump(Main),
 
+  % ======================================
     definition(unit, Unit, [New, Cons], DoDef, TOS),
     definition(x, X, [Dup, I], DoDef, TOS),
     definition(swons, Swons, [Swap, Cons], DoDef, TOS),
+  % ======================================
 
-    label(dodef, DoDef),  % TOS points to body expr, set by definition.
+    label(dodef, DoDef),  % ======================================
+    % TOS points to body expr, set by definition.
     asm(mov_imm(TEMP1, 4)),  % Used for linking to previous cell.
     incr(SP),
     sub_base_from_offset(TOS, SP),
@@ -207,10 +212,11 @@
      label(Label)].
 
 ⟐(unpack_pair(From, HeadAddr, TailAddr, Base)) -->
-    [lsl_imm(HeadAddr, From, 2)],  % Trim off the type tag 00 bits.
+    [label('unpack[', _), lsl_imm(HeadAddr, From, 2)],  % Trim off the type tag 00 bits.
     ⟐(roll_down_add_base_if_not_zero(HeadAddr, Base)),
     [lsl_imm(TailAddr, From, 17)],  % Trim off tag and head address.
-    ⟐(roll_down_add_base_if_not_zero(TailAddr, Base)).
+    ⟐(roll_down_add_base_if_not_zero(TailAddr, Base)),
+    [label(']unpack', _)].
 
 ⟐(roll_down_add_base_if_not_zero(Addr, Base)) -->
     [asr_imm(Addr, Addr, 17),  % Preserving sign.
@@ -362,7 +368,8 @@
 asm([(N, Instruction)|Rest]) --> !, asm(N, Instruction), asm(Rest).
 
 asm(Here, expr_cell(Func, NextCell)) --> !,
-    {Data is ((Func - Here) << 15) \/ NextCell}, asm(Here, word(Data)).
+    {Data is (((Func - Here) /\ 0x7fff) << 15) \/ NextCell},
+    asm(Here, word(Data)).
 
 asm(_, symbol(Sym)) --> !, {Data is (Sym + 4) \/ 0x80000000}, asm(_, word(Data)).
 % The symbol is at the beginning of the function machine code, so the pointer it
diff -r 59ac931ae32f -r 85903a959917 thun/joy_asmii.bin
Binary file thun/joy_asmii.bin has changed
diff -r 59ac931ae32f -r 85903a959917 thun/markII.rst
--- a/thun/markII.rst	Wed Nov 13 21:15:33 2019 -0800
+++ b/thun/markII.rst	Mon Dec 02 14:14:38 2019 -0800
@@ -4,6 +4,14 @@
 =========================
 
 
+
+This (and the previous incarnation) is really more of a "macro assembler"
+than a compiler, and nothing like what I want it to be.  It should be
+tracking the "types" of registers in some enviroment that gets carried
+along and picking primitives and making optimizations based on that
+information.
+
+
 TO replace the crude first draft I want to expand the representation of
 data types.
 
@@ -401,6 +409,556 @@
     ペ, write_cell(TOS,   SP)
 
 
+--------------------------------------
+
+Debugging definitions
+
+     swons 0xd2 load R[0] <- ram[R[0] + 0x34c]
+>          0xd3 mov R[2] <- 0x354
+           0xd4 BR T 0x2 immediate 
+           0xd5 BR F -0x69fffc immediate  and R[15] <- PC + 1
+           0xd6 BR GT -0x4c0000 immediate  and R[15] <- PC + 1
+     dodef 0xd7 mov R[7] <- 0x4
+           0xd8 sub R[0] <- R[0] 0x4 immediate
+
+Q: Is 0x354 >> 2 == 0xd5 ?
+
+In [1]: 0x354 >> 2 == 0xd5
+Out[1]: True
+
+Okay then.
+
+
+>    dodef 0xd7 mov R[7] <- 0x4
+           0xd8 sub R[0] <- R[0] 0x4 immediate
+           0xd9 sub R[2] <- R[2] 0x0 immediate
+           0xda BR EQ 0x2 immediate 
+           0xdb sub R[2] <- R[2] R[0]
+           0xdc and R[2] <- R[2] 0x7fff immediate
+
+
+0xff4  r0
+0x354  r2
+
+
+>          0xde ior R[2] <- R[2] R[7]
+           0xdf store R[2] -> ram[R[0]]
+           0xe0 mov R[7] <- 0x168
+           0xe1 add R[7] <- R[7] 0x4 immediate
+           0xe2 BR T R[7]
+  expressi 0xe3 BR F 0x740004 immediate  and R[15] <- PC + 1
+
+0x39b00004  r2
+
+           0xe0 mov R[7] <- 0x168
+>          0xe1 add R[7] <- R[7] 0x4 immediate
+           0xe2 BR T R[7]
+  expressi 0xe3 BR F 0x740004 immediate  and R[15] <- PC + 1
+
+
+0x16c  r7   = 364 decimal
+
+0x5b I machine code in words
+
+In [8]: 0x16c >> 2 == 0x5b
+Out[8]: True
+
+         i 0x5a load R[0] <- ram[R[0] + 0x16c]
+>          0x5b lsl R[6] <- R[2] 0x2 immediate
+           0x5c asr R[6] <- R[6] 0x11 immediate
+           0x5d BR EQ 0x1 immediate 
+           0x5e add R[6] <- R[6] R[0]
+           0x5f lsl R[2] <- R[2] 0x11 immediate
+           0x60 asr R[2] <- R[2] 0x11 immediate
+
+and then...
+
+         i 0x5a load R[0] <- ram[R[0] + 0x16c]
+           0x5b lsl R[6] <- R[2] 0x2 immediate
+           0x5c asr R[6] <- R[6] 0x11 immediate
+           0x5d BR EQ 0x1 immediate 
+>          0x5e add R[6] <- R[6] R[0]
+           0x5f lsl R[2] <- R[2] 0x11 immediate
+           0x60 asr R[2] <- R[2] 0x11 immediate
+           0x61 BR EQ 0x1 immediate 
+           0x62 add R[2] <- R[2] R[0]
+           0x63 sub R[6] <- R[6] 0x0 immediate
+
+0x354  r6  check
+
+           0x5e add R[6] <- R[6] R[0]
+           0x5f lsl R[2] <- R[2] 0x11 immediate
+           0x60 asr R[2] <- R[2] 0x11 immediate
+           0x61 BR EQ 0x1 immediate 
+>          0x62 add R[2] <- R[2] R[0]
+           0x63 sub R[6] <- R[6] 0x0 immediate
+           0x64 BR EQ 0x22 immediate 
+           0x65 sub R[10] <- R[0] 0x4 immediate
+
+0xff8  r2
+
+           0x61 BR EQ 0x1 immediate 
+           0x62 add R[2] <- R[2] R[0]
+           0x63 sub R[6] <- R[6] 0x0 immediate
+#117       0x64 BR EQ 0x22 immediate 
+>          0x65 sub R[10] <- R[0] 0x4 immediate
+           0x66 mov R[9] <- 0x4
+           0x67 load R[3] <- ram[R[6]]
+     iball 0x68 lsl R[7] <- R[3] 0x2 immediate
+           0x69 asr R[7] <- R[7] 0x11 immediate
+           0x6a BR EQ 0x1 immediate 
+
+line 120
+
+#120       0x65 sub R[10] <- R[0] 0x4 immediate
+           0x66 mov R[9] <- 0x4
+>          0x67 load R[3] <- ram[R[6]]
+     iball 0x68 lsl R[7] <- R[3] 0x2 immediate
+           0x69 asr R[7] <- R[7] 0x11 immediate
+           0x6a BR EQ 0x1 immediate 
+           0x6b add R[7] <- R[7] R[6]
+           0x6c lsl R[8] <- R[3] 0x11 immediate
+
+line 123
+
+0xff960004  r3
+
+     iball 0x68 lsl R[7] <- R[3] 0x2 immediate
+           0x69 asr R[7] <- R[7] 0x11 immediate
+           0x6a BR EQ 0x1 immediate 
+>          0x6b add R[7] <- R[7] R[6]
+           0x6c lsl R[8] <- R[3] 0x11 immediate
+           0x6d asr R[8] <- R[8] 0x11 immediate
+           0x6e BR EQ 0x1 immediate 
+           0x6f add R[8] <- R[8] R[6]
+           0x70 mov R[6] <- R[8]
+
+0x280  r7  Address of swons def list?  of swap symbol?
+
+    In [4]: w.cpu.R[7]
+    Out[4]: 640L
+
+    In [5]: hex(_)
+    Out[5]: '0x280L'
+
+    In [6]: w.cpu.ram[w.cpu.R[7]]
+    Out[6]: 2147484292L
+
+    In [7]: bin(_)
+    Out[7]: '0b10000000000000000000001010000100'
+
+    In [8]: w.syms.keys()
+    Out[8]: [160, 35, 7, 104, 44, 45, 14, 205, 48, 200, 210, 227, 86, 215, 90, 157]
+
+    In [9]: 640 >> 2
+    Out[9]: 160
+


More information about the Joypy-announce mailing list
Back to archive index