updated, replace : with =

This commit is contained in:
~d6 2024-04-01 10:22:48 -04:00
parent 4f6b71d641
commit 0f57e455ac
4 changed files with 4 additions and 1380 deletions

View File

@ -149,7 +149,7 @@
STH2kr STA2 ( end* [pos*] ; pos<-n )
STH2r INC2 INC2 ( end pos+2* )
GTH2k ?&loop ( end* pos+2* )
POP2 POP2 LIT2r :cards/last ( [last*] )
POP2 POP2 LIT2r =cards/last ( [last*] )
LIT2 [ &card $2 ] ( c* [last*] )
STH2kr STA2 INC2r INC2r ( [last+2*] ; last<-c )
LIT2 [ &xy $2 ] ( xy* [last+2*] )
@ -212,7 +212,7 @@
( returns top card at coords, or 0000 if no card. )
@find-card ( x* y* -> addr* )
LIT2r :cards LIT2r :cards/last ( x* y* [limit* first*] )
LIT2r =cards LIT2r =cards/last ( x* y* [limit* first*] )
&loop ( x* y* [limit* pos*] )
OVR2 OVR2 STH2kr ( x* y* x* y* pos* [limit* pos*] )
intersects ?&done ( x* y* [limit* pos*] )
@ -249,7 +249,7 @@
@draw-all-cards ( draw* -> )
,&draw STR2 ( )
held-end-offset STH2 ( [limit*] )
LIT2r :cards ( [limit* pos*] )
LIT2r =cards ( [limit* pos*] )
&loop ( [limit* pos*] )
STH2kr LDA2 INC2r INC2r ( card* [limit* pos+2*] )
#00 STH2kr LDA INC2r ( card* x* [limit* pos+3*] )
@ -257,7 +257,7 @@
LIT2 [ &draw $2 ] JSR2 ( [limit* pos+4] )
GTH2kr STHr ?&loop ( [limit* pos+4] )
POP2r POP2r ( )
LIT2r :cards/end ( [limit*] )
LIT2r =cards/end ( [limit*] )
held-end-offset STH2 ( [limit* offset*] )
&mloop ( [limit* pos*] )
STH2kr LDA2 INC2r INC2r ( card* [limit* pos+2*] )

1227
uxnbot.lua

File diff suppressed because it is too large Load Diff

View File

@ -1,79 +0,0 @@
#!/usr/bin/python
import re
import socket
import sys
import tempfile
import uxnrepl
server = "irc.libera.chat"
nick = b"uxnbot"
channel = b"#uxn"
sandbox = tempfile.mkdtemp(prefix='uxnrepl')
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def send(msg):
print('>>> %r' % msg)
irc.send(msg + b'\r\n')
def recv():
msg = irc.recv(2040)
print('<<< %r' % msg)
return msg
print("connecting to: %s" % server)
irc.connect((server, 6667))
send(b"USER %s %s %s :bot for testing uxntal code" % (nick, nick, nick))
send(b"NICK %s" % nick)
#send("PRIVMSG nickserv :iNOOPE\r\n")
send(b"JOIN %s" % channel)
ping_re = re.compile(br'PING (.+)$')
chan_msg_re = re.compile(br':([^!]+)![^ ]+ PRIVMSG ([^ ]+) :' + nick + br': (.*)$')
priv_msg_re = re.compile(br':([^!]+)![^ ]+ PRIVMSG ' + nick + br' :(.*)$')
ignored = {b'rst', b'wst', b''}
def evaluate(msg):
output = uxnrepl.execute(msg.decode('utf-8'), sandbox=sandbox)
lines = [s.strip() for s in output.split(b'\n')]
interesting = [s for s in lines if s not in ignored]
result = b' | '.join(interesting)
print('*** executing %r gave %r -> %r -> %r' % (msg, output, interesting, result))
return result
while True:
text = recv()
m = ping_re.match(text)
if m:
send(b'PONG %s' % m.group(1).strip())
continue
m = chan_msg_re.match(text)
if m and m.group(2) == channel:
user = m.group(1)
msg = m.group(3).strip()
result = evaluate(msg)
send(b'PRIVMSG %s :%s: %s' % (channel, user, result))
continue
m = priv_msg_re.match(text)
if m:
user = m.group(1)
msg = m.group(2).strip()
result = evaluate(msg)
send(b'PRIVMSG %s :%s' % (user, result))
continue
# message from user in channel:
# b':d_m!~d_m@user/d-m/x-5109880 PRIVMSG #uxn :uxnbot: hello\r\n'
# keep alive:
# b'PING :mercury.libera.chat\r\n'
# private message
# b':d_m!~d_m@user/d-m/x-5109880 PRIVMSG uxnbot :hello\r\n'

70
uxnrepl
View File

@ -1,70 +0,0 @@
#!/usr/bin/python
from os import system
from sys import stdin, stdout
from tempfile import mkstemp
template = '''
|0100
( start ) %s ( end )
#05 DEI ,emit-wst/n STR
;wst print
@dump-wst
#04 DEI #01 GTH ?&next !emit-wst &next STH !dump-wst
@emit-wst
#05 DEI LIT [ &n $1 ] GTH ?&next #0a18 DEO !start-rst
&next STHr emit #2018 DEO !emit-wst
@start-rst
;rst print
@dump-rst
#05 DEI #00 GTH ?&next !emit-rst &next STHr !dump-rst
@emit-rst
#04 DEI #01 GTH ?&next #0a18 DEO #800f DEO BRK
&next emit #2018 DEO !emit-rst
@print ( addr* -> )
LDAk DUP ?{ POP POP2 JMP2r } #18 DEO INC2 !print
@emit
DUP #04 SFT ,&ch JSR
&ch #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO JMP2r
@rst "rst 20 00
@wst "wst 20 00
'''
def write_rom(path, s):
f = open(path, 'w')
prog = template % s
f.write(prog)
f.close()
def run(s):
_, tmp_tal = mkstemp(suffix='.tal', prefix='uxnrepl')
_, tmp_rom = mkstemp(suffix='.rom', prefix='uxnrepl')
write_rom(tmp_tal, s)
res = system('uxnasm %s %s 2>/dev/null' % (tmp_tal, tmp_rom))
if res != 0:
system('uxnasm %s %s' % (tmp_tal, tmp_rom))
return
system('uxncli %s' % tmp_rom)
def main():
print('uxnrepl (ctrl-d to exit)')
while True:
stdout.write('> ')
stdout.flush()
s = stdin.readline()
if not s:
print('bye!')
break
run(s)
if __name__ == "__main__":
main()