mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
vlib: fix typos and formatting (#19649)
This commit is contained in:
parent
fc2e75503f
commit
f98bb863ab
23 changed files with 152 additions and 154 deletions
|
@ -1095,7 +1095,7 @@ fn test_hex() {
|
|||
assert st1.hex() == '41'.repeat(100)
|
||||
}
|
||||
|
||||
fn test_left_shift_precendence() {
|
||||
fn test_left_shift_precedence() {
|
||||
mut arr := []int{}
|
||||
arr << 1 + 1
|
||||
arr << 1 - 1
|
||||
|
|
|
@ -11,7 +11,7 @@ pub mut:
|
|||
f_reserved [2]u64
|
||||
f_index u32
|
||||
f_size u32
|
||||
f_mod_base u64 // Base Address of module comtaining this symbol
|
||||
f_mod_base u64 // Base Address of module containing this symbol
|
||||
f_flags u32
|
||||
f_value u64 // Value of symbol, ValuePresent should be 1
|
||||
f_address u64 // Address of symbol including base address of module
|
||||
|
|
|
@ -14,7 +14,7 @@ struct array_buffer {
|
|||
|
||||
fn (mut a array_buffer) make_copy() {
|
||||
if a.index_start != 0 || a.has_slice {
|
||||
mut new_arr := JS.makeEmtpyJSArray()
|
||||
mut new_arr := JS.makeEmptyJSArray()
|
||||
for i in 0 .. a.len {
|
||||
#new_arr.push(a.val.get(i))
|
||||
|
||||
|
@ -148,10 +148,10 @@ pub fn (a array) repeat(count int) array {
|
|||
}
|
||||
|
||||
#function makeEmptyArray() { return new array(new array_buffer({ arr: [], len: new int(0), index_start: new int(0), cap: new int(0) })); }
|
||||
#function makeEmtpyJSArray() { return new Array(); }
|
||||
#function makeEmptyJSArray() { return new Array(); }
|
||||
|
||||
fn JS.makeEmptyArray() array
|
||||
fn JS.makeEmtpyJSArray() JS.Array
|
||||
fn JS.makeEmptyJSArray() JS.Array
|
||||
fn empty_array() array {
|
||||
return JS.makeEmptyArray()
|
||||
}
|
||||
|
@ -222,13 +222,13 @@ fn v_filter(arr array, callback fn (voidptr) bool) array {
|
|||
}
|
||||
|
||||
fn v_map(arr array, callback fn (voidptr) voidptr) array {
|
||||
mut maped := empty_array()
|
||||
mut mapped := empty_array()
|
||||
|
||||
for i := 0; i < arr.arr.len; i++ {
|
||||
maped.push(callback(arr.arr.get(i)))
|
||||
mapped.push(callback(arr.arr.get(i)))
|
||||
}
|
||||
|
||||
return maped
|
||||
return mapped
|
||||
}
|
||||
|
||||
struct array_iterator {
|
||||
|
|
|
@ -1052,7 +1052,7 @@ fn test_hex() {
|
|||
assert st1.hex() == '41'.repeat(100)
|
||||
}*/
|
||||
|
||||
fn test_left_shift_precendence() {
|
||||
fn test_left_shift_precedence() {
|
||||
mut arr := []int{}
|
||||
arr << 1 + 1
|
||||
arr << 1 - 1
|
||||
|
|
|
@ -32,7 +32,7 @@ fn test_str_methods() {
|
|||
// assert u64(-1).str() == '18446744073709551615'
|
||||
}
|
||||
|
||||
fn test_and_precendence() {
|
||||
fn test_and_precedence() {
|
||||
assert (2 & 0 == 0) == ((2 & 0) == 0)
|
||||
assert (2 & 0 != 0) == ((2 & 0) != 0)
|
||||
assert (0 & 0 >= 0) == ((0 & 0) >= 0)
|
||||
|
@ -41,7 +41,7 @@ fn test_and_precendence() {
|
|||
assert (1 & 2 > 0) == ((1 & 2) > 0)
|
||||
}
|
||||
|
||||
fn test_or_precendence() {
|
||||
fn test_or_precedence() {
|
||||
assert (1 | 0 == 0) == ((1 | 0) == 0)
|
||||
assert (1 | 0 != 1) == ((1 | 0) != 1)
|
||||
assert (1 | 0 >= 2) == ((1 | 0) >= 2)
|
||||
|
@ -50,7 +50,7 @@ fn test_or_precendence() {
|
|||
assert (1 | 0 > 1) == ((1 | 0) > 1)
|
||||
}
|
||||
|
||||
fn test_xor_precendence() {
|
||||
fn test_xor_precedence() {
|
||||
assert (1 ^ 0 == 2) == ((1 ^ 0) == 2)
|
||||
assert (1 ^ 0 != 2) == ((1 ^ 0) != 2)
|
||||
assert (1 ^ 0 >= 0) == ((1 ^ 0) >= 0)
|
||||
|
@ -59,12 +59,12 @@ fn test_xor_precendence() {
|
|||
assert (1 ^ 0 > 1) == ((1 ^ 0) > 1)
|
||||
}
|
||||
|
||||
fn test_left_shift_precendence() {
|
||||
fn test_left_shift_precedence() {
|
||||
assert (2 << 4 | 3) == ((2 << 4) | 3)
|
||||
assert (2 << 4 | 3) != (2 << (4 | 3))
|
||||
}
|
||||
|
||||
fn test_right_shift_precendence() {
|
||||
fn test_right_shift_precedence() {
|
||||
assert (256 >> 4 | 3) == ((256 >> 4) | 3)
|
||||
assert (256 >> 4 | 3) != (256 >> (4 | 3))
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module builtin
|
||||
|
||||
pub interface JS.Promise {
|
||||
then(onFullfilled JS.Any, onRejected JS.Any)
|
||||
then(onFullfiled JS.Any, onRejected JS.Any)
|
||||
catch(onCatch JS.Any) JS.Promise
|
||||
finally(callback JS.Any) JS.Promise
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ pub fn promise_new[T](executor fn (resolve fn (T), reject fn (JS.Any))) Promise[
|
|||
return Promise[T]{promise}
|
||||
}
|
||||
|
||||
pub fn (p Promise[T]) then(on_fullfilled fn (T), on_rejected fn (JS.Any)) {
|
||||
p.promise.then(on_fullfilled, on_rejected)
|
||||
pub fn (p Promise[T]) then(on_fulfilled fn (T), on_rejected fn (JS.Any)) {
|
||||
p.promise.then(on_fulfilled, on_rejected)
|
||||
}
|
||||
|
||||
// catch method returns a Promise and deals with rejected cases only.
|
||||
|
|
|
@ -669,7 +669,7 @@ https://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/
|
|||
239 sys_get_mempolicy int *policy unsigned long *nmask unsigned long maxnode unsigned long addr unsigned long flags
|
||||
240 sys_mq_open const char *u_name int oflag mode_t mode struct mq_attr *u_attr
|
||||
241 sys_mq_unlink const char *u_name
|
||||
242 sys_mq_timedsend mqd_t mqdes const char *u_msg_ptr size_t msg_len unsigned int msg_prio const stuct timespec *u_abs_timeout
|
||||
242 sys_mq_timedsend mqd_t mqdes const char *u_msg_ptr size_t msg_len unsigned int msg_prio const struct timespec *u_abs_timeout
|
||||
243 sys_mq_timedreceive mqd_t mqdes char *u_msg_ptr size_t msg_len unsigned int *u_msg_prio const struct timespec *u_abs_timeout
|
||||
244 sys_mq_notify mqd_t mqdes const struct sigevent *u_notification
|
||||
245 sys_mq_getsetattr mqd_t mqdes const struct mq_attr *u_mqstat struct mq_attr *u_omqstat
|
||||
|
|
|
@ -101,7 +101,7 @@ fn abs64(x i64) u64 {
|
|||
//_9876543210987654321098765432109876543210
|
||||
//_nPPPPPPPPBBBBWWWWWWWWWWTDDDDDDDSUAA=====
|
||||
// = data type 5 bit max 32 data type
|
||||
// A allign 2 bit Note: for now only 1 used!
|
||||
// A align 2 bit Note: for now only 1 used!
|
||||
// U uppercase 1 bit 0 do nothing, 1 do to_upper()
|
||||
// S sign 1 bit show the sign if positive
|
||||
// D decimals 7 bit number of decimals digit to show
|
||||
|
@ -116,7 +116,7 @@ fn abs64(x i64) u64 {
|
|||
// convert from data format to compact u64
|
||||
pub fn get_str_intp_u64_format(fmt_type StrIntpType, in_width int, in_precision int, in_tail_zeros bool, in_sign bool, in_pad_ch u8, in_base int, in_upper_case bool) u64 {
|
||||
width := if in_width != 0 { abs64(in_width) } else { u64(0) }
|
||||
allign := if in_width > 0 { u64(1 << 5) } else { u64(0) } // two bit 0 .left 1 .rigth, for now we use only one
|
||||
align := if in_width > 0 { u64(1 << 5) } else { u64(0) } // two bit 0 .left 1 .right, for now we use only one
|
||||
upper_case := if in_upper_case { u64(1 << 7) } else { u64(0) }
|
||||
sign := if in_sign { u64(1 << 8) } else { u64(0) }
|
||||
precision := if in_precision != 987698 {
|
||||
|
@ -126,14 +126,14 @@ pub fn get_str_intp_u64_format(fmt_type StrIntpType, in_width int, in_precision
|
|||
}
|
||||
tail_zeros := if in_tail_zeros { u32(1) << 16 } else { u32(0) }
|
||||
base := u64(u32(in_base & 0xf) << 27)
|
||||
res := u64((u64(fmt_type) & 0x1F) | allign | upper_case | sign | precision | tail_zeros | (u64(width & 0x3FF) << 17) | base | (u64(in_pad_ch) << 31))
|
||||
res := u64((u64(fmt_type) & 0x1F) | align | upper_case | sign | precision | tail_zeros | (u64(width & 0x3FF) << 17) | base | (u64(in_pad_ch) << 31))
|
||||
return res
|
||||
}
|
||||
|
||||
// convert from data format to compact u32
|
||||
pub fn get_str_intp_u32_format(fmt_type StrIntpType, in_width int, in_precision int, in_tail_zeros bool, in_sign bool, in_pad_ch u8, in_base int, in_upper_case bool) u32 {
|
||||
width := if in_width != 0 { abs64(in_width) } else { u32(0) }
|
||||
allign := if in_width > 0 { u32(1 << 5) } else { u32(0) } // two bit 0 .left 1 .rigth, for now we use only one
|
||||
align := if in_width > 0 { u32(1 << 5) } else { u32(0) } // two bit 0 .left 1 .right, for now we use only one
|
||||
upper_case := if in_upper_case { u32(1 << 7) } else { u32(0) }
|
||||
sign := if in_sign { u32(1 << 8) } else { u32(0) }
|
||||
precision := if in_precision != 987698 {
|
||||
|
@ -143,7 +143,7 @@ pub fn get_str_intp_u32_format(fmt_type StrIntpType, in_width int, in_precision
|
|||
}
|
||||
tail_zeros := if in_tail_zeros { u32(1) << 16 } else { u32(0) }
|
||||
base := u32(u32(in_base & 0xf) << 27)
|
||||
res := u32((u32(fmt_type) & 0x1F) | allign | upper_case | sign | precision | tail_zeros | (u32(width & 0x3FF) << 17) | base | (u32(in_pad_ch & 1) << 31))
|
||||
res := u32((u32(fmt_type) & 0x1F) | align | upper_case | sign | precision | tail_zeros | (u32(width & 0x3FF) << 17) | base | (u32(in_pad_ch & 1) << 31))
|
||||
return res
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ pub fn get_str_intp_u32_format(fmt_type StrIntpType, in_width int, in_precision
|
|||
fn (data &StrIntpData) process_str_intp_data(mut sb strings.Builder) {
|
||||
x := data.fmt
|
||||
typ := unsafe { StrIntpType(x & 0x1F) }
|
||||
allign := int((x >> 5) & 0x01)
|
||||
align := int((x >> 5) & 0x01)
|
||||
upper_case := ((x >> 7) & 0x01) > 0
|
||||
sign := int((x >> 8) & 0x01)
|
||||
precision := int((x >> 9) & 0x7F)
|
||||
|
@ -166,7 +166,7 @@ fn (data &StrIntpData) process_str_intp_data(mut sb strings.Builder) {
|
|||
return
|
||||
}
|
||||
|
||||
// if width > 0 { println("${x.hex()} Type: ${x & 0x7F} Width: ${width} Precision: ${precision} allign:${allign}") }
|
||||
// if width > 0 { println("${x.hex()} Type: ${x & 0x7F} Width: ${width} Precision: ${precision} align:${align}") }
|
||||
|
||||
// manage base if any
|
||||
if base > 0 {
|
||||
|
@ -190,20 +190,20 @@ fn (data &StrIntpData) process_str_intp_data(mut sb strings.Builder) {
|
|||
len1: len1_set // number of decimal digits, if needed
|
||||
positive: true // mandatory: the sign of the number passed
|
||||
sign_flag: sign_set // flag for print sign as prefix in padding
|
||||
allign: .left // alignment of the string
|
||||
align: .left // alignment of the string
|
||||
rm_tail_zero: tail_zeros // false // remove the tail zeros from floats
|
||||
}
|
||||
|
||||
// allign
|
||||
// align
|
||||
if fmt_pad_ch == 0 {
|
||||
match allign {
|
||||
0 { bf.allign = .left }
|
||||
1 { bf.allign = .right }
|
||||
// 2 { bf.allign = .center }
|
||||
else { bf.allign = .left }
|
||||
match align {
|
||||
0 { bf.align = .left }
|
||||
1 { bf.align = .right }
|
||||
// 2 { bf.align = .center }
|
||||
else { bf.align = .left }
|
||||
}
|
||||
} else {
|
||||
bf.allign = .right
|
||||
bf.align = .right
|
||||
}
|
||||
|
||||
unsafe {
|
||||
|
@ -708,7 +708,7 @@ pub fn str_intp_g64(in_str string) string {
|
|||
[manualfree]
|
||||
pub fn str_intp_sub(base_str string, in_str string) string {
|
||||
index := base_str.index('%%') or {
|
||||
eprintln('No strin interpolation %% parameteres')
|
||||
eprintln('No string interpolation %% parameters')
|
||||
exit(1)
|
||||
}
|
||||
// return base_str[..index] + in_str + base_str[index+2..]
|
||||
|
|
|
@ -52,7 +52,7 @@ fn (mut f Flag) free() {
|
|||
// str returns a string representation of the given Flag
|
||||
pub fn (f Flag) str() string {
|
||||
return '' + ' flag:\n' + ' name: ${f.name}\n' +
|
||||
' abbr: `${f.abbr.ascii_str()}`\n' + ' usag: ${f.usage}\n' +
|
||||
' abbr: `${f.abbr.ascii_str()}`\n' + ' usage: ${f.usage}\n' +
|
||||
' desc: ${f.val_desc}'
|
||||
}
|
||||
|
||||
|
@ -266,7 +266,7 @@ fn (mut fs FlagParser) parse_value(longhand string, shorthand u8) []string {
|
|||
}
|
||||
}
|
||||
for i, del in to_delete {
|
||||
// i entrys are deleted so it's shifted left i times.
|
||||
// i entries are deleted so it's shifted left i times.
|
||||
fs.args.delete(del - i)
|
||||
}
|
||||
return found_entries
|
||||
|
|
|
@ -236,7 +236,7 @@ fn test_could_expect_no_free_args() {
|
|||
assert args.len < 0 // expect an error and need to use args
|
||||
}
|
||||
|
||||
fn test_allow_abreviations() {
|
||||
fn test_allow_abbreviations() {
|
||||
mut fp := flag.new_flag_parser(['-v', '-o', 'some_file', '-i', '42', '-f', '2.0'])
|
||||
v := fp.bool('version', `v`, false, '')
|
||||
o := fp.string('output', `o`, 'empty', '')
|
||||
|
|
|
@ -923,7 +923,7 @@ pub fn (ctx &Context) draw_ellipse_empty(x f32, y f32, rw f32, rh f32, c gx.Colo
|
|||
sgl.end()
|
||||
}
|
||||
|
||||
// draw_ellipse_filled draws an opaque elipse.
|
||||
// draw_ellipse_filled draws an opaque ellipse.
|
||||
// `x`,`y` defines the center of the ellipse.
|
||||
// `rw` defines the *width* radius of the ellipse.
|
||||
// `rh` defines the *height* radius of the ellipse.
|
||||
|
|
|
@ -1,24 +1,25 @@
|
|||
#include <Cocoa/Cocoa.h>
|
||||
|
||||
NSColor* nscolor(gx__Color c) {
|
||||
float red= (float)c.r / 255.0f;
|
||||
float green= (float)c.g / 255.0f;
|
||||
float blue= (float)c.b / 255.0f;
|
||||
return [NSColor colorWithDeviceRed:red green:green blue:blue alpha:1.0f];
|
||||
float red = (float)c.r / 255.0f;
|
||||
float green = (float)c.g / 255.0f;
|
||||
float blue = (float)c.b / 255.0f;
|
||||
return [NSColor colorWithDeviceRed:red green:green blue:blue alpha:1.0f];
|
||||
}
|
||||
|
||||
NSString* nsstring(string s) {
|
||||
return [ [ NSString alloc ] initWithBytesNoCopy:s.str length:s.len
|
||||
encoding:NSUTF8StringEncoding freeWhenDone: false];
|
||||
return [[NSString alloc] initWithBytesNoCopy:s.str
|
||||
length:s.len
|
||||
encoding:NSUTF8StringEncoding
|
||||
freeWhenDone:false];
|
||||
}
|
||||
|
||||
|
||||
gg__Size gg_get_screen_size() {
|
||||
NSScreen *screen = [NSScreen mainScreen];
|
||||
NSDictionary *description = [screen deviceDescription];
|
||||
NSScreen* screen = [NSScreen mainScreen];
|
||||
NSDictionary* description = [screen deviceDescription];
|
||||
NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue];
|
||||
CGSize displayPhysicalSize = CGDisplayScreenSize(
|
||||
[[description objectForKey:@"NSScreenNumber"] unsignedIntValue]);
|
||||
CGSize displayPhysicalSize =
|
||||
CGDisplayScreenSize([[description objectForKey:@"NSScreenNumber"] unsignedIntValue]);
|
||||
gg__Size res;
|
||||
res.width = displayPixelSize.width;
|
||||
res.height = displayPixelSize.height;
|
||||
|
@ -26,33 +27,31 @@ gg__Size gg_get_screen_size() {
|
|||
}
|
||||
|
||||
void darwin_draw_string(int x, int y, string s, gx__TextCfg cfg) {
|
||||
NSFont* font = [NSFont userFontOfSize: 0]; //cfg.size];
|
||||
// # NSFont* font = [NSFont fontWithName:@"Roboto Mono" size:cfg.size];
|
||||
if (cfg.mono) {
|
||||
// # font = [NSFont fontWithName:@"Roboto Mono" size:cfg.size];
|
||||
font = [NSFont fontWithName:@"Menlo" size:cfg.size-5];
|
||||
}
|
||||
if (cfg.bold) {
|
||||
font = [[NSFontManager sharedFontManager] convertFont:font toHaveTrait:NSBoldFontMask];
|
||||
}
|
||||
|
||||
NSFont* font = [NSFont userFontOfSize:0]; // cfg.size];
|
||||
// # NSFont* font = [NSFont fontWithName:@"Roboto Mono" size:cfg.size];
|
||||
if (cfg.mono) {
|
||||
// # font = [NSFont fontWithName:@"Roboto Mono" size:cfg.size];
|
||||
font = [NSFont fontWithName:@"Menlo" size:cfg.size - 5];
|
||||
}
|
||||
if (cfg.bold) {
|
||||
font = [[NSFontManager sharedFontManager] convertFont:font toHaveTrait:NSBoldFontMask];
|
||||
}
|
||||
|
||||
NSDictionary* attr = @{
|
||||
NSForegroundColorAttributeName: nscolor(cfg.color),
|
||||
//NSParagraphStyleAttributeName: paragraphStyle,
|
||||
NSFontAttributeName: font,
|
||||
};
|
||||
[nsstring(s) drawAtPoint:NSMakePoint(x,y-15) withAttributes:attr];
|
||||
NSForegroundColorAttributeName : nscolor(cfg.color),
|
||||
// NSParagraphStyleAttributeName: paragraphStyle,
|
||||
NSFontAttributeName : font,
|
||||
};
|
||||
[nsstring(s) drawAtPoint:NSMakePoint(x, y - 15) withAttributes:attr];
|
||||
}
|
||||
|
||||
int darwin_text_width(string s) {
|
||||
// println('text_width "$s" len=$s.len')
|
||||
NSString* n = @"";
|
||||
if (s.len == 1) {
|
||||
// println('len=1')
|
||||
n=[NSString stringWithFormat:@"%c" , s.str[0]];
|
||||
}
|
||||
else {
|
||||
// println('len=1')
|
||||
n = [NSString stringWithFormat:@"%c", s.str[0]];
|
||||
} else {
|
||||
n = nsstring(s);
|
||||
}
|
||||
/*
|
||||
|
@ -75,51 +74,49 @@ void darwin_draw_rect(float x, float y, float width, float height, gx__Color c)
|
|||
NSRectFill(rect);
|
||||
}
|
||||
|
||||
|
||||
void darwin_window_refresh() {
|
||||
//[g_view setNeedsDisplay:YES];
|
||||
// update UI on the main thread TODO separate fn
|
||||
// update UI on the main thread TODO separate fn
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[g_view setNeedsDisplay:YES];
|
||||
});
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[g_view setNeedsDisplay:YES];
|
||||
});
|
||||
|
||||
//puts("refresh");
|
||||
// puts("refresh");
|
||||
//[g_view drawRect:NSMakeRect(0,0,2000,2000)];
|
||||
//[[NSGraphicsContext currentContext] flushGraphics];
|
||||
}
|
||||
|
||||
gg__Image darwin_create_image(string path_) {
|
||||
// file = file.trim_space()
|
||||
// file = file.trim_space()
|
||||
NSString* path = nsstring(path_);
|
||||
NSImage* img = [[NSImage alloc] initWithContentsOfFile:path];
|
||||
NSImage* img = [[NSImage alloc] initWithContentsOfFile:path];
|
||||
if (img == 0) {
|
||||
}
|
||||
NSSize size = [img size];
|
||||
NSSize size = [img size];
|
||||
gg__Image res;
|
||||
res.width = size.width;
|
||||
res.height = size.height;
|
||||
res.width = size.width;
|
||||
res.height = size.height;
|
||||
res.path = path_;
|
||||
res.ok = true;
|
||||
//printf("inited img width=%d\n", res.width) ;
|
||||
// need __brige_retained so that the pointer is not freed by ARC
|
||||
res.data = (__bridge_retained voidptr)(img);
|
||||
// printf("inited img width=%d\n", res.width) ;
|
||||
// need __brige_retained so that the pointer is not freed by ARC
|
||||
res.data = (__bridge_retained voidptr)(img);
|
||||
return res;
|
||||
}
|
||||
|
||||
void darwin_draw_image(float x, float y, float w, float h, gg__Image* img) {
|
||||
NSImage* i= (__bridge NSImage*)(img->data);
|
||||
[i drawInRect:NSMakeRect(x,y,w,h)];
|
||||
NSImage* i = (__bridge NSImage*)(img->data);
|
||||
[i drawInRect:NSMakeRect(x, y, w, h)];
|
||||
}
|
||||
|
||||
void darwin_draw_circle(float x, float y, float d, gx__Color color) {
|
||||
NSColor* c = nscolor(color);
|
||||
NSRect rect = NSMakeRect(x, y, d * 2, d * 2);
|
||||
void darwin_draw_circle(float x, float y, float d, gx__Color color) {
|
||||
NSColor* c = nscolor(color);
|
||||
NSRect rect = NSMakeRect(x, y, d * 2, d * 2);
|
||||
NSBezierPath* circlePath = [NSBezierPath bezierPath];
|
||||
[circlePath appendBezierPathWithOvalInRect: rect];
|
||||
[circlePath appendBezierPathWithOvalInRect:rect];
|
||||
[c setFill];
|
||||
// [circlePath stroke];
|
||||
[circlePath fill];
|
||||
// NSRectFill(rect);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import stbi
|
|||
import sokol.gfx
|
||||
import sokol.sgl
|
||||
|
||||
// Image holds the fileds and data needed to
|
||||
// Image holds the fields and data needed to
|
||||
// represent a bitmap/pixel based image in memory.
|
||||
[heap]
|
||||
pub struct Image {
|
||||
|
|
|
@ -27,7 +27,7 @@ pub fn (x Vec4) str() string {
|
|||
return '|${x.e[0]:-6.3},${x.e[1]:-6.3},${x.e[2]:-6.3},${x.e[3]:-6.3}|'
|
||||
}
|
||||
|
||||
// create a Vec4 function passing x,y,z as parameteres. w is set to 1
|
||||
// create a Vec4 function passing x,y,z as parameters. w is set to 1
|
||||
pub fn vec3(x f32, y f32, z f32) Vec4 {
|
||||
return Vec4{
|
||||
e: [x, y, z, 1]!
|
||||
|
|
2
vlib/gg/testdata/draw_elipses.vv
vendored
2
vlib/gg/testdata/draw_elipses.vv
vendored
|
@ -7,7 +7,7 @@ fn main() {
|
|||
mut context := gg.new_context(
|
||||
width: 200
|
||||
height: 200
|
||||
window_title: 'Elipses'
|
||||
window_title: 'Ellipses'
|
||||
frame_fn: frame
|
||||
)
|
||||
context.run()
|
||||
|
|
|
@ -107,7 +107,7 @@ pub fn ntoh16(net u16) u16 {
|
|||
// The returned array length .len, will be in [1,2,4,8] .
|
||||
pub fn u64tovarint(n u64) ![]u8 {
|
||||
if n > u64(1) << 62 {
|
||||
return error('cannnot encode more than 2^62-1')
|
||||
return error('cannot encode more than 2^62-1')
|
||||
}
|
||||
msb := match true {
|
||||
n < 64 {
|
||||
|
|
|
@ -43,15 +43,15 @@ The syntax for a format specifier is:
|
|||
|
||||
The Flags field may be zero or more (in any order) of:
|
||||
|
||||
| Character | Description |
|
||||
| ----------- | ------------------------------------------------------------ |
|
||||
| `-` (minus) | Left-align the output of this specifier. (The default is to right-align the output.) |
|
||||
| `+` (plus) | Prepends a plus for positive signed-numeric types. positive = `+`, negative = `-`. (The default doesn't prepend anything to positive numbers.) |
|
||||
| Character | Description |
|
||||
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| `-` (minus) | Left-align the output of this specifier. (The default is to right-align the output.) |
|
||||
| `+` (plus) | Prepends a plus for positive signed-numeric types. positive = `+`, negative = `-`. (The default doesn't prepend anything to positive numbers.) |
|
||||
| `0` (zero) | When the 'width' option is specified, prepends zeros for numeric types. (The default prepends spaces.) For example, `printf("%4X",3)` produces ` 3`, while `printf("%04X",3)` produces `0003`. |
|
||||
|
||||
#### Width field
|
||||
|
||||
The Width field specifies a *maximum* number of characters to output,
|
||||
The Width field specifies a _maximum_ number of characters to output,
|
||||
and is typically used to pad fixed-width fields in tabulated output,
|
||||
it causes truncation of oversized fields.
|
||||
|
||||
|
@ -64,31 +64,31 @@ with a total width of 5 characters.
|
|||
|
||||
The Length field can be omitted or be any of:
|
||||
|
||||
| Character | Description |
|
||||
| --------- | ------------------------------------------------------------ |
|
||||
| `hh` | For integer types, causes `printf` to expect an `byte` or `i8` argument. |
|
||||
| Character | Description |
|
||||
| --------- | -------------------------------------------------------------------------- |
|
||||
| `hh` | For integer types, causes `printf` to expect an `byte` or `i8` argument. |
|
||||
| `h` | For integer types, causes `printf` to expect an `int16` or `u16` argument. |
|
||||
| `l` | For integer types, causes `printf` to expect an `i64` or `u64` argument. |
|
||||
| `ll` | For integer types, causes `printf` to expect an `i64` or `u64` argument. |
|
||||
| | |
|
||||
| | |
|
||||
| `l` | For integer types, causes `printf` to expect an `i64` or `u64` argument. |
|
||||
| `ll` | For integer types, causes `printf` to expect an `i64` or `u64` argument. |
|
||||
| | |
|
||||
| | |
|
||||
|
||||
#### Type field
|
||||
|
||||
The Type field can be any of:
|
||||
|
||||
| Character | Description |
|
||||
| --------- | ------------------------------------------------------------ |
|
||||
| `%` | Prints a literal `%` character (this type doesn't accept any flags, width, precision, length fields). |
|
||||
| Character | Description |
|
||||
| --------- | --------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `%` | Prints a literal `%` character (this type doesn't accept any flags, width, precision, length fields). |
|
||||
| `d`, `i` | `int` as a signed `int` `%d` and `%i` are synonymous for output. The size of the argument is specified by the length field. |
|
||||
| `u` | `unsigned int`. The size of the argument is specified by the length field. |
|
||||
| `f`, `F` | `double` in normal notation. `f` and `F` only differs in how the strings are printed: lowercase or uppercase. |
|
||||
| `e`, `E` | `double` in scientific notation.`e` and `E` only differs in how the strings are printed: lowercase or uppercase. |
|
||||
| `g`, `G` | `double` in automatic notation.`g` and `G` only differs in how the strings are printed: lowercase or uppercase. |
|
||||
| `x`, `X` | `unsigned int` as a hexadecimal number. `x` uses lower-case letters and `X` uses upper-case. |
|
||||
| `s` | string |
|
||||
| `p` | `void *` (pointer to void) in an implementation-defined format. |
|
||||
| `c` | `char` (character). |
|
||||
| `u` | `unsigned int`. The size of the argument is specified by the length field. |
|
||||
| `f`, `F` | `double` in normal notation. `f` and `F` only differs in how the strings are printed: lowercase or uppercase. |
|
||||
| `e`, `E` | `double` in scientific notation.`e` and `E` only differs in how the strings are printed: lowercase or uppercase. |
|
||||
| `g`, `G` | `double` in automatic notation.`g` and `G` only differs in how the strings are printed: lowercase or uppercase. |
|
||||
| `x`, `X` | `unsigned int` as a hexadecimal number. `x` uses lower-case letters and `X` uses upper-case. |
|
||||
| `s` | string |
|
||||
| `p` | `void *` (pointer to void) in an implementation-defined format. |
|
||||
| `c` | `char` (character). |
|
||||
|
||||
## Examples
|
||||
|
||||
|
@ -244,7 +244,7 @@ struct BF_param {
|
|||
len1 int = 6 // number of decimal digits, if needed
|
||||
positive bool = true // mandatory: the sign of the number passed
|
||||
sign_flag bool = false // flag for print sign as prefix in padding
|
||||
allign Align_text = .right // alignment of the string
|
||||
align Align_text = .right // alignment of the string
|
||||
rm_tail_zero bool = false // remove the tail zeros from floats
|
||||
}
|
||||
|
||||
|
|
|
@ -85,8 +85,9 @@ pub mut:
|
|||
len1 int = 6 // number of decimal digits, if needed
|
||||
positive bool = true // mandatory: the sign of the number passed
|
||||
sign_flag bool // flag for print sign as prefix in padding
|
||||
allign Align_text = .right // alignment of the string
|
||||
rm_tail_zero bool // remove the tail zeros from floats
|
||||
align Align_text = .right // alignment of the string
|
||||
allign Align_text [deprecated: 'use align instead'; deprecated_after: '2023-11-30'] = .right
|
||||
rm_tail_zero bool // remove the tail zeros from floats
|
||||
}
|
||||
|
||||
// format_str returns a `string` formatted according to the options set in `p`.
|
||||
|
@ -103,13 +104,13 @@ pub fn format_str(s string, p BF_param) string {
|
|||
defer {
|
||||
unsafe { res.free() }
|
||||
}
|
||||
if p.allign == .right {
|
||||
if p.align == .right {
|
||||
for i1 := 0; i1 < dif; i1++ {
|
||||
res.write_u8(p.pad_ch)
|
||||
}
|
||||
}
|
||||
res.write_string(s)
|
||||
if p.allign == .left {
|
||||
if p.align == .left {
|
||||
for i1 := 0; i1 < dif; i1++ {
|
||||
res.write_u8(p.pad_ch)
|
||||
}
|
||||
|
|
|
@ -21,13 +21,13 @@ pub fn format_str_sb(s string, p BF_param, mut sb strings.Builder) {
|
|||
return
|
||||
}
|
||||
|
||||
if p.allign == .right {
|
||||
if p.align == .right {
|
||||
for i1 := 0; i1 < dif; i1++ {
|
||||
sb.write_u8(p.pad_ch)
|
||||
}
|
||||
}
|
||||
sb.write_string(s)
|
||||
if p.allign == .left {
|
||||
if p.align == .left {
|
||||
for i1 := 0; i1 < dif; i1++ {
|
||||
sb.write_u8(p.pad_ch)
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) {
|
|||
dif := p.len0 - number_len
|
||||
mut sign_written := false
|
||||
|
||||
if p.allign == .right {
|
||||
if p.align == .right {
|
||||
if p.pad_ch == `0` {
|
||||
if p.positive {
|
||||
if p.sign_flag {
|
||||
|
@ -127,7 +127,7 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) {
|
|||
}
|
||||
//===========================================
|
||||
|
||||
if p.allign == .left {
|
||||
if p.align == .left {
|
||||
for i1 := 0; i1 < dif; i1++ {
|
||||
res.write_u8(p.pad_ch)
|
||||
}
|
||||
|
@ -365,7 +365,7 @@ pub fn format_fl(f f64, p BF_param) string {
|
|||
|
||||
// make the padding if needed
|
||||
dif := p.len0 - buf_i + sign_len_diff
|
||||
if p.allign == .right {
|
||||
if p.align == .right {
|
||||
for i1 := 0; i1 < dif; i1++ {
|
||||
out[out_i] = p.pad_ch
|
||||
out_i++
|
||||
|
@ -373,7 +373,7 @@ pub fn format_fl(f f64, p BF_param) string {
|
|||
}
|
||||
vmemcpy(&out[out_i], &buf[0], buf_i)
|
||||
out_i += buf_i
|
||||
if p.allign == .left {
|
||||
if p.align == .left {
|
||||
for i1 := 0; i1 < dif; i1++ {
|
||||
out[out_i] = p.pad_ch
|
||||
out_i++
|
||||
|
@ -436,7 +436,7 @@ pub fn format_es(f f64, p BF_param) string {
|
|||
|
||||
// make the padding if needed
|
||||
dif := p.len0 - buf_i + sign_len_diff
|
||||
if p.allign == .right {
|
||||
if p.align == .right {
|
||||
for i1 := 0; i1 < dif; i1++ {
|
||||
out[out_i] = p.pad_ch
|
||||
out_i++
|
||||
|
@ -444,7 +444,7 @@ pub fn format_es(f f64, p BF_param) string {
|
|||
}
|
||||
vmemcpy(&out[out_i], &buf[0], buf_i)
|
||||
out_i += buf_i
|
||||
if p.allign == .left {
|
||||
if p.align == .left {
|
||||
for i1 := 0; i1 < dif; i1++ {
|
||||
out[out_i] = p.pad_ch
|
||||
out_i++
|
||||
|
|
|
@ -15,7 +15,7 @@ pub fn format_str_sb(s string, p BF_param, mut sb strings.Builder) {
|
|||
return
|
||||
}
|
||||
|
||||
if p.allign == .right {
|
||||
if p.align == .right {
|
||||
for i1 := 0; i1 < dif; i1++ {
|
||||
sb.write_u8(p.pad_ch)
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ pub fn format_str_sb(s string, p BF_param, mut sb strings.Builder) {
|
|||
|
||||
sb.write_string(s)
|
||||
|
||||
if p.allign == .left {
|
||||
if p.align == .left {
|
||||
for i1 := 0; i1 < dif; i1++ {
|
||||
sb.write_u8(p.pad_ch)
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) {
|
|||
dif := p.len0 - number_len
|
||||
mut sign_written := false
|
||||
|
||||
if p.allign == .right {
|
||||
if p.align == .right {
|
||||
if p.pad_ch == `0` {
|
||||
if p.positive {
|
||||
if p.sign_flag {
|
||||
|
@ -94,7 +94,7 @@ pub fn format_dec_sb(d u64, p BF_param, mut res strings.Builder) {
|
|||
|
||||
//===========================================
|
||||
|
||||
if p.allign == .left {
|
||||
if p.align == .left {
|
||||
for i1 := 0; i1 < dif; i1++ {
|
||||
res.write_u8(p.pad_ch)
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ pub fn v_sprintf(str string, pt ...voidptr) string {
|
|||
mut i := 0 // main string index
|
||||
mut p_index := 0 // parameter index
|
||||
mut sign := false // sign flag
|
||||
mut allign := Align_text.right
|
||||
mut align := Align_text.right
|
||||
mut len0 := -1 // forced length, if -1 free length
|
||||
mut len1 := -1 // decimal part for floats
|
||||
def_len1 := 6 // default value for len1
|
||||
|
@ -66,7 +66,7 @@ pub fn v_sprintf(str string, pt ...voidptr) string {
|
|||
for i < str.len {
|
||||
if status == .reset_params {
|
||||
sign = false
|
||||
allign = .right
|
||||
align = .right
|
||||
len0 = -1
|
||||
len1 = -1
|
||||
pad_ch = ` `
|
||||
|
@ -130,11 +130,11 @@ pub fn v_sprintf(str string, pt ...voidptr) string {
|
|||
i++
|
||||
continue
|
||||
} else if ch == `-` {
|
||||
allign = .left
|
||||
align = .left
|
||||
i++
|
||||
continue
|
||||
} else if ch in [`0`, ` `] {
|
||||
if allign == .right {
|
||||
if align == .right {
|
||||
pad_ch = ch
|
||||
}
|
||||
i++
|
||||
|
@ -298,7 +298,7 @@ pub fn v_sprintf(str string, pt ...voidptr) string {
|
|||
len1: 0
|
||||
positive: positive
|
||||
sign_flag: sign
|
||||
allign: allign
|
||||
align: align
|
||||
)
|
||||
res.write_string(tmp)
|
||||
unsafe { tmp.free() }
|
||||
|
@ -349,7 +349,7 @@ pub fn v_sprintf(str string, pt ...voidptr) string {
|
|||
len1: 0
|
||||
positive: positive
|
||||
sign_flag: sign
|
||||
allign: allign
|
||||
align: align
|
||||
)
|
||||
res.write_string(tmp)
|
||||
unsafe { tmp.free() }
|
||||
|
@ -408,7 +408,7 @@ pub fn v_sprintf(str string, pt ...voidptr) string {
|
|||
len1: 0
|
||||
positive: true
|
||||
sign_flag: false
|
||||
allign: allign
|
||||
align: align
|
||||
)
|
||||
res.write_string(tmp)
|
||||
unsafe { tmp.free() }
|
||||
|
@ -432,7 +432,7 @@ pub fn v_sprintf(str string, pt ...voidptr) string {
|
|||
len1: len1
|
||||
positive: positive
|
||||
sign_flag: sign
|
||||
allign: allign
|
||||
align: align
|
||||
)
|
||||
if ch == `F` {
|
||||
tmp := s.to_upper()
|
||||
|
@ -459,7 +459,7 @@ pub fn v_sprintf(str string, pt ...voidptr) string {
|
|||
len1: len1
|
||||
positive: positive
|
||||
sign_flag: sign
|
||||
allign: allign
|
||||
align: align
|
||||
)
|
||||
if ch == `E` {
|
||||
tmp := s.to_upper()
|
||||
|
@ -491,7 +491,7 @@ pub fn v_sprintf(str string, pt ...voidptr) string {
|
|||
len1: len1
|
||||
positive: positive
|
||||
sign_flag: sign
|
||||
allign: allign
|
||||
align: align
|
||||
rm_tail_zero: true
|
||||
)
|
||||
unsafe { tmp.free() }
|
||||
|
@ -504,7 +504,7 @@ pub fn v_sprintf(str string, pt ...voidptr) string {
|
|||
len1: len1
|
||||
positive: positive
|
||||
sign_flag: sign
|
||||
allign: allign
|
||||
align: align
|
||||
rm_tail_zero: true
|
||||
)
|
||||
unsafe { tmp.free() }
|
||||
|
@ -534,7 +534,7 @@ pub fn v_sprintf(str string, pt ...voidptr) string {
|
|||
len1: 0
|
||||
positive: true
|
||||
sign_flag: false
|
||||
allign: allign
|
||||
align: align
|
||||
)
|
||||
res.write_string(tmp)
|
||||
unsafe { tmp.free() }
|
||||
|
@ -631,13 +631,13 @@ pub fn format_fl_old(f f64, p BF_param) string {
|
|||
|
||||
dif := p.len0 - s.len + sign_len_diff
|
||||
|
||||
if p.allign == .right {
|
||||
if p.align == .right {
|
||||
for i1 := 0; i1 < dif; i1++ {
|
||||
res.write_u8(p.pad_ch)
|
||||
}
|
||||
}
|
||||
res.write_string(s)
|
||||
if p.allign == .left {
|
||||
if p.align == .left {
|
||||
for i1 := 0; i1 < dif; i1++ {
|
||||
res.write_u8(p.pad_ch)
|
||||
}
|
||||
|
@ -699,13 +699,13 @@ fn format_es_old(f f64, p BF_param) string {
|
|||
}
|
||||
|
||||
dif := p.len0 - s.len + sign_len_diff
|
||||
if p.allign == .right {
|
||||
if p.align == .right {
|
||||
for i1 := 0; i1 < dif; i1++ {
|
||||
res.write_u8(p.pad_ch)
|
||||
}
|
||||
}
|
||||
res.write_string(s)
|
||||
if p.allign == .left {
|
||||
if p.align == .left {
|
||||
for i1 := 0; i1 < dif; i1++ {
|
||||
res.write_u8(p.pad_ch)
|
||||
}
|
||||
|
@ -796,13 +796,13 @@ pub fn format_dec_old(d u64, p BF_param) string {
|
|||
}
|
||||
dif := p.len0 - s.len + sign_len_diff
|
||||
|
||||
if p.allign == .right {
|
||||
if p.align == .right {
|
||||
for i1 := 0; i1 < dif; i1++ {
|
||||
res.write_u8(p.pad_ch)
|
||||
}
|
||||
}
|
||||
res.write_string(s)
|
||||
if p.allign == .left {
|
||||
if p.align == .left {
|
||||
for i1 := 0; i1 < dif; i1++ {
|
||||
res.write_u8(p.pad_ch)
|
||||
}
|
||||
|
|
|
@ -165,8 +165,8 @@ pub fn header(text string, divider string) string {
|
|||
} else {
|
||||
cols - 3 - 2 * divider.len
|
||||
})
|
||||
tlimit_alligned := if (tlimit % 2) != (cols % 2) { tlimit + 1 } else { tlimit }
|
||||
tstart := imax(0, (cols - tlimit_alligned) / 2)
|
||||
tlimit_aligned := if (tlimit % 2) != (cols % 2) { tlimit + 1 } else { tlimit }
|
||||
tstart := imax(0, (cols - tlimit_aligned) / 2)
|
||||
mut ln := ''
|
||||
if divider.len > 0 {
|
||||
ln = divider.repeat(1 + cols / divider.len)[0..cols]
|
||||
|
|
|
@ -171,7 +171,7 @@ pub fn (mut g Gen) gen_pe_header() {
|
|||
|
||||
g.pe_coff_hdr_pos = g.pos()
|
||||
for i, b in pe_header {
|
||||
end_addr := i * 2 + 2 // allign correctly with description table
|
||||
end_addr := i * 2 + 2 // align correctly with description table
|
||||
g.write16(b)
|
||||
if g.pref.is_verbose && pe_header_description[end_addr] != '' {
|
||||
g.println(pe_header_description[end_addr])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue