Skip to content

Commit

Permalink
Add support for absent object to universal backend
Browse files Browse the repository at this point in the history
  • Loading branch information
feeley committed Feb 26, 2014
1 parent 831c03a commit 83d16ec
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
41 changes: 37 additions & 4 deletions gsc/_t-univ.scm
Expand Up @@ -25,6 +25,9 @@
(define (univ-void-representation ctx)
'natural)

(define (univ-absent-representation ctx)
'class)

(define (univ-boolean-representation ctx)
'natural)

Expand Down Expand Up @@ -581,6 +584,9 @@
(define-macro (^void)
`(univ-emit-void ctx))

(define-macro (^absent)
`(univ-emit-absent ctx))

(define-macro (^bool val)
`(univ-emit-bool ctx ,val))

Expand Down Expand Up @@ -2369,6 +2375,9 @@
((void-object? obj)
(^void))

((absent-object? obj)
(^absent))

((undefined? obj)
(univ-undefined ctx))

Expand All @@ -2385,6 +2394,9 @@
(map (lambda (x) (^obj x))
(vector->list obj)))))

;; ((structure-object? obj)
;; ...)

(else
(^ "UNIMPLEMENTED_OBJECT("
(object->string obj)
Expand Down Expand Up @@ -2701,6 +2713,16 @@ EOF
(^global-var (^prefix "void_val"))
(^new (^prefix (univ-use-rtlib ctx 'Void))))))

((Absent)
(^ (^class-declaration
(^prefix "Absent")
'()
'())
"\n"
(^var-declaration
(^global-var (^prefix "absent_val"))
(^new (^prefix (univ-use-rtlib ctx 'Absent))))))

((Boolean)
(^class-declaration
(^prefix "Boolean")
Expand Down Expand Up @@ -5312,6 +5334,19 @@ function Gambit_trampoline(pc) {
(compiler-internal-error
"univ-emit-void, unknown target"))))))

(define (univ-emit-absent ctx)
(case (univ-absent-representation ctx)

((class)
(let ((absent-val (^global-var (^prefix "absent_val"))))
(univ-use-rtlib ctx 'Absent)
(use-global ctx absent-val)
absent-val))

(else
(compiler-internal-error
"univ-emit-absent, unknown target"))))

(define (univ-emit-bool ctx val)
(case (target-name (ctx-target ctx))

Expand Down Expand Up @@ -7339,18 +7374,16 @@ tanh
(lambda (ctx arg1 arg2) (^>= arg1 arg2))
univ-emit-fixnum-unbox))

(univ-define-prim "##fx->char" #f
(univ-define-prim "##integer->char" #f
(make-translated-operand-generator
(lambda (ctx return arg)
(return (^char-box (^chr-fromint (^fixnum-unbox arg)))))))

(univ-define-prim "##fx<-char" #f
(univ-define-prim "##char->integer" #f
(make-translated-operand-generator
(lambda (ctx return arg)
(return (^fixnum-box (^chr-toint (^char-unbox arg)))))))

;;TODO: ("##fixnum->char" (1) #f () 0 char extended)
;;TODO: ("##char->fixnum" (1) #f () 0 fixnum extended)
;;TODO: ("##flonum->fixnum" (1) #f () 0 fixnum extended)
;;TODO: ("##fixnum->flonum" (1) #f () 0 real extended)
;;TODO: ("##fixnum->flonum-exact?" (1) #f () 0 boolean extended)
Expand Down
4 changes: 2 additions & 2 deletions include/stamp.h
Expand Up @@ -2,5 +2,5 @@
* Time stamp of last source code repository commit.
*/

#define ___STAMP_YMD 20140225
#define ___STAMP_HMS 41118
#define ___STAMP_YMD 20140226
#define ___STAMP_HMS 31140

0 comments on commit 83d16ec

Please sign in to comment.