File tree Expand file tree Collapse file tree 7 files changed +22
-14
lines changed Expand file tree Collapse file tree 7 files changed +22
-14
lines changed Original file line number Diff line number Diff line change 1
1
You need to install webpack.
2
- And then using npm install src/vm/js/nqp-loader and src/vm/js/nqp-runtime and install empty-module from npm.
2
+ And then using npm install src/vm/js/nqp-loader and src/vm/js/nqp-runtime and install empty-module, browserify-bignum from npm.
3
3
For increased awesomeness we use webpack-dev-server and webpack-reload-plugin so you need to install those.
4
4
5
5
Original file line number Diff line number Diff line change @@ -26,4 +26,4 @@ sub setup() {
26
26
27
27
set-setup(& setup );
28
28
29
- nqp :: say (" Hello Fancy Browser World" );
29
+ say (" Hello Fancy Browser World" );
Original file line number Diff line number Diff line change @@ -7,11 +7,11 @@ module.exports = {
7
7
alias : {
8
8
"ffi" : "empty-module" ,
9
9
"fs-ext" : "empty-module" ,
10
- "bignum" : "empty-module" ,
11
10
"ffi" : "empty-module" ,
12
11
"ref" : "empty-module" ,
13
12
"nqp-js-io" : "empty-module" ,
14
- "sleep" : "empty-module"
13
+ "sleep" : "empty-module" ,
14
+ "bignum" : "browserify-bignum"
15
15
}
16
16
} ,
17
17
output : {
Original file line number Diff line number Diff line change @@ -1097,6 +1097,11 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
1097
1097
}
1098
1098
}
1099
1099
1100
+ my sub loadable ($ name ) {
1101
+ # workaround for webpack
1102
+ quote_string($ name ) ~ " , function() \{ return require({ quote_string($ name )} )\} " ;
1103
+ }
1104
+
1100
1105
multi method as_js (QAST ::CompUnit $ node , : $ want , : $ cps ) {
1101
1106
# Should have a single child which is the outer block.
1102
1107
if + @ ($ node ) != 1 || ! nqp ::istype($ node [0 ], QAST ::Block) {
@@ -1124,13 +1129,13 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
1124
1129
if nqp ::istype($ op , QAST ::Op) && $ op . op eq ' forceouterctx' {
1125
1130
$ * SETTING_NAME := $ op [1 ][1 ]. value ;
1126
1131
$ * SETTING_TARGET := $ op [0 ]. value ;
1127
- $ pre := $ pre ~ " nqp.load_setting({ quote_string ($ * SETTING_NAME )} );\n " ;
1132
+ $ pre := $ pre ~ " nqp.load_setting({ loadable ($ * SETTING_NAME ~ ' .setting ' )} );\n " ;
1128
1133
# HACK to get nqp::sprintf to work
1129
1134
$ pre := $ pre ~ " require('sprintf');\n " ;
1130
1135
} elsif nqp ::istype($ op , QAST ::Op)
1131
1136
&& $ op . op eq ' callmethod'
1132
1137
&& $ op . name eq ' load_module' {
1133
- $ pre := $ pre ~ " nqp.load_module({ quote_string ($ op [1 ]. value )} );\n " ;
1138
+ $ pre := $ pre ~ " nqp.load_module({ loadable ($ op [1 ]. value )} );\n " ;
1134
1139
} else {
1135
1140
# self.log($op.dump);
1136
1141
}
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ module.exports = function(source) {
31
31
var tmp = temp . openSync ( ) ;
32
32
fs . writeFileSync ( tmp . path , source ) ;
33
33
34
- var command = "cd " + path + ";.//nqp-js --setting=NULL -- target=js --source-map '" + tmp . path + "'" ;
34
+ var command = "cd " + path + ";.//nqp-js --target=js --source-map '" + tmp . path + "'" ;
35
35
36
36
37
37
var result = child_process . execSync ( command , { encoding :"utf8" } ) ;
Original file line number Diff line number Diff line change @@ -595,10 +595,11 @@ BinaryCursor.prototype.deserialize = function(sc) {
595
595
596
596
var declareCuids = 'var ' + cuids . join ( ',' ) + ';\n' ;
597
597
598
- var prelude = "var nqp = require('nqp-runtime') ;\n" ;
598
+ var prelude = ";\n" ;
599
599
if ( code ) {
600
600
/* TODO reduce accidental poisoning */
601
601
/* TODO make cuids be in scope */
602
+ var nqp = require ( 'nqp-runtime' ) ;
602
603
eval ( prelude + declareCuids + code ) ;
603
604
}
604
605
Original file line number Diff line number Diff line change @@ -65,17 +65,19 @@ function saveCtx(where, block) {
65
65
saveCtxAs = old ;
66
66
}
67
67
68
- exports . load_setting = function ( settingName ) {
69
- exports . load_module ( settingName + '.setting' ) ;
70
- } ;
71
-
72
- exports . load_module = function ( module ) {
68
+ exports . load_module = function ( module , helper ) {
73
69
saveCtx ( module , function ( ) {
74
70
module = module . replace ( / : : / g, '/' ) ;
75
- require ( module ) ;
71
+ if ( helper ) {
72
+ helper ( ) ;
73
+ } else {
74
+ require ( module ) ;
75
+ }
76
76
} ) ;
77
77
} ;
78
78
79
+ exports . load_setting = exports . load_module ;
80
+
79
81
exports . setup_setting = function ( settingName ) {
80
82
return savedCtxs [ settingName + '.setting' ] ;
81
83
} ;
You can’t perform that action at this time.
0 commit comments