diff --git a/doc/examples/main.c b/doc/examples/main.c index 1aa86137..831b0d7b 100644 --- a/doc/examples/main.c +++ b/doc/examples/main.c @@ -19,15 +19,29 @@ */ #if __GNUC__ +void +exit (int code) +{ + asm ( + "movl %0,%%ebx\n\t" + "movl $1,%%eax\n\t" + "int $0x80" + : // no outputs "=" (r) + : "" (code) + ); + // not reached + exit (0); +} + void write (int fd, char const* s, int n) { int r; //syscall (SYS_write, fd, s, n)); asm ( - "mov %0, %%ebx\n\t" - "mov %1, %%ecx\n\t" - "mov %2, %%edx\n\t" + "mov %0,%%ebx\n\t" + "mov %1,%%ecx\n\t" + "mov %2,%%edx\n\t" "mov $0x4, %%eax\n\t" "int $0x80\n\t" @@ -37,20 +51,6 @@ write (int fd, char const* s, int n) ); } -void -exit (int code) -{ - asm ( - "movl %0, %%ebx\n\t" - "movl $1, %%eax\n\t" - "int $0x80" - : // no outputs "=" (r) - : "" (code) - ); - // not reached - exit (0); -} - #define STDOUT 1 typedef long size_t; @@ -84,9 +84,8 @@ int //main () main (int argc, char *argv[]) { - int i = 0; - if (argc > 1 && !strcmp (argv[1], "--help")) puts ("argc > 1 && --help\n"); puts ("Hi Mes!\n"); + if (argc > 1 && !strcmp (argv[1], "--help")) return puts ("argc > 1 && --help\n"); return 42; } diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index b1eb6cc1..a25aefca 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -163,7 +163,7 @@ (append ((ident->base locals) name) (i386:value->accu (* size value)) ;; FIXME: type: int - (i386:mem->accu) ;; FIXME: type: int + (i386:base-mem->accu) ;; FIXME: type: int (i386:push-accu) ;; hmm )))) @@ -189,6 +189,7 @@ ((p-expr (fixed ,value)) (string->number value)) ((p-expr (ident ,name)) ((ident->accu (.locals info)) name)) ((fctn-call . _) ((ast->info info) `(expr-stmt ,o))) + ((not (fctn-call . _)) ((ast->info info) o)) ((sub . _) ((ast->info info) o)) ;; FIXME: expr-stmt (_ (format (current-error-port) "SKIP expr->accu=~a\n" o) @@ -215,6 +216,47 @@ (let ((s (string-drop o (string-length prefix)))) (map byte->hex (string-split s #\space)))))) +(define (test->jump->info info) + (define (jump type) + (lambda (o) + (let* ((text (.text info)) + (info (clone info #:text '())) + (info ((ast->info info) o)) + (jump-text (lambda (body-length) + (list (lambda (f g t d) (type body-length)))))) + (lambda (body-length) + (clone info #:text + (append text + (.text info) + (jump-text body-length))))))) + (lambda (o) + (pmatch o + ((lt ,a ,b) ((jump i386:jump-nc) o)) + ((gt ,a ,b) ((jump i386:jump-nc) o)) + ((ne ,a ,b) ((jump i386:jump-nz) o)) + ((eq ,a ,b) ((jump i386:jump-nz) o)) + ((not _) ((jump i386:jump-z) o)) + ((and ,a ,b) + (let* ((text (.text info)) + (info (clone info #:text '())) + + (a-jump ((test->jump->info info) a)) + (a-text (.text (a-jump 0))) + (a-length (length (text->list a-text))) + + (b-jump ((test->jump->info info) b)) + (b-text (.text (b-jump 0))) + (b-length (length (text->list b-text)))) + + (lambda (body-length) + (clone info #:text + (append text + (.text (a-jump (+ b-length body-length))) + (.text (b-jump body-length))))))) + ((array-ref . _) ((jump i386:jump-byte-z) o)) + ((de-ref _) ((jump i386:jump-byte-z) o)) + (_ ((jump i386:jump-z) o))))) + (define (ast->info info) (lambda (o) (let ((globals (.globals info)) @@ -237,6 +279,9 @@ (stderr "SKIP: #define ~s ~s\n" name value) info) + ;; ; + ((expr-stmt) info) + ((compd-stmt (block-item-list . ,statements)) ((ast-list->info info) statements)) ((expr-stmt (fctn-call (p-expr (ident ,name)) (expr-list . ,expr-list))) @@ -251,23 +296,23 @@ #:globals globals)))) ((if ,test ,body) - (let* ((jump (pmatch test - ((lt ,a ,b) i386:jump-nc) - ((gt ,a ,b) i386:jump-nc) - (_ i386:jump-z))) - (jump-text (lambda (body-length) - (list (lambda (f g t d) (jump body-length))))) - (test-info ((ast->info info) test)) - (test+jump-info (clone test-info #:text (append (.text test-info) - (jump-text 0)))) - (text-length (length (.text test+jump-info))) + (let* ((text-length (length text)) + + (test-jump->info ((test->jump->info info) test)) + (test+jump-info (test-jump->info 0)) + (test-length (length (.text test+jump-info))) + (body-info ((ast->info test+jump-info) body)) - (body-text (list-tail (.text body-info) text-length)) - (body-length (length (text->list body-text)))) + (text-body-info (.text body-info)) + (body-text (list-tail text-body-info test-length)) + (body-length (length (text->list body-text))) + + (text+test-text (.text (test-jump->info body-length))) + (test-text (list-tail text+test-text text-length))) (clone info #:text - (append (.text test-info) - (jump-text body-length) + (append text + test-text body-text) #:globals (.globals body-info)))) @@ -311,30 +356,29 @@ #:locals locals))) ((while ,test ,body) - (let* ((jump (pmatch test - ((lt ,a ,b) i386:jump-c) - ((gt ,a ,b) i386:jump-c) - ;;(_ i386:jump-nz) - (_ i386:jump-byte-nz) ;; FIXME - )) - (jump-text (lambda (body-length) - (list (lambda (f g t d) (jump body-length))))) - - (info (clone info #:text '())) + (let* ((info (clone info #:text '())) (body-info ((ast->info info) body)) (body-text (.text body-info)) (body-length (length (text->list body-text))) - (test-info ((ast->info info) test)) - (test-text (.text test-info)) - (test-length (length (text->list test-text)))) + (test-jump->info ((test->jump->info info) test)) + (test+jump-info (test-jump->info 0)) + (test-length (length (text->list (.text test+jump-info)))) + + + (skip-body-text (list (lambda (f g t d) (i386:jump (+ 2 body-length))))) ;; FIXME: 2 + + (jump-text (list (lambda (f g t d) (i386:jump (- (+ body-length test-length)))))) + (jump-length (length (text->list jump-text))) + + (test-text (.text (test-jump->info jump-length)))) (clone info #:text (append text - (list (lambda (f g t d) (i386:jump (+ 2 body-length)))) ;; FIXME: 2 + skip-body-text body-text test-text - (jump-text (- (+ body-length test-length)))) + jump-text) #:globals (.globals body-info)))) ((labeled-stmt (ident ,label) ,statement) @@ -361,15 +405,17 @@ (clone info #:text (append text (list (lambda (f g t d) - (append (i386:value->accu value) - (i386:accu-zero?)))))))) + (append + (i386:value->accu value) + (i386:accu-zero?)))))))) ((de-ref (p-expr (ident ,name))) (clone info #:text (append text (list (lambda (f g t d) - (append (i386:local->accu (assoc-ref locals name)) - (i386:byte-mem->accu))))))) + (append + (i386:local->accu (assoc-ref locals name)) + (i386:byte-mem->accu))))))) ((fctn-call . ,call) (let ((info ((ast->info info) `(expr-stmt ,o)))) @@ -379,6 +425,14 @@ (i386:accu-zero?))))))) ;; FIXME + ;;((post-inc ,expr) ((ast->info info) `(expr-stmt ,o))) + ((post-inc (p-expr (ident ,name))) + (clone info #:text + (append text (list (lambda (f g t d) + (append + (i386:local->accu (assoc-ref locals name)) + (i386:local-add (assoc-ref locals name) 1) + (i386:accu-zero?))))))) ((post-inc ,expr) ((ast->info info) `(expr-stmt ,o))) ((post-dec ,expr) ((ast->info info) `(expr-stmt ,o))) ((pre-inc ,expr) ((ast->info info) `(expr-stmt ,o))) @@ -388,73 +442,46 @@ ((expr-stmt (post-inc (p-expr (ident ,name)))) (clone info #:text (append text (list (lambda (f g t d) - (append (i386:local->accu (assoc-ref locals name)) - (i386:local-add (assoc-ref locals name) 1) - (i386:accu-zero?))))))) + (i386:local-add (assoc-ref locals name) 1)))))) ;; ++i ((expr-stmt (pre-inc (p-expr (ident ,name)))) (clone info #:text (append text (list (lambda (f g t d) - (append (i386:local-add (assoc-ref locals name) 1) - (i386:local->accu (assoc-ref locals name)) - (i386:accu-zero?))))))) + (append + (i386:local-add (assoc-ref locals name) 1) + (i386:local->accu (assoc-ref locals name)) + (i386:accu-zero?))))))) ;; i-- ((expr-stmt (post-dec (p-expr (ident ,name)))) (clone info #:text (append text (list (lambda (f g t d) - (append (i386:local->accu (assoc-ref locals name)) - (i386:local-add (assoc-ref locals name) -1) - (i386:accu-zero?))))))) + (append + (i386:local->accu (assoc-ref locals name)) + (i386:local-add (assoc-ref locals name) -1) + (i386:accu-zero?))))))) ;; --i ((expr-stmt (pre-dec (p-expr (ident ,name)))) (clone info #:text (append text (list (lambda (f g t d) - (append (i386:local-add (assoc-ref locals name) -1) - (i386:local->accu (assoc-ref locals name)) - (i386:accu-zero?))))))) + (append + (i386:local-add (assoc-ref locals name) -1) + (i386:local->accu (assoc-ref locals name)) + (i386:accu-zero?))))))) ((not ,expr) (let* ((test-info ((ast->info info) expr))) (clone info #:text (append (.text test-info) (list (lambda (f g t d) - (i386:xor-zf)))) + (append + (i386:accu-not) + (i386:accu-zero?))))) #:globals (.globals test-info)))) - ((and ,a ,b) - (let* ((info (clone info #:text '())) - (a-info ((ast->info info) a)) - (a-text (.text a-info)) - (a-length (length (text->list a-text))) - - (b-info ((ast->info info) b)) - (b-text (.text b-info)) - (b-length (length (text->list b-text)))) - - (clone info #:text - (append text - a-text - (list (lambda (f g t d) (i386:jump-byte-z (+ b-length - 2)))) ;; FIXME: need jump after last test - b-text)))) - - ;; FIXME and, gt - ((eq (de-ref (p-expr (ident ,a))) (de-ref (p-expr (ident ,b)))) - (clone info #:text - (append text - (list (lambda (f g t d) - (append - (append (i386:local->accu (assoc-ref locals a)) - (i386:byte-mem->base) - (i386:local->accu (assoc-ref locals b)) - (i386:byte-mem->accu) - (i386:byte-test-base)))))))) - - ((gt (p-expr (ident ,a)) (p-expr (fixed ,b))) - ;; (stderr "GT: ~a > ~a\n" a b) + ((eq (p-expr (ident ,a)) (p-expr (fixed ,b))) (let ((b (string->number b))) (clone info #:text (append text @@ -464,9 +491,60 @@ (i386:value->accu b) (i386:sub-base)))))))) + ((eq (fctn-call . ,call) (p-expr (fixed ,b))) + (let ((b (string->number b)) + (info ((ast->info info) `(expr-stmt (fctn-call ,@call))))) + (clone info #:text + (append text + (.text info) + (list (lambda (f g t d) + (append + (i386:value->base b) + (i386:sub-base)))))))) + + ((eq (fctn-call . ,call) (p-expr (ident ,b))) + (let ((info ((ast->info info) `(expr-stmt (fctn-call ,@call))))) + (clone info #:text + (append text + (.text info) + (list (lambda (f g t d) + (append + (i386:local->base b) + (i386:sub-base)))))))) + + ((eq (de-ref (p-expr (ident ,a))) (de-ref (p-expr (ident ,b)))) + (clone info #:text + (append text + (list (lambda (f g t d) + (append + (i386:local->accu (assoc-ref locals a)) + (i386:byte-mem->base) + (i386:local->accu (assoc-ref locals b)) + (i386:byte-mem->accu) + (i386:byte-test-base))))))) + + ((gt (p-expr (ident ,a)) (p-expr (fixed ,b))) + (let ((b (string->number b))) + (clone info #:text + (append text + (list (lambda (f g t d) + (append + (i386:local->base (assoc-ref locals a)) + (i386:value->accu b) + (i386:sub-base)))))))) + + ((gt (p-expr (ident ,a)) (neg (p-expr (fixed ,b)))) + (let ((b (- (string->number b)))) + (clone info #:text + (append text + (list (lambda (f g t d) + (append + (i386:local->base (assoc-ref locals a)) + (i386:value->accu b) + (i386:sub-base)))))))) + - ((eq (p-expr (ident ,a)) (p-expr (fixed ,b))) - ;;(stderr "EQ: ~a > ~a\n" a b) + ((ne (p-expr (ident ,a)) (p-expr (fixed ,b))) (let ((b (string->number b))) (clone info #:text (append text @@ -476,21 +554,43 @@ (i386:value->accu b) (i386:sub-base) (i386:xor-zf)))))))) - - ((ne (p-expr (ident ,a)) (p-expr (fixed ,b))) - ;;(stderr "NE: ~a > ~a\n" a b) - (let ((b (string->number b))) + ((ne (fctn-call . ,call) (p-expr (fixed ,b))) + (let ((b (string->number b)) + (info ((ast->info info) `(expr-stmt (fctn-call ,@call))))) + (clone info #:text + (append text + (.text info) + (list (lambda (f g t d) + (append + (i386:value->base b) + (i386:sub-base) + (i386:xor-zf)))))))) + + ((ne (fctn-call . ,call) (p-expr (ident ,b))) + (let ((info ((ast->info info) `(expr-stmt (fctn-call ,@call))))) + (clone info #:text + (append text + (.text info) + (list (lambda (f g t d) + (append + (i386:local->base b) + (i386:sub-base) + (i386:xor-zf)))))))) + + ((ne (de-ref (p-expr (ident ,a))) (de-ref (p-expr (ident ,b)))) (clone info #:text (append text (list (lambda (f g t d) - (append - (i386:local->base (assoc-ref locals a)) - (i386:value->accu b) - (i386:sub-base)))))))) - + (append + (i386:local->accu (assoc-ref locals a)) + (i386:byte-mem->base) + (i386:local->accu (assoc-ref locals b)) + (i386:byte-mem->accu) + (i386:byte-test-base) + (i386:xor-zf))))))) + ((lt (p-expr (ident ,a)) (p-expr (fixed ,b))) - ;;(stderr "LT: ~a < ~a\n" a b) (let ((b (string->number b))) (clone info #:text (append text @@ -504,11 +604,12 @@ (clone info #:text (append text (list (lambda (f g t d) - (append (i386:local->accu (assoc-ref locals a)) - (i386:byte-mem->base) - (i386:local->accu (assoc-ref locals b)) - (i386:byte-mem->accu) - (i386:byte-sub-base))))))) + (append + (i386:local->accu (assoc-ref locals a)) + (i386:byte-mem->base) + (i386:local->accu (assoc-ref locals b)) + (i386:byte-mem->accu) + (i386:byte-sub-base))))))) ((array-ref (p-expr (fixed ,value)) (p-expr (ident ,name))) (let ((value (string->number value))) @@ -517,7 +618,7 @@ (append ((ident->base locals) name) (i386:value->accu value) - (i386:byte-mem->accu)))))))) ; FIXME: type: char + (i386:byte-base-mem->accu)))))))) ; FIXME: type: char ((array-ref (p-expr (ident ,name)) (p-expr (ident ,index))) (clone info #:text @@ -525,7 +626,7 @@ (append ((ident->base locals) name) ((ident->accu locals) index) - (i386:byte-mem->accu))))))) ; FIXME: type: char + (i386:byte-base-mem->accu))))))) ; FIXME: type: char ((return ,expr) (let ((accu ((expr->accu info) expr))) @@ -550,13 +651,27 @@ ;; int i = argc; ((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ident ,name) (initzer (p-expr (ident ,local)))))) (let ((locals (add-local name))) - (clone info #:text - (append text (list (lambda (f g t d) - (append - ((ident->accu locals) local) - ((accu->ident locals) name))))) + (clone info #:text + (append text (list (lambda (f g t d) + (append + ((ident->accu locals) local) + ((accu->ident locals) name))))) #:locals locals))) + ;; char *p = "t.c"; + ;;(decl (decl-spec-list (type-spec (fixed-type "char"))) (init-declr-list (init-declr (ptr-declr (pointer) (ident "p")) (initzer (p-expr (string "t.c\n")))))) + ((decl (decl-spec-list (type-spec (fixed-type _))) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name)) (initzer (p-expr (string ,value)))))) + (let ((locals (add-local name)) + (globals (append globals (list (string->global value))))) + (clone info #:text + (append text + (list (lambda (f g t d) + (append + (i386:global->accu (+ (data-offset value g) d)) + ((accu->ident locals) name))))) + #:locals locals + #:globals globals))) + ;; SCM i = argc; ((decl (decl-spec-list (type-spec (typename ,type))) (init-declr-list (init-declr (ident ,name) (initzer (p-expr (ident ,local)))))) (let ((locals (add-local name))) diff --git a/module/mes/libc-i386.mes b/module/mes/libc-i386.mes index b6105208..77743793 100644 --- a/module/mes/libc-i386.mes +++ b/module/mes/libc-i386.mes @@ -34,6 +34,9 @@ (define (i386:ref-global o) `(#x68 ,@(int->bv32 o))) ; push $0x +(define (i386:global->accu o) + `(#xb8 ,@(int->bv32 o))) ; mov $<>,%eax + (define (i386:ref-local n) (or n rl) `(#xff #x75 ,(- 0 (* 4 n)))) ; pushl 0x(%ebp) @@ -82,14 +85,17 @@ (or n lb) `(#x8b #x55 ,(- 0 (* 4 n)))) ; mov -<0xn>(%ebp),%edx -(define (i386:byte-mem->accu) +(define (i386:byte-base-mem->accu) '(#x01 #xd0 ; add %edx,%eax #x0f #xb6 #x00)) ; movzbl (%eax),%eax +(define (i386:byte-mem->accu) + '(#x0f #xb6 #x00)) ; movzbl (%eax),%eax + (define (i386:byte-mem->base) '(#x0f #xb6 #x10)) ; movzbl (%eax),%edx -(define (i386:mem->accu) +(define (i386:base-mem->accu) '(#x01 #xd0 ; add %edx,%eax #x8b #x00)) ; mov (%eax),%eax @@ -128,12 +134,19 @@ #x83 #xc4 ,(* n 4) ; add $00,%esp ))) +(define (i386:accu-not) + `(#x0f #x94 #xc0 ; sete %al + #x0f #xb6 #xc0)) ; movzbl %al,%eax + +(define (i386:xor-accu v) + `(#x35 ,@(int->bv32 v))) ;xor $0xff,%eax + (define (i386:xor-zf) '(#x9f ; lahf #x80 #xf4 #x40 ; xor $0x40,%ah #x9e)) ; sahf -(define (i386:test-accu) +(define (i386:accu-test) '(#x85 #xc0)) ; test %eax,%eax (define (i386:jump n) @@ -211,3 +224,45 @@ #xc9 ; leave #xc3 ; ret )) + +#! +08048121 : + 8048121: 55 push %ebp + 8048122: 89 e5 mov %esp,%ebp + 8048124: 83 ec 10 sub $0x10,%esp + 8048127: eb 08 jmp 8048131 + + + 8048129: 83 45 08 01 addl $0x1,0x8(%ebp) + 804812d: 83 45 0c 01 addl $0x1,0xc(%ebp) + + *a + 8048131: 8b 45 08 mov 0x8(%ebp),%eax + 8048134: 0f b6 00 movzbl (%eax),%eax + 8048137: 84 c0 test %al,%al + 8048139: 74 08 je 8048143 + + *b + 804813b: 8b 45 0c mov 0xc(%ebp),%eax + 804813e: 0f b6 00 movzbl (%eax),%eax + 8048141: 84 c0 test %al,%al + 8048143: 74 10 je 8048155 + + *a == *b + 8048145: 8b 45 08 mov 0x8(%ebp),%eax + 8048148: 0f b6 10 movzbl (%eax),%edx + 804814b: 8b 45 0c mov 0xc(%ebp),%eax + 804814e: 0f b6 00 movzbl (%eax),%eax + 8048151: 38 c2 cmp %al,%dl + 8048153: 84 c0 test %al,%al + 8048155: 75 d2 jne 8048129 + + + 8048157: 8b 45 08 mov 0x8(%ebp),%eax + 804815a: 0f b6 10 movzbl (%eax),%edx + 804815d: 8b 45 0c mov 0xc(%ebp),%eax + 8048160: 0f b6 00 movzbl (%eax),%eax + 8048163: 28 d0 sub %dl,%al + 8048165: c9 leave + 8048166: c3 ret +!# diff --git a/module/mes/libc-i386.scm b/module/mes/libc-i386.scm index 67ce55fc..02c521bb 100644 --- a/module/mes/libc-i386.scm +++ b/module/mes/libc-i386.scm @@ -28,11 +28,15 @@ #:use-module (srfi srfi-1) #:use-module (mes elf) #:export ( + i386:accu-not i386:accu->local i386:accu-non-zero? + i386:accu-test i386:accu-zero? i386:base-sub + i386:base-mem->accu i386:byte-base-sub + i386:byte-base-mem->accu i386:byte-mem->accu i386:byte-mem->base i386:byte-test-base @@ -41,6 +45,7 @@ i386:formal i386:function-locals i386:function-preamble + i386:global->accu i386:jump i386:jump i386:jump-byte-nz @@ -57,18 +62,17 @@ i386:local-add i386:local-assign i386:local-test - i386:mem->accu i386:push-accu i386:ref-global i386:ref-local i386:ret i386:ret-local i386:sub-base - i386:test-accu i386:test-base i386:test-jump-z i386:value->accu i386:value->base + i386:xor-accu i386:xor-zf ;; libc diff --git a/scaffold/micro-mes.c b/scaffold/micro-mes.c index 528f09a7..8e5d8e13 100644 --- a/scaffold/micro-mes.c +++ b/scaffold/micro-mes.c @@ -41,7 +41,7 @@ void exit (int code) { asm ( - "movl $0,%%ebx\n\t" + "movl %0,%%ebx\n\t" "movl $1,%%eax\n\t" "int $0x80" : // no outputs "=" (r) @@ -51,6 +51,12 @@ exit (int code) exit (0); } +char const* +getenv (char const* p) +{ + return 0; +} + int open (char const *s, int mode) { @@ -74,7 +80,8 @@ write (int fd, char const* s, int n) "mov %0,%%ebx\n\t" "mov %1,%%ecx\n\t" "mov %2,%%edx\n\t" - "mov $0x4,%%eax\n\t" + + "mov $0x4, %%eax\n\t" "int $0x80\n\t" : // no outputs "=" (r) : "" (fd), "" (s), "" (n) @@ -151,7 +158,6 @@ eputs (char const* s) return 0; } -#if __GNUC__ char const* itoa (int x) { @@ -174,7 +180,6 @@ itoa (int x) return p+1; } -#endif void assert_fail (char* s) @@ -187,14 +192,10 @@ assert_fail (char* s) #endif #define assert(x) ((x) ? (void)0 : assert_fail(#x)) -#define false 0 -#define true 1 -typedef int bool; - typedef int SCM; #if __GNUC__ -bool g_debug = false; +int g_debug = 0; #endif int g_free = 0; @@ -222,18 +223,8 @@ bload_env (SCM a) ///((internal)) int main (int argc, char *argv[]) { - puts ("arg0="); - puts (argv[0]); - if (argc > 1) - { - puts ("\narg1="); - puts (argv[1]); - if (!strcmp (argv[1], "--help")) /*return*/ puts ("XXUsage: mes [--dump|--load] < FILE"); - } - puts ("\n"); - #if __GNUC__ - //g_debug = getenv ("MES_DEBUG"); + g_debug = (int)getenv ("MES_DEBUG"); #endif //if (getenv ("MES_ARENA")) ARENA_SIZE = atoi (getenv ("MES_ARENA")); @@ -246,8 +237,8 @@ main (int argc, char *argv[]) #endif #if MES_MINI - SCM program = bload_env (r0); puts ("Hello micro-mes!\n"); + SCM program = bload_env (r0); #else SCM program = (argc > 1 && !strcmp (argv[1], "--load")) ? bload_env (r0) : load_env (r0); diff --git a/scaffold/t.c b/scaffold/t.c index cf4aef4e..ce529e3e 100644 --- a/scaffold/t.c +++ b/scaffold/t.c @@ -78,18 +78,27 @@ strcmp (char const* a, char const* b) while (*a && *b && *a == *b) {a++;b++;} return *a - *b; } -int test (); +int test (char *p); #endif int main (int argc, char *argv[]) { + char *p = "t.c\n"; puts ("t.c\n"); - return test (); + + if (argc > 1 && !strcmp (argv[1], "--help")) return 1; + puts ("t: if (argc > 1 && !strcmp (argv[1], \"--help\")\n"); + + // FIXME mescc?! + if (argc > 1) if (!strcmp (argv[1], "--help")) return 1; + + return test (p); + return 22; } int -test () +test (char *p) { int f = 0; int t = 1; @@ -107,9 +116,21 @@ test () puts ("t: if (one < 0)\n"); if (one < 0) return 1; - puts ("t: stlrlen (\"\")\n"); + puts ("t: if (strlen (\"\"))\n"); if (strlen ("")) return 1; + puts ("t: if (strlen (p) != 4)\n"); + if (strlen (p) != 4) return 1; + + puts ("t: if (!strlen (\".\"))\n"); + if (!strlen (".")) return 1; + + puts ("t: if (strcmp (p, \"foo\"))\n"); + if (!strcmp (p, "foo")) return 1; + + puts ("t: if (strcmp (p, \"t.c\\n\"))\n"); + if (strcmp (p, "t.c\n")) return 1; + puts ("t: if (!1)\n"); if (!1) return 1; @@ -122,6 +143,12 @@ test () puts ("t: if (1 && 0)\n"); if (1 && 0) return 1; + puts ("t: if (!t && f)\n"); + if (!t && f) return 1; + + puts ("t: if (t && !one)\n"); + if (t && !one) return 1; + int i=0; puts ("t: if (i++)\n"); if (i++) return 1; @@ -154,6 +181,20 @@ test () return 1; ok4: + puts ("t: if (strlen (p) == 4)\n"); + if (strlen (p) == 4) goto ok40; + ok40: + + puts ("t: if (!strcmp (p, \"t.c\\n\"))\n"); + if (!strcmp (p, "t.c\n")) goto ok41; + return 1; + ok41: + + puts ("t: if (strcmp (p, \"foo\"))\n"); + if (strcmp (p, "foo")) goto ok42; + return 1; + ok42: + puts ("t: if (!0)\n"); if (!0) goto ok5; return 1;