Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholascc committed Apr 25, 2022
0 parents commit cc751eb
Show file tree
Hide file tree
Showing 149 changed files with 50,610 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.exe
*.bat
*.bc
*.obj
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Nicholas Charette

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Binary file added assets/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/bullet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/enemy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/player.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions lib/core/allocation.eme
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
malloc :: foreign fn #export (int) -> ^u8;
free :: foreign fn(int);
realloc :: foreign fn(^u8, int) -> ^u8;

alloc :: fn #inline #export ($T) -> ^T {
return bit_cast(^T, malloc(size_of(T)));
}

allocn :: fn #inline #export ($T, x: int) -> ^T {
return bit_cast(^T, malloc(size_of(T)*x));
}

ptr_subscript :: fn #inline #export (ptr: ^$T, i: int) -> ^T {
return bit_cast(^T, size_of(T)*i + bit_cast(int, ptr));
}

free :: fn #inline #export (ptr: ^$T) {
free(bit_cast(int, ptr));
}

realloc :: fn #inline #export (ptr: ^$T, new_size: int) -> ^T {
return bit_cast(^T, realloc(bit_cast(^u8, ptr), new_size));
}
93 changes: 93 additions & 0 deletions lib/core/array.eme
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import "lib/core/allocation.eme";
import "lib/core/assert.eme";
import "lib/core/char.eme";
import "lib/core/io.eme";




array :: struct #export (T: type) {
length: int;
data: ^T;
}

subscript :: fn #inline #operator #export (a: array($T), n: int) -> ^T {
assert(n >= 0 && n < a.length);
return ptr_subscript(a.data, n);
}

subscript :: fn #inline #operator #export (a: ^array($T), n: int) -> ^T {
assert(n >= 0 && n < a.length);
return ptr_subscript(a.data, n);
}

new :: fn #inline #export (array($T), length: int) -> array(T) {
assert(length >= 0);
r: array(T);
r.length = length;
r.data = allocn(T, length);
return r;
}

delete :: fn #inline #export (x: array($T)) {
free(x.data);
}

copy :: fn #inline #export (x: array($T)) -> array(T) {
return copy(array(T), x);
}

copy :: fn #export (array($T1), x: array(T1)) -> array(T1) {
r := new(array(T1), x.length);
each(r) it = x[it_index];
return r;
}

truncate :: fn #export (x: ^array($T), length: int) {
assert(length <= x.length);
x.length = length;
}

reverse :: fn #export (arr: array($T)) {
start := 0;
end := arr.length-1;
while(start < end) {
temp := arr[end];
arr[end] = arr[start];
arr[start] = temp;

start = start + 1;
end = end - 1;
}
}




array_iter :: struct #export (T: type) {
arr: array(T);
index: int;
}

iterator_make :: fn #inline #operator #export (a: array($T)) -> array_iter(T) {
r: array_iter(T);
r.arr = a;
r.index = 0;
return r;
}

iterator_element :: fn #inline #operator #export (a: array_iter($T)) -> ^T {
return a.arr^[a.index];
}

iterator_index :: fn #inline #operator #export (a: array_iter($T)) -> int {
return a.index;
}

iterator_done :: fn #inline #operator #export (a: array_iter($T)) -> bool {
return a.index >= a.arr.length;
}

iterator_next :: fn #inline #operator #export (a: ^array_iter($T)) {
a.index = a.index + 1;
}
12 changes: 12 additions & 0 deletions lib/core/assert.eme
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import "lib/core/char.eme"
import "lib/core/io.eme"

exit :: foreign fn(int);

assert :: fn #export (x: bool) {
if(x) return;
print("
An assert failed.
");
exit(1);
}
105 changes: 105 additions & 0 deletions lib/core/char.eme
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import "lib/core/array.eme";
import "lib/core/list.eme";
import "lib/core/allocation.eme";
import "lib/core/assert.eme";

char :: unique #export u8;

to_char :: fn #inline #export (c: u8) -> char {
return bit_cast(char, c);
}

to_u8 :: fn #inline #export (c: char) -> u8 {
return bit_cast(u8, c);
}




to_lower :: fn #export (c: char) -> char {
u := to_u8(c);
if(u >= 65 && u <= 90) return to_char(u+32);
else return c;
}

to_upper :: fn #export (c: char) -> char {
u := to_u8(c);
if(u >= 97 && u <= 127) return to_char(u-32);
else return c;
}


to_lower :: fn #export (x: array(char)) {
each(x) it = to_lower(*it);
}

to_upper :: fn #export (x: array(char)) {
each(x) it = to_upper(*it);
}


to_digit :: fn #export (x: int) -> char {
assert(x >= 0 && x < 10);
offset := num_cast(u8, x);
return to_char(48+offset);
}


to_string :: fn #export (x: int) -> list(char) {
r := new(list(char), 0, 1);

is_negative := x < 0;

if(x == 0) {
append(^r, "0");
return r;
} else if(x < 0) {
x = 0-x;
}

while(x > 0) {
next := x/10;
rem := x-next*10;
push(^r, to_digit(rem));
x = next;
}

if(is_negative) {
append(^r, "-");
}

reverse(r.array);

return r;
}


make_string_literal :: fn #export #operator #inline (data: ^u8, length: int) -> array(char) {
r: array(char);
r.length = length;
r.data = bit_cast(^char, data);
return r;
}


new_c_string :: fn #export (x: array(char)) -> ^char {
r := allocn(char, x.length+1);
each(x) {
p := ptr_subscript(r, it_index);
p = *it;
}
p := ptr_subscript(r, x.length);
p = to_char(0);
return r;
}

from_c_string :: fn #export (x: ^char) -> array(char) {
i := 0;
while(to_u8(*ptr_subscript(x, i)) > 0) {
i = i + 1;
}
r: array(char);
r.data = x;
r.length = i;
return r;
}
9 changes: 9 additions & 0 deletions lib/core/core.eme
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import #export "lib/core/array.eme"
import #export "lib/core/list.eme"
import #export "lib/core/dellist.eme"
import #export "lib/core/char.eme"
import #export "lib/core/io.eme"
import #export "lib/core/allocation.eme"
import #export "lib/core/assert.eme"
import #export "lib/core/range.eme"
import #export "lib/core/option.eme"
48 changes: 48 additions & 0 deletions lib/core/dellist.eme
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import "lib/core/list.eme"
import "lib/core/array.eme"
import "lib/core/option.eme"

dellist :: struct #export (T: type) {
list: list(opt(T));
}

new :: fn #export #inline (dellist($T), length: int, capacity: int) -> dellist(T) {
r: dellist(T);
r.list = new(list(opt(T)), length, capacity);
return r;
}

new :: fn #export #inline (dellist($T), length: int) -> dellist(T) {
r: dellist(T);
r.list = new(list(opt(T)), length);
return r;
}

new :: fn #export #inline (dellist($T)) -> dellist(T) {
r: dellist(T);
r.list = new(list(opt(T)), length);
return r;
}

subscript :: fn #export #inline #operator (x: dellist($T), i: int) -> ^opt(T) {
return x.list^[i];
}

clean_up :: fn #export (x: ^dellist($T)) {
i := 0;
j := 0;
while(i < x.list.array.length) {
if((*x)[i].non_null) {
(*x)[j] = (*x)[i];
j = j + 1;
}
i = i + 1;
}
x.list.array.length = j;
}



iterator_make :: fn #inline #operator #export (a: dellist($T)) -> array_iter(opt(T)) {
return iterator_make(a.list);
}
46 changes: 46 additions & 0 deletions lib/core/io.eme
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import "lib/core/array.eme"
import "lib/core/list.eme"
import "lib/core/char.eme"

putchar :: foreign fn(char);


print :: fn #export #inline (c: char) {
putchar(c);
}

print :: fn #export (x: array(char)) {
each(x) putchar(*it);
}

print :: fn #export (x: array($T)) {
each(x) {
if(it_index > 0) print(" ");
print(*it);
}
}

print :: fn #export #inline (x: list($T)) {
print(x.array);
}

print :: fn #export (x: int) {
s := to_string(x);
print(s);
delete(s);
}

print_float :: foreign fn (float);

print :: fn #inline #export (x: float) {
print_float(x);
}

println :: fn #export #inline () {
print(to_char(10));
}

println :: fn #export #inline (x: $T) {
print(x);
println();
}
Loading

0 comments on commit cc751eb

Please sign in to comment.