mescc: Beginning of expression and test template.
* scaffold/t.c: New file.
* GNUmakefile (mescc-check, t-check): New targets.
* module/language/c99/compiler.mes (write-any): Catch weirdness.
(make): Add <function> slot.
(.function): New accessor.
(clone): Handle it.
(function->info): Set it.
(ast->info): Make tests generic in if, for, while. Add goto, label,
!, ==, !=, -, &&.
* module/mes/elf-util.mes (lambda/label->list): New function.
(text->list): Use it.
(functions->text, function-prefix): New function.
(function-offset): Use it.
(label-offset): New function.
* module/mes/elf-util.scm (mes): Export them.
* module/mes/elf.mes (make-elf): Use text->list.
* module/mes/libc-i386.mes (eputs, puts): Remove.
(i386:byte-base-sub): Rename from sub-byte-base.
(i386:byte-jump-z): Rename from i386:Xjump-byte-z.
(i386:byte-mem->accu): Rename from i386:Xmem-byte->accu.
(i386:byte-mem->base): Rename from i386:Xmem-byte->base.
(i386:accu->local, i386:accu-non-zero?, i386:accu-zero?,
i386:base-sub, i386:byte-sub-base, i386:jump-c, i386:jump-cz,
i386:jump-nc, i386:jump-ncz, i386:byte-mem->base, i386:sub-base,
i386:test-accu, i386:test-base, i386:test-jump-z, i386:value->base,
i386:xor-zf): New functions.
2017-04-02 10:23:00 +00:00
|
|
|
/* -*-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/>.
|
|
|
|
*/
|
2017-01-05 20:24:56 +00:00
|
|
|
|
mescc: Beginning of expression and test template.
* scaffold/t.c: New file.
* GNUmakefile (mescc-check, t-check): New targets.
* module/language/c99/compiler.mes (write-any): Catch weirdness.
(make): Add <function> slot.
(.function): New accessor.
(clone): Handle it.
(function->info): Set it.
(ast->info): Make tests generic in if, for, while. Add goto, label,
!, ==, !=, -, &&.
* module/mes/elf-util.mes (lambda/label->list): New function.
(text->list): Use it.
(functions->text, function-prefix): New function.
(function-offset): Use it.
(label-offset): New function.
* module/mes/elf-util.scm (mes): Export them.
* module/mes/elf.mes (make-elf): Use text->list.
* module/mes/libc-i386.mes (eputs, puts): Remove.
(i386:byte-base-sub): Rename from sub-byte-base.
(i386:byte-jump-z): Rename from i386:Xjump-byte-z.
(i386:byte-mem->accu): Rename from i386:Xmem-byte->accu.
(i386:byte-mem->base): Rename from i386:Xmem-byte->base.
(i386:accu->local, i386:accu-non-zero?, i386:accu-zero?,
i386:base-sub, i386:byte-sub-base, i386:jump-c, i386:jump-cz,
i386:jump-nc, i386:jump-ncz, i386:byte-mem->base, i386:sub-base,
i386:test-accu, i386:test-base, i386:test-jump-z, i386:value->base,
i386:xor-zf): New functions.
2017-04-02 10:23:00 +00:00
|
|
|
#if __GNUC__
|
2017-01-08 16:51:40 +00:00
|
|
|
void
|
|
|
|
exit (int code)
|
|
|
|
{
|
|
|
|
asm (
|
|
|
|
"movl %0,%%ebx\n\t"
|
|
|
|
"movl $1,%%eax\n\t"
|
|
|
|
"int $0x80"
|
|
|
|
: // no outputs "=" (r)
|
|
|
|
: "" (code)
|
|
|
|
);
|
|
|
|
// not reached
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
2017-01-05 20:24:56 +00:00
|
|
|
void
|
|
|
|
write (int fd, char const* s, int n)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
//syscall (SYS_write, fd, s, n));
|
|
|
|
asm (
|
2017-01-08 16:51:40 +00:00
|
|
|
"mov %0,%%ebx\n\t"
|
|
|
|
"mov %1,%%ecx\n\t"
|
|
|
|
"mov %2,%%edx\n\t"
|
2017-01-05 20:24:56 +00:00
|
|
|
|
|
|
|
"mov $0x4, %%eax\n\t"
|
|
|
|
"int $0x80\n\t"
|
|
|
|
: // no outputs "=" (r)
|
|
|
|
: "" (fd), "" (s), "" (n)
|
|
|
|
: "eax", "ebx", "ecx", "edx"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define STDOUT 1
|
|
|
|
|
|
|
|
typedef long size_t;
|
|
|
|
size_t
|
|
|
|
strlen (char const* s)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
while (s[i]) i++;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
puts (char const* s)
|
|
|
|
{
|
|
|
|
//write (STDOUT, s, strlen (s));
|
|
|
|
//int i = write (STDOUT, s, strlen (s));
|
|
|
|
int i = strlen (s);
|
|
|
|
write (1, s, i);
|
|
|
|
return 0;
|
|
|
|
}
|
mescc: Beginning of expression and test template.
* scaffold/t.c: New file.
* GNUmakefile (mescc-check, t-check): New targets.
* module/language/c99/compiler.mes (write-any): Catch weirdness.
(make): Add <function> slot.
(.function): New accessor.
(clone): Handle it.
(function->info): Set it.
(ast->info): Make tests generic in if, for, while. Add goto, label,
!, ==, !=, -, &&.
* module/mes/elf-util.mes (lambda/label->list): New function.
(text->list): Use it.
(functions->text, function-prefix): New function.
(function-offset): Use it.
(label-offset): New function.
* module/mes/elf-util.scm (mes): Export them.
* module/mes/elf.mes (make-elf): Use text->list.
* module/mes/libc-i386.mes (eputs, puts): Remove.
(i386:byte-base-sub): Rename from sub-byte-base.
(i386:byte-jump-z): Rename from i386:Xjump-byte-z.
(i386:byte-mem->accu): Rename from i386:Xmem-byte->accu.
(i386:byte-mem->base): Rename from i386:Xmem-byte->base.
(i386:accu->local, i386:accu-non-zero?, i386:accu-zero?,
i386:base-sub, i386:byte-sub-base, i386:jump-c, i386:jump-cz,
i386:jump-nc, i386:jump-ncz, i386:byte-mem->base, i386:sub-base,
i386:test-accu, i386:test-base, i386:test-jump-z, i386:value->base,
i386:xor-zf): New functions.
2017-04-02 10:23:00 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
strcmp (char const* a, char const* b)
|
|
|
|
{
|
|
|
|
while (*a && *b && *a == *b) {a++;b++;}
|
|
|
|
return *a - *b;
|
|
|
|
}
|
2017-01-05 20:24:56 +00:00
|
|
|
#endif
|
|
|
|
|
2016-12-31 08:03:07 +00:00
|
|
|
int
|
mescc: Beginning of expression and test template.
* scaffold/t.c: New file.
* GNUmakefile (mescc-check, t-check): New targets.
* module/language/c99/compiler.mes (write-any): Catch weirdness.
(make): Add <function> slot.
(.function): New accessor.
(clone): Handle it.
(function->info): Set it.
(ast->info): Make tests generic in if, for, while. Add goto, label,
!, ==, !=, -, &&.
* module/mes/elf-util.mes (lambda/label->list): New function.
(text->list): Use it.
(functions->text, function-prefix): New function.
(function-offset): Use it.
(label-offset): New function.
* module/mes/elf-util.scm (mes): Export them.
* module/mes/elf.mes (make-elf): Use text->list.
* module/mes/libc-i386.mes (eputs, puts): Remove.
(i386:byte-base-sub): Rename from sub-byte-base.
(i386:byte-jump-z): Rename from i386:Xjump-byte-z.
(i386:byte-mem->accu): Rename from i386:Xmem-byte->accu.
(i386:byte-mem->base): Rename from i386:Xmem-byte->base.
(i386:accu->local, i386:accu-non-zero?, i386:accu-zero?,
i386:base-sub, i386:byte-sub-base, i386:jump-c, i386:jump-cz,
i386:jump-nc, i386:jump-ncz, i386:byte-mem->base, i386:sub-base,
i386:test-accu, i386:test-base, i386:test-jump-z, i386:value->base,
i386:xor-zf): New functions.
2017-04-02 10:23:00 +00:00
|
|
|
//main ()
|
|
|
|
main (int argc, char *argv[])
|
2016-07-24 21:18:53 +00:00
|
|
|
{
|
2016-08-14 07:06:09 +00:00
|
|
|
puts ("Hi Mes!\n");
|
2017-01-08 16:51:40 +00:00
|
|
|
if (argc > 1 && !strcmp (argv[1], "--help")) return puts ("argc > 1 && --help\n");
|
2016-12-17 09:57:38 +00:00
|
|
|
return 42;
|
2016-07-24 21:18:53 +00:00
|
|
|
}
|
2017-01-05 20:24:56 +00:00
|
|
|
|
|
|
|
#if __GNUC__
|
|
|
|
void
|
|
|
|
_start ()
|
|
|
|
{
|
mescc: Beginning of expression and test template.
* scaffold/t.c: New file.
* GNUmakefile (mescc-check, t-check): New targets.
* module/language/c99/compiler.mes (write-any): Catch weirdness.
(make): Add <function> slot.
(.function): New accessor.
(clone): Handle it.
(function->info): Set it.
(ast->info): Make tests generic in if, for, while. Add goto, label,
!, ==, !=, -, &&.
* module/mes/elf-util.mes (lambda/label->list): New function.
(text->list): Use it.
(functions->text, function-prefix): New function.
(function-offset): Use it.
(label-offset): New function.
* module/mes/elf-util.scm (mes): Export them.
* module/mes/elf.mes (make-elf): Use text->list.
* module/mes/libc-i386.mes (eputs, puts): Remove.
(i386:byte-base-sub): Rename from sub-byte-base.
(i386:byte-jump-z): Rename from i386:Xjump-byte-z.
(i386:byte-mem->accu): Rename from i386:Xmem-byte->accu.
(i386:byte-mem->base): Rename from i386:Xmem-byte->base.
(i386:accu->local, i386:accu-non-zero?, i386:accu-zero?,
i386:base-sub, i386:byte-sub-base, i386:jump-c, i386:jump-cz,
i386:jump-nc, i386:jump-ncz, i386:byte-mem->base, i386:sub-base,
i386:test-accu, i386:test-base, i386:test-jump-z, i386:value->base,
i386:xor-zf): New functions.
2017-04-02 10:23:00 +00:00
|
|
|
// int r=main ();
|
|
|
|
// exit (r);
|
|
|
|
int r;
|
|
|
|
asm (
|
|
|
|
"mov %%ebp,%%eax\n\t"
|
|
|
|
"addl $8,%%eax\n\t"
|
|
|
|
"push %%eax\n\t"
|
|
|
|
|
|
|
|
"mov %%ebp,%%eax\n\t"
|
|
|
|
"addl $4,%%eax\n\t"
|
|
|
|
"movzbl (%%eax),%%eax\n\t"
|
|
|
|
"push %%eax\n\t"
|
|
|
|
|
|
|
|
"call main\n\t"
|
|
|
|
"movl %%eax,%0\n\t"
|
|
|
|
: "=r" (r)
|
|
|
|
: //no inputs "" (&main)
|
|
|
|
);
|
2017-01-05 20:24:56 +00:00
|
|
|
exit (r);
|
|
|
|
}
|
|
|
|
#endif
|