Commit 8990ccb0c119a29a70e6805e51b0ea853f96c9d0

Authored by David René
1 parent 5b9a783b

system/message_queue.anubis:

add set_name method in MessageQueue. This allow to change the name of message queue for better debugging
tools/basis.anubis:
move println on the top of file to permit some function to use it
improve the read_line_from_stdin for better working on Windows
web/service_machine.anubis:
update vm_info to fit with right number of resurgent symbols
src/vmtools.cpp:
read_byte is able to read byte per byte on stdin instead of line before. This only work with stdin.
anubis_dev/library/system/message_queue.anubis
... ... @@ -2,6 +2,7 @@
2 2  
3 3 read muscle.anubis
4 4 read tools/basis.anubis
  5 +read system/string.anubis
5 6  
6 7 public type MessageResult:
7 8 timeout,
... ... @@ -19,7 +20,8 @@ public type MessageQueue:
19 20 One -> One connection_closed,
20 21 One -> One quit,
21 22 One -> Bool quit_requested,
22   - One -> String get_name
  23 + One -> String get_name,
  24 + String -> One set_name
23 25 ).
24 26  
25 27  
... ... @@ -105,7 +107,7 @@ define MessageResult
105 107 public define MessageQueue
106 108 create_MessageQueue
107 109 (
108   - String name
  110 + String g_name
109 111 )=
110 112 with rcv_flip = var((List(Message))[]),
111 113 rcv_flap = var((List(Message))[]),
... ... @@ -117,6 +119,7 @@ public define MessageQueue
117 119 send_flip_flag = var((Bool) true),
118 120 conn_closed = var((Bool) false),
119 121 quit = var((Bool) false),
  122 + name = var((String) g_name),
120 123 message_queue
121 124 (
122 125 //add_Message
... ... @@ -143,11 +146,11 @@ public define MessageQueue
143 146 (Message msg) |->
144 147 if *send_flip_flag then
145 148 send_flip <- ([msg . *send_flip]);
146   -// println("add_Message_to_send add in flip");
  149 +// println("add_Message_to_send [0x"+zero_pad_n(8,to_hexa(*msg.what))+"] add in flip ["+*name+"]");
147 150 unique
148 151 else
149 152 send_flap <- ([msg . *send_flap]);
150   -// println("add_Message_to_send add in flap");
  153 +// println("add_Message_to_send [0x"+zero_pad_n(8,to_hexa(*msg.what))+"] add in flap ["+*name+"]");
151 154 unique,
152 155  
153 156 //get_next_Message_to_send
... ... @@ -178,6 +181,9 @@ public define MessageQueue
178 181 *quit,
179 182 //get_name
180 183 (One u) |->
181   - name
  184 + *name,
  185 + //set_name
  186 + (String new_name) |->
  187 + name <- new_name
182 188 ).
183 189  
... ...
anubis_dev/library/system/message_transceiver.anubis
... ... @@ -82,7 +82,7 @@ define One
82 82 {
83 83 failure then
84 84 message_receiver(conn, queue, constant_byte_array(0,0)),
85   - closed then unique,
  85 + closed then unique,
86 86 ok(msg) then
87 87 queue.add_received_Message(msg);
88 88 message_receiver(conn, queue, constant_byte_array(0,0)),
... ...
anubis_dev/library/tools/basis.anubis
1   -
  1 +
2 2 The Anubis Project
3 3  
4 4 Some basic definitions.
... ... @@ -347,7 +347,17 @@ public define Int
347 347 }.
348 348  
349 349 *** (3) String functions
350   -
  350 +
  351 + Print the given string together with a newline. This is a convenience function to avoid
  352 + typing +"\n" at each call of print.
  353 +
  354 +public define One
  355 + println
  356 + (
  357 + String line
  358 + )=
  359 + print(line + "\n").
  360 +
351 361 public define String
352 362 String s + Word32 i =
353 363 s + to_decimal(i).
... ... @@ -639,8 +649,6 @@ public define Bool
639 649 ) =
640 650 member(c,s,0).
641 651  
642   -
643   -
644 652 A syntactical variant for member, using the sign ':' (remind of 'membership' relation
645 653 in Set Theory). 'a:b' means that 'a' belongs to the list 'b'.
646 654  
... ... @@ -2144,7 +2152,7 @@ public define Bool
2144 2152  
2145 2153 *** (14.1) Reading a line from the standard input.
2146 2154  
2147   -define String
  2155 +public define String
2148 2156 read_line_from_stdin
2149 2157 (
2150 2158 List(Word8) so_far
... ... @@ -2153,9 +2161,12 @@ define String
2153 2161 {
2154 2162 failure then implode(reverse(so_far)),
2155 2163 success(c) then
2156   - if c = '\n'
2157   - then implode(reverse(so_far))
2158   - else read_line_from_stdin([c . so_far])
  2164 + //println("read line read char ["+c+"|"+implode([c])+"]");
  2165 + if c = '\n' | c='\r' then
  2166 + implode(reverse(so_far))
  2167 + else
  2168 + print(implode[c]);
  2169 + read_line_from_stdin([c . so_far])
2159 2170 }.
2160 2171  
2161 2172  
... ... @@ -2399,15 +2410,7 @@ public define RGBA
2399 2410 rgba(r,g,b,a).
2400 2411  
2401 2412  
2402   - Print the given string together with a newline. This is a convenience function to avoid
2403   - typing +"\n" at each call of print.
2404   -
2405   -public define One
2406   - println
2407   - (
2408   - String line
2409   - )=
2410   - print(line + "\n").
  2413 +
2411 2414  
2412 2415 public define One
2413 2416 print
... ...
anubis_dev/library/web/service_machine.anubis
... ... @@ -75,7 +75,7 @@ define One
75 75 {
76 76 [ ] then unique,
77 77 [h . t] then
78   - if h is vm_info(mid,state,ws,sip,ip,ss,sp,l1,l5,l15) then
  78 + if h is vm_info(mid,state,ws,ip,ss,sp,l1,l5,l15) then
79 79 print(to_decimal(mid)); print(state); print(ws);
80 80 print(to_decimal(ip));
81 81 //(if state is running then print(to_decimal(ip)) else unique);
... ...
anubis_dev/vm/src/vmtools.cpp
... ... @@ -8,6 +8,7 @@
8 8 #include "AnubisSupport.h"
9 9 //#include <malloc.h>
10 10 #include <stdio.h>
  11 +#include <conio.h>
11 12 #include <assert.h>
12 13 #include <fcntl.h>
13 14 #include <errno.h>
... ... @@ -1714,7 +1715,52 @@ open_IP_connection(U32 conn_seg,
1714 1715 switch (conn[4]) /* type of connection (see vm.h) */
1715 1716 {
1716 1717 case conn_file:
1717   - return getc(*((FILE **)(conn+8)));
  1718 + FILE* fd;
  1719 + fd = *((FILE **)(conn+8));
  1720 + if (fd == stdin)
  1721 + {
  1722 +#ifdef WIN32
  1723 +/* HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
  1724 + DWORD events;
  1725 + INPUT_RECORD buffer;
  1726 + PeekConsoleInput(handle, &buffer, 1, &events);
  1727 + if (events > 0)
  1728 + {
  1729 + if(buffer.EventType == KEY_EVENT & buffer.Event.KeyEvent.bKeyDown==1)
  1730 + {
  1731 + int read_char;
  1732 + ReadConsoleInput(handle, &buffer, 1, &events);
  1733 +
  1734 + read_char = buffer.Event.KeyEvent.uChar.AsciiChar;
  1735 + FlushConsoleInputBuffer(handle);
  1736 + if (read_char == 0)
  1737 + {
  1738 + return 2*EOF;
  1739 + }
  1740 + else
  1741 + {
  1742 + if (read_char != 27) //don't show escape
  1743 + putchar(read_char);
  1744 +
  1745 + //printf("Read char [%d]\n bKeyDown [%d]\n",read_char, buffer.Event.KeyEvent.bKeyDown);
  1746 + return(read_char);
  1747 + }
  1748 + }
  1749 + else if (buffer.EventType > 0)
  1750 + {
  1751 + FlushConsoleInputBuffer(handle);
  1752 + }
  1753 + }
  1754 + return 2*EOF;
  1755 +*/
  1756 +#endif
  1757 + if (kbhit()) //a character waiting to be read
  1758 + return(getch());
  1759 + else
  1760 + return 2*EOF;
  1761 +
  1762 + }
  1763 + return getc(fd);
1718 1764  
1719 1765 case conn_network:
1720 1766 {
... ...