Jump to content

Untrusted environment: Difference between revisions

(Added Wren)
Line 110:
7 49
ret, msg: false [string " print("hello")..."]:3: attempt to call global 'setmetatable' (a nil value)</pre>
 
=={{header|Nim}}==
Nim can compile to native code (via C, C++ or Objective-C) or to Javascript. When compiling to native code, as other languages such as Ada, it includes checks to insure than code is safe.
 
So, in release mode which is the mode to prefer, assignments , indexing, accesses via references, overflows ar checked. So, for instance, in normal code there is no way to get a buffer overflow as this would raise an IndexDefect exception.
 
Nim insures (except if explicitly specified otherwise) that memory is initialized with binary zeros, which avoids random behaviors. That means also that all pointers and references are initialized to nil which will avoid undefined behavior when dereferencing a non explicitly initialized pointer.
 
Nim uses copy semantic which means that assignments always copy the value and not the address. This avoids aliasing which is unsafe, but this may produce less efficient code. Fortunately, the compiler is smart enough to avoid most of the copies. Nevertheless, the programmer should be aware of this and take care of that.
 
The compiler does many checks to detect possible violation of memory safety. All is done to make sure that, unless explicitly required, no memory corruption is possible.
 
However, as a system language, Nim allows to do unsafe operations. These operations are unsafe:
 
– calling an external procedure (typically using C interface);
 
– converting from a type to another type using a cast (but normal conversions are safe);
 
– using pointers (allocating memory, dereferencing, freeing memory); but references are safe as all is managed by the GC;
 
– taking the address of an object (which means in fact to use pointers).
 
There is no simple way to do arithmetic operations on addresses. This is of course possible using casts between addresses/pointers and integers but this is almost never necessary.
 
Nim allows to deactivate and reactivate checks in some zones using pragmas. It allows also to remove almost all checks by using option <code>-d:danger</code> when compiling. In this mode, the code is the most efficient, but at the price of safety.
 
=={{header|PARI/GP}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.