Verified Commit 0082e0af authored by Peter Achten's avatar Peter Achten Committed by Camil Staps

Merge branch 'javascript-interface-enhancements-for-svg-library' into...

Merge branch 'javascript-interface-enhancements-for-svg-library' into 'server-and-client-side-svg-rendering-with-abc-interpreter'

Javascript interface enhancements for the SVG library

See merge request !272
parents fa61ed6c 3ccab5c7
......@@ -160,10 +160,14 @@ toUIAttributes attr vst
# (attr,vst) = serializeForClient attr vst
= ('Data.Map'.fromList [(JS_ATTR_SVG,JSONString attr)], vst)
fromUIAttributes :: !String !*JSWorld -> (!ServerToClientAttr s,!*JSWorld)
fromUIAttributes :: !*String !*JSWorld -> (!ServerToClientAttr s,!*JSWorld)
fromUIAttributes json world
= jsDeserializeGraph json world
ensure_uniqueness :: !String -> *String
ensure_uniqueness _ = code {
no_op
}
// the server side state:
:: ServerSVGState s
......@@ -367,7 +371,7 @@ clientGetTaskId me world
clientInitDOMEl :: !(SVGEditor s v) !JSVal !{!JSVal} !*JSWorld -> *JSWorld | JSONEncode{|*|} s
clientInitDOMEl svglet me args world
#! (model, world) = me .# "attributes.value" .? world
#! (model, world) = jsDeserializeGraph (jsValToString` "" model) world
#! (model, world) = jsDeserializeGraph (ensure_uniqueness (jsValToString` "" model)) world
#! (jsView, world) = jsMakeCleanReference (svglet.initView model) me world
#! (jsModel,world) = jsMakeCleanReference model me world
#! world = (me .# JS_ATTR_VIEW .= jsView) world
......@@ -388,7 +392,7 @@ clientHandleAttributeChange svglet me args world
#! world = timeTrace ("clientHandleAttributeChange [" +++ join "," (map fst nv_pairs) +++ "] started at ") world
= case svg_or_text of
Just json
#! (request,world) = fromUIAttributes (jsValToString` "" json) world
#! (request,world) = fromUIAttributes (ensure_uniqueness (jsValToString` "" json)) world
= case request of
(ServerNeedsTextMetrics new_fonts new_texts)
#! world = timeTrace "clientHandleAttributeChange (ServerNeedsTextMetrics) started at " world
......
......@@ -208,7 +208,7 @@ wrapInitUIFunction :: !(JSVal *JSWorld -> *JSWorld) -> {!JSVal} -> *JSWorld -> *
* @param The string to deserialize.
* @result The deserialized value.
*/
jsDeserializeGraph :: !String !*JSWorld -> *(!.a, !*JSWorld)
jsDeserializeGraph :: !*String !*JSWorld -> *(!.a, !*JSWorld)
/**
* Load external CSS stylesheet by its URL.
......
......@@ -552,10 +552,10 @@ where
repl_r_args 0 1
}
jsDeserializeGraph :: !String !*JSWorld -> *(!.a, !*JSWorld)
jsDeserializeGraph :: !*String !*JSWorld -> *(!.a, !*JSWorld)
jsDeserializeGraph s w = (deserialize s, w)
where
deserialize :: !String -> .a
deserialize :: !*String -> .a
deserialize _ = code {
instruction 6
}
......
......@@ -75,22 +75,11 @@ const ABC={
}
},
deserialize: function (string) {
var max_words_needed=string.length/8*4; // rough upper bound
ABC.require_hp(max_words_needed);
var array=new Int8Array(string.length);
for (var i in string)
array[i]=string.charCodeAt(i);
var graph=new Uint32Array(array.buffer);
var unused_semispace=ABC.util.instance.exports.get_unused_semispace();
for (var i=0; i<graph.length; i++)
ABC.memory_array[unused_semispace/4+i]=graph[i];
_deserialize: function (addr, size) {
var old_hp=ABC.interpreter.instance.exports.get_hp();
var new_hp=ABC.util.instance.exports.copy_from_string(
unused_semispace,
graph.length/2,
addr,
size,
ABC.interpreter.instance.exports.get_asp()+8,
ABC.interpreter.instance.exports.get_bsp()-8,
old_hp,
......@@ -103,7 +92,28 @@ const ABC={
ABC.interpreter.instance.exports.set_hp_free(new_hp_free);
return ABC.memory_array[unused_semispace/4];
return ABC.memory_array[addr/4];
},
deserialize_from_unique_string: function (str_ptr) {
var size=ABC.memory_array[str_ptr/4+2];
ABC.require_hp(size/8*4); // rough upper bound
return ABC._deserialize(str_ptr+16, size/8);
},
deserialize: function (string) {
var max_words_needed=string.length/8*4; // rough upper bound
ABC.require_hp(max_words_needed);
var array=new Uint8Array(string.length);
for (var i=0; i<string.length; i++)
array[i]=string.charCodeAt(i);
var graph=new Uint32Array(array.buffer);
var unused_semispace=ABC.util.instance.exports.get_unused_semispace();
for (var i=0; i<graph.length; i++)
ABC.memory_array[unused_semispace/4+i]=graph[i];
return ABC._deserialize(unused_semispace, graph.length/2);
},
interpret: null,
......@@ -319,11 +329,15 @@ const ABC={
get_clean_string: function (hp_ptr) {
var size=ABC.memory_array[hp_ptr/4+2];
var string_buffer=new Uint8Array(ABC.memory.buffer, hp_ptr+16);
var string='';
for (var i=0; i<size; i++)
string+=String.fromCharCode(string_buffer[i]);
return string;
var string_buffer=new Uint8Array(ABC.memory.buffer, hp_ptr+16, size);
if (typeof TextDecoder!='undefined') {
return new TextDecoder('x-user-defined').decode(string_buffer);
} else {
var string='';
for (var i=0; i<size; i++)
string+=String.fromCharCode(string_buffer[i]);
return string;
}
},
addresses: {},
......@@ -481,8 +495,8 @@ ABC.loading_promise=fetch('js/app.pbc').then(function(resp){
ABC.memory_array[asp/4]=ABC.shared_clean_values[index].ref;
break;
case 6: /* iTasks.UI.JS.Interface: deserialize */
var string=ABC.get_clean_string(ABC.memory_array[asp/4]);
ABC.memory_array[asp/4]=ABC.deserialize(string);
var hp_ptr=ABC.memory_array[asp/4];
ABC.memory_array[asp/4]=ABC.deserialize_from_unique_string(hp_ptr);
break;
case 7: /* iTasks.UI.JS.Interface: initialize_client in wrapInitUIFunction */
var array=ABC.memory_array[asp/4]+24;
......
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