diff --git a/gitlab-pages/docs/advanced/include.md b/gitlab-pages/docs/advanced/include.md new file mode 100644 index 000000000..956d4a80e --- /dev/null +++ b/gitlab-pages/docs/advanced/include.md @@ -0,0 +1,71 @@ +--- +id: include +title: Including Other Contracts +--- + +Lets say we have a contract that's getting a bit too big. If it has a modular +structure, you might find it useful to use the `#include` statement to split the +contract up over multiple files. + + +You take the code that you want to include and put it in a separate file, for +example `included.ligo`: + + + + +```pascaligo + +// Demonstrate PascaLIGO inclusion statements, see includer.ligo + +const foo : int = 144 +``` + + +```cameligo + +// Demonstrate CameLIGO inclusion statements, see includer.mligo + +let foo : int = 144 +``` + + +```reasonligo + +// Demonstrate ReasonLIGO inclusion statements, see includer.religo + +let foo : int = 144; +``` + + + + +And then you can include this code using the `#include` statement like so: + + + + +```pascaligo + +#include "included.ligo" + +const bar : int = foo +``` + + +```cameligo + +#include "included.mligo" + +let bar : int = foo +``` + + +```reasonligo + +#include "included.religo" + +let bar : int = foo; +``` + + diff --git a/gitlab-pages/website/sidebars.json b/gitlab-pages/website/sidebars.json index 13ce03e4e..f684e1fb4 100644 --- a/gitlab-pages/website/sidebars.json +++ b/gitlab-pages/website/sidebars.json @@ -15,6 +15,7 @@ "Advanced": [ "advanced/timestamps-addresses", "advanced/entrypoints-contracts", + "advanced/include", "advanced/first-contract" ], "API": [ diff --git a/src/test/contracts/included.mligo b/src/test/contracts/included.mligo new file mode 100644 index 000000000..2d5850f1b --- /dev/null +++ b/src/test/contracts/included.mligo @@ -0,0 +1,3 @@ +// Demonstrate CameLIGO inclusion statements, see includer.mligo + +let foo : int = 144 diff --git a/src/test/contracts/included.religo b/src/test/contracts/included.religo new file mode 100644 index 000000000..1478f2650 --- /dev/null +++ b/src/test/contracts/included.religo @@ -0,0 +1,3 @@ +// Demonstrate ReasonLIGO inclusion statements, see includer.religo + +let foo : int = 144; diff --git a/src/test/contracts/includer.mligo b/src/test/contracts/includer.mligo new file mode 100644 index 000000000..611939afc --- /dev/null +++ b/src/test/contracts/includer.mligo @@ -0,0 +1,5 @@ +// Demonstrate CameLIGO inclusion statements, see included.mligo + +#include "included.mligo" + +let bar : int = foo diff --git a/src/test/contracts/includer.religo b/src/test/contracts/includer.religo new file mode 100644 index 000000000..8a04951e9 --- /dev/null +++ b/src/test/contracts/includer.religo @@ -0,0 +1,5 @@ +// Demonstrate ReasonLIGO inclusion statements, see included.religo + +#include "included.religo" + +let bar : int = foo; diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index b633f3faa..c4610dc89 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -604,6 +604,14 @@ let include_ () : unit result = let%bind program = type_file "./contracts/includer.ligo" in expect_eq_evaluate program "bar" (e_int 144) +let include_mligo () : unit result = + let%bind program = mtype_file "./contracts/includer.mligo" in + expect_eq_evaluate program "bar" (e_int 144) + +let include_religo () : unit result = + let%bind program = retype_file "./contracts/includer.religo" in + expect_eq_evaluate program "bar" (e_int 144) + let record_ez_int names n = ez_e_record @@ List.map (fun x -> x, e_int n) names @@ -1899,6 +1907,8 @@ let main = test_suite "Integration (End to End)" [ test "quote declaration" quote_declaration ; test "quote declarations" quote_declarations ; test "#include directives" include_ ; + test "#include directives (mligo)" include_mligo ; + test "#include directives (religo)" include_religo ; test "counter contract" counter_contract ; test "super counter contract" super_counter_contract ; test "super counter contract" super_counter_contract_mligo ;