Debugging tips and tricks
printLn(toString(...)) to query variables on the command line and in the
In a live environment, the
etch compiler will strip out
Our compiler is very strict. It will complain about:
- Unknown and unsupported symbols, operators, and indexes.
- Lack of types for variables and parameters.
nullto primitive types.
- Incorrect, incompatible, and uninferrable types in statements and functions.
- Duplicate variables, parameters, and functions.
- Incomparable types in boolean tests.
- Unmatched and unexpected beginnings, middles, and endings in selections, iterations, statements, and blocks.
- Incorrectly formed statements.
- Incorrect amount, or lack of, operands in boolean tests.
- Non-functions, unmatched functions, and functions that do not return a value.
- Local function definitions.
nullor no value from functions.
- Attempts to construct primitives and unmatched constructors.
- Mismatches between type and instance functions - awaiting clarification.
- Member access support issues with dot operator - awaiting clarification.
continue, variables, and expressions declared at topmost scope.
System.Argv() give us access to compiler argument count and values. In the following code, first we print the number of compiler arguments, then we list them.
function main() var message : String; printLn("System args: " + toString(System.Argc())); // print the argument values for(i in 0:System.Argc() - 1) message = toString(i) + " = " + System.Argv(i); printLn(message); endfor endfunction
Running the code from the command line with zero flags
-- sends arguments to the
For example, run the code snippet above with zero flags
-- and an example argument
hello like this:
./vm-lang sysargs-examples.etch -- hello
You should see the following output:
F E ╱ vm-lang v0.1.0-30-g557389e0 T C Copyright 2018-2019 (c) Fetch AI Ltd. H System args: 2 0 = ./vm-lang 1 = hello
etch features like this are useful for playing around with and for debugging in a dev environment. They should not be included in smart contract code.
For smart contracts, there are more flags, such as
-data, which do specific things. We explain coding, compiling, contract flags, and all about
etch smart contracts here.