parse negative constants

This commit is contained in:
2026-06-06 09:26:34 +02:00
parent a6d44ec5e0
commit 535364931e
8 changed files with 445 additions and 427 deletions

View File

@@ -285,7 +285,7 @@ _builtin_environ:
emit!(&mut self.output, " mov QWORD [rbp-{}], {}", offset, reg);
}
}
Stmt::Const { name: _, value: _ } => {
Stmt::Const { .. } => {
// handled in SymbolTable
}
Stmt::Block(statements) => {

View File

@@ -39,6 +39,7 @@ pub enum Stmt {
Const {
name: Token,
value: Token,
neg: bool,
},
Block(Vec<Stmt>),
If {
@@ -271,8 +272,9 @@ impl Parser {
fn const_declaration(&mut self) -> Result<Stmt, ZernError> {
let name = self.consume(TokenType::Identifier, "expected const name")?;
self.consume(TokenType::Equal, "expected '=' after const name")?;
let neg = self.match_token(&[TokenType::Minus]);
let value = self.consume(TokenType::IntLiteral, "expected a number after '='")?;
Ok(Stmt::Const { name, value })
Ok(Stmt::Const { name, value, neg })
}
fn extern_declaration(&mut self) -> Result<Stmt, ZernError> {

View File

@@ -1,393 +1,406 @@
const S_IFDIR = 0o040000
const S_IFMT = 0o170000
const PROT_READ = 1
const PROT_WRITE = 2
const MAP_PRIVATE = 2
const MAP_ANONYMOUS = 32
const O_RDONLY = 0
const O_WRONLY = 1
const O_CREAT = 64
const O_TRUNC = 512
const SEEK_SET = 0
const SEEK_END = 2
const STDIN = 0
const STDOUT = 1
const SYS_read = 0
const SYS_write = 1
const SYS_open = 2
const SYS_close = 3
const SYS_stat = 4
const SYS_fstat = 5
const SYS_lstat = 6
const SYS_poll = 7
const SYS_lseek = 8
const SYS_mmap = 9
const SYS_mprotect = 10
const SYS_munmap = 11
const SYS_brk = 12
const SYS_rt_sigaction = 13
const SYS_rt_sigprocmask = 14
const SYS_rt_sigreturn = 15
const SYS_ioctl = 16
const SYS_pread64 = 17
const SYS_pwrite64 = 18
const SYS_readv = 19
const SYS_writev = 20
const SYS_access = 21
const SYS_pipe = 22
const SYS_select = 23
const SYS_sched_yield = 24
const SYS_mremap = 25
const SYS_msync = 26
const SYS_mincore = 27
const SYS_madvise = 28
const SYS_shmget = 29
const SYS_shmat = 30
const SYS_shmctl = 31
const SYS_dup = 32
const SYS_dup2 = 33
const SYS_pause = 34
const SYS_nanosleep = 35
const SYS_getitimer = 36
const SYS_alarm = 37
const SYS_setitimer = 38
const SYS_getpid = 39
const SYS_sendfile = 40
const SYS_socket = 41
const SYS_connect = 42
const SYS_accept = 43
const SYS_sendto = 44
const SYS_recvfrom = 45
const SYS_sendmsg = 46
const SYS_recvmsg = 47
const SYS_shutdown = 48
const SYS_bind = 49
const SYS_listen = 50
const SYS_getsockname = 51
const SYS_getpeername = 52
const SYS_socketpair = 53
const SYS_setsockopt = 54
const SYS_getsockopt = 55
const SYS_clone = 56
const SYS_fork = 57
const SYS_vfork = 58
const SYS_execve = 59
const SYS_exit = 60
const SYS_wait4 = 61
const SYS_kill = 62
const SYS_uname = 63
const SYS_semget = 64
const SYS_semop = 65
const SYS_semctl = 66
const SYS_shmdt = 67
const SYS_msgget = 68
const SYS_msgsnd = 69
const SYS_msgrcv = 70
const SYS_msgctl = 71
const SYS_fcntl = 72
const SYS_flock = 73
const SYS_fsync = 74
const SYS_fdatasync = 75
const SYS_truncate = 76
const SYS_ftruncate = 77
const SYS_getdents = 78
const SYS_getcwd = 79
const SYS_chdir = 80
const SYS_fchdir = 81
const SYS_rename = 82
const SYS_mkdir = 83
const SYS_rmdir = 84
const SYS_creat = 85
const SYS_link = 86
const SYS_unlink = 87
const SYS_symlink = 88
const SYS_readlink = 89
const SYS_chmod = 90
const SYS_fchmod = 91
const SYS_chown = 92
const SYS_fchown = 93
const SYS_lchown = 94
const SYS_umask = 95
const SYS_gettimeofday = 96
const SYS_getrlimit = 97
const SYS_getrusage = 98
const SYS_sysinfo = 99
const SYS_times = 100
const SYS_ptrace = 101
const SYS_getuid = 102
const SYS_syslog = 103
const SYS_getgid = 104
const SYS_setuid = 105
const SYS_setgid = 106
const SYS_geteuid = 107
const SYS_getegid = 108
const SYS_setpgid = 109
const SYS_getppid = 110
const SYS_getpgrp = 111
const SYS_setsid = 112
const SYS_setreuid = 113
const SYS_setregid = 114
const SYS_getgroups = 115
const SYS_setgroups = 116
const SYS_setresuid = 117
const SYS_getresuid = 118
const SYS_setresgid = 119
const SYS_getresgid = 120
const SYS_getpgid = 121
const SYS_setfsuid = 122
const SYS_setfsgid = 123
const SYS_getsid = 124
const SYS_capget = 125
const SYS_capset = 126
const SYS_rt_sigpending = 127
const SYS_rt_sigtimedwait = 128
const SYS_rt_sigqueueinfo = 129
const SYS_rt_sigsuspend = 130
const SYS_sigaltstack = 131
const SYS_utime = 132
const SYS_mknod = 133
const SYS_uselib = 134
const SYS_personality = 135
const SYS_ustat = 136
const SYS_statfs = 137
const SYS_fstatfs = 138
const SYS_sysfs = 139
const SYS_getpriority = 140
const SYS_setpriority = 141
const SYS_sched_setparam = 142
const SYS_sched_getparam = 143
const SYS_sched_setscheduler = 144
const SYS_sched_getscheduler = 145
const SYS_sched_get_priority_max = 146
const SYS_sched_get_priority_min = 147
const SYS_sched_rr_get_interval = 148
const SYS_mlock = 149
const SYS_munlock = 150
const SYS_mlockall = 151
const SYS_munlockall = 152
const SYS_vhangup = 153
const SYS_modify_ldt = 154
const SYS_pivot_root = 155
const SYS__sysctl = 156
const SYS_prctl = 157
const SYS_arch_prctl = 158
const SYS_adjtimex = 159
const SYS_setrlimit = 160
const SYS_chroot = 161
const SYS_sync = 162
const SYS_acct = 163
const SYS_settimeofday = 164
const SYS_mount = 165
const SYS_umount2 = 166
const SYS_swapon = 167
const SYS_swapoff = 168
const SYS_reboot = 169
const SYS_sethostname = 170
const SYS_setdomainname = 171
const SYS_iopl = 172
const SYS_ioperm = 173
const SYS_create_module = 174
const SYS_init_module = 175
const SYS_delete_module = 176
const SYS_get_kernel_syms = 177
const SYS_query_module = 178
const SYS_quotactl = 179
const SYS_nfsservctl = 180
const SYS_getpmsg = 181
const SYS_putpmsg = 182
const SYS_afs_syscall = 183
const SYS_tuxcall = 184
const SYS_security = 185
const SYS_gettid = 186
const SYS_readahead = 187
const SYS_setxattr = 188
const SYS_lsetxattr = 189
const SYS_fsetxattr = 190
const SYS_getxattr = 191
const SYS_lgetxattr = 192
const SYS_fgetxattr = 193
const SYS_listxattr = 194
const SYS_llistxattr = 195
const SYS_flistxattr = 196
const SYS_removexattr = 197
const SYS_lremovexattr = 198
const SYS_fremovexattr = 199
const SYS_tkill = 200
const SYS_time = 201
const SYS_futex = 202
const SYS_sched_setaffinity = 203
const SYS_sched_getaffinity = 204
const SYS_set_thread_area = 205
const SYS_io_setup = 206
const SYS_io_destroy = 207
const SYS_io_getevents = 208
const SYS_io_submit = 209
const SYS_io_cancel = 210
const SYS_get_thread_area = 211
const SYS_lookup_dcookie = 212
const SYS_epoll_create = 213
const SYS_epoll_ctl_old = 214
const SYS_epoll_wait_old = 215
const SYS_remap_file_pages = 216
const SYS_getdents64 = 217
const SYS_set_tid_address = 218
const SYS_restart_syscall = 219
const SYS_semtimedop = 220
const SYS_fadvise64 = 221
const SYS_timer_create = 222
const SYS_timer_settime = 223
const SYS_timer_gettime = 224
const SYS_timer_getoverrun = 225
const SYS_timer_delete = 226
const SYS_clock_settime = 227
const SYS_clock_gettime = 228
const SYS_clock_getres = 229
const SYS_clock_nanosleep = 230
const SYS_exit_group = 231
const SYS_epoll_wait = 232
const SYS_epoll_ctl = 233
const SYS_tgkill = 234
const SYS_utimes = 235
const SYS_vserver = 236
const SYS_mbind = 237
const SYS_set_mempolicy = 238
const SYS_get_mempolicy = 239
const SYS_mq_open = 240
const SYS_mq_unlink = 241
const SYS_mq_timedsend = 242
const SYS_mq_timedreceive = 243
const SYS_mq_notify = 244
const SYS_mq_getsetattr = 245
const SYS_kexec_load = 246
const SYS_waitid = 247
const SYS_add_key = 248
const SYS_request_key = 249
const SYS_keyctl = 250
const SYS_ioprio_set = 251
const SYS_ioprio_get = 252
const SYS_inotify_init = 253
const SYS_inotify_add_watch = 254
const SYS_inotify_rm_watch = 255
const SYS_migrate_pages = 256
const SYS_openat = 257
const SYS_mkdirat = 258
const SYS_mknodat = 259
const SYS_fchownat = 260
const SYS_futimesat = 261
const SYS_newfstatat = 262
const SYS_unlinkat = 263
const SYS_renameat = 264
const SYS_linkat = 265
const SYS_symlinkat = 266
const SYS_readlinkat = 267
const SYS_fchmodat = 268
const SYS_faccessat = 269
const SYS_pselect6 = 270
const SYS_ppoll = 271
const SYS_unshare = 272
const SYS_set_robust_list = 273
const SYS_get_robust_list = 274
const SYS_splice = 275
const SYS_tee = 276
const SYS_sync_file_range = 277
const SYS_vmsplice = 278
const SYS_move_pages = 279
const SYS_utimensat = 280
const SYS_epoll_pwait = 281
const SYS_signalfd = 282
const SYS_timerfd_create = 283
const SYS_eventfd = 284
const SYS_fallocate = 285
const SYS_timerfd_settime = 286
const SYS_timerfd_gettime = 287
const SYS_accept4 = 288
const SYS_signalfd4 = 289
const SYS_eventfd2 = 290
const SYS_epoll_create1 = 291
const SYS_dup3 = 292
const SYS_pipe2 = 293
const SYS_inotify_init1 = 294
const SYS_preadv = 295
const SYS_pwritev = 296
const SYS_rt_tgsigqueueinfo = 297
const SYS_perf_event_open = 298
const SYS_recvmmsg = 299
const SYS_fanotify_init = 300
const SYS_fanotify_mark = 301
const SYS_prlimit64 = 302
const SYS_name_to_handle_at = 303
const SYS_open_by_handle_at = 304
const SYS_clock_adjtime = 305
const SYS_syncfs = 306
const SYS_sendmmsg = 307
const SYS_setns = 308
const SYS_getcpu = 309
const SYS_process_vm_readv = 310
const SYS_process_vm_writev = 311
const SYS_kcmp = 312
const SYS_finit_module = 313
const SYS_sched_setattr = 314
const SYS_sched_getattr = 315
const SYS_renameat2 = 316
const SYS_seccomp = 317
const SYS_getrandom = 318
const SYS_memfd_create = 319
const SYS_kexec_file_load = 320
const SYS_bpf = 321
const SYS_execveat = 322
const SYS_userfaultfd = 323
const SYS_membarrier = 324
const SYS_mlock2 = 325
const SYS_copy_file_range = 326
const SYS_preadv2 = 327
const SYS_pwritev2 = 328
const SYS_pkey_mprotect = 329
const SYS_pkey_alloc = 330
const SYS_pkey_free = 331
const SYS_statx = 332
const SYS_io_pgetevents = 333
const SYS_rseq = 334
const SYS_uretprobe = 335
const SYS_pidfd_send_signal = 424
const SYS_io_uring_setup = 425
const SYS_io_uring_enter = 426
const SYS_io_uring_register = 427
const SYS_open_tree = 428
const SYS_move_mount = 429
const SYS_fsopen = 430
const SYS_fsconfig = 431
const SYS_fsmount = 432
const SYS_fspick = 433
const SYS_pidfd_open = 434
const SYS_clone3 = 435
const SYS_close_range = 436
const SYS_openat2 = 437
const SYS_pidfd_getfd = 438
const SYS_faccessat2 = 439
const SYS_process_madvise = 440
const SYS_epoll_pwait2 = 441
const SYS_mount_setattr = 442
const SYS_quotactl_fd = 443
const SYS_landlock_create_ruleset = 444
const SYS_landlock_add_rule = 445
const SYS_landlock_restrict_self = 446
const SYS_memfd_secret = 447
const SYS_process_mrelease = 448
const SYS_futex_waitv = 449
const SYS_set_mempolicy_home_node = 450
const SYS_cachestat = 451
const SYS_fchmodat2 = 452
const SYS_map_shadow_stack = 453
const SYS_futex_wake = 454
const SYS_futex_wait = 455
const SYS_futex_requeue = 456
const SYS_statmount = 457
const SYS_listmount = 458
const SYS_lsm_get_self_attr = 459
const SYS_lsm_set_self_attr = 460
const SYS_lsm_list_modules = 461
const SYS_mseal = 462
const SYS_setxattrat = 463
const SYS_getxattrat = 464
const SYS_listxattrat = 465
const SYS_removexattrat = 466
const SYS_open_tree_attr = 467
const SIGABRT = 6
const AT_FDCWD = -100
const S_IFDIR = 0o040000
const S_IFMT = 0o170000
const PROT_READ = 1
const PROT_WRITE = 2
const MAP_PRIVATE = 2
const MAP_ANONYMOUS = 32
const O_RDONLY = 0
const O_WRONLY = 1
const O_CREAT = 64
const O_TRUNC = 512
const SEEK_SET = 0
const SEEK_END = 2
const F_OK = 0
const SYS_read = 0
const SYS_write = 1
const SYS_open = 2
const SYS_close = 3
const SYS_stat = 4
const SYS_fstat = 5
const SYS_lstat = 6
const SYS_poll = 7
const SYS_lseek = 8
const SYS_mmap = 9
const SYS_mprotect = 10
const SYS_munmap = 11
const SYS_brk = 12
const SYS_rt_sigaction = 13
const SYS_rt_sigprocmask = 14
const SYS_rt_sigreturn = 15
const SYS_ioctl = 16
const SYS_pread64 = 17
const SYS_pwrite64 = 18
const SYS_readv = 19
const SYS_writev = 20
const SYS_access = 21
const SYS_pipe = 22
const SYS_select = 23
const SYS_sched_yield = 24
const SYS_mremap = 25
const SYS_msync = 26
const SYS_mincore = 27
const SYS_madvise = 28
const SYS_shmget = 29
const SYS_shmat = 30
const SYS_shmctl = 31
const SYS_dup = 32
const SYS_dup2 = 33
const SYS_pause = 34
const SYS_nanosleep = 35
const SYS_getitimer = 36
const SYS_alarm = 37
const SYS_setitimer = 38
const SYS_getpid = 39
const SYS_sendfile = 40
const SYS_socket = 41
const SYS_connect = 42
const SYS_accept = 43
const SYS_sendto = 44
const SYS_recvfrom = 45
const SYS_sendmsg = 46
const SYS_recvmsg = 47
const SYS_shutdown = 48
const SYS_bind = 49
const SYS_listen = 50
const SYS_getsockname = 51
const SYS_getpeername = 52
const SYS_socketpair = 53
const SYS_setsockopt = 54
const SYS_getsockopt = 55
const SYS_clone = 56
const SYS_fork = 57
const SYS_vfork = 58
const SYS_execve = 59
const SYS_exit = 60
const SYS_wait4 = 61
const SYS_kill = 62
const SYS_uname = 63
const SYS_semget = 64
const SYS_semop = 65
const SYS_semctl = 66
const SYS_shmdt = 67
const SYS_msgget = 68
const SYS_msgsnd = 69
const SYS_msgrcv = 70
const SYS_msgctl = 71
const SYS_fcntl = 72
const SYS_flock = 73
const SYS_fsync = 74
const SYS_fdatasync = 75
const SYS_truncate = 76
const SYS_ftruncate = 77
const SYS_getdents = 78
const SYS_getcwd = 79
const SYS_chdir = 80
const SYS_fchdir = 81
const SYS_rename = 82
const SYS_mkdir = 83
const SYS_rmdir = 84
const SYS_creat = 85
const SYS_link = 86
const SYS_unlink = 87
const SYS_symlink = 88
const SYS_readlink = 89
const SYS_chmod = 90
const SYS_fchmod = 91
const SYS_chown = 92
const SYS_fchown = 93
const SYS_lchown = 94
const SYS_umask = 95
const SYS_gettimeofday = 96
const SYS_getrlimit = 97
const SYS_getrusage = 98
const SYS_sysinfo = 99
const SYS_times = 100
const SYS_ptrace = 101
const SYS_getuid = 102
const SYS_syslog = 103
const SYS_getgid = 104
const SYS_setuid = 105
const SYS_setgid = 106
const SYS_geteuid = 107
const SYS_getegid = 108
const SYS_setpgid = 109
const SYS_getppid = 110
const SYS_getpgrp = 111
const SYS_setsid = 112
const SYS_setreuid = 113
const SYS_setregid = 114
const SYS_getgroups = 115
const SYS_setgroups = 116
const SYS_setresuid = 117
const SYS_getresuid = 118
const SYS_setresgid = 119
const SYS_getresgid = 120
const SYS_getpgid = 121
const SYS_setfsuid = 122
const SYS_setfsgid = 123
const SYS_getsid = 124
const SYS_capget = 125
const SYS_capset = 126
const SYS_rt_sigpending = 127
const SYS_rt_sigtimedwait = 128
const SYS_rt_sigqueueinfo = 129
const SYS_rt_sigsuspend = 130
const SYS_sigaltstack = 131
const SYS_utime = 132
const SYS_mknod = 133
const SYS_uselib = 134
const SYS_personality = 135
const SYS_ustat = 136
const SYS_statfs = 137
const SYS_fstatfs = 138
const SYS_sysfs = 139
const SYS_getpriority = 140
const SYS_setpriority = 141
const SYS_sched_setparam = 142
const SYS_sched_getparam = 143
const SYS_sched_setscheduler = 144
const SYS_sched_getscheduler = 145
const SYS_sched_get_priority_max = 146
const SYS_sched_get_priority_min = 147
const SYS_sched_rr_get_interval = 148
const SYS_mlock = 149
const SYS_munlock = 150
const SYS_mlockall = 151
const SYS_munlockall = 152
const SYS_vhangup = 153
const SYS_modify_ldt = 154
const SYS_pivot_root = 155
const SYS__sysctl = 156
const SYS_prctl = 157
const SYS_arch_prctl = 158
const SYS_adjtimex = 159
const SYS_setrlimit = 160
const SYS_chroot = 161
const SYS_sync = 162
const SYS_acct = 163
const SYS_settimeofday = 164
const SYS_mount = 165
const SYS_umount2 = 166
const SYS_swapon = 167
const SYS_swapoff = 168
const SYS_reboot = 169
const SYS_sethostname = 170
const SYS_setdomainname = 171
const SYS_iopl = 172
const SYS_ioperm = 173
const SYS_create_module = 174
const SYS_init_module = 175
const SYS_delete_module = 176
const SYS_get_kernel_syms = 177
const SYS_query_module = 178
const SYS_quotactl = 179
const SYS_nfsservctl = 180
const SYS_getpmsg = 181
const SYS_putpmsg = 182
const SYS_afs_syscall = 183
const SYS_tuxcall = 184
const SYS_security = 185
const SYS_gettid = 186
const SYS_readahead = 187
const SYS_setxattr = 188
const SYS_lsetxattr = 189
const SYS_fsetxattr = 190
const SYS_getxattr = 191
const SYS_lgetxattr = 192
const SYS_fgetxattr = 193
const SYS_listxattr = 194
const SYS_llistxattr = 195
const SYS_flistxattr = 196
const SYS_removexattr = 197
const SYS_lremovexattr = 198
const SYS_fremovexattr = 199
const SYS_tkill = 200
const SYS_time = 201
const SYS_futex = 202
const SYS_sched_setaffinity = 203
const SYS_sched_getaffinity = 204
const SYS_set_thread_area = 205
const SYS_io_setup = 206
const SYS_io_destroy = 207
const SYS_io_getevents = 208
const SYS_io_submit = 209
const SYS_io_cancel = 210
const SYS_get_thread_area = 211
const SYS_lookup_dcookie = 212
const SYS_epoll_create = 213
const SYS_epoll_ctl_old = 214
const SYS_epoll_wait_old = 215
const SYS_remap_file_pages = 216
const SYS_getdents64 = 217
const SYS_set_tid_address = 218
const SYS_restart_syscall = 219
const SYS_semtimedop = 220
const SYS_fadvise64 = 221
const SYS_timer_create = 222
const SYS_timer_settime = 223
const SYS_timer_gettime = 224
const SYS_timer_getoverrun = 225
const SYS_timer_delete = 226
const SYS_clock_settime = 227
const SYS_clock_gettime = 228
const SYS_clock_getres = 229
const SYS_clock_nanosleep = 230
const SYS_exit_group = 231
const SYS_epoll_wait = 232
const SYS_epoll_ctl = 233
const SYS_tgkill = 234
const SYS_utimes = 235
const SYS_vserver = 236
const SYS_mbind = 237
const SYS_set_mempolicy = 238
const SYS_get_mempolicy = 239
const SYS_mq_open = 240
const SYS_mq_unlink = 241
const SYS_mq_timedsend = 242
const SYS_mq_timedreceive = 243
const SYS_mq_notify = 244
const SYS_mq_getsetattr = 245
const SYS_kexec_load = 246
const SYS_waitid = 247
const SYS_add_key = 248
const SYS_request_key = 249
const SYS_keyctl = 250
const SYS_ioprio_set = 251
const SYS_ioprio_get = 252
const SYS_inotify_init = 253
const SYS_inotify_add_watch = 254
const SYS_inotify_rm_watch = 255
const SYS_migrate_pages = 256
const SYS_openat = 257
const SYS_mkdirat = 258
const SYS_mknodat = 259
const SYS_fchownat = 260
const SYS_futimesat = 261
const SYS_newfstatat = 262
const SYS_unlinkat = 263
const SYS_renameat = 264
const SYS_linkat = 265
const SYS_symlinkat = 266
const SYS_readlinkat = 267
const SYS_fchmodat = 268
const SYS_faccessat = 269
const SYS_pselect6 = 270
const SYS_ppoll = 271
const SYS_unshare = 272
const SYS_set_robust_list = 273
const SYS_get_robust_list = 274
const SYS_splice = 275
const SYS_tee = 276
const SYS_sync_file_range = 277
const SYS_vmsplice = 278
const SYS_move_pages = 279
const SYS_utimensat = 280
const SYS_epoll_pwait = 281
const SYS_signalfd = 282
const SYS_timerfd_create = 283
const SYS_eventfd = 284
const SYS_fallocate = 285
const SYS_timerfd_settime = 286
const SYS_timerfd_gettime = 287
const SYS_accept4 = 288
const SYS_signalfd4 = 289
const SYS_eventfd2 = 290
const SYS_epoll_create1 = 291
const SYS_dup3 = 292
const SYS_pipe2 = 293
const SYS_inotify_init1 = 294
const SYS_preadv = 295
const SYS_pwritev = 296
const SYS_rt_tgsigqueueinfo = 297
const SYS_perf_event_open = 298
const SYS_recvmmsg = 299
const SYS_fanotify_init = 300
const SYS_fanotify_mark = 301
const SYS_prlimit64 = 302
const SYS_name_to_handle_at = 303
const SYS_open_by_handle_at = 304
const SYS_clock_adjtime = 305
const SYS_syncfs = 306
const SYS_sendmmsg = 307
const SYS_setns = 308
const SYS_getcpu = 309
const SYS_process_vm_readv = 310
const SYS_process_vm_writev = 311
const SYS_kcmp = 312
const SYS_finit_module = 313
const SYS_sched_setattr = 314
const SYS_sched_getattr = 315
const SYS_renameat2 = 316
const SYS_seccomp = 317
const SYS_getrandom = 318
const SYS_memfd_create = 319
const SYS_kexec_file_load = 320
const SYS_bpf = 321
const SYS_execveat = 322
const SYS_userfaultfd = 323
const SYS_membarrier = 324
const SYS_mlock2 = 325
const SYS_copy_file_range = 326
const SYS_preadv2 = 327
const SYS_pwritev2 = 328
const SYS_pkey_mprotect = 329
const SYS_pkey_alloc = 330
const SYS_pkey_free = 331
const SYS_statx = 332
const SYS_io_pgetevents = 333
const SYS_rseq = 334
const SYS_uretprobe = 335
const SYS_pidfd_send_signal = 424
const SYS_io_uring_setup = 425
const SYS_io_uring_enter = 426
const SYS_io_uring_register = 427
const SYS_open_tree = 428
const SYS_move_mount = 429
const SYS_fsopen = 430
const SYS_fsconfig = 431
const SYS_fsmount = 432
const SYS_fspick = 433
const SYS_pidfd_open = 434
const SYS_clone3 = 435
const SYS_close_range = 436
const SYS_openat2 = 437
const SYS_pidfd_getfd = 438
const SYS_faccessat2 = 439
const SYS_process_madvise = 440
const SYS_epoll_pwait2 = 441
const SYS_mount_setattr = 442
const SYS_quotactl_fd = 443
const SYS_landlock_create_ruleset = 444
const SYS_landlock_add_rule = 445
const SYS_landlock_restrict_self = 446
const SYS_memfd_secret = 447
const SYS_process_mrelease = 448
const SYS_futex_waitv = 449
const SYS_set_mempolicy_home_node = 450
const SYS_cachestat = 451
const SYS_fchmodat2 = 452
const SYS_map_shadow_stack = 453
const SYS_futex_wake = 454
const SYS_futex_wait = 455
const SYS_futex_requeue = 456
const SYS_statmount = 457
const SYS_listmount = 458
const SYS_lsm_get_self_attr = 459
const SYS_lsm_set_self_attr = 460
const SYS_lsm_list_modules = 461
const SYS_mseal = 462
const SYS_setxattrat = 463
const SYS_getxattrat = 464
const SYS_listxattrat = 465
const SYS_removexattrat = 466
const SYS_open_tree_attr = 467

View File

@@ -3,6 +3,7 @@ const SOCK_STREAM = 1
const SOCK_DGRAM = 2
const SOL_SOCKET = 1
const SO_REUSEADDR = 2
const SOMAXCONN = 128
const DNS_TYPE_A = 1
const DNS_CLASS_IN = 1
@@ -25,7 +26,7 @@ func net.listen[packed_host: i64, port: i64] : i64, bool
_builtin_syscall(SYS_close, s)
return -1, false
if _builtin_syscall(SYS_listen, s, 128) < 0
if _builtin_syscall(SYS_listen, s, SOMAXCONN) < 0
_builtin_syscall(SYS_close, s)
return -1, false

View File

@@ -2,7 +2,7 @@ func panic[msg: str] : void
io.print("PANIC: ")
io.println(msg)
// for gdb backtrace
_builtin_syscall(SYS_kill, os.getpid(), 6)
_builtin_syscall(SYS_kill, os.getpid(), SIGABRT)
os.exit(1)
const MEM_BLOCK_SIZE = 32
@@ -332,7 +332,7 @@ func io.snprintf[..] : i64
return n
func io.print_sized[x: ptr, size: i64] : void
_builtin_syscall(SYS_write, 1, x, size)
_builtin_syscall(SYS_write, STDOUT, x, size)
func io.print[x: str] : void
io.print_sized(x as ptr, str.len(x))
@@ -367,7 +367,7 @@ func io.println_i64[x: i64] : void
func io.read_char[] : u8
c := 0 as u8
_builtin_syscall(SYS_read, 0, ^c, 1)
_builtin_syscall(SYS_read, STDIN, ^c, 1)
return c
func io.read_line[] : str
@@ -382,19 +382,19 @@ func io.read_line[] : str
return s
func io.file_exists[path: str] : bool
return _builtin_syscall(SYS_faccessat, -100, path, 0, 0) == 0
return _builtin_syscall(SYS_faccessat, AT_FDCWD, path, F_OK, 0) == 0
func io.is_a_directory[path: str] : bool
st := _stackalloc(256) // it has 21 mixed-size fields so ptr for now
rc := _builtin_syscall(SYS_newfstatat, -100, path, st, 0)
rc := _builtin_syscall(SYS_newfstatat, AT_FDCWD, path, st, 0)
if rc != 0
return false
return (mem.read32(st + 24) & S_IFMT) == S_IFDIR
func io.read_text_file[path: str] : str, bool
fd := _builtin_syscall(SYS_openat, -100, path, O_RDONLY, 0)
fd := _builtin_syscall(SYS_openat, AT_FDCWD, path, O_RDONLY, 0)
if fd < 0
return 0 as str, false
@@ -413,13 +413,13 @@ func io.read_text_file[path: str] : str, bool
return buffer as str, true
func io.read_binary_file[path: str] : Blob, bool
fd := _builtin_syscall(SYS_openat, -100, path, 0, 0)
fd := _builtin_syscall(SYS_openat, AT_FDCWD, path, O_RDONLY, 0)
if fd < 0
return 0 as Blob, false
buf := new* Blob
buf->size = _builtin_syscall(SYS_lseek, fd, 0, 2)
_builtin_syscall(SYS_lseek, fd, 0, 0)
buf->size = _builtin_syscall(SYS_lseek, fd, 0, SEEK_END)
_builtin_syscall(SYS_lseek, fd, 0, SEEK_SET)
buf->data = mem.alloc(buf->size)
@@ -436,7 +436,7 @@ func io.write_file[path: str, content: str] : bool
return io.write_binary_file(path, content as ptr, str.len(content))
func io.write_binary_file[path: str, content: ptr, size: i64] : bool
fd := _builtin_syscall(SYS_openat, -100, path, O_WRONLY|O_CREAT|O_TRUNC, 0o644)
fd := _builtin_syscall(SYS_openat, AT_FDCWD, path, O_WRONLY|O_CREAT|O_TRUNC, 0o644)
if fd < 0
return false
@@ -863,6 +863,13 @@ func array.free[xs: Array] : void
mem.free(xs->data)
mem.free(xs)
func array.free_with_items[xs: Array] : void
if xs->data != 0
for i in 0..xs->size
mem.free(array.nth(xs, i))
mem.free(xs->data)
mem.free(xs)
func array.pop[xs: Array] : any
if xs->size == 0
panic("array.pop on empty array")
@@ -1082,7 +1089,7 @@ func os.run_shell_command[command: str] : i64, bool
return -(st & 0x7f), true
func os.list_directory[path: str] : Array, bool
fd := _builtin_syscall(SYS_openat, -100, path, O_RDONLY, 0)
fd := _builtin_syscall(SYS_openat, AT_FDCWD, path, O_RDONLY, 0)
if fd < 0
return 0 as Array, false
@@ -1091,10 +1098,7 @@ func os.list_directory[path: str] : Array, bool
while true
n := _builtin_syscall(SYS_getdents64, fd, buf, 1024)
if n < 0
for i in 0..files->size
mem.free(array.nth(files, i))
array.free(files)
array.free_with_items(files)
_builtin_syscall(SYS_close, fd)
return 0 as Array, false
else if n == 0

View File

@@ -36,7 +36,7 @@ impl FnType {
pub struct SymbolTable {
pub functions: HashMap<String, FnType>,
pub constants: HashMap<String, u64>,
pub constants: HashMap<String, i64>,
pub structs: HashMap<String, HashMap<String, StructField>>,
}
@@ -63,24 +63,21 @@ impl SymbolTable {
pub fn register_declaration(&mut self, stmt: &Stmt) -> Result<(), ZernError> {
match stmt {
Stmt::Const { name, value } => {
Stmt::Const { name, value, neg } => {
if self.is_name_defined(&name.lexeme) {
return error!(name.loc, format!("tried to redefine '{}'", name.lexeme));
}
if value.lexeme.starts_with("0x") {
self.constants.insert(
name.lexeme.clone(),
u64::from_str_radix(&value.lexeme[2..], 16).unwrap(),
);
let mut value = if value.lexeme.starts_with("0x") {
u64::from_str_radix(&value.lexeme[2..], 16).unwrap()
} else if value.lexeme.starts_with("0o") {
self.constants.insert(
name.lexeme.clone(),
u64::from_str_radix(&value.lexeme[2..], 8).unwrap(),
);
u64::from_str_radix(&value.lexeme[2..], 8).unwrap()
} else {
self.constants
.insert(name.lexeme.clone(), value.lexeme.parse().unwrap());
value.lexeme.parse().unwrap()
} as i64;
if *neg {
value = -value;
}
self.constants.insert(name.lexeme.clone(), value);
}
Stmt::Extern(name) => {
if self.is_name_defined(&name.lexeme) {

View File

@@ -196,7 +196,7 @@ impl<'a> TypeChecker<'a> {
}
}
}
Stmt::Const { name: _, value: _ } => {
Stmt::Const { .. } => {
// handled in SymbolTable
}
Stmt::Block(stmts) => {