40
40
//
41
41
// C. Scott Ananian
42
42
// 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 ) {
44
44
// helper function for debugging
45
45
var assert = function ( b , obj ) {
46
46
if ( ! b ) {
@@ -56,40 +56,15 @@ define(["text!bcompile.js", "bytecode-table"], function make_bcompile(bcompile_s
56
56
// We also need to count lexical scope nesting depth during compilation
57
57
var state = {
58
58
functions : [ ] ,
59
- literals : [ ] ,
59
+ literals : null ,
60
60
// internal
61
61
scope : 0 ,
62
62
desugar_frame_get : ! dont_desugar_frame_get
63
63
} ;
64
64
// 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 ) ; } ;
93
68
// create a function representation
94
69
state . new_function = function ( nargs ) {
95
70
var newf = {
@@ -755,7 +730,7 @@ define(["text!bcompile.js", "bytecode-table"], function make_bcompile(bcompile_s
755
730
} ;
756
731
bcompile . __module_name__ = "bcompile" ;
757
732
bcompile . __module_init__ = make_bcompile ;
758
- bcompile . __module_deps__ = [ "bytecode-table" ] ;
733
+ bcompile . __module_deps__ = [ "bytecode-table" , "literal-map" ] ;
759
734
bcompile . __module_source__ = bcompile_source ;
760
735
return bcompile ;
761
736
} ) ;
0 commit comments