Skip to content

Commit

Permalink
#rune "" to ''; Remove infix and postfix call notation
Browse files Browse the repository at this point in the history
  • Loading branch information
gingerBill committed Nov 28, 2016
1 parent cbb70c7 commit 598dab5
Show file tree
Hide file tree
Showing 19 changed files with 371 additions and 324 deletions.
2 changes: 1 addition & 1 deletion build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if %release_mode% EQU 0 ( rem Debug
)

set compiler_warnings= ^
-we4013 -we4706 -we4002 ^
-we4013 -we4706 -we4002 -we4133 ^
-wd4100 -wd4101 -wd4127 -wd4189 ^
-wd4201 -wd4204 -wd4244 ^
-wd4306 ^
Expand Down
31 changes: 30 additions & 1 deletion code/demo.odin
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
#import "fmt.odin"
#import "utf8.odin"

main :: proc() {
fmt.println("Hellope, World!")
MAX :: 64
buf: [MAX]rune
backing: [MAX]byte
offset: int

msg := "Hello"
count := utf8.rune_count(msg)
assert(count <= MAX)
runes := buf[:count]

offset = 0
for i := 0; i < count; i++ {
s := msg[offset:]
r, len := utf8.decode_rune(s)
runes[count-i-1] = r
offset += len
}

offset = 0
for i := 0; i < count; i++ {
data, len := utf8.encode_rune(runes[i])
for j := 0; j < len; j++ {
backing[offset+j] = data[j]
}
offset += len
}

reverse := backing[:count] as string
fmt.println(reverse)
}
2 changes: 1 addition & 1 deletion code/game.odin
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#import "os.odin"
#import "opengl.odin" as gl

TWO_HEARTS :: #rune "💕"
TWO_HEARTS :: '💕'

win32_perf_count_freq := win32.GetQueryPerformanceFrequency()
time_now :: proc() -> f64 {
Expand Down
26 changes: 13 additions & 13 deletions core/fmt.odin
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ print_rune_to_buffer :: proc(buf: ^[]byte, r: rune) {
print_string_to_buffer(buf, b[:n] as string)
}

print_space_to_buffer :: proc(buf: ^[]byte) { print_rune_to_buffer(buf, #rune " ") }
print_nl_to_buffer :: proc(buf: ^[]byte) { print_rune_to_buffer(buf, #rune "\n") }
print_space_to_buffer :: proc(buf: ^[]byte) { print_rune_to_buffer(buf, ' ') }
print_nl_to_buffer :: proc(buf: ^[]byte) { print_rune_to_buffer(buf, '\n') }

__NUM_TO_CHAR_TABLE := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@$"

Expand All @@ -99,7 +99,7 @@ print_u64_to_buffer :: proc(buffer: ^[]byte, value: u64) {
buf: [20]byte
len := 0
if i == 0 {
buf[len] = #rune "0"
buf[len] = '0'
len++
}
for i > 0 {
Expand All @@ -115,7 +115,7 @@ print_i64_to_buffer :: proc(buffer: ^[]byte, value: i64) {
neg := i < 0
if neg {
i = -i
print_rune_to_buffer(buffer, #rune "-")
print_rune_to_buffer(buffer, '-')
}
print_u64_to_buffer(buffer, i as u64)
}
Expand All @@ -132,7 +132,7 @@ print_i128_to_buffer :: proc(buffer: ^[]byte, value: i128) {
neg := i < 0
if neg {
i = -i
print_rune_to_buffer(buffer, #rune "-")
print_rune_to_buffer(buffer, '-')
}
print_u128_to_buffer(buffer, i as u128)
}
Expand All @@ -142,19 +142,19 @@ print_i128_to_buffer :: proc(buffer: ^[]byte, value: i128) {
print__f64 :: proc(buffer: ^[]byte, value: f64, decimal_places: int) {
f := value
if f == 0 {
print_rune_to_buffer(buffer, #rune "0")
print_rune_to_buffer(buffer, '0')
return
}
if f < 0 {
print_rune_to_buffer(buffer, #rune "-")
print_rune_to_buffer(buffer, '-')
f = -f
}

i := f as u64
print_u64_to_buffer(buffer, i)
f -= i as f64

print_rune_to_buffer(buffer, #rune ".")
print_rune_to_buffer(buffer, '.')

mult: f64 = 10.0
for ; decimal_places >= 0; decimal_places-- {
Expand Down Expand Up @@ -488,7 +488,7 @@ print_any_to_buffer :: proc(buf: ^[]byte, arg: any) {

bprintf :: proc(buf: ^[]byte, fmt: string, args: ..any) -> int {
is_digit :: proc(r: rune) -> bool #inline {
return r >= #rune "0" && r <= #rune "9"
return '0' <= r && r <= '9'
}

parse_int :: proc(s: string, offset: int) -> (int, int) {
Expand All @@ -501,7 +501,7 @@ bprintf :: proc(buf: ^[]byte, fmt: string, args: ..any) -> int {
}

result *= 10
result += (c - #rune "0") as int
result += (c - '0') as int
}

return result, offset
Expand All @@ -514,7 +514,7 @@ bprintf :: proc(buf: ^[]byte, fmt: string, args: ..any) -> int {
r := fmt[i] as rune
index := implicit_index

if r != #rune "%" {
if r != '%' {
continue
}

Expand All @@ -523,7 +523,7 @@ bprintf :: proc(buf: ^[]byte, fmt: string, args: ..any) -> int {
if i < fmt.count {
next := fmt[i] as rune

if next == #rune "%" {
if next == '%' {
print_string_to_buffer(buf, "%")
i++
prev = i
Expand Down Expand Up @@ -582,7 +582,7 @@ bprint :: proc(buf: ^[]byte, args: ..any) -> int {
bprintln :: proc(buf: ^[]byte, args: ..any) -> int {
for i := 0; i < args.count; i++ {
if i > 0 {
append(buf, #rune " ")
append(buf, ' ')
}
print_any_to_buffer(buf, args[i])
}
Expand Down
4 changes: 2 additions & 2 deletions core/utf8.odin
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
RUNE_ERROR :: #rune "\ufffd"
RUNE_ERROR :: '\ufffd'
RUNE_SELF :: 0x80
RUNE_BOM :: 0xfeff
RUNE_EOF :: ~(0 as rune)
MAX_RUNE :: #rune "\U0010ffff"
MAX_RUNE :: '\U0010ffff'
UTF_MAX :: 4


Expand Down
76 changes: 39 additions & 37 deletions core/win32.odin
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#foreign_system_library "user32"
#foreign_system_library "gdi32"

_:= compile_assert(ODIN_OS == "windows")

HANDLE :: type rawptr
HWND :: type HANDLE
HDC :: type HANDLE
Expand Down Expand Up @@ -387,43 +389,43 @@ Key_Code :: enum i32 {
DELETE = 0x2E,
HELP = 0x2F,

NUM0 = #rune "0",
NUM1 = #rune "1",
NUM2 = #rune "2",
NUM3 = #rune "3",
NUM4 = #rune "4",
NUM5 = #rune "5",
NUM6 = #rune "6",
NUM7 = #rune "7",
NUM8 = #rune "8",
NUM9 = #rune "9",

A = #rune "A",
B = #rune "B",
C = #rune "C",
D = #rune "D",
E = #rune "E",
F = #rune "F",
G = #rune "G",
H = #rune "H",
I = #rune "I",
J = #rune "J",
K = #rune "K",
L = #rune "L",
M = #rune "M",
N = #rune "N",
O = #rune "O",
P = #rune "P",
Q = #rune "Q",
R = #rune "R",
S = #rune "S",
T = #rune "T",
U = #rune "U",
V = #rune "V",
W = #rune "W",
X = #rune "X",
Y = #rune "Y",
Z = #rune "Z",
NUM0 = '0',
NUM1 = '1',
NUM2 = '2',
NUM3 = '3',
NUM4 = '4',
NUM5 = '5',
NUM6 = '6',
NUM7 = '7',
NUM8 = '8',
NUM9 = '9',

A = 'A',
B = 'B',
C = 'C',
D = 'D',
E = 'E',
F = 'F',
G = 'G',
H = 'H',
I = 'I',
J = 'J',
K = 'K',
L = 'L',
M = 'M',
N = 'N',
O = 'O',
P = 'P',
Q = 'Q',
R = 'R',
S = 'S',
T = 'T',
U = 'U',
V = 'V',
W = 'W',
X = 'X',
Y = 'Y',
Z = 'Z',

LWIN = 0x5B,
RWIN = 0x5C,
Expand Down
6 changes: 3 additions & 3 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ GB_STATIC_ASSERT(ARRAY_GROW_FORMULA(0) > 0);
typedef Array(void) ArrayVoid;

#define array_init_reserve(x_, allocator_, init_capacity_) do { \
GB_ASSERT((x_) != NULL); \
void **e = cast(void **)&((x_)->e); \
GB_ASSERT((x_) != NULL); \
(x_)->allocator = (allocator_); \
(x_)->count = 0; \
(x_)->capacity = (init_capacity_); \
*e = gb_alloc((allocator_), gb_size_of(*(x_)->e)*(init_capacity_)); \
} while (0)

#define array_init_count(x_, allocator_, init_count_) do { \
GB_ASSERT((x_) != NULL); \
void **e = cast(void **)&((x_)->e); \
GB_ASSERT((x_) != NULL); \
(x_)->allocator = (allocator_); \
(x_)->count = (init_count_); \
(x_)->capacity = (init_count_); \
Expand Down Expand Up @@ -67,8 +67,8 @@ typedef Array(void) ArrayVoid;


void array__set_capacity(void *ptr, isize capacity, isize element_size) {
GB_ASSERT(ptr != NULL);
ArrayVoid *x = cast(ArrayVoid *)ptr;
GB_ASSERT(ptr != NULL);

GB_ASSERT(element_size > 0);

Expand Down
18 changes: 13 additions & 5 deletions src/checker/checker.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,9 @@ CycleChecker *cycle_checker_add(CycleChecker *cc, Entity *e) {
if (cc->path.e == NULL) {
array_init(&cc->path, heap_allocator());
}
GB_ASSERT(e != NULL && e->kind == Entity_TypeName);
array_add(&cc->path, e);
if (e != NULL && e->kind == Entity_TypeName) {
array_add(&cc->path, e);
}
return cc;
}

Expand Down Expand Up @@ -508,6 +509,11 @@ void add_global_constant(gbAllocator a, String name, Type *type, ExactValue valu
}


void add_global_string_constant(gbAllocator a, String name, String value) {
add_global_constant(a, name, t_untyped_string, make_exact_value_string(value));

}


void init_universal_scope(void) {
// NOTE(bill): No need to free these
Expand All @@ -528,9 +534,11 @@ void init_universal_scope(void) {

add_global_entity(make_entity_nil(a, str_lit("nil"), t_untyped_nil));

add_global_constant(a, str_lit("ODIN_OS"), t_untyped_string, make_exact_value_string(str_lit("windows")));
add_global_constant(a, str_lit("ODIN_ARCH"), t_untyped_string, make_exact_value_string(str_lit("amd64")));
add_global_constant(a, str_lit("ODIN_VERSION"), t_untyped_string, make_exact_value_string(str_lit(VERSION_STRING)));
add_global_string_constant(a, str_lit("ODIN_OS"), str_lit("windows"));
add_global_string_constant(a, str_lit("ODIN_ARCH"), str_lit("amd64"));
add_global_string_constant(a, str_lit("ODIN_VENDOR"), str_lit("odin"));
add_global_string_constant(a, str_lit("ODIN_VERSION"), str_lit(VERSION_STRING));
add_global_string_constant(a, str_lit("ODIN_ENDIAN"), str_lit("little"));


// Builtin Procedures
Expand Down
Loading

0 comments on commit 598dab5

Please sign in to comment.