2017-04-02 10:01:33 +00:00
|
|
|
/* -*-comment-start: "//";comment-end:""-*-
|
2018-07-22 12:24:36 +00:00
|
|
|
* GNU Mes --- Maxwell Equations of Software
|
2017-11-21 18:22:26 +00:00
|
|
|
* Copyright © 2016,2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2017-04-02 10:01:33 +00:00
|
|
|
*
|
2018-07-22 12:24:36 +00:00
|
|
|
* This file is part of GNU Mes.
|
2017-04-02 10:01:33 +00:00
|
|
|
*
|
2018-07-22 12:24:36 +00:00
|
|
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
2017-04-02 10:01:33 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2018-07-22 12:24:36 +00:00
|
|
|
* GNU Mes is distributed in the hope that it will be useful, but
|
2017-04-02 10:01:33 +00:00
|
|
|
* 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
|
2018-07-22 12:24:36 +00:00
|
|
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
2017-04-02 10:01:33 +00:00
|
|
|
*/
|
|
|
|
|
2017-04-12 19:27:59 +00:00
|
|
|
#if POSIX
|
|
|
|
#error "POSIX not supported"
|
2017-04-02 10:29:09 +00:00
|
|
|
#endif
|
|
|
|
|
2017-06-11 11:11:40 +00:00
|
|
|
#include <stdio.h>
|
2018-07-21 08:47:05 +00:00
|
|
|
#include <stdlib.h>
|
2017-04-02 10:01:33 +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
|
|
|
typedef int SCM;
|
|
|
|
|
|
|
|
#if __GNUC__
|
2017-01-08 16:51:40 +00:00
|
|
|
int g_debug = 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
|
|
|
#endif
|
|
|
|
|
|
|
|
int g_free = 0;
|
|
|
|
|
|
|
|
SCM g_symbols = 0;
|
|
|
|
SCM g_stack = 0;
|
|
|
|
SCM r0 = 0; // a/env
|
|
|
|
SCM r1 = 0; // param 1
|
|
|
|
SCM r2 = 0; // save 2+load/dump
|
|
|
|
SCM r3 = 0; // continuation
|
|
|
|
|
|
|
|
SCM
|
|
|
|
mes_environment ()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
bload_env (SCM a) ///((internal))
|
|
|
|
{
|
|
|
|
eputs ("bload_env\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-02 10:01:33 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
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
|
|
|
g_debug = (int)getenv ("MES_DEBUG");
|
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
|
|
|
#endif
|
|
|
|
//if (getenv ("MES_ARENA")) ARENA_SIZE = atoi (getenv ("MES_ARENA"));
|
|
|
|
|
2017-04-12 19:27:59 +00:00
|
|
|
// FIXME
|
|
|
|
//if (argc > 1 && !strcmp (argv[1], "--help")) return eputs ("Usage: mes [--dump|--load] < FILE\n");
|
2017-03-29 06:05:18 +00:00
|
|
|
//if (argc > 1 && !strcmp (argv[1], "--version")) {eputs ("Mes ");eputs (VERSION);return eputs ("\n");};
|
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
|
|
|
|
|
|
|
r0 = mes_environment ();
|
|
|
|
|
|
|
|
puts ("Hello micro-mes!\n");
|
2017-01-08 16:51:40 +00:00
|
|
|
SCM program = bload_env (r0);
|
2017-01-03 11:52:59 +00:00
|
|
|
int i = argc;
|
mescc: Formals, local variables.
* module/language/c99/compiler.mes (statement->text+symbols+locals):
Rename from statement->text+symbols. Handle locals.
(formals->text): Add proper function preamble.
(formals->locals): Add formals as locals.
(expr->accu, ident->accu, ident->base, ident-ref, global-ref): New
functions.
(strlen, eputs, fputs, puts): New functions.
(libc): New variable.
(i386:libc): Rename from libc. Remove eputs and puts.
* module/mes/libc-i386.mes (i386:eputs, i386:puts: Remove.
(i386:call, i386:ret): Handle locals as argument.
(i386:function-locals, i386:function-preamble, i386:jump,
i386:local->accu, i386:local-add, i386:local-assign,
i386:local->base, i386:ref-global, i386:ref-local, i386:ret-local,
i386:mem-byte->accu, i386:test-jump, i386:write): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-02 22:21:33 +00:00
|
|
|
return i;
|
2017-04-02 10:01:33 +00:00
|
|
|
}
|