zilch-lang / nstar

The compiler for N⋆, a statically typed assembly language used as a compiler backend for Zilch
BSD 3-Clause "New" or "Revised" License
28 stars 2 forks source link

unsafe blocks #14

Closed Mesabloo closed 3 years ago

Mesabloo commented 3 years ago

As seen in https://github.com/nihil-lang/nsc/issues/2#issuecomment-697162215, we will need to have some sort of unsafe blocks to encapsulate potential undefined behaviors, like pointer offsets or address dereferencing (the compiler can't determine that the address actually points to something valid).

Unsafe blocks would have a similar syntax to

# instructions
unsafe {
    # instructions
}
# instructions

where it encloses unsafe operations as described above. The compiler could also detect whether an instruction is really unsafe, or not, and probably throw a warning back, something like "This instruction be potentially not be unsafe. You could remove it from the enclosing unsafe block."

Mesabloo commented 3 years ago

Also, instead of having to put a complete block for one single instruction, we could allow this:

unsafe <instruction>

which would act the same as

unsafe {
  <instruction>
}

or

unsafe { <instruction> }