-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cpp] member access can now be used on both: non-variable pointers (e…
…quivalent of -> in C). previously non-variables werent supported for member access at all. e.g `get_foo().id = 5` would fail to compile. in addition, variable pointers i.e `my_foo.id = 5` works in two scenarios: normal member access (. in C) and pointer access (-> in C but for a variable)
- Loading branch information
Showing
3 changed files
with
51 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,35 @@ | ||
putchar :: (ch : i8 weak) -> u0 := extern; | ||
print_digit :: (digit : i64 weak) -> u0 | ||
{ | ||
// ascii 48 == '0' | ||
putchar(48 + digit); | ||
} | ||
"yogi bear";"gaming";"straightming"; | ||
'\t'; | ||
|
||
is_odd :: (val : i64) -> bool | ||
{ | ||
mystr : i8& const := "well met"; | ||
|
||
half : i64 := (val / 2); | ||
low_half : i64 := ((val - 1) / 2); | ||
return (half == low_half); | ||
} | ||
|
||
animal :: struct | ||
{ | ||
id : i64; | ||
} | ||
|
||
get_fox :: () -> animal | ||
puts :: (str : i8& const) -> u0 := extern; | ||
main :: () -> i64 | ||
{ | ||
//ret : animal := animal | ||
//{ | ||
// .id := 2 | ||
//}; | ||
//ret : animal; | ||
//ret.id = 5; | ||
//return ret; | ||
|
||
//return animal | ||
//{ | ||
// .id := 8 | ||
//}; | ||
ret : animal; | ||
return ret; | ||
puts("hello world!"); | ||
|
||
mydata : data := data{.id := 0}; | ||
print_id(mydata); | ||
mydata.id = 1; | ||
print_id(mydata); | ||
|
||
ptr : data& := ref mydata; | ||
(deref ptr).id = 2; | ||
print_id(mydata); | ||
ptr.id = 3; | ||
print_id(mydata); | ||
return 0; | ||
} | ||
|
||
puts :: (str : i8& const) -> u0 := extern; | ||
print_hello :: () -> u0 | ||
putchar :: (ch : i8) -> u0 := extern; | ||
print_id :: (in : data) -> u0 | ||
{ | ||
buffer : i8& := __builtin_malloc(6 * (sizeof i8)); | ||
defer __builtin_free(buffer); | ||
|
||
three : i64 const := 3; | ||
|
||
// 97 = 'a' | ||
// so n'th letter of alphabet = (97 + (n - 1)) | ||
buffer[0] = 'h'; | ||
buffer[1] = 'e'; | ||
buffer[2] = 'l'; | ||
buffer[three] = 'l'; | ||
buffer[4] = 'o'; | ||
buffer[5] = '\0'; | ||
puts(buffer); | ||
|
||
literal : i8& const := "hello\tagain!"; | ||
puts(literal); | ||
putchar('0' + (in.id@i8)); | ||
putchar('\n'); | ||
} | ||
|
||
main :: () -> i64 | ||
data :: struct | ||
{ | ||
print_hello(); | ||
|
||
putchar(10); | ||
my_fox : animal := get_fox(); | ||
print_digit(my_fox.id); | ||
putchar(10); | ||
i : i64 weak := 0; | ||
for i = 0, i != 10, i = (i + 1) | ||
{ | ||
j : i64 const := i; | ||
print_digit(i); | ||
print_digit(j); | ||
} | ||
putchar(10); | ||
print_digit(1); | ||
print_digit(2); | ||
print_digit(3); | ||
|
||
if is_odd(23456) | ||
{ | ||
print_digit(8); | ||
} | ||
else | ||
{ | ||
print_digit(9); | ||
} | ||
return 0; | ||
id : i64 := 0; | ||
} | ||
|
||
== default : build == | ||
{ | ||
set_build_type(debug); | ||
set_linkage_type(executable); | ||
set_output_name("scratchpad"); | ||
} |