Skip to content

Commit

Permalink
Move files around (#736)
Browse files Browse the repository at this point in the history
* src/lang/base -> src/base
   src/cpp -> src/base/cpp
   src/lang/{checkers,eval} -> src/

* Dismiss util library and move its only module to base

* Remove unused scilla_module_parse.ml

* Make ParserUtil part of Syntax

* More Core -> Core_kernel

* Separate scilla-base from the rest of Scilla

This commit _does not_ introduce scilla-base package yet.
It's a preliminary step towards this goal.

Polynomials can be factored out as a separate package, hence
it gets its own directory and a separate test suite.

This commit preserves the total number of tests so far -- 1790
  • Loading branch information
Anton Trunov authored Dec 11, 2019
1 parent b2130b1 commit 09f5a4b
Show file tree
Hide file tree
Showing 773 changed files with 467 additions and 507 deletions.
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ make clean; make

10. Test your installation by running
```shell
./bin/eval-runner -gaslimit 10000 -libdir src/stdlib tests/eval/exp/good/let.scilexp
./bin/eval-runner -gaslimit 10000 -libdir src/stdlib tests/eval/good/let.scilexp
```

If the output is as below, then you are good to go 👍. No further action will be necessary.
Expand Down
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,37 @@ slim:
dev:
./scripts/libff.sh
dune build --profile dev @install
dune build tests/polynomials/testsuite_polynomials.exe
dune build tests/base/testsuite_base.exe
dune build tests/testsuite.exe
@test -L bin || ln -s _build/install/default/bin .

# Launch utop such that it finds the libraroes.
utop: all
OCAMLPATH=_build/install/default/lib:$(OCAMLPATH) utop

# === TESTS (begin) ===========================================================
# Build and run tests
# the make utility increases the maximum stack limit, this allows our tests
# to pass but analogous programs might break when run on users' machines
# (e.g. on macOS 10.14.5 make sets the limit to 65532kB, but the standard
# value is 8192kB)

testbase: dev
ulimit -s 128 -n 1024; dune exec tests/base/testsuite_base.exe

goldbase: dev
ulimit -s 128 -n 1024; dune exec tests/base/testsuite_base.exe -- -update-gold true

# Run all tests for all packages in the repo: scilla-base, polynomials, scilla
test: dev
ulimit -s 128 -n 1024; dune exec tests/polynomials/testsuite_polynomials.exe
ulimit -s 128 -n 1024; dune exec tests/base/testsuite_base.exe -- -print-diff true
ulimit -s 128 -n 1024; dune exec tests/testsuite.exe -- -print-diff true

gold: dev
ulimit -s 128 -n 1024; dune exec tests/polynomials/testsuite_polynomials.exe
ulimit -s 128 -n 1024; dune exec tests/base/testsuite_base.exe -- -update-gold true
ulimit -s 128 -n 1024; dune exec tests/testsuite.exe -- -update-gold true

# This must be run only if there is an external IPC server available
Expand All @@ -51,6 +66,9 @@ test_extipcserver: dev
-ext-ipc-server $(IPC_SOCK_PATH) \
-only-test "all_tests:0:contract_tests:0:these_tests_must_SUCCEED"

# === TESTS (end) =============================================================


# Clean up
clean:
# Remove files produced by dune.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ Once the project is built you can try the following things:
From the project root, execute

```
./bin/eval-runner -gaslimit 10000 -libdir src/stdlib tests/eval/exp/good/let.scilexp
./bin/eval-runner -gaslimit 10000 -libdir src/stdlib tests/eval/good/let.scilexp
```

Instead of `let.scilla` you might want to try any different file in
`tests/eval/exp`. The second argument, which is a path to the Scilla
`tests/eval`. The second argument, which is a path to the Scilla
standard library can alternatively be specified in the environment
variable `SCILLA_STDLIB_PATH`. This must be an absolute path (or a
list of paths separated with `:` (or `;` on Windows).
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions src/lang/base/BuiltIns.ml → src/base/BuiltIns.ml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ module ScillaBuiltIns
let substr ls _ = match ls with
| [StringLit x; UintLit (Uint32L s); UintLit (Uint32L e)] ->
(try
pure @@ StringLit (Core.String.sub x ~pos:(Uint32.to_int s) ~len:(Uint32.to_int e))
pure @@ StringLit (String.sub x ~pos:(Uint32.to_int s) ~len:(Uint32.to_int e))
with Invalid_argument msg -> builtin_fail ("String.substr: " ^ msg) ls)
| _ -> builtin_fail "String.substr" ls

Expand Down Expand Up @@ -629,13 +629,13 @@ module ScillaBuiltIns
| ByStrX bs -> Bystrx.to_raw_bytes bs
| Msg entries ->
let raw_entries = List.map entries ~f:(fun (s, v) -> s ^ raw_bytes v) in
Core.String.concat ~sep:"" raw_entries
Core_kernel.String.concat ~sep:"" raw_entries
| Map (_, tbl) ->
let raw_strings = Caml.Hashtbl.fold (fun k v acc -> raw_bytes k :: raw_bytes v :: acc) tbl [] in
Core.String.concat ~sep:"" raw_strings
Core_kernel.String.concat ~sep:"" raw_strings
| ADTValue (cons_name, _, params) ->
let raw_params = List.map params ~f:raw_bytes in
Core.String.concat ~sep:"" (cons_name :: raw_params)
Core_kernel.String.concat ~sep:"" (cons_name :: raw_params)
| Clo _fun -> "(Clo <fun>)"
| TAbs _fun -> "(Tabs <fun>)"
in
Expand Down Expand Up @@ -689,7 +689,7 @@ module ScillaBuiltIns
| [ByStrX bs] when Bystrx.width bs <= 32 ->
(* of_bytes_big_endian functions expect 2^n number of bytes exactly *)
let rem = 32 - Bystrx.width bs in
let pad = Core.String.make rem '\000' in
let pad = Core_kernel.String.make rem '\000' in
let bs_padded = pad ^ (Bystrx.to_raw_bytes bs) in
let u = Uint256.of_bytes_big_endian (Bytes.of_string bs_padded) 0 in
pure (UintLit (Uint256L u))
Expand Down Expand Up @@ -826,7 +826,7 @@ module ScillaBuiltIns
(* Hash the public key *)
let pkh = sha256_hasher pks in
(* and extract the least significant 20 bytes. *)
let addr = Core.String.suffix pkh 20 in
let addr = Core_kernel.String.suffix pkh 20 in
(match Bystrx.of_raw_bytes address_length addr with
| Some bs -> pure @@ ByStrX bs
| None -> builtin_fail "schnorr_get_address: Internal error." ls)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
open Syntax
open ErrorUtils
open Lexing
open ParserUtil

module MInter = ScillaParser.MenhirInterpreter

Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions src/lang/base/GlobalConfig.ml → src/base/GlobalConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ let add_stdlib_dirs dirs =
let file_extn_contract = "scilla"
(* File extension for Scilla libraries. *)
let file_extn_library = "scillib"
(* File extension for Scilla expressions. *)
let file_extn_expression = "scilexp"

(* Try find library "name" in known locations *)
let find_lib_dir name =
Expand Down
2 changes: 2 additions & 0 deletions src/lang/base/GlobalConfig.mli → src/base/GlobalConfig.mli
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,7 @@ module StdlibTracker : sig
val file_extn_contract : string
(* File extension for Scilla libraries. *)
val file_extn_library : string
(* File extension for Scilla expressions. *)
val file_extn_expression : string

end
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions src/lang/base/JSON.ml → src/base/JSON.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

open Syntax
open ErrorUtils
open ParserUtil
open Core_kernel
open Yojson
open ContractUtil.MessagePayload
Expand Down Expand Up @@ -399,7 +398,7 @@ let get_json_data filename =
end

module ContractInfo = struct
open ParserUtil.ParsedSyntax
open Syntax.ParsedSyntax

let get_json cmver (contr : contract) (event_info : (string * (string * typ) list) list) =
(* 0. contract version *)
Expand Down
2 changes: 1 addition & 1 deletion src/lang/base/JSON.mli → src/base/JSON.mli
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module BlockChainState : sig
end

module ContractInfo : sig
open ParserUtil.ParsedSyntax
open Syntax.ParsedSyntax
(* Given a parsed contract, give a string JSON with these details:
{
"name" : "foo",
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion src/lang/base/JSONParser.mli → src/base/JSONParser.mli
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
scilla. If not, see <http://www.gnu.org/licenses/>.
*)

open Core_kernel
open Syntax
open Yojson

Expand Down Expand Up @@ -45,7 +46,7 @@ type adt_parser_entry =
| Parser of (Basic.t -> literal)

(* ADT parsers table *)
val adt_parsers : (string, adt_parser_entry) Core.Caml.Hashtbl.t
val adt_parsers : (string, adt_parser_entry) Caml.Hashtbl.t

(* Put an ADT parser to the table *)
val add_adt_parser : string -> adt_parser_entry -> unit
Expand Down
4 changes: 2 additions & 2 deletions src/lang/base/MonadUtil.ml → src/base/MonadUtil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ module EvalMonad = struct

let fromR r =
match r with
| Core.Error s -> fail s
| Core.Ok a -> pure a
| Core_kernel.Error s -> fail s
| Core_kernel.Ok a -> pure a

let out_of_gas_err = mk_error0 "Ran out of gas"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ type_term: MAP CID UNDERSCORE
## In state 22, spurious reduction of production scid -> CID
## In state 44, spurious reduction of production t_map_key -> scid
##
# see tests/eval/exp/bad/list_to_map.scilexp
# see tests/eval/bad/list_to_map.scilexp

This map type likely has an invalid map value type.

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

open Syntax
open Core_kernel
open ParserUtil
open FrontEndParser

(***********************************************************)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 5 additions & 7 deletions src/lang/base/ScillaParser.mly → src/base/ScillaParser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
%{
open Syntax
open ErrorUtils
open ParserUtil

open ParsedSyntax

let to_prim_type_exn d loc = match d with
Expand All @@ -39,7 +37,7 @@
| "ByStr" -> Bystr_typ
| _ -> let re = Str.regexp "ByStr\\([0-9]+\\)$" in
if Str.string_match re d 0 then
let open Core in
let open Core_kernel in
let b = Int.of_string (Str.matched_group 1 d) in
Bystrx_typ b
else raise (SyntaxError ("Invalid primitive type", loc))
Expand Down Expand Up @@ -141,11 +139,11 @@
(* %nonassoc NEG *)
%right TARROW

%start <ParserUtil.ParsedSyntax.expr_annot> exp_term
%start <Syntax.ParsedSyntax.expr_annot> exp_term
%start <Syntax.typ> type_term
%start <ParserUtil.ParsedSyntax.stmt_annot list> stmts_term
%start <ParserUtil.ParsedSyntax.cmodule> cmodule
%start <ParserUtil.ParsedSyntax.lmodule> lmodule
%start <Syntax.ParsedSyntax.stmt_annot list> stmts_term
%start <Syntax.ParsedSyntax.cmodule> cmodule
%start <Syntax.ParsedSyntax.lmodule> lmodule

%%

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions src/lang/base/Syntax.ml → src/base/Syntax.ml
Original file line number Diff line number Diff line change
Expand Up @@ -934,3 +934,29 @@ module ScillaSyntax (SR : Rep) (ER : Rep) = struct

end


(*******************************************************)
(* Annotations *)
(*******************************************************)

module ParserRep = struct
type rep = loc
[@@deriving sexp]

let dummy_rep = dummy_loc
let get_loc l = l
let mk_id_address s = Ident (s, dummy_loc)
let mk_id_uint128 s = Ident (s, dummy_loc)
let mk_id_uint32 s = Ident (s, dummy_loc)
let mk_id_bnum s = Ident (s, dummy_loc)
let mk_id_string s = Ident (s, dummy_loc)

let parse_rep _ = dummy_loc
let get_rep_str r = get_loc_str r
end

(*******************************************************)
(* Syntax as generated by the parser *)
(*******************************************************)

module ParsedSyntax = ScillaSyntax (ParserRep) (ParserRep)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/lang/base/Utils.ml → src/base/Utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ open Core_kernel

(* Add item a to list if it isn't already present. Use ~equal to check presence. *)
let list_add_unique ~equal ls a =
if Core.List.mem ls a ~equal then ls else (a :: ls)
if List.mem ls a ~equal then ls else (a :: ls)

(* Fold n times, each time applying 0-(n-1) and accummulator to f. *)
let int_fold ~init ~(f : 'a -> int -> 'a) n =
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ let () =
[]
in

(* This file runs in _build/default/src/cpp.
(* This file runs in _build/default/src/base/cpp.
* libff is installed in _deps/libff/install. *)
let libff_dir = Sys.getcwd() ^ "/../../../../_deps/libff/install" in
let libff_dir = Sys.getcwd() ^ "/../../../../../_deps/libff/install" in
let libff_include_dir = libff_dir ^ "/include" in
let libff_lib_dir = libff_dir ^ "/lib" in
if not (Sys.file_exists libff_include_dir) || not (Sys.file_exists libff_lib_dir)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/lang/base/dune → src/base/dune
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
(name scilla_base)
(wrapped false)
(libraries core ppx_sexp_conv num hex stdint batteries ppx_deriving.show
cryptokit secp256k1 bitstring yojson scilla_cpp_deps scilla_util menhirLib)
cryptokit secp256k1 bitstring yojson fileutils scilla_cpp_deps menhirLib)
(preprocess
(pps ppx_sexp_conv ppx_let ppx_deriving.show bisect_ppx -conditional))
(synopsis "Scilla workbench implementation."))
6 changes: 3 additions & 3 deletions src/lang/checkers/Accept.ml → src/checkers/Accept.ml
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ module ScillaAcceptChecker

let dup_accept_warning (group : loc list) : unit =
(warn2
(Core.sprintf
(Core_kernel.sprintf
"transition %s had a potential code path with duplicate accept statements:\n"
(get_id transition.comp_name) ^
String.concat ""
(List.map
(fun loc -> Core.sprintf " Accept at %s\n" (get_loc_str loc))
(fun loc -> Core_kernel.sprintf " Accept at %s\n" (get_loc_str loc))
group))
warning_level_duplicate_accepts
(List.hd group)
Expand All @@ -137,7 +137,7 @@ module ScillaAcceptChecker
(match List.for_all BatList.is_empty all_accept_groups with
| true ->
(warn0
(Core.sprintf "No transition in contract %s contains an accept statement\n"
(Core_kernel.sprintf "No transition in contract %s contains an accept statement\n"
(get_id contr.cname))
warning_level_missing_accept)
| false -> ())
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ module ScillaGUA
match sr with
| SPol p ->
(* Find a "analyzable" Container term in the polynomial. *)
let (cterms, oterms) = Core.List.partition_tf p ~f:(fun (coef, vplist) ->
let (cterms, oterms) = Core_kernel.List.partition_tf p ~f:(fun (coef, vplist) ->
match vplist with
(* We can only analyze "Length(accarg) + C" *)
| [(Container (SPol ([cpol;(1, [(Length (Base lenvar), 1)])]), _), _)]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module ScillaSanityChecker
let e' =
if is_mem_id i rem
then
e @ mk_error1 (Core.sprintf "Identifier %s used more than once\n" (get_id i)) (gloc @@ get_rep i)
e @ mk_error1 (Core_kernel.sprintf "Identifier %s used more than once\n" (get_id i)) (gloc @@ get_rep i)
else e
in
recurser rem e'
Expand Down Expand Up @@ -109,7 +109,7 @@ module ScillaSanityChecker
let e = List.fold_left (fun e c ->
match List.find_opt (fun (s, _) -> get_id s = amount_label || get_id s = sender_label) c.comp_params with
| Some (s, _) ->
e @ mk_error1 (Core.sprintf "Parameter %s in %s %s cannot be explicit.\n"
e @ mk_error1 (Core_kernel.sprintf "Parameter %s in %s %s cannot be explicit.\n"
(get_id s)
(component_type_to_string c.comp_type)
(get_id c.comp_name))
Expand All @@ -124,7 +124,7 @@ module ScillaSanityChecker
|| (get_id s = ContractUtil.this_address_label)
) contr.cparams) with
| Some (s, _) ->
e @ mk_error1 (Core.sprintf "Contract parameter %s cannot be explicit.\n" (get_id s))
e @ mk_error1 (Core_kernel.sprintf "Contract parameter %s cannot be explicit.\n" (get_id s))
(ER.get_loc @@ get_rep s)
| None -> e
in
Expand Down Expand Up @@ -206,7 +206,7 @@ module ScillaSanityChecker
* https://github.com/Zilliqa/scilla/issues/687. To close this Issue:
* Make this an error by just using fail1 below instead of warn1. *)
let bounds = get_pattern_bounds pat in
match Core.List.find_a_dup ~compare:compare_id bounds with
match Core_kernel.List.find_a_dup ~compare:compare_id bounds with
| Some v ->
warn1 (Printf.sprintf "Deprecated: variable %s shadows a previous binding in the same pattern." (get_id v))
warning_level_name_shadowing
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/lang/eval/Eval.ml → src/eval/Eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ open PrettyPrinters
open EvalTypeUtilities
open EvalSyntax

module CU = ScillaContractUtil (ParserUtil.ParserRep) (ParserUtil.ParserRep)
module CU = ScillaContractUtil (ParserRep) (ParserRep)

(***************************************************)
(* Utilities *)
Expand Down
1 change: 0 additions & 1 deletion src/lang/eval/EvalUtil.ml → src/eval/EvalUtil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ open TypeUtil
open BuiltIns
open Gas

open ParserUtil
module SR = ParserRep
module ER = ParserRep
module EvalSyntax = ScillaSyntax (SR) (ER)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ open Result.Let_syntax
open MonadUtil
open Syntax
open JSON
open ParserUtil
open TypeUtil
open StateIPCIdl
open ErrorUtils
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 09f5a4b

Please sign in to comment.