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)))
|
|
|
|
|
2016-12-31 08:03:07 +00:00
|
|
|
(define (mescc)
|
2017-01-04 23:55:46 +00:00
|
|
|
(parse-c99
|
|
|
|
#:inc-dirs (string-split (getenv "C_INCLUDE_PATH") #\:)
|
2017-04-02 16:50:07 +00:00
|
|
|
#:cpp-defs `(
|
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-03-22 06:54:45 +00:00
|
|
|
"STDIN=0"
|
|
|
|
"STDOUT=1"
|
|
|
|
"STDERR=2"
|
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
|
|
|
"O_RDONLY=0"
|
2017-03-22 06:54:45 +00:00
|
|
|
|
|
|
|
"INT_MIN=-2147483648"
|
|
|
|
"INT_MAX=2147483647"
|
|
|
|
|
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 (write-any x)
|
2017-01-03 17:22:56 +00:00
|
|
|
(write-char (cond ((char? x) x)
|
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
|
|
|
((and (number? x) (< (+ x 256) 0)) (format (current-error-port) "***BROKEN*** x=~a ==> ~a\n" x (dec->hex x)) (integer->char #xaa))
|
2017-01-03 17:22:56 +00:00
|
|
|
((number? x) (integer->char (if (>= x 0) x (+ x 256))))
|
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
|
|
|
((procedure? x)
|
|
|
|
(stderr "write-any: proc: ~a\n" x)
|
|
|
|
(stderr " ==> ~a\n" (map dec->hex (x '() '() 0 0)))
|
|
|
|
barf)
|
2017-01-03 17:22:56 +00:00
|
|
|
(else (stderr "write-any: ~a\n" x) barf))))
|
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)
|
|
|
|
((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)
|
|
|
|
(_
|
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)
|
|
|
|
((fctn-defn _ (ptr-declr (pointer) (ftn-declr (ident ,name) _)) (compd-stmt (block-item-list . ,statements))) statements)))
|
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-02-27 06:50:33 +00:00
|
|
|
(define (push-local-de-ref locals)
|
|
|
|
(lambda (o)
|
2017-04-07 07:36:30 +00:00
|
|
|
(wrap-as (i386:push-local-de-ref (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 (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
|
|
|
|
|
|
|
(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-02-27 06:50:33 +00:00
|
|
|
(if 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-03-17 07:37:45 +00:00
|
|
|
TODO:push-function))))))))
|
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-02-27 06:50:33 +00:00
|
|
|
(if local ((push-local-de-ref (.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-de-ref (.globals info)) o)))))
|
2017-01-17 18:03:08 +00:00
|
|
|
|
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
|
|
|
|
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)))
|
2017-03-17 07:37:45 +00:00
|
|
|
;;(stderr "expr->arg o=~s\n" o)
|
2017-02-27 06:50:33 +00:00
|
|
|
(pmatch o
|
|
|
|
|
|
|
|
((p-expr (string ,string))
|
2017-04-07 07:53:56 +00:00
|
|
|
(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
|
|
|
|
|
|
|
((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
|
|
|
|
|
|
|
((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)))
|
|
|
|
;; (stderr "ident->accu: local[~a]: ~a\n" o (and local (local:id local)))
|
|
|
|
;; (stderr "ident->accu: global[~a]: ~a\n" o global)
|
|
|
|
;; (stderr "globals: ~a\n" (.globals info))
|
|
|
|
;; (if (and (not global) (not (local:id local)))
|
|
|
|
;; (stderr "globals: ~a\n" (map car (.globals 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
|
|
|
(if local
|
2017-03-17 16:32:23 +00:00
|
|
|
(let* ((ptr (local:pointer local))
|
|
|
|
(type (ident->type info o))
|
|
|
|
(size (and type (type->size info type))))
|
2017-03-09 07:14:27 +00:00
|
|
|
;;(stderr "ident->accu PTR[~a]: ~a\n" o ptr)
|
2017-03-17 16:32:23 +00:00
|
|
|
;;(stderr "type: ~s\n" type)
|
|
|
|
;;(stderr "ident->accu PTR[~a]: ~a\n" o ptr)
|
|
|
|
;;(stderr "locals: ~s\n" locals)
|
|
|
|
(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
|
|
|
|
(let ((ptr (ident->pointer info o)))
|
2017-03-09 07:14:27 +00:00
|
|
|
;;(stderr "ident->accu PTR[~a]: ~a\n" o ptr)
|
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)))))
|
|
|
|
(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)))))))))))
|
|
|
|
|
|
|
|
(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-07 07:36:30 +00:00
|
|
|
(if local (wrap-as (i386:accu->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)
|
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:accu->global (+ (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
|
|
|
(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-07 07:36:30 +00:00
|
|
|
(if local (wrap-as (append (i386:local->accu (local:id local))
|
|
|
|
(i386:byte-base->accu-address)))
|
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
|
|
|
TODO:base->ident-address-global))))
|
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
|
|
|
|
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)))
|
2017-03-09 07:14:27 +00:00
|
|
|
;;(stderr "ident->base: local[~a]: ~a\n" o (and local (local:id local)))
|
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))
|
|
|
|
(size (and type (type->size info type))))
|
|
|
|
(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-03-09 07:14:27 +00:00
|
|
|
;;(stderr "ident->accu PTR[~a]: ~a\n" o ptr)
|
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)))))
|
|
|
|
(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)
|
|
|
|
(let* ((id (1+ (length (filter local? (map cdr locals)))))
|
|
|
|
(locals (cons (make-local name type pointer id) locals)))
|
|
|
|
locals))
|
|
|
|
;; (stderr "expr->accu o=~a\n" 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
|
|
|
(pmatch o
|
2017-03-09 07:14:27 +00:00
|
|
|
((p-expr (string ,string))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (list (lambda (f g ta t d)
|
|
|
|
(i386:global->accu (+ (data-offset (add-s:-prefix string) 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))))
|
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))
|
|
|
|
((ref-to (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
|
|
|
|
|
|
|
((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)))))
|
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-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))
|
|
|
|
(size (type->size info type))
|
|
|
|
(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)))))
|
|
|
|
|
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))
|
|
|
|
(size (and type (type->size info type))))
|
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-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-05 18:11:13 +00:00
|
|
|
(let* ((globals (append globals (filter-map expr->global expr-list)))
|
|
|
|
(info (clone info #:globals globals))
|
|
|
|
(text-length (length text))
|
|
|
|
(args-info (let loop ((expressions (reverse expr-list)) (info info))
|
|
|
|
(if (null? expressions) info
|
|
|
|
(loop (cdr expressions) ((expr->arg info) (car expressions))))))
|
|
|
|
(text (.text args-info))
|
|
|
|
(n (length expr-list)))
|
|
|
|
(if (and (not (assoc-ref locals name))
|
|
|
|
(assoc-ref (.functions info) name))
|
|
|
|
(clone args-info #:text
|
|
|
|
(append text
|
|
|
|
(list (lambda (f g ta t d)
|
|
|
|
(i386:call f g ta t d (+ t (function-offset name f)) n))))
|
|
|
|
#:globals globals)
|
|
|
|
(let* ((empty (clone info #:text '()))
|
|
|
|
(accu ((expr->accu empty) `(p-expr (ident ,name)))))
|
|
|
|
(clone args-info #:text
|
|
|
|
(append text
|
|
|
|
(.text accu)
|
|
|
|
(list (lambda (f g ta t d)
|
|
|
|
(i386:call-accu f g ta t d n))))
|
|
|
|
#:globals globals))))))
|
|
|
|
|
|
|
|
((fctn-call ,function (expr-list . ,expr-list))
|
|
|
|
(let* ((globals (append globals (filter-map expr->global expr-list)))
|
|
|
|
(info (clone info #:globals globals))
|
|
|
|
(text-length (length text))
|
|
|
|
(args-info (let loop ((expressions (reverse expr-list)) (info info))
|
|
|
|
(if (null? expressions) info
|
|
|
|
(loop (cdr expressions) ((expr->arg info) (car expressions))))))
|
|
|
|
(text (.text args-info))
|
|
|
|
(n (length expr-list))
|
|
|
|
(empty (clone info #:text '()))
|
|
|
|
(accu ((expr->accu empty) function)))
|
|
|
|
(clone info #:text
|
|
|
|
(append text
|
|
|
|
(.text accu)
|
|
|
|
(list (lambda (f g ta t d)
|
|
|
|
(i386:call-accu f g ta t d n))))
|
|
|
|
#: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
|
|
|
|
|
|
|
((cond-expr . ,cond-expr)
|
|
|
|
((ast->info info) `(expr-stmt ,o)))
|
|
|
|
|
|
|
|
((post-inc (p-expr (ident ,name)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(append-text info (append ((ident->accu info) name)
|
|
|
|
((ident-add info) name 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
|
|
|
|
2017-04-05 21:05:16 +00:00
|
|
|
((post-dec (p-expr (ident ,name)))
|
|
|
|
(or (assoc-ref locals name) (begin (stderr "i-- ~a\n" name) barf))
|
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)))
|
|
|
|
(or (assoc-ref locals name) (begin (stderr "++i ~a\n" name) barf))
|
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)))
|
|
|
|
(or (assoc-ref locals name) (begin (stderr "--i ~a\n" name) barf))
|
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)))
|
|
|
|
((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-04-07 12:31:35 +00:00
|
|
|
((eq ,a ,b) ((binop->accu info) a b (i386:sub-base)))
|
|
|
|
((ge ,a ,b) ((binop->accu info) b a (i386:sub-base)))
|
|
|
|
((gt ,a ,b) ((binop->accu info) b a (i386:sub-base)))
|
|
|
|
((ne ,a ,b) ((binop->accu info) a b (append (i386:sub-base)
|
|
|
|
(i386:xor-zf))))
|
|
|
|
((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
|
|
|
|
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-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)))
|
|
|
|
((d-sel (ident ,field) . ,d-sel)
|
|
|
|
(let* ((type (list "struct" "scm")) ;; FIXME
|
|
|
|
(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
|
|
|
|
((de-ref (p-expr (ident ,array)))
|
|
|
|
(append-text info (append (wrap-as (i386:accu->base))
|
|
|
|
((base->ident-address info) array)
|
|
|
|
(wrap-as (i386:base->accu)))))
|
|
|
|
((de-ref (post-inc (p-expr (ident ,name))))
|
|
|
|
(let ((info ((expr->accu info) `(assn-expr (de-ref (p-expr (ident ,name))) (op ,op) ,b))))
|
|
|
|
(append-text info ((ident-add info) name 1))))
|
|
|
|
((de-ref (post-dec (p-expr (ident ,name))))
|
|
|
|
(let ((info ((expr->accu info) `(assn-expr (de-ref (p-expr (ident ,name))) (op ,op) ,b))))
|
|
|
|
(append-text info ((ident-add info) name -1))))
|
|
|
|
((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))
|
|
|
|
(append
|
|
|
|
(wrap-as (i386:base-address->accu-address))
|
|
|
|
(if (<= size 4) '()
|
|
|
|
(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))))))))))
|
|
|
|
(_ barf-assign))))
|
2017-04-06 07:12:50 +00:00
|
|
|
|
|
|
|
(_
|
|
|
|
(format (current-error-port) "SKIP: expr->accu=~s\n" o)
|
|
|
|
barf
|
|
|
|
info)))))
|
|
|
|
|
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)
|
2017-04-06 21:05:44 +00:00
|
|
|
;; (stderr "expr->accu* o=~s\n" o)
|
|
|
|
|
2017-04-06 07:12:50 +00:00
|
|
|
(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))
|
|
|
|
(size (type->size info type)))
|
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
|
|
|
|
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-02 05:41:19 +00:00
|
|
|
(format (current-error-port) "SKIP: expr->accu*=~s\n" 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
|
|
|
barf
|
2017-01-17 18:03:08 +00:00
|
|
|
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
|
|
|
)))
|
|
|
|
|
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)
|
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-03-17 16:32:23 +00:00
|
|
|
(stderr "SKIP: decl type=~s\n" o)
|
|
|
|
barf
|
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
|
|
|
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-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-01-17 18:03:08 +00:00
|
|
|
(define (case->jump-info info)
|
|
|
|
(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)
|
|
|
|
((p-expr (ident ,constant)) (assoc-ref (.constants info) constant))
|
|
|
|
((p-expr (fixed ,value)) (cstring->number value))
|
|
|
|
((neg (p-expr (fixed ,value))) (- (cstring->number value))))))
|
|
|
|
(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)
|
|
|
|
(let* ((text (.text info))
|
|
|
|
(info (clone info #:text '()))
|
|
|
|
|
|
|
|
(a-jump ((test->jump->info info) a))
|
|
|
|
(a-text (.text (a-jump 0)))
|
|
|
|
(a-length (length (text->list a-text)))
|
|
|
|
|
|
|
|
(b-jump ((test->jump->info info) b))
|
|
|
|
(b-text (.text (b-jump 0)))
|
|
|
|
(b-length (length (text->list b-text))))
|
|
|
|
|
|
|
|
(lambda (body-length)
|
|
|
|
(clone info #:text
|
|
|
|
(append text
|
|
|
|
(.text (a-jump (+ b-length body-length)))
|
|
|
|
(.text (b-jump body-length)))))))
|
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)
|
|
|
|
(let* ((text (.text info))
|
|
|
|
(info (clone info #:text '()))
|
|
|
|
|
|
|
|
(a-jump ((test->jump->info info) a))
|
|
|
|
(a-text (.text (a-jump 0)))
|
|
|
|
(a-length (length (text->list a-text)))
|
|
|
|
|
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)
|
|
|
|
(clone info #:text
|
|
|
|
(append text
|
|
|
|
(.text (a-jump jump-length))
|
|
|
|
jump-text
|
|
|
|
(.text (b-jump body-length)))))))
|
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))
|
|
|
|
((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
|
|
|
|
(_ (stderr "struct-field: no match: ~s\n" o) barf)))
|
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))
|
|
|
|
("int" . (builtin 4 #f))))
|
|
|
|
|
|
|
|
(define (type->size info o)
|
2017-03-13 18:38:38 +00:00
|
|
|
;;(stderr "types=~s\n" (.types info))
|
|
|
|
;;(stderr "type->size o=~s => ~s\n" o (cadr (assoc-ref (.types info) o)))
|
|
|
|
(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)
|
|
|
|
(begin
|
|
|
|
(stderr "***TYPE NOT FOUND**: o=~s\n" o)
|
|
|
|
barf
|
|
|
|
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
|
|
|
|
|
|
|
(define (ident->decl info o)
|
2017-03-12 11:02:12 +00:00
|
|
|
;; (stderr "ident->decl o=~s\n" 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
|
|
|
;; (stderr " types=~s\n" (.types info))
|
|
|
|
;; (stderr " local=~s\n" (assoc-ref (.locals info) o))
|
|
|
|
;; (stderr " global=~s\n" (assoc-ref (.globals 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
|
|
|
|
|
|
|
(define (type->description info o)
|
|
|
|
;; (stderr "type->description =~s\n" o)
|
|
|
|
;; (stderr "types=~s\n" (.types info))
|
|
|
|
;; (stderr "type->description o=~s ==> ~s\n" o (caddr (assoc-ref (.types info) o)))
|
|
|
|
;; (stderr " assoc ~a\n" (assoc-ref (.types 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))
|
|
|
|
(_ (caddr (assoc-ref (.types info) 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-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)
|
|
|
|
(let* ((id (1+ (length (filter local? (map cdr locals)))))
|
|
|
|
(locals (cons (make-local name type pointer id) locals)))
|
2017-01-07 20:53:12 +00:00
|
|
|
locals))
|
2017-01-04 23:55:46 +00:00
|
|
|
|
2017-04-02 10:29:09 +00:00
|
|
|
;; (stderr "\n ast->info=~s\n" o)
|
2017-01-17 17:57:41 +00:00
|
|
|
;; (stderr " globals[~a=>~a]: ~a\n" (length globals) (length (append-map cdr globals)) (map (lambda (s) (if (string? s) (string-delete #\newline s))) (map car globals)))
|
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
|
|
|
;; (stderr " text=~a\n" text)
|
2017-01-04 23:55:46 +00:00
|
|
|
;; (stderr " info=~a\n" info)
|
|
|
|
;; (stderr " globals=~a\n" globals)
|
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-01-17 18:03:08 +00:00
|
|
|
((switch ,expr (compd-stmt (block-item-list . ,cases)))
|
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* ((expr ((expr->accu info) expr))
|
2017-01-17 18:03:08 +00:00
|
|
|
(empty (clone info #:text '()))
|
|
|
|
(case-infos (map (case->jump-info empty) cases))
|
|
|
|
(case-lengths (map (lambda (c-j) (length (text->list (.text (c-j 0))))) case-infos))
|
|
|
|
(cases-info (let loop ((cases cases) (info expr) (lengths case-lengths))
|
|
|
|
(if (null? cases) info
|
|
|
|
(let ((c-j ((case->jump-info info) (car cases))))
|
|
|
|
(loop (cdr cases) (c-j (apply + (cdr lengths))) (cdr lengths)))))))
|
|
|
|
cases-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
|
|
|
((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)))
|
|
|
|
(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-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))))))
|
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 (not (.function info)) decl-barf0)
|
|
|
|
(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))))))
|
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 (not (.function info)) decl-barf2)
|
|
|
|
(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-01-08 16:51:40 +00:00
|
|
|
;; char *p = "t.c";
|
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-03-23 17:48:19 +00:00
|
|
|
(when (not (.function info))
|
2017-04-06 07:12:50 +00:00
|
|
|
(stderr "o=~s\n" o)
|
|
|
|
decl-barf3)
|
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))
|
2017-03-09 07:14:27 +00:00
|
|
|
(globals (append globals (list (string->global string))))
|
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 #:globals globals)))
|
2017-04-07 07:53:56 +00:00
|
|
|
(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)))))
|
2017-01-08 16:51:40 +00:00
|
|
|
|
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
|
|
|
;; char *p = 0;
|
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-03-23 17:48:19 +00:00
|
|
|
(clone info #:globals (append globals (list (ident->global name type 0 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
|
|
|
|
2017-01-17 18:03:08 +00:00
|
|
|
;; char arena[20000];
|
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 (array-of (ident ,name) (p-expr (fixed ,count))))))
|
|
|
|
(let ((type (ast->type type)))
|
|
|
|
(if (.function info)
|
|
|
|
TODO:decl-array
|
|
|
|
(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-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
|
|
|
;;(stderr "0TYPE: ~s\n" 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) name)
|
|
|
|
((accu->ident info) value)))) ;; FIXME: deref?
|
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))))
|
|
|
|
(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
|
|
|
|
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))))
|
|
|
|
;;(stderr "1TYPE: ~s\n" type)
|
|
|
|
(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))))))
|
|
|
|
;;(stderr "2TYPE: ~s\n" type)
|
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
|
|
|
;;(stderr "3TYPE: ~s\n" type)
|
|
|
|
(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
|
|
|
;;(stderr "6TYPE: ~s\n" 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))))
|
|
|
|
(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))))))
|
|
|
|
;;(stderr "7TYPE: ~s\n" type)
|
|
|
|
(let ((type (decl->type type)))
|
|
|
|
;;(stderr "0DECL: ~s\n" 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-01-10 21:44:01 +00:00
|
|
|
(constants (map ident->constant (map cadadr fields) (iota (length 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
|
|
|
(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)))))
|
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 (struct->type (list "struct" name) (map struct-field fields))))
|
2017-03-09 07:14:27 +00:00
|
|
|
;;(stderr "type: ~a\n" type)
|
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
|
|
|
|
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
|
|
|
|
;;
|
|
|
|
;; 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))
|
|
|
|
;;(foo (stderr "1DECL: ~s\n" type))
|
|
|
|
(fields (type->description info type))
|
|
|
|
(size (type->size info type))
|
|
|
|
(field-size 4)) ;; FIXME:4, not fixed
|
|
|
|
;;(stderr "7TYPE: ~s\n" type)
|
|
|
|
(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-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)
|
|
|
|
|
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 . _)
|
|
|
|
(format (current-error-port) "SKIP: decl statement=~s\n" o)
|
2017-03-12 11:02:12 +00:00
|
|
|
barf
|
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)
|
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))))
|
|
|
|
;;(stderr "INITZER[~a] => 0x~a\n" o (dec->hex (+ ta (function-offset name functions))))
|
|
|
|
(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)))
|
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
|
|
|
(_ (stderr "initzer->data:SKIP: ~s\n" o)
|
|
|
|
barf
|
2017-04-06 07:12:50 +00:00
|
|
|
(int->bv32 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-01-04 23:55:46 +00:00
|
|
|
(define (info->exe info)
|
2017-04-02 09:55:37 +00:00
|
|
|
(display "dumping elf\n" (current-error-port))
|
2017-04-03 05:09:03 +00:00
|
|
|
(for-each write-any (make-elf (.functions info) (.globals info) (.init info))))
|
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-02 09:55:37 +00:00
|
|
|
(_ (format (current-error-port) ".formals: no match: ~a\n" o)
|
|
|
|
barf)))
|
|
|
|
|
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)))))
|
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
|
|
|
(_ (format (current-error-port) "formals->text: no match: ~a\n" o)
|
|
|
|
barf)))
|
|
|
|
|
2017-03-17 16:32:23 +00:00
|
|
|
(define (formal:ptr o)
|
|
|
|
(pmatch o
|
|
|
|
((param-decl (decl-spec-list . ,decl) (param-declr (ptr-declr (pointer) . _)))
|
|
|
|
1)
|
|
|
|
((param-decl (decl-spec-list . ,decl) (param-declr (ident ,name)))
|
|
|
|
0)
|
|
|
|
(_
|
|
|
|
(stderr "formal:ptr[~a] => 0\n" o)
|
|
|
|
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-01-04 23:55:46 +00:00
|
|
|
(_ (format (current-error-port) "formals->info: no match: ~a\n" o)
|
2017-04-02 09:55:37 +00:00
|
|
|
barf)))
|
|
|
|
|
2017-01-04 23:55:46 +00:00
|
|
|
(define (function->info info)
|
2017-04-02 09:55:37 +00:00
|
|
|
(lambda (o)
|
2017-04-02 15:01:22 +00:00
|
|
|
;;(stderr "function->info o=~s\n" o)
|
|
|
|
;;(stderr "formals=~s\n" (.formals 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
|
|
|
(let* ((name (.name o))
|
2017-04-02 15:01:22 +00:00
|
|
|
(formals (.formals o))
|
|
|
|
(text (formals->text formals))
|
|
|
|
(locals (formals->locals formals)))
|
|
|
|
(format (current-error-port) "compiling ~s\n" name)
|
|
|
|
;;(stderr "locals=~s\n" locals)
|
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-01-04 23:55:46 +00:00
|
|
|
(if (null? statements) (clone 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
|
|
|
#:function #f
|
2017-03-09 07:14:27 +00:00
|
|
|
#:functions (append (.functions info) (list (cons name (.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
|
|
|
|
2016-12-31 08:03:07 +00:00
|
|
|
(define (compile)
|
2017-04-02 15:01:22 +00:00
|
|
|
(stderr "COMPILE\n")
|
2016-12-31 08:03:07 +00:00
|
|
|
(let* ((ast (mescc))
|
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 (make <info>
|
|
|
|
#:functions i386:libc
|
|
|
|
#:types i386:type-alist))
|
2017-01-17 18:03:08 +00:00
|
|
|
(ast (append libc ast))
|
2017-01-04 23:55:46 +00:00
|
|
|
(info ((ast->info info) ast))
|
|
|
|
(info ((ast->info info) _start)))
|
|
|
|
(info->exe info)))
|