update all the high level test files
This commit is contained in:
parent
32c0c5611f
commit
feaebcec1d
|
|
@ -5,10 +5,6 @@ const str nl = "\n";
|
||||||
|
|
||||||
plex Terminal {
|
plex Terminal {
|
||||||
nat handle;
|
nat handle;
|
||||||
|
|
||||||
init() {
|
|
||||||
handle = open("/dev/term/0", 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -29,7 +25,7 @@ function add(int a, int b) int {
|
||||||
* Print with a newline
|
* Print with a newline
|
||||||
*/
|
*/
|
||||||
function pln(str message) {
|
function pln(str message) {
|
||||||
Terminal term();
|
Terminal term = open("/dev/term/0", 0);
|
||||||
write(term, message, message.length);
|
write(term, message, message.length);
|
||||||
write(term, nl, nl.length);
|
write(term, nl, nl.length);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,6 @@ const str nl = "\n";
|
||||||
|
|
||||||
plex Terminal {
|
plex Terminal {
|
||||||
nat handle;
|
nat handle;
|
||||||
|
|
||||||
init() {
|
|
||||||
handle = open("/dev/term/0", 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -30,7 +26,7 @@ function fib(int n) int {
|
||||||
* Print with a newline
|
* Print with a newline
|
||||||
*/
|
*/
|
||||||
function pln(str message) {
|
function pln(str message) {
|
||||||
Terminal term();
|
Terminal term = open("/dev/term/0", 0);
|
||||||
write(term, message, message.length);
|
write(term, message, message.length);
|
||||||
write(term, nl, nl.length);
|
write(term, nl, nl.length);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,6 @@ const str nl = "\n";
|
||||||
|
|
||||||
plex Terminal {
|
plex Terminal {
|
||||||
nat handle;
|
nat handle;
|
||||||
|
|
||||||
init() {
|
|
||||||
handle = open("/dev/term/0", 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -22,7 +18,7 @@ function main() {
|
||||||
* Print with a newline
|
* Print with a newline
|
||||||
*/
|
*/
|
||||||
function pln(str message) {
|
function pln(str message) {
|
||||||
Terminal term();
|
Terminal term = open("/dev/term/0", 0);
|
||||||
write(term, message, message.length);
|
write(term, message, message.length);
|
||||||
write(term, nl, nl.length);
|
write(term, nl, nl.length);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,17 +5,13 @@ const str nl = "\n";
|
||||||
|
|
||||||
plex Terminal {
|
plex Terminal {
|
||||||
nat handle;
|
nat handle;
|
||||||
|
|
||||||
init() {
|
|
||||||
handle = open("/dev/term/0", 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main function
|
* Main function
|
||||||
*/
|
*/
|
||||||
function main() {
|
function main() {
|
||||||
Terminal term();
|
Terminal term = open("/dev/term/0", 0);
|
||||||
real a = 5.0;
|
real a = 5.0;
|
||||||
do (int i = 5000, 0, -1) {
|
do (int i = 5000, 0, -1) {
|
||||||
a = a + 5.0;
|
a = a + 5.0;
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,18 @@
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const str prompt = "Enter a string: ";
|
|
||||||
const str nl = "\n";
|
const str nl = "\n";
|
||||||
|
|
||||||
plex Terminal {
|
plex Terminal {
|
||||||
nat handle;
|
nat handle;
|
||||||
|
|
||||||
init() {
|
|
||||||
handle = open("/dev/term/0", 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main function
|
* Main function
|
||||||
*/
|
*/
|
||||||
function main() {
|
function main() {
|
||||||
Terminal term();
|
Terminal term = open("/dev/term/0", 0);
|
||||||
pln(term, prompt);
|
pln(term, "Enter a string: ");
|
||||||
pln(term, term.read(32));
|
pln(term, term.read(32));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,12 @@ plex Screen implements Device {
|
||||||
nat width;
|
nat width;
|
||||||
nat height;
|
nat height;
|
||||||
nat buffer_size;
|
nat buffer_size;
|
||||||
byte[] screen_buffer;
|
byte[] buffer;
|
||||||
|
|
||||||
init() {
|
draw() {
|
||||||
this.handle = open("/dev/screen/0", 0);
|
unsafe {
|
||||||
|
write(this, this.buffer, this.buffer_size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -33,26 +35,21 @@ plex Mouse implements Device {
|
||||||
bool right;
|
bool right;
|
||||||
bool middle;
|
bool middle;
|
||||||
bool btn4;
|
bool btn4;
|
||||||
nat size;
|
|
||||||
|
|
||||||
init() {
|
|
||||||
this.handle = open("/dev/mouse/0", 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main function
|
* Main function
|
||||||
*/
|
*/
|
||||||
function main() {
|
function main() {
|
||||||
Screen screen();
|
Screen screen = open("/dev/screen/0", 0);
|
||||||
Mouse mouse();
|
Mouse mouse = open("/dev/mouse/0", 0);
|
||||||
|
|
||||||
outline_swatch(screen, BLACK, 1, 1, 8);
|
outline_swatch(screen, BLACK, 1, 1);
|
||||||
outline_swatch(screen, WHITE, 21, 1, 8);
|
outline_swatch(screen, WHITE, 21, 1);
|
||||||
screen.draw();
|
screen.draw();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
mouse.read();
|
mouse.refresh();
|
||||||
if (not mouse.left) continue;
|
if (not mouse.left) continue;
|
||||||
|
|
||||||
int box_size = 20;
|
int box_size = 20;
|
||||||
|
|
@ -68,7 +65,7 @@ function main() {
|
||||||
set_color(box_size, x, y, mouse.x, mouse.y, color);
|
set_color(box_size, x, y, mouse.x, mouse.y, color);
|
||||||
screen.draw();
|
screen.draw();
|
||||||
|
|
||||||
draw_box(screen, selected_color, x, y, 5, 5);
|
rectangle(screen, selected_color, x, y, 5, 5);
|
||||||
}
|
}
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
@ -76,16 +73,18 @@ function main() {
|
||||||
/**
|
/**
|
||||||
* Checks if the click is within the bound and update the selected color if so.
|
* Checks if the click is within the bound and update the selected color if so.
|
||||||
*/
|
*/
|
||||||
function set_color(int mouse_x, int mouse_y, int box_x, int box_y, nat color, nat box_size) {
|
function set_color(int box_size, int bx, int by, int mx, int my, byte color) {
|
||||||
int right = box_x + box_size;
|
int right = bx + box_size;
|
||||||
int bottom = box_y + box_size;
|
int bottom = by + box_size;
|
||||||
|
|
||||||
if (mouse_x < box_x) return;
|
if (mx < bx) return;
|
||||||
if (mouse_x > right) return;
|
if (mx > right) return;
|
||||||
if (mouse_y < box_y) return;
|
if (my < by) return;
|
||||||
if (mouse_y > bottom) return;
|
if (my > bottom) return;
|
||||||
|
|
||||||
selected_color = color;
|
selected_color = color;
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -97,22 +96,24 @@ function outline_swatch(Device screen, byte color, int x, int y) {
|
||||||
bg_color = DARK_GRAY;
|
bg_color = DARK_GRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_box(screen, bg_color, x, y, 20, 20);
|
rectangle(screen, bg_color, x, y, 20, 20);
|
||||||
draw_box(screen, color, x + 2, y + 2, 17, 17);
|
rectangle(screen, color, x + 2, y + 2, 17, 17);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw a box
|
* Draw a rectangle
|
||||||
*/
|
*/
|
||||||
function draw_box(Device screen, int screen_width, byte color, int x, int y, int width, int height) {
|
function rectangle(Device screen, byte color, int x, int y, int width, int height) {
|
||||||
// we need unsafe because we are using `ptr` and `memset` directly
|
// we need unsafe because we are using pointers `&` and `memset` directly
|
||||||
// unsafe takes the guardrails off and allows you to access/modify memory directly
|
// unsafe takes the guardrails off and allows you to access/modify memory directly
|
||||||
unsafe {
|
unsafe {
|
||||||
int pixel = y * screen_width + x + screen.buffer.ptr + 4;
|
int pixel = y * width + x + &screen.buffer + 4;
|
||||||
do (int i = height; i > 0; i--) {
|
do (int i = height; i > 0; i--) {
|
||||||
int row = pixel + width;
|
int row = pixel + width;
|
||||||
memset(screen.buffer.ptr, row, color, width);
|
memset(screen.buffer, row, color, width);
|
||||||
pixel += screen_width;
|
pixel += width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,11 @@ plex Screen implements Device {
|
||||||
nat width;
|
nat width;
|
||||||
nat height;
|
nat height;
|
||||||
nat buffer_size;
|
nat buffer_size;
|
||||||
byte[] screen_buffer;
|
byte[] buffer;
|
||||||
|
|
||||||
draw() {
|
draw() {
|
||||||
unsafe {
|
unsafe {
|
||||||
write(this.handle, &this.screen_buffer, this.buffer_size);
|
write(this, this.buffer, this.buffer_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -105,13 +105,13 @@ function outline_swatch(Device screen, byte color, int x, int y) {
|
||||||
* Draw a rectangle
|
* Draw a rectangle
|
||||||
*/
|
*/
|
||||||
function rectangle(Device screen, byte color, int x, int y, int width, int height) {
|
function rectangle(Device screen, byte color, int x, int y, int width, int height) {
|
||||||
// we need unsafe because we are using `ptr` and `memset` directly
|
// we need unsafe because we are using pointers `&` and `memset` directly
|
||||||
// unsafe takes the guardrails off and allows you to access/modify memory directly
|
// unsafe takes the guardrails off and allows you to access/modify memory directly
|
||||||
unsafe {
|
unsafe {
|
||||||
int pixel = y * width + x + screen.buffer.ptr + 4;
|
int pixel = y * width + x + &screen.buffer + 4;
|
||||||
do (int i = height; i > 0; i--) {
|
do (int i = height; i > 0; i--) {
|
||||||
int row = pixel + width;
|
int row = pixel + width;
|
||||||
memset(screen.buffer.ptr, row, color, width);
|
memset(screen.buffer, row, color, width);
|
||||||
pixel += width;
|
pixel += width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,6 @@ const real y = 1.0;
|
||||||
|
|
||||||
plex Terminal {
|
plex Terminal {
|
||||||
nat handle;
|
nat handle;
|
||||||
|
|
||||||
init() {
|
|
||||||
this.handle = open("/dev/term/0", 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -24,7 +20,7 @@ function main() {
|
||||||
* Print with a newline
|
* Print with a newline
|
||||||
*/
|
*/
|
||||||
function pln(str message) {
|
function pln(str message) {
|
||||||
Terminal term();
|
Terminal term = open("/dev/term/0", 0);
|
||||||
write(term, message, message.length);
|
write(term, message, message.length);
|
||||||
write(term, nl, nl.length);
|
write(term, nl, nl.length);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,6 @@ const nat WHITE = 255;
|
||||||
*/
|
*/
|
||||||
plex Terminal {
|
plex Terminal {
|
||||||
nat handle;
|
nat handle;
|
||||||
|
|
||||||
init() {
|
|
||||||
handle = open("/dev/term/0", 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
plex Screen {
|
plex Screen {
|
||||||
|
|
@ -22,12 +18,8 @@ plex Screen {
|
||||||
nat buffer_size;
|
nat buffer_size;
|
||||||
byte[] screen_buffer;
|
byte[] screen_buffer;
|
||||||
|
|
||||||
init() {
|
|
||||||
this.handle = open("/dev/screen/0", 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
draw() {
|
draw() {
|
||||||
write(this.handle, this.screen_buffer, this.buffer_size);
|
write(&this, this.screen_buffer, this.buffer_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,23 +32,19 @@ plex Mouse {
|
||||||
bool middle;
|
bool middle;
|
||||||
bool btn4;
|
bool btn4;
|
||||||
nat size;
|
nat size;
|
||||||
|
|
||||||
init() {
|
|
||||||
this.handle = open("/dev/mouse/0", 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main function
|
* Main function
|
||||||
*/
|
*/
|
||||||
function main() {
|
function main() {
|
||||||
Screen screen();
|
Screen screen = open("/dev/screen/0", 0);
|
||||||
pln(screen.handle.str);
|
pln(screen.handle.str);
|
||||||
pln(screen.width.str);
|
pln(screen.width.str);
|
||||||
pln(screen.size.str);
|
pln(screen.size.str);
|
||||||
pln(screen.screen_buffer.ptr.str);
|
pln(screen.screen_buffer.ptr.str);
|
||||||
|
|
||||||
Mouse mouse();
|
Mouse mouse = open("/dev/mouse/0", 0);
|
||||||
screen.draw();
|
screen.draw();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue