test: Split-up Mescc scaffold test.
* make.scm (check-scaffold, check-scaffold-tests): New targets. * mlibc/include/00-test.i: New file. * mlibc/include/30-test.i: New file. * mlibc/mini-libc-mes.c (puts): New function. * scaffold/tests/00-exit-0.c: : New file. * scaffold/tests/01-return-0.c: : New file. * scaffold/tests/02-return-1.c: : New file. * scaffold/tests/03-call.c: : New file. * scaffold/tests/04-call-0.c: : New file. * scaffold/tests/05-call-1.c: : New file. * scaffold/tests/06-call-!1.c: : New file. * scaffold/tests/10-if-0.c: : New file. * scaffold/tests/11-if-1.c: : New file. * scaffold/tests/12-if-==.c: : New file. * scaffold/tests/13-if-!=.c: : New file. * scaffold/tests/14-if-goto.c: : New file. * scaffold/tests/15-if-!f.c: : New file. * scaffold/tests/16-if-t.c: : New file. * scaffold/tests/20-while.c: : New file. * scaffold/tests/21-char[].c: : New file. * scaffold/tests/22-while-char[].c: : New file. * scaffold/tests/30-strlen.c: : New file. * scaffold/tests/31-eputs.c: : New file. * scaffold/tests/32-compare.c: : New file. * scaffold/tests/33-and-or.c: : New file. * scaffold/tests/34-pre-post.c: : New file. * scaffold/tests/35-compare-char.c: : New file. * scaffold/tests/36-compare-arithmetic.c: : New file. * scaffold/tests/37-compare-assign.c: : New file. * scaffold/tests/38-compare-call.c: : New file. * scaffold/tests/40-if-else.c: : New file. * scaffold/tests/41-?.c: : New file. * scaffold/tests/42-goto-label.c: : New file. * scaffold/tests/43-for-do-while.c: : New file. * scaffold/tests/44-switch.c: : New file. * scaffold/tests/45-void-call.c: : New file. * scaffold/tests/50-assert.c: : New file. * scaffold/tests/51-strcmp.c: : New file. * scaffold/tests/52-itoa.c: : New file. * scaffold/tests/53-strcpy.c: : New file. * scaffold/tests/54-argv.c: : New file. * scaffold/tests/60-math.c: : New file. * scaffold/tests/61-array.c: : New file. * scaffold/tests/63-struct-cell.c: : New file. * scaffold/tests/64-make-cell.c: : New file. * scaffold/tests/65-read.c: : New file. * scaffold/tests/66-struct-array.c: : New file. * scaffold/t.c: Remove. * scaffold/t-tcc.c: Remove.
This commit is contained in:
parent
637c40aeb9
commit
64db2eaf7d
|
@ -42,6 +42,9 @@
|
||||||
#:export (build
|
#:export (build
|
||||||
check
|
check
|
||||||
clean
|
clean
|
||||||
|
group
|
||||||
|
target-prefix?
|
||||||
|
check-target?
|
||||||
|
|
||||||
cpp.mescc
|
cpp.mescc
|
||||||
compile.mescc
|
compile.mescc
|
||||||
|
@ -128,7 +131,7 @@
|
||||||
(gulp-pipe* run))
|
(gulp-pipe* run))
|
||||||
(let ((status (if (string? result) 0
|
(let ((status (if (string? result) 0
|
||||||
(or (status:term-sig result) (status:exit-val result)))))
|
(or (status:term-sig result) (status:exit-val result)))))
|
||||||
(if output (with-output-to-file log (lambda _ (display output))))
|
(if (not (string-null? output)) (with-output-to-file log (lambda _ (display output))))
|
||||||
(store #:add-file log)
|
(store #:add-file log)
|
||||||
(format (current-error-port) "\t[~a]\n"
|
(format (current-error-port) "\t[~a]\n"
|
||||||
(if (or (and signal (= status signal))
|
(if (or (and signal (= status signal))
|
||||||
|
@ -208,10 +211,14 @@
|
||||||
|
|
||||||
(define* (check name #:key (exit 0) (signal #f) (dependencies '()))
|
(define* (check name #:key (exit 0) (signal #f) (dependencies '()))
|
||||||
(target (file-name (string-append "check-" name))
|
(target (file-name (string-append "check-" name))
|
||||||
(method method-check)
|
(method method-check)
|
||||||
(inputs (cons (get-target name) dependencies))
|
(inputs (cons (get-target name) dependencies))
|
||||||
(exit exit)
|
(exit exit)
|
||||||
(signal signal)))
|
(signal signal)))
|
||||||
|
|
||||||
|
(define* (group name #:key (dependencies '()))
|
||||||
|
(target (file-name name)
|
||||||
|
(inputs (map get-target dependencies))))
|
||||||
|
|
||||||
(define (target->input-files o)
|
(define (target->input-files o)
|
||||||
(let ((inputs (target-inputs o)))
|
(let ((inputs (target-inputs o)))
|
||||||
|
@ -474,9 +481,15 @@
|
||||||
;;(inputs (list snarf-target))
|
;;(inputs (list snarf-target))
|
||||||
(method (SNARF.mes mes?)))))
|
(method (SNARF.mes mes?)))))
|
||||||
|
|
||||||
|
(define ((target-prefix? prefix) o)
|
||||||
|
(string-prefix? prefix (target-file-name o)))
|
||||||
|
|
||||||
|
(define (check-target? o)
|
||||||
|
((target-prefix? "check-") o))
|
||||||
|
|
||||||
(define (add-target o)
|
(define (add-target o)
|
||||||
(set! %targets (append %targets (list o)))
|
(set! %targets (append %targets (list o)))
|
||||||
o)
|
o)
|
||||||
(define (get-target o)
|
(define (get-target o)
|
||||||
(find (lambda (t)
|
(if (target? o) o
|
||||||
(equal? (target-file-name t) o)) %targets))
|
(find (lambda (t) (equal? (target-file-name t) o)) %targets)))
|
||||||
|
|
137
make.scm
137
make.scm
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
(use-modules (srfi srfi-1)
|
(use-modules (srfi srfi-1)
|
||||||
(srfi srfi-26)
|
(srfi srfi-26)
|
||||||
|
(ice-9 curried-definitions)
|
||||||
(ice-9 match)
|
(ice-9 match)
|
||||||
(guix make))
|
(guix make))
|
||||||
|
|
||||||
|
@ -44,6 +45,107 @@
|
||||||
(add-target (bin.mescc "stage0/exit-42.c"))
|
(add-target (bin.mescc "stage0/exit-42.c"))
|
||||||
(add-target (check "stage0/exit-42.guile" #:exit 42))
|
(add-target (check "stage0/exit-42.guile" #:exit 42))
|
||||||
|
|
||||||
|
(define* (add-scaffold-test name #:key (exit 0) (libc libc-mes.E))
|
||||||
|
(add-target (bin.gcc (string-append "scaffold/tests/" name ".c") #:libc #f))
|
||||||
|
(add-target (check (string-append "scaffold/tests/" name ".mlibc-gcc") #:exit exit))
|
||||||
|
|
||||||
|
(add-target (bin.mescc (string-append "scaffold/tests/" name ".c") #:libc libc))
|
||||||
|
(add-target (check (string-append "scaffold/tests/" name "." (cond ((not libc) "0-")
|
||||||
|
((eq? libc mini-libc-mes.E) "mini-")
|
||||||
|
(else "")) "guile") #:exit exit)))
|
||||||
|
|
||||||
|
;; tests/00: exit, functions without libc
|
||||||
|
(add-scaffold-test "00-exit-0" #:libc #f)
|
||||||
|
(add-scaffold-test "01-return-0" #:libc #f)
|
||||||
|
(add-scaffold-test "02-return-1" #:libc #f #:exit 1)
|
||||||
|
(add-scaffold-test "03-call" #:libc #f)
|
||||||
|
(add-scaffold-test "04-call-0" #:libc #f)
|
||||||
|
(add-scaffold-test "05-call-1" #:libc #f #:exit 1)
|
||||||
|
(add-scaffold-test "06-call-!1" #:libc #f)
|
||||||
|
|
||||||
|
(add-target (group "check-scaffold-tests/0" #:dependencies (filter (target-prefix? "check-scaffold/tests/0") %targets)))
|
||||||
|
|
||||||
|
;; tests/10: control without libc
|
||||||
|
(for-each
|
||||||
|
(cut add-scaffold-test <> #:libc #f)
|
||||||
|
'("10-if-0"
|
||||||
|
"11-if-1"
|
||||||
|
"12-if-=="
|
||||||
|
"13-if-!="
|
||||||
|
"14-if-goto"
|
||||||
|
"15-if-!f"
|
||||||
|
"16-if-t"))
|
||||||
|
|
||||||
|
(add-target (group "check-scaffold-tests/1" #:dependencies (filter (target-prefix? "check-scaffold/tests/1") %targets)))
|
||||||
|
|
||||||
|
;; tests/20: loop without libc
|
||||||
|
(for-each
|
||||||
|
(cut add-scaffold-test <> #:libc #f)
|
||||||
|
'("20-while"
|
||||||
|
"21-char[]"
|
||||||
|
"22-while-char[]"))
|
||||||
|
|
||||||
|
(add-target (group "check-scaffold-tests/2" #:dependencies (filter (target-prefix? "check-scaffold/tests/2") %targets)))
|
||||||
|
|
||||||
|
;; tests/30: call, compare: mini-libc-mes.c
|
||||||
|
(for-each
|
||||||
|
(cut add-scaffold-test <> #:libc mini-libc-mes.E)
|
||||||
|
'("30-strlen"
|
||||||
|
"31-eputs"
|
||||||
|
"32-compare"
|
||||||
|
"33-and-or"
|
||||||
|
"34-pre-post"
|
||||||
|
"35-compare-char"
|
||||||
|
"36-compare-arithmetic"
|
||||||
|
"37-compare-assign"
|
||||||
|
"38-compare-call"))
|
||||||
|
|
||||||
|
(add-target (group "check-scaffold-tests/3" #:dependencies (filter (target-prefix? "check-scaffold/tests/3") %targets)))
|
||||||
|
|
||||||
|
;; tests/40: control: mini-libc-mes.c
|
||||||
|
(for-each
|
||||||
|
(cut add-scaffold-test <> #:libc mini-libc-mes.E)
|
||||||
|
'("40-if-else"
|
||||||
|
"41-?"
|
||||||
|
"42-goto-label"
|
||||||
|
"43-for-do-while"
|
||||||
|
"44-switch"
|
||||||
|
"45-void-call"))
|
||||||
|
|
||||||
|
(add-target (group "check-scaffold-tests/4" #:dependencies (filter (target-prefix? "check-scaffold/tests/4") %targets)))
|
||||||
|
|
||||||
|
;; tests/50: libc-mes.c
|
||||||
|
(for-each
|
||||||
|
add-scaffold-test
|
||||||
|
'("50-assert"
|
||||||
|
"51-strcmp"
|
||||||
|
"52-itoa"
|
||||||
|
"54-argv"))
|
||||||
|
|
||||||
|
(add-target (group "check-scaffold-tests/5" #:dependencies (filter (target-prefix? "check-scaffold/tests/5") %targets)))
|
||||||
|
|
||||||
|
;; tests/60: building up to scaffold/m.c, scaffold/micro-mes.c
|
||||||
|
(for-each
|
||||||
|
add-scaffold-test
|
||||||
|
'("60-math"
|
||||||
|
"61-array"
|
||||||
|
"63-struct-cell"
|
||||||
|
"64-make-cell"
|
||||||
|
"65-read"))
|
||||||
|
|
||||||
|
(add-target (group "check-scaffold-tests/6" #:dependencies (filter (target-prefix? "check-scaffold/tests/6") %targets)))
|
||||||
|
|
||||||
|
;; tests/70: and beyond src/mes.c -- building up to 8cc.c, pcc.c, tcc.c, libguile/eval.c
|
||||||
|
(for-each
|
||||||
|
add-scaffold-test
|
||||||
|
'("70-printf"
|
||||||
|
"71-struct-array"))
|
||||||
|
|
||||||
|
(add-target (group "check-scaffold-tests/7" #:dependencies (filter (target-prefix? "check-scaffold/tests/7") %targets)))
|
||||||
|
|
||||||
|
(add-target (group "check-scaffold-tests" #:dependencies (filter (target-prefix? "check-scaffold/tests") %targets)))
|
||||||
|
|
||||||
|
(add-target (group "check-scaffold" #:dependencies (filter (target-prefix? "check-scaffold") %targets)))
|
||||||
|
|
||||||
(add-target (bin.gcc "scaffold/hello.c"))
|
(add-target (bin.gcc "scaffold/hello.c"))
|
||||||
(add-target (check "scaffold/hello.gcc" #:exit 42))
|
(add-target (check "scaffold/hello.gcc" #:exit 42))
|
||||||
|
@ -67,33 +169,12 @@
|
||||||
(add-target (bin.mescc "scaffold/m.c"))
|
(add-target (bin.mescc "scaffold/m.c"))
|
||||||
(add-target (check "scaffold/m.guile" #:exit 255))
|
(add-target (check "scaffold/m.guile" #:exit 255))
|
||||||
|
|
||||||
|
|
||||||
(add-target (bin.gcc "scaffold/t-tcc.c"))
|
|
||||||
(add-target (check "scaffold/t-tcc.gcc"))
|
|
||||||
|
|
||||||
(add-target (bin.gcc "scaffold/t-tcc.c" #:libc #f))
|
|
||||||
(add-target (check "scaffold/t-tcc.mlibc-gcc"))
|
|
||||||
|
|
||||||
(add-target (bin.mescc "scaffold/t-tcc.c"))
|
|
||||||
(add-target (check "scaffold/t-tcc.guile"))
|
|
||||||
|
|
||||||
|
|
||||||
(add-target (bin.gcc "scaffold/micro-mes.c" #:libc #f))
|
(add-target (bin.gcc "scaffold/micro-mes.c" #:libc #f))
|
||||||
(add-target (check "scaffold/micro-mes.mlibc-gcc" #:exit 1))
|
(add-target (check "scaffold/micro-mes.mlibc-gcc" #:exit 1))
|
||||||
|
|
||||||
(add-target (bin.mescc "scaffold/micro-mes.c"))
|
(add-target (bin.mescc "scaffold/micro-mes.c"))
|
||||||
(add-target (check "scaffold/micro-mes.guile" #:exit 1))
|
(add-target (check "scaffold/micro-mes.guile" #:exit 1))
|
||||||
|
|
||||||
|
|
||||||
(add-target (bin.gcc "scaffold/t.c"))
|
|
||||||
(add-target (check "scaffold/t.gcc"))
|
|
||||||
|
|
||||||
(add-target (bin.gcc "scaffold/t.c" #:libc #f))
|
|
||||||
(add-target (check "scaffold/t.mlibc-gcc"))
|
|
||||||
|
|
||||||
(add-target (bin.mescc "scaffold/t.c"))
|
|
||||||
(add-target (check "scaffold/t.guile"))
|
|
||||||
|
|
||||||
(define snarf-bases
|
(define snarf-bases
|
||||||
'("gc" "lib" "math" "mes" "posix" "reader" "vector"))
|
'("gc" "lib" "math" "mes" "posix" "reader" "vector"))
|
||||||
|
|
||||||
|
@ -195,22 +276,18 @@
|
||||||
;; FIXME: run tests/base.test
|
;; FIXME: run tests/base.test
|
||||||
(setenv "MES" "src/mes.guile")
|
(setenv "MES" "src/mes.guile")
|
||||||
|
|
||||||
(define (check-target? o)
|
|
||||||
(string-prefix? "check-" (target-file-name o)))
|
|
||||||
|
|
||||||
(define (main args)
|
(define (main args)
|
||||||
(cond ((member "clean" args) (clean))
|
(cond ((member "clean" args) (clean))
|
||||||
((member "help" args) (display "Usage: ./make.scm [TARGET]...
|
((member "help" args) (format #t "Usage: ./make.scm [TARGET]...
|
||||||
|
|
||||||
Targets:
|
Targets:
|
||||||
all
|
all
|
||||||
check
|
check
|
||||||
clean
|
clean
|
||||||
|
help~a
|
||||||
stage0/exit42.mini-guile
|
"
|
||||||
scaffold/hello.guile
|
;;(string-join (map target-file-name %targets) "\n " 'prefix)
|
||||||
src/mes.guile
|
(string-join (filter (negate (cut string-index <> #\/)) (map target-file-name %targets)) "\n " 'prefix)))
|
||||||
"))
|
|
||||||
(else
|
(else
|
||||||
(let ((targets (match args
|
(let ((targets (match args
|
||||||
(() (filter (negate check-target?) %targets))
|
(() (filter (negate check-target?) %targets))
|
||||||
|
|
38
mlibc/include/00-test.i
Normal file
38
mlibc/include/00-test.i
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int test ();
|
||||||
|
|
||||||
|
int
|
||||||
|
main ()
|
||||||
|
{
|
||||||
|
int r = test ();
|
||||||
|
#if __MESC__
|
||||||
|
asm ("mov____%eax,%ebx");
|
||||||
|
asm ("mov____$i32,%eax SYS_exit");
|
||||||
|
asm ("int____$0x80");
|
||||||
|
#else // !__MESC__
|
||||||
|
asm ("mov %0,%%ebx"
|
||||||
|
: // no outputs
|
||||||
|
: "" (r));
|
||||||
|
asm ("mov $1,%eax");
|
||||||
|
asm ("int $0x80");
|
||||||
|
#endif
|
||||||
|
}
|
28
mlibc/include/30-test.i
Normal file
28
mlibc/include/30-test.i
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int test ();
|
||||||
|
|
||||||
|
int
|
||||||
|
main ()
|
||||||
|
{
|
||||||
|
int r = test ();
|
||||||
|
return r;
|
||||||
|
}
|
|
@ -23,9 +23,16 @@
|
||||||
#if __GNUC__ && POSIX
|
#if __GNUC__ && POSIX
|
||||||
#include_next <stdarg.h>
|
#include_next <stdarg.h>
|
||||||
#else // ! (__GNUC__ && POSIX)
|
#else // ! (__GNUC__ && POSIX)
|
||||||
|
|
||||||
|
#if __GNUC__
|
||||||
|
typedef char* va_list;
|
||||||
|
#define va_start(ap, last) (void)((ap) = (char*)(&(last) + 1))
|
||||||
|
#else // !__GNUC__
|
||||||
typedef int va_list;
|
typedef int va_list;
|
||||||
#define va_start(ap, last) (void)((ap) = (char*)(&(last) + 4))
|
#define va_start(ap, last) (void)((ap) = (char*)(&(last) + 4))
|
||||||
#define va_arg(ap, type) (((type*)((ap) = ((ap) + sizeof(type))))[-1])
|
#endif // !__GNUC__
|
||||||
|
|
||||||
|
#define va_arg(ap, type) (type)(((int*)((ap) = ((ap) + 4)))[-1])
|
||||||
#define va_end(ap) (void)((ap) = 0)
|
#define va_end(ap) (void)((ap) = 0)
|
||||||
#define va_copy(dest, src) dest = src
|
#define va_copy(dest, src) dest = src
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ int g_stdout;
|
||||||
#define STDERR 2
|
#define STDERR 2
|
||||||
|
|
||||||
int printf (char const* format, ...);
|
int printf (char const* format, ...);
|
||||||
|
int sprintf (char *str, char const* format, ...);
|
||||||
|
|
||||||
#if __GNUC__ && POSIX
|
#if __GNUC__ && POSIX
|
||||||
#ifndef _GNU_SOURCE
|
#ifndef _GNU_SOURCE
|
||||||
|
|
|
@ -343,11 +343,13 @@ atoi (char const *s)
|
||||||
return i * sign;
|
return i * sign;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// FIXME: copied from libc-mes.c now
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
printf (char const* format, ...)
|
vprintf (char const* format, va_list ap)
|
||||||
{
|
{
|
||||||
int va_arg = 0;
|
|
||||||
int va;
|
|
||||||
char const *p = format;
|
char const *p = format;
|
||||||
while (*p)
|
while (*p)
|
||||||
if (*p != '%')
|
if (*p != '%')
|
||||||
|
@ -359,56 +361,51 @@ printf (char const* format, ...)
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case '%': {putchar (*p); break;}
|
case '%': {putchar (*p); break;}
|
||||||
case 'c':
|
case 'c': {char c; c = va_arg (ap, char); putchar (c); break;}
|
||||||
{
|
case 'd': {int d; d = va_arg (ap, int); puts (itoa (d)); break;}
|
||||||
asm (
|
case 's': {char *s; s = va_arg (ap, char *); puts (s); break;}
|
||||||
"mov -0xc(%%ebp),%%eax\n\t"
|
|
||||||
"shl $0x2,%%eax\n\t"
|
|
||||||
"add %%ebp,%%eax\n\t"
|
|
||||||
"add $0xc,%%eax\n\t"
|
|
||||||
"mov (%%eax),%%eax\n\t"
|
|
||||||
//"mov %%eax,%0\n\t"
|
|
||||||
: "=va" (va)
|
|
||||||
: //no inputs ""
|
|
||||||
);
|
|
||||||
putchar ((char)va);
|
|
||||||
va_arg++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'd': {
|
|
||||||
asm (
|
|
||||||
"mov -0xc(%%ebp),%%eax\n\t"
|
|
||||||
"shl $0x2,%%eax\n\t"
|
|
||||||
"add %%ebp,%%eax\n\t"
|
|
||||||
"add $0xc,%%eax\n\t"
|
|
||||||
"mov (%%eax),%%eax\n\t"
|
|
||||||
//"mov %%eax,%0\n\t"
|
|
||||||
: "=va" (va)
|
|
||||||
: //no inputs ""
|
|
||||||
);
|
|
||||||
puts (itoa ((int)va));
|
|
||||||
va_arg++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 's': {
|
|
||||||
asm (
|
|
||||||
"mov -0xc(%%ebp),%%eax\n\t"
|
|
||||||
"shl $0x2,%%eax\n\t"
|
|
||||||
"add %%ebp,%%eax\n\t"
|
|
||||||
"add $0xc,%%eax\n\t"
|
|
||||||
"mov (%%eax),%%eax\n\t"
|
|
||||||
//"mov %%eax,%0\n\t"
|
|
||||||
: "=va" (va)
|
|
||||||
: //no inputs ""
|
|
||||||
);
|
|
||||||
puts ((char*)va);
|
|
||||||
va_arg++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: putchar (*p);
|
default: putchar (*p);
|
||||||
}
|
}
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
va_end (ap);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
printf (char const* format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start (ap, format);
|
||||||
|
int r = vprintf (format, ap);
|
||||||
|
va_end (ap);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
sprintf (char *str, char const* format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start (ap, format);
|
||||||
|
char const *p = format;
|
||||||
|
while (*p)
|
||||||
|
if (*p != '%')
|
||||||
|
*str++ = *p++;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p++;
|
||||||
|
char c = *p;
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case '%': {*str++ = *p; break;}
|
||||||
|
case 'c': {char c; c = va_arg (ap, char); *str++ = c; break;}
|
||||||
|
case 'd': {int d; d = va_arg (ap, int); char const *s = itoa (d); while (*s) *str++ = *s++; break;}
|
||||||
|
case 's': {char *s; s = va_arg (ap, char *); while (*s) *str++ = *s++; break;}
|
||||||
|
default: *str++ = *p;
|
||||||
|
}
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
va_end (ap);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -354,7 +354,7 @@ getenv (char const* s)
|
||||||
int
|
int
|
||||||
vprintf (char const* format, va_list ap)
|
vprintf (char const* format, va_list ap)
|
||||||
{
|
{
|
||||||
char *p = format;
|
char const *p = format;
|
||||||
while (*p)
|
while (*p)
|
||||||
if (*p != '%')
|
if (*p != '%')
|
||||||
putchar (*p++);
|
putchar (*p++);
|
||||||
|
@ -368,11 +368,11 @@ vprintf (char const* format, va_list ap)
|
||||||
case 'c': {char c; c = va_arg (ap, char); putchar (c); break;}
|
case 'c': {char c; c = va_arg (ap, char); putchar (c); break;}
|
||||||
case 'd': {int d; d = va_arg (ap, int); puts (itoa (d)); break;}
|
case 'd': {int d; d = va_arg (ap, int); puts (itoa (d)); break;}
|
||||||
case 's': {char *s; s = va_arg (ap, char *); puts (s); break;}
|
case 's': {char *s; s = va_arg (ap, char *); puts (s); break;}
|
||||||
default: putchar (*p);
|
default: {putchar (*p); break;}
|
||||||
}
|
}
|
||||||
va_end (ap);
|
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
va_end (ap);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,3 +385,30 @@ printf (char const* format, ...)
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
sprintf (char *str, char const* format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start (ap, format);
|
||||||
|
char const *p = format;
|
||||||
|
while (*p)
|
||||||
|
if (*p != '%')
|
||||||
|
*str++ = *p++;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p++;
|
||||||
|
char c = *p;
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case '%': {*str++ = *p; break;}
|
||||||
|
case 'c': {char c; c = va_arg (ap, char); *str++ = c; break;}
|
||||||
|
case 'd': {int d; d = va_arg (ap, int); char const *s; s = itoa (d); while (*s) *str++ = *s++; break;}
|
||||||
|
case 's': {char *s; s = va_arg (ap, char *); while (*s) *str++ = *s++; break;}
|
||||||
|
default: {*str++ = *p; break;}
|
||||||
|
}
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
va_end (ap);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -63,3 +63,11 @@ eputs (char const* s)
|
||||||
write (2, s, i);
|
write (2, s, i);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
puts (char const* s)
|
||||||
|
{
|
||||||
|
int i = strlen (s);
|
||||||
|
write (1, s, i);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
988
scaffold/t.c
988
scaffold/t.c
|
@ -1,988 +0,0 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
|
||||||
* Mes --- Maxwell Equations of Software
|
|
||||||
* Copyright © 2016,2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
|
||||||
*
|
|
||||||
* This file is part of Mes.
|
|
||||||
*
|
|
||||||
* Mes is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 3 of the License, or (at
|
|
||||||
* your option) any later version.
|
|
||||||
*
|
|
||||||
* Mes is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <mlibc.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
struct scm {
|
|
||||||
int type;
|
|
||||||
int car;
|
|
||||||
int cdr;
|
|
||||||
};
|
|
||||||
|
|
||||||
int bla = 1234;
|
|
||||||
char arena[84];
|
|
||||||
#if __MESC__
|
|
||||||
struct scm *g_cells = arena;
|
|
||||||
#else
|
|
||||||
struct scm *g_cells = (struct scm*)arena;
|
|
||||||
#endif
|
|
||||||
char *g_chars = arena;
|
|
||||||
|
|
||||||
int foo () {puts ("t: foo\n"); return 0;};
|
|
||||||
int bar (int i) {puts ("t: bar\n"); return 0;};
|
|
||||||
struct function {
|
|
||||||
int (*function) (void);
|
|
||||||
int arity;
|
|
||||||
char *name;
|
|
||||||
};
|
|
||||||
struct function g_fun = {&exit,1,"fun"};
|
|
||||||
struct function g_foo = {&foo,0,"foo"};
|
|
||||||
struct function g_bar = {&bar,1,"bar"};
|
|
||||||
|
|
||||||
//void *functions[2];
|
|
||||||
int functions[2];
|
|
||||||
|
|
||||||
struct function g_functions[2];
|
|
||||||
int g_function = 0;
|
|
||||||
|
|
||||||
enum type_t {TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART};
|
|
||||||
|
|
||||||
typedef int SCM;
|
|
||||||
int g_free = 3;
|
|
||||||
SCM tmp;
|
|
||||||
SCM tmp_num;
|
|
||||||
|
|
||||||
int ARENA_SIZE = 200;
|
|
||||||
#define TYPE(x) g_cells[x].type
|
|
||||||
#define CAR(x) g_cells[x].car
|
|
||||||
#define CDR(x) g_cells[x].cdr
|
|
||||||
#define VALUE(x) g_cells[x].cdr
|
|
||||||
|
|
||||||
#define CAAR(x) CAR (CAR (x))
|
|
||||||
|
|
||||||
struct scm scm_fun = {TFUNCTION,0,0};
|
|
||||||
SCM cell_fun;
|
|
||||||
|
|
||||||
char *env[] = {"foo", "bar", "baz", 0};
|
|
||||||
|
|
||||||
int
|
|
||||||
add (int a, int b)
|
|
||||||
{
|
|
||||||
return a + b;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
inc (int i)
|
|
||||||
{
|
|
||||||
return i + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
identity (int i)
|
|
||||||
{
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 1
|
|
||||||
int
|
|
||||||
label (int c)
|
|
||||||
{
|
|
||||||
label:
|
|
||||||
if (c == 0) return c;
|
|
||||||
c--;
|
|
||||||
goto label;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
swits (int c)
|
|
||||||
{
|
|
||||||
int x = -1;
|
|
||||||
|
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case TCHAR: {goto next;}
|
|
||||||
case 1: {goto next;}
|
|
||||||
case 2: {goto next;}
|
|
||||||
default: {goto next;}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
next:
|
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
{
|
|
||||||
x = 0;
|
|
||||||
c = 34;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case -1:
|
|
||||||
case 1:
|
|
||||||
x = 1;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
x = 2;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
int g = 48;
|
|
||||||
int
|
|
||||||
get ()
|
|
||||||
{
|
|
||||||
int i = g;
|
|
||||||
g++;
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
read_test ()
|
|
||||||
{
|
|
||||||
char *p = (char*)g_chars;
|
|
||||||
int i = 0;
|
|
||||||
puts ("t: read 0123456789\nt: ");
|
|
||||||
int c = get ();
|
|
||||||
while (i < 10) {
|
|
||||||
*p++ = c;
|
|
||||||
putchar (c);
|
|
||||||
c = get ();
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
puts ("\n");
|
|
||||||
if (strcmp (g_chars, "0123456789")) return 1;
|
|
||||||
|
|
||||||
puts ("t: ungetc ('A') == getchar ()\n");
|
|
||||||
ungetc ('A', STDIN);
|
|
||||||
if (getchar () != 'A') return 1;
|
|
||||||
ungetc (0, STDIN);
|
|
||||||
//ungetc ('\1', STDIN);
|
|
||||||
ungetc (1, STDIN);
|
|
||||||
puts ("t: ungetc ();ungetc ();getchar ();getchar ()\n");
|
|
||||||
if (getchar () != 1) return 1;
|
|
||||||
//if (getchar () != '\0') return 1;
|
|
||||||
if (getchar () != 0) return 1;
|
|
||||||
|
|
||||||
puts ("t: i == 'm'\n");
|
|
||||||
char m = 0x1122336d;
|
|
||||||
i = m;
|
|
||||||
if (i != 'm') return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
array_test (char **e)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
puts ("a[i] = i-1\n");
|
|
||||||
int a[3];
|
|
||||||
for (int i=0; i < 3; i++) a[i] = i-1;
|
|
||||||
for (int i=0; i < 3; i++) if (a[i] != i-1) return 1;
|
|
||||||
|
|
||||||
puts ("env [");
|
|
||||||
puts (itoa (env));
|
|
||||||
puts ("]\n");
|
|
||||||
|
|
||||||
puts ("e [");
|
|
||||||
puts (itoa (e));
|
|
||||||
puts ("]\n");
|
|
||||||
|
|
||||||
puts ("env [0] == \"foo\"\n");
|
|
||||||
if (strcmp (env[0], "foo")) return 1;
|
|
||||||
|
|
||||||
puts ("env [1] == \"bar\"\n");
|
|
||||||
if (strcmp (env[1], "bar")) return 1;
|
|
||||||
|
|
||||||
puts ("t: **p in *env[]\n");
|
|
||||||
|
|
||||||
char **pp = env;
|
|
||||||
while (*pp)
|
|
||||||
{
|
|
||||||
puts ("pp [");
|
|
||||||
puts (itoa (pp));
|
|
||||||
puts ("]: ");
|
|
||||||
if (*pp) puts (*pp);
|
|
||||||
puts ("\n");
|
|
||||||
pp++;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
if (i != 3) return i;
|
|
||||||
|
|
||||||
pp = env;
|
|
||||||
puts ("t: *pp++ == \"foo\"\n");
|
|
||||||
if (strcmp (*pp++, "foo")) return 1;
|
|
||||||
|
|
||||||
puts ("t: *pp++ == \"bar\"\n");
|
|
||||||
if (strcmp (*pp++, "bar")) return 1;
|
|
||||||
|
|
||||||
char *buf = "hello";
|
|
||||||
puts ("t: buf[0]\n");
|
|
||||||
if (buf[0] != 'h') return 1;
|
|
||||||
|
|
||||||
puts ("t: buf + 1\n");
|
|
||||||
if (*(buf+1) != 'e') return 1;
|
|
||||||
|
|
||||||
char **p = &buf;
|
|
||||||
puts ("t: **p\n");
|
|
||||||
if (**p != 'h') return 1;
|
|
||||||
|
|
||||||
puts ("t: *(p + 1)\n");
|
|
||||||
if (*(*p + 1) != 'e') return 1;
|
|
||||||
|
|
||||||
puts ("t: getenv ()");
|
|
||||||
if (!getenv ("SHELL")) return 1;
|
|
||||||
|
|
||||||
return read_test ();
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
math_test ()
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
puts ("t: 0 < 0\n");
|
|
||||||
if (0 < 0) return 1;
|
|
||||||
|
|
||||||
puts ("t: 2 < 1\n");
|
|
||||||
if (2 < 1) return 1;
|
|
||||||
|
|
||||||
puts ("t: -1 < -2\n");
|
|
||||||
if (-1 < -2) return 1;
|
|
||||||
|
|
||||||
puts ("t: 0 < -1\n");
|
|
||||||
if (0 < -1) return 1;
|
|
||||||
|
|
||||||
puts ("t: 0 > 0\n");
|
|
||||||
if (0 > 0) return 1;
|
|
||||||
|
|
||||||
puts ("t: 1 > 2\n");
|
|
||||||
if (1 > 2) return 1;
|
|
||||||
|
|
||||||
puts ("t: -2 > -1\n");
|
|
||||||
if (-2 > -1) return 1;
|
|
||||||
|
|
||||||
puts ("t: -1 > 0\n");
|
|
||||||
if (-1 > 0) return 1;
|
|
||||||
|
|
||||||
puts ("t: 1 == inc (0)\n");
|
|
||||||
if (1 == inc (0)) goto ok0;
|
|
||||||
return 1;
|
|
||||||
ok0:
|
|
||||||
|
|
||||||
puts ("t: 0 < inc (0)\n");
|
|
||||||
if (0 < inc (0)) goto ok1;
|
|
||||||
return 1;
|
|
||||||
ok1:
|
|
||||||
|
|
||||||
puts ("t: inc (0) + 2 != 3\n");
|
|
||||||
if (inc (0) + inc (1) != 3) return 1;
|
|
||||||
|
|
||||||
puts ("t: 4/2=");
|
|
||||||
i = 4 / 2;
|
|
||||||
if (i!=2) return 1;
|
|
||||||
i += 48;
|
|
||||||
putchar (i);
|
|
||||||
puts ("\n");
|
|
||||||
|
|
||||||
puts ("t: 3*4=\n");
|
|
||||||
i = 3 * 4;
|
|
||||||
if (i!=12) return 1;
|
|
||||||
|
|
||||||
puts ("t: i /= 4\n");
|
|
||||||
i /= 4;
|
|
||||||
if (i!=3) return 1;
|
|
||||||
|
|
||||||
puts ("t: i *= 4\n");
|
|
||||||
i *= 4;
|
|
||||||
if (i!=12) return 1;
|
|
||||||
|
|
||||||
puts ("t: 1 << 3\n");
|
|
||||||
if (1 << 3 != 8) return 1 << 3;
|
|
||||||
|
|
||||||
puts ("t: 3 << 4\n");
|
|
||||||
if (3 << 4 != 48) return 3 << 4;
|
|
||||||
|
|
||||||
puts ("t: 48 >> 3\n");
|
|
||||||
if (48 >> 4 != 3) return 48 >> 4;
|
|
||||||
|
|
||||||
puts ("t: 10 >> 1\n");
|
|
||||||
if (10 >> 1 != 5) return 10 >> 1;
|
|
||||||
|
|
||||||
puts ("t: 1 | 4\n");
|
|
||||||
if ((1 | 4) != 5) return 1 | 4;
|
|
||||||
|
|
||||||
i = -3;
|
|
||||||
puts ("t: -i\n");
|
|
||||||
if (-i != 3) return 1;
|
|
||||||
|
|
||||||
puts ("t: -1 + 2\n");
|
|
||||||
if (-1 + 2 != 1) return 1;
|
|
||||||
|
|
||||||
puts ("t: 1 & 3\n");
|
|
||||||
if ((1 & 3) != 1) return 1;
|
|
||||||
|
|
||||||
puts ("t: 1 | 3\n");
|
|
||||||
if ((1 | 2) != 3) return 1;
|
|
||||||
|
|
||||||
puts ("t: ^ 1 \n");
|
|
||||||
if ((1 ^ 3) != 2) return 1;
|
|
||||||
|
|
||||||
puts ("t: 3 == 3\n");
|
|
||||||
if ((3 == 3) != 1) return 1;
|
|
||||||
|
|
||||||
puts ("t: 3 != 3\n");
|
|
||||||
if ((3 != 3) != 0) return 1;
|
|
||||||
|
|
||||||
puts ("t: 011 == 15\n");
|
|
||||||
if (011 != 9) return 1;
|
|
||||||
|
|
||||||
puts ("t: 0b11 == 3\n");
|
|
||||||
if (0b11 != 3) return 1;
|
|
||||||
|
|
||||||
puts ("t: 0x11 == 3\n");
|
|
||||||
if (0x11 != 17) return 1;
|
|
||||||
|
|
||||||
return array_test (env);
|
|
||||||
}
|
|
||||||
|
|
||||||
SCM
|
|
||||||
alloc (int n)
|
|
||||||
{
|
|
||||||
SCM x = g_free;
|
|
||||||
g_free += n;
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
SCM
|
|
||||||
make_cell (SCM type, SCM car, SCM cdr)
|
|
||||||
{
|
|
||||||
SCM x = alloc (1);
|
|
||||||
TYPE (x) = VALUE (type);
|
|
||||||
if (VALUE (type) == TCHAR || VALUE (type) == TNUMBER) {
|
|
||||||
if (car) CAR (x) = CAR (car);
|
|
||||||
if (cdr) CDR(x) = CDR(cdr);
|
|
||||||
}
|
|
||||||
else if (VALUE (type) == TFUNCTION) {
|
|
||||||
if (car) CAR (x) = car;
|
|
||||||
if (cdr) CDR(x) = CDR(cdr);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
CAR (x) = car;
|
|
||||||
CDR(x) = cdr;
|
|
||||||
}
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
SCM
|
|
||||||
make_cell_test ()
|
|
||||||
{
|
|
||||||
VALUE (tmp_num) = TPAIR;
|
|
||||||
make_cell (tmp_num, 0, 1);
|
|
||||||
return math_test ();
|
|
||||||
}
|
|
||||||
|
|
||||||
SCM
|
|
||||||
make_tmps_test (struct scm* cells)
|
|
||||||
{
|
|
||||||
puts ("t: tmp = g_free++\n");
|
|
||||||
tmp = g_free++;
|
|
||||||
puts ("t: cells[tmp].type = CHAR\n");
|
|
||||||
cells[tmp].type = TCHAR;
|
|
||||||
tmp_num = g_free++;
|
|
||||||
cells[tmp_num].type = TNUMBER;
|
|
||||||
|
|
||||||
return make_cell_test();
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
struct_test ()
|
|
||||||
{
|
|
||||||
puts ("t: g_cells[0] = g_cells[1]\n");
|
|
||||||
TYPE (1) = 1;
|
|
||||||
CAR (1) = 2;
|
|
||||||
CDR (1) = 3;
|
|
||||||
g_cells[0] = g_cells[1];
|
|
||||||
if (TYPE (0) != 1) return 1;
|
|
||||||
if (CAR (0) != 2) return 2;
|
|
||||||
if (CDR (0) != 3) return 3;
|
|
||||||
|
|
||||||
puts ("t: g_cells[i] = g_cells[j]\n");
|
|
||||||
int i = 0;
|
|
||||||
int j = 1;
|
|
||||||
TYPE (1) = 4;
|
|
||||||
CAR (1) = 5;
|
|
||||||
CDR (1) = 6;
|
|
||||||
g_cells[i] = g_cells[j];
|
|
||||||
if (TYPE (0) != 4) return 1;
|
|
||||||
if (CAR (0) != 5) return 2;
|
|
||||||
if (CDR (0) != 6) return 3;
|
|
||||||
|
|
||||||
puts ("t: g_cells[0+add(0,0] = g_cells[0+inc(0)]\n");
|
|
||||||
TYPE (1) = 1;
|
|
||||||
CAR (1) = 2;
|
|
||||||
CDR (1) = 3;
|
|
||||||
g_cells[0+add(0, 0)] = g_cells[0+inc(0)];
|
|
||||||
if (TYPE (0) != 1) return 1;
|
|
||||||
if (CAR (0) != 2) return 2;
|
|
||||||
if (CDR (0) != 3) return 3;
|
|
||||||
|
|
||||||
g_cells[0].type = TNUMBER;
|
|
||||||
g_cells[0].car = 0;
|
|
||||||
g_cells[0].cdr = 0;
|
|
||||||
g_cells[1].type = TNUMBER;
|
|
||||||
g_cells[1].car = 0;
|
|
||||||
g_cells[1].cdr = 0;
|
|
||||||
|
|
||||||
puts ("t: TYPE (0) != TYPE (1)\n");
|
|
||||||
if (TYPE (0) == TYPE (1)) goto ok;
|
|
||||||
return 1;
|
|
||||||
ok:
|
|
||||||
|
|
||||||
g_cells[0].car = 1;
|
|
||||||
g_cells[1].car = 2;
|
|
||||||
|
|
||||||
puts ("t: int c = VALUE (0)\n");
|
|
||||||
int c = CAR (0);
|
|
||||||
if (c != 1) return 1;
|
|
||||||
|
|
||||||
puts ("t: CAAR (0) != 2\n");
|
|
||||||
if (CAAR (0) != 2) return 1;
|
|
||||||
|
|
||||||
puts ("t: 2 != CAAR (0)\n");
|
|
||||||
if (2 != CAAR (0)) return 1;
|
|
||||||
|
|
||||||
g_cells[3].type = 0x64;
|
|
||||||
if (g_cells[3].type != 0x64)
|
|
||||||
return g_cells[3].type;
|
|
||||||
|
|
||||||
TYPE (4) = 4;
|
|
||||||
if (TYPE (4) != 4)
|
|
||||||
return 4;
|
|
||||||
|
|
||||||
CDR (3) = 0x22;
|
|
||||||
CDR (4) = 0x23;
|
|
||||||
if (CDR (3) != 0x22)
|
|
||||||
return CDR (3);
|
|
||||||
|
|
||||||
puts ("t: g_fun.arity != 1;\n");
|
|
||||||
if (g_fun.arity != 1) return 1;
|
|
||||||
|
|
||||||
puts ("t: g_fun.function != exit;\n");
|
|
||||||
if (g_fun.function != &exit) return 1;
|
|
||||||
|
|
||||||
puts ("t: struct fun = {&exit,1,\"exit\"};\n");
|
|
||||||
struct function fun = {&exit,1,"exit"};
|
|
||||||
|
|
||||||
puts ("t: fun.arity != 1;\n");
|
|
||||||
if (fun.arity != 1) return 1;
|
|
||||||
|
|
||||||
puts ("t: fun.function != exit;\n");
|
|
||||||
if (fun.function != &exit) return 1;
|
|
||||||
|
|
||||||
puts ("t: puts (fun.name)\n");
|
|
||||||
if (strcmp (fun.name, "exit")) return 1;
|
|
||||||
|
|
||||||
puts ("t: puts (g_fun.name)\n");
|
|
||||||
if (strcmp (g_fun.name, "fun")) return 1;
|
|
||||||
|
|
||||||
puts ("t: g_functions[g_function++] = g_foo;\n");
|
|
||||||
g_functions[g_function++] = g_foo;
|
|
||||||
|
|
||||||
puts ("t: pbar->arity == 1\n");
|
|
||||||
struct function* barp = &g_bar;
|
|
||||||
if (barp->arity != 1) return 1;
|
|
||||||
|
|
||||||
int fn = 0;
|
|
||||||
puts ("t: g_functions[g_cells[fn].cdr].arity\n");
|
|
||||||
if (g_functions[g_cells[fn].cdr].arity) return 1;
|
|
||||||
if (g_functions[g_cells[fn].cdr].arity != 0) return 1;
|
|
||||||
|
|
||||||
int (*functionx) (void) = 0;
|
|
||||||
functionx = g_functions[0].function;
|
|
||||||
puts ("t: functionx == foo\n");
|
|
||||||
if (functionx != foo) return 11;
|
|
||||||
|
|
||||||
puts ("t: g_functions[0].name\n");
|
|
||||||
if (strcmp (g_functions[0].name, "foo")) return 1;
|
|
||||||
|
|
||||||
puts ("t: (functionx) () == foo\n");
|
|
||||||
if ((functionx) () != 0) return 12;
|
|
||||||
|
|
||||||
puts ("t: g_functions[<foo>].arity\n");
|
|
||||||
if (g_functions[0].arity != 0) return 17;
|
|
||||||
|
|
||||||
fn++;
|
|
||||||
g_functions[fn] = g_bar;
|
|
||||||
g_cells[fn].cdr = fn;
|
|
||||||
if (g_cells[fn].cdr != fn) return 13;
|
|
||||||
|
|
||||||
puts ("t: g_functions[g_cells[fn].cdr].function\n");
|
|
||||||
functionx = g_functions[g_cells[fn].cdr].function;
|
|
||||||
|
|
||||||
puts ("t: g_functions[1].name\n");
|
|
||||||
if (strcmp (g_functions[1].name, "bar")) return 1;
|
|
||||||
|
|
||||||
puts ("t: functionx == bar\n");
|
|
||||||
if (functionx != bar) return 15;
|
|
||||||
|
|
||||||
puts ("t: (functiony) (1) == bar\n");
|
|
||||||
int (*functiony) (int) = 0;
|
|
||||||
functiony = g_functions[g_cells[fn].cdr].function;
|
|
||||||
if ((functiony) (1) != 0) return 16;
|
|
||||||
|
|
||||||
puts ("t: g_functions[<bar>].arity\n");
|
|
||||||
if (g_functions[fn].arity != 1) return 18;
|
|
||||||
|
|
||||||
// fake name
|
|
||||||
scm_fun.car = 33;
|
|
||||||
scm_fun.cdr = g_function;
|
|
||||||
//g_functions[g_function++] = g_fun;
|
|
||||||
g_functions[g_function] = g_fun;
|
|
||||||
cell_fun = g_free++;
|
|
||||||
g_cells[cell_fun] = scm_fun;
|
|
||||||
|
|
||||||
puts ("t: TYPE (cell_fun)\n");
|
|
||||||
if (TYPE (cell_fun) != TFUNCTION) return 1;
|
|
||||||
|
|
||||||
puts ("t: CAR (cell_fun)\n");
|
|
||||||
if (CAR (cell_fun) != 33) return 1;
|
|
||||||
|
|
||||||
puts ("t: CDR (cell_fun)\n");
|
|
||||||
if (CDR (cell_fun) != g_function) return 1;
|
|
||||||
|
|
||||||
return make_tmps_test (g_cells);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
string_test ()
|
|
||||||
{
|
|
||||||
puts ("t: strcpy (buf, \"hallo\")\n");
|
|
||||||
char buf[10];
|
|
||||||
strcpy (buf, "hallo");
|
|
||||||
if (strcmp (buf, "hallo")) return 1;
|
|
||||||
|
|
||||||
return struct_test ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
void_func ()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if 1
|
|
||||||
int
|
|
||||||
test (char *p)
|
|
||||||
{
|
|
||||||
int f = 0;
|
|
||||||
int t = 1;
|
|
||||||
int one = 1;
|
|
||||||
char c = 'C';
|
|
||||||
int i=0;
|
|
||||||
|
|
||||||
char *x = arena;
|
|
||||||
char *y = g_chars;
|
|
||||||
|
|
||||||
puts ("t: for (i=1; i<5; ++i)\n");
|
|
||||||
for (i=1; i<5; ++i);
|
|
||||||
if (i != 5) return i;
|
|
||||||
|
|
||||||
puts ("t: while (i<3) i++\n");
|
|
||||||
i = 1;
|
|
||||||
while (i<3) i++;
|
|
||||||
if (i != 3) return i;
|
|
||||||
|
|
||||||
puts ("t: do i-- while (i>0)\n");
|
|
||||||
do i--; while (i>0);
|
|
||||||
if (i != 0) return 1;
|
|
||||||
|
|
||||||
puts ("t: if (0)\n");
|
|
||||||
if (0) return 1;
|
|
||||||
|
|
||||||
if (i)
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
puts ("t: else 1\n");
|
|
||||||
|
|
||||||
if (i)
|
|
||||||
puts ("0");
|
|
||||||
else if (i == 1)
|
|
||||||
puts ("1");
|
|
||||||
else
|
|
||||||
puts ("t: else if 2\n");
|
|
||||||
|
|
||||||
puts ("t: if (f)\n");
|
|
||||||
if (f) return 1;
|
|
||||||
|
|
||||||
puts ("t: if (one != 1)\n");
|
|
||||||
if (one != 1) return 1;
|
|
||||||
|
|
||||||
puts ("t: if (1 != one)\n");
|
|
||||||
if (1 != one) return 1;
|
|
||||||
|
|
||||||
puts ("t: if (one > 1)\n");
|
|
||||||
if (one > 1) return 1;
|
|
||||||
|
|
||||||
puts ("t: if (one < 0)\n");
|
|
||||||
if (one < 0) return 1;
|
|
||||||
|
|
||||||
puts ("t: if (one <= 0)\n");
|
|
||||||
if (one <= 0) return 1;
|
|
||||||
|
|
||||||
puts ("t: if (one >= 2)\n");
|
|
||||||
if (one >= 2) return 1;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
puts ("t: if (one == 0)\n");
|
|
||||||
if (one == 0) return 1;
|
|
||||||
|
|
||||||
puts ("t: if (f != 0)\n");
|
|
||||||
if (one != 1) return 1;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
puts ("t: if (f || !t)\n");
|
|
||||||
if (f || !t) return 1;
|
|
||||||
|
|
||||||
puts ("t: if (i++)\n");
|
|
||||||
if (i++) return 1;
|
|
||||||
|
|
||||||
puts ("t: if (--i)\n");
|
|
||||||
if (--i) return 1;
|
|
||||||
|
|
||||||
puts ("t: i += 2\n");
|
|
||||||
i += 2;
|
|
||||||
if (i != 2) return 1;
|
|
||||||
|
|
||||||
puts ("t: i -= 2\n");
|
|
||||||
i -= 2;
|
|
||||||
if (i != 0) return 1;
|
|
||||||
|
|
||||||
puts ("t: if (f = 0) ?\n");
|
|
||||||
if (f = 0) return 1;
|
|
||||||
|
|
||||||
puts ("t: if (!(t = 1)) ?\n");
|
|
||||||
if (!(t = 1)) return 1;
|
|
||||||
|
|
||||||
puts ("t: if ((f = 0) != 0) ?\n");
|
|
||||||
if ((f = 0) != 0) return 1;
|
|
||||||
|
|
||||||
puts ("t: if ((t = 1) != 1) ?\n");
|
|
||||||
if ((t = 1) != 1) return 1;
|
|
||||||
|
|
||||||
puts ("t: (one == 1) ?\n");
|
|
||||||
(one == 1) ? 1 : exit (1);
|
|
||||||
|
|
||||||
puts ("t: (f) ?\n");
|
|
||||||
(f) ? exit (1) : 1;
|
|
||||||
|
|
||||||
puts ("t: assert (1) ?\n");
|
|
||||||
assert (1);
|
|
||||||
|
|
||||||
puts ("t: assert (f==0) ?\n");
|
|
||||||
assert (f==0);
|
|
||||||
|
|
||||||
puts ("t: p[0] != 't'\n");
|
|
||||||
if (p[0] != 't') return p[0];
|
|
||||||
|
|
||||||
puts ("t: p[i] != 't'\n");
|
|
||||||
if (p[i] != 't') return p[i];
|
|
||||||
|
|
||||||
puts ("t: identity (p[i]) != 't'\n");
|
|
||||||
if (identity (p[i]) != 't') return identity (p[i]);
|
|
||||||
|
|
||||||
puts ("t: *g_chars != 'A'\n");
|
|
||||||
arena[0] = 'A';
|
|
||||||
if (*g_chars != 'A') return 1;
|
|
||||||
|
|
||||||
puts ("t: *x != 'A'\n");
|
|
||||||
if (*x != 'A') return 1;
|
|
||||||
|
|
||||||
puts ("t: *y != 'A'\n");
|
|
||||||
if (*y != 'A') return 1;
|
|
||||||
|
|
||||||
puts ("t: *x != 'Q'\n");
|
|
||||||
g_chars[0] = 'Q';
|
|
||||||
if (*x != 'Q') return 1;
|
|
||||||
|
|
||||||
puts ("t: *x++ != 'C'\n");
|
|
||||||
*x++ = c;
|
|
||||||
if (*g_chars != 'C') return 1;
|
|
||||||
|
|
||||||
puts ("t: 1 + 2\n");
|
|
||||||
if (1 + 2 != 3) return 1;
|
|
||||||
|
|
||||||
puts ("t: 2 - 1\n");
|
|
||||||
if (2 - 1 != 1) return 1;
|
|
||||||
|
|
||||||
puts ("t: 1 << 3\n");
|
|
||||||
if (1 << 3 != 8) return 1;
|
|
||||||
|
|
||||||
puts ("t: 8 >> 3\n");
|
|
||||||
if (8 >> 3 != 1) return 1;
|
|
||||||
|
|
||||||
puts ("t: 8 / 4\n");
|
|
||||||
if (8 / 4 != 2) return 1;
|
|
||||||
|
|
||||||
puts ("t: inc (0)\n");
|
|
||||||
if (inc (0) != 1) return 1;
|
|
||||||
|
|
||||||
puts ("t: inc (inc (0))\n");
|
|
||||||
if (inc (inc (0)) != 2) return 1;
|
|
||||||
|
|
||||||
puts ("t: inc (inc (inc (0)))\n");
|
|
||||||
if (inc (inc (inc (0))) != 3) return 1;
|
|
||||||
|
|
||||||
puts ("t: add (1, 2)\n");
|
|
||||||
if (add (1, 2) != 3) return 1;
|
|
||||||
|
|
||||||
puts ("t: add (inc (0), inc (1))\n");
|
|
||||||
if (add (inc (0), inc (1)) != 3) return 1;
|
|
||||||
|
|
||||||
puts ("t: add (TSTRING, 3)\n");
|
|
||||||
if (add (TSTRING, 3) != 13) return 1;
|
|
||||||
|
|
||||||
puts ("t: add (inc (inc (0)), inc (inc (1)))\n");
|
|
||||||
if (add (inc (inc (0)), inc (inc (1))) != 5) return 1;
|
|
||||||
|
|
||||||
puts ("t: goto label\n");
|
|
||||||
if (label (1) != 0) return 1;
|
|
||||||
|
|
||||||
puts ("t: switch 0\n");
|
|
||||||
if (swits (0) != 0) return swits (0);
|
|
||||||
|
|
||||||
puts ("t: switch 1\n");
|
|
||||||
if (swits (1) != 1) return 1;
|
|
||||||
|
|
||||||
puts ("t: switch -1\n");
|
|
||||||
if (swits (-1) != 1) return 1;
|
|
||||||
|
|
||||||
puts ("t: switch -1\n");
|
|
||||||
if (swits (-2) != 2) return 1;
|
|
||||||
|
|
||||||
puts ("t: if (1)\n");
|
|
||||||
if (1) goto ok0;
|
|
||||||
return 1;
|
|
||||||
ok0:
|
|
||||||
|
|
||||||
puts ("t: while (1) break;\n");
|
|
||||||
while (1) break;
|
|
||||||
|
|
||||||
puts ("t: while (1) ... break;\n");
|
|
||||||
while (1) {f=0;break;}
|
|
||||||
|
|
||||||
puts ("t: while (1) {while (1) break;break;}\n");
|
|
||||||
while (1) {while (1) break;break;}
|
|
||||||
|
|
||||||
puts ("t: while () {continue;...}\n");
|
|
||||||
while (one--) {continue;one=1;}
|
|
||||||
one += 2;
|
|
||||||
|
|
||||||
puts ("t: while (1) { goto label; };\n");
|
|
||||||
while (1) {
|
|
||||||
goto ok00;
|
|
||||||
}
|
|
||||||
ok00:
|
|
||||||
|
|
||||||
puts ("t: if (0); return 1; else;\n");
|
|
||||||
if (0) return 1; else goto ok01;
|
|
||||||
ok01:
|
|
||||||
|
|
||||||
puts ("t: if (t)\n");
|
|
||||||
if (t) goto ok1;
|
|
||||||
return 1;
|
|
||||||
ok1:
|
|
||||||
|
|
||||||
puts ("t: if (one > 0)\n");
|
|
||||||
if (one > 0) goto ok2;
|
|
||||||
return 1;
|
|
||||||
ok2:
|
|
||||||
|
|
||||||
puts ("t: if (one < 2)\n");
|
|
||||||
if (one < 2) goto ok3;
|
|
||||||
return 1;
|
|
||||||
ok3:
|
|
||||||
|
|
||||||
puts ("t: if (one >= 0)\n");
|
|
||||||
if (one >= 0) goto ok30;
|
|
||||||
return 1;
|
|
||||||
ok30:
|
|
||||||
|
|
||||||
puts ("t: if (one >= 1)\n");
|
|
||||||
if (one >= 0) goto ok31;
|
|
||||||
return 1;
|
|
||||||
ok31:
|
|
||||||
|
|
||||||
puts ("t: if (one <= 2)\n");
|
|
||||||
if (one <= 2) goto ok32;
|
|
||||||
return 1;
|
|
||||||
ok32:
|
|
||||||
|
|
||||||
puts ("t: if (one <= 1)\n");
|
|
||||||
if (one <= 1) goto ok33;
|
|
||||||
return 1;
|
|
||||||
ok33:
|
|
||||||
|
|
||||||
puts ("t: if (strlen (\".\"))\n");
|
|
||||||
if (strlen (".")) goto ok4;
|
|
||||||
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;
|
|
||||||
ok5:
|
|
||||||
|
|
||||||
puts ("t: if (one == 1)\n");
|
|
||||||
if (one == 1) goto ok6;
|
|
||||||
return 1;
|
|
||||||
ok6:
|
|
||||||
|
|
||||||
puts ("t: if (one != 0)\n");
|
|
||||||
if (one != 0) goto ok7;
|
|
||||||
return 1;
|
|
||||||
ok7:
|
|
||||||
|
|
||||||
puts ("t: if (1 && !0)\n");
|
|
||||||
if (1 && !0) goto ok8;
|
|
||||||
return 1;
|
|
||||||
ok8:
|
|
||||||
|
|
||||||
puts ("t: if (f || t)\n");
|
|
||||||
if (f || t) goto ok80;
|
|
||||||
return 1;
|
|
||||||
ok80:
|
|
||||||
|
|
||||||
puts ("t: if (++i)\n");
|
|
||||||
if (++i) goto ok9;
|
|
||||||
return 1;
|
|
||||||
ok9:
|
|
||||||
|
|
||||||
puts ("t: if (i--)\n");
|
|
||||||
if (i--) goto ok10;
|
|
||||||
return 1;
|
|
||||||
ok10:
|
|
||||||
|
|
||||||
puts ("t: *g_chars == 'B'\n");
|
|
||||||
arena[0] = 'B';
|
|
||||||
if (*g_chars == 'B') goto ok11;
|
|
||||||
return 1;
|
|
||||||
ok11:
|
|
||||||
|
|
||||||
puts ("t: *x == 'B'\n");
|
|
||||||
x = arena;
|
|
||||||
if (*x == 'B') goto ok12;
|
|
||||||
return 1;
|
|
||||||
ok12:
|
|
||||||
|
|
||||||
puts ("t: *y == 'B'\n");
|
|
||||||
y = g_chars;
|
|
||||||
if (*y == 'B') goto ok13;
|
|
||||||
return 1;
|
|
||||||
ok13:
|
|
||||||
|
|
||||||
puts ("t: *x == 'R'\n");
|
|
||||||
g_chars[0] = 'R';
|
|
||||||
if (*x == 'R') goto ok14;
|
|
||||||
return 1;
|
|
||||||
ok14:
|
|
||||||
|
|
||||||
puts ("t: *x++ == 'C'\n");
|
|
||||||
*x++ = c;
|
|
||||||
if (*g_chars == 'C') goto ok15;
|
|
||||||
return 1;
|
|
||||||
ok15:
|
|
||||||
|
|
||||||
puts ("t: itoa (33) == \"33\"\n");
|
|
||||||
if (strcmp (itoa (33), "33")) return 1;
|
|
||||||
|
|
||||||
puts ("strcmp (itoa (-1), \"-1\")\n");
|
|
||||||
if (strcmp (itoa (-1), "-1")) return 1;
|
|
||||||
|
|
||||||
puts ("strcmp (itoa (0), \"0\")\n");
|
|
||||||
if (strcmp (itoa (0), "0")) return 1;
|
|
||||||
|
|
||||||
puts ("strcmp (itoa (1), \"1\")\n");
|
|
||||||
if (strcmp (itoa (1), "1")) return 1;
|
|
||||||
|
|
||||||
puts ("void_func ()\n");
|
|
||||||
void_func ();
|
|
||||||
|
|
||||||
return string_test ();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int
|
|
||||||
main (int argc, char *argv[])
|
|
||||||
{
|
|
||||||
char *p = "t.c\n";
|
|
||||||
puts ("t.c\n");
|
|
||||||
|
|
||||||
puts ("t: argv[0] == \"scaffold/t....\"\n");
|
|
||||||
if (strncmp (argv[0], "scaffold/t", 5)) return 1;
|
|
||||||
|
|
||||||
puts ("t: *argv\"\n");
|
|
||||||
puts (*argv);
|
|
||||||
puts ("\n");
|
|
||||||
|
|
||||||
puts ("t: if (argc > 1 && !strcmp (argv[1], \"--help\")\n");
|
|
||||||
if (argc > 1 && !strcmp (argv[1], "--help")) return 1;
|
|
||||||
|
|
||||||
return test (p);
|
|
||||||
|
|
||||||
return 22;
|
|
||||||
}
|
|
33
scaffold/tests/00-exit-0.c
Normal file
33
scaffold/tests/00-exit-0.c
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
main ()
|
||||||
|
{
|
||||||
|
#if __MESC__
|
||||||
|
asm ("mov____$i32,%ebx %0");
|
||||||
|
asm ("mov____$i32,%eax SYS_exit");
|
||||||
|
asm ("int____$0x80");
|
||||||
|
#else // !__MESC__
|
||||||
|
asm ("mov $0,%ebx");
|
||||||
|
asm ("mov $1,%eax");
|
||||||
|
asm ("int $0x80");
|
||||||
|
#endif
|
||||||
|
}
|
27
scaffold/tests/01-return-0.c
Normal file
27
scaffold/tests/01-return-0.c
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "00-test.i"
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
27
scaffold/tests/02-return-1.c
Normal file
27
scaffold/tests/02-return-1.c
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "00-test.i"
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
33
scaffold/tests/03-call.c
Normal file
33
scaffold/tests/03-call.c
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "00-test.i"
|
||||||
|
|
||||||
|
int
|
||||||
|
test0 ()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
return test0 ();
|
||||||
|
}
|
33
scaffold/tests/04-call-0.c
Normal file
33
scaffold/tests/04-call-0.c
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "00-test.i"
|
||||||
|
|
||||||
|
int
|
||||||
|
testi (int t)
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
return testi (0);
|
||||||
|
}
|
33
scaffold/tests/05-call-1.c
Normal file
33
scaffold/tests/05-call-1.c
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "00-test.i"
|
||||||
|
|
||||||
|
int
|
||||||
|
testi (int t)
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
return testi (1);
|
||||||
|
}
|
33
scaffold/tests/06-call-!1.c
Normal file
33
scaffold/tests/06-call-!1.c
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "00-test.i"
|
||||||
|
|
||||||
|
int
|
||||||
|
testi (int t)
|
||||||
|
{
|
||||||
|
return !t;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
return testi (1);
|
||||||
|
}
|
28
scaffold/tests/10-if-0.c
Normal file
28
scaffold/tests/10-if-0.c
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "00-test.i"
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
if (0) return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
28
scaffold/tests/11-if-1.c
Normal file
28
scaffold/tests/11-if-1.c
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "00-test.i"
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
if (1) return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
28
scaffold/tests/12-if-==.c
Normal file
28
scaffold/tests/12-if-==.c
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "00-test.i"
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
if (0 == 0) return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
28
scaffold/tests/13-if-!=.c
Normal file
28
scaffold/tests/13-if-!=.c
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "00-test.i"
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
if (0 != 1) return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
33
scaffold/tests/14-if-goto.c
Normal file
33
scaffold/tests/14-if-goto.c
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "00-test.i"
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
if (0 == 0) goto ok;
|
||||||
|
return 1;
|
||||||
|
ok:
|
||||||
|
if (0 != 1) goto ok1;
|
||||||
|
return 1;
|
||||||
|
ok1:
|
||||||
|
return 0;
|
||||||
|
}
|
29
scaffold/tests/15-if-!f.c
Normal file
29
scaffold/tests/15-if-!f.c
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "00-test.i"
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
int t = 1;
|
||||||
|
if (t) return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
29
scaffold/tests/16-if-t.c
Normal file
29
scaffold/tests/16-if-t.c
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "00-test.i"
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
int t = 1;
|
||||||
|
if (t) return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
29
scaffold/tests/20-while.c
Normal file
29
scaffold/tests/20-while.c
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "00-test.i"
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
int v = 3;
|
||||||
|
while (v) v--;
|
||||||
|
return v;
|
||||||
|
}
|
34
scaffold/tests/21-char[].c
Normal file
34
scaffold/tests/21-char[].c
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "00-test.i"
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
int f;
|
||||||
|
int v = 3;
|
||||||
|
char *s = "mes";
|
||||||
|
if (!s[0]) return 1;
|
||||||
|
if (!s[f]) return 1;
|
||||||
|
if (s[3]) return 1;
|
||||||
|
if (s[v]) return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
31
scaffold/tests/22-while-char[].c
Normal file
31
scaffold/tests/22-while-char[].c
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "00-test.i"
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
char *s = "mes";
|
||||||
|
int i = 0;
|
||||||
|
while (s[i]) i++;
|
||||||
|
if (i != 3) return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
31
scaffold/tests/30-strlen.c
Normal file
31
scaffold/tests/30-strlen.c
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
if (strlen ("mes") == 3) goto ok;
|
||||||
|
return 1;
|
||||||
|
ok:
|
||||||
|
if (strlen ("mes") != 3) return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
30
scaffold/tests/31-eputs.c
Normal file
30
scaffold/tests/31-eputs.c
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
puts ("\n");
|
||||||
|
puts ("mes");
|
||||||
|
return 0;
|
||||||
|
}
|
122
scaffold/tests/32-compare.c
Normal file
122
scaffold/tests/32-compare.c
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
int f = 0;
|
||||||
|
int t = 1;
|
||||||
|
int one = t;
|
||||||
|
|
||||||
|
puts ("\n");
|
||||||
|
puts ("t: if (f)\n");
|
||||||
|
if (f) return 1;
|
||||||
|
|
||||||
|
puts ("t: if (one != 1)\n");
|
||||||
|
if (one != 1) return 1;
|
||||||
|
|
||||||
|
puts ("t: if (1 != one)\n");
|
||||||
|
if (1 != one) return 1;
|
||||||
|
|
||||||
|
puts ("t: if (one > 1)\n");
|
||||||
|
if (one > 1) return 1;
|
||||||
|
|
||||||
|
puts ("t: if (one < 0)\n");
|
||||||
|
if (one < 0) return 1;
|
||||||
|
|
||||||
|
puts ("t: if (one <= 0)\n");
|
||||||
|
if (one <= 0) return 1;
|
||||||
|
|
||||||
|
puts ("t: if (one >= 2)\n");
|
||||||
|
if (one >= 2) return 1;
|
||||||
|
|
||||||
|
puts ("t: if (!1)\n");
|
||||||
|
if (!1) return 1;
|
||||||
|
|
||||||
|
puts ("t: if (one == 0)\n");
|
||||||
|
if (one == 0) return 1;
|
||||||
|
|
||||||
|
puts ("t: if (f != 0)\n");
|
||||||
|
if (one != 1) return 1;
|
||||||
|
|
||||||
|
puts ("t: if (1)\n");
|
||||||
|
if (1) goto ok0;
|
||||||
|
return 1;
|
||||||
|
ok0:
|
||||||
|
|
||||||
|
puts ("t: if (0); return 1; else;\n");
|
||||||
|
if (0) return 1; else goto ok1;
|
||||||
|
ok1:
|
||||||
|
|
||||||
|
puts ("t: if (t)\n");
|
||||||
|
if (t) goto ok2;
|
||||||
|
return 1;
|
||||||
|
ok2:
|
||||||
|
|
||||||
|
puts ("t: if (one > 0)\n");
|
||||||
|
if (one > 0) goto ok3;
|
||||||
|
return 1;
|
||||||
|
ok3:
|
||||||
|
|
||||||
|
puts ("t: if (one < 2)\n");
|
||||||
|
if (one < 2) goto ok4;
|
||||||
|
return 1;
|
||||||
|
ok4:
|
||||||
|
|
||||||
|
puts ("t: if (one >= 0)\n");
|
||||||
|
if (one >= 0) goto ok5;
|
||||||
|
return 1;
|
||||||
|
ok5:
|
||||||
|
|
||||||
|
puts ("t: if (one >= 1)\n");
|
||||||
|
if (one >= 0) goto ok6;
|
||||||
|
return 1;
|
||||||
|
ok6:
|
||||||
|
|
||||||
|
puts ("t: if (one <= 2)\n");
|
||||||
|
if (one <= 2) goto ok7;
|
||||||
|
return 1;
|
||||||
|
ok7:
|
||||||
|
|
||||||
|
puts ("t: if (one <= 1)\n");
|
||||||
|
if (one <= 1) goto ok8;
|
||||||
|
return 1;
|
||||||
|
ok8:
|
||||||
|
|
||||||
|
puts ("t: if (!0)\n");
|
||||||
|
if (!0) goto ok9;
|
||||||
|
return 1;
|
||||||
|
ok9:
|
||||||
|
|
||||||
|
puts ("t: if (one == 1)\n");
|
||||||
|
if (one == 1) goto ok10;
|
||||||
|
return 1;
|
||||||
|
ok10:
|
||||||
|
|
||||||
|
puts ("t: if (one != 0)\n");
|
||||||
|
if (one != 0) goto ok11;
|
||||||
|
return 1;
|
||||||
|
ok11:
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
55
scaffold/tests/33-and-or.c
Normal file
55
scaffold/tests/33-and-or.c
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
int f = 0;
|
||||||
|
int t = 1;
|
||||||
|
int one = t;
|
||||||
|
|
||||||
|
puts ("\n");
|
||||||
|
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;
|
||||||
|
|
||||||
|
puts ("t: if (f || !t)\n");
|
||||||
|
if (f || !t) return 1;
|
||||||
|
|
||||||
|
puts ("t: if (1 && !0)\n");
|
||||||
|
if (1 && !0) goto ok0;
|
||||||
|
return 1;
|
||||||
|
ok0:
|
||||||
|
|
||||||
|
puts ("t: if (f || t)\n");
|
||||||
|
if (f || t) goto ok1;
|
||||||
|
return 1;
|
||||||
|
ok1:
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
58
scaffold/tests/34-pre-post.c
Normal file
58
scaffold/tests/34-pre-post.c
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
int f = 0;
|
||||||
|
int t = 1;
|
||||||
|
int one = t;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
puts ("\n");
|
||||||
|
puts ("t: if (i++)\n");
|
||||||
|
if (i++) return 1;
|
||||||
|
|
||||||
|
puts ("t: if (--i)\n");
|
||||||
|
if (--i) return 1;
|
||||||
|
|
||||||
|
puts ("t: i += 2\n");
|
||||||
|
i += 2;
|
||||||
|
if (i != 2) return 1;
|
||||||
|
|
||||||
|
puts ("t: i -= 2\n");
|
||||||
|
i -= 2;
|
||||||
|
if (i != 0) return 1;
|
||||||
|
|
||||||
|
puts ("t: if (++i)\n");
|
||||||
|
if (++i) goto ok0;
|
||||||
|
return 1;
|
||||||
|
ok0:
|
||||||
|
|
||||||
|
puts ("t: if (i--)\n");
|
||||||
|
if (i--) goto ok1;
|
||||||
|
return 1;
|
||||||
|
ok1:
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
92
scaffold/tests/35-compare-char.c
Normal file
92
scaffold/tests/35-compare-char.c
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
char g_arena[10];
|
||||||
|
char *g_chars = g_arena;
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
char c = 'C';
|
||||||
|
char *p = "mes";
|
||||||
|
char *x = g_arena;
|
||||||
|
char *y = g_chars;
|
||||||
|
|
||||||
|
puts ("\n");
|
||||||
|
puts ("t: p[0] != 'm'\n");
|
||||||
|
if (p[0] != 'm') return p[0];
|
||||||
|
|
||||||
|
puts ("t: p[i] != 't'\n");
|
||||||
|
if (p[i] != 'm') return p[i];
|
||||||
|
|
||||||
|
puts ("t: *g_chars != 'A'\n");
|
||||||
|
g_arena[0] = 'A';
|
||||||
|
if (*g_chars != 'A') return 1;
|
||||||
|
|
||||||
|
puts ("t: *x != 'A'\n");
|
||||||
|
if (*x != 'A') return 1;
|
||||||
|
|
||||||
|
puts ("t: *y != 'A'\n");
|
||||||
|
if (*y != 'A') return 1;
|
||||||
|
|
||||||
|
puts ("t: *x != 'Q'\n");
|
||||||
|
g_chars[0] = 'Q';
|
||||||
|
if (*x != 'Q') return 1;
|
||||||
|
|
||||||
|
puts ("t: *x++ != 'C'\n");
|
||||||
|
*x++ = c;
|
||||||
|
if (*g_chars != 'C') return 1;
|
||||||
|
|
||||||
|
puts ("t: *g_chars == 'B'\n");
|
||||||
|
g_arena[0] = 'B';
|
||||||
|
if (*g_chars == 'B') goto ok1;
|
||||||
|
return 1;
|
||||||
|
ok1:
|
||||||
|
|
||||||
|
puts ("t: *x == 'B'\n");
|
||||||
|
x = g_arena;
|
||||||
|
if (*x == 'B') goto ok2;
|
||||||
|
return 1;
|
||||||
|
ok2:
|
||||||
|
|
||||||
|
puts ("t: *y == 'B'\n");
|
||||||
|
y = g_chars;
|
||||||
|
if (*y == 'B') goto ok3;
|
||||||
|
return 1;
|
||||||
|
ok3:
|
||||||
|
|
||||||
|
puts ("t: *x == 'R'\n");
|
||||||
|
g_chars[0] = 'R';
|
||||||
|
if (*x == 'R') goto ok4;
|
||||||
|
return 1;
|
||||||
|
ok4:
|
||||||
|
|
||||||
|
puts ("t: *x++ == 'C'\n");
|
||||||
|
*x++ = c;
|
||||||
|
if (*g_chars == 'C') goto ok5;
|
||||||
|
return 1;
|
||||||
|
ok5:
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
44
scaffold/tests/36-compare-arithmetic.c
Normal file
44
scaffold/tests/36-compare-arithmetic.c
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
puts ("\n");
|
||||||
|
puts ("t: 1 + 2\n");
|
||||||
|
if (1 + 2 != 3) return 1;
|
||||||
|
|
||||||
|
puts ("t: 2 - 1\n");
|
||||||
|
if (2 - 1 != 1) return 1;
|
||||||
|
|
||||||
|
puts ("t: 1 << 3\n");
|
||||||
|
if (1 << 3 != 8) return 1;
|
||||||
|
|
||||||
|
puts ("t: 8 >> 3\n");
|
||||||
|
if (8 >> 3 != 1) return 1;
|
||||||
|
|
||||||
|
puts ("t: 8 / 4\n");
|
||||||
|
if (8 / 4 != 2) return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
45
scaffold/tests/37-compare-assign.c
Normal file
45
scaffold/tests/37-compare-assign.c
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
int f = 0;
|
||||||
|
int t = 1;
|
||||||
|
int one = t;
|
||||||
|
|
||||||
|
puts ("\n");
|
||||||
|
puts ("t: if (f = 0) ?\n");
|
||||||
|
if (f = 0) return 1;
|
||||||
|
|
||||||
|
puts ("t: if (!(t = 1)) ?\n");
|
||||||
|
if (!(t = 1)) return 1;
|
||||||
|
|
||||||
|
puts ("t: if ((f = 0) != 0) ?\n");
|
||||||
|
if ((f = 0) != 0) return 1;
|
||||||
|
|
||||||
|
puts ("t: if ((t = 1) != 1) ?\n");
|
||||||
|
if ((t = 1) != 1) return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
98
scaffold/tests/38-compare-call.c
Normal file
98
scaffold/tests/38-compare-call.c
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
enum type_t {TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART};
|
||||||
|
|
||||||
|
int
|
||||||
|
add (int a, int b)
|
||||||
|
{
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
inc (int i)
|
||||||
|
{
|
||||||
|
return i + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
identity (int i)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
int f = 0;
|
||||||
|
int t = 1;
|
||||||
|
int one = t;
|
||||||
|
char *p = "mes";
|
||||||
|
|
||||||
|
puts ("\n");
|
||||||
|
puts ("t: if (strlen (\"\"))\n");
|
||||||
|
if (strlen ("")) return 1;
|
||||||
|
|
||||||
|
puts ("t: if (strlen (p) != 3)\n");
|
||||||
|
if (strlen (p) != 3) return 1;
|
||||||
|
|
||||||
|
puts ("t: if (!strlen (\".\"))\n");
|
||||||
|
if (!strlen (".")) return 1;
|
||||||
|
|
||||||
|
puts ("t: identity (p[i]) != 'm'\n");
|
||||||
|
if (identity (p[i]) != 'm') return identity (p[i]);
|
||||||
|
|
||||||
|
puts ("t: inc (0)\n");
|
||||||
|
if (inc (0) != 1) return 1;
|
||||||
|
|
||||||
|
puts ("t: inc (inc (0))\n");
|
||||||
|
if (inc (inc (0)) != 2) return 1;
|
||||||
|
|
||||||
|
puts ("t: inc (inc (inc (0)))\n");
|
||||||
|
if (inc (inc (inc (0))) != 3) return 1;
|
||||||
|
|
||||||
|
puts ("t: add (1, 2)\n");
|
||||||
|
if (add (1, 2) != 3) return 1;
|
||||||
|
|
||||||
|
puts ("t: add (inc (0), inc (1))\n");
|
||||||
|
if (add (inc (0), inc (1)) != 3) return 1;
|
||||||
|
|
||||||
|
puts ("t: add (TSTRING, 3)\n");
|
||||||
|
if (add (TSTRING, 3) != 13) return 1;
|
||||||
|
|
||||||
|
puts ("t: add (inc (inc (0)), inc (inc (1)))\n");
|
||||||
|
if (add (inc (inc (0)), inc (inc (1))) != 5) return 1;
|
||||||
|
|
||||||
|
puts ("t: if (strlen (\".\"))\n");
|
||||||
|
if (strlen (".")) goto ok1;
|
||||||
|
return 1;
|
||||||
|
ok1:
|
||||||
|
|
||||||
|
puts ("t: if (strlen (p) == 3)\n");
|
||||||
|
if (strlen (p) == 3) goto ok2;
|
||||||
|
ok2:
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
43
scaffold/tests/40-if-else.c
Normal file
43
scaffold/tests/40-if-else.c
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
puts ("\n");
|
||||||
|
if (i)
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
puts ("t: else 1\n");
|
||||||
|
|
||||||
|
if (i)
|
||||||
|
puts ("0");
|
||||||
|
else if (i == 1)
|
||||||
|
puts ("1");
|
||||||
|
else
|
||||||
|
puts ("t: else if 2\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
39
scaffold/tests/41-?.c
Normal file
39
scaffold/tests/41-?.c
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
int f;
|
||||||
|
int t = 1;
|
||||||
|
int one = t;
|
||||||
|
|
||||||
|
puts ("\n");
|
||||||
|
puts ("t: (one == 1) ?\n");
|
||||||
|
(one == 1) ? 1 : exit (1);
|
||||||
|
|
||||||
|
puts ("t: (f) ?\n");
|
||||||
|
(f) ? exit (1) : 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
46
scaffold/tests/42-goto-label.c
Normal file
46
scaffold/tests/42-goto-label.c
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
label (int c)
|
||||||
|
{
|
||||||
|
label:
|
||||||
|
if (c == 0) return c;
|
||||||
|
c--;
|
||||||
|
goto label;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
int f;
|
||||||
|
int t = 1;
|
||||||
|
int one = t;
|
||||||
|
|
||||||
|
puts ("\n");
|
||||||
|
puts ("t: goto label\n");
|
||||||
|
if (label (1) != 0) return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
68
scaffold/tests/43-for-do-while.c
Normal file
68
scaffold/tests/43-for-do-while.c
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
int f = 0;
|
||||||
|
int t = 1;
|
||||||
|
int one = t;
|
||||||
|
char *p = "mes";
|
||||||
|
|
||||||
|
puts ("\n");
|
||||||
|
|
||||||
|
puts ("t: for (i=1; i<5; ++i)\n");
|
||||||
|
for (i=1; i<5; ++i);
|
||||||
|
if (i != 5) return i;
|
||||||
|
|
||||||
|
puts ("t: while (i<3) i++\n");
|
||||||
|
i = 1;
|
||||||
|
while (i<3) i++;
|
||||||
|
if (i != 3) return i;
|
||||||
|
|
||||||
|
puts ("t: do i-- while (i>0)\n");
|
||||||
|
do i--; while (i>0);
|
||||||
|
if (i != 0) return 1;
|
||||||
|
|
||||||
|
puts ("t: while (1) break;\n");
|
||||||
|
while (1) break;
|
||||||
|
|
||||||
|
puts ("t: while (1) ... break;\n");
|
||||||
|
while (1) {f=0;break;}
|
||||||
|
|
||||||
|
puts ("t: while (1) {while (1) break;break;}\n");
|
||||||
|
while (1) {while (1) break;break;}
|
||||||
|
|
||||||
|
puts ("t: while () {continue;...}\n");
|
||||||
|
while (one--) {continue;one=1;}
|
||||||
|
one += 2;
|
||||||
|
|
||||||
|
puts ("t: while (1) { goto label; };\n");
|
||||||
|
while (1) {
|
||||||
|
goto ok1;
|
||||||
|
}
|
||||||
|
ok1:
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
77
scaffold/tests/44-switch.c
Normal file
77
scaffold/tests/44-switch.c
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
enum type_t {TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART};
|
||||||
|
|
||||||
|
int
|
||||||
|
swits (int c)
|
||||||
|
{
|
||||||
|
int x = -1;
|
||||||
|
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case TCHAR: {goto next;}
|
||||||
|
case 1: {goto next;}
|
||||||
|
case 2: {goto next;}
|
||||||
|
default: {goto next;}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
next:
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
{
|
||||||
|
x = 0;
|
||||||
|
c = 34;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case -1:
|
||||||
|
case 1:
|
||||||
|
x = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
x = 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
puts ("\n");
|
||||||
|
puts ("t: switch 0\n");
|
||||||
|
if (swits (0) != 0) return swits (0);
|
||||||
|
|
||||||
|
puts ("t: switch 1\n");
|
||||||
|
if (swits (1) != 1) return 1;
|
||||||
|
|
||||||
|
puts ("t: switch -1\n");
|
||||||
|
if (swits (-1) != 1) return 1;
|
||||||
|
|
||||||
|
puts ("t: switch -1\n");
|
||||||
|
if (swits (-2) != 2) return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
37
scaffold/tests/45-void-call.c
Normal file
37
scaffold/tests/45-void-call.c
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void
|
||||||
|
void_func ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
puts ("\n");
|
||||||
|
puts ("void_func ()\n");
|
||||||
|
void_func ();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
38
scaffold/tests/50-assert.c
Normal file
38
scaffold/tests/50-assert.c
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
int f;
|
||||||
|
|
||||||
|
puts ("\n");
|
||||||
|
puts ("t: assert (1) ?\n");
|
||||||
|
assert (1);
|
||||||
|
|
||||||
|
puts ("t: assert (f==0) ?\n");
|
||||||
|
assert (f==0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
61
scaffold/tests/51-strcmp.c
Normal file
61
scaffold/tests/51-strcmp.c
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
char *p = "mes";
|
||||||
|
|
||||||
|
puts ("\n");
|
||||||
|
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, "mes")) return 1;
|
||||||
|
|
||||||
|
puts ("t: if (!strcmp (p, \"t.c\\n\"))\n");
|
||||||
|
if (!strcmp (p, "mes")) goto ok1;
|
||||||
|
return 1;
|
||||||
|
ok1:
|
||||||
|
|
||||||
|
puts ("t: if (strcmp (p, \"foo\"))\n");
|
||||||
|
if (strcmp (p, "foo")) goto ok2;
|
||||||
|
return 1;
|
||||||
|
ok2:
|
||||||
|
|
||||||
|
puts ("t: itoa (33) == \"33\"\n");
|
||||||
|
if (strcmp (itoa (33), "33")) return 1;
|
||||||
|
|
||||||
|
puts ("strcmp (itoa (-1), \"-1\")\n");
|
||||||
|
if (strcmp (itoa (-1), "-1")) return 1;
|
||||||
|
|
||||||
|
puts ("strcmp (itoa (0), \"0\")\n");
|
||||||
|
if (strcmp (itoa (0), "0")) return 1;
|
||||||
|
|
||||||
|
puts ("strcmp (itoa (1), \"1\")\n");
|
||||||
|
if (strcmp (itoa (1), "1")) return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
45
scaffold/tests/52-itoa.c
Normal file
45
scaffold/tests/52-itoa.c
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
#include <mlibc.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
char *p = "mes";
|
||||||
|
|
||||||
|
puts ("\n");
|
||||||
|
puts ("t: itoa (33) == \"33\"\n");
|
||||||
|
if (strcmp (itoa (33), "33")) return 1;
|
||||||
|
|
||||||
|
puts ("strcmp (itoa (-1), \"-1\")\n");
|
||||||
|
if (strcmp (itoa (-1), "-1")) return 1;
|
||||||
|
|
||||||
|
puts ("strcmp (itoa (0), \"0\")\n");
|
||||||
|
if (strcmp (itoa (0), "0")) return 1;
|
||||||
|
|
||||||
|
puts ("strcmp (itoa (1), \"1\")\n");
|
||||||
|
if (strcmp (itoa (1), "1")) return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
35
scaffold/tests/53-strcpy.c
Normal file
35
scaffold/tests/53-strcpy.c
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
puts ("\n");
|
||||||
|
puts ("t: strcpy (buf, \"mes\")\n");
|
||||||
|
char buf[10];
|
||||||
|
strcpy (buf, "mes");
|
||||||
|
if (strcmp (buf, "mes")) return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
39
scaffold/tests/54-argv.c
Normal file
39
scaffold/tests/54-argv.c
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
puts ("\n");
|
||||||
|
puts ("t: argv[0] == \"scaffold/test....\"\n");
|
||||||
|
if (strncmp (argv[0], "scaffold/test", 5)) return 1;
|
||||||
|
|
||||||
|
puts ("t: *argv\"\n");
|
||||||
|
puts (*argv);
|
||||||
|
puts ("\n");
|
||||||
|
|
||||||
|
puts ("t: if (argc > 1 && !strcmp (argv[1], \"--help\")\n");
|
||||||
|
if (argc > 1 && !strcmp (argv[1], "--help")) return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
147
scaffold/tests/60-math.c
Normal file
147
scaffold/tests/60-math.c
Normal file
|
@ -0,0 +1,147 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
|
||||||
|
int
|
||||||
|
add (int a, int b)
|
||||||
|
{
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
inc (int i)
|
||||||
|
{
|
||||||
|
return i + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
puts ("\n");
|
||||||
|
puts ("t: 0 < 0\n");
|
||||||
|
if (0 < 0) return 1;
|
||||||
|
|
||||||
|
puts ("t: 2 < 1\n");
|
||||||
|
if (2 < 1) return 1;
|
||||||
|
|
||||||
|
puts ("t: -1 < -2\n");
|
||||||
|
if (-1 < -2) return 1;
|
||||||
|
|
||||||
|
puts ("t: 0 < -1\n");
|
||||||
|
if (0 < -1) return 1;
|
||||||
|
|
||||||
|
puts ("t: 0 > 0\n");
|
||||||
|
if (0 > 0) return 1;
|
||||||
|
|
||||||
|
puts ("t: 1 > 2\n");
|
||||||
|
if (1 > 2) return 1;
|
||||||
|
|
||||||
|
puts ("t: -2 > -1\n");
|
||||||
|
if (-2 > -1) return 1;
|
||||||
|
|
||||||
|
puts ("t: -1 > 0\n");
|
||||||
|
if (-1 > 0) return 1;
|
||||||
|
|
||||||
|
puts ("t: 1 == inc (0)\n");
|
||||||
|
if (1 == inc (0)) goto ok0;
|
||||||
|
return 1;
|
||||||
|
ok0:
|
||||||
|
|
||||||
|
puts ("t: 0 < inc (0)\n");
|
||||||
|
if (0 < inc (0)) goto ok1;
|
||||||
|
return 1;
|
||||||
|
ok1:
|
||||||
|
|
||||||
|
puts ("t: inc (0) + 2 != 3\n");
|
||||||
|
if (inc (0) + inc (1) != 3) return 1;
|
||||||
|
|
||||||
|
puts ("t: 4/2=");
|
||||||
|
i = 4 / 2;
|
||||||
|
if (i!=2) return 1;
|
||||||
|
i += 48;
|
||||||
|
putchar (i);
|
||||||
|
puts ("\n");
|
||||||
|
|
||||||
|
puts ("t: 3*4=\n");
|
||||||
|
i = 3 * 4;
|
||||||
|
if (i!=12) return 1;
|
||||||
|
|
||||||
|
puts ("t: i /= 4\n");
|
||||||
|
i /= 4;
|
||||||
|
if (i!=3) return 1;
|
||||||
|
|
||||||
|
puts ("t: i *= 4\n");
|
||||||
|
i *= 4;
|
||||||
|
if (i!=12) return 1;
|
||||||
|
|
||||||
|
puts ("t: 1 << 3\n");
|
||||||
|
if (1 << 3 != 8) return 1 << 3;
|
||||||
|
|
||||||
|
puts ("t: 3 << 4\n");
|
||||||
|
if (3 << 4 != 48) return 3 << 4;
|
||||||
|
|
||||||
|
puts ("t: 48 >> 3\n");
|
||||||
|
if (48 >> 4 != 3) return 48 >> 4;
|
||||||
|
|
||||||
|
puts ("t: 10 >> 1\n");
|
||||||
|
if (10 >> 1 != 5) return 10 >> 1;
|
||||||
|
|
||||||
|
puts ("t: 1 | 4\n");
|
||||||
|
if ((1 | 4) != 5) return 1 | 4;
|
||||||
|
|
||||||
|
i = -3;
|
||||||
|
puts ("t: -i\n");
|
||||||
|
if (-i != 3) return 1;
|
||||||
|
|
||||||
|
puts ("t: -1 + 2\n");
|
||||||
|
if (-1 + 2 != 1) return 1;
|
||||||
|
|
||||||
|
puts ("t: 1 & 3\n");
|
||||||
|
if ((1 & 3) != 1) return 1;
|
||||||
|
|
||||||
|
puts ("t: 1 | 3\n");
|
||||||
|
if ((1 | 2) != 3) return 1;
|
||||||
|
|
||||||
|
puts ("t: ^ 1 \n");
|
||||||
|
if ((1 ^ 3) != 2) return 1;
|
||||||
|
|
||||||
|
puts ("t: 3 == 3\n");
|
||||||
|
if ((3 == 3) != 1) return 1;
|
||||||
|
|
||||||
|
puts ("t: 3 != 3\n");
|
||||||
|
if ((3 != 3) != 0) return 1;
|
||||||
|
|
||||||
|
puts ("t: 011 == 15\n");
|
||||||
|
if (011 != 9) return 1;
|
||||||
|
|
||||||
|
puts ("t: 0b11 == 3\n");
|
||||||
|
if (0b11 != 3) return 1;
|
||||||
|
|
||||||
|
puts ("t: 0x11 == 3\n");
|
||||||
|
if (0x11 != 17) return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
100
scaffold/tests/61-array.c
Normal file
100
scaffold/tests/61-array.c
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <mlibc.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char *env[] = {"foo", "bar", "baz", 0};
|
||||||
|
|
||||||
|
int
|
||||||
|
test (char **e)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
puts ("\n");
|
||||||
|
puts ("a[i] = i-1\n");
|
||||||
|
int a[3];
|
||||||
|
for (int i=0; i < 3; i++) a[i] = i-1;
|
||||||
|
for (int i=0; i < 3; i++) if (a[i] != i-1) return 1;
|
||||||
|
|
||||||
|
puts ("env [");
|
||||||
|
puts (itoa ((int)env));
|
||||||
|
puts ("]\n");
|
||||||
|
|
||||||
|
puts ("e [");
|
||||||
|
puts (itoa ((int)e));
|
||||||
|
puts ("]\n");
|
||||||
|
|
||||||
|
puts ("env [0] == \"foo\"\n");
|
||||||
|
if (strcmp (env[0], "foo")) return 1;
|
||||||
|
|
||||||
|
puts ("env [1] == \"bar\"\n");
|
||||||
|
if (strcmp (env[1], "bar")) return 1;
|
||||||
|
|
||||||
|
puts ("t: **p in *env[]\n");
|
||||||
|
|
||||||
|
char **pp = env;
|
||||||
|
while (*pp)
|
||||||
|
{
|
||||||
|
puts ("pp [");
|
||||||
|
puts (itoa ((int)pp));
|
||||||
|
puts ("]: ");
|
||||||
|
if (*pp) puts (*pp);
|
||||||
|
puts ("\n");
|
||||||
|
pp++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (i != 3) return i;
|
||||||
|
|
||||||
|
pp = env;
|
||||||
|
puts ("t: *pp++ == \"foo\"\n");
|
||||||
|
if (strcmp (*pp++, "foo")) return 1;
|
||||||
|
|
||||||
|
puts ("t: *pp++ == \"bar\"\n");
|
||||||
|
if (strcmp (*pp++, "bar")) return 1;
|
||||||
|
|
||||||
|
char *buf = "hello";
|
||||||
|
puts ("t: buf[0]\n");
|
||||||
|
if (buf[0] != 'h') return 1;
|
||||||
|
|
||||||
|
puts ("t: buf + 1\n");
|
||||||
|
if (*(buf+1) != 'e') return 1;
|
||||||
|
|
||||||
|
char **p = &buf;
|
||||||
|
puts ("t: **p\n");
|
||||||
|
if (**p != 'h') return 1;
|
||||||
|
|
||||||
|
puts ("t: *(p + 1)\n");
|
||||||
|
if (*(*p + 1) != 'e') return 1;
|
||||||
|
|
||||||
|
puts ("t: getenv ()");
|
||||||
|
if (!getenv ("PATH")) return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
return test (env);
|
||||||
|
}
|
248
scaffold/tests/63-struct-cell.c
Normal file
248
scaffold/tests/63-struct-cell.c
Normal file
|
@ -0,0 +1,248 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
add (int a, int b)
|
||||||
|
{
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
inc (int i)
|
||||||
|
{
|
||||||
|
return i + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct scm {
|
||||||
|
int type;
|
||||||
|
int car;
|
||||||
|
int cdr;
|
||||||
|
};
|
||||||
|
|
||||||
|
int bla = 1234;
|
||||||
|
char g_arena[84];
|
||||||
|
#if __MESC__
|
||||||
|
struct scm *g_cells = g_arena;
|
||||||
|
#else
|
||||||
|
struct scm *g_cells = (struct scm*)g_arena;
|
||||||
|
#endif
|
||||||
|
char *g_chars = g_arena;
|
||||||
|
|
||||||
|
int foo () {puts ("t: foo\n"); return 0;};
|
||||||
|
int bar (int i) {puts ("t: bar\n"); return 0;};
|
||||||
|
struct function {
|
||||||
|
int (*function) (void);
|
||||||
|
int arity;
|
||||||
|
char *name;
|
||||||
|
};
|
||||||
|
struct function g_fun = {&exit,1,"fun"};
|
||||||
|
struct function g_foo = {&foo,0,"foo"};
|
||||||
|
struct function g_bar = {&bar,1,"bar"};
|
||||||
|
|
||||||
|
//void *functions[2];
|
||||||
|
int functions[2];
|
||||||
|
|
||||||
|
struct function g_functions[2];
|
||||||
|
int g_function = 0;
|
||||||
|
|
||||||
|
enum type_t {TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART};
|
||||||
|
|
||||||
|
typedef int SCM;
|
||||||
|
int g_free = 3;
|
||||||
|
SCM tmp;
|
||||||
|
SCM tmp_num;
|
||||||
|
|
||||||
|
int ARENA_SIZE = 200;
|
||||||
|
#define TYPE(x) g_cells[x].type
|
||||||
|
#define CAR(x) g_cells[x].car
|
||||||
|
#define CDR(x) g_cells[x].cdr
|
||||||
|
#define VALUE(x) g_cells[x].cdr
|
||||||
|
|
||||||
|
#define CAAR(x) CAR (CAR (x))
|
||||||
|
|
||||||
|
struct scm scm_fun = {TFUNCTION,0,0};
|
||||||
|
SCM cell_fun;
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
puts ("\n");
|
||||||
|
puts ("t: g_cells[0] = g_cells[1]\n");
|
||||||
|
TYPE (1) = 1;
|
||||||
|
CAR (1) = 2;
|
||||||
|
CDR (1) = 3;
|
||||||
|
g_cells[0] = g_cells[1];
|
||||||
|
if (TYPE (0) != 1) return 1;
|
||||||
|
if (CAR (0) != 2) return 2;
|
||||||
|
if (CDR (0) != 3) return 3;
|
||||||
|
|
||||||
|
puts ("t: g_cells[i] = g_cells[j]\n");
|
||||||
|
int i = 0;
|
||||||
|
int j = 1;
|
||||||
|
TYPE (1) = 4;
|
||||||
|
CAR (1) = 5;
|
||||||
|
CDR (1) = 6;
|
||||||
|
g_cells[i] = g_cells[j];
|
||||||
|
if (TYPE (0) != 4) return 1;
|
||||||
|
if (CAR (0) != 5) return 2;
|
||||||
|
if (CDR (0) != 6) return 3;
|
||||||
|
|
||||||
|
puts ("t: g_cells[0+add(0,0] = g_cells[0+inc(0)]\n");
|
||||||
|
TYPE (1) = 1;
|
||||||
|
CAR (1) = 2;
|
||||||
|
CDR (1) = 3;
|
||||||
|
g_cells[0+add(0, 0)] = g_cells[0+inc(0)];
|
||||||
|
if (TYPE (0) != 1) return 1;
|
||||||
|
if (CAR (0) != 2) return 2;
|
||||||
|
if (CDR (0) != 3) return 3;
|
||||||
|
|
||||||
|
g_cells[0].type = TNUMBER;
|
||||||
|
g_cells[0].car = 0;
|
||||||
|
g_cells[0].cdr = 0;
|
||||||
|
g_cells[1].type = TNUMBER;
|
||||||
|
g_cells[1].car = 0;
|
||||||
|
g_cells[1].cdr = 0;
|
||||||
|
|
||||||
|
puts ("t: TYPE (0) != TYPE (1)\n");
|
||||||
|
if (TYPE (0) == TYPE (1)) goto ok;
|
||||||
|
return 1;
|
||||||
|
ok:
|
||||||
|
|
||||||
|
g_cells[0].car = 1;
|
||||||
|
g_cells[1].car = 2;
|
||||||
|
|
||||||
|
puts ("t: int c = VALUE (0)\n");
|
||||||
|
int c = CAR (0);
|
||||||
|
if (c != 1) return 1;
|
||||||
|
|
||||||
|
puts ("t: CAAR (0) != 2\n");
|
||||||
|
if (CAAR (0) != 2) return 1;
|
||||||
|
|
||||||
|
puts ("t: 2 != CAAR (0)\n");
|
||||||
|
if (2 != CAAR (0)) return 1;
|
||||||
|
|
||||||
|
g_cells[3].type = 0x64;
|
||||||
|
if (g_cells[3].type != 0x64)
|
||||||
|
return g_cells[3].type;
|
||||||
|
|
||||||
|
TYPE (4) = 4;
|
||||||
|
if (TYPE (4) != 4)
|
||||||
|
return 4;
|
||||||
|
|
||||||
|
CDR (3) = 0x22;
|
||||||
|
CDR (4) = 0x23;
|
||||||
|
if (CDR (3) != 0x22)
|
||||||
|
return CDR (3);
|
||||||
|
|
||||||
|
puts ("t: g_fun.arity != 1;\n");
|
||||||
|
if (g_fun.arity != 1) return 1;
|
||||||
|
|
||||||
|
puts ("t: g_fun.function != exit;\n");
|
||||||
|
if (g_fun.function != &exit) return 1;
|
||||||
|
|
||||||
|
puts ("t: struct fun = {&exit,1,\"exit\"};\n");
|
||||||
|
struct function fun = {&exit,1,"exit"};
|
||||||
|
|
||||||
|
puts ("t: fun.arity != 1;\n");
|
||||||
|
if (fun.arity != 1) return 1;
|
||||||
|
|
||||||
|
puts ("t: fun.function != exit;\n");
|
||||||
|
if (fun.function != &exit) return 1;
|
||||||
|
|
||||||
|
puts ("t: puts (fun.name)\n");
|
||||||
|
if (strcmp (fun.name, "exit")) return 1;
|
||||||
|
|
||||||
|
puts ("t: puts (g_fun.name)\n");
|
||||||
|
if (strcmp (g_fun.name, "fun")) return 1;
|
||||||
|
|
||||||
|
puts ("t: g_functions[g_function++] = g_foo;\n");
|
||||||
|
g_functions[g_function++] = g_foo;
|
||||||
|
|
||||||
|
puts ("t: pbar->arity == 1\n");
|
||||||
|
struct function* barp = &g_bar;
|
||||||
|
if (barp->arity != 1) return 1;
|
||||||
|
|
||||||
|
int fn = 0;
|
||||||
|
puts ("t: g_functions[g_cells[fn].cdr].arity\n");
|
||||||
|
if (g_functions[g_cells[fn].cdr].arity) return 1;
|
||||||
|
if (g_functions[g_cells[fn].cdr].arity != 0) return 1;
|
||||||
|
|
||||||
|
int (*functionx) (void) = 0;
|
||||||
|
functionx = g_functions[0].function;
|
||||||
|
puts ("t: functionx == foo\n");
|
||||||
|
if (functionx != foo) return 11;
|
||||||
|
|
||||||
|
puts ("t: g_functions[0].name\n");
|
||||||
|
if (strcmp (g_functions[0].name, "foo")) return 1;
|
||||||
|
|
||||||
|
puts ("t: (functionx) () == foo\n");
|
||||||
|
if ((functionx) () != 0) return 12;
|
||||||
|
|
||||||
|
puts ("t: g_functions[<foo>].arity\n");
|
||||||
|
if (g_functions[0].arity != 0) return 17;
|
||||||
|
|
||||||
|
fn++;
|
||||||
|
g_functions[fn] = g_bar;
|
||||||
|
g_cells[fn].cdr = fn;
|
||||||
|
if (g_cells[fn].cdr != fn) return 13;
|
||||||
|
|
||||||
|
puts ("t: g_functions[g_cells[fn].cdr].function\n");
|
||||||
|
functionx = g_functions[g_cells[fn].cdr].function;
|
||||||
|
|
||||||
|
puts ("t: g_functions[1].name\n");
|
||||||
|
if (strcmp (g_functions[1].name, "bar")) return 1;
|
||||||
|
|
||||||
|
puts ("t: functionx == bar\n");
|
||||||
|
if (functionx != bar) return 15;
|
||||||
|
|
||||||
|
puts ("t: (functiony) (1) == bar\n");
|
||||||
|
int (*functiony) (int) = 0;
|
||||||
|
functiony = g_functions[g_cells[fn].cdr].function;
|
||||||
|
if ((functiony) (1) != 0) return 16;
|
||||||
|
|
||||||
|
puts ("t: g_functions[<bar>].arity\n");
|
||||||
|
if (g_functions[fn].arity != 1) return 18;
|
||||||
|
|
||||||
|
// fake name
|
||||||
|
scm_fun.car = 33;
|
||||||
|
scm_fun.cdr = g_function;
|
||||||
|
//g_functions[g_function++] = g_fun;
|
||||||
|
g_functions[g_function] = g_fun;
|
||||||
|
cell_fun = g_free++;
|
||||||
|
g_cells[cell_fun] = scm_fun;
|
||||||
|
|
||||||
|
puts ("t: TYPE (cell_fun)\n");
|
||||||
|
if (TYPE (cell_fun) != TFUNCTION) return 1;
|
||||||
|
|
||||||
|
puts ("t: CAR (cell_fun)\n");
|
||||||
|
if (CAR (cell_fun) != 33) return 1;
|
||||||
|
|
||||||
|
puts ("t: CDR (cell_fun)\n");
|
||||||
|
if (CDR (cell_fun) != g_function) return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
133
scaffold/tests/64-make-cell.c
Normal file
133
scaffold/tests/64-make-cell.c
Normal file
|
@ -0,0 +1,133 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
struct scm {
|
||||||
|
int type;
|
||||||
|
int car;
|
||||||
|
int cdr;
|
||||||
|
};
|
||||||
|
|
||||||
|
int bla = 1234;
|
||||||
|
char g_arena[84];
|
||||||
|
#if __MESC__
|
||||||
|
struct scm *g_cells = g_arena;
|
||||||
|
#else
|
||||||
|
struct scm *g_cells = (struct scm*)g_arena;
|
||||||
|
#endif
|
||||||
|
char *g_chars = g_arena;
|
||||||
|
|
||||||
|
int foo () {puts ("t: foo\n"); return 0;};
|
||||||
|
int bar (int i) {puts ("t: bar\n"); return 0;};
|
||||||
|
struct function {
|
||||||
|
int (*function) (void);
|
||||||
|
int arity;
|
||||||
|
char *name;
|
||||||
|
};
|
||||||
|
struct function g_fun = {&exit,1,"fun"};
|
||||||
|
struct function g_foo = {&foo,0,"foo"};
|
||||||
|
struct function g_bar = {&bar,1,"bar"};
|
||||||
|
|
||||||
|
//void *functions[2];
|
||||||
|
int functions[2];
|
||||||
|
|
||||||
|
struct function g_functions[2];
|
||||||
|
int g_function = 0;
|
||||||
|
|
||||||
|
enum type_t {TCHAR, TCLOSURE, TCONTINUATION, TFUNCTION, TKEYWORD, TMACRO, TNUMBER, TPAIR, TREF, TSPECIAL, TSTRING, TSYMBOL, TVALUES, TVECTOR, TBROKEN_HEART};
|
||||||
|
|
||||||
|
typedef int SCM;
|
||||||
|
int g_free = 3;
|
||||||
|
SCM tmp;
|
||||||
|
SCM tmp_num;
|
||||||
|
|
||||||
|
int ARENA_SIZE = 200;
|
||||||
|
#define TYPE(x) g_cells[x].type
|
||||||
|
#define CAR(x) g_cells[x].car
|
||||||
|
#define CDR(x) g_cells[x].cdr
|
||||||
|
#define VALUE(x) g_cells[x].cdr
|
||||||
|
|
||||||
|
#define CAAR(x) CAR (CAR (x))
|
||||||
|
|
||||||
|
struct scm scm_fun = {TFUNCTION,0,0};
|
||||||
|
SCM cell_fun;
|
||||||
|
|
||||||
|
SCM
|
||||||
|
alloc (int n)
|
||||||
|
{
|
||||||
|
SCM x = g_free;
|
||||||
|
g_free += n;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
SCM
|
||||||
|
make_cell (SCM type, SCM car, SCM cdr)
|
||||||
|
{
|
||||||
|
SCM x = alloc (1);
|
||||||
|
TYPE (x) = VALUE (type);
|
||||||
|
if (VALUE (type) == TCHAR || VALUE (type) == TNUMBER) {
|
||||||
|
if (car) CAR (x) = CAR (car);
|
||||||
|
if (cdr) CDR(x) = CDR(cdr);
|
||||||
|
}
|
||||||
|
else if (VALUE (type) == TFUNCTION) {
|
||||||
|
if (car) CAR (x) = car;
|
||||||
|
if (cdr) CDR(x) = CDR(cdr);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
CAR (x) = car;
|
||||||
|
CDR(x) = cdr;
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
SCM
|
||||||
|
make_cell_test ()
|
||||||
|
{
|
||||||
|
VALUE (tmp_num) = TPAIR;
|
||||||
|
make_cell (tmp_num, 0, 1);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SCM
|
||||||
|
make_tmps_test (struct scm* cells)
|
||||||
|
{
|
||||||
|
puts ("t: tmp = g_free++\n");
|
||||||
|
tmp = g_free++;
|
||||||
|
puts ("t: cells[tmp].type = CHAR\n");
|
||||||
|
cells[tmp].type = TCHAR;
|
||||||
|
tmp_num = g_free++;
|
||||||
|
cells[tmp_num].type = TNUMBER;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
puts ("\n");
|
||||||
|
make_tmps_test (g_cells);
|
||||||
|
make_cell_test ();
|
||||||
|
return 0;
|
||||||
|
}
|
79
scaffold/tests/65-read.c
Normal file
79
scaffold/tests/65-read.c
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char g_arena[84];
|
||||||
|
#if __MESC__
|
||||||
|
struct scm *g_cells = g_arena;
|
||||||
|
#else
|
||||||
|
struct scm *g_cells = (struct scm*)g_arena;
|
||||||
|
#endif
|
||||||
|
char *g_chars = g_arena;
|
||||||
|
|
||||||
|
int g = 48;
|
||||||
|
int
|
||||||
|
get ()
|
||||||
|
{
|
||||||
|
int i = g;
|
||||||
|
g++;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
char *p = (char*)g_chars;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
puts ("\n: ");
|
||||||
|
puts ("t: read 0123456789\nt: ");
|
||||||
|
int c = get ();
|
||||||
|
while (i < 10) {
|
||||||
|
*p++ = c;
|
||||||
|
putchar (c);
|
||||||
|
c = get ();
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
puts ("\n");
|
||||||
|
if (strcmp (g_chars, "0123456789")) return 1;
|
||||||
|
|
||||||
|
puts ("t: ungetc ('A') == getchar ()\n");
|
||||||
|
ungetc ('A', STDIN);
|
||||||
|
if (getchar () != 'A') return 1;
|
||||||
|
ungetc (0, STDIN);
|
||||||
|
//ungetc ('\1', STDIN);
|
||||||
|
ungetc (1, STDIN);
|
||||||
|
puts ("t: ungetc ();ungetc ();getchar ();getchar ()\n");
|
||||||
|
if (getchar () != 1) return 1;
|
||||||
|
//if (getchar () != '\0') return 1;
|
||||||
|
if (getchar () != 0) return 1;
|
||||||
|
|
||||||
|
puts ("t: i == 'm'\n");
|
||||||
|
char m = 0x1122336d;
|
||||||
|
i = m;
|
||||||
|
if (i != 'm') return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
46
scaffold/tests/70-printf.c
Normal file
46
scaffold/tests/70-printf.c
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
char *s = "mes";
|
||||||
|
char c = 'm';
|
||||||
|
int i = 3;
|
||||||
|
char buf[10];
|
||||||
|
|
||||||
|
printf ("c=%c\n", c);
|
||||||
|
sprintf (buf, "c=%c\n", c);
|
||||||
|
if (strcmp (buf, "c=m\n")) return 1;
|
||||||
|
|
||||||
|
printf ("i=%d\n", i);
|
||||||
|
sprintf (buf, "i=%d\n", i);
|
||||||
|
if (strcmp (buf, "i=3\n")) return 1;
|
||||||
|
|
||||||
|
printf ("s=%s\n", s);
|
||||||
|
sprintf (buf, "s=%s\n", s);
|
||||||
|
if (strcmp (buf, "s=mes\n")) return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -18,6 +18,7 @@
|
||||||
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
struct foo;
|
struct foo;
|
||||||
|
@ -30,7 +31,7 @@ struct foo
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
test ()
|
||||||
{
|
{
|
||||||
//struct foo f;
|
//struct foo f;
|
||||||
foo_struct f;
|
foo_struct f;
|
Loading…
Reference in a new issue