Compare commits

...

8 Commits

Author SHA1 Message Date
Jan Nieuwenhuizen ad90a067e4
mescc: Recognize U integer suffix.
* module/mescc/compile.scm (cstring->int): Recognize U integer
suffix.  Thanks, Peter de Wachter!
2018-10-19 23:31:30 +02:00
Peter De Wachter c494d96dea
mescc: Add INTn_MIN/MAX defines to stdint.h.
* include/stdint.h: Add INTn_MIN/MAX defines.  Move integere size
defines from limits.h
* include/limits.h: Include it.
2018-10-16 20:40:41 +02:00
Peter De Wachter c08d2987b4
mescc: Allow superfluous parentheses in function declarations.
E.g.:  int (f)();
This is obscure but valid C.  It occurs in the csmith headers (thanks
to macro shenanigans).

* module/mescc/compile.scm (fctn-defn:get-name,
fctn-defn:get-statement): Allow superfluous parentheses in function declarations.
2018-10-16 20:40:40 +02:00
Peter De Wachter 673021b78b
mescc: Implement unary plus operator.
* module/mescc/compile.scm (ast->type, expr->register,
try-expr->number):): Implement unary plus operator.
2018-10-16 20:40:38 +02:00
Peter De Wachter bb1f5352e6
mescc: Add missing assembly defines.
* lib/x86-mes/x86.M1: Add missing assembly defines.
* lib/x86_64-mes/x86_64.M1: Likewise.
2018-10-16 20:40:37 +02:00
Peter De Wachter 6b5338415d
mescc: Delete duplicate assembly defines.
* lib/x86-mes/x86.M1: Delete duplicate assembly defines.
* lib/x86_64-mes/x86_64.M1: Likewise.
2018-10-16 20:40:36 +02:00
Peter De Wachter ab76bafb08
mescc: Exit with non-zero exit code when subprocess fails.
system* returns the result of waitpid. So, suppose that a subprocess
fails with exit code 1. Then the waitpid return value will be 256.
And exit(256) is equivalent to exit(0).

Modified-by: Jan Nieuwenhuizen <janneke@gnu.org>

* mes/module/mes/posix.mes (status:exit-val): New function.
* module/mescc/mescc.scm (assert-system*): Use it.
2018-10-16 20:40:35 +02:00
Jan Nieuwenhuizen 991e21f7eb
mescc: Oops typo.
* module/mescc/M1.scm (hex2:immediate8): Typo.
2018-10-12 09:37:10 +02:00
8 changed files with 57 additions and 18 deletions

View File

@ -29,19 +29,12 @@
#else // ! WITH_GLIBC
#define CHAR_BIT 8
#define UCHAR_MAX 255
#define CHAR_MAX 255
#define UINT_MAX 4294967295U
#define ULONG_MAX 4294967295U
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#include <stdint.h>
#define MB_CUR_MAX 1
#define LONG_MIN -2147483648
#define LONG_MAX 2147483647
#define _POSIX_OPEN_MAX 16
#define PATH_MAX 512
#define NAME_MAX 255
#define PATH_MAX 512
#define _POSIX_OPEN_MAX 16
#endif // ! WITH_GLIBC

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2018 Peter De Wachter <pdewacht@gmail.com>
*
* This file is part of GNU Mes.
*
@ -80,6 +81,40 @@ typedef unsigned* uintptr_t;
typedef long ptrdiff_t;
#endif
#define CHAR_BIT 8
#define CHAR_MAX 255
#define UCHAR_MAX 255
#define INT8_MAX 127
#define INT8_MIN (-INT8_MAX-1)
#define UINT8_MAX 255
#define INT16_MAX 32767
#define INT16_MIN (-INT16_MAX-1)
#define UINT16_MAX 65535
#define INT32_MAX 2147483647
#define INT32_MIN (-INT32_MAX-1)
#define UINT32_MAX 4294967295U
#define INT64_MAX 9223372036854775807LL
#define INT64_MIN (-INT64_MAX-1)
#define UINT64_MAX 18446744073709551615ULL
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#if __i386__
#define LONG_MIN INT_MIN
#define LONG_MAX INT_MAX
#define UINT_MAX UINT32_MAX
#define ULONG_MAX UINT32_MAX
#elif __x86_64__
#define LONG_MIN INT64_MIN
#define LONG_MAX INT64_MAX
#define UINT_MAX UINT32_MAX
#define ULONG_MAX UINT64_MAX
#endif
#endif // ! WITH_GLIBC
#endif // __MES_STDINT_H

View File

@ -129,14 +129,15 @@ DEFINE mov____0x8(%ebp),%edx 8b55
DEFINE mov____0x8(%ebp),%esi 8b75
DEFINE mov____0x8(%ebp),%esp 8b65
DEFINE movb___%al,0x32 a2
DEFINE movb___%bl,0x32 881d
DEFINE movsbl_%al,%eax 0fbec0
DEFINE movsbl_%bl,%ebx 0fbedb
DEFINE movswl_%ax,%eax 0fbfc0
DEFINE movswl_%bx,%ebx 0fbfdb
DEFINE movw___%ax,0x32 66a3
DEFINE movw___%bx,0x32 66891d
DEFINE movzbl_%al,%eax 0fb6c0
DEFINE movzbl_%bl,%ebx 0fb6db
DEFINE movzbl_%bl,%ebx 0fb6db
DEFINE movzbl_(%eax),%eax 0fb600
DEFINE movzbl_(%ebx),%ebx 0fb61b
DEFINE movzbl_0x32(%eax),%eax 0fb680
@ -203,7 +204,6 @@ DEFINE test___%eax,%eax 85c0
DEFINE test___%ebx,%ebx 85db
DEFINE xchg___%eax,%ebx 93
DEFINE xchg___%eax,(%esp) 870424
DEFINE xchg___%eax,(%esp) 870424
DEFINE xchg___%ebx,(%esp) 871c24
DEFINE xor____$i32,%eax 35
DEFINE xor____$i8,%ah 80f4

View File

@ -1,5 +1,6 @@
### GNU Mes --- Maxwell Equations of Software
### Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
### Copyright © 2018 Peter De Wachter <pdewacht@gmail.com>
###
### This file is part of GNU Mes.
###
@ -54,6 +55,7 @@ DEFINE call___*%rax ffd0
DEFINE call___*%rdi ffd7
DEFINE cmp____$i32,%rax 483d
DEFINE cmp____$i8,%rax 4883f8
DEFINE cmp____$i8,%rdi 4883ff
DEFINE cmp____%r15,%rax 4c39f8
DEFINE cmp____%r15,%rdi 4c39ff
DEFINE cqto 4899
@ -78,8 +80,6 @@ DEFINE mov____$i32,%rax 48c7c0
DEFINE mov____$i32,%rdi 48c7c7
DEFINE mov____$i32,0x8(%rbp) c745
DEFINE mov____$i64,%r15 49bf
DEFINE mov____$i64,%rax 48a1
DEFINE mov____$i64,%rax 48b8
DEFINE mov____$i64,%rax 48b8
DEFINE mov____$i64,%rdi 48bf
DEFINE mov____%al,(%rdi) 8807
@ -92,7 +92,6 @@ DEFINE mov____%eax,%rax 89c0
DEFINE mov____%eax,(%rdi) 8907
DEFINE mov____%eax,0x32(%rbp) 8985
DEFINE mov____%eax,0x8(%rbp) 8945
DEFINE mov____%eax,0x8(%rbp) 8945
DEFINE mov____%edi,%edi 89ff
DEFINE mov____%edi,%rdi 89ff
DEFINE mov____%edi,0x32(%rbp) 89bd

View File

@ -57,3 +57,6 @@
(define (waitpid pid . options)
(let ((options (if (null? options) 0 (car options))))
(core:waitpid pid options)))
(define (status:exit-val status)
(ash status -8))

View File

@ -87,7 +87,7 @@
(dec->hex (quotient o #x100000000))))
(string-append "%" (number->string (dec->hex (modulo o #x100000000)))
" %" (if (< o 0) "-1"
(number->string (dec->hex (quoteint o #x100000000)))))))
(number->string (dec->hex (quotient o #x100000000)))))))
(define* (display-join o #:optional (sep ""))
(let loop ((o o))

View File

@ -209,6 +209,7 @@
((mod ,a ,b) (ast->type a info))
((mul ,a ,b) (ast->type a info))
((not ,a) (ast->type a info))
((pos ,a) (ast->type a info))
((neg ,a) (ast->type a info))
((eq ,a ,b) (ast->type a info))
((ge ,a ,b) (ast->type a info))
@ -1218,6 +1219,9 @@
(info (append-text info (wrap-as (as info 'r-negate)))))
(append-text info (wrap-as (as info 'test-r))))) ;; hmm, use ast->info?
((pos ,expr)
(expr->register expr info))
((neg ,expr)
(let* ((info (expr->register expr info))
(info (allocate-register info))
@ -1542,6 +1546,7 @@
(define (cstring->int o)
(let ((o (cond ((string-suffix? "ULL" o) (string-drop-right o 3))
((string-suffix? "UL" o) (string-drop-right o 2))
((string-suffix? "U" o) (string-drop-right o 1))
((string-suffix? "LL" o) (string-drop-right o 2))
((string-suffix? "L" o) (string-drop-right o 1))
(else o))))
@ -1559,6 +1564,8 @@
(pmatch o
((fixed ,a) (cstring->int a))
((p-expr ,expr) (expr->number info expr))
((pos ,a)
(expr->number info a))
((neg ,a)
(- (expr->number info a)))
((add ,a ,b)
@ -2536,6 +2543,7 @@
(define (fctn-defn:get-name o)
(pmatch o
((_ (ftn-declr (ident ,name) _) _) name)
((_ (ftn-declr (scope (ident ,name)) _) _) name)
((_ (ptr-declr (pointer . _) (ftn-declr (ident ,name) _)) _) name)
(_ (error "fctn-defn:get-name not supported:" o))))
@ -2609,6 +2617,7 @@
(define (fctn-defn:get-statement o)
(pmatch o
((_ (ftn-declr (ident _) _) ,statement) statement)
((_ (ftn-declr (scope (ident _)) _) ,statement) statement)
((_ (ptr-declr (pointer . _) (ftn-declr (ident _) . _)) ,statement) statement)
(_ (error "fctn-defn:get-statement: not supported: " o))))

View File

@ -281,7 +281,7 @@
(let ((status (apply system* args)))
(when (not (zero? status))
(stderr "mescc: failed: ~a\n" (string-join args))
(exit status))
(exit (status:exit-val status)))
status))
(define (multi-opt option-name) (lambda (o) (and (eq? (car o) option-name) (cdr o))))