(* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. *) module import cstring, cstdio, cstdlib type ElnaLocation* = record line: Word; column: Word end ElnaPosition* = record start_location: ElnaLocation; end_location: ElnaLocation end proc write*#[T](fd: Int; buf: ^const T; size: Word) -> Int extern proc write_s*(value: []const Word8) write(1, value.ptr, value.length) return proc write_z*(value: ^Word8) write(1, value, strlen(value)) return proc write_b*(value: Bool) if value then write_s("true") else write_s("false") end return proc write_c*(value: Word8) putchar(cast(value: Int)); fflush(nil) return proc write_i*(value: Int) var digit: Int n: Word buffer: [10]Word8 begin n := 10u; if value = 0 then write_c('0') end; while value <> 0 do digit := value % 10; value := value / 10; buffer[n] := cast(cast('0': Int) + digit: Word8); n := n - 1u end; while n < 10u do n := n + 1u; write_c(buffer[n]) end return proc write_u*(value: Word) write_i(cast(value: Int)) return (* Returns true or false depending whether two strings are equal. *) proc string_compare*(lhs_pointer: ^Word8; lhs_length: Word; rhs_pointer: []const Word8) -> Bool var result: Bool begin if lhs_length = rhs_pointer.length then result := memcmp(lhs_pointer, rhs_pointer.ptr, lhs_length) = 0 else result := false end return result proc free_and_nil*#[T](ptr: ^T) -> ^T begin if ptr <> nil then free(ptr) end return nil end.