mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-16 09:17:35 +02:00
Added stubs for compiling/evaluating vectors
This commit is contained in:
parent
935226740e
commit
bc01c9dd19
4 changed files with 19 additions and 0 deletions
11
cgen.scm
11
cgen.scm
|
@ -316,6 +316,15 @@
|
||||||
(_c-compile-scalars args)
|
(_c-compile-scalars args)
|
||||||
num-args)))
|
num-args)))
|
||||||
|
|
||||||
|
(define (c-compile-vector exp)
|
||||||
|
;; TODO: this is just a stub, does not allocate vector contents
|
||||||
|
(let ((cvar-name (mangle (gensym 'c))))
|
||||||
|
(c-code/vars
|
||||||
|
(string-append "&" cvar-name) ; Code is just the variable name
|
||||||
|
(list ; Allocate integer on the C stack
|
||||||
|
(string-append
|
||||||
|
"make_empty_vector(" cvar-name ");")))))
|
||||||
|
|
||||||
;; c-compile-const : const-exp -> c-pair
|
;; c-compile-const : const-exp -> c-pair
|
||||||
;;
|
;;
|
||||||
;; Typically this function is used to compile constant values such as
|
;; Typically this function is used to compile constant values such as
|
||||||
|
@ -327,6 +336,8 @@
|
||||||
(c-code "nil"))
|
(c-code "nil"))
|
||||||
((pair? exp)
|
((pair? exp)
|
||||||
(c-compile-scalars exp))
|
(c-compile-scalars exp))
|
||||||
|
((vector? exp)
|
||||||
|
(c-compile-vector exp))
|
||||||
((integer? exp)
|
((integer? exp)
|
||||||
(let ((cvar-name (mangle (gensym 'c))))
|
(let ((cvar-name (mangle (gensym 'c))))
|
||||||
(c-code/vars
|
(c-code/vars
|
||||||
|
|
|
@ -176,6 +176,8 @@ typedef struct {tag_type tag; FILE *fp; int mode;} port_type;
|
||||||
typedef struct {tag_type tag; int num_elt; object *elts;} vector_type;
|
typedef struct {tag_type tag; int num_elt; object *elts;} vector_type;
|
||||||
typedef vector_type *vector;
|
typedef vector_type *vector;
|
||||||
|
|
||||||
|
#define make_empty_vector(v) vector_type v; v.tag = vector_tag; v.num_elt = 0; v.elts = NULL;
|
||||||
|
|
||||||
/* Define cons type. */
|
/* Define cons type. */
|
||||||
|
|
||||||
typedef struct {tag_type tag; object cons_car,cons_cdr;} cons_type;
|
typedef struct {tag_type tag; object cons_car,cons_cdr;} cons_type;
|
||||||
|
|
5
test.scm
5
test.scm
|
@ -8,3 +8,8 @@
|
||||||
(write (make-vector 4 #t))
|
(write (make-vector 4 #t))
|
||||||
(write (string->list "abc"))
|
(write (string->list "abc"))
|
||||||
(write (apply append '((1) (2) (3))))
|
(write (apply append '((1) (2) (3))))
|
||||||
|
(write #(a))
|
||||||
|
(write #(1 2 3))
|
||||||
|
(write #((1) (2) (3)))
|
||||||
|
(write '#(1))
|
||||||
|
(write '#())
|
||||||
|
|
|
@ -295,6 +295,7 @@
|
||||||
(or (integer? exp)
|
(or (integer? exp)
|
||||||
(real? exp)
|
(real? exp)
|
||||||
(string? exp)
|
(string? exp)
|
||||||
|
(vector? exp)
|
||||||
(char? exp)
|
(char? exp)
|
||||||
(boolean? exp)))
|
(boolean? exp)))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue