Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Commit

Permalink
refactor(template) Remove now obsolete support for wrapVariables
Browse files Browse the repository at this point in the history
Signed-off-by: Jerome Simeon <[email protected]>
  • Loading branch information
jeromesimeon committed Aug 7, 2020
1 parent 9f5a25a commit a7850e1
Show file tree
Hide file tree
Showing 12 changed files with 13,287 additions and 13,354 deletions.
69 changes: 15 additions & 54 deletions extraction/src/ErgoParser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -58,35 +58,11 @@ let make_template_variable_as prov v s =
(make_template_input prov))

(* Construct AST for variables *)
let wrap_template_variable prov name ve =
let varparam =
ErgoCompiler.econst prov
(ErgoCompiler.ErgoData.dstring (Util.char_list_of_string name))
in
ErgoCompiler.ecallfun
prov
(relative_name_of_qname (Some "org.accordproject.ergo.template","variableTag"))
[varparam;ve]

let wrap_template_variable_as prov name ve fe =
let varparam =
ErgoCompiler.econst prov
(ErgoCompiler.ErgoData.dstring (Util.char_list_of_string name))
in
ErgoCompiler.ecallfun
prov
(relative_name_of_qname (Some "org.accordproject.ergo.template","variableTagAs"))
[varparam;ve;fe]

let wrap_template_if_block prov name veCond veTrue veFalse =
let varparam =
ErgoCompiler.econst prov
(ErgoCompiler.ErgoData.dstring (Util.char_list_of_string name))
in
ErgoCompiler.ecallfun
prov
(relative_name_of_qname (Some "org.accordproject.ergo.template","ifBlockTag"))
[varparam;veCond;veTrue;veFalse]
[veCond;veTrue;veFalse]

let wrap_template_computed prov e =
let textparam = e in
Expand All @@ -100,36 +76,24 @@ let make_template_ulist prov name ve =
let e = ErgoCompiler.eunaryoperator prov (EOpDot a) (ErgoCompiler.ethis_this prov) in
let fl = (ErgoCompiler.this_name, e) :: [] in
let bullet = make_list_sep () in
let listContent =
ErgoCompiler.ebinarybuiltin prov
ErgoCompiler.ErgoOps.Binary.opstringjoin
(ErgoCompiler.econst prov (ErgoCompiler.ErgoData.dstring (Util.char_list_of_string "")))
(ErgoCompiler.eforeach prov fl None
(ErgoCompiler.etext prov
(ErgoCompiler.econst prov (ErgoCompiler.ErgoData.dstring (Util.char_list_of_string bullet)) :: ve)))
in
ErgoCompiler.ecallfun
prov
(relative_name_of_qname (Some "org.accordproject.ergo.template","listBlockTag"))
[listContent]
ErgoCompiler.ebinarybuiltin prov
ErgoCompiler.ErgoOps.Binary.opstringjoin
(ErgoCompiler.econst prov (ErgoCompiler.ErgoData.dstring (Util.char_list_of_string "")))
(ErgoCompiler.eforeach prov fl None
(ErgoCompiler.etext prov
(ErgoCompiler.econst prov (ErgoCompiler.ErgoData.dstring (Util.char_list_of_string bullet)) :: ve)))

let make_template_olist prov name ve =
let a = Util.char_list_of_string name in
let e = ErgoCompiler.eunaryoperator prov (EOpDot a) (ErgoCompiler.ethis_this prov) in
let fl = (ErgoCompiler.this_name, e) :: [] in
let bullet = make_order_sep () in
let listContent =
ErgoCompiler.ebinarybuiltin prov
ErgoCompiler.ErgoOps.Binary.opstringjoin
(ErgoCompiler.econst prov (ErgoCompiler.ErgoData.dstring (Util.char_list_of_string "")))
(ErgoCompiler.eforeach prov fl None
(ErgoCompiler.etext prov
(ErgoCompiler.econst prov (ErgoCompiler.ErgoData.dstring (Util.char_list_of_string bullet)) :: ve)))
in
ErgoCompiler.ecallfun
prov
(relative_name_of_qname (Some "org.accordproject.ergo.template","listBlockTag"))
[listContent]
ErgoCompiler.ebinarybuiltin prov
ErgoCompiler.ErgoOps.Binary.opstringjoin
(ErgoCompiler.econst prov (ErgoCompiler.ErgoData.dstring (Util.char_list_of_string "")))
(ErgoCompiler.eforeach prov fl None
(ErgoCompiler.etext prov
(ErgoCompiler.econst prov (ErgoCompiler.ErgoData.dstring (Util.char_list_of_string bullet)) :: ve)))

let make_template_join prov name sep ve =
let a = Util.char_list_of_string name in
Expand Down Expand Up @@ -677,13 +641,10 @@ textlist:
varexpr:
| v = IDENT AS s = STRING
{ let prov = mk_provenance $startpos $endpos in
let ve = make_template_variable_as prov v s in
wrap_template_variable_as prov v ve
(ErgoCompiler.econst prov (ErgoCompiler.ErgoData.dstring (Util.char_list_of_string s))) }
make_template_variable_as prov v s }
| v = IDENT
{ let prov = mk_provenance $startpos $endpos in
let ve = make_template_variable prov v in
wrap_template_variable prov v ve }
make_template_variable prov v }

(* foreach list *)
foreachlist:
Expand Down
4 changes: 1 addition & 3 deletions extraction/src/ErgoStdlib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ let ergo_stdcto =
("$ERGODIR/extraction/stdlib/money.cto", Money.money);
("$ERGODIR/extraction/stdlib/time.cto", Time.time);
("$ERGODIR/extraction/stdlib/options.cto", Options.options);
("$ERGODIR/extraction/stdlib/runtime.cto", Runtime.runtime);
("$ERGODIR/extraction/stdlib/commonmark.cto", Commonmark.commonmark);
("$ERGODIR/extraction/stdlib/ciceromark.cto", Ciceromark.ciceromark); ]
("$ERGODIR/extraction/stdlib/runtime.cto", Runtime.runtime); ]
let ergo_stdlib =
[ ("$ERGODIR/extraction/stdlib/stdlib.ergo", stdlib);
("$ERGODIR/extraction/stdlib/etime.ergo", etime);
Expand Down
36 changes: 6 additions & 30 deletions extraction/stdlib/template.ergo
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,14 @@

namespace org.accordproject.ergo.template

define function variableTag(variableName:String,text:String) : String {
if getOptions().wrapVariables
then return "<variable id=\"" ++ variableName ++ "\" value=\"" ++ encode(text) ++ "\"/>"
else return text
}

define function variableTagAs(variableName:String,text:String,format:String) : String {
if getOptions().wrapVariables
then return "<variable id=\"" ++ variableName ++ "\" value=\"" ++ encode(text) ++ "\" format=\"" ++ encode(format) ++ "\"/>"
else return text
}

define function ifBlockTag(variableName:String,condition:Boolean,whenTrue:String,whenFalse:String) : String {
if getOptions().wrapVariables
then
let conditionText = if condition then whenTrue else whenFalse;
return "<if id=\"" ++ variableName ++ "\" value=\"" ++ encode(conditionText) ++ "\" whenTrue=\"" ++ encode(whenTrue) ++ "\" whenFalse=\"" ++ encode(whenFalse) ++ "\"/>"
else
let conditionText = if condition then whenTrue else whenFalse;
return conditionText
}

define function listBlockTag(text:String) : String {
if getOptions().wrapVariables
then return "```<list/>" ++ text ++ "\n```"
else return text
define function ifBlockTag(condition:Boolean,whenTrue:String,whenFalse:String) : String {
if condition
then return whenTrue
else return whenFalse
}

define function computedTag(text:String) : String {
if getOptions().wrapVariables
then return "<computed value=\"" ++ encode(text) ++ "\"/>"
else if getOptions().template
then return "{{" ++ text ++ "}}"
if getOptions().template
then return "{{%" ++ text ++ "%}}"
else return text
}
2 changes: 1 addition & 1 deletion mechanization/Version.v
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Require Import String.

Section Version.
Definition ergo_version := "0.21.1"%string.
Definition ergo_version := "0.21.2"%string.

End Version.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,4 @@
}
},
"dependencies": {}
}
}
9,000 changes: 4,500 additions & 4,500 deletions packages/ergo-cli/extracted/ergoccore.js

Large diffs are not rendered by default.

8,612 changes: 4,306 additions & 4,306 deletions packages/ergo-cli/extracted/ergotopcore.js

Large diffs are not rendered by default.

8,854 changes: 4,427 additions & 4,427 deletions packages/ergo-compiler/extracted/compilercore.js

Large diffs are not rendered by default.

46 changes: 23 additions & 23 deletions packages/ergo-compiler/test/logicmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ describe('LogicManager', () => {
logicManager.compileLogicSync(false);
logicManager.getInvokeCall('helloworld').length.should.equal(250);
logicManager.getDispatchCall().length.should.equal(172);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(38403);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(32667);
logicManager.compileLogicSync(false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(38403);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(32667);
});

it('should succeed creating a dispatch call for a JS logic file with a contract class (ES6)', () => {
Expand Down Expand Up @@ -194,9 +194,9 @@ describe('LogicManager', () => {
logicManager.compileLogic(false).then((logicCode) => {
logicManager.getInvokeCall('helloworld').length.should.equal(250);
logicManager.getDispatchCall().length.should.equal(172);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(38403);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(32667);
logicManager.compileLogicSync(false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(38403);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(32667);
});
});

Expand All @@ -213,16 +213,16 @@ describe('LogicManager', () => {
logicManager.compileLogicSync(false);
logicManager.getInvokeCall('helloworld').length.should.equal(250);
logicManager.getDispatchCall().length.should.equal(172);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(38403);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(32667);
logicManager.compileLogicSync(false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(38403);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(32667);
});

it('should load a logic file (without extension) to the script manager', () => {
const logicManager = new LogicManager('cicero');
logicManager.addLogicFile(ergoSample,'test');
logicManager.compileLogicSync(false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(38403);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(32667);
});

it('should set the contract name', () => {
Expand All @@ -238,15 +238,15 @@ describe('LogicManager', () => {
logicManager.addLogicFile(ergoSample,'test.ergo');
logicManager.getTarget().should.equal('cicero');
logicManager.compileLogicSync(false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(38403);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(32667);
logicManager.setTarget('es6', true);
logicManager.getTarget().should.equal('es6');
const contractName = 'org.accordproject.helloemit.HelloWorld';
logicManager.setContractName(contractName);
logicManager.getContractName().should.equal(ErgoCompiler.contractCallName(contractName));
logicManager.getInvokeCall('helloworld').length.should.equal(250);
logicManager.getDispatchCall().length.should.equal(234);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(36708);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(30972);
});

it('should fail to create init and dispatch for ES6 without a contract name', () => {
Expand All @@ -256,29 +256,29 @@ describe('LogicManager', () => {
logicManager.compileLogicSync(false);
logicManager.getInvokeCall('helloworld').length.should.equal(250);
logicManager.getDispatchCall().length.should.equal(234);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(36708);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(30972);
});

it('should set the compilation target to ES6 but not recompile the logic', () => {
const logicManager = new LogicManager('cicero');
logicManager.addLogicFile(ergoSample,'test.ergo');
logicManager.compileLogicSync(false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(38403);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(32667);
logicManager.setTarget('es6', false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(38403);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(32667);
});

it('should set the compilation target to ES5', () => {
const logicManager = new LogicManager('cicero');
logicManager.addLogicFile(ergoSample,'test.ergo');
logicManager.getTarget().should.equal('cicero');
logicManager.compileLogicSync(false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(38403);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(32667);
logicManager.setTarget('es5', true);
logicManager.getTarget().should.equal('es5');
logicManager.getInvokeCall('helloworld').length.should.equal(174);
logicManager.getDispatchCall().length.should.equal(158);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(36562);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(30826);
});

it('should fail to create init code for Java', () => {
Expand Down Expand Up @@ -312,7 +312,7 @@ describe('LogicManager', () => {
'model.cto'
]);
modelManager.getModels()[0].content.length.should.equal(1330);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(45965);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(40229);
});

it('should load a directory with formula', async function () {
Expand All @@ -326,7 +326,7 @@ describe('LogicManager', () => {
'model.cto'
]);
modelManager.getModels()[0].content.length.should.equal(1330);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(40923);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(35187);
});
});

Expand All @@ -343,7 +343,7 @@ describe('LogicManager', () => {
'model.cto'
]);
modelManager.getModels()[0].content.length.should.equal(1330);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(45965);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(40229);
});

it('should load a Zip with formula', async function () {
Expand All @@ -358,7 +358,7 @@ describe('LogicManager', () => {
'model.cto'
]);
modelManager.getModels()[0].content.length.should.equal(1330);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(40923);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(35187);
});
});

Expand All @@ -379,7 +379,7 @@ describe('LogicManager', () => {
'model.cto'
]);
modelManager.getModels()[0].content.length.should.equal(1330);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(45965);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(40229);
});

it('should load a Zip with formula', async function () {
Expand All @@ -398,7 +398,7 @@ describe('LogicManager', () => {
'model.cto'
]);
modelManager.getModels()[0].content.length.should.equal(1330);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(40923);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(35187);
});
});

Expand Down Expand Up @@ -436,15 +436,15 @@ describe('LogicManager', () => {
logicManager.compileLogicSync(false);
logicManager.getInvokeCall('helloworld').length.should.equal(250);
logicManager.getDispatchCall().length.should.equal(172);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(38403);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(32667);
logicManager.updateLogic(ergoSample,'test.ergo');
logicManager.compileLogicSync(false);
logicManager.updateLogic(ergoSample,'testNEW.ergo');
logicManager.compileLogicSync(false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(38403);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(32667);
logicManager.updateLogic(ergoSample3,'test.ergo');
logicManager.compileLogicSync(false);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(38403);
logicManager.getScriptManager().getCompiledScript().getContents().length.should.equal(32667);
});

});
Expand Down
12 changes: 6 additions & 6 deletions packages/ergo-compiler/test/scriptmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ describe('ScriptManager', () => {
scriptManager.getLogic().map(x => x.name).should.deep.equal(['test.ergo']);
scriptManager.allFunctionDeclarations().length.should.equal(2);
scriptManager.allFunctionDeclarations().map(x => x.getName()).should.deep.equal(['paymentClause','__dispatch']);
scriptManager.getCompiledScript().getContents().length.should.equal(38403);
scriptManager.getCompiledJavaScript().length.should.equal(38403);
scriptManager.getCompiledScript().getContents().length.should.equal(32667);
scriptManager.getCompiledJavaScript().length.should.equal(32667);
scriptManager.allFunctionDeclarations().length.should.equal(114);
scriptManager.allFunctionDeclarations().filter(x => x.name === '__init').length.should.equal(1);
expect(scriptManager.hasInit()).to.not.throw;
Expand All @@ -76,8 +76,8 @@ describe('ScriptManager', () => {
const script2 = scriptManager.createScript('test.ergo','.ergo',ergoSample);
scriptManager.addScript(script1);
scriptManager.addScript(script2);
scriptManager.compileLogic().getContents().length.should.equal(38403);
scriptManager.getCompiledScript().getContents().length.should.equal(38403);
scriptManager.compileLogic().getContents().length.should.equal(32667);
scriptManager.getCompiledScript().getContents().length.should.equal(32667);
scriptManager.getAllScripts().length.should.equal(3);
});

Expand Down Expand Up @@ -182,8 +182,8 @@ describe('ScriptManager', () => {
const script2 = scriptManager.createScript('test.ergo','.ergo',ergoSample);
scriptManager.addScript(script1);
scriptManager.addScript(script2);
scriptManager.compileLogic().getContents().length.should.equal(38403);
scriptManager.getCompiledJavaScript().length.should.equal(38403);
scriptManager.compileLogic().getContents().length.should.equal(32667);
scriptManager.getCompiledJavaScript().length.should.equal(32667);
scriptManager.clearScripts();
return (() => scriptManager.getCompiledJavaScript()).should.throw('Did not find any compiled JavaScript logic');
});
Expand Down
2 changes: 0 additions & 2 deletions scripts/external/ergo.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
"js": "packages/ergo-compiler/lib/externalModels",
"ocaml": "extraction/extracted",
"models": [
"https://models.accordproject.org/markdown/commonmark.cto",
"https://models.accordproject.org/markdown/ciceromark.cto",
"https://models.accordproject.org/cicero/contract.cto",
"https://models.accordproject.org/cicero/runtime.cto",
"https://models.accordproject.org/[email protected]",
Expand Down

0 comments on commit a7850e1

Please sign in to comment.