-
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.
- Loading branch information
1 parent
55b2a5f
commit 6ecf5d3
Showing
16 changed files
with
194 additions
and
23 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
include altlib."posix.al" | ||
|
||
typedef TestAllocator := #S { | ||
data: #1I, | ||
size: #I, | ||
reserved: #I | ||
}; | ||
|
||
func ^#1TestAllocator.init(this #1TestAllocator, size #I) -> #V { | ||
def PROT_READ := 1 | ||
def PROT_WRITE := 2 | ||
def MAP_PRIVATE := 2 | ||
def MAP_ANONYMOUS := 32 | ||
this->data& <- posix_mmap(0 as #1I, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0) | ||
this->size& <- 0 | ||
this->reserved& <- size | ||
} | ||
|
||
func ^#1TestAllocator.deinit(this #1TestAllocator) -> #V { | ||
eval posix_munmap(this->data, this->reserved) | ||
} | ||
|
||
func ^#1TestAllocator.alloc(this #1TestAllocator, size #I) -> #1I { | ||
return if (this->size + size <= this->reserved) { | ||
def x := this->data as #I | ||
def ptr := (x + this->size) as #1I | ||
this->size& <- this->size + size | ||
return ptr | ||
} | ||
else 0 as #1I | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
ALFLAGS=-i altlib ../../altlib/ | ||
LDFLAGS=-z noexecstack | ||
|
||
SRCS_AL := $(wildcard *.al) | ||
EXES_AL := $(patsubst %.al, $(BUILD_DIR)/test/algo/%, $(SRCS_AL)) | ||
|
||
OBJS_STDLIB := $(wildcard $(BUILD_DIR)/stdlib/*.o) | ||
OBJS_ALTLIB := $(wildcard $(BUILD_DIR)/altlib/*.o) | ||
|
||
all: $(EXES_AL) | ||
|
||
$(BUILD_DIR)/test/algo/%: %.al make_dir | ||
$(BUILD_DIR)/calias -a $(ALFLAGS) $< -o $(patsubst %, %.o, $@) | ||
ld $(LDFLAGS) -o $@ $(patsubst %, %.o, $@) $(OBJS_STDLIB) $(OBJS_ALTLIB) | ||
|
||
make_dir: | ||
mkdir -p $(BUILD_DIR)/test/algo | ||
|
||
clean: | ||
rm -r $(BUILD_DIR)/test |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
include altlib."posix.al" | ||
include altlib."stdio.al" | ||
include altlib."test_allocator.al" | ||
|
||
func ^._start() -> #V { | ||
def allocator := .{ | ||
data := 0 as #1I, | ||
size := 0, | ||
reserved := 0 | ||
} | ||
eval allocator&.init(1024) | ||
|
||
def buffer := allocator&.alloc(128) as #1C | ||
def a := readi_(buffer) | ||
def b := readi_(buffer) | ||
def c := a + b | ||
eval puti_(c) | ||
|
||
eval allocator&.deinit() | ||
eval posix_exit(0) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
include altlib."posix.al" | ||
include altlib."stdio.al" | ||
include altlib."test_allocator.al" | ||
|
||
func ^._start() -> #V { | ||
def allocator := .{ | ||
data := 0 as #1I, | ||
size := 0, | ||
reserved := 0 | ||
} | ||
eval allocator&.init(1024) | ||
|
||
def buffer := allocator&.alloc(256) as #1C | ||
eval reads_(buffer) | ||
eval puts_(buffer) | ||
|
||
eval allocator&.deinit() | ||
eval posix_exit(0) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
include altlib."posix.al" | ||
include altlib."stdio.al" | ||
include altlib."test_allocator.al" | ||
|
||
func ^._start() -> #V { | ||
def allocator := .{ | ||
data := 0 as #1I, | ||
size := 0, | ||
reserved := 0 | ||
} | ||
eval allocator&.init(1024) | ||
|
||
def buffer1 := allocator&.alloc(256) as #I | ||
def buffer2 := allocator&.alloc(256) as #I | ||
def buffer3 := allocator&.alloc(256) as #I | ||
def buffer4 := allocator&.alloc(256) as #I | ||
def buffer5 := allocator&.alloc(256) as #I | ||
eval puti_(buffer2 - buffer1) | ||
eval puti_(buffer3 - buffer2) | ||
eval puti_(buffer4 - buffer3) | ||
eval puti_(buffer5) | ||
|
||
eval allocator&.deinit() | ||
eval posix_exit(0) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
256 | ||
256 | ||
256 | ||
0 |