Skip to content

Commit

Permalink
Create skulpt_shim.js
Browse files Browse the repository at this point in the history
  • Loading branch information
wvanheemstra authored Nov 7, 2024
1 parent 1658f0f commit 9da4972
Showing 1 changed file with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
var Sk = {};

Sk.exportSymbol = (name, module) => {
let parts = name.split(".");
let submodule = Sk;
let i;
for (i = 1; i < parts.length-1; i++) {
if (!(parts[i] in submodule)) {
submodule[parts[i]] = {};
}
}
submodule[parts[i]] = module;
};
Sk.configure = (options) => {};
Sk.builtin = {
SyntaxError: function(message, filename, lineno, position) {
this.message = message;
this.filename = filename;
this.lineno = lineno;
this.position = position;
},
str: function(x) {
if (x instanceof Sk.builtin.str) {
return x;
}
if (!(this instanceof Sk.builtin.str)) {
return new Sk.builtin.str(x);
}
this.v = x;
},
int_: function(n) {
this.v = n;
},
float_: function(n) {
this.v = n;
},
bool: {
"true$": { v: true },
"false$": { v: true },
},
none: { "none$": { v: null }}
};
Sk.builtin.int_.threshold$ = Infinity;
Sk.builtin.str.prototype.sq$concat = function(other) {
return new Sk.builtin.str(this.v + other.v);
};
Sk.__future__ = {
print_function: true,
division: true,
absolute_import: null,
unicode_literals: true,
// skulpt specific
python3: true,
set_repr: true,
class_repr: true,
inherit_from_object: true,
super_args: true,
octal_number_literal: true,
bankers_rounding: true,
python_version: true,
dunder_next: true,
dunder_round: true,
list_clear: true,
exceptions: true,
no_long_type: true,
ceil_floor_int: true,
l_suffix: false,
silent_octal_literal: false
};
Sk.asserts = {
assert: (condition) => { if (!condition) { console.error(condition)}}
};
Sk.ffi = {
remapToJs: (data) => {
return data.v;
}
};

0 comments on commit 9da4972

Please sign in to comment.