2016-12-31 08:03:07 +00:00
|
|
|
;;; -*-scheme-*-
|
|
|
|
|
|
|
|
;;; Mes --- Maxwell Equations of Software
|
2017-01-02 06:41:56 +00:00
|
|
|
;;; Copyright © 2016,2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
2016-12-31 08:03:07 +00:00
|
|
|
;;;
|
|
|
|
;;; 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/>.
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;;; compiler.mes produces an i386 binary from the C produced by
|
|
|
|
;;; Nyacc c99.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(cond-expand
|
2017-04-02 09:55:37 +00:00
|
|
|
(guile-2
|
|
|
|
(set-port-encoding! (current-output-port) "ISO-8859-1"))
|
|
|
|
(guile)
|
|
|
|
(mes
|
2017-04-02 15:01:22 +00:00
|
|
|
(mes-use-module (mes pmatch))
|
2017-04-02 09:55:37 +00:00
|
|
|
(mes-use-module (nyacc lang c99 parser))
|
|
|
|
(mes-use-module (mes elf-util))
|
|
|
|
(mes-use-module (mes elf))
|
2017-04-02 10:29:09 +00:00
|
|
|
(mes-use-module (mes as-i386))
|
|
|
|
(mes-use-module (mes libc))
|
2017-01-04 23:55:46 +00:00
|
|
|
(mes-use-module (mes optargs))))
|
2017-04-02 09:55:37 +00:00
|
|
|
|
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
|
|
|
(define (logf port string . rest)
|
|
|
|
(apply format (cons* port string rest))
|
|
|
|
(force-output port)
|
|
|
|
#t)
|
|
|
|
|
|
|
|
(define (stderr string . rest)
|
|
|
|
(apply logf (cons* (current-error-port) string rest)))
|
|
|
|
|
2017-04-12 19:27:59 +00:00
|
|
|
(define %datadir (if (string-prefix? "@DATADIR" "@DATADIR@") "" "@DATADIR@"))
|
|
|
|
(define %docdir (if (string-prefix? "@DOCDIR" "@DOCDIR@") "doc/" "@DOCDIR@"))
|
|
|
|
(define %moduledir "module/")
|
|
|
|
(define %prefix (if (string-prefix? "@PREFIX" "@PREFIX@") "" "@PREFIX@"))
|
|
|
|
(define %version (if (string-prefix? "@VERSION" "@VERSION@") "git" "@VERSION@"))
|
|
|
|
|
|
|
|
(define mes? (pair? (current-module)))
|
|
|
|
|
|
|
|
(define (c99-input->ast)
|
2017-01-04 23:55:46 +00:00
|
|
|
(parse-c99
|
2017-05-02 15:00:07 +00:00
|
|
|
#:inc-dirs (cons* "." "libc/include" "libc" "src" "out" "out/src" (string-split (getenv "C_INCLUDE_PATH") #\:))
|
2017-04-02 16:50:07 +00:00
|
|
|
#:cpp-defs `(
|
2017-04-12 19:27:59 +00:00
|
|
|
"POSIX=0"
|
core: Prepare gc.c for mescc, non-POSIX_SOURCE.
* mes.c (NLENGTH, NVALUE, NVECTOR): New macros.
(mes_builtins): Add comment on .i include order.
* module/language/c99/compiler.mes (mescc): Add define _POSIX_SOURCE=0.
* gc.c (gc_up_arena, gc_flip, gc_loop, gc)[!_POSIX_SOURCE]: Use eputs
rather than fprintf.
(gc_loop): Use CAR, TYPE, NVECTOR rather than .car, .type, .vector.
* gc.c (gc_up_arena)[!_POSIX_SOURCE]: Add non-POSIX mlib.c
implementation.
2017-03-26 13:55:12 +00:00
|
|
|
"_POSIX_SOURCE=0"
|
2017-02-05 15:52:44 +00:00
|
|
|
"__GNUC__=0"
|
mescc: Run module/base-0.mes.
* gc.c: New file.
* vector.c: New file.
* mes.c: Remove vector and gc functions, include vector.c, gc.c.
* GNUmakefile (mes.o): Add gc, vector dependencies.
* scaffold/mini-mes.c (eval_apply): Support primitive-load through
read_input_file.
(getenv_, open_input_file, current_input_port,
set_current_input_port force_output, exit_, values, arity_, xassq,
is_p, minus, plus, divide, modulo multiply, logior, ash): New function.
(mes_symbols): Add symbols %gnuc, %mesc.
* scaffold/mini-mes.c (): New functions.
* scaffold/b-0.mes: New file.
* scaffold/t-0.mes: New file.
2017-03-26 19:13:01 +00:00
|
|
|
"__MESC__=1"
|
|
|
|
"__NYACC__=1" ;; REMOVEME
|
2017-04-12 19:27:59 +00:00
|
|
|
"EOF=-1"
|
2017-03-22 06:54:45 +00:00
|
|
|
"STDIN=0"
|
|
|
|
"STDOUT=1"
|
|
|
|
"STDERR=2"
|
|
|
|
|
|
|
|
"INT_MIN=-2147483648"
|
|
|
|
"INT_MAX=2147483647"
|
|
|
|
|
2017-04-12 19:27:59 +00:00
|
|
|
"MES_FULL=0"
|
|
|
|
"FIXED_PRIMITIVES=1"
|
|
|
|
|
|
|
|
,(if mes? "__MESC_MES__=1" "__MESC_MES__=0")
|
|
|
|
|
2017-04-02 16:50:07 +00:00
|
|
|
,(string-append "DATADIR=\"" %datadir "\"")
|
|
|
|
,(string-append "DOCDIR=\"" %docdir "\"")
|
|
|
|
,(string-append "PREFIX=\"" %prefix "\"")
|
|
|
|
,(string-append "MODULEDIR=\"" %moduledir "\"")
|
|
|
|
,(string-append "VERSION=\"" %version "\"")
|
2017-01-04 23:55:46 +00:00
|
|
|
)
|
2017-04-02 15:01:22 +00:00
|
|
|
#:mode 'code))
|
2016-12-31 08:03:07 +00:00
|
|
|
|
|
|
|
(define (ast:function? o)
|
|
|
|
(and (pair? o) (eq? (car o) 'fctn-defn)))
|
|
|
|
|
|
|
|
(define (.name o)
|
|
|
|
(pmatch o
|
2017-01-02 06:41:56 +00:00
|
|
|
((fctn-defn _ (ftn-declr (ident ,name) _) _) name)
|
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
|
|
|
((fctn-defn _ (ptr-declr (pointer) (ftn-declr (ident ,name) _)) _) name)
|
2017-04-17 00:15:11 +00:00
|
|
|
((fctn-defn _ (ptr-declr (pointer (pointer)) (ftn-declr (ident ,name) _)) _) name)
|
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
|
|
|
((param-decl _ (param-declr (ident ,name))) name)
|
|
|
|
((param-decl _ (param-declr (ptr-declr (pointer) (ident ,name)))) name)
|
|
|
|
((param-decl _ (param-declr (ptr-declr (pointer) (array-of (ident ,name))))) name)
|
2017-04-17 00:15:11 +00:00
|
|
|
((param-decl _ (param-declr (ptr-declr (pointer (pointer)) (ident ,name)))) name)
|
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
|
|
|
(_
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(format (current-error-port) "SKIP: .name =~a\n" o))))
|
|
|
|
|
|
|
|
(define (.type o)
|
|
|
|
(pmatch o
|
|
|
|
((param-decl (decl-spec-list (type-spec ,type)) _) (decl->type type))
|
|
|
|
((param-decl ,type _) type)
|
|
|
|
(_
|
|
|
|
(format (current-error-port) "SKIP: .type =~a\n" o))))
|
2016-12-31 08:03:07 +00:00
|
|
|
|
|
|
|
(define (.statements o)
|
|
|
|
(pmatch o
|
2017-01-02 06:41:56 +00:00
|
|
|
((fctn-defn _ (ftn-declr (ident ,name) _) (compd-stmt (block-item-list . ,statements))) statements)
|
2017-04-17 00:15:11 +00:00
|
|
|
((fctn-defn _ (ptr-declr (pointer) (ftn-declr (ident ,name) _)) (compd-stmt (block-item-list . ,statements))) statements)
|
|
|
|
((fctn-defn _ (ptr-declr (pointer (pointer)) (ftn-declr (ident ,name) _)) (compd-stmt (block-item-list . ,statements))) statements)
|
|
|
|
(_ (error ".statements: unsupported: " o))))
|
2016-12-31 08:03:07 +00:00
|
|
|
|
2017-01-04 23:55:46 +00:00
|
|
|
(define <info> '<info>)
|
2017-01-10 21:44:01 +00:00
|
|
|
(define <types> '<types>)
|
|
|
|
(define <constants> '<constants>)
|
2017-01-04 23:55:46 +00:00
|
|
|
(define <functions> '<functions>)
|
|
|
|
(define <globals> '<globals>)
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(define <init> '<init>)
|
2017-01-04 23:55:46 +00:00
|
|
|
(define <locals> '<locals>)
|
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
|
|
|
(define <function> '<function>)
|
2017-01-04 23:55:46 +00:00
|
|
|
(define <text> '<text>)
|
2017-04-10 04:59:50 +00:00
|
|
|
(define <break> '<break>)
|
2017-01-10 21:44:01 +00:00
|
|
|
|
2017-04-10 04:59:50 +00:00
|
|
|
(define* (make o #:key (types '()) (constants '()) (functions '()) (globals '()) (init '()) (locals '()) (function #f) (text '()) (break '()))
|
2017-01-04 23:55:46 +00:00
|
|
|
(pmatch o
|
|
|
|
(<info> (list <info>
|
2017-01-10 21:44:01 +00:00
|
|
|
(cons <types> types)
|
|
|
|
(cons <constants> constants)
|
2017-01-04 23:55:46 +00:00
|
|
|
(cons <functions> functions)
|
|
|
|
(cons <globals> globals)
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(cons <init> init)
|
2017-01-04 23:55:46 +00:00
|
|
|
(cons <locals> locals)
|
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
|
|
|
(cons <function> function)
|
2017-04-10 04:59:50 +00:00
|
|
|
(cons <text> text)
|
|
|
|
(cons <break> break)))))
|
2017-01-04 23:55:46 +00:00
|
|
|
|
2017-01-10 21:44:01 +00:00
|
|
|
(define (.types o)
|
|
|
|
(pmatch o
|
|
|
|
((<info> . ,alist) (assq-ref alist <types>))))
|
|
|
|
|
|
|
|
(define (.constants o)
|
|
|
|
(pmatch o
|
|
|
|
((<info> . ,alist) (assq-ref alist <constants>))))
|
|
|
|
|
2017-01-04 23:55:46 +00:00
|
|
|
(define (.functions o)
|
|
|
|
(pmatch o
|
|
|
|
((<info> . ,alist) (assq-ref alist <functions>))))
|
|
|
|
|
|
|
|
(define (.globals o)
|
|
|
|
(pmatch o
|
|
|
|
((<info> . ,alist) (assq-ref alist <globals>))))
|
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(define (.init o)
|
|
|
|
(pmatch o
|
|
|
|
((<info> . ,alist) (assq-ref alist <init>))))
|
|
|
|
|
2017-01-04 23:55:46 +00:00
|
|
|
(define (.locals o)
|
|
|
|
(pmatch o
|
|
|
|
((<info> . ,alist) (assq-ref alist <locals>))))
|
|
|
|
|
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
|
|
|
(define (.function o)
|
|
|
|
(pmatch o
|
|
|
|
((<info> . ,alist) (assq-ref alist <function>))))
|
|
|
|
|
2017-01-04 23:55:46 +00:00
|
|
|
(define (.text o)
|
|
|
|
(pmatch o
|
|
|
|
((<info> . ,alist) (assq-ref alist <text>))))
|
|
|
|
|
2017-04-10 04:59:50 +00:00
|
|
|
(define (.break o)
|
|
|
|
(pmatch o
|
|
|
|
((<info> . ,alist) (assq-ref alist <break>))))
|
|
|
|
|
2017-01-04 23:55:46 +00:00
|
|
|
(define (info? o)
|
|
|
|
(and (pair? o) (eq? (car o) <info>)))
|
|
|
|
|
|
|
|
(define (clone o . rest)
|
|
|
|
(cond ((info? o)
|
2017-01-10 21:44:01 +00:00
|
|
|
(let ((types (.types o))
|
|
|
|
(constants (.constants o))
|
|
|
|
(functions (.functions o))
|
2017-01-04 23:55:46 +00:00
|
|
|
(globals (.globals o))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(init (.init o))
|
2017-01-04 23:55:46 +00:00
|
|
|
(locals (.locals o))
|
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
|
|
|
(function (.function o))
|
2017-04-10 04:59:50 +00:00
|
|
|
(text (.text o))
|
|
|
|
(break (.break o)))
|
2017-01-04 23:55:46 +00:00
|
|
|
(let-keywords rest
|
|
|
|
#f
|
2017-01-10 21:44:01 +00:00
|
|
|
((types types)
|
|
|
|
(constants constants)
|
|
|
|
(functions functions)
|
2017-01-04 23:55:46 +00:00
|
|
|
(globals globals)
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(init init)
|
2017-01-04 23:55:46 +00:00
|
|
|
(locals locals)
|
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
|
|
|
(function function)
|
2017-04-10 04:59:50 +00:00
|
|
|
(text text)
|
|
|
|
(break break))
|
|
|
|
(make <info> #:types types #:constants constants #:functions functions #:globals globals #:init init #:locals locals #:function function #:text text #:break break))))))
|
2017-01-04 23:55:46 +00:00
|
|
|
|
2017-02-27 06:50:33 +00:00
|
|
|
(define (push-global globals)
|
|
|
|
(lambda (o)
|
2017-03-17 07:37:45 +00:00
|
|
|
(list
|
|
|
|
(lambda (f g ta t d)
|
|
|
|
(i386:push-global (+ (data-offset o g) d))))))
|
2017-02-27 06:50:33 +00:00
|
|
|
|
|
|
|
(define (push-local locals)
|
|
|
|
(lambda (o)
|
2017-04-07 07:36:30 +00:00
|
|
|
(wrap-as (i386:push-local (local:id o)))))
|
2017-02-27 06:50:33 +00:00
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(define (push-global-address globals)
|
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
|
|
|
(lambda (o)
|
2017-03-17 07:37:45 +00:00
|
|
|
(list
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(lambda (f g ta t d)
|
2017-03-17 07:37:45 +00:00
|
|
|
(i386:push-global-address (+ (data-offset o g) d))))))
|
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
|
|
|
|
2017-02-27 06:50:33 +00:00
|
|
|
(define (push-local-address locals)
|
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
|
|
|
(lambda (o)
|
2017-04-07 07:36:30 +00:00
|
|
|
(wrap-as (i386:push-local-address (local:id o)))))
|
mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
procedure and give more debug information.
(ref-local, ref-global): Remove.
(push-global-ref, push-global, push-ident-ref): New functions.
(push-ident): New function.
(expr->arg): Use them.
(ident->accu, ident->accu, accu->ident, value->ident, ident->base):
Take info parameter, also handle globals.
(ident-address->accu, ident->global, cstring->number): New functions.
(ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
(i386:push-global-ref): Rename from i386:ref-global.
(i386:push-local): Rename from i386:ref-local.
(i386:value->local): Rename from i386:local-assign.
(i386:push-global, i386:push-local-ref, i386:value->global,
i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 19:12:06 +00:00
|
|
|
|
2017-01-17 18:03:08 +00:00
|
|
|
(define push-global-de-ref push-global)
|
|
|
|
|
2017-04-17 00:15:11 +00:00
|
|
|
(define (push-local-de-ref info)
|
2017-02-27 06:50:33 +00:00
|
|
|
(lambda (o)
|
2017-04-17 00:15:11 +00:00
|
|
|
(let* ((local o)
|
|
|
|
(ptr (local:pointer local))
|
|
|
|
(size (if (= ptr 1) (type->size info (local:type o))
|
|
|
|
4)))
|
|
|
|
(if (= size 1)
|
|
|
|
(wrap-as (i386:push-byte-local-de-ref (local:id o)))
|
|
|
|
(wrap-as (i386:push-local-de-ref (local:id o)))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (push-local-de-de-ref info)
|
|
|
|
(lambda (o)
|
|
|
|
(let* ((local o)
|
|
|
|
(ptr (local:pointer local))
|
|
|
|
(size (if (= ptr 2) (type->size info (local:type o));; URG
|
|
|
|
4)))
|
|
|
|
(if (= size 1)
|
|
|
|
(wrap-as (i386:push-byte-local-de-de-ref (local:id o)))
|
|
|
|
(error "TODO int-de-de-ref")))))
|
2017-02-27 06:50:33 +00:00
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(define (string->global string)
|
2017-03-09 07:14:27 +00:00
|
|
|
(make-global (add-s:-prefix string) "string" 0 (append (string->list string) (list #\nul))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
|
2017-04-17 00:15:11 +00:00
|
|
|
(define (int->global value)
|
|
|
|
(make-global (add-s:-prefix (number->string value)) "int" 0 (int->bv32 value)))
|
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(define (ident->global name type pointer value)
|
|
|
|
(make-global name type pointer (int->bv32 value)))
|
|
|
|
|
|
|
|
(define (make-local name type pointer id)
|
|
|
|
(cons name (list type pointer id)))
|
|
|
|
(define local:type car)
|
|
|
|
(define local:pointer cadr)
|
|
|
|
(define local:id caddr)
|
|
|
|
|
|
|
|
(define (push-ident info)
|
mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
procedure and give more debug information.
(ref-local, ref-global): Remove.
(push-global-ref, push-global, push-ident-ref): New functions.
(push-ident): New function.
(expr->arg): Use them.
(ident->accu, ident->accu, accu->ident, value->ident, ident->base):
Take info parameter, also handle globals.
(ident-address->accu, ident->global, cstring->number): New functions.
(ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
(i386:push-global-ref): Rename from i386:ref-global.
(i386:push-local): Rename from i386:ref-local.
(i386:value->local): Rename from i386:local-assign.
(i386:push-global, i386:push-local-ref, i386:value->global,
i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 19:12:06 +00:00
|
|
|
(lambda (o)
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(let ((local (assoc-ref (.locals info) o)))
|
2017-05-07 05:36:44 +00:00
|
|
|
(if local
|
|
|
|
(begin
|
|
|
|
(let* ((ptr (local:pointer local))
|
|
|
|
(size (if (= ptr 1) (type->size info (local:type local))
|
|
|
|
4)))
|
|
|
|
(if (= ptr -1) ((push-local-address (.locals info)) local)
|
|
|
|
((push-local (.locals info)) local))))
|
2017-03-17 07:37:45 +00:00
|
|
|
(let ((global (assoc-ref (.globals info) o)))
|
|
|
|
(if global
|
|
|
|
((push-global (.globals info)) o) ;; FIXME: char*/int
|
|
|
|
(let ((constant (assoc-ref (.constants info) o)))
|
|
|
|
(if constant
|
2017-04-07 07:36:30 +00:00
|
|
|
(wrap-as (append (i386:value->accu constant)
|
2017-04-07 12:31:35 +00:00
|
|
|
(i386:push-accu)))
|
2017-04-12 19:27:59 +00:00
|
|
|
(error "TODO:push-function: " o)))))))))
|
mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
procedure and give more debug information.
(ref-local, ref-global): Remove.
(push-global-ref, push-global, push-ident-ref): New functions.
(push-ident): New function.
(expr->arg): Use them.
(ident->accu, ident->accu, accu->ident, value->ident, ident->base):
Take info parameter, also handle globals.
(ident-address->accu, ident->global, cstring->number): New functions.
(ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
(i386:push-global-ref): Rename from i386:ref-global.
(i386:push-local): Rename from i386:ref-local.
(i386:value->local): Rename from i386:local-assign.
(i386:push-global, i386:push-local-ref, i386:value->global,
i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 19:12:06 +00:00
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(define (push-ident-address info)
|
mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
procedure and give more debug information.
(ref-local, ref-global): Remove.
(push-global-ref, push-global, push-ident-ref): New functions.
(push-ident): New function.
(expr->arg): Use them.
(ident->accu, ident->accu, accu->ident, value->ident, ident->base):
Take info parameter, also handle globals.
(ident-address->accu, ident->global, cstring->number): New functions.
(ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
(i386:push-global-ref): Rename from i386:ref-global.
(i386:push-local): Rename from i386:ref-local.
(i386:value->local): Rename from i386:local-assign.
(i386:push-global, i386:push-local-ref, i386:value->global,
i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 19:12:06 +00:00
|
|
|
(lambda (o)
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(let ((local (assoc-ref (.locals info) o)))
|
2017-02-27 06:50:33 +00:00
|
|
|
(if local ((push-local-address (.locals info)) local)
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
((push-global-address (.globals info)) o)))))
|
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
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(define (push-ident-de-ref info)
|
2017-01-17 18:03:08 +00:00
|
|
|
(lambda (o)
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(let ((local (assoc-ref (.locals info) o)))
|
2017-04-17 00:15:11 +00:00
|
|
|
(if local ((push-local-de-ref info) local)
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
((push-global-de-ref (.globals info)) o)))))
|
2017-01-17 18:03:08 +00:00
|
|
|
|
2017-04-17 00:15:11 +00:00
|
|
|
(define (push-ident-de-de-ref info)
|
|
|
|
(lambda (o)
|
|
|
|
(let ((local (assoc-ref (.locals info) o)))
|
|
|
|
(if local ((push-local-de-de-ref info) local)
|
|
|
|
(error "TODO: global push-local-de-de-ref")))))
|
|
|
|
|
2017-04-04 12:37:17 +00:00
|
|
|
(define (expr->arg info)
|
|
|
|
(lambda (o)
|
|
|
|
(let ((info ((expr->accu info) o)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (wrap-as (i386:push-accu))))))
|
2017-04-04 12:37:17 +00:00
|
|
|
|
2017-04-23 11:53:36 +00:00
|
|
|
(define (globals:add-string globals)
|
|
|
|
(lambda (o)
|
|
|
|
(let ((string (add-s:-prefix o)))
|
|
|
|
(if (assoc-ref globals string) globals
|
|
|
|
(append globals (list (string->global o)))))))
|
|
|
|
|
mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
procedure and give more debug information.
(ref-local, ref-global): Remove.
(push-global-ref, push-global, push-ident-ref): New functions.
(push-ident): New function.
(expr->arg): Use them.
(ident->accu, ident->accu, accu->ident, value->ident, ident->base):
Take info parameter, also handle globals.
(ident-address->accu, ident->global, cstring->number): New functions.
(ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
(i386:push-global-ref): Rename from i386:ref-global.
(i386:push-local): Rename from i386:ref-local.
(i386:value->local): Rename from i386:local-assign.
(i386:push-global, i386:push-local-ref, i386:value->global,
i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 19:12:06 +00:00
|
|
|
(define (expr->arg info) ;; FIXME: get Mes curried-definitions
|
2017-04-02 09:55:37 +00:00
|
|
|
(lambda (o)
|
2017-02-27 06:50:33 +00:00
|
|
|
(let ((text (.text info)))
|
|
|
|
(pmatch o
|
|
|
|
|
|
|
|
((p-expr (string ,string))
|
2017-04-23 11:53:36 +00:00
|
|
|
(let* ((globals ((globals:add-string (.globals info)) string))
|
|
|
|
(info (clone info #:globals globals)))
|
|
|
|
(append-text info ((push-global-address info) (add-s:-prefix string)))))
|
2017-02-27 06:50:33 +00:00
|
|
|
|
|
|
|
((p-expr (ident ,name))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info ((push-ident info) name)))
|
2017-02-27 06:50:33 +00:00
|
|
|
|
2017-04-04 12:37:17 +00:00
|
|
|
((cast (type-name (decl-spec-list (type-spec (fixed-type _)))
|
|
|
|
(abs-declr (pointer)))
|
|
|
|
,cast)
|
|
|
|
((expr->arg info) cast))
|
2017-02-27 06:50:33 +00:00
|
|
|
|
2017-04-17 00:15:11 +00:00
|
|
|
((cast (type-name (decl-spec-list (type-spec (fixed-type ,type)))) ,cast)
|
|
|
|
((expr->arg info) cast))
|
|
|
|
|
2017-02-27 06:50:33 +00:00
|
|
|
((de-ref (p-expr (ident ,name)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info ((push-ident-de-ref info) name)))
|
2017-02-27 06:50:33 +00:00
|
|
|
|
2017-04-17 00:15:11 +00:00
|
|
|
((de-ref (de-ref (p-expr (ident ,name))))
|
|
|
|
(append-text info ((push-ident-de-de-ref info) name)))
|
|
|
|
|
2017-02-27 06:50:33 +00:00
|
|
|
((ref-to (p-expr (ident ,name)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info ((push-ident-address info) name)))
|
2017-02-27 06:50:33 +00:00
|
|
|
|
2017-04-07 07:53:56 +00:00
|
|
|
(_ (append-text ((expr->accu info) o)
|
|
|
|
(wrap-as (i386:push-accu))))))))
|
2017-04-02 09:55:37 +00:00
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
;; FIXME: see ident->base
|
mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
procedure and give more debug information.
(ref-local, ref-global): Remove.
(push-global-ref, push-global, push-ident-ref): New functions.
(push-ident): New function.
(expr->arg): Use them.
(ident->accu, ident->accu, accu->ident, value->ident, ident->base):
Take info parameter, also handle globals.
(ident-address->accu, ident->global, cstring->number): New functions.
(ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
(i386:push-global-ref): Rename from i386:ref-global.
(i386:push-local): Rename from i386:ref-local.
(i386:value->local): Rename from i386:local-assign.
(i386:push-global, i386:push-local-ref, i386:value->global,
i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 19:12:06 +00:00
|
|
|
(define (ident->accu info)
|
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
|
|
|
(lambda (o)
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(let ((local (assoc-ref (.locals info) o))
|
|
|
|
(global (assoc-ref (.globals info) o))
|
|
|
|
(constant (assoc-ref (.constants info) o)))
|
mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
procedure and give more debug information.
(ref-local, ref-global): Remove.
(push-global-ref, push-global, push-ident-ref): New functions.
(push-ident): New function.
(expr->arg): Use them.
(ident->accu, ident->accu, accu->ident, value->ident, ident->base):
Take info parameter, also handle globals.
(ident-address->accu, ident->global, cstring->number): New functions.
(ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
(i386:push-global-ref): Rename from i386:ref-global.
(i386:push-local): Rename from i386:ref-local.
(i386:value->local): Rename from i386:local-assign.
(i386:push-global, i386:push-local-ref, i386:value->global,
i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 19:12:06 +00:00
|
|
|
(if local
|
2017-03-17 16:32:23 +00:00
|
|
|
(let* ((ptr (local:pointer local))
|
|
|
|
(type (ident->type info o))
|
2017-04-17 00:15:11 +00:00
|
|
|
(size (if (= ptr 0) (type->size info type)
|
|
|
|
4)))
|
2017-03-17 16:32:23 +00:00
|
|
|
(case ptr
|
2017-04-07 07:36:30 +00:00
|
|
|
((-1) (wrap-as (i386:local-ptr->accu (local:id local))))
|
|
|
|
((1) (wrap-as (i386:local->accu (local:id local))))
|
2017-03-17 16:32:23 +00:00
|
|
|
(else
|
2017-04-07 07:36:30 +00:00
|
|
|
(wrap-as (if (= size 1) (i386:byte-local->accu (local:id local))
|
2017-04-07 12:31:35 +00:00
|
|
|
(i386:local->accu (local:id local)))))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(if global
|
2017-04-17 00:15:11 +00:00
|
|
|
(let* ((ptr (ident->pointer info o))
|
|
|
|
(type (ident->type info o))
|
|
|
|
(size (if (= ptr 1) (type->size info type)
|
|
|
|
4)))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(case ptr
|
|
|
|
((-1) (list (lambda (f g ta t d)
|
|
|
|
(i386:global->accu (+ (data-offset o g) d)))))
|
2017-04-17 00:15:11 +00:00
|
|
|
((1) (list (lambda (f g ta t d)
|
|
|
|
(i386:global-address->accu (+ (data-offset o g) d)))))
|
|
|
|
|
|
|
|
((2) (list (lambda (f g ta t d)
|
|
|
|
(append (i386:value->accu (+ (data-offset o g) d))))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(else (list (lambda (f g ta t d)
|
|
|
|
(i386:global-address->accu (+ (data-offset o g) d)))))))
|
2017-04-07 07:36:30 +00:00
|
|
|
(if constant (wrap-as (i386:value->accu constant))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(list (lambda (f g ta t d)
|
|
|
|
(i386:global->accu (+ ta (function-offset o f)))))))))))
|
|
|
|
|
2017-04-17 00:15:11 +00:00
|
|
|
(define (ident-address->accu info)
|
|
|
|
(lambda (o)
|
|
|
|
(let ((local (assoc-ref (.locals info) o))
|
|
|
|
(global (assoc-ref (.globals info) o))
|
|
|
|
(constant (assoc-ref (.constants info) o)))
|
|
|
|
(if local
|
|
|
|
(let* ((ptr (local:pointer local))
|
|
|
|
(type (ident->type info o))
|
|
|
|
(size (if (= ptr 1) (type->size info type)
|
|
|
|
4)))
|
|
|
|
;;(stderr "ident->accu ~a => ~a\n" o ptr)
|
|
|
|
(wrap-as (i386:local-ptr->accu (local:id local))))
|
|
|
|
(if global
|
|
|
|
(let ((ptr (ident->pointer info o)))
|
|
|
|
(case ptr
|
2017-04-17 00:24:20 +00:00
|
|
|
;; ((1)
|
|
|
|
;; (list (lambda (f g ta t d)
|
|
|
|
;; (i386:global->accu (+ (data-offset o g) d)))))
|
2017-04-17 00:15:11 +00:00
|
|
|
(else (list (lambda (f g ta t d)
|
|
|
|
(append (i386:value->accu (+ (data-offset o g) d))))))))
|
2017-05-06 09:01:58 +00:00
|
|
|
(list (lambda (f g ta t d)
|
|
|
|
(i386:global->accu (+ ta (function-offset o f))))))))))
|
2017-04-17 00:15:11 +00:00
|
|
|
|
|
|
|
(define (ident-address->base info)
|
|
|
|
(lambda (o)
|
|
|
|
(let ((local (assoc-ref (.locals info) o))
|
|
|
|
(global (assoc-ref (.globals info) o))
|
|
|
|
(constant (assoc-ref (.constants info) o)))
|
|
|
|
(if local
|
|
|
|
(let* ((ptr (local:pointer local))
|
|
|
|
(type (ident->type info o))
|
|
|
|
(size (if (= ptr 1) (type->size info type)
|
|
|
|
4)))
|
|
|
|
(wrap-as (i386:local-ptr->base (local:id local))))
|
|
|
|
(if global
|
|
|
|
(let ((ptr (ident->pointer info o)))
|
|
|
|
(case ptr
|
|
|
|
((1)
|
|
|
|
(list (lambda (f g ta t d)
|
|
|
|
(i386:global->base (+ (data-offset o g) d)))))
|
|
|
|
(else (list (lambda (f g ta t d)
|
|
|
|
(append (i386:value->base (+ (data-offset o g) d))))))))
|
|
|
|
(error "TODO ident-address->base" o))))))
|
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(define (value->accu v)
|
2017-04-07 07:36:30 +00:00
|
|
|
(wrap-as (i386:value->accu v)))
|
mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
procedure and give more debug information.
(ref-local, ref-global): Remove.
(push-global-ref, push-global, push-ident-ref): New functions.
(push-ident): New function.
(expr->arg): Use them.
(ident->accu, ident->accu, accu->ident, value->ident, ident->base):
Take info parameter, also handle globals.
(ident-address->accu, ident->global, cstring->number): New functions.
(ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
(i386:push-global-ref): Rename from i386:ref-global.
(i386:push-local): Rename from i386:ref-local.
(i386:value->local): Rename from i386:local-assign.
(i386:push-global, i386:push-local-ref, i386:value->global,
i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 19:12:06 +00:00
|
|
|
|
|
|
|
(define (accu->ident info)
|
2017-01-03 11:52:59 +00:00
|
|
|
(lambda (o)
|
mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
procedure and give more debug information.
(ref-local, ref-global): Remove.
(push-global-ref, push-global, push-ident-ref): New functions.
(push-ident): New function.
(expr->arg): Use them.
(ident->accu, ident->accu, accu->ident, value->ident, ident->base):
Take info parameter, also handle globals.
(ident-address->accu, ident->global, cstring->number): New functions.
(ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
(i386:push-global-ref): Rename from i386:ref-global.
(i386:push-local): Rename from i386:ref-local.
(i386:value->local): Rename from i386:local-assign.
(i386:push-global, i386:push-local-ref, i386:value->global,
i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 19:12:06 +00:00
|
|
|
(let ((local (assoc-ref (.locals info) o)))
|
2017-04-17 00:15:11 +00:00
|
|
|
(if local
|
|
|
|
(let ((ptr (local:pointer local)))
|
|
|
|
(case ptr
|
|
|
|
(else (wrap-as (i386:accu->local (local:id local))))))
|
|
|
|
(let ((ptr (ident->pointer info o)))
|
|
|
|
(list (lambda (f g ta t d)
|
|
|
|
(i386:accu->global (+ (data-offset o g) d)))))))))
|
mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
procedure and give more debug information.
(ref-local, ref-global): Remove.
(push-global-ref, push-global, push-ident-ref): New functions.
(push-ident): New function.
(expr->arg): Use them.
(ident->accu, ident->accu, accu->ident, value->ident, ident->base):
Take info parameter, also handle globals.
(ident-address->accu, ident->global, cstring->number): New functions.
(ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
(i386:push-global-ref): Rename from i386:ref-global.
(i386:push-local): Rename from i386:ref-local.
(i386:value->local): Rename from i386:local-assign.
(i386:push-global, i386:push-local-ref, i386:value->global,
i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 19:12:06 +00:00
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(define (base->ident info)
|
2017-01-17 17:57:41 +00:00
|
|
|
(lambda (o)
|
|
|
|
(let ((local (assoc-ref (.locals info) o)))
|
2017-04-07 07:36:30 +00:00
|
|
|
(if local (wrap-as (i386:base->local (local:id local)))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(list (lambda (f g ta t d)
|
|
|
|
(i386:base->global (+ (data-offset o g) d))))))))
|
|
|
|
|
|
|
|
(define (base->ident-address info)
|
|
|
|
(lambda (o)
|
|
|
|
(let ((local (assoc-ref (.locals info) o)))
|
2017-04-17 00:15:11 +00:00
|
|
|
(if local
|
|
|
|
(let* ((ptr (local:pointer local))
|
|
|
|
(type (ident->type info o))
|
|
|
|
(size (if (= ptr 1) (type->size info type)
|
|
|
|
4)))
|
|
|
|
(wrap-as (append (i386:local->accu (local:id local))
|
|
|
|
(if (= size 1) (i386:byte-base->accu-address)
|
|
|
|
(i386:byte-base->accu-address)))))
|
2017-04-12 19:27:59 +00:00
|
|
|
(error "TODO:base->ident-address-global" o)))))
|
2017-01-17 17:57:41 +00:00
|
|
|
|
mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
procedure and give more debug information.
(ref-local, ref-global): Remove.
(push-global-ref, push-global, push-ident-ref): New functions.
(push-ident): New function.
(expr->arg): Use them.
(ident->accu, ident->accu, accu->ident, value->ident, ident->base):
Take info parameter, also handle globals.
(ident-address->accu, ident->global, cstring->number): New functions.
(ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
(i386:push-global-ref): Rename from i386:ref-global.
(i386:push-local): Rename from i386:ref-local.
(i386:value->local): Rename from i386:local-assign.
(i386:push-global, i386:push-local-ref, i386:value->global,
i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 19:12:06 +00:00
|
|
|
(define (value->ident info)
|
|
|
|
(lambda (o value)
|
|
|
|
(let ((local (assoc-ref (.locals info) o)))
|
2017-04-07 07:36:30 +00:00
|
|
|
(if local (wrap-as (i386:value->local (local:id local) value))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(list (lambda (f g ta t d)
|
mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
procedure and give more debug information.
(ref-local, ref-global): Remove.
(push-global-ref, push-global, push-ident-ref): New functions.
(push-ident): New function.
(expr->arg): Use them.
(ident->accu, ident->accu, accu->ident, value->ident, ident->base):
Take info parameter, also handle globals.
(ident-address->accu, ident->global, cstring->number): New functions.
(ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
(i386:push-global-ref): Rename from i386:ref-global.
(i386:push-local): Rename from i386:ref-local.
(i386:value->local): Rename from i386:local-assign.
(i386:push-global, i386:push-local-ref, i386:value->global,
i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 19:12:06 +00:00
|
|
|
(i386:value->global (+ (data-offset o g) d) value)))))))
|
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(define (ident-add info)
|
|
|
|
(lambda (o n)
|
mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
procedure and give more debug information.
(ref-local, ref-global): Remove.
(push-global-ref, push-global, push-ident-ref): New functions.
(push-ident): New function.
(expr->arg): Use them.
(ident->accu, ident->accu, accu->ident, value->ident, ident->base):
Take info parameter, also handle globals.
(ident-address->accu, ident->global, cstring->number): New functions.
(ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
(i386:push-global-ref): Rename from i386:ref-global.
(i386:push-local): Rename from i386:ref-local.
(i386:value->local): Rename from i386:local-assign.
(i386:push-global, i386:push-local-ref, i386:value->global,
i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 19:12:06 +00:00
|
|
|
(let ((local (assoc-ref (.locals info) o)))
|
2017-04-07 07:36:30 +00:00
|
|
|
(if local (wrap-as (i386:local-add (local:id local) n))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(list (lambda (f g ta t d)
|
|
|
|
(i386:global-add (+ (data-offset o g) d) n)))))))
|
mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
procedure and give more debug information.
(ref-local, ref-global): Remove.
(push-global-ref, push-global, push-ident-ref): New functions.
(push-ident): New function.
(expr->arg): Use them.
(ident->accu, ident->accu, accu->ident, value->ident, ident->base):
Take info parameter, also handle globals.
(ident-address->accu, ident->global, cstring->number): New functions.
(ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
(i386:push-global-ref): Rename from i386:ref-global.
(i386:push-local): Rename from i386:ref-local.
(i386:value->local): Rename from i386:local-assign.
(i386:push-global, i386:push-local-ref, i386:value->global,
i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 19:12:06 +00:00
|
|
|
|
2017-04-17 00:15:11 +00:00
|
|
|
(define (ident-address-add info)
|
|
|
|
(lambda (o n)
|
|
|
|
(let ((local (assoc-ref (.locals info) o)))
|
|
|
|
(if local (wrap-as (append (i386:push-accu)
|
|
|
|
(i386:local->accu (local:id local))
|
|
|
|
(i386:accu-mem-add n)
|
|
|
|
(i386:pop-accu)))
|
|
|
|
(list (lambda (f g ta t d)
|
|
|
|
(append (i386:push-accu)
|
|
|
|
(i386:global->accu (+ (data-offset o g) d))
|
|
|
|
(i386:accu-mem-add n)
|
|
|
|
(i386:pop-accu))))))))
|
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
;; FIXME: see ident->accu
|
mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
procedure and give more debug information.
(ref-local, ref-global): Remove.
(push-global-ref, push-global, push-ident-ref): New functions.
(push-ident): New function.
(expr->arg): Use them.
(ident->accu, ident->accu, accu->ident, value->ident, ident->base):
Take info parameter, also handle globals.
(ident-address->accu, ident->global, cstring->number): New functions.
(ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
(i386:push-global-ref): Rename from i386:ref-global.
(i386:push-local): Rename from i386:ref-local.
(i386:value->local): Rename from i386:local-assign.
(i386:push-global, i386:push-local-ref, i386:value->global,
i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 19:12:06 +00:00
|
|
|
(define (ident->base info)
|
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
|
|
|
(lambda (o)
|
mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
procedure and give more debug information.
(ref-local, ref-global): Remove.
(push-global-ref, push-global, push-ident-ref): New functions.
(push-ident): New function.
(expr->arg): Use them.
(ident->accu, ident->accu, accu->ident, value->ident, ident->base):
Take info parameter, also handle globals.
(ident-address->accu, ident->global, cstring->number): New functions.
(ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
(i386:push-global-ref): Rename from i386:ref-global.
(i386:push-local): Rename from i386:ref-local.
(i386:value->local): Rename from i386:local-assign.
(i386:push-global, i386:push-local-ref, i386:value->global,
i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 19:12:06 +00:00
|
|
|
(let ((local (assoc-ref (.locals info) o)))
|
|
|
|
(if local
|
2017-03-17 16:32:23 +00:00
|
|
|
(let* ((ptr (local:pointer local))
|
|
|
|
(type (ident->type info o))
|
2017-04-17 00:15:11 +00:00
|
|
|
(size (if (and type (= ptr 1)) (type->size info type)
|
|
|
|
4)))
|
2017-03-17 16:32:23 +00:00
|
|
|
(case ptr
|
2017-04-07 07:36:30 +00:00
|
|
|
((-1) (wrap-as (i386:local-ptr->base (local:id local))))
|
|
|
|
((1) (wrap-as (i386:local->base (local:id local))))
|
2017-03-17 16:32:23 +00:00
|
|
|
(else
|
2017-04-07 07:36:30 +00:00
|
|
|
(wrap-as (if (= size 1) (i386:byte-local->base (local:id local))
|
|
|
|
(i386:local->base (local:id local)))))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(let ((global (assoc-ref (.globals info) o) ))
|
|
|
|
(if global
|
|
|
|
(let ((ptr (ident->pointer info o)))
|
2017-04-06 07:12:50 +00:00
|
|
|
(case ptr
|
|
|
|
((-1) (list (lambda (f g ta t d)
|
|
|
|
(i386:global->base (+ (data-offset o g) d)))))
|
2017-04-17 00:15:11 +00:00
|
|
|
((2) (list (lambda (f g ta t d)
|
|
|
|
(i386:global->base (+ (data-offset o g) d)))))
|
2017-04-06 07:12:50 +00:00
|
|
|
(else (list (lambda (f g ta t d)
|
|
|
|
(i386:global-address->base (+ (data-offset o g) d)))))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(let ((constant (assoc-ref (.constants info) o)))
|
2017-04-07 07:36:30 +00:00
|
|
|
(if constant (wrap-as (i386:value->base constant))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(list (lambda (f g ta t d)
|
|
|
|
(i386:global->base (+ ta (function-offset o f)))))))))))))
|
2017-01-17 17:57:41 +00:00
|
|
|
|
2017-01-04 23:55:46 +00:00
|
|
|
(define (expr->accu info)
|
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
|
|
|
(lambda (o)
|
2017-04-05 18:11:13 +00:00
|
|
|
(let ((locals (.locals info))
|
|
|
|
(constants (.constants info))
|
|
|
|
(text (.text info))
|
2017-03-09 07:14:27 +00:00
|
|
|
(globals (.globals info)))
|
2017-04-05 18:11:13 +00:00
|
|
|
(define (add-local locals name type pointer)
|
2017-05-04 17:39:23 +00:00
|
|
|
(let* ((id (if (or (null? locals) (not (local? (cdar locals)))) 1
|
|
|
|
(1+ (local:id (cdar locals)))))
|
2017-04-05 18:11:13 +00:00
|
|
|
(locals (cons (make-local name type pointer id) locals)))
|
|
|
|
locals))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(pmatch o
|
2017-05-08 19:32:32 +00:00
|
|
|
((expr) info)
|
2017-03-09 07:14:27 +00:00
|
|
|
((p-expr (string ,string))
|
2017-04-17 00:15:11 +00:00
|
|
|
(let* ((globals (append globals (list (string->global string))))
|
|
|
|
(info (clone info #:globals globals)))
|
|
|
|
(append-text info (list (lambda (f g ta t d)
|
|
|
|
(i386:global->accu (+ (data-offset (add-s:-prefix string) globals) d)))))))
|
|
|
|
|
2017-04-12 19:27:59 +00:00
|
|
|
((p-expr (string . ,strings))
|
|
|
|
(append-text info (list (lambda (f g ta t d)
|
|
|
|
(i386:global->accu (+ (data-offset (add-s:-prefix (apply string-append strings)) globals) d))))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
((p-expr (fixed ,value))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (value->accu (cstring->number value))))
|
2017-04-17 00:15:11 +00:00
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
((p-expr (ident ,name))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info ((ident->accu info) name)))
|
2017-04-06 07:12:50 +00:00
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
((initzer ,initzer) ((expr->accu info) initzer))
|
2017-05-06 09:01:58 +00:00
|
|
|
|
|
|
|
;; &foo
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
((ref-to (p-expr (ident ,name)))
|
2017-05-06 09:01:58 +00:00
|
|
|
(append-text info ((ident-address->accu info) name)))
|
|
|
|
|
|
|
|
;; &f.field
|
|
|
|
((ref-to (d-sel (ident ,field) (p-expr (ident ,array))))
|
|
|
|
(let* ((type (ident->type info array))
|
|
|
|
(fields (type->description info type))
|
|
|
|
(field-size 4) ;; FIXME:4, not fixed
|
|
|
|
(offset (* field-size (1- (length (member field (reverse fields) (lambda (a b) (equal? a (cdr b))))))))
|
|
|
|
(text (.text info)))
|
|
|
|
(append-text info (append ((ident->accu info) array)
|
|
|
|
(wrap-as (i386:accu+n offset))))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
|
2017-05-07 05:36:44 +00:00
|
|
|
;; &a[x];
|
|
|
|
((ref-to (array-ref ,index (p-expr (ident ,array))))
|
|
|
|
((expr->accu* info) `(array-ref ,index (p-expr (ident ,array)))))
|
|
|
|
|
2017-05-08 19:32:32 +00:00
|
|
|
((sizeof-expr (p-expr (ident ,name)))
|
|
|
|
(let* ((type (ident->type info name))
|
|
|
|
(fields (or (type->description info type) '()))
|
|
|
|
(size (type->size info type)))
|
|
|
|
(append-text info (wrap-as (i386:value->accu size)))))
|
|
|
|
|
|
|
|
((sizeof-type (type-name (decl-spec-list (type-spec (fixed-type ,name)))))
|
|
|
|
(let* ((type name)
|
|
|
|
(fields (or (type->description info type) '()))
|
|
|
|
(size (type->size info type)))
|
|
|
|
(append-text info (wrap-as (i386:value->accu size)))))
|
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
((sizeof-type (type-name (decl-spec-list (type-spec (struct-ref (ident ,name))))))
|
2017-03-17 16:32:23 +00:00
|
|
|
(let* ((type (list "struct" name))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(fields (or (type->description info type) '()))
|
|
|
|
(size (type->size info type)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (wrap-as (i386:value->accu size)))))
|
2017-05-08 19:32:32 +00:00
|
|
|
|
2017-03-13 18:38:38 +00:00
|
|
|
;; c+p expr->arg
|
2017-04-05 12:24:34 +00:00
|
|
|
;; g_cells[<expr>]
|
|
|
|
((array-ref ,index (p-expr (ident ,array)))
|
2017-04-07 21:06:09 +00:00
|
|
|
(let* ((type (ident->type info array))
|
2017-04-17 00:15:11 +00:00
|
|
|
(ptr (ident->pointer info array))
|
|
|
|
(size (if (< ptr 2) (type->size info type)
|
|
|
|
4))
|
2017-04-07 21:06:09 +00:00
|
|
|
(info ((expr->accu* info) o)))
|
|
|
|
(append-text info (wrap-as (append (case size
|
|
|
|
((1) (i386:byte-mem->accu))
|
|
|
|
((4) (i386:mem->accu))
|
|
|
|
(else '())))))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
|
|
|
|
;; f.field
|
|
|
|
((d-sel (ident ,field) (p-expr (ident ,array)))
|
|
|
|
(let* ((type (ident->type info array))
|
|
|
|
(fields (type->description info type))
|
|
|
|
(field-size 4) ;; FIXME:4, not fixed
|
|
|
|
(offset (* field-size (1- (length (member field (reverse fields) (lambda (a b) (equal? a (cdr b))))))))
|
|
|
|
(text (.text info)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (append ((ident->accu info) array)
|
|
|
|
(wrap-as (i386:mem+n->accu offset))))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
|
|
|
|
((d-sel (ident ,field) (array-ref ,index (p-expr (ident ,array))))
|
2017-04-07 21:06:09 +00:00
|
|
|
(let* ((type (ident->type info array))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(fields (or (type->description info type) '()))
|
|
|
|
(field-size 4) ;; FIXME:4, not fixed
|
|
|
|
(rest (or (member field (reverse fields) (lambda (a b) (equal? a (cdr b))))
|
2017-04-02 15:01:22 +00:00
|
|
|
(begin
|
|
|
|
(stderr "no field:~a\n" field)
|
2017-04-06 07:12:50 +00:00
|
|
|
'())))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(offset (* field-size (1- (length rest))))
|
2017-04-07 21:06:09 +00:00
|
|
|
(info ((expr->accu* info) `(array-ref ,index (p-expr (ident ,array))))))
|
|
|
|
(append-text info (wrap-as (i386:mem+n->accu offset)))))
|
|
|
|
|
2017-05-06 09:01:58 +00:00
|
|
|
((i-sel (ident ,field) (p-expr (ident ,array)))
|
|
|
|
(let* ((type (ident->type info array))
|
|
|
|
(fields (type->description info type))
|
|
|
|
(field-size 4) ;; FIXME:4, not fixed
|
|
|
|
(offset (* field-size (1- (length (member field (reverse fields) (lambda (a b) (equal? a (cdr b))))))))
|
|
|
|
(text (.text info)))
|
|
|
|
(append-text info (append ((ident-address->accu info) array)
|
|
|
|
(wrap-as (i386:mem->accu))
|
|
|
|
(wrap-as (i386:mem+n->accu offset))))))
|
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
;;; FIXME: FROM INFO ...only zero?!
|
|
|
|
((p-expr (fixed ,value))
|
|
|
|
(let ((value (cstring->number value)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (wrap-as (i386:value->accu value)))))
|
2017-01-17 18:03:08 +00:00
|
|
|
|
2017-03-09 22:27:12 +00:00
|
|
|
((p-expr (char ,char))
|
|
|
|
(let ((char (char->integer (car (string->list char)))))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (wrap-as (i386:value->accu char)))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
|
|
|
|
((p-expr (ident ,name))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info ((ident->accu info) name)))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
|
|
|
|
((de-ref (p-expr (ident ,name)))
|
2017-03-17 16:32:23 +00:00
|
|
|
(let* ((type (ident->type info name))
|
2017-04-17 00:15:11 +00:00
|
|
|
(ptr (ident->pointer info name))
|
|
|
|
(size (if (= ptr 1) (type->size info type)
|
|
|
|
4)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (append ((ident->accu info) name)
|
|
|
|
(wrap-as (if (= size 1) (i386:byte-mem->accu)
|
|
|
|
(i386:mem->accu)))))))
|
2017-01-17 18:03:08 +00:00
|
|
|
|
2017-04-17 00:15:11 +00:00
|
|
|
((de-ref (post-inc (p-expr (ident ,name))))
|
|
|
|
(let* ((info ((expr->accu info) `(de-ref (p-expr (ident ,name)))))
|
|
|
|
(type (ident->type info name))
|
|
|
|
(ptr (ident->pointer info name))
|
2017-05-07 05:36:44 +00:00
|
|
|
(size (if (= ptr 1) (type->size info type)
|
|
|
|
4)))
|
2017-04-17 00:15:11 +00:00
|
|
|
(append-text info ((ident-add info) name size))))
|
|
|
|
|
|
|
|
((de-ref ,expr)
|
|
|
|
(let ((info ((expr->accu info) expr)))
|
|
|
|
(append-text info (wrap-as (i386:byte-mem->accu))))) ;; FIXME: byte
|
|
|
|
|
2017-04-05 18:11:13 +00:00
|
|
|
((fctn-call (p-expr (ident ,name)) (expr-list . ,expr-list))
|
|
|
|
(if (equal? name "asm") (let ((arg0 (cadr (cadar expr-list)))) ;; FIXME
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (wrap-as (asm->hex arg0))))
|
2017-04-23 11:53:36 +00:00
|
|
|
(let* ((text-length (length text))
|
2017-04-05 18:11:13 +00:00
|
|
|
(args-info (let loop ((expressions (reverse expr-list)) (info info))
|
|
|
|
(if (null? expressions) info
|
|
|
|
(loop (cdr expressions) ((expr->arg info) (car expressions))))))
|
|
|
|
(n (length expr-list)))
|
|
|
|
(if (and (not (assoc-ref locals name))
|
|
|
|
(assoc-ref (.functions info) name))
|
2017-04-23 11:53:36 +00:00
|
|
|
(append-text args-info (list (lambda (f g ta t d)
|
|
|
|
(i386:call f g ta t d (+ t (function-offset name f)) n))))
|
2017-04-05 18:11:13 +00:00
|
|
|
(let* ((empty (clone info #:text '()))
|
|
|
|
(accu ((expr->accu empty) `(p-expr (ident ,name)))))
|
2017-04-23 11:53:36 +00:00
|
|
|
(append-text args-info (append (.text accu)
|
|
|
|
(list (lambda (f g ta t d)
|
|
|
|
(i386:call-accu f g ta t d n))))))))))
|
2017-04-05 18:11:13 +00:00
|
|
|
|
|
|
|
((fctn-call ,function (expr-list . ,expr-list))
|
2017-04-23 11:53:36 +00:00
|
|
|
(let* ((text-length (length text))
|
2017-04-05 18:11:13 +00:00
|
|
|
(args-info (let loop ((expressions (reverse expr-list)) (info info))
|
|
|
|
(if (null? expressions) info
|
|
|
|
(loop (cdr expressions) ((expr->arg info) (car expressions))))))
|
|
|
|
(n (length expr-list))
|
|
|
|
(empty (clone info #:text '()))
|
|
|
|
(accu ((expr->accu empty) function)))
|
2017-04-23 11:53:36 +00:00
|
|
|
(append-text args-info (append (.text accu)
|
|
|
|
(list (lambda (f g ta t d)
|
|
|
|
(i386:call-accu f g ta t d n)))))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
|
|
|
|
((cond-expr . ,cond-expr)
|
|
|
|
((ast->info info) `(expr-stmt ,o)))
|
|
|
|
|
|
|
|
((post-inc (p-expr (ident ,name)))
|
2017-04-17 00:15:11 +00:00
|
|
|
(let* ((type (ident->type info name))
|
|
|
|
(ptr (ident->pointer info name))
|
|
|
|
(size (if (> ptr 1) 4 1)))
|
|
|
|
(append-text info (append ((ident->accu info) name)
|
|
|
|
((ident-add info) name size)))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
|
2017-04-05 21:05:16 +00:00
|
|
|
((post-dec (p-expr (ident ,name)))
|
2017-04-12 19:27:59 +00:00
|
|
|
(or (assoc-ref locals name) (begin (stderr "i-- ~a\n" name) (error "undefined identifier: " name)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (append ((ident->accu info) name)
|
|
|
|
((ident-add info) name -1))))
|
2017-04-05 21:05:16 +00:00
|
|
|
|
|
|
|
((pre-inc (p-expr (ident ,name)))
|
2017-04-12 19:27:59 +00:00
|
|
|
(or (assoc-ref locals name) (begin (stderr "++i ~a\n" name) (error "undefined identifier: " name)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (append ((ident-add info) name 1)
|
|
|
|
((ident->accu info) name))))
|
2017-04-05 21:05:16 +00:00
|
|
|
|
|
|
|
((pre-dec (p-expr (ident ,name)))
|
2017-04-12 19:27:59 +00:00
|
|
|
(or (assoc-ref locals name) (begin (stderr "--i ~a\n" name) (error "undefined identifier: " name)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (append ((ident-add info) name -1)
|
|
|
|
((ident->accu info) name))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
|
2017-04-07 12:31:35 +00:00
|
|
|
((add ,a ,b) ((binop->accu info) a b (i386:accu+base)))
|
|
|
|
((sub ,a ,b) ((binop->accu info) a b (i386:accu-base)))
|
|
|
|
((bitwise-or ,a ,b) ((binop->accu info) a b (i386:accu-or-base)))
|
2017-05-06 12:57:39 +00:00
|
|
|
((bitwise-and ,a ,b) ((binop->accu info) a b (i386:accu-and-base)))
|
|
|
|
((bitwise-xor ,a ,b) ((binop->accu info) a b (i386:accu-xor-base)))
|
2017-04-07 12:31:35 +00:00
|
|
|
((lshift ,a ,b) ((binop->accu info) a b (i386:accu<<base)))
|
|
|
|
((rshift ,a ,b) ((binop->accu info) a b (i386:accu>>base)))
|
|
|
|
((div ,a ,b) ((binop->accu info) a b (i386:accu/base)))
|
|
|
|
((mod ,a ,b) ((binop->accu info) a b (i386:accu%base)))
|
|
|
|
((mul ,a ,b) ((binop->accu info) a b (i386:accu*base)))
|
mescc: Mini-mes (gcc-compiled) runs read-0.mes.
* module/language/c99/compiler.mes (expr->accu): Add mul.
(test->jump->info): Add le, ge.
(ast->info): Support int and char* initialization at top level.
* module/mes/as-i386.mes (i386:accu*base, i386:Xjump-cz,
i386:Xjump-ncz): New function.
* module/mes/as-i386.scm: Export them.
* doc/examples/t.c (test): Test them.
* module/mes/libc.mes (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
(libc): Export them.
* module/mes/mini-0.mes: Load full reader.
* mlibc.c (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
* mes.c (list length error lookup_ getchar ungetchar peekchar
peek_byte read_byte unread_byte greater_p less_p): Move functions
needed to run read-0.mes into core.
* doc/examples/mini-mes.c: Likewise.
* lib.c (length, error): Comment-out.
* math.c (greater_p, less_p): Comment-out.
* posix.c: (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte): Comment-out.
* reader.c (lookup_): Comment-out.
2017-03-22 05:39:24 +00:00
|
|
|
|
2017-04-06 07:12:50 +00:00
|
|
|
((not ,expr)
|
|
|
|
(let* ((test-info ((ast->info info) expr)))
|
|
|
|
(clone info #:text
|
|
|
|
(append (.text test-info)
|
2017-04-07 07:36:30 +00:00
|
|
|
(wrap-as (i386:accu-not)))
|
2017-04-06 07:12:50 +00:00
|
|
|
#:globals (.globals test-info))))
|
|
|
|
|
|
|
|
((neg (p-expr (fixed ,value)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (value->accu (- (cstring->number value)))))
|
2017-04-06 07:12:50 +00:00
|
|
|
|
|
|
|
((neg (p-expr (ident ,name)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (append ((ident->base info) name)
|
|
|
|
(wrap-as (i386:value->accu 0))
|
|
|
|
(wrap-as (i386:sub-base)))))
|
2017-04-06 07:12:50 +00:00
|
|
|
|
2017-05-06 15:30:14 +00:00
|
|
|
((eq ,a ,b) ((binop->accu info) a b (append (i386:sub-base) (i386:z->accu))))
|
2017-04-07 12:31:35 +00:00
|
|
|
((ge ,a ,b) ((binop->accu info) b a (i386:sub-base)))
|
|
|
|
((gt ,a ,b) ((binop->accu info) b a (i386:sub-base)))
|
2017-05-06 15:30:14 +00:00
|
|
|
|
|
|
|
;; FIXME: set accu *and* flags
|
|
|
|
((ne ,a ,b) ((binop->accu info) a b (append (i386:push-accu)
|
|
|
|
(i386:sub-base)
|
|
|
|
(i386:nz->accu)
|
|
|
|
(i386:accu<->stack)
|
|
|
|
(i386:sub-base)
|
|
|
|
(i386:xor-zf)
|
|
|
|
(i386:pop-accu))))
|
|
|
|
|
|
|
|
((ne ,a ,b) ((binop->accu info) a b (append (i386:sub-base) (i386:xor-zf))))
|
2017-04-07 12:31:35 +00:00
|
|
|
((le ,a ,b) ((binop->accu info) b a (i386:base-sub)))
|
|
|
|
((lt ,a ,b) ((binop->accu info) b a (i386:base-sub)))
|
2017-03-12 10:05:20 +00:00
|
|
|
|
2017-05-06 12:57:39 +00:00
|
|
|
((or ,a ,b)
|
|
|
|
(let* ((empty (clone info #:text '()))
|
|
|
|
(b-length (length (append (i386:Xjump-nz 0)
|
|
|
|
(i386:accu-test))))
|
|
|
|
(info ((expr->accu info) a))
|
|
|
|
(info (append-text info (wrap-as (i386:accu-test))))
|
|
|
|
(info (append-text info (wrap-as (append (i386:Xjump-nz (- b-length 1))
|
|
|
|
(i386:accu-test)))))
|
|
|
|
(info ((expr->accu info) b))
|
|
|
|
(info (append-text info (wrap-as (i386:accu-test)))))
|
|
|
|
info))
|
|
|
|
|
|
|
|
((and ,a ,b)
|
|
|
|
(let* ((empty (clone info #:text '()))
|
|
|
|
(b-length (length (append (i386:Xjump-z 0)
|
|
|
|
(i386:accu-test))))
|
|
|
|
(info ((expr->accu info) a))
|
|
|
|
(info (append-text info (wrap-as (i386:accu-test))))
|
|
|
|
(info (append-text info (wrap-as (append (i386:Xjump-z (- b-length 1))
|
|
|
|
(i386:accu-test)))))
|
|
|
|
(info ((expr->accu info) b))
|
|
|
|
(info (append-text info (wrap-as (i386:accu-test)))))
|
|
|
|
info))
|
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
((cast ,cast ,o)
|
|
|
|
((expr->accu info) o))
|
|
|
|
|
2017-05-07 05:36:44 +00:00
|
|
|
((assn-expr (de-ref (post-inc (p-expr (ident ,name)))) (op ,op) ,b)
|
|
|
|
(let ((info ((expr->accu info) `(assn-expr (de-ref (p-expr (ident ,name))) (op ,op) ,b))))
|
|
|
|
(append-text info ((ident-add info) name 1)))) ;; FIXME: size
|
|
|
|
|
|
|
|
((assn-expr (de-ref (post-dec (p-expr (ident ,name)))) (op ,op) ,b)
|
|
|
|
(let ((info ((expr->accu info) `(assn-expr (de-ref (p-expr (ident ,name))) (op ,op) ,b))))
|
|
|
|
(append-text info ((ident-add info) name -1)))) ;; FIXME: size
|
|
|
|
|
2017-04-08 04:31:12 +00:00
|
|
|
((assn-expr ,a (op ,op) ,b)
|
|
|
|
(let* ((info ((expr->accu info) b))
|
|
|
|
(info (if (equal? op "=") info
|
|
|
|
(let* ((info (append-text info (wrap-as (i386:push-accu))))
|
|
|
|
(info ((expr->accu info) a))
|
|
|
|
(info (append-text info (wrap-as (i386:pop-base)))))
|
|
|
|
(append-text info (cond ((equal? op "+=") (wrap-as (i386:accu+base)))
|
|
|
|
((equal? op "-=") (wrap-as (i386:accu-base)))
|
|
|
|
((equal? op "*=") (wrap-as (i386:accu*base)))
|
|
|
|
((equal? op "/=") (wrap-as (i386:accu/base)))
|
|
|
|
((equal? op "%=") (wrap-as (i386:accu%base)))
|
|
|
|
((equal? op "|=") (wrap-as (i386:accu-or-base)))
|
|
|
|
(else (error "mescc: op ~a not supported: ~a\n" op o))))))))
|
|
|
|
(pmatch a
|
|
|
|
((p-expr (ident ,name)) (append-text info ((accu->ident info) name)))
|
2017-05-04 17:39:23 +00:00
|
|
|
((d-sel (ident ,field) ,p-expr)
|
|
|
|
(let* ((type (p-expr->type info p-expr))
|
2017-04-08 04:31:12 +00:00
|
|
|
(fields (type->description info type))
|
|
|
|
(size (type->size info type))
|
|
|
|
(field-size 4) ;; FIXME:4, not fixed
|
|
|
|
(offset (* field-size (1- (length (member field (reverse fields) (lambda (a b) (equal? a (cdr b))))))))
|
|
|
|
(info (append-text info (wrap-as (i386:push-accu))))
|
|
|
|
(info ((expr->accu* info) a))
|
|
|
|
(info (append-text info (wrap-as (i386:pop-base)))))
|
|
|
|
(append-text info (wrap-as (i386:base->accu-address))))) ; FIXME: size
|
2017-04-17 00:15:11 +00:00
|
|
|
;; FIXME: c&p above
|
2017-04-08 04:31:12 +00:00
|
|
|
((de-ref (p-expr (ident ,array)))
|
2017-05-07 05:36:44 +00:00
|
|
|
(let* ((type (ident->type info array))
|
|
|
|
(ptr (ident->pointer info array))
|
|
|
|
(size (if (> ptr 1) 4 1)))
|
|
|
|
(append-text info (append (wrap-as (i386:accu->base))
|
|
|
|
((base->ident-address info) array)
|
|
|
|
(i386:base->accu)))))
|
2017-04-08 04:31:12 +00:00
|
|
|
((array-ref ,index (p-expr (ident ,array)))
|
|
|
|
(let* ((type (ident->type info array))
|
|
|
|
(size (type->size info type))
|
|
|
|
(info (append-text info (wrap-as (append (i386:push-accu)))))
|
|
|
|
(info ((expr->accu* info) a))
|
|
|
|
(info (append-text info (wrap-as (append (i386:pop-base))))))
|
|
|
|
(append-text info
|
|
|
|
(append (if (eq? size 1) (wrap-as (i386:byte-base->accu-address))
|
2017-05-05 07:24:19 +00:00
|
|
|
(if (<= size 4) (wrap-as (i386:base->accu-address))
|
|
|
|
(append
|
|
|
|
(wrap-as (i386:base-address->accu-address))
|
|
|
|
(wrap-as (append (i386:accu+n 4)
|
|
|
|
(i386:base+n 4)
|
|
|
|
(i386:base-address->accu-address)))
|
|
|
|
(if (<= size 8) '()
|
|
|
|
(wrap-as (append (i386:accu+n 4)
|
|
|
|
(i386:base+n 4)
|
|
|
|
(i386:base-address->accu-address)))))))))))
|
2017-04-12 19:27:59 +00:00
|
|
|
(_ (error "expr->accu: unsupported assign: " a)))))
|
2017-04-06 07:12:50 +00:00
|
|
|
|
2017-04-12 19:27:59 +00:00
|
|
|
(_ (error "expr->accu: unsupported: " o))))))
|
2017-04-06 07:12:50 +00:00
|
|
|
|
2017-04-07 12:41:47 +00:00
|
|
|
(define (expr->base info)
|
2017-04-06 21:05:44 +00:00
|
|
|
(lambda (o)
|
2017-04-07 07:36:30 +00:00
|
|
|
(let* ((info (append-text info (wrap-as (i386:push-accu))))
|
2017-04-06 21:05:44 +00:00
|
|
|
(info ((expr->accu info) o))
|
2017-04-07 07:36:30 +00:00
|
|
|
(info (append-text info (wrap-as (append (i386:accu->base) (i386:pop-accu))))))
|
2017-04-06 21:05:44 +00:00
|
|
|
info)))
|
|
|
|
|
2017-04-07 12:31:35 +00:00
|
|
|
(define (binop->accu info)
|
2017-04-07 05:06:35 +00:00
|
|
|
(lambda (a b c)
|
|
|
|
(let* ((info ((expr->accu info) a))
|
2017-04-07 12:41:47 +00:00
|
|
|
(info ((expr->base info) b)))
|
2017-04-07 07:36:30 +00:00
|
|
|
(append-text info (wrap-as c)))))
|
2017-04-07 05:06:35 +00:00
|
|
|
|
|
|
|
(define (append-text info text)
|
|
|
|
(clone info #:text (append (.text info) text)))
|
|
|
|
|
2017-04-07 07:36:30 +00:00
|
|
|
(define (wrap-as o)
|
2017-04-07 05:06:35 +00:00
|
|
|
(list (lambda (f g ta t d) o)))
|
|
|
|
|
2017-04-06 07:12:50 +00:00
|
|
|
(define (expr->accu* info)
|
|
|
|
(lambda (o)
|
|
|
|
(pmatch o
|
2017-04-06 21:05:44 +00:00
|
|
|
;; g_cells[<expr>]
|
|
|
|
((array-ref ,index (p-expr (ident ,array)))
|
|
|
|
(let* ((info ((expr->accu info) index))
|
|
|
|
(type (ident->type info array))
|
2017-04-17 00:15:11 +00:00
|
|
|
(ptr (ident->pointer info array))
|
|
|
|
(size (if (< ptr 2) (type->size info type)
|
|
|
|
4)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (append (wrap-as (append (i386:accu->base)
|
|
|
|
(if (eq? size 1) '()
|
|
|
|
(append
|
|
|
|
(if (<= size 4) '()
|
|
|
|
(i386:accu+accu))
|
|
|
|
(if (<= size 8) '()
|
|
|
|
(i386:accu+base))
|
|
|
|
(i386:accu-shl 2)))))
|
|
|
|
((ident->base info) array)
|
|
|
|
(wrap-as (i386:accu+base))))))
|
2017-04-06 21:05:44 +00:00
|
|
|
|
2017-04-07 21:06:09 +00:00
|
|
|
;; g_cells[<expr>].type
|
|
|
|
((d-sel (ident ,field) (array-ref ,index (p-expr (ident ,array))))
|
2017-04-06 07:12:50 +00:00
|
|
|
(let* ((type (ident->type info array))
|
|
|
|
(fields (or (type->description info type) '()))
|
|
|
|
(field-size 4) ;; FIXME:4, not fixed
|
|
|
|
(offset (* field-size (1- (length (member field (reverse fields) (lambda (a b) (equal? a (cdr b))))))))
|
2017-04-07 21:06:09 +00:00
|
|
|
(info ((expr->accu* info) `(array-ref ,index (p-expr (ident ,array))))))
|
|
|
|
(append-text info (wrap-as (append (i386:accu+value offset))))))
|
2017-04-06 07:12:50 +00:00
|
|
|
|
|
|
|
((d-sel (ident ,field) (p-expr (ident ,name)))
|
|
|
|
(let* ((type (ident->type info name))
|
|
|
|
(fields (or (type->description info type) '()))
|
|
|
|
(field-size 4) ;; FIXME
|
|
|
|
(offset (* field-size (1- (length (member field (reverse fields) (lambda (a b) (equal? a (cdr b))))))))
|
|
|
|
(text (.text info)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (append ((ident->accu info) name)
|
|
|
|
(wrap-as (i386:accu+value offset))))))
|
2017-01-17 18:03:08 +00:00
|
|
|
|
2017-04-12 19:27:59 +00:00
|
|
|
(_ (error "expr->accu*: unsupported: " o)))))
|
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
|
|
|
|
2017-01-10 21:44:01 +00:00
|
|
|
(define (ident->constant name value)
|
|
|
|
(cons name value))
|
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(define (make-type name type size description)
|
|
|
|
(cons name (list type size description)))
|
|
|
|
|
|
|
|
(define (enum->type name fields)
|
|
|
|
(make-type name 'enum 4 fields))
|
|
|
|
|
|
|
|
(define (struct->type name fields)
|
|
|
|
(make-type name 'struct (* 4 (length fields)) fields)) ;; FIXME
|
|
|
|
|
|
|
|
(define (decl->type o)
|
|
|
|
(pmatch o
|
|
|
|
((fixed-type ,type) type)
|
|
|
|
((struct-ref (ident ,name)) (list "struct" name))
|
|
|
|
((decl (decl-spec-list (type-spec (struct-ref (ident ,name)))));; "scm"
|
|
|
|
(list "struct" name)) ;; FIXME
|
2017-03-17 16:32:23 +00:00
|
|
|
((typename ,name) name)
|
2017-04-17 00:15:11 +00:00
|
|
|
(,name name)
|
2017-04-12 19:27:59 +00:00
|
|
|
(_ (error "decl->type: unsupported: " o))))
|
2017-01-10 21:44:01 +00:00
|
|
|
|
2017-01-04 23:55:46 +00:00
|
|
|
(define (expr->global o)
|
2017-04-02 09:55:37 +00:00
|
|
|
(pmatch o
|
2017-01-04 23:55:46 +00:00
|
|
|
((p-expr (string ,string)) (string->global string))
|
2017-04-17 00:15:11 +00:00
|
|
|
((p-expr (fixed ,value)) (int->global (cstring->number value)))
|
2017-04-02 09:55:37 +00:00
|
|
|
(_ #f)))
|
|
|
|
|
2017-03-09 07:14:27 +00:00
|
|
|
(define (initzer->global o)
|
|
|
|
(pmatch o
|
|
|
|
((initzer ,initzer) (expr->global initzer))
|
|
|
|
(_ #f)))
|
|
|
|
|
2017-01-03 11:45:47 +00:00
|
|
|
(define (byte->hex o)
|
|
|
|
(string->number (string-drop o 2) 16))
|
|
|
|
|
|
|
|
(define (asm->hex o)
|
|
|
|
(let ((prefix ".byte "))
|
2017-01-17 18:03:08 +00:00
|
|
|
(if (not (string-prefix? prefix o)) (begin (stderr "SKIP:~s\n" o)'())
|
2017-01-04 23:55:46 +00:00
|
|
|
(let ((s (string-drop o (string-length prefix))))
|
|
|
|
(map byte->hex (string-split s #\space))))))
|
2017-01-03 11:45:47 +00:00
|
|
|
|
2017-05-06 06:39:04 +00:00
|
|
|
(define (clause->jump-info info)
|
2017-01-17 18:03:08 +00:00
|
|
|
(define (jump n)
|
2017-04-07 07:36:30 +00:00
|
|
|
(wrap-as (i386:Xjump n)))
|
2017-01-17 18:03:08 +00:00
|
|
|
(define (jump-nz n)
|
2017-04-07 07:36:30 +00:00
|
|
|
(wrap-as (i386:Xjump-nz n)))
|
2017-04-09 04:52:39 +00:00
|
|
|
(define (jump-z n)
|
|
|
|
(wrap-as (i386:Xjump-z n)))
|
2017-01-17 18:03:08 +00:00
|
|
|
(define (statement->info info body-length)
|
|
|
|
(lambda (o)
|
|
|
|
(pmatch o
|
2017-04-07 07:53:56 +00:00
|
|
|
((break) (append-text info (jump body-length)))
|
2017-04-10 04:59:50 +00:00
|
|
|
(_ ((ast->info info) o)))))
|
2017-04-09 04:52:39 +00:00
|
|
|
(define (test->text test)
|
|
|
|
(let ((value (pmatch test
|
|
|
|
(0 0)
|
2017-05-02 15:00:07 +00:00
|
|
|
((p-expr (char ,value)) (char->integer (car (string->list value))))
|
2017-04-09 04:52:39 +00:00
|
|
|
((p-expr (ident ,constant)) (assoc-ref (.constants info) constant))
|
|
|
|
((p-expr (fixed ,value)) (cstring->number value))
|
2017-05-02 15:00:07 +00:00
|
|
|
((neg (p-expr (fixed ,value))) (- (cstring->number value)))
|
|
|
|
(_ (error "case test: unsupported: " test)))))
|
2017-04-09 04:52:39 +00:00
|
|
|
(lambda (n)
|
|
|
|
(append (wrap-as (i386:accu-cmp-value value))
|
|
|
|
(jump-z (+ (length (text->list (jump 0)))
|
|
|
|
(if (= n 0) 0
|
|
|
|
(* n (length (text->list ((test->text 0) 0)))))))))))
|
|
|
|
(define (cases+jump cases clause-length)
|
|
|
|
(append-text info
|
|
|
|
(append
|
|
|
|
(append-map (lambda (t i) (t i)) cases (reverse (iota (length cases))))
|
|
|
|
(if (null? cases) '()
|
|
|
|
(jump clause-length)))))
|
2017-01-17 18:03:08 +00:00
|
|
|
(lambda (o)
|
2017-04-09 04:52:39 +00:00
|
|
|
(lambda (body-length)
|
|
|
|
(let loop ((o o) (cases '()) (clause #f))
|
|
|
|
(pmatch o
|
|
|
|
((case ,test ,statement)
|
|
|
|
(loop statement (append cases (list (test->text test))) clause))
|
|
|
|
((default ,statement)
|
|
|
|
(loop statement cases clause))
|
|
|
|
((compd-stmt (block-item-list))
|
|
|
|
(loop '() cases clause))
|
|
|
|
((compd-stmt (block-item-list . ,elements))
|
|
|
|
(let ((clause (or clause (cases+jump cases 0))))
|
|
|
|
(loop `(compd-stmt (block-item-list ,@(cdr elements))) cases
|
|
|
|
((statement->info clause body-length) (car elements)))))
|
|
|
|
(()
|
|
|
|
(let* ((cases-length (length (.text (cases+jump cases 0))))
|
|
|
|
(clause-text (list-tail (.text clause) cases-length))
|
|
|
|
(clause-length (length (text->list clause-text))))
|
|
|
|
(clone clause #:text
|
|
|
|
(append (.text (cases+jump cases clause-length))
|
|
|
|
clause-text))))
|
|
|
|
(_
|
|
|
|
(let ((clause (or clause (cases+jump cases 0))))
|
|
|
|
(loop '() cases
|
|
|
|
((statement->info clause body-length) o)))))))))
|
2017-01-17 18:03:08 +00:00
|
|
|
|
2017-01-08 16:51:40 +00:00
|
|
|
(define (test->jump->info info)
|
2017-03-18 07:17:18 +00:00
|
|
|
(define (jump type . test)
|
2017-01-08 16:51:40 +00:00
|
|
|
(lambda (o)
|
|
|
|
(let* ((text (.text info))
|
|
|
|
(info (clone info #:text '()))
|
|
|
|
(info ((ast->info info) o))
|
|
|
|
(jump-text (lambda (body-length)
|
2017-04-07 07:36:30 +00:00
|
|
|
(wrap-as (type body-length)))))
|
2017-04-06 07:12:50 +00:00
|
|
|
(lambda (body-length)
|
|
|
|
(clone info #:text
|
|
|
|
(append text
|
|
|
|
(.text info)
|
|
|
|
(if (null? test) '() (car test))
|
|
|
|
(jump-text body-length)))))))
|
2017-01-08 16:51:40 +00:00
|
|
|
(lambda (o)
|
|
|
|
(pmatch o
|
2017-03-24 20:45:19 +00:00
|
|
|
;; unsigned
|
|
|
|
;; ((le ,a ,b) ((jump i386:Xjump-ncz) o)) ; ja
|
|
|
|
;; ((lt ,a ,b) ((jump i386:Xjump-nc) o)) ; jae
|
|
|
|
;; ((ge ,a ,b) ((jump i386:Xjump-ncz) o))
|
|
|
|
;; ((gt ,a ,b) ((jump i386:Xjump-nc) o))
|
|
|
|
|
|
|
|
((le ,a ,b) ((jump i386:Xjump-g) o))
|
|
|
|
((lt ,a ,b) ((jump i386:Xjump-ge) o))
|
|
|
|
((ge ,a ,b) ((jump i386:Xjump-g) o))
|
|
|
|
((gt ,a ,b) ((jump i386:Xjump-ge) o))
|
|
|
|
|
2017-02-24 12:27:39 +00:00
|
|
|
((ne ,a ,b) ((jump i386:Xjump-nz) o))
|
|
|
|
((eq ,a ,b) ((jump i386:Xjump-nz) o))
|
|
|
|
((not _) ((jump i386:Xjump-z) o))
|
2017-01-08 16:51:40 +00:00
|
|
|
((and ,a ,b)
|
2017-04-23 11:53:08 +00:00
|
|
|
(let* ((globals (.globals info))
|
|
|
|
(text (.text info))
|
2017-01-08 16:51:40 +00:00
|
|
|
(info (clone info #:text '()))
|
|
|
|
|
|
|
|
(a-jump ((test->jump->info info) a))
|
|
|
|
(a-text (.text (a-jump 0)))
|
|
|
|
(a-length (length (text->list a-text)))
|
|
|
|
|
|
|
|
(b-jump ((test->jump->info info) b))
|
|
|
|
(b-text (.text (b-jump 0)))
|
|
|
|
(b-length (length (text->list b-text))))
|
|
|
|
|
|
|
|
(lambda (body-length)
|
2017-04-23 11:53:08 +00:00
|
|
|
(let* ((info (append-text info text))
|
|
|
|
(a-info (a-jump (+ b-length body-length)))
|
|
|
|
(info (append-text info (.text a-info)))
|
|
|
|
(b-info (b-jump body-length))
|
|
|
|
(info (append-text info (.text b-info))))
|
|
|
|
(clone info
|
|
|
|
#:globals (append globals
|
|
|
|
(list-tail (.globals a-info) (length globals))
|
|
|
|
(list-tail (.globals b-info) (length globals))))))))
|
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
((or ,a ,b)
|
2017-04-23 11:53:08 +00:00
|
|
|
(let* ((globals (.globals info))
|
|
|
|
(text (.text info))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(info (clone info #:text '()))
|
|
|
|
|
|
|
|
(a-jump ((test->jump->info info) a))
|
|
|
|
(a-text (.text (a-jump 0)))
|
|
|
|
(a-length (length (text->list a-text)))
|
|
|
|
|
2017-04-07 07:36:30 +00:00
|
|
|
(jump-text (wrap-as (i386:Xjump 0)))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(jump-length (length (text->list jump-text)))
|
|
|
|
|
|
|
|
(b-jump ((test->jump->info info) b))
|
|
|
|
(b-text (.text (b-jump 0)))
|
|
|
|
(b-length (length (text->list b-text)))
|
|
|
|
|
2017-04-07 07:36:30 +00:00
|
|
|
(jump-text (wrap-as (i386:Xjump b-length))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
|
|
|
|
(lambda (body-length)
|
2017-04-23 11:53:08 +00:00
|
|
|
(let* ((info (append-text info text))
|
|
|
|
(a-info (a-jump jump-length))
|
|
|
|
(info (append-text info (.text a-info)))
|
|
|
|
(info (append-text info jump-text))
|
|
|
|
(b-info (b-jump body-length))
|
|
|
|
(info (append-text info (.text b-info))))
|
|
|
|
(clone info
|
|
|
|
#:globals (append globals
|
|
|
|
(list-tail (.globals a-info) (length globals))
|
|
|
|
(list-tail (.globals b-info) (length globals))))))))
|
2017-03-17 22:49:29 +00:00
|
|
|
|
2017-03-18 07:17:18 +00:00
|
|
|
((array-ref . _) ((jump i386:jump-byte-z
|
2017-04-07 07:36:30 +00:00
|
|
|
(wrap-as (i386:accu-zero?))) o))
|
2017-03-18 07:17:18 +00:00
|
|
|
|
|
|
|
((de-ref _) ((jump i386:jump-byte-z
|
2017-04-07 07:36:30 +00:00
|
|
|
(wrap-as (i386:accu-zero?))) o))
|
2017-03-18 07:17:18 +00:00
|
|
|
|
|
|
|
((assn-expr (p-expr (ident ,name)) ,op ,expr)
|
|
|
|
((jump i386:Xjump-z
|
|
|
|
(append
|
|
|
|
((ident->accu info) name)
|
2017-04-07 07:36:30 +00:00
|
|
|
(wrap-as (i386:accu-zero?)))) o))
|
2017-03-18 07:17:18 +00:00
|
|
|
|
2017-04-07 07:36:30 +00:00
|
|
|
(_ ((jump i386:Xjump-z (wrap-as (i386:accu-zero?))) o)))))
|
2017-01-08 16:51:40 +00:00
|
|
|
|
mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
procedure and give more debug information.
(ref-local, ref-global): Remove.
(push-global-ref, push-global, push-ident-ref): New functions.
(push-ident): New function.
(expr->arg): Use them.
(ident->accu, ident->accu, accu->ident, value->ident, ident->base):
Take info parameter, also handle globals.
(ident-address->accu, ident->global, cstring->number): New functions.
(ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
(i386:push-global-ref): Rename from i386:ref-global.
(i386:push-local): Rename from i386:ref-local.
(i386:value->local): Rename from i386:local-assign.
(i386:push-global, i386:push-local-ref, i386:value->global,
i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 19:12:06 +00:00
|
|
|
(define (cstring->number s)
|
2017-01-17 18:03:08 +00:00
|
|
|
(cond ((string-prefix? "0x" s) (string->number (string-drop s 2) 16))
|
2017-05-06 16:16:24 +00:00
|
|
|
((string-prefix? "0b" s) (string->number (string-drop s 2) 2))
|
2017-01-17 18:03:08 +00:00
|
|
|
((string-prefix? "0" s) (string->number s 8))
|
|
|
|
(else (string->number s))))
|
|
|
|
|
|
|
|
(define (struct-field o)
|
|
|
|
(pmatch o
|
|
|
|
((comp-decl (decl-spec-list (type-spec (enum-ref (ident ,type))))
|
|
|
|
(comp-declr-list (comp-declr (ident ,name))))
|
|
|
|
(cons type name))
|
|
|
|
((comp-decl (decl-spec-list (type-spec (fixed-type ,type))) (comp-declr-list (comp-declr (ident ,name))))
|
|
|
|
(cons type name))
|
|
|
|
((comp-decl (decl-spec-list (type-spec (typename ,type))) (comp-declr-list (comp-declr (ident ,name))))
|
|
|
|
(cons type name))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
((comp-decl (decl-spec-list (type-spec (fixed-type ,type))) (comp-declr-list (comp-declr (ftn-declr (scope (ptr-declr (pointer) (ident ,name))) (param-list (param-decl (decl-spec-list (type-spec (void)))))))))
|
|
|
|
(cons type name)) ;; FIXME function / int
|
2017-03-09 07:14:27 +00:00
|
|
|
((comp-decl (decl-spec-list (type-spec (fixed-type ,type))) (comp-declr-list (comp-declr (ptr-declr (pointer) (ident ,name)))))
|
|
|
|
(cons type name)) ;; FIXME: ptr/char
|
2017-04-12 19:27:59 +00:00
|
|
|
(_ (error "struct-field: unsupported: " o))))
|
mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
procedure and give more debug information.
(ref-local, ref-global): Remove.
(push-global-ref, push-global, push-ident-ref): New functions.
(push-ident): New function.
(expr->arg): Use them.
(ident->accu, ident->accu, accu->ident, value->ident, ident->base):
Take info parameter, also handle globals.
(ident-address->accu, ident->global, cstring->number): New functions.
(ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
(i386:push-global-ref): Rename from i386:ref-global.
(i386:push-local): Rename from i386:ref-local.
(i386:value->local): Rename from i386:local-assign.
(i386:push-global, i386:push-local-ref, i386:value->global,
i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 19:12:06 +00:00
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(define (ast->type o)
|
|
|
|
(pmatch o
|
|
|
|
((fixed-type ,type)
|
|
|
|
type)
|
|
|
|
((struct-ref (ident ,type))
|
|
|
|
(list "struct" type))
|
|
|
|
(_ (stderr "SKIP: type=~s\n" o)
|
|
|
|
"int")))
|
|
|
|
|
|
|
|
(define i386:type-alist
|
|
|
|
'(("char" . (builtin 1 #f))
|
2017-05-08 19:34:08 +00:00
|
|
|
("short" . (builtin 2 #f))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
("int" . (builtin 4 #f))))
|
|
|
|
|
|
|
|
(define (type->size info o)
|
2017-03-13 18:38:38 +00:00
|
|
|
(pmatch o
|
|
|
|
((decl-spec-list (type-spec (fixed-type ,type)))
|
|
|
|
(type->size info type))
|
|
|
|
((decl-spec-list (type-spec (fixed-type ,type)) (type-qual ,qual))
|
|
|
|
(type->size info type))
|
2017-03-17 16:32:23 +00:00
|
|
|
(_ (let ((type (assoc-ref (.types info) o)))
|
|
|
|
(if type (cadr type)
|
2017-04-12 19:27:59 +00:00
|
|
|
(error "type->size: unsupported: " o))))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
|
|
|
|
(define (ident->decl info o)
|
|
|
|
(or (assoc-ref (.locals info) o)
|
|
|
|
(assoc-ref (.globals info) o)
|
|
|
|
(begin
|
|
|
|
(stderr "NO IDENT: ~a\n" (assoc-ref (.functions info) o))
|
|
|
|
(assoc-ref (.functions info) o))))
|
|
|
|
|
|
|
|
(define (ident->type info o)
|
|
|
|
(and=> (ident->decl info o) car))
|
|
|
|
|
|
|
|
(define (ident->pointer info o)
|
2017-03-02 19:26:13 +00:00
|
|
|
(let ((local (assoc-ref (.locals info) o)))
|
|
|
|
(if local (local:pointer local)
|
|
|
|
(or (and=> (ident->decl info o) global:pointer) 0))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
|
2017-05-04 17:39:23 +00:00
|
|
|
(define (p-expr->type info o)
|
|
|
|
(pmatch o
|
|
|
|
((p-expr (ident ,name)) (ident->type info name))
|
2017-05-05 07:24:19 +00:00
|
|
|
((array-ref ,index (p-expr (ident ,array)))
|
2017-05-04 17:39:23 +00:00
|
|
|
(ident->type info array))
|
|
|
|
(_ (error "p-expr->type: unsupported: " o))))
|
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(define (type->description info o)
|
2017-03-13 18:38:38 +00:00
|
|
|
(pmatch o
|
|
|
|
((decl-spec-list (type-spec (fixed-type ,type)))
|
|
|
|
(type->description info type))
|
|
|
|
((decl-spec-list (type-spec (fixed-type ,type)) (type-qual ,qual))
|
|
|
|
(type->description info type))
|
2017-05-04 17:39:23 +00:00
|
|
|
(_ (let ((type (assoc-ref (.types info) o)))
|
|
|
|
(if (not type) (stderr "TYPES=~s\n" (.types info)))
|
|
|
|
(if type (caddr type)
|
|
|
|
(error "type->description: unsupported:" o))))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
|
|
|
|
(define (local? o) ;; formals < 0, locals > 0
|
|
|
|
(positive? (local:id o)))
|
|
|
|
|
2017-05-06 06:39:04 +00:00
|
|
|
(define (statements->clauses statements)
|
|
|
|
(let loop ((statements statements) (clauses '()))
|
|
|
|
(if (null? statements) clauses
|
|
|
|
(let ((s (car statements)))
|
|
|
|
(pmatch s
|
|
|
|
((case ,test (compd-stmt (block-item-list . _)))
|
|
|
|
(loop (cdr statements) (append clauses (list s))))
|
|
|
|
((case ,test (break))
|
|
|
|
(loop (cdr statements) (append clauses (list s))))
|
|
|
|
((case ,test) (loop (cdr statements) (append clauses (list s))))
|
|
|
|
|
|
|
|
((case ,test ,statement)
|
|
|
|
(let loop2 ((statement statement) (heads `((case ,test))))
|
|
|
|
(define (heads->case heads statement)
|
|
|
|
(if (null? heads) statement
|
|
|
|
(append (car heads) (list (heads->case (cdr heads) statement)))))
|
|
|
|
(pmatch statement
|
|
|
|
((case ,t2 ,s2) (loop2 s2 (append heads `((case ,t2)))))
|
|
|
|
((default ,s2) (loop2 s2 (append heads `((default)))))
|
|
|
|
((compd-stmt (block-item-list . _)) (loop (cdr statements) (append clauses (list (heads->case heads statement)))))
|
|
|
|
(_ (let loop3 ((statements (cdr statements)) (c (list statement)))
|
|
|
|
(if (null? statements) (loop statements (append clauses (list (heads->case heads `(compd-stmt (block-item-list ,@c))))))
|
|
|
|
(let ((s (car statements)))
|
|
|
|
(pmatch s
|
|
|
|
((case . _) (loop statements (append clauses (list (heads->case heads `(compd-stmt (block-item-list ,@c)))))))
|
|
|
|
((default _) (loop statements (append clauses (list (heads->case heads `(compd-stmt (block-item-list ,@c)))))))
|
|
|
|
((break) (loop (cdr statements) (append clauses (list (heads->case heads `(compd-stmt (block-item-list ,@(append c (list s)))))))))
|
|
|
|
(_ (loop3 (cdr statements) (append c (list s))))))))))))
|
|
|
|
((default (compd-stmt (block-item-list _)))
|
|
|
|
(loop (cdr statements) (append clauses (list s))))
|
|
|
|
((default . ,statement)
|
|
|
|
(let loop2 ((statements (cdr statements)) (c statement))
|
|
|
|
(if (null? statements) (loop statements (append clauses (list `(default ,@c))))
|
|
|
|
(let ((s (car statements)))
|
|
|
|
(pmatch s
|
|
|
|
((compd-stmt (block-item-list . _)) (loop (cdr statements) (append clauses (list `(default ,s)))))
|
|
|
|
((case . _) (loop statements (append clauses (list `(default (compd-stmt (block-item-list ,@c)))))))
|
|
|
|
((default _) (loop statements (append clauses (list `(default (compd-stmt (block-item-list ,@c)))))))
|
|
|
|
((break) (loop (cdr statements) (append clauses (list `(default (compd-stmt (block-item-list ,@(append c (list s)))))))))
|
|
|
|
|
|
|
|
(_ (loop2 (cdr statements) (append c (list s)))))))))
|
|
|
|
(_ (error "statements->clauses: unsupported:" s)))))))
|
|
|
|
|
2017-01-04 23:55:46 +00:00
|
|
|
(define (ast->info info)
|
2017-04-02 09:55:37 +00:00
|
|
|
(lambda (o)
|
2017-01-04 23:55:46 +00:00
|
|
|
(let ((globals (.globals info))
|
|
|
|
(locals (.locals info))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(constants (.constants info))
|
2017-01-04 23:55:46 +00:00
|
|
|
(text (.text info)))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(define (add-local locals name type pointer)
|
2017-05-04 17:39:23 +00:00
|
|
|
(let* ((id (if (or (null? locals) (not (local? (cdar locals)))) 1
|
|
|
|
(1+ (local:id (cdar locals)))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(locals (cons (make-local name type pointer id) locals)))
|
2017-01-07 20:53:12 +00:00
|
|
|
locals))
|
2017-04-02 09:55:37 +00:00
|
|
|
(pmatch o
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(((trans-unit . _) . _)
|
|
|
|
((ast-list->info info) o))
|
|
|
|
((trans-unit . ,elements)
|
|
|
|
((ast-list->info info) elements))
|
2017-01-04 23:55:46 +00:00
|
|
|
((fctn-defn . _) ((function->info info) o))
|
|
|
|
((comment . _) info)
|
|
|
|
((cpp-stmt (define (name ,name) (repl ,value)))
|
|
|
|
info)
|
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
((cast (type-name (decl-spec-list (type-spec (void)))) _)
|
|
|
|
info)
|
|
|
|
|
2017-04-10 04:59:50 +00:00
|
|
|
((break)
|
|
|
|
(append-text info (wrap-as (i386:Xjump (- (car (.break info)) (length (text->list text)))))))
|
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
;; FIXME: expr-stmt wrapper?
|
|
|
|
(trans-unit info)
|
2017-01-08 16:51:40 +00:00
|
|
|
((expr-stmt) info)
|
|
|
|
|
2017-01-04 23:55:46 +00:00
|
|
|
((compd-stmt (block-item-list . ,statements)) ((ast-list->info info) statements))
|
|
|
|
|
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 ,test ,body)
|
2017-01-08 16:51:40 +00:00
|
|
|
(let* ((text-length (length text))
|
|
|
|
|
|
|
|
(test-jump->info ((test->jump->info info) test))
|
|
|
|
(test+jump-info (test-jump->info 0))
|
|
|
|
(test-length (length (.text test+jump-info)))
|
|
|
|
|
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
|
|
|
(body-info ((ast->info test+jump-info) body))
|
2017-01-08 16:51:40 +00:00
|
|
|
(text-body-info (.text body-info))
|
|
|
|
(body-text (list-tail text-body-info test-length))
|
|
|
|
(body-length (length (text->list body-text)))
|
|
|
|
|
|
|
|
(text+test-text (.text (test-jump->info body-length)))
|
|
|
|
(test-text (list-tail text+test-text text-length)))
|
2017-01-03 17:22:56 +00:00
|
|
|
|
2017-01-04 23:55:46 +00:00
|
|
|
(clone info #:text
|
2017-01-08 16:51:40 +00:00
|
|
|
(append text
|
|
|
|
test-text
|
2017-01-04 23:55:46 +00:00
|
|
|
body-text)
|
|
|
|
#:globals (.globals body-info))))
|
2017-01-03 17:22:56 +00:00
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
((if ,test ,then ,else)
|
|
|
|
(let* ((text-length (length text))
|
|
|
|
|
|
|
|
(test-jump->info ((test->jump->info info) test))
|
|
|
|
(test+jump-info (test-jump->info 0))
|
|
|
|
(test-length (length (.text test+jump-info)))
|
|
|
|
|
|
|
|
(then-info ((ast->info test+jump-info) then))
|
|
|
|
(text-then-info (.text then-info))
|
|
|
|
(then-text (list-tail text-then-info test-length))
|
2017-04-07 07:36:30 +00:00
|
|
|
(then-jump-text (wrap-as (i386:Xjump 0)))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(then-jump-length (length (text->list then-jump-text)))
|
|
|
|
(then-length (+ (length (text->list then-text)) then-jump-length))
|
|
|
|
|
2017-02-24 12:27:39 +00:00
|
|
|
(then+jump-info (clone then-info #:text (append text-then-info then-jump-text)))
|
|
|
|
(else-info ((ast->info then+jump-info) else))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(text-else-info (.text else-info))
|
2017-02-24 12:27:39 +00:00
|
|
|
(else-text (list-tail text-else-info (length (.text then+jump-info))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(else-length (length (text->list else-text)))
|
|
|
|
|
2017-02-24 12:27:39 +00:00
|
|
|
(text+test-text (.text (test-jump->info then-length)))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(test-text (list-tail text+test-text text-length))
|
2017-04-07 07:36:30 +00:00
|
|
|
(then-jump-text (wrap-as (i386:Xjump else-length))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
|
|
|
|
(clone info #:text
|
|
|
|
(append text
|
|
|
|
test-text
|
|
|
|
then-text
|
|
|
|
then-jump-text
|
|
|
|
else-text)
|
2017-02-24 12:27:39 +00:00
|
|
|
#:globals (append (.globals then-info)
|
|
|
|
(list-tail (.globals else-info) (length globals))))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
|
2017-04-06 07:12:50 +00:00
|
|
|
;; Hmm?
|
2017-01-10 19:27:44 +00:00
|
|
|
((expr-stmt (cond-expr ,test ,then ,else))
|
|
|
|
(let* ((text-length (length text))
|
|
|
|
|
|
|
|
(test-jump->info ((test->jump->info info) test))
|
|
|
|
(test+jump-info (test-jump->info 0))
|
|
|
|
(test-length (length (.text test+jump-info)))
|
|
|
|
|
|
|
|
(then-info ((ast->info test+jump-info) then))
|
|
|
|
(text-then-info (.text then-info))
|
|
|
|
(then-text (list-tail text-then-info test-length))
|
|
|
|
(then-length (length (text->list then-text)))
|
|
|
|
|
2017-04-07 07:36:30 +00:00
|
|
|
(jump-text (wrap-as (i386:Xjump 0)))
|
2017-01-10 19:27:44 +00:00
|
|
|
(jump-length (length (text->list jump-text)))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
|
2017-01-10 19:27:44 +00:00
|
|
|
(test+then+jump-info
|
|
|
|
(clone then-info
|
|
|
|
#:text (append (.text then-info) jump-text)))
|
|
|
|
|
|
|
|
(else-info ((ast->info test+then+jump-info) else))
|
|
|
|
(text-else-info (.text else-info))
|
|
|
|
(else-text (list-tail text-else-info (length (.text test+then+jump-info))))
|
|
|
|
(else-length (length (text->list else-text)))
|
|
|
|
|
|
|
|
(text+test-text (.text (test-jump->info (+ then-length jump-length))))
|
|
|
|
(test-text (list-tail text+test-text text-length))
|
2017-04-07 07:36:30 +00:00
|
|
|
(jump-text (wrap-as (i386:Xjump else-length))))
|
2017-01-10 19:27:44 +00:00
|
|
|
|
|
|
|
(clone info #:text
|
|
|
|
(append text
|
|
|
|
test-text
|
|
|
|
then-text
|
|
|
|
jump-text
|
|
|
|
else-text)
|
|
|
|
#:globals (.globals else-info))))
|
|
|
|
|
2017-05-06 06:39:04 +00:00
|
|
|
((switch ,expr (compd-stmt (block-item-list . ,statements)))
|
|
|
|
(let* ((clauses (statements->clauses statements))
|
|
|
|
(expr ((expr->accu info) expr))
|
2017-01-17 18:03:08 +00:00
|
|
|
(empty (clone info #:text '()))
|
2017-05-06 06:39:04 +00:00
|
|
|
(clause-infos (map (clause->jump-info empty) clauses))
|
|
|
|
(clause-lengths (map (lambda (c-j) (length (text->list (.text (c-j 0))))) clause-infos))
|
|
|
|
(clauses-info (let loop ((clauses clauses) (info expr) (lengths clause-lengths))
|
|
|
|
(if (null? clauses) info
|
|
|
|
(let ((c-j ((clause->jump-info info) (car clauses))))
|
|
|
|
(loop (cdr clauses) (c-j (apply + (cdr lengths))) (cdr lengths)))))))
|
|
|
|
clauses-info))
|
2017-01-17 18:03:08 +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
|
|
|
((for ,init ,test ,step ,body)
|
2017-03-10 06:01:51 +00:00
|
|
|
(let* ((info (clone info #:text '())) ;; FIXME: goto in body...
|
2017-01-05 20:24:56 +00:00
|
|
|
|
|
|
|
(info ((ast->info info) init))
|
|
|
|
|
|
|
|
(init-text (.text info))
|
|
|
|
(init-locals (.locals info))
|
|
|
|
(info (clone info #:text '()))
|
|
|
|
|
|
|
|
(body-info ((ast->info info) body))
|
|
|
|
(body-text (.text body-info))
|
|
|
|
(body-length (length (text->list body-text)))
|
|
|
|
|
2017-04-06 07:12:50 +00:00
|
|
|
(step-info ((expr->accu info) step))
|
2017-01-05 20:24:56 +00:00
|
|
|
(step-text (.text step-info))
|
|
|
|
(step-length (length (text->list step-text)))
|
|
|
|
|
2017-01-10 19:51:29 +00:00
|
|
|
(test-jump->info ((test->jump->info info) test))
|
|
|
|
(test+jump-info (test-jump->info 0))
|
|
|
|
(test-length (length (text->list (.text test+jump-info))))
|
|
|
|
|
2017-04-07 07:36:30 +00:00
|
|
|
(skip-body-text (wrap-as (i386:Xjump (+ body-length step-length))))
|
2017-01-10 19:51:29 +00:00
|
|
|
|
2017-04-07 07:36:30 +00:00
|
|
|
(jump-text (wrap-as (i386:Xjump (- (+ body-length step-length test-length)))))
|
2017-01-10 19:51:29 +00:00
|
|
|
(jump-length (length (text->list jump-text)))
|
|
|
|
|
|
|
|
(test-text (.text (test-jump->info jump-length))))
|
2017-01-05 20:24:56 +00:00
|
|
|
|
|
|
|
(clone info #:text
|
|
|
|
(append text
|
|
|
|
init-text
|
2017-01-10 19:51:29 +00:00
|
|
|
skip-body-text
|
2017-01-05 20:24:56 +00:00
|
|
|
body-text
|
|
|
|
step-text
|
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
|
|
|
test-text
|
2017-01-10 19:51:29 +00:00
|
|
|
jump-text)
|
2017-01-17 17:57:41 +00:00
|
|
|
#:globals (append globals (list-tail (.globals body-info) (length globals)))
|
2017-01-05 20:24:56 +00:00
|
|
|
#:locals locals)))
|
|
|
|
|
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
|
|
|
((while ,test ,body)
|
2017-04-10 04:59:50 +00:00
|
|
|
(let* ((skip-info (lambda (body-length test-length)
|
|
|
|
(clone info
|
|
|
|
#:text (append text (wrap-as (i386:Xjump body-length)))
|
|
|
|
#:break (cons (+ (length (text->list text)) body-length test-length
|
|
|
|
(length (i386:Xjump 0)))
|
|
|
|
(.break info)))))
|
|
|
|
(text (.text (skip-info 0 0)))
|
2017-03-10 06:01:51 +00:00
|
|
|
(text-length (length text))
|
2017-04-10 04:59:50 +00:00
|
|
|
(body-info (lambda (body-length test-length)
|
|
|
|
((ast->info (skip-info body-length test-length)) body)))
|
2017-03-10 06:01:51 +00:00
|
|
|
|
2017-04-10 04:59:50 +00:00
|
|
|
(body-text (list-tail (.text (body-info 0 0)) text-length))
|
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
|
|
|
(body-length (length (text->list body-text)))
|
|
|
|
|
2017-03-10 06:01:51 +00:00
|
|
|
(empty (clone info #:text '()))
|
|
|
|
(test-jump->info ((test->jump->info empty) test))
|
2017-01-08 16:51:40 +00:00
|
|
|
(test+jump-info (test-jump->info 0))
|
|
|
|
(test-length (length (text->list (.text test+jump-info))))
|
|
|
|
|
2017-04-07 07:36:30 +00:00
|
|
|
(jump-text (wrap-as (i386:Xjump (- (+ body-length test-length)))))
|
2017-01-08 16:51:40 +00:00
|
|
|
(jump-length (length (text->list jump-text)))
|
|
|
|
|
2017-04-10 04:59:50 +00:00
|
|
|
(test-text (.text (test-jump->info jump-length)))
|
|
|
|
|
|
|
|
(body-info (body-info body-length (length (text->list test-text)))))
|
|
|
|
|
2017-01-04 23:55:46 +00:00
|
|
|
(clone info #:text
|
2017-03-10 06:01:51 +00:00
|
|
|
(append
|
|
|
|
(.text body-info)
|
|
|
|
test-text
|
|
|
|
jump-text)
|
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
|
|
|
#:globals (.globals body-info))))
|
|
|
|
|
2017-03-12 10:05:00 +00:00
|
|
|
((do-while ,body ,test)
|
|
|
|
(let* ((text-length (length text))
|
|
|
|
|
|
|
|
(body-info ((ast->info info) body))
|
|
|
|
(body-text (list-tail (.text body-info) text-length))
|
|
|
|
(body-length (length (text->list body-text)))
|
|
|
|
|
|
|
|
(empty (clone info #:text '()))
|
|
|
|
(test-jump->info ((test->jump->info empty) test))
|
|
|
|
(test+jump-info (test-jump->info 0))
|
|
|
|
(test-length (length (text->list (.text test+jump-info))))
|
|
|
|
|
2017-04-07 07:36:30 +00:00
|
|
|
(jump-text (wrap-as (i386:Xjump (- (+ body-length test-length)))))
|
2017-03-12 10:05:00 +00:00
|
|
|
(jump-length (length (text->list jump-text)))
|
|
|
|
|
|
|
|
(test-text (.text (test-jump->info jump-length))))
|
|
|
|
(clone info #:text
|
|
|
|
(append
|
|
|
|
(.text body-info)
|
|
|
|
test-text
|
|
|
|
jump-text)
|
|
|
|
#:globals (.globals body-info))))
|
|
|
|
|
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
|
|
|
((labeled-stmt (ident ,label) ,statement)
|
2017-04-07 07:53:56 +00:00
|
|
|
(let ((info (append-text info (list label))))
|
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
|
|
|
((ast->info info) statement)))
|
|
|
|
|
|
|
|
((goto (ident ,label))
|
2017-04-02 10:13:04 +00:00
|
|
|
(let* ((jump (lambda (n) (i386:XXjump n)))
|
|
|
|
(offset (+ (length (jump 0)) (length (text->list text)))))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (append
|
|
|
|
(list (lambda (f g ta t d)
|
|
|
|
(jump (- (label-offset (.function info) label f) offset))))))))
|
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
|
|
|
|
2017-04-06 07:12:50 +00:00
|
|
|
((return ,expr)
|
2017-04-07 07:53:56 +00:00
|
|
|
(let ((info ((expr->accu info) expr)))
|
2017-05-06 07:11:42 +00:00
|
|
|
(append-text info (append (wrap-as (i386:ret))))))
|
mescc: Have micro-mes use strcmp to print help.
* doc/examples/micro-mes.c (main): Add --help.
* module/language/c99/compiler.mes (info?): New function.
(expr->accu): Handle function call and sub.
(ast->info): Handle if not, and, de-ref, eq, sub, return f ().
* module/mes/libc-i386.mes (i386:accu-zero?, i386:Xmem-byte->accu,
i386:Xmem-byte->base, i386:jump-byte-nz, i386:jump-byte-z,
i386:test-byte-base, i386:Xjump-byte-z, i386:sub-byte-base): New
functions.
* module/mes/libc-i386.scm: Export them.
2017-01-05 23:20:05 +00:00
|
|
|
|
2017-04-06 07:12:50 +00:00
|
|
|
;; DECL
|
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
|
|
|
|
2017-04-06 07:12:50 +00:00
|
|
|
;; int i;
|
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ident ,name))))
|
|
|
|
(if (.function info)
|
|
|
|
(clone info #:locals (add-local locals name type 0))
|
|
|
|
(clone info #:globals (append globals (list (ident->global name type 0 0))))))
|
2017-01-03 11:33:34 +00:00
|
|
|
|
2017-05-06 17:31:00 +00:00
|
|
|
;; enum e i;
|
|
|
|
((decl (decl-spec-list (type-spec (enum-ref (ident ,type)))) (init-declr-list (init-declr (ident ,name))))
|
|
|
|
(let ((type "int")) ;; FIXME
|
|
|
|
(if (.function info)
|
|
|
|
(clone info #:locals (add-local locals name type 0))
|
|
|
|
(clone info #:globals (append globals (list (ident->global name type 0 0)))))))
|
|
|
|
|
2017-01-17 18:03:08 +00:00
|
|
|
;; int i = 0;
|
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ident ,name) (initzer (p-expr (fixed ,value))))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(let ((value (cstring->number value)))
|
|
|
|
(if (.function info)
|
|
|
|
(let* ((locals (add-local locals name type 0))
|
|
|
|
(info (clone info #:locals locals)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info ((value->ident info) name value)))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(clone info #:globals (append globals (list (ident->global name type 0 value)))))))
|
2017-01-17 18:03:08 +00:00
|
|
|
|
2017-01-17 17:57:41 +00:00
|
|
|
;; char c = 'A';
|
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ident ,name) (initzer (p-expr (char ,value))))))
|
2017-04-12 19:27:59 +00:00
|
|
|
(if (not (.function info)) (error "ast->info: unsupported: " o))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(let* ((locals (add-local locals name type 0))
|
2017-01-17 17:57:41 +00:00
|
|
|
(info (clone info #:locals locals))
|
|
|
|
(value (char->integer (car (string->list value)))))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info ((value->ident info) name value))))
|
2017-01-17 17:57:41 +00:00
|
|
|
|
2017-01-17 18:03:08 +00:00
|
|
|
;; int i = -1;
|
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ident ,name) (initzer (neg (p-expr (fixed ,value)))))))
|
mescc: Mini-mes (gcc-compiled) runs read-0.mes.
* module/language/c99/compiler.mes (expr->accu): Add mul.
(test->jump->info): Add le, ge.
(ast->info): Support int and char* initialization at top level.
* module/mes/as-i386.mes (i386:accu*base, i386:Xjump-cz,
i386:Xjump-ncz): New function.
* module/mes/as-i386.scm: Export them.
* doc/examples/t.c (test): Test them.
* module/mes/libc.mes (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
(libc): Export them.
* module/mes/mini-0.mes: Load full reader.
* mlibc.c (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
* mes.c (list length error lookup_ getchar ungetchar peekchar
peek_byte read_byte unread_byte greater_p less_p): Move functions
needed to run read-0.mes into core.
* doc/examples/mini-mes.c: Likewise.
* lib.c (length, error): Comment-out.
* math.c (greater_p, less_p): Comment-out.
* posix.c: (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte): Comment-out.
* reader.c (lookup_): Comment-out.
2017-03-22 05:39:24 +00:00
|
|
|
(let ((value (- (cstring->number value))))
|
|
|
|
(if (.function info)
|
|
|
|
(let* ((locals (add-local locals name type 0))
|
|
|
|
(info (clone info #:locals locals)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info ((value->ident info) name value)))
|
mescc: Mini-mes (gcc-compiled) runs read-0.mes.
* module/language/c99/compiler.mes (expr->accu): Add mul.
(test->jump->info): Add le, ge.
(ast->info): Support int and char* initialization at top level.
* module/mes/as-i386.mes (i386:accu*base, i386:Xjump-cz,
i386:Xjump-ncz): New function.
* module/mes/as-i386.scm: Export them.
* doc/examples/t.c (test): Test them.
* module/mes/libc.mes (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
(libc): Export them.
* module/mes/mini-0.mes: Load full reader.
* mlibc.c (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
* mes.c (list length error lookup_ getchar ungetchar peekchar
peek_byte read_byte unread_byte greater_p less_p): Move functions
needed to run read-0.mes into core.
* doc/examples/mini-mes.c: Likewise.
* lib.c (length, error): Comment-out.
* math.c (greater_p, less_p): Comment-out.
* posix.c: (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte): Comment-out.
* reader.c (lookup_): Comment-out.
2017-03-22 05:39:24 +00:00
|
|
|
(clone info #:globals (append globals (list (ident->global name type 0 value)))))))
|
2017-01-17 18:03:08 +00:00
|
|
|
|
2017-01-03 11:33:34 +00:00
|
|
|
;; int i = argc;
|
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ident ,name) (initzer (p-expr (ident ,local))))))
|
2017-04-12 19:27:59 +00:00
|
|
|
(if (not (.function info)) (error "ast->info: unsupported: " o))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(let* ((locals (add-local locals name type 0))
|
mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
procedure and give more debug information.
(ref-local, ref-global): Remove.
(push-global-ref, push-global, push-ident-ref): New functions.
(push-ident): New function.
(expr->arg): Use them.
(ident->accu, ident->accu, accu->ident, value->ident, ident->base):
Take info parameter, also handle globals.
(ident-address->accu, ident->global, cstring->number): New functions.
(ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
(i386:push-global-ref): Rename from i386:ref-global.
(i386:push-local): Rename from i386:ref-local.
(i386:value->local): Rename from i386:local-assign.
(i386:push-global, i386:push-local-ref, i386:value->global,
i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 19:12:06 +00:00
|
|
|
(info (clone info #:locals locals)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (append ((ident->accu info) local)
|
|
|
|
((accu->ident info) name)))))
|
2017-01-04 23:55:46 +00:00
|
|
|
|
2017-04-17 00:15:11 +00:00
|
|
|
;; char *p = "foo";
|
2017-04-10 06:06:33 +00:00
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type)) . _) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name)) (initzer (p-expr (string ,string))))))
|
2017-04-17 00:15:11 +00:00
|
|
|
(if (.function info)
|
|
|
|
(let* ((locals (add-local locals name type 1))
|
|
|
|
(globals (append globals (list (string->global string))))
|
|
|
|
(info (clone info #:locals locals #:globals globals)))
|
|
|
|
(append-text info (append
|
|
|
|
(list (lambda (f g ta t d)
|
|
|
|
(append
|
|
|
|
(i386:global->accu (+ (data-offset (add-s:-prefix string) g) d)))))
|
|
|
|
((accu->ident info) name))))
|
|
|
|
(let* ((global (string->global string))
|
|
|
|
(globals (append globals (list global)))
|
|
|
|
(size 4)
|
|
|
|
(global (make-global name type 1 (string->list (make-string size #\nul))))
|
|
|
|
(globals (append globals (list global)))
|
|
|
|
(info (clone info #:globals globals))
|
|
|
|
(here (data-offset name globals)))
|
|
|
|
(clone info #:init
|
|
|
|
(append
|
|
|
|
(.init info)
|
|
|
|
(list (lambda (functions globals ta t d data)
|
|
|
|
(append
|
|
|
|
(list-head data here)
|
|
|
|
(initzer->data info functions globals ta t d `(initzer (p-expr (string ,string))))
|
|
|
|
(list-tail data (+ here size))))))))))
|
2017-01-08 16:51:40 +00:00
|
|
|
|
2017-04-17 00:15:11 +00:00
|
|
|
;; char const *p;
|
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type)) (type-qual ,qualifier)) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name)))))
|
|
|
|
(if (.function info)
|
|
|
|
(let* ((locals (add-local locals name type 1))
|
|
|
|
(info (clone info #:locals locals)))
|
|
|
|
(append-text info (append (wrap-as (i386:value->accu 0))
|
|
|
|
((accu->ident info) name))))
|
|
|
|
(let ((globals (append globals (list (ident->global name type 1 0)))))
|
|
|
|
(clone info #:globals globals))))
|
|
|
|
|
|
|
|
;; char *p;
|
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type)) . _) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name)))))
|
|
|
|
(if (.function info)
|
|
|
|
(let* ((locals (add-local locals name type 1))
|
|
|
|
(info (clone info #:locals locals)))
|
|
|
|
(append-text info (append (wrap-as (i386:value->accu 0))
|
|
|
|
((accu->ident info) name))))
|
|
|
|
(let ((globals (append globals (list (ident->global name type 1 0)))))
|
|
|
|
(clone info #:globals globals))))
|
|
|
|
|
2017-04-10 06:06:33 +00:00
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type)) . _) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name)) (initzer (p-expr (fixed ,value))))))
|
2017-03-23 17:48:19 +00:00
|
|
|
(let ((value (cstring->number value)))
|
|
|
|
(if (.function info)
|
|
|
|
(let* ((locals (add-local locals name type 1))
|
|
|
|
(info (clone info #:locals locals)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (append (wrap-as (i386:value->accu value))
|
|
|
|
((accu->ident info) name))))
|
2017-04-17 00:15:11 +00:00
|
|
|
(clone info #:globals (append globals (list (ident->global name type 1 value)))))))
|
|
|
|
|
|
|
|
;; char **p;
|
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ptr-declr (pointer (pointer)) (ident ,name)))))
|
|
|
|
(if (.function info)
|
|
|
|
(let* ((locals (add-local locals name type 2))
|
|
|
|
(info (clone info #:locals locals)))
|
|
|
|
(append-text info (append (wrap-as (i386:value->accu 0))
|
|
|
|
((accu->ident info) name))))
|
|
|
|
(let ((globals (append globals (list (ident->global name type 2 0)))))
|
|
|
|
(clone info #:globals globals))))
|
|
|
|
|
|
|
|
;; char **p = 0;
|
|
|
|
;;((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ptr-declr (pointer (pointer)) (ident ,name)) (initzer (p-expr (fixed ,value)))))))
|
|
|
|
|
|
|
|
;; char **p = g_environment;
|
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ptr-declr (pointer (pointer)) (ident ,name)) (initzer (p-expr (ident ,b)))))) ;; FIXME: initzer
|
|
|
|
(if (.function info)
|
|
|
|
(let* ((locals (add-local locals name type 2))
|
|
|
|
(info (clone info #:locals locals)))
|
|
|
|
(append-text info (append
|
|
|
|
((ident->accu info) b)
|
|
|
|
((accu->ident info) name))))
|
|
|
|
(let* ((globals (append globals (list (ident->global name type 2 0))))
|
|
|
|
(here (data-offset name globals)))
|
|
|
|
(clone info
|
|
|
|
#:globals globals
|
|
|
|
#:init (append (.init info)
|
|
|
|
(list (lambda (functions globals ta t d data)
|
|
|
|
(append
|
|
|
|
(list-head data here)
|
|
|
|
;;(initzer->data info functions globals ta t d initzer)
|
|
|
|
(initzer->data info functions globals ta t d `(p-expr (ident ,b)))
|
|
|
|
(list-tail data (+ here 4))))))))
|
|
|
|
;;;(clone info #:globals (append globals (list (ident->global name type 1 0))))
|
|
|
|
))
|
mescc: Mini-mes (gcc-compiled) runs read-0.mes.
* module/language/c99/compiler.mes (expr->accu): Add mul.
(test->jump->info): Add le, ge.
(ast->info): Support int and char* initialization at top level.
* module/mes/as-i386.mes (i386:accu*base, i386:Xjump-cz,
i386:Xjump-ncz): New function.
* module/mes/as-i386.scm: Export them.
* doc/examples/t.c (test): Test them.
* module/mes/libc.mes (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
(libc): Export them.
* module/mes/mini-0.mes: Load full reader.
* mlibc.c (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
* mes.c (list length error lookup_ getchar ungetchar peekchar
peek_byte read_byte unread_byte greater_p less_p): Move functions
needed to run read-0.mes into core.
* doc/examples/mini-mes.c: Likewise.
* lib.c (length, error): Comment-out.
* math.c (greater_p, less_p): Comment-out.
* posix.c: (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte): Comment-out.
* reader.c (lookup_): Comment-out.
2017-03-22 05:39:24 +00:00
|
|
|
|
2017-05-04 17:39:23 +00:00
|
|
|
;; struct foo bar[2];
|
2017-05-05 07:24:19 +00:00
|
|
|
;; char arena[20000];
|
|
|
|
((decl (decl-spec-list (type-spec ,type)) (init-declr-list (init-declr (array-of (ident ,name) (p-expr (fixed ,count))))))
|
|
|
|
(let ((type (ast->type type)))
|
2017-05-04 17:39:23 +00:00
|
|
|
(if (.function info)
|
|
|
|
(let* ((local (car (add-local locals name type -1)))
|
|
|
|
(count (string->number count))
|
|
|
|
(size (type->size info type))
|
|
|
|
(local (make-local name type -1 (+ (local:id local) (* count size))))
|
|
|
|
(locals (cons local locals))
|
|
|
|
(info (clone info #:locals locals)))
|
|
|
|
info)
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(let* ((globals (.globals info))
|
|
|
|
(count (cstring->number count))
|
|
|
|
(size (type->size info type))
|
|
|
|
(array (make-global name type -1 (string->list (make-string (* count size) #\nul))))
|
|
|
|
(globals (append globals (list array))))
|
2017-04-07 07:53:56 +00:00
|
|
|
(clone info #:globals globals)))))
|
2017-01-17 17:57:41 +00:00
|
|
|
|
2017-05-05 07:24:19 +00:00
|
|
|
;; char* a[10];
|
|
|
|
((decl (decl-spec-list (type-spec ,type)) (init-declr-list (init-declr (ptr-declr (pointer) (array-of (ident ,name) (p-expr (fixed ,count)))))))
|
|
|
|
(let ((type (ast->type type)))
|
|
|
|
(if (.function info)
|
|
|
|
(let* ((local (car (add-local locals name type -1)))
|
|
|
|
(count (string->number count))
|
|
|
|
(size (type->size info type))
|
|
|
|
(local (make-local name type 1 (+ (local:id local) (* count size))))
|
|
|
|
(locals (cons local locals))
|
|
|
|
(info (clone info #:locals locals)))
|
|
|
|
info)
|
|
|
|
(let* ((globals (.globals info))
|
|
|
|
(count (cstring->number count))
|
|
|
|
(size (type->size info type))
|
|
|
|
(array (make-global name type 1 (string->list (make-string (* count size) #\nul))))
|
|
|
|
(globals (append globals (list array))))
|
|
|
|
(clone info #:globals globals)))))
|
2017-05-04 17:39:23 +00:00
|
|
|
|
|
|
|
;; struct foo bar;
|
|
|
|
((decl (decl-spec-list (type-spec (struct-ref (ident ,type)))) (init-declr-list (init-declr (ident ,name))))
|
|
|
|
(if (.function info)
|
|
|
|
(let* ((locals (add-local locals name `("struct" ,type) 1))
|
|
|
|
(info (clone info #:locals locals)))
|
|
|
|
info)
|
|
|
|
(let* ((size (type->size info (list "struct" type)))
|
|
|
|
(global (make-global name (list "struct" type) -1 (string->list (make-string size #\nul))))
|
|
|
|
(globals (append globals (list global)))
|
|
|
|
(info (clone info #:globals globals)))
|
|
|
|
info)))
|
|
|
|
|
2017-01-17 18:03:08 +00:00
|
|
|
;;struct scm *g_cells = (struct scm*)arena;
|
|
|
|
((decl (decl-spec-list (type-spec (struct-ref (ident ,type)))) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name)) (initzer (cast (type-name (decl-spec-list (type-spec (struct-ref (ident ,=type)))) (abs-declr (pointer))) (p-expr (ident ,value)))))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(if (.function info)
|
2017-05-04 17:39:23 +00:00
|
|
|
(let* ((locals (add-local locals name `("struct" ,type) 1))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(info (clone info #:locals locals)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (append ((ident->accu info) name)
|
|
|
|
((accu->ident info) value)))) ;; FIXME: deref?
|
2017-05-04 17:39:23 +00:00
|
|
|
(let* ((globals (append globals (list (ident->global name `("struct" ,type) 1 0))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(info (clone info #:globals globals)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (append ((ident->accu info) name)
|
|
|
|
((accu->ident info) value)))))) ;; FIXME: deref?
|
2017-01-17 18:03:08 +00:00
|
|
|
|
2017-05-04 17:39:23 +00:00
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
;; SCM tmp;
|
|
|
|
((decl (decl-spec-list (type-spec (typename ,type))) (init-declr-list (init-declr (ident ,name))))
|
|
|
|
(if (.function info)
|
|
|
|
(clone info #:locals (add-local locals name type 0))
|
|
|
|
(clone info #:globals (append globals (list (ident->global name type 0 0))))))
|
mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
procedure and give more debug information.
(ref-local, ref-global): Remove.
(push-global-ref, push-global, push-ident-ref): New functions.
(push-ident): New function.
(expr->arg): Use them.
(ident->accu, ident->accu, accu->ident, value->ident, ident->base):
Take info parameter, also handle globals.
(ident-address->accu, ident->global, cstring->number): New functions.
(ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
(i386:push-global-ref): Rename from i386:ref-global.
(i386:push-local): Rename from i386:ref-local.
(i386:value->local): Rename from i386:local-assign.
(i386:push-global, i386:push-local-ref, i386:value->global,
i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 19:12:06 +00:00
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
;; SCM g_stack = 0;
|
|
|
|
((decl (decl-spec-list (type-spec (typename ,type))) (init-declr-list (init-declr (ident ,name) (initzer (p-expr (fixed ,value))))))
|
2017-03-12 11:02:12 +00:00
|
|
|
(let ((value (cstring->number value)))
|
2017-04-06 07:12:50 +00:00
|
|
|
(if (.function info)
|
|
|
|
(let* ((locals (add-local locals name type 0))
|
|
|
|
(info (clone info #:locals locals)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info ((value->ident info) name value)))
|
2017-04-06 07:12:50 +00:00
|
|
|
(let ((globals (append globals (list (ident->global name type 0 value)))))
|
|
|
|
(clone info #:globals globals)))))
|
mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
procedure and give more debug information.
(ref-local, ref-global): Remove.
(push-global-ref, push-global, push-ident-ref): New functions.
(push-ident): New function.
(expr->arg): Use them.
(ident->accu, ident->accu, accu->ident, value->ident, ident->base):
Take info parameter, also handle globals.
(ident-address->accu, ident->global, cstring->number): New functions.
(ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
(i386:push-global-ref): Rename from i386:ref-global.
(i386:push-local): Rename from i386:ref-local.
(i386:value->local): Rename from i386:local-assign.
(i386:push-global, i386:push-local-ref, i386:value->global,
i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 19:12:06 +00:00
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
;; SCM g_stack = 0; // comment
|
|
|
|
((decl (decl-spec-list (type-spec (typename ,type))) (init-declr-list (init-declr (ident _) (initzer (p-expr (fixed _))))) (comment _))
|
|
|
|
((ast->info info) (list-head o (- (length o) 1))))
|
|
|
|
|
2017-01-03 11:33:34 +00:00
|
|
|
;; SCM i = argc;
|
|
|
|
((decl (decl-spec-list (type-spec (typename ,type))) (init-declr-list (init-declr (ident ,name) (initzer (p-expr (ident ,local))))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(if (.function info)
|
|
|
|
(let* ((locals (add-local locals name type 0))
|
|
|
|
(info (clone info #:locals locals)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (append ((ident->accu info) local)
|
|
|
|
((accu->ident info) name))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(let* ((globals (append globals (list (ident->global name type 0 0))))
|
|
|
|
(info (clone info #:globals globals)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (append ((ident->accu info) local)
|
|
|
|
((accu->ident info) name))))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
|
|
|
|
;; int (*function) (void) = g_functions[g_cells[fn].cdr].function;
|
2017-03-02 19:26:13 +00:00
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ftn-declr (scope (ptr-declr (pointer) (ident ,name))) (param-list . ,param-list)) (initzer ,initzer))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(let* ((locals (add-local locals name type 1))
|
|
|
|
(info (clone info #:locals locals))
|
|
|
|
(empty (clone info #:text '()))
|
|
|
|
(accu ((expr->accu empty) initzer)))
|
|
|
|
(clone info
|
|
|
|
#:text
|
|
|
|
(append text
|
|
|
|
(.text accu)
|
|
|
|
((accu->ident info) name)
|
|
|
|
(list (lambda (f g ta t d)
|
2017-04-07 07:36:30 +00:00
|
|
|
(append (i386:value->base ta)
|
|
|
|
(i386:accu+base)))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
#:locals locals)))
|
|
|
|
|
2017-01-17 18:03:08 +00:00
|
|
|
;; char *p = (char*)g_cells;
|
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name)) (initzer (cast (type-name (decl-spec-list (type-spec (fixed-type ,=type))) (abs-declr (pointer))) (p-expr (ident ,value)))))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(if (.function info)
|
|
|
|
(let* ((locals (add-local locals name type 1))
|
|
|
|
(info (clone info #:locals locals)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (append ((ident->accu info) value)
|
|
|
|
((accu->ident info) name))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(let* ((globals (append globals (list (ident->global name type 1 0))))
|
|
|
|
(here (data-offset name globals))
|
|
|
|
(there (data-offset value globals)))
|
|
|
|
(clone info
|
|
|
|
#:globals globals
|
|
|
|
#:init (append (.init info)
|
|
|
|
(list (lambda (functions globals ta t d data)
|
|
|
|
(append
|
|
|
|
(list-head data here)
|
|
|
|
;;; FIXME: type
|
|
|
|
;;; char *x = arena;
|
|
|
|
(int->bv32 (+ d (data-offset value globals)))
|
|
|
|
;;; char *y = x;
|
|
|
|
;;;(list-head (list-tail data there) 4)
|
|
|
|
(list-tail data (+ here 4))))))))))
|
2017-01-17 18:03:08 +00:00
|
|
|
|
|
|
|
;; char *p = g_cells;
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
((decl (decl-spec-list (type-spec ,type)) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name)) (initzer (p-expr (ident ,value))))))
|
|
|
|
(let ((type (decl->type type)))
|
|
|
|
(if (.function info)
|
|
|
|
(let* ((locals (add-local locals name type 1))
|
|
|
|
(info (clone info #:locals locals)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (append ((ident->accu info) value)
|
|
|
|
((accu->ident info) name))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(let* ((globals (append globals (list (ident->global name type 1 0))))
|
2017-03-17 16:54:37 +00:00
|
|
|
(here (data-offset name globals)))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(clone info
|
|
|
|
#:globals globals
|
|
|
|
#:init (append (.init info)
|
|
|
|
(list (lambda (functions globals ta t d data)
|
|
|
|
(append
|
|
|
|
(list-head data here)
|
|
|
|
;;; FIXME: type
|
|
|
|
;;; char *x = arena;p
|
|
|
|
(int->bv32 (+ d (data-offset value globals)))
|
|
|
|
(list-tail data (+ here 4)))))))))))
|
2017-01-17 18:03:08 +00:00
|
|
|
|
2017-01-10 21:44:01 +00:00
|
|
|
;; enum
|
|
|
|
((decl (decl-spec-list (type-spec (enum-def (ident ,name) (enum-def-list . ,fields)))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(let ((type (enum->type name fields))
|
2017-05-06 17:31:00 +00:00
|
|
|
(constants (let loop ((fields fields) (i 0) (constants constants))
|
|
|
|
(if (null? fields) constants
|
|
|
|
(let* ((field (car fields))
|
|
|
|
(name (pmatch field
|
|
|
|
((enum-defn (ident ,name) . _) name)))
|
|
|
|
(i (pmatch field
|
|
|
|
((enum-defn ,name (p-expr (fixed ,value))) (cstring->number value))
|
|
|
|
((enum-defn ,name) i))))
|
|
|
|
(loop (cdr fields)
|
|
|
|
(1+ i)
|
|
|
|
(append constants (list (ident->constant name i)))))))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(clone info
|
|
|
|
#:types (append (.types info) (list type))
|
2017-01-10 21:44:01 +00:00
|
|
|
#:constants (append constants (.constants info)))))
|
|
|
|
|
2017-01-17 18:03:08 +00:00
|
|
|
;; struct
|
|
|
|
((decl (decl-spec-list (type-spec (struct-def (ident ,name) (field-list . ,fields)))))
|
2017-05-04 17:39:23 +00:00
|
|
|
(let ((type (struct->type (list "struct" name) (map struct-field fields))))
|
2017-01-17 18:03:08 +00:00
|
|
|
(clone info #:types (append (.types info) (list type)))))
|
mescc: Support globals.
* module/language/c99/compiler.mes (write-any): Catch writing of
procedure and give more debug information.
(ref-local, ref-global): Remove.
(push-global-ref, push-global, push-ident-ref): New functions.
(push-ident): New function.
(expr->arg): Use them.
(ident->accu, ident->accu, accu->ident, value->ident, ident->base):
Take info parameter, also handle globals.
(ident-address->accu, ident->global, cstring->number): New functions.
(ast->info): Update.
* module/mes/libc-i386.mes (i386:ret-local): Remove.
(i386:push-global-ref): Rename from i386:ref-global.
(i386:push-local): Rename from i386:ref-local.
(i386:value->local): Rename from i386:local-assign.
(i386:push-global, i386:push-local-ref, i386:value->global,
i386:local-address->accu): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-10 19:12:06 +00:00
|
|
|
|
2017-05-06 07:27:28 +00:00
|
|
|
;; struct foo {} bar;
|
|
|
|
((decl (decl-spec-list (type-spec (struct-def (ident ,type) (field-list . ,fields))))
|
|
|
|
(init-declr-list (init-declr (ident ,name))))
|
|
|
|
(let ((info ((ast->info info) `(decl (decl-spec-list (type-spec (struct-def (ident ,type) (field-list . ,fields))))))))
|
|
|
|
((ast->info info)
|
|
|
|
`(decl (decl-spec-list (type-spec (struct-ref (ident ,type)))) (init-declr-list (init-declr (ident ,name)))))))
|
|
|
|
|
2017-05-06 09:01:58 +00:00
|
|
|
;; struct foo* bar = expr;
|
|
|
|
((decl (decl-spec-list (type-spec (struct-ref (ident ,type)))) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name)) (initzer (ref-to (p-expr (ident ,value)))))))
|
|
|
|
(if (.function info) (let* ((locals (add-local locals name (list "struct" type) 1))
|
|
|
|
(info (clone info #:locals locals)))
|
|
|
|
(append-text info (append ((ident-address->accu info) value)
|
|
|
|
((accu->ident info) name))))
|
|
|
|
(error "ast->info: unsupported global:" o)))
|
|
|
|
|
2017-04-17 00:15:11 +00:00
|
|
|
;; char *p = &bla;
|
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name)) (initzer (ref-to (p-expr (ident ,value)))))))
|
|
|
|
(let ((type (decl->type type)))
|
|
|
|
(if (.function info)
|
|
|
|
(let* ((locals (add-local locals name type 1))
|
|
|
|
(info (clone info #:locals locals)))
|
|
|
|
(append-text info (append ((ident-address->accu info) value)
|
|
|
|
((accu->ident info) name))))
|
|
|
|
(error "TODO" o))))
|
|
|
|
|
|
|
|
;; char **p = &bla;
|
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ptr-declr (pointer (pointer)) (ident ,name)) (initzer (ref-to (p-expr (ident ,value)))))))
|
|
|
|
(let ((type (decl->type type)))
|
|
|
|
(if (.function info)
|
|
|
|
(let* ((locals (add-local locals name type 2))
|
|
|
|
(info (clone info #:locals locals)))
|
|
|
|
(append-text info (append ((ident-address->accu info) value)
|
|
|
|
((accu->ident info) name))))
|
|
|
|
(error "TODO" o))))
|
|
|
|
|
|
|
|
;; char *p = bla[0];
|
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name)) (initzer (array-ref ,index (p-expr (ident ,array)))))))
|
|
|
|
(if (.function info)
|
|
|
|
(let* ((locals (add-local locals name type 1))
|
|
|
|
(info (clone info #:locals locals))
|
|
|
|
(info ((expr->accu* info) `(array-ref ,index (p-expr (ident ,array))))))
|
|
|
|
(append-text info ((accu->ident info) name)))
|
|
|
|
(error "TODO" o)))
|
|
|
|
|
2017-05-07 05:36:44 +00:00
|
|
|
;; char *foo = &bar[0];
|
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name)) (initzer (ref-to (array-ref ,index (p-expr (ident ,array))))))))
|
|
|
|
(if (.function info)
|
|
|
|
(let* ((locals (add-local locals name type 1))
|
|
|
|
(info (clone info #:locals locals))
|
|
|
|
(info ((expr->accu* info) `(array-ref ,index (p-expr (ident ,array))))))
|
|
|
|
(append-text info ((accu->ident info) name)))
|
|
|
|
(error "TODO" o)))
|
|
|
|
|
2017-04-17 00:15:11 +00:00
|
|
|
;; char *p = *bla;
|
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ptr-declr (pointer) (ident ,name)) (initzer (de-ref (p-expr (ident ,value)))))))
|
|
|
|
(if (.function info)
|
2017-05-07 05:36:44 +00:00
|
|
|
(let* ((locals (add-local locals name type 1))
|
2017-04-17 00:15:11 +00:00
|
|
|
(info (clone info #:locals locals))
|
|
|
|
(local (assoc-ref (.locals info) name)))
|
|
|
|
(append-text info (append ((ident->accu info) value)
|
|
|
|
(wrap-as (i386:mem->accu))
|
|
|
|
((accu->ident info) name))))
|
|
|
|
(error "TODO" o)))
|
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
;; DECL
|
2017-04-17 00:15:11 +00:00
|
|
|
;; char *bla[] = {"a", "b"};
|
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ptr-declr (pointer) (array-of (ident ,name))) (initzer (initzer-list . ,initzers)))))
|
|
|
|
(let* ((type (decl->type type))
|
|
|
|
(entries (map initzer->global initzers))
|
|
|
|
(entry-size 4)
|
|
|
|
(size (* (length entries) entry-size)))
|
|
|
|
(if (.function info)
|
|
|
|
(error "TODO: <type> x[] = {};" o)
|
|
|
|
(let* ((global (make-global name type 2 (string->list (make-string size #\nul))))
|
|
|
|
(globals (append globals entries (list global)))
|
|
|
|
(info (clone info #:globals globals))
|
|
|
|
(here (data-offset name globals)))
|
|
|
|
(clone info #:init
|
|
|
|
(append
|
|
|
|
(.init info)
|
|
|
|
(list (lambda (functions globals ta t d data)
|
|
|
|
(append
|
|
|
|
(list-head data here)
|
|
|
|
(append-map
|
|
|
|
(lambda (i)
|
|
|
|
(initzer->data info functions globals ta t d i))
|
|
|
|
initzers)
|
|
|
|
(list-tail data (+ here size)))))))))))
|
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
;;
|
|
|
|
;; struct f = {...};
|
|
|
|
((decl (decl-spec-list (type-spec ,type)) (init-declr-list (init-declr (ident ,name) (initzer (initzer-list . ,initzers)))))
|
|
|
|
(let* ((type (decl->type type))
|
|
|
|
(fields (type->description info type))
|
|
|
|
(size (type->size info type))
|
|
|
|
(field-size 4)) ;; FIXME:4, not fixed
|
|
|
|
(if (.function info)
|
2017-03-09 07:14:27 +00:00
|
|
|
(let* ((globals (append globals (filter-map initzer->global initzers)))
|
|
|
|
(locals (let loop ((fields (cdr fields)) (locals locals))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(if (null? fields) locals
|
|
|
|
(loop (cdr fields) (add-local locals "foobar" "int" 0)))))
|
|
|
|
(locals (add-local locals name type -1))
|
2017-03-09 07:14:27 +00:00
|
|
|
(info (clone info #:locals locals #:globals globals))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(empty (clone info #:text '())))
|
|
|
|
(let loop ((fields (iota (length fields))) (initzers initzers) (info info))
|
|
|
|
(if (null? fields) info
|
|
|
|
(let ((offset (* field-size (car fields)))
|
|
|
|
(initzer (car initzers)))
|
|
|
|
(loop (cdr fields) (cdr initzers)
|
|
|
|
(clone info #:text
|
|
|
|
(append
|
|
|
|
(.text info)
|
|
|
|
((ident->accu info) name)
|
2017-04-07 07:36:30 +00:00
|
|
|
(wrap-as (append (i386:accu->base)))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(.text ((expr->accu empty) initzer))
|
2017-04-07 07:36:30 +00:00
|
|
|
(wrap-as (i386:accu->base-address+n offset)))))))))
|
2017-03-09 07:14:27 +00:00
|
|
|
(let* ((globals (append globals (filter-map initzer->global initzers)))
|
|
|
|
(global (make-global name type -1 (string->list (make-string size #\nul))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(globals (append globals (list global)))
|
|
|
|
(here (data-offset name globals))
|
|
|
|
(info (clone info #:globals globals))
|
|
|
|
(field-size 4))
|
|
|
|
(let loop ((fields (iota (length fields))) (initzers initzers) (info info))
|
|
|
|
(if (null? fields) info
|
|
|
|
(let ((offset (* field-size (car fields)))
|
|
|
|
(initzer (car initzers)))
|
|
|
|
(loop (cdr fields) (cdr initzers)
|
|
|
|
(clone info #:init
|
|
|
|
(append
|
|
|
|
(.init info)
|
|
|
|
(list (lambda (functions globals ta t d data)
|
|
|
|
(append
|
|
|
|
(list-head data (+ here offset))
|
|
|
|
(initzer->data info functions globals ta t d (car initzers))
|
|
|
|
(list-tail data (+ here offset field-size)))))))))))))))
|
|
|
|
|
2017-03-17 16:54:37 +00:00
|
|
|
|
|
|
|
;;char cc = g_cells[c].cdr; ==> generic?
|
|
|
|
((decl (decl-spec-list (type-spec ,type)) (init-declr-list (init-declr (ident ,name) (initzer ,initzer))))
|
|
|
|
(let ((type (decl->type type)))
|
|
|
|
(if (.function info)
|
|
|
|
(let* ((locals (add-local locals name type 0))
|
|
|
|
(info (clone info #:locals locals)))
|
|
|
|
(clone info #:text
|
|
|
|
(append (.text ((expr->accu info) initzer))
|
|
|
|
((accu->ident info) name))))
|
|
|
|
(let* ((globals (append globals (list (ident->global name type 1 0))))
|
|
|
|
(here (data-offset name globals)))
|
|
|
|
(clone info
|
|
|
|
#:globals globals
|
|
|
|
#:init (append (.init info)
|
|
|
|
(list (lambda (functions globals ta t d data)
|
|
|
|
(append
|
|
|
|
(list-head data here)
|
|
|
|
(initzer->data info functions globals ta t d initzer)
|
|
|
|
(list-tail data (+ here 4)))))))))))
|
|
|
|
|
|
|
|
|
2017-03-12 11:02:12 +00:00
|
|
|
((decl (decl-spec-list (type-spec (typename ,type))) (init-declr-list (init-declr (ftn-declr (ident ,name) (param-list . ,param-list)))))
|
|
|
|
info)
|
|
|
|
|
2017-03-17 16:54:37 +00:00
|
|
|
((decl (decl-spec-list (type-spec (typename ,type))) (init-declr-list (init-declr (ftn-declr (ident ,name) (param-list . ,param-list)))) (comment ,comment))
|
|
|
|
info)
|
|
|
|
|
2017-03-17 16:32:23 +00:00
|
|
|
((decl (decl-spec-list (stor-spec (typedef)) (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ident ,name))))
|
|
|
|
(let ((types (.types info)))
|
|
|
|
(clone info #:types (cons (cons name (assoc-ref types type)) types))))
|
|
|
|
|
2017-05-02 21:30:46 +00:00
|
|
|
;; int foo ();
|
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ftn-declr (ident ,name) (param-list . ,param-list)))))
|
|
|
|
info)
|
|
|
|
|
|
|
|
;; void foo ();
|
|
|
|
((decl (decl-spec-list (type-spec (void))) (init-declr-list (init-declr (ftn-declr (ident ,name) (param-list . ,param-list)))))
|
|
|
|
info)
|
|
|
|
|
|
|
|
;; void foo (*);
|
|
|
|
((decl (decl-spec-list (type-spec (void))) (init-declr-list (init-declr (ptr-declr (pointer) (ftn-declr (ident ,name) (param-list . ,param-list))))))
|
|
|
|
info)
|
|
|
|
|
|
|
|
;; char const* itoa ();
|
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type)) (type-qual ,qual)) (init-declr-list (init-declr (ptr-declr (pointer) (ftn-declr (ident ,name) (param-list . ,param-list))))))
|
|
|
|
info)
|
|
|
|
|
2017-05-08 19:15:53 +00:00
|
|
|
;; char *strcpy ();
|
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ptr-declr (pointer) (ftn-declr (ident ,name) (param-list . ,param-list))))))
|
|
|
|
info)
|
|
|
|
|
2017-05-02 15:00:07 +00:00
|
|
|
;; printf (char const* format, ...)
|
2017-05-02 21:30:46 +00:00
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ftn-declr (ident ,name) (param-list ,param-list . (ellipsis))))))
|
2017-05-02 15:00:07 +00:00
|
|
|
info)
|
|
|
|
|
2017-05-03 06:09:19 +00:00
|
|
|
;; int i = 0, j = 0;
|
|
|
|
((decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list (init-declr (ident ,name) . ,initzer) . ,rest))
|
|
|
|
(let loop ((inits `((init-declr (ident ,name) ,@initzer) ,@rest)) (info info))
|
|
|
|
(if (null? inits) info
|
|
|
|
(loop (cdr inits)
|
|
|
|
((ast->info info)
|
|
|
|
`(decl (decl-spec-list (type-spec (fixed-type ,type))) (init-declr-list ,(car inits))))))))
|
|
|
|
|
2017-03-12 11:02:12 +00:00
|
|
|
((decl (decl-spec-list (stor-spec (typedef)) ,type) ,name)
|
|
|
|
(format (current-error-port) "SKIP: typedef=~s\n" o)
|
|
|
|
info)
|
|
|
|
|
|
|
|
((decl (@ ,at))
|
|
|
|
(format (current-error-port) "SKIP: at=~s\n" o)
|
|
|
|
info)
|
|
|
|
|
2017-04-12 19:27:59 +00:00
|
|
|
((decl . _) (error "ast->info: unsupported: " o))
|
2017-01-17 18:03:08 +00:00
|
|
|
|
2017-04-06 07:12:50 +00:00
|
|
|
;; ...
|
|
|
|
((gt . _) ((expr->accu info) o))
|
|
|
|
((ge . _) ((expr->accu info) o))
|
|
|
|
((ne . _) ((expr->accu info) o))
|
|
|
|
((eq . _) ((expr->accu info) o))
|
|
|
|
((le . _) ((expr->accu info) o))
|
|
|
|
((lt . _) ((expr->accu info) o))
|
|
|
|
((lshift . _) ((expr->accu info) o))
|
|
|
|
((rshift . _) ((expr->accu info) o))
|
|
|
|
|
|
|
|
;; EXPR
|
2017-04-05 21:05:16 +00:00
|
|
|
((expr-stmt ,expression)
|
|
|
|
(let ((info ((expr->accu info) expression)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (wrap-as (i386:accu-zero?)))))
|
2017-04-05 21:05:16 +00:00
|
|
|
|
|
|
|
;; FIXME: why do we get (post-inc ...) here
|
2017-04-06 07:12:50 +00:00
|
|
|
;; (array-ref
|
2017-04-05 21:05:16 +00:00
|
|
|
(_ (let ((info ((expr->accu info) o)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (wrap-as (i386:accu-zero?)))))))))
|
2017-04-02 09:55:37 +00:00
|
|
|
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
(define (initzer->data info functions globals ta t d o)
|
|
|
|
(pmatch o
|
|
|
|
((initzer (p-expr (fixed ,value))) (int->bv32 (cstring->number value)))
|
core+mini-mes: Replace manual snippets by snarfed includes.
* build-aux/mes-snarf.scm (symbol->source, function->header,
function->source, function->environment): Add workarounds to
avoid struct-copy initializers.
* GNUmakefile (mini-mes): Snarf symbols and functions.
* scaffold/mini-mes.c: Include mini-mes.h, mini-mes.symbols.h,
mini-mes.symbols.i, mini-mes.i, mini-mes.environment.i.
Add snarfable symbol/special definitions.
(type_t): Prefix all types with `T', update users.
(assert_defined, gc_push_frame, gc_peek_frame, gc_init_cells): Mark
as internal.
* mes.c (type_t): Prefix all types with `T', update users.
* scaffold/mini-mes.c (eq_p, type_, car_, cdr_,
list_of_char_equal_p, lookup_macro, write_byte): New functions (from
mes.c).
(assq): Add debugging, workaround.
2017-03-10 19:56:18 +00:00
|
|
|
((initzer (neg (p-expr (fixed ,value)))) (int->bv32 (- (cstring->number value))))
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
((initzer (ref-to (p-expr (ident ,name))))
|
|
|
|
(int->bv32 (+ ta (function-offset name functions))))
|
|
|
|
((initzer (p-expr (ident ,name)))
|
|
|
|
(let ((value (assoc-ref (.constants info) name)))
|
|
|
|
(int->bv32 value)))
|
2017-03-09 07:14:27 +00:00
|
|
|
((initzer (p-expr (string ,string)))
|
|
|
|
(int->bv32 (+ (data-offset (add-s:-prefix string) globals) d)))
|
2017-04-12 19:27:59 +00:00
|
|
|
(_ (error "initzer->data: unsupported: " o))))
|
2017-04-02 09:55:37 +00:00
|
|
|
|
|
|
|
(define (.formals o)
|
|
|
|
(pmatch o
|
|
|
|
((fctn-defn _ (ftn-declr _ ,formals) _) formals)
|
2017-01-02 06:41:56 +00:00
|
|
|
((fctn-defn _ (ptr-declr (pointer) (ftn-declr _ ,formals)) _) formals)
|
2017-04-17 00:15:11 +00:00
|
|
|
((fctn-defn _ (ptr-declr (pointer (pointer)) (ftn-declr _ ,formals)) _) formals)
|
2017-04-12 19:27:59 +00:00
|
|
|
(_ (error ".formals: " o))))
|
2017-04-02 09:55:37 +00:00
|
|
|
|
2017-01-02 06:41:56 +00:00
|
|
|
(define (formal->text n)
|
|
|
|
(lambda (o i)
|
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
|
|
|
;;(i386:formal i n)
|
|
|
|
'()
|
|
|
|
))
|
2017-04-02 09:55:37 +00:00
|
|
|
|
|
|
|
(define (formals->text o)
|
|
|
|
(pmatch o
|
|
|
|
((param-list . ,formals)
|
2017-01-02 06:41:56 +00:00
|
|
|
(let ((n (length formals)))
|
2017-04-07 07:36:30 +00:00
|
|
|
(wrap-as (append (i386:function-preamble)
|
|
|
|
(append-map (formal->text n) formals (iota n))
|
|
|
|
(i386:function-locals)))))
|
2017-04-12 19:27:59 +00:00
|
|
|
(_ (error "formals->text: unsupported: " o))))
|
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
|
|
|
|
2017-03-17 16:32:23 +00:00
|
|
|
(define (formal:ptr o)
|
|
|
|
(pmatch o
|
|
|
|
((param-decl (decl-spec-list . ,decl) (param-declr (ident ,name)))
|
|
|
|
0)
|
2017-04-17 00:15:11 +00:00
|
|
|
((param-decl (decl-spec-list . ,decl) (param-declr (ptr-declr (pointer) (array-of (ident ,name)))))
|
|
|
|
2)
|
|
|
|
((param-decl (decl-spec-list . ,decl) (param-declr (ptr-declr (pointer) (ident ,name))))
|
|
|
|
1)
|
|
|
|
((param-decl (decl-spec-list . ,decl) (param-declr (ptr-declr (pointer) . _)))
|
|
|
|
1)
|
|
|
|
((param-decl (decl-spec-list . ,decl) (param-declr (ptr-declr (pointer (pointer)) (ident ,name))))
|
|
|
|
2)
|
2017-03-17 16:32:23 +00:00
|
|
|
(_
|
2017-04-17 00:15:11 +00:00
|
|
|
(stderr "formal:ptr[~a] => ~a\n" o 0)
|
2017-03-17 16:32:23 +00:00
|
|
|
0)))
|
|
|
|
|
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
|
|
|
(define (formals->locals o)
|
|
|
|
(pmatch o
|
|
|
|
((param-list . ,formals)
|
|
|
|
(let ((n (length formals)))
|
2017-03-17 16:32:23 +00:00
|
|
|
(map make-local (map .name formals) (map .type formals) (map formal:ptr formals) (iota n -2 -1))))
|
2017-04-12 19:27:59 +00:00
|
|
|
(_ (error "formals->locals: unsupported: " o))))
|
2017-04-02 09:55:37 +00:00
|
|
|
|
2017-01-04 23:55:46 +00:00
|
|
|
(define (function->info info)
|
2017-04-02 09:55:37 +00:00
|
|
|
(lambda (o)
|
2017-05-06 07:11:42 +00:00
|
|
|
(define (assert-return text)
|
|
|
|
(let ((return (wrap-as (i386:ret))))
|
|
|
|
(if (equal? (list-tail text (- (length text) (length return))) return) text
|
|
|
|
(append text (wrap-as (i386:ret))))))
|
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
|
|
|
(let* ((name (.name o))
|
2017-04-02 15:01:22 +00:00
|
|
|
(formals (.formals o))
|
|
|
|
(text (formals->text formals))
|
|
|
|
(locals (formals->locals formals)))
|
mescc: Parse mlibc early, show progress.
* module/mes/libc.mes (_start, strlen, getchar, assert_fail, ungetc,
putchar, fputc, eputs, fputs, puts, strcmp, itoa, isdigit, atoi,
malloc, realloc, strncmp, c:getenv): Change to function, add
progress. Update callers.
* module/language/c99/compiler.mes (c99-input->info): Compile libc separately.
* guile/mescc.scm: Update progress.
* scripts/mescc.mes: Update progress.
2017-04-24 17:09:54 +00:00
|
|
|
(format (current-error-port) "compiling: ~a\n" name)
|
2017-04-02 09:55:37 +00:00
|
|
|
(let loop ((statements (.statements o))
|
2017-03-09 07:14:27 +00:00
|
|
|
(info (clone info #:locals locals #:function (.name o) #:text text)))
|
2017-05-06 07:11:42 +00:00
|
|
|
(if (null? statements) (assert-return (clone info
|
|
|
|
#:function #f
|
|
|
|
#:functions (append (.functions info) (list (cons name (assert-return (.text info)))))))
|
2017-04-02 09:55:37 +00:00
|
|
|
(let* ((statement (car statements)))
|
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
|
|
|
(loop (cdr statements)
|
|
|
|
((ast->info info) (car statements)))))))))
|
2017-01-04 23:55:46 +00:00
|
|
|
|
|
|
|
(define (ast-list->info info)
|
|
|
|
(lambda (elements)
|
|
|
|
(let loop ((elements elements) (info info))
|
|
|
|
(if (null? elements) info
|
|
|
|
(loop (cdr elements) ((ast->info info) (car elements)))))))
|
2017-04-02 09:55:37 +00:00
|
|
|
|
2017-04-12 19:27:59 +00:00
|
|
|
(define (c99-input->info)
|
mescc: Parse mlibc early, show progress.
* module/mes/libc.mes (_start, strlen, getchar, assert_fail, ungetc,
putchar, fputc, eputs, fputs, puts, strcmp, itoa, isdigit, atoi,
malloc, realloc, strncmp, c:getenv): Change to function, add
progress. Update callers.
* module/language/c99/compiler.mes (c99-input->info): Compile libc separately.
* guile/mescc.scm: Update progress.
* scripts/mescc.mes: Update progress.
2017-04-24 17:09:54 +00:00
|
|
|
(let* ((info (make <info>
|
mescc: Run mini-mes.
* .gitignore: Ignore tiny-mes and tiny .mo's.
* doc/examples/tiny-mes.c: Simplify.
* doc/examples/mini-mes.c: Use simplifications from tiny-mes.
* doc/examples/t.c (read_test, struct_test): New functions.
(test): Add tests for arena, g_cells globals.
* module/mes/elf-util.mes (dec->hex): New function.
(lambda/label->list): Add text-address parameter. Update callers.
* module/language/c99/compiler.mes (make, info, clone): Add init field.
(.init): New function.
(ident->accu): Add exceptions for globals.
* module/mes/elf-util.scm: Export it.
* module/mes/libc-i386.mes (i386:accu->base-ref,
i386:byte-accu->base-ref, i386:accu->base-ref+n,
i386:accu->global-ref, i386:global-ref->accu, i386:global-ref->base,
i386:global-add, i386:global->accu):, i386:local-ref->accu,
i386:local-ptr->accu, i386:local-ptr->base): New functions.
* module/mes/libc-i386.scm: Export them.
2017-01-29 14:22:39 +00:00
|
|
|
#:functions i386:libc
|
|
|
|
#:types i386:type-alist))
|
mescc: Parse mlibc early, show progress.
* module/mes/libc.mes (_start, strlen, getchar, assert_fail, ungetc,
putchar, fputc, eputs, fputs, puts, strcmp, itoa, isdigit, atoi,
malloc, realloc, strncmp, c:getenv): Change to function, add
progress. Update callers.
* module/language/c99/compiler.mes (c99-input->info): Compile libc separately.
* guile/mescc.scm: Update progress.
* scripts/mescc.mes: Update progress.
2017-04-24 17:09:54 +00:00
|
|
|
(foo (stderr "compiling: mlibc\n"))
|
|
|
|
(info (let loop ((info info) (libc libc))
|
|
|
|
(if (null? libc) info
|
|
|
|
(loop ((ast->info info) ((car libc))) (cdr libc)))))
|
|
|
|
(foo (stderr "parsing: input\n"))
|
|
|
|
(ast (c99-input->ast))
|
|
|
|
(foo (stderr "compiling: input\n"))
|
2017-01-04 23:55:46 +00:00
|
|
|
(info ((ast->info info) ast))
|
mescc: Parse mlibc early, show progress.
* module/mes/libc.mes (_start, strlen, getchar, assert_fail, ungetc,
putchar, fputc, eputs, fputs, puts, strcmp, itoa, isdigit, atoi,
malloc, realloc, strncmp, c:getenv): Change to function, add
progress. Update callers.
* module/language/c99/compiler.mes (c99-input->info): Compile libc separately.
* guile/mescc.scm: Update progress.
* scripts/mescc.mes: Update progress.
2017-04-24 17:09:54 +00:00
|
|
|
(info ((ast->info info) (_start))))
|
2017-04-12 19:27:59 +00:00
|
|
|
info))
|
|
|
|
|
|
|
|
(define (write-any x)
|
|
|
|
(write-char (cond ((char? x) x)
|
|
|
|
((and (number? x) (< (+ x 256) 0))
|
|
|
|
(format (current-error-port) "***BROKEN*** x=~a ==> ~a\n" x (dec->hex x)) (integer->char #xaa))
|
|
|
|
((number? x) (integer->char (if (>= x 0) x (+ x 256))))
|
|
|
|
((procedure? x)
|
|
|
|
(stderr "write-any: proc: ~a\n" x)
|
|
|
|
(stderr " ==> ~a\n" (map dec->hex (x '() '() 0 0)))
|
|
|
|
(error "procedure: write-any:" x))
|
|
|
|
(else (stderr "write-any: ~a\n" x) (error "write-any: else: " x)))))
|
|
|
|
|
|
|
|
(define (info->elf info)
|
|
|
|
(display "dumping elf\n" (current-error-port))
|
|
|
|
(for-each write-any (make-elf (.functions info) (.globals info) (.init info))))
|
|
|
|
|
|
|
|
(define (c99-input->elf)
|
|
|
|
((compose info->elf c99-input->info)))
|