@@ -101,6 +101,11 @@ define(['./parse', './bcompile', './bytecode-table', './top-level', './str-escap
101101 } ) + '"' ;
102102 } ;
103103
104+ var luaName = function ( bc ) {
105+ var name = bc . name . toUpperCase ( ) ;
106+ if ( name === '2DUP' ) { return 'DUP2' ; }
107+ return name ;
108+ } ;
104109 var pad = function ( s , width ) {
105110 if ( width === undefined ) { width = 10 ; }
106111 while ( s . length < width ) { s += ' ' ; }
@@ -111,6 +116,7 @@ define(['./parse', './bcompile', './bytecode-table', './top-level', './str-escap
111116 console . log ( '-- generated by TurtleScript write-lua-bytecode.js' ) ;
112117 console . log ( 'local jsval = require("luaturtle.jsval")' ) ;
113118 console . log ( 'local ifunc = require("luaturtle.ifunc")' ) ;
119+ console . log ( 'local ops = require("luaturtle.ops")' ) ;
114120 console . log ( '' ) ;
115121 console . log ( 'local startup = {}' ) ;
116122 console . log ( '' ) ;
@@ -137,14 +143,15 @@ define(['./parse', './bcompile', './bytecode-table', './top-level', './str-escap
137143 var pc = j ;
138144 var bc = bytecode_table . for_num ( f . bytecode [ j ] ) ;
139145 var a = f . bytecode . slice ( j , j += bc . args + 1 ) ;
140- a = a . map ( function ( b ) {
146+ a = a . map ( function ( b , i ) {
147+ if ( i === 0 ) { return 'ops.' + luaName ( bc ) ; }
141148 if ( typeof ( b ) !== 'number' ) { b = b . label ; }
142149 return '' + b ;
143150 } ) ;
144151 var b = a . slice ( 1 ) ;
145152 a = a . join ( ', ' ) + ( ( j < f . bytecode . length ) ? ',' : '' ) ;
146153 b = bc . name + ( b . length ? ( '(' + b . join ( ',' ) + ')' ) : '' ) ;
147- console . log ( ' ' + pad ( a ) + '-- ' + pc + ': ' + b ) ;
154+ console . log ( ' ' + pad ( a , 25 ) + '-- ' + pc + ': ' + b ) ;
148155 }
149156 console . log ( ' }' ) ;
150157 console . log ( ' }' + comma ( i ) ) ;
0 commit comments