mescc: Refactor type system: WIP

* module/language/c99/compiler.mes (): WIP
* module/language/c99/info.scm (): WIP
This commit is contained in:
Jan Nieuwenhuizen 2018-05-10 12:40:07 +02:00
parent 1b4a994b6d
commit a1862f749f
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
7 changed files with 480 additions and 587 deletions

View File

@ -232,9 +232,6 @@ broken="$broken
42_function_pointer
46_grep
49_bracket_evaluation
52_unnamed_enum
55_lshift_type
"
#22_floating_point ; float

File diff suppressed because it is too large Load Diff

View File

@ -97,7 +97,7 @@
function:type
function:text
-><type>
->type
->rank
rank--
rank++
@ -162,36 +162,32 @@
(value var:value))
(define-immutable-record-type <global>
(make-global- name type var pointer c-array value function)
(make-global- name type var value function)
global?
(name global:name)
(type global:type)
(var global:var) ; <var>
(pointer global:pointer)
(c-array global:c-array)
(value global:value)
(function global:function))
(define (make-global name type pointer c-array value function)
(make-global- name type (make-var name type function #f value) pointer c-array value function))
(define (make-global name type value function)
(make-global- name type (make-var name type function #f value) value function))
(define (global->string o)
(or (and=> (global:function o) (cut string-append <> "-" (global:name o)))
(global:name o)))
(define-immutable-record-type <local>
(make-local- type var id pointer c-array)
(make-local- type var id)
local?
(type local:type)
(var local:var) ; <var>
(id local:id)
(pointer local:pointer)
(c-array local:c-array))
(id local:id))
(define (make-local name type pointer c-array id)
(make-local- type (make-var name type #f id #f) id pointer c-array))
(define (make-local name type id)
(make-local- type (make-var name type #f id #f) id))
(define-immutable-record-type <function>
(make-function name type text)
@ -207,7 +203,7 @@
((and (pair? o) (eq? (car o) 'tag))) ;; FIXME: enum?
(else #f)))
(define (-><type> o)
(define (->type o)
(cond ((type? o) o)
((pointer? o) (pointer:type o))
((c-array? o) (c-array:type o))
@ -216,7 +212,7 @@
(#t
(format (current-error-port) "->type--: not a <type>: ~s\n" o)
(make-type 'builtin 4 #f))
(else (error "-><type>: not a <type>:" o))))
(else (error "->type: not a <type>:" o))))
(define (->rank o)
(cond ((type? o) 0)

View File

@ -20,6 +20,7 @@
#include "00-test.i"
char *g_hello = "hello";
char g_arena[4] = "XXX";
char *g_chars = g_arena;
@ -32,32 +33,36 @@ struct foo *file;
int
test ()
{
if (*g_chars != 'X') return 1;
if (*g_hello != 'h') return 1;
if (g_hello[0] != 'h') return 2;
if (g_chars[0] != 'X') return 3;
if (*g_chars != 'X') return 4;
g_arena[0] = 'A';
if (*g_chars != 'A') return 2;
if (*g_chars != 'A') return 5;
char *x = g_arena;
if (*x++ != 'A') return 3;
if (*x++ != 'A') return 5;
*x++ = 'C';
if (g_chars[1] != 'C') return 4;
if (g_chars[2] != 'X') return 5;
if (g_chars[1] != 'C') return 7;
if (g_chars[2] != 'X') return 8;
*--x = 'X';
if (g_chars[1] != 'X') return 7;
if (g_chars[1] != 'X') return 9;
char **pp = &x;
if (**pp != 'X') return 7;
if (**pp != 'X') return 10;
char *p = *pp;
if (*p != 'X') return 8;
if (*p != 'X') return 11;
char ***ppp = &pp;
if (***ppp != 'X') return 9;
if (***ppp != 'X') return 12;
char **pp2 = *ppp;
if (**pp2 != 'X') return 10;
if (**pp2 != 'X') return 13;
struct foo *f = 0;
if (f) return 11;
if (file) return 12;
if (f) return 14;
if (file) return 15;
return 0;
}

View File

@ -18,6 +18,8 @@
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
*/
static int i = 2;
int
test ()
{
@ -27,10 +29,9 @@ test ()
return foo - i--;
}
static int i = 2;
int
main ()
{
test ();
return test ();
return i - 2 - test ();
}

View File

@ -32,11 +32,7 @@ struct scm {
int bla = 1234;
char g_arena[84];
#if __MESC__
struct scm *g_cells = g_arena;
#else
struct scm *g_cells = (struct scm*)g_arena;
#endif
char *g_chars = g_arena;
int foo () {puts ("t: foo\n"); return 0;};

View File

@ -41,6 +41,14 @@ struct anon {struct {int bar; int baz;};};
struct here {int and;} there;
int
test (struct foo* p)
{
struct foo *g = &f;
g[0].length = 0;
p[0].length = 0;
}
int
main (int argc, char* argv[])
{