4040//
4141// C. Scott Ananian
4242// 2011-05-10 / 2020-02-12
43- define ( [ "text!bcompile.js" , "bytecode-table" ] , function make_bcompile ( bcompile_source , bytecode_table ) {
43+ define ( [ "text!bcompile.js" , "bytecode-table" , "literal-map" ] , function make_bcompile ( bcompile_source , bytecode_table , LiteralMap ) {
4444 // helper function for debugging
4545 var assert = function ( b , obj ) {
4646 if ( ! b ) {
@@ -56,40 +56,15 @@ define(["text!bcompile.js", "bytecode-table"], function make_bcompile(bcompile_s
5656 // We also need to count lexical scope nesting depth during compilation
5757 var state = {
5858 functions : [ ] ,
59- literals : [ ] ,
59+ literals : null ,
6060 // internal
6161 scope : 0 ,
6262 desugar_frame_get : ! dont_desugar_frame_get
6363 } ;
6464 // literal symbol table. Does string intern'ing too.
65- var ObjectIs = Object . is || function ( a , b ) {
66- if ( typeof ( a ) === 'number' && typeof ( b ) === 'number' ) {
67- if ( a !== a ) { return ( b !== b ) ; } // NaN
68- if ( a === 0 ) { return ( b === 0 ) && ( 1 / a === 1 / b ) ; } // +/- 0
69- }
70- return ( a === b ) ;
71- } ;
72- var literalMap = Object . create ( null ) ;
73- state . literal = function ( val ) {
74- var i , pair , key , entries ;
75- key = typeof ( val ) + ':' + val ; // very basic hash key
76- entries = literalMap [ key ] ;
77- if ( entries !== undefined ) {
78- i = 0 ;
79- while ( i < entries . length ) {
80- pair = entries [ i ] ;
81- if ( ObjectIs ( pair [ 0 ] , val ) ) { return pair [ 1 ] ; }
82- i += 1 ;
83- }
84- } else {
85- entries = [ ] ;
86- literalMap [ key ] = entries ;
87- }
88- i = this . literals . length ;
89- this . literals [ i ] = val ;
90- entries . push ( [ val , i ] ) ;
91- return i ;
92- } ;
65+ var lm = LiteralMap . New ( ) ;
66+ state . literals = lm . list ;
67+ state . literal = function ( val ) { return lm . get ( val ) ; } ;
9368 // create a function representation
9469 state . new_function = function ( nargs ) {
9570 var newf = {
@@ -755,7 +730,7 @@ define(["text!bcompile.js", "bytecode-table"], function make_bcompile(bcompile_s
755730 } ;
756731 bcompile . __module_name__ = "bcompile" ;
757732 bcompile . __module_init__ = make_bcompile ;
758- bcompile . __module_deps__ = [ "bytecode-table" ] ;
733+ bcompile . __module_deps__ = [ "bytecode-table" , "literal-map" ] ;
759734 bcompile . __module_source__ = bcompile_source ;
760735 return bcompile ;
761736} ) ;
0 commit comments