mescc: Refactor type system: WIP
* module/language/c99/compiler.mes (): WIP * module/language/c99/info.scm (): WIP
This commit is contained in:
parent
1b4a994b6d
commit
a1862f749f
|
@ -232,9 +232,6 @@ broken="$broken
|
||||||
42_function_pointer
|
42_function_pointer
|
||||||
46_grep
|
46_grep
|
||||||
49_bracket_evaluation
|
49_bracket_evaluation
|
||||||
|
|
||||||
52_unnamed_enum
|
|
||||||
55_lshift_type
|
|
||||||
"
|
"
|
||||||
|
|
||||||
#22_floating_point ; float
|
#22_floating_point ; float
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -97,7 +97,7 @@
|
||||||
function:type
|
function:type
|
||||||
function:text
|
function:text
|
||||||
|
|
||||||
-><type>
|
->type
|
||||||
->rank
|
->rank
|
||||||
rank--
|
rank--
|
||||||
rank++
|
rank++
|
||||||
|
@ -162,36 +162,32 @@
|
||||||
(value var:value))
|
(value var:value))
|
||||||
|
|
||||||
(define-immutable-record-type <global>
|
(define-immutable-record-type <global>
|
||||||
(make-global- name type var pointer c-array value function)
|
(make-global- name type var value function)
|
||||||
global?
|
global?
|
||||||
(name global:name)
|
(name global:name)
|
||||||
(type global:type)
|
(type global:type)
|
||||||
(var global:var) ; <var>
|
(var global:var) ; <var>
|
||||||
|
|
||||||
(pointer global:pointer)
|
|
||||||
(c-array global:c-array)
|
|
||||||
(value global:value)
|
(value global:value)
|
||||||
(function global:function))
|
(function global:function))
|
||||||
|
|
||||||
(define (make-global name type pointer c-array value function)
|
(define (make-global name type value function)
|
||||||
(make-global- name type (make-var name type function #f value) pointer c-array value function))
|
(make-global- name type (make-var name type function #f value) value function))
|
||||||
|
|
||||||
(define (global->string o)
|
(define (global->string o)
|
||||||
(or (and=> (global:function o) (cut string-append <> "-" (global:name o)))
|
(or (and=> (global:function o) (cut string-append <> "-" (global:name o)))
|
||||||
(global:name o)))
|
(global:name o)))
|
||||||
|
|
||||||
(define-immutable-record-type <local>
|
(define-immutable-record-type <local>
|
||||||
(make-local- type var id pointer c-array)
|
(make-local- type var id)
|
||||||
local?
|
local?
|
||||||
(type local:type)
|
(type local:type)
|
||||||
(var local:var) ; <var>
|
(var local:var) ; <var>
|
||||||
|
|
||||||
(id local:id)
|
(id local:id))
|
||||||
(pointer local:pointer)
|
|
||||||
(c-array local:c-array))
|
|
||||||
|
|
||||||
(define (make-local name type pointer c-array id)
|
(define (make-local name type id)
|
||||||
(make-local- type (make-var name type #f id #f) id pointer c-array))
|
(make-local- type (make-var name type #f id #f) id))
|
||||||
|
|
||||||
(define-immutable-record-type <function>
|
(define-immutable-record-type <function>
|
||||||
(make-function name type text)
|
(make-function name type text)
|
||||||
|
@ -207,7 +203,7 @@
|
||||||
((and (pair? o) (eq? (car o) 'tag))) ;; FIXME: enum?
|
((and (pair? o) (eq? (car o) 'tag))) ;; FIXME: enum?
|
||||||
(else #f)))
|
(else #f)))
|
||||||
|
|
||||||
(define (-><type> o)
|
(define (->type o)
|
||||||
(cond ((type? o) o)
|
(cond ((type? o) o)
|
||||||
((pointer? o) (pointer:type o))
|
((pointer? o) (pointer:type o))
|
||||||
((c-array? o) (c-array:type o))
|
((c-array? o) (c-array:type o))
|
||||||
|
@ -216,7 +212,7 @@
|
||||||
(#t
|
(#t
|
||||||
(format (current-error-port) "->type--: not a <type>: ~s\n" o)
|
(format (current-error-port) "->type--: not a <type>: ~s\n" o)
|
||||||
(make-type 'builtin 4 #f))
|
(make-type 'builtin 4 #f))
|
||||||
(else (error "-><type>: not a <type>:" o))))
|
(else (error "->type: not a <type>:" o))))
|
||||||
|
|
||||||
(define (->rank o)
|
(define (->rank o)
|
||||||
(cond ((type? o) 0)
|
(cond ((type? o) 0)
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include "00-test.i"
|
#include "00-test.i"
|
||||||
|
|
||||||
|
char *g_hello = "hello";
|
||||||
char g_arena[4] = "XXX";
|
char g_arena[4] = "XXX";
|
||||||
char *g_chars = g_arena;
|
char *g_chars = g_arena;
|
||||||
|
|
||||||
|
@ -32,32 +33,36 @@ struct foo *file;
|
||||||
int
|
int
|
||||||
test ()
|
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';
|
g_arena[0] = 'A';
|
||||||
if (*g_chars != 'A') return 2;
|
if (*g_chars != 'A') return 5;
|
||||||
char *x = g_arena;
|
char *x = g_arena;
|
||||||
if (*x++ != 'A') return 3;
|
if (*x++ != 'A') return 5;
|
||||||
*x++ = 'C';
|
*x++ = 'C';
|
||||||
if (g_chars[1] != 'C') return 4;
|
if (g_chars[1] != 'C') return 7;
|
||||||
if (g_chars[2] != 'X') return 5;
|
if (g_chars[2] != 'X') return 8;
|
||||||
*--x = 'X';
|
*--x = 'X';
|
||||||
if (g_chars[1] != 'X') return 7;
|
if (g_chars[1] != 'X') return 9;
|
||||||
|
|
||||||
char **pp = &x;
|
char **pp = &x;
|
||||||
if (**pp != 'X') return 7;
|
if (**pp != 'X') return 10;
|
||||||
|
|
||||||
char *p = *pp;
|
char *p = *pp;
|
||||||
if (*p != 'X') return 8;
|
if (*p != 'X') return 11;
|
||||||
|
|
||||||
char ***ppp = &pp;
|
char ***ppp = &pp;
|
||||||
if (***ppp != 'X') return 9;
|
if (***ppp != 'X') return 12;
|
||||||
|
|
||||||
char **pp2 = *ppp;
|
char **pp2 = *ppp;
|
||||||
if (**pp2 != 'X') return 10;
|
if (**pp2 != 'X') return 13;
|
||||||
|
|
||||||
struct foo *f = 0;
|
struct foo *f = 0;
|
||||||
if (f) return 11;
|
if (f) return 14;
|
||||||
if (file) return 12;
|
if (file) return 15;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static int i = 2;
|
||||||
|
|
||||||
int
|
int
|
||||||
test ()
|
test ()
|
||||||
{
|
{
|
||||||
|
@ -27,10 +29,9 @@ test ()
|
||||||
return foo - i--;
|
return foo - i--;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int i = 2;
|
|
||||||
int
|
int
|
||||||
main ()
|
main ()
|
||||||
{
|
{
|
||||||
test ();
|
test ();
|
||||||
return test ();
|
return i - 2 - test ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,11 +32,7 @@ struct scm {
|
||||||
|
|
||||||
int bla = 1234;
|
int bla = 1234;
|
||||||
char g_arena[84];
|
char g_arena[84];
|
||||||
#if __MESC__
|
|
||||||
struct scm *g_cells = g_arena;
|
|
||||||
#else
|
|
||||||
struct scm *g_cells = (struct scm*)g_arena;
|
struct scm *g_cells = (struct scm*)g_arena;
|
||||||
#endif
|
|
||||||
char *g_chars = g_arena;
|
char *g_chars = g_arena;
|
||||||
|
|
||||||
int foo () {puts ("t: foo\n"); return 0;};
|
int foo () {puts ("t: foo\n"); return 0;};
|
||||||
|
|
|
@ -41,6 +41,14 @@ struct anon {struct {int bar; int baz;};};
|
||||||
|
|
||||||
struct here {int and;} there;
|
struct here {int and;} there;
|
||||||
|
|
||||||
|
int
|
||||||
|
test (struct foo* p)
|
||||||
|
{
|
||||||
|
struct foo *g = &f;
|
||||||
|
g[0].length = 0;
|
||||||
|
p[0].length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char* argv[])
|
main (int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue