Verified Commit 7fcc132f authored by Camil Staps's avatar Camil Staps 🚀

Update SVGEditor to the new JS interface; OnClick works now

parent 9eb486d5
......@@ -3,9 +3,12 @@ Global
ProjectRoot: .
Target: iTasks
Exec: {Project}/OnClick.exe
ByteCode: {Project}/OnClick.bc
CodeGen
CheckStacks: False
CheckIndexes: True
OptimiseABC: True
GenerateByteCode: True
Application
HeapSize: 134217728
StackSize: 512000
......@@ -25,7 +28,7 @@ Global
Stack: False
Dynamics: True
GenericFusion: False
DescExL: False
DescExL: True
Output
Output: ShowConstructors
Font: Monaco
......@@ -40,6 +43,9 @@ Global
ResourceSource:
GenerateDLL: False
ExportedNames:
StripByteCode: True
KeepByteCodeSymbols: True
PrelinkByteCode: True
Paths
Path: {Project}
Precompile:
......
definition module iTasks.UI.JS.Interface
from StdMaybe import :: Maybe
from StdOverloaded import class toString
:: *JSWorld
......@@ -18,10 +19,12 @@ jsMakeCleanReference :: a -> JSVal b
jsGetCleanReference :: !(JSVal a) !*JSWorld -> *(!Maybe b, !*JSWorld)
jsIsUndefined :: !(JSVal a) -> Bool
jsIsNull :: !(JSVal a) -> Bool
jsValToInt :: !(JSVal a) -> Maybe Int
jsValToBool :: !(JSVal a) -> Maybe Bool
jsValToString :: !(JSVal a) -> Maybe String
jsValToReal :: !(JSVal a) -> Maybe Real
/**
* Access properties of a JavaScript value.
......@@ -60,6 +63,8 @@ jsWrapFun :: !({!JSVal a} *JSWorld -> *JSWorld) !*JSWorld -> *(!JSFun f, !*JSWor
wrapInitUIFunction :: !((JSObj ()) *JSWorld -> *JSWorld) -> {!JSVal a} -> *JSWorld -> *JSWorld
jsDeserializeGraph :: !String !*JSWorld -> *(!.a, !*JSWorld)
/**
* Load external CSS stylesheet by its URL.
*
......@@ -74,3 +79,5 @@ addCSSFromUrl :: !String !*JSWorld -> *JSWorld
* @param An optional callback function for when the script has loaded.
*/
addJSFromUrl :: !String !(Maybe (JSFun a)) !*JSWorld -> *JSWorld
jsTrace :: !a .b -> .b | toString a
......@@ -55,6 +55,9 @@ where
jsIsUndefined :: !(JSVal a) -> Bool
jsIsUndefined v = v=:JSUndefined
jsIsNull :: !(JSVal a) -> Bool
jsIsNull v = v=:JSNull
jsValToInt :: !(JSVal a) -> Maybe Int
jsValToInt v = case v of
JSInt i -> Just i
......@@ -80,6 +83,13 @@ jsValToString v = case v of
JSBool b -> Just (if b "true" "false")
_ -> Nothing
// TODO add proper support for Reals
jsValToReal :: !(JSVal a) -> Maybe Real
jsValToReal v = case v of
JSInt i -> Just (toReal i)
JSString s -> Just (toReal s)
_ -> Nothing
instance toJS Int where toJS i = JSInt i
instance toJS Bool where toJS b = JSBool b
instance toJS String where toJS s = JSString s
......@@ -164,6 +174,14 @@ wrapInitUIFunction f = \args
-> f r
-> abort "failed to get iTasks component from JavaScript\n"
jsDeserializeGraph :: !String !*JSWorld -> *(!.a, !*JSWorld)
jsDeserializeGraph s w = (deserialize s, w)
where
deserialize :: !String -> .a
deserialize _ = code {
instruction 5
}
addCSSFromUrl :: !String !*JSWorld -> *JSWorld
addCSSFromUrl css w = case add_css css of
True -> w
......@@ -190,6 +208,10 @@ where
pushB TRUE
}
jsTrace :: !a .b -> .b | toString a
jsTrace s x = case eval_js ("console.log('"+++toString s+++"')") of
True -> x
eval_js :: !String -> Bool
eval_js s = code {
instruction 1
......
"use strict";
var MAX_INSTRUCTIONS=-1;
var ABC_DEBUG=false;
function SharedCleanValue(index) {
return {
......@@ -52,8 +52,8 @@ const abc_interpreter={
var new_hp=abc_interpreter.util.instance.exports.copy_from_string(
unused_semispace,
graph.length/2,
abc_interpreter.interpreter.instance.exports.get_asp(),
abc_interpreter.interpreter.instance.exports.get_bsp(),
abc_interpreter.interpreter.instance.exports.get_asp()+8,
abc_interpreter.interpreter.instance.exports.get_bsp()-8,
old_hp,
abc_interpreter.code_offset*8);
abc_interpreter.interpreter.instance.exports.set_hp(new_hp);
......@@ -84,7 +84,6 @@ const abc_interpreter={
copy_js_to_clean: function (values, store_ptrs, hp, hp_free) {
for (var i=0; i<values.length; i++) {
//console.log('copy',values[i]);
if (values[i]===null) {
abc_interpreter.memory_array[store_ptrs/4]=hp;
abc_interpreter.memory_array[hp/4]=26*8+2; // INT
......@@ -233,19 +232,13 @@ abc_interpreter.loading_promise=fetch('js/app.pbc').then(function(resp){
abc_interpreter.shared_clean_values[index]=new_location;
},
debug: function(what,a,b,c) {
if (!ABC_DEBUG)
return;
switch (what) {
case 0:
console.log('loop',a,'/',b,'; hp at',c);
break;
case 1:
console.log('desc',a);
break;
case 2:
console.log('hnf, arity',a);
break;
case 3:
console.log('thunk, arity',a);
break;
case 0: console.log('loop',a,'/',b,'; hp at',c); break;
case 1: console.log('desc',a); break;
case 2: console.log('hnf, arity',a); break;
case 3: console.log('thunk, arity',a); break;
}
}
}}
......@@ -260,7 +253,8 @@ abc_interpreter.loading_promise=fetch('js/app.pbc').then(function(resp){
debug_instr: function (addr, instr) {
if (MAX_INSTRUCTIONS-- == 0)
throw 'MAX_INSTRUCTIONS ran out';
console.log(addr,(addr/8-abc_interpreter.code_offset)+'\t'+abc_instructions[instr]);
if (ABC_DEBUG)
console.log(addr/8-abc_interpreter.code_offset,abc_instructions[instr]);
},
handle_illegal_instr: function (pc, instr, asp, bsp, csp, hp, hp_free) {
if (abc_instructions[instr]=='instruction') {
......@@ -270,12 +264,14 @@ abc_interpreter.loading_promise=fetch('js/app.pbc').then(function(resp){
return 0;
case 1: /* iTasks.UI.JS.Interface: eval_js */
var string=abc_interpreter.get_clean_string(abc_interpreter.memory_array[asp/4]);
console.log('eval',string);
if (ABC_DEBUG)
console.log('eval',string);
Function(string)();
break;
case 2:
var string=abc_interpreter.get_clean_string(abc_interpreter.memory_array[asp/4]);
console.log('eval',string);
if (ABC_DEBUG)
console.log('eval',string);
var result=eval('('+string+')'); // the parentheses are needed for {}, for instance
var copied=abc_interpreter.copy_js_to_clean([result], asp, hp, hp_free);
abc_interpreter.interpreter.instance.exports.set_hp(copied.hp);
......@@ -289,6 +285,11 @@ abc_interpreter.loading_promise=fetch('js/app.pbc').then(function(resp){
var index=abc_interpreter.memory_array[bsp/4];
abc_interpreter.memory_array[asp/4]=abc_interpreter.shared_clean_values[index];
break;
case 5: /* iTasks.UI.JS.Interface: deserialize */
var string=abc_interpreter.get_clean_string(abc_interpreter.memory_array[asp/4]);
var shared_clean_value=abc_interpreter.deserialize(string);
abc_interpreter.memory_array[asp/4]=abc_interpreter.shared_clean_values[shared_clean_value.shared_clean_value_index];
break;
case 10: /* iTasks.UI.JS.Interface: add CSS */
var url=abc_interpreter.get_clean_string(abc_interpreter.memory_array[asp/4]);
var css=document.createElement('link');
......@@ -377,6 +378,23 @@ abc_interpreter.loading_promise=fetch('js/app.pbc').then(function(resp){
expR: Math.exp,
lnR: Math.log,
log10R: Math.log10,
RtoAC: function (dest, v) {
v=Number(0+v).toLocaleString(
['en-US'],
{
useGrouping: false,
maximumSignificantDigits: 15,
}
);
abc_interpreter.memory_array[dest/4]=6*8+2; // __STRING__
abc_interpreter.memory_array[dest/4+1]=0;
abc_interpreter.memory_array[dest/4+2]=v.length;
abc_interpreter.memory_array[dest/4+3]=0;
var arr=new Uint8Array(abc_interpreter.memory_array.buffer, dest+16);
for (var i=0; i<v.length; i++)
arr[i]=v.charCodeAt(i);
return dest+16+(((v.length+7)>>3)<<3);
},
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment