aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--elymas/interpreter3
-rw-r--r--elymas/interpreter.ey3
-rw-r--r--elymas/lib/bin.ey14
-rw-r--r--elymas/lib/math.ey27
-rw-r--r--elymas/lib/sys/linux.ey320
-rw-r--r--notes40
7 files changed, 410 insertions, 3 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..3e8d12b
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,6 @@
+all: elymas/interpreter
+
+elymas/interpreter: elymas/interpreter.ey compiler/*.ey
+ cd compiler && \
+ ../interpreter/elymas elymas.ey ../elymas/interpreter.ey
+ mv -v compiler/interpreter $@
diff --git a/elymas/interpreter b/elymas/interpreter
deleted file mode 100644
index 9aac36d..0000000
--- a/elymas/interpreter
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env elymas
-
-{ "/proc/self/fd/0" include }' "interpreter.bin" sys .freeze
diff --git a/elymas/interpreter.ey b/elymas/interpreter.ey
new file mode 100644
index 0000000..35c0dad
--- /dev/null
+++ b/elymas/interpreter.ey
@@ -0,0 +1,3 @@
+#!/usr/bin/env elymas
+
+{ "/proc/self/fd/0" include }' "interpreter" sys .freeze
diff --git a/elymas/lib/bin.ey b/elymas/lib/bin.ey
new file mode 100644
index 0000000..4fe1f4a
--- /dev/null
+++ b/elymas/lib/bin.ey
@@ -0,0 +1,14 @@
+# The idea of bin is to define manipulation routines for strings used
+# as binary data structures
+
+<
+ # 0 -> string
+ # 0 <- string from 9th byte onwards
+ # 1 <- first 8 bytes of string interpreted as 64bit unsigned int
+ { ==s
+ [ [ 0 1 2 3 4 5 6 7 ] s each ] 256 math .unbase
+ 8 s str .postfix
+ } /scanu64 deff
+> /bin defv
+
+# vim: syn=elymas
diff --git a/elymas/lib/math.ey b/elymas/lib/math.ey
new file mode 100644
index 0000000..db04c7b
--- /dev/null
+++ b/elymas/lib/math.ey
@@ -0,0 +1,27 @@
+# Discrete mathematics useful in computer stuff
+# More complicated stuff in sublibs
+
+<
+ # converts an array of digits into an integer
+ # i.e. [ 1 2 3 ] 10 unbase => 321
+ # i.e. [ ] 10 unbase => 0
+ # 0 -> base to convert from
+ # 1 -> array of digits
+ # 0 <- resulting integer
+ { ==b
+ _ len _ ==l dearray
+ 0 l { b mul add } rep
+ } /unbase deff
+
+ # converts an integer into an array of digits
+ # i.e. 123 10 base => [ 3 2 1 ]
+ # i.e. 0 10 base => [ ]
+ # 0 <- base to convert to
+ # 1 <- integer to convert
+ # 0 -> resulting array of digits
+ { ==b
+ [ -01 { _ } { _ b mod -01 b div } loop -- ]
+ } /base deff
+> /math defv
+
+# vim: syn=elymas
diff --git a/elymas/lib/sys/linux.ey b/elymas/lib/sys/linux.ey
new file mode 100644
index 0000000..0c65bbc
--- /dev/null
+++ b/elymas/lib/sys/linux.ey
@@ -0,0 +1,320 @@
+# The idea of sys .linux is to define an isomorphic yet
+# elymas-style interface to syscalls
+
+<
+ 43 ==ACCEPT
+ 288 ==ACCEPT64
+ 21 ==ACCESS
+ 163 ==ACCT
+ 248 ==ADD_KEY
+ 159 ==ADJTIMEX
+ 183 ==AFS_SYSCALL
+ 37 ==ALARM
+ 158 ==ARCH_PRCTL
+ 49 ==BIND
+ 12 ==BRK
+ 125 ==CAPGET
+ 126 ==CAPSET
+ 80 ==CHDIR
+ 90 ==CHMOD
+ 92 ==CHOWN
+ 161 ==CHROOT
+ 229 ==CLOCK_GETRES
+ 228 ==CLOCK_GETTIME
+ 230 ==CLOCK_NANOSLEEP
+ 227 ==CLOCK_SETTIME
+ 56 ==CLONE
+ 3 ==CLOSE
+ 42 ==CONNECT
+ 85 ==CREAT
+ 174 ==CREATE_MODULE
+ 176 ==DELETE_MODULE
+ 32 ==DUP
+ 33 ==DUP2
+ 292 ==DUP3
+ 213 ==EPOLL_CREATE
+ 291 ==EPOLL_CREATE1
+ 233 ==EPOLL_CTL
+ 214 ==EPOLL_CTL_OLD
+ 281 ==EPOLL_PWAIT
+ 232 ==EPOLL_WAIT
+ 215 ==EPOLL_WAIT_OLD
+ 284 ==EVENTFD
+ 290 ==EVENTFD2
+ 59 ==EXECVE
+ 60 ==EXIT
+ 231 ==EXIT_GROUP
+ 269 ==FACCESSAT
+ 221 ==FADVISE64
+ 285 ==FALLOCATE
+ 300 ==FANOTIFY_INIT
+ 301 ==FANOTIFY_MARK
+ 81 ==FCHDIR
+ 91 ==FCHMOD
+ 268 ==FCHMODAT
+ 93 ==FCHOWN
+ 260 ==FCHOWNAT
+ 72 ==FCNTL
+ 75 ==FDATASYNC
+ 193 ==FGETXATTR
+ 196 ==FLISTXATTR
+ 73 ==FLOCK
+ 57 ==FORK
+ 199 ==FREMOVEXATTR
+ 190 ==FSETXATTR
+ 5 ==FSTAT
+ 138 ==FSTATFS
+ 74 ==FSYNC
+ 77 ==FTRUNCATE
+ 202 ==FUTEX
+ 261 ==FUTIMESAT
+ 177 ==GET_KERNEL_SYMS
+ 239 ==GET_MEMPOLICY
+ 274 ==GET_ROBUST_LIST
+ 211 ==GET_THREAD_AREA
+ 79 ==GETCWD
+ 78 ==GETDENTS
+ 217 ==GETDENTS64
+ 108 ==GETEGID
+ 107 ==GETEUID
+ 104 ==GETGID
+ 115 ==GETGROUPS
+ 36 ==GETITIMER
+ 52 ==GETPEERNAME
+ 121 ==GETPGID
+ 111 ==GETPGRP
+ 39 ==GETPID
+ 181 ==GETPMSG
+ 110 ==GETPPID
+ 140 ==GETPRIORITY
+ 120 ==GETRESGID
+ 118 ==GETRESUID
+ 97 ==GETRLIMIT
+ 98 ==GETRUSAGE
+ 124 ==GETSID
+ 51 ==GETSOCKNAME
+ 55 ==GETSOCKOPT
+ 186 ==GETTID
+ 96 ==GETTIMEOFDAY
+ 102 ==GETUID
+ 191 ==GETXATTR
+ 175 ==INIT_MODULE
+ 254 ==INOTIFY_ADD_WATCH
+ 253 ==INOTIFY_INIT
+ 294 ==INOTIFY_INIT1
+ 255 ==INOTIFY_RM_WATCH
+ 210 ==IO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 17 ==PREAD64
+ 295 ==PREADV
+ 302 ==PRLIMIT64
+ 270 ==PSELECT6
+ 101 ==PTRACE
+ 182 ==PUTPMSG
+ 18 ==PWRITE64
+ 296 ==PWRITEV
+ 178 ==QUERY_MODULE
+ 179 ==QUOTACTL
+ 0 ==READ
+ 187 ==READAHEAD
+ 89 ==READLINK
+ 267 ==READLINKAT
+ 19 ==READV
+ 169 ==REBOOT
+ 45 ==RECVFROM
+ 299 ==RECVMMSG
+ 47 ==RECVMSG
+ 216 ==REMAP_FILE_PAGES
+ 197 ==REMOVEXATTR
+ 82 ==RENAME
+ 264 ==RENAMEAT
+ 249 ==REQUEST_KEY
+ 219 ==RESTART_SYSCALL
+ 84 ==RMDIR
+ 13 ==RT_SIGACTION
+ 127 ==RT_SIGPENDING
+ 14 ==RT_SIGPROCMASK
+ 129 ==RT_SIGQUEUEINFO
+ 15 ==RT_SIGRETURN
+ 130 ==RT_SIGSUSPEND
+ 128 ==RT_SIGTIMEDWAIT
+ 297 ==RT_TGSIGQUEUEINFO
+ 146 ==SCHED_GET_PRIORITY_MAX
+ 147 ==SCHED_GET_PRIORITY_MIN
+ 204 ==SCHED_GETAFFINITY
+ 143 ==SCHED_GETPARAM
+ 145 ==SCHED_GETSCHEDULER
+ 148 ==SCHED_RR_GET_INTERVAL
+ 203 ==SCHED_SETAFFINITY
+ 142 ==SCHED_SETPARAM
+ 144 ==SCHED_SETSCHEDULER
+ 24 ==SCHED_YIELD
+ 185 ==SECURITY
+ 23 ==SELECT
+ 66 ==SEMCTL
+ 64 ==SEMGET
+ 65 ==SEMOP
+ 220 ==SEMTIMEDOP
+ 40 ==SENDFILE
+ 46 ==SENDMSG
+ 44 ==SENDTO
+ 238 ==SET_MEMPOLICY
+ 273 ==SET_ROBUST_LIST
+ 205 ==SET_THREAD_AREA
+ 218 ==SET_TID_ADDRESS
+ 171 ==SETDOMAINNAME
+ 123 ==SETFSGID
+ 122 ==SETFSUID
+ 106 ==SETGID
+ 116 ==SETGROUPS
+ 170 ==SETHOSTNAME
+ 38 ==SETITIMER
+ 109 ==SETPGID
+ 141 ==SETPRIORITY
+ 114 ==SETREGID
+ 119 ==SETRESGID
+ 117 ==SETRESUID
+ 113 ==SETREUID
+ 160 ==SETRLIMIT
+ 112 ==SETSID
+ 54 ==SETSOCKOPT
+ 164 ==SETTIMEOFDAY
+ 105 ==SETUID
+ 188 ==SETXATTR
+ 30 ==SHMAT
+ 31 ==SHMCTL
+ 67 ==SHMDT
+ 29 ==SHMGET
+ 48 ==SHUTDOWN
+ 131 ==SIGALTSTACK
+ 282 ==SIGNALFD
+ 289 ==SIGNALFD4
+ 41 ==SOCKET
+ 53 ==SOCKETPAIR
+ 275 ==SPLICE
+ 4 ==STAT
+ 137 ==STATFS
+ 168 ==SWAPOFF
+ 167 ==SWAPON
+ 88 ==SYMLINK
+ 266 ==SYMLINKAT
+ 162 ==SYNC
+ 277 ==SYNC_FILE_RANGE
+ 156 ==SYSCTL
+ 139 ==SYSFS
+ 99 ==SYSINFO
+ 103 ==SYSLOG
+ 276 ==TEE
+ 234 ==TGKILL
+ 201 ==TIME
+ 222 ==TIMER_CREATE
+ 226 ==TIMER_DELETE
+ 225 ==TIMER_GETOVERRUN
+ 224 ==TIMER_GETTIME
+ 223 ==TIMER_SETTIME
+ 283 ==TIMERFD_CREATE
+ 287 ==TIMERFD_GETTIME
+ 286 ==TIMERFD_SETTIME
+ 100 ==TIMES
+ 200 ==TKILL
+ 76 ==TRUNCATE
+ 184 ==TUXCALL
+ 95 ==UMASK
+ 166 ==UMOUNT2
+ 63 ==UNAME
+ 87 ==UNLINK
+ 263 ==UNLINKAT
+ 272 ==UNSHARE
+ 134 ==USELIB
+ 136 ==USTAT
+ 132 ==UTIME
+ 280 ==UTIMENSAT
+ 235 ==UTIMES
+ 58 ==VFORK
+ 153 ==VHANGUP
+ 278 ==VMSPLICE
+ 236 ==VSERVER
+ 61 ==WAIT4
+ 247 ==WAITID
+ 1 ==WRITE
+ 20 ==WRITEV
+
+ # 0 <- raw return value
+ # 1 <- seconds since 1970
+ # 2 <- microseconds since 1970
+ {
+ # struct timeval takes 16 bytes on a x64
+ 16 str .alloc ==timeval
+ timeval 0 0 0 0 0 GETTIMEOFDAY sys .asm .syscall --
+ timeval bin .scanu64 bin .scanu64 -123
+ } /gettimeofday deff
+> /linux sys .defv
+
+# vim: syn=elymas
diff --git a/notes b/notes
index a3169d8..b59aa41 100644
--- a/notes
+++ b/notes
@@ -280,3 +280,43 @@ Maybe ; should act differently when getting a string, or use another single char
Uses: Categorical operators over Set
Anyway: This should be handled by a library, use escape mechanism for ;
+
+== Musings about the API ==
+
+sys .file
+sys .net
+sys .net .tcpip
+
+ "127.0.0.1" 80 connect
+ "www.google.de" 80 connect
+
+sys .poll
+ create -> p
+ file userdata p .add
+ file p .remove
+ timeout p .poll
+
+sys .linux
+
+str
+ ... "format" sprintf
+ string "format" sscanf
+ end string prefix
+ { 0 end string infix }
+ start string postfix
+ { start string len infix }
+ start end string infix
+ { start end range string * }
+
+str .encode
+ string from to encode
+
+str .utf8
+
+bin
+ ... "format" bprintf
+ string "format" bscanf
+
+math
+ [ 1 2 3 ] 16 unbase -> 1+2*16+3*16*16
+ 12345 10 base -> [ 5 4 3 2 1 ]