📄 types.zc
字号:
//[of]:description
//[c]Define types, provides utility functions for basic types
//[cf]
//[c]
//[of]:types
//[c]
public typedef mem = -> void
public typedef size = dword
public typedef object = -> void
public typedef string = [] char
public typedef o = octet
public typedef s = short
public typedef i = int
public typedef b = byte
public typedef w = word
public typedef d = dword
public typedef c = char
//[cf]
//[of]:debug utils
//[c]
public equ trap =
(nil : [] int) [] = 0
//[c]
public func assert (c: bool)
if ~ c
trap
end
end
//[cf]
//[of]:static interface
//[c]Static Interface
//[c]
//[c]This type is used to create an interface that expose only some
//[c]method of an existing implementation (static interface).
//[c]
//[c]A pointer of the original type is just cast to the sub-class
//[c]of this type.
//[c]
public struct static interface
// some C compilers require at least one field
dummy : int
end
//[cf]
//[c]
//[of]:int
//[c]
//[c]## move to base/numbers ?
//[c]
public equ unsigned (i: int) = i:dword
//[cf]
//[of]:char
//[of]:constants
//[c]
public equ nul char = \0
public equ lf char = \n
public equ cr char = \r
public equ tab char = \t
public equ space char = \w
//[cf]
//[c]
//[c]case conversion
//[of]:upper (c)
//[c]
public func upper (c: char)
if c >= $a && c <= $z
return c + ($A - $a)
end
return c
end
//[cf]
//[of]:lower (c)
//[c]
public func lower (c: char)
if c >= $A && c <= $Z
return c + ($a - $A)
end
return c
end
//[cf]
//[c]
//[c]testing
//[of]:is nul (c)
//[c]
public equ is nul (c: char) = c == nul char
//[cf]
//[of]:not nul (c)
//[c]
public equ not nul (c: char) = c <> nul char
//[cf]
//[of]:is alpha (c)
//[c]
public func is alpha (c: char)
return (c>=$a && c<=$z) || (c>=$A && c<=$Z)
end
//[cf]
//[of]:is digit (c)
//[c]
public func is digit (c: char)
return (c>=$0 && c<=$9)
end
//[cf]
//[of]:is hex digit (c)
//[c]
public func is hex digit (c: char)
return is digit (c) || (c>=$a && c<=$f) || (c>=$A && c<=$F)
end
//[cf]
//[of]:is blank (c)
//[c]
public func is blank (c: char)
return c == \w || c == \t
end
//[cf]
//[of]:is lower (c)
//[c]
public func is lower (c: char)
return c >= $a && c <= $z
end
//[cf]
//[of]:is upper (c)
//[c]
public func is upper (c: char)
return c >= $A && c <= $Z
end
//[cf]
//[cf]
//[of]:range
//[c]Range of two integers
//[c]
//[of]:structure
//[c]
public struct range
first: int
last: int
end
//[cf]
//[c]
//[c]initialize
//[of]:copy (src)
//[c]
public func copy (src: range, dst: range)
first (dst) = first (src)
last (dst) = last (src)
end
//[cf]
//[c]
//[c]testing
//[of]:is empty (r)
//[c]
public equ is empty (r: range) =
first (r) == last (r)
//[cf]
//[of]:not empty (r)
//[c]
public equ not empty (r: range) =
first (r) <> last (r)
//[cf]
//[of]:is equal (r, s)
//[c]
public equ is equal (r: range, s: range) =
(first (r) == first (s)) & (last (r) == last (s))
//[cf]
//[of]:not equal (r, s)
//[c]
public equ not equal (r: range, s: range) =
(first (r) <> first (s)) | (last (r) <> last (s))
//[cf]
//[c]
//[cf]
//[of]:unsigned range
//[c]Range of two unsigned integers
//[c]
//[of]:structure
//[c]
public struct unsigned range
first: dword
last: dword
end
//[cf]
//[c]
//[c]initialize
//[of]:copy (src)
//[c]
public func copy (src: unsigned range, dst: unsigned range)
first (dst) = first (src)
last (dst) = last (src)
end
//[cf]
//[c]
//[c]testing
//[of]:is empty (r)
//[c]
public equ is empty (r: unsigned range) =
first (r) == last (r)
//[cf]
//[of]:not empty (r)
//[c]
public equ not empty (r: unsigned range) =
first (r) <> last (r)
//[cf]
//[of]:is equal (r, s)
//[c]
public equ is equal (r: unsigned range, s: unsigned range) =
(first (r) == first (s)) & (last (r) == last (s))
//[cf]
//[of]:not equal (r, s)
//[c]
public equ not equal (r: unsigned range, s: unsigned range) =
(first (r) <> first (s)) | (last (r) <> last (s))
//[cf]
//[cf]
//[c]
//[of]:time
//[c]
public typedef time = int
public equ nil time = 0
//[cf]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -