0
+ (addl (imm
(+ si wordsize)) esp)
0
(call (make-string "__check_" name))
0
-(def emit-static-type-check-routine (name mask tag)
0
+ (subl (imm (+ si wordsize)) esp))
0
+(def emit-get-tag (src dest-reg tmp-reg)
0
+ ; get the tag of the object pointed by the register src
0
+ (let cont (unique-label) ; label to the end of this routine
0
+ ; check if it is a character
0
+ (op-and (imm chmask) dest-reg)
0
+ (cmp (imm chtag) dest-reg)
0
+ ; check if it is a basic type
0
+ (op-and (imm basicmask) dest-reg)
0
+ (cmp (imm extendedtag) dest-reg) ; is it an extended type?
0
+ (movl (deref (- extendedtag) src) dest-reg) ; get extended type tag
0
+ ; special case to handle strings' tag
0
+ (movl dest-reg tmp-reg)
0
+ (op-and (imm fxmask) tmp-reg)
0
+ (cmp (imm strtag) tmp-reg)
0
+ (movl (imm extendedtag) dest-reg) ; it's a string
0
+(def emit-static-type-check-routine (name mask tag extended-p)
0
(decl-globl (make-string "__check_" name))
0
(emit-fun-header (make-string "__check_" name))
0
- (op-and (imm mask) ebx)
0
+ (op-and (imm (if extended-p basicmask mask)) ebx)
0
+ (cmp (imm (if extended-p extendedtag tag)) ebx)
0
(let err-label (unique-label)
0
+ (movl (deref (- extendedtag) eax) ebx) ; get extended object tag
0
+ (op-and (imm mask) ebx))
0
- ; clear return address to avoid confusing __print_backtrace
0
- (emit-save wordsize (imm 0))
0
+ (subl (imm wordsize) esp) ; adjust esp to be consistent with labelcall
0
+ (emit-save wordsize (imm frame-sentinel))
0
+ (emit-save 0 (imm 0)) ; won't return, no need to have a valid ret. point
0
+ (if (and extended-p mask)
0
+ (movl (imm (+ extendedtag tag)) ecx)
0
+ (shll (imm fxshift) ecx) ; make the tag a fixnum
0
+ (emit-save (next-si 0) ecx) ; pass expected tag
0
+ (emit-get-tag eax ebx ecx)
0
+ (shll (imm fxshift) ebx)
0
+ (emit-save (next-si-n 0 2) ebx) ; pass tag found
0
+ (movl (imm 2) eax) ; number of args passed
0
(def emit-extended-type-check (si env tag . mask)
0
(emit-type-check si env "vec"));vecmask vectag))
0
(def emit-is-str (si env)
0
- (emit-
extended-type-check si env strtag fxmask))
0
+ (emit-
type-check si env "str"));strtag fxmask))
0
(def emit-is-float (si env)
0
- (emit-
extended-type-check si env floattag))
0
+ (emit-
type-check si env "float"));floattag))
0
(def emit-is-sym (si env)
0
(emit-type-check si env "sym"));symbolmask symboltag))
0
(def emit-is-closure (si env)
0
(emit-type-check si env "closure"));closuremask closuretag))
0
+(def emit-is-continuation (si env)
0
+ (emit-type-check si env "continuation"))
0
(def emit-exact-arg-count-check (si env n)
0
(with (error-label (unique-label)
0
cont-label (unique-label))
0
(def emit-static-routines ()
0
; emit code for static routines
0
;(emit-thread-trampoline)
0
- ; these routines expect return adress in ecx
0
- (emit-static-type-check-routine "extended" basicmask extendedtag)
0
- (emit-static-type-check-routine "fx" fxmask fxtag)
0
- (emit-static-type-check-routine "ch" chmask chtag)
0
- (emit-static-type-check-routine "cell" cellmask celltag)
0
- (emit-static-type-check-routine "vec" vecmask vectag)
0
- (emit-static-type-check-routine "sym" symbolmask symboltag)
0
- (emit-static-type-check-routine "closure" closuremask closuretag)
0
- ; function call (with exactly one arg) expects:
0
- ; (emit-fun-header funcall-lbl)
0
+ (emit-static-type-check-routine "fx" fxmask fxtag nil)
0
+ (emit-static-type-check-routine "ch" chmask chtag nil)
0
+ (emit-static-type-check-routine "cell" cellmask celltag nil)
0
+ (emit-static-type-check-routine "vec" vecmask vectag nil)
0
+ (emit-static-type-check-routine "sym" symbolmask symboltag nil)
0
+ (emit-static-type-check-routine "closure" closuremask closuretag nil)
0
+ (emit-static-type-check-routine "str" fxmask strtag t)
0
+ (emit-static-type-check-routine "float" nil floattag t)
0
+ (emit-static-type-check-routine "continuation" nil continuation-tag t))
0
;(emit-static-routines)
0
(install-primop '__restore-continuation
0
(fn (si env cont-expr value)
0
(emit-expr si env cont-expr)
0
- (emit-
extended-type-check si env continuation-tag)
0
+ (emit-
is-continuation si env)
0
(emit-expr (next-si si) env value)
0
(movl eax edi) ; save value to return from continuation
Comments
No one has commented yet.