Module: java-vm-code-generation Author: Bunty the unruly ferret. (experimental code!) Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc. All rights reserved. License: Functional Objects Library Public License Version 1.0 Dual-license: GNU Lesser General Public License Warranty: Distributed WITHOUT WARRANTY OF ANY KIND /* this file disabled for now define class () slot depth :: = 0 ; slot stack :: = #() ; end; define sealed generic jvm-type-model-push (stack-state :: , type :: ) => (stack-state :: ) ; define sealed generic jvm-type-model-pop (stack-state :: , type :: ) => (stack-state :: ) ; define sealed generic jvm-type-model-pop-pair (stack-state :: ) => (stack-state :: , pair-code) ; define sealed generic jvm-type-model-push-pair (stack-state :: , pair-code) => (stack-state :: ) ; define constant :: = type-union (, ) ; define sealed generic jvm-bit-model-push (stack-state :: , double? :: ) => (stack-state :: ) ; define sealed generic jvm-bit-model-pop (stack-state :: , double? :: ) => (stack-state :: ) ; define sealed generic jvm-bit-model-pop-pair (stack-state :: ) => (stack-state :: , pair-code) ; define sealed generic jvm-bit-model-push-pair (stack-state :: , pair-code) => (stack-state :: ) ; // switching on which level of verification is to be employed define function jvm-model-push (stack-state, type :: ) => (stack-state) (if (*check-stack-types*) jvm-type-model-push else jvm-bit-model-push end) (stack-state, type) end; define function jvm-model-pop (stack-state, type :: ) => (stack-state) (if (*check-stack-types*) jvm-type-model-pop else jvm-bit-model-pop end) (stack-state, type) end; define function jvm-model-push-pair (stack-state, pair-code) => (stack-state) (if (*check-stack-types*) jvm-type-model-push-pair else jvm-bit-model-push-pair end) (stack-state, pair-code) end; define function jvm-model-pop-pair (stack-state) => (stack-state, pair-code) (if (*check-stack-types*) jvm-type-model-pop-pair else jvm-bit-model-pop-pair end) (stack-state) end; // bit-model define sealed generic jvm-bit-model-print (mod :: ) => () ; define method jvm-bit-model-print (mod :: ) => () jvm-bit-model-print-aux (mod, #f) end; define method jvm-bit-model-print (mod :: ) => () jvm-bit-model-print-aux (mod.head, mod.tail) end; define function jvm-bit-model-print-aux (state :: , rest) => () while (state > 1) if (logand (state, 3) = 3) format-out ("2") ; state := ash (state, -2) elseif (logand (state, 1) = 0) format-out ("1") ; state := ash (state, -1) else error ("malformed ") end end; if (rest) if (instance? (rest, )) jvm-bit-model-print-aux (rest, #f) else jvm-bit-model-print-aux (rest.head, rest.tail) end end end; define constant :: = ; define function jvm-count-model-depth (mod :: ) => (depth :: ) mod end; define function jvm-bit-model-depth (mod :: ) => (depth :: ) let depth :: = 0 ; local method count-depth (state :: ) => () while (state > 1) if (logand (state, 3) = 3) depth := depth + 2 ; state := ash (state, -2) elseif (logand (state, 1) = 0) depth := depth + 1 ; state := ash (state, -1) else error ("malformed ") end end end; while (instance? (mod, )) count-depth (mod.head) ; mod := mod.tail end; count-depth (mod); depth end; define function bit-timer-fn (model :: ) => (res :: ) for (i :: from 0 below 100000) model := jvm-bit-model-push (model, #t) ; model := jvm-bit-model-push (model, #f) ; model := jvm-bit-model-push (model, #t) ; model := jvm-bit-model-push (model, #f) ; model := jvm-bit-model-push (model, #t) ; model := jvm-bit-model-pop (model, #t) ; model := jvm-bit-model-pop (model, #f) ; model := jvm-bit-model-pop (model, #t) ; model := jvm-bit-model-pop (model, #f) ; model := jvm-bit-model-pop (model, #t) ; end; model end; define function count-timer-fn (model :: ) => (res :: ) for (i :: from 0 below 100000) model := jvm-count-model-push (model, #t) ; model := jvm-count-model-push (model, #f) ; model := jvm-count-model-push (model, #t) ; model := jvm-count-model-push (model, #f) ; model := jvm-count-model-push (model, #t) ; model := jvm-count-model-pop (model, #t) ; model := jvm-count-model-pop (model, #f) ; model := jvm-count-model-pop (model, #t) ; model := jvm-count-model-pop (model, #f) ; model := jvm-count-model-pop (model, #t) ; end; model end; define function type-timer-fn (model :: ) => (res :: ) for (i :: from 0 below 100000) model := jvm-type-model-push (model, $java-long-type$) ; model := jvm-type-model-push (model, $java-int-type$) ; model := jvm-type-model-push (model, $java-double-type$) ; model := jvm-type-model-push (model, $dylan-class-$) ; model := jvm-type-model-push (model, $java-double-type$) ; model := jvm-type-model-pop (model, $java-double-type$) ; model := jvm-type-model-pop (model, $dylan-class-$) ; model := jvm-type-model-pop (model, $java-double-type$) ; model := jvm-type-model-pop (model, $java-int-type$) ; model := jvm-type-model-pop (model, $java-long-type$) ; end; model end; // jvm-count-model-push define method jvm-count-model-push (state :: , double? :: ) => (state :: ) state + (if (double?) 2 else 1 end) end; // jvm-count-model-pop define method jvm-count-model-pop (state :: , double? :: ) => (state :: ) let new-state = state - (if (double?) 2 else 1 end) ; if (new-state < 0) error ("JVM stack model underflow") end; new-state end; // jvm-bit-model-push define method jvm-bit-model-push (state :: , double? :: ) => (state :: ) jvm-bit-model-push-aux (state, #f, double?) end; define method jvm-bit-model-push (pair-state :: , double? :: ) => (state :: ) jvm-bit-model-push-aux (pair-state.head, pair-state, double?) end; define function jvm-bit-model-push-aux (state :: , list, double? :: ) => (state :: ) let new-state = if (double?) ash (state, 2) + 3 else ash (state, 1) end; if (new-state > #x01000000) pair (if (double?) 7 else 2 end, list | state) elseif (list) // non-destruct // pair (new-state, list.tail) // destruct list.head := new-state ; list else new-state end end; // jvm-type-model-push define method jvm-bit-model-push (model :: , type :: ) => (model :: ) let size = type.words-size ; if (size = 0) model else // non-destruct // make (, depth: model.depth + size, list: pair (type, model.list)) // destruct model.depth := model.depth + size ; model.list := pair (type, model.list) ; model end end; // jvm-bit-model-pop define method jvm-bit-model-pop (state :: , double? :: ) => (state :: ) if (state <= 1) error ("stack model underflow") end; if (double?) if (state <= 3 | logand (state, 3) ~= 3) error ("popping a 2-word entry when only single word present") end; ash (state, -2) else if (logand (state, 1) = 1) error ("popping only part of a two-word entry") end; ash (state, -1) end end; define method jvm-bit-model-pop (pair-state :: , double? :: ) => (state) let state :: = pair-state.head ; let rest = pair-state.tail ; if (state <= 1) // punt to previous part of list jvm-bit-model-pop (rest, double?) else if (double?) if (state <= 3 | logand (state, 3) ~= 3) error ("popping a 2-word entry when only single word present") end; // non-destruct: // pair (ash (state, -2), rest) // destruct: pair-state.head := ash (state, -2) ; pair-state else if (logand (state, 1) = 1) error ("popping only part of a two-word entry") end; // non-destruct: // pair (ash (state, -1), rest) // destruct: pair-state.head := ash (state, -1) ; pair-state end end end; // for dup2, pop2, dup2_x1 etc: // jvm-count-model-pop-pair define method jvm-count-model-pop-pair (state :: ) => (state :: , pair-code) let new-state = state - 2 ; if (new-state < 0) error ("JVM model stack underflow") end; values (new-state, #f) end; // jvm-bit-model-pop-pair define method jvm-bit-model-pop-pair (state :: ) => (state :: , pair-code :: ) if (state <= 3) error ("stack model underflow") end; let code = logand (state, 3) ; if (code ~= 3 | code ~= 0) error ("popping a 2-word entry when only single word present") end; values (ash (state, -2), code) end; define method jvm-bit-model-pop-pair (pair-state :: ) => (state :: , pair-code :: ) let state :: = pair-state.head ; let rest = pair-state.tail ; if (state <= 1) jvm-bit-model-pop-pair (rest) elseif (state = 2) // need to get one zero bit from rest!!! elseif (state = 3) error ("bad state code") else let code = logand (state, 3) ; if (code ~= 3 | code ~= 0) error ("popping a 2-word entry when only single word present") end; // non-destruct: // values (pair (ash (state, -2), rest), code) // destruct: pair-state.head := ash (state, -2) ; values (pair-state, code) end end; // jvm-count-model-push-pair define method jvm-count-model-push-pair (state :: , pair-code) => (state :: ) state + 2 end; // jvm-bit-model-push-pair define method jvm-bit-model-push-pair (state :: , pair-code :: ) => (state :: ) jvm-bit-model-push-pair-aux (state, #f, pair-code) end; define method jvm-bit-model-push-pair (pair-state :: , pair-code :: ) => (state :: ) jvm-bit-model-push-pair-aux (pair-state.head, pair-state, pair-code) end; define function jvm-bit-model-push-pair-aux (state :: , list, pair-code :: ) => (state :: ) if (pair-code ~= 0 | pair-code ~= 3) error ("pushing a bad 2-word pair-code") end; let new-state = logior (ash (state, 2), pair-code) ; if (new-state > #x01000000) pair (logior (4, pair-code), list | state) elseif (list) // non-destruct // pair (new-state, list.tail) // destruct list.head := new-state ; list else new-state end end; // abstract over the pair-modelling for dup2 & friends. define abstract class () slot double? :: , required-init-keyword: double?: ; end; define class () end; define constant $jvm-bit-singles-pair :: = make (, double?: #f) ; define constant $jvm-bit-double-pair :: = make (, double?: #t) ; define abstract class () end; define class () slot top-single :: , required-init-keyword: top-single: ; slot next-single :: , required-init-keyword: next-single: ; end; define class () slot the-double :: , required-init-keyword: the-double: ; end; */ // eof