-
Notifications
You must be signed in to change notification settings - Fork 0
/
emulator.js
89 lines (88 loc) · 2.36 KB
/
emulator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
{
if(window['c']===void 0)window['c']=Object.create(null);
function isset(o){return void 0!==o;}
window['Scope']=function(scope){
var self = Object.create(null);
self.vars=isset(scope) ? scope.vars : new Array();//another ternary operator FOR THE WIN
self['getVar']=function(varname){
if(isset(self.vars[varname]))return self.vars[varname];
console.err('Something was looking for variable ' + varname + ", and it didn't exist!");
return false;
};
return self;
}
window['Variable']=function(data){
var self = Object.create(null);
self.data=data;
self.defaultNull=false;
if(typeof data === 'string')
self.defaultNull='';
else if(typeof data === 'number')
self.defaultNull=0;
self['getType']=function(){
return typeof(self.data);
};
self['setTo']=function(data){
self.data=data;
};
self['getVal']=function(){
return isset(self.data) ? self.data : self.defaultNull;
};
return self;
}
window['c']['emulator']=function(){
var self = Object.create(null);
self.scope=Scope();
self['emulate']=function(arr){
for(var i=0;i<arr['length'];i++){
if(isset(arr[i]) && isset(arr[i]['htmlText'])){
console.log([arr[i], arr[i]['htmlText']]);
var r=window['Blocks']['evaluate'](arr[i],arr[i]['htmlText'],arr,i);
if(r==="cancel-execution")return;
//maybe add some other stuff here?
}
}
};
self['getShiftedEmulatable']=function(emulatable, shift){
var arr={};
for(var i=shift;i<emulatable['length'];++i){
arr[i-shift]=emulatable[i];
}
return arr;
};
self['requestVar']=function(varname){
return window['Variable'](self.scope['getVar'](varname));
};
self['getVars']=function(){
return self.scope.vars;
};
self['emulateStack']=function(stackName){
var stack=window['Stack']['emulatable'](window['Stack']['call'](stackName));
console.log('emulating');
self['emulate'](stack);
};
self['attempt']=function(fn){
if(typeof fn === 'function'){
return fn();
}else if(isset(fn)){
return fn;
}else{
return null;
}
};
//TODO: finish
self['regexitize']=function(text, regex){
var obj=new RegExp();
return null;
};
return self;
};
//new emulator that converts js into
window['c']['_emulator']=function() {
var self = Object.create(null);
self['emulate']=function() {
};
return self;
};
}
if(logging)console.log('Emulator initiated');