scm_t_uint8 nlocs;
scm_t_uint8 nexts;
scm_t_uint32 len; /* the maximum index of base[] */
+ scm_t_uint32 metalen; /* well, i lie. this many bytes at the end of
+ base[] for metadata */
scm_t_uint8 base[0];
};
#define SCM_VALIDATE_OBJCODE(p,x) SCM_MAKE_VALIDATE (p, x, OBJCODE_P)
#define SCM_OBJCODE_LEN(x) (SCM_OBJCODE_DATA (x)->len)
+#define SCM_OBJCODE_META_LEN(x) (SCM_OBJCODE_DATA (x)->metalen)
+#define SCM_OBJCODE_TOTAL_LEN(x) (SCM_OBJCODE_LEN (x) + SCM_OBJCODE_META_LEN (x))
#define SCM_OBJCODE_NARGS(x) (SCM_OBJCODE_DATA (x)->nargs)
#define SCM_OBJCODE_NREST(x) (SCM_OBJCODE_DATA (x)->nrest)
#define SCM_OBJCODE_NLOCS(x) (SCM_OBJCODE_DATA (x)->nlocs)
really_make_boot_program (long nargs)
{
scm_byte_t bytes[] = {0, 0, 0, 0,
+ 0, 0, 0, 0,
0, 0, 0, 0,
scm_op_mv_call, 0, 0, 1, scm_op_make_int8_1, scm_op_halt};
- ((scm_t_uint32*)bytes)[1] = 6; /* set len in current endianness */
+ ((scm_t_uint32*)bytes)[1] = 6; /* set len in current endianness, no meta */
if (SCM_UNLIKELY (nargs > 255 || nargs < 0))
abort ();
- bytes[9] = (scm_byte_t)nargs;
+ bytes[13] = (scm_byte_t)nargs;
return scm_make_program (scm_bytecode_to_objcode (make_u8vector (bytes, sizeof(bytes))),
SCM_BOOL_F, SCM_EOL);
}
assembly-pack assembly-unpack
object->assembly assembly->object))
-;; nargs, nrest, nlocs, nexts, len
-(define *program-header-len* (+ 1 1 1 1 4))
+;; nargs, nrest, nlocs, nexts, len, metalen
+(define *program-header-len* (+ 1 1 1 1 4 4))
;; lengths are encoded in 3 bytes
(define *len-len* 3)
(+ 1 *len-len* (string-length str)))
((define ,str)
(+ 1 *len-len* (string-length str)))
- ((load-program ,nargs ,nrest ,nlocs ,nexts ,labels ,len . ,code)
- (+ 1 *program-header-len* len))
+ ((load-program ,nargs ,nrest ,nlocs ,nexts ,labels ,len ,metalen . ,code)
+ (+ 1 *program-header-len* len metalen))
((,inst . _) (guard (>= (instruction-length inst) 0))
(+ 1 (instruction-length inst)))
(else (error "unknown instruction" assembly))))
(write-byte opcode)
(pmatch asm
((load-program ,nargs ,nrest ,nlocs ,nexts
- ,labels ,length . ,code)
+ ,labels ,length ,metalength . ,code)
(write-byte nargs)
(write-byte nrest)
(write-byte nlocs)
(write-byte nexts)
(write-uint32-le length) ;; FIXME!
+ (write-uint32-le metalength) ;; FIXME!
(letrec ((i 0)
(write (lambda (x) (set! i (1+ i)) (write-byte x)))
(get-addr (lambda () i)))
(define (decode-load-program pop)
(let* ((nargs (pop)) (nrest (pop)) (nlocs (pop)) (nexts (pop))
(a (pop)) (b (pop)) (c (pop)) (d (pop))
+ (e (pop)) (f (pop)) (g (pop)) (h (pop))
(len (+ a (ash b 8) (ash c 16) (ash d 24)))
+ (metalen (+ e (ash f 8) (ash g 16) (ash h 24)))
+ (totlen (+ len metalen))
(i 0))
(define (sub-pop) ;; ...records. ha. ha.
- (let ((b (cond ((< i len) (pop))
- ((= i len) #f)
+ (let ((b (cond ((< i totlen) (pop))
+ ((= i totlen) #f)
(else (error "tried to decode too many bytes")))))
(if b (set! i (1+ i)))
b))
(let lp ((out '()))
- (cond ((> i len)
+ (cond ((> i totlen)
(error "error decoding program -- read too many bytes" out))
- ((= i len)
- `(load-program ,nargs ,nrest ,nlocs ,nexts () ,len
+ ((= i totlen)
+ `(load-program ,nargs ,nrest ,nlocs ,nexts () ,len ,metalen
,@(reverse! out)))
(else
(let ((exp (decode-bytecode sub-pop)))
(define (disassemble-load-program asm env)
(pmatch asm
- ((load-program ,nargs ,nrest ,nlocs ,nexts ,labels ,len . ,code)
+ ((load-program ,nargs ,nrest ,nlocs ,nexts ,labels ,len ,metalen . ,code)
(let ((objs (and env (assq-ref env 'objects)))
(meta (and env (assq-ref env 'meta)))
(exts (and env (assq-ref env 'exts)))
(receive (code bindings sources labels objects len)
(process-body)
(let ((prog `(load-program ,nargs ,nrest ,nlocs ,nexts ,labels
- ,len . ,code)))
+ ,len 0 . ,code)))
(cond
(toplevel?
;; toplevel bytecode isn't loaded by the vm, no way to do
(char->integer #\x)))
;; fixme: little-endian test.
- (comp-test '(load-program 3 2 1 0 '() 3 (make-int8 3) (return))
- (vector 'load-program 3 2 1 0 3 0 0 0
+ (comp-test '(load-program 3 2 1 0 '() 3 0 (make-int8 3) (return))
+ (vector 'load-program 3 2 1 0 3 0 0 0 0 0 0 0
(instruction->opcode 'make-int8) 3
(instruction->opcode 'return)))))