Skip to content

Commit

Permalink
[js] Implement partial nqp::hllizerfor (for builtin things only).
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed Jan 27, 2016
1 parent 6dc8c8c commit 6e6470b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/vm/js/QAST/Compiler.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,8 @@ class QAST::OperationsJS {
add_simple_op('bindhllsym', $T_OBJ, [$T_STR, $T_STR, $T_OBJ], :sideffects);
add_simple_op('gethllsym', $T_OBJ, [$T_STR, $T_STR]);

add_simple_op('hllizefor', $T_OBJ, [$T_OBJ, $T_STR], :ctx, :sideffects);

add_simple_op('bindcomp', $T_OBJ, [$T_STR, $T_OBJ], :sideffects);
add_simple_op('getcomp', $T_OBJ, [$T_STR], :sideffects);

Expand Down
11 changes: 3 additions & 8 deletions src/vm/js/nqp-runtime/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ var NQPException = require('./nqp-exception.js');

var reprs = require('./reprs.js');

var hll = require('./hll.js');

exports.CodeRef = CodeRef;

op.atpos = function(array, index) {
Expand Down Expand Up @@ -332,7 +334,7 @@ op.istype = function(obj, type) {
}

if (obj instanceof Array) {
if (hllConfigs.nqp && type == hllConfigs.nqp.content.get('list')) {
if (hll.hllConfigs.nqp && type == hll.hllConfigs.nqp.content.get('list')) {
return 1;
} else {
return 0;
Expand Down Expand Up @@ -435,13 +437,6 @@ op.settypehllrole = function(type, role) {
return role;
};

var hllConfigs = {};
op.sethllconfig = function(language, configHash) {
hllConfigs[language] = configHash;
/* STUB */
return configHash;
};

var sha1 = require('sha1');

op.sha1 = function(text) {
Expand Down
38 changes: 38 additions & 0 deletions src/vm/js/nqp-runtime/hll.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
var Map = require('es6-map')
var Hash = require('./hash.js');
var CodeRef = require('./code-ref.js');

var op = {};
exports.op = op;

Expand Down Expand Up @@ -29,3 +32,38 @@ op.bindcurhllsym = function(name, value) {
op.getcurhllsym = function(name) {
return op.gethllsym('nqp', name);
};

op.hllizefor = function(ctx, obj, language) {
var config = hllConfigs[language].content;
if (obj !== null && obj._STable) {
console.log("stably object");
} else {
if (obj instanceof Hash) {
var foreign_transform_hash = config.get('foreign_transform_hash');
if (foreign_transform_hash === undefined) return obj;
return foreign_transform_hash.$call(ctx, {}, obj);
} else if (obj instanceof Array) {
var foreign_transform_array = config.get('foreign_transform_array');
if (foreign_transform_array === undefined) return obj;
return foreign_transform_array.$call(ctx, {}, obj);
} else if (obj instanceof CodeRef) {
var foreign_transform_code = config.get('foreign_transform_code');
if (foreign_transform_code === undefined) return obj;
return foreign_transform_code.$call(ctx, {}, obj);
} else if (obj == null) {
var null_value = config.get('null_value');
if (null_value === undefined) return obj;
return null_value;
} else {
return obj;
}
}
};

var hllConfigs = {};
exports.hllConfigs = hllConfigs;

op.sethllconfig = function(language, configHash) {
hllConfigs[language] = configHash;
return configHash;
};

0 comments on commit 6e6470b

Please sign in to comment.