Skip to content

Commit

Permalink
better memory
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard authored and Richard committed Apr 6, 2019
1 parent c1ab2ba commit 646a461
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub fn main(){
// get the offset for the color to use
color_offset = (colors + (x * size_num))
// set current color to string at that position
canvas_set_fill_style(ctx,mem_num(color_offset))
canvas_set_fill_style(ctx,mem(color_offset))
// draw the rect
canvas_fill_rect(ctx,(x * 10),(x * 10),50,50)
// recur until 3 squares are drawn
Expand All @@ -128,7 +128,7 @@ high_score = 0

fn run_my_game(){
...
mem_num(high_score,(mem_num(high_score) + 100))
mem(high_score,(mem(high_score) + 100))
...
}
```
Expand Down Expand Up @@ -178,10 +178,10 @@ It's easiest to think that everything is a `f64` number in wasp.
## Functions
* **[pub] fn name (x,...){ ... })** - create a function that executes a list of expressions returning the result of the last one. Optionally provide an export name to make visible to host.
* **function_name(...)** - call a function with arguments
* **mem(x:integer)** - get 8-bit value from memory location x
* **mem(x:integer y)** - set 8-bit value at memory location x to value y
* **mem_num(x:integer)** - get 64-bit float value from memory location x
* **mem_num(x:integer y)** - set 64-bit float value at memory location x to value y
* **mem_byte(x:integer)** - get 8-bit value from memory location x
* **mem_byte(x:integer y)** - set 8-bit value at memory location x to value y
* **mem(x:integer)** - get 64-bit float value from memory location x
* **mem(x:integer y)** - set 64-bit float value at memory location x to value y

* **mem_heap_start()** - get number that represents the start of the heap
* **mem_heap_end()** - get number that represents the end of the heap
Expand Down
2 changes: 1 addition & 1 deletion examples/canvas/main.w
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn main(){
// get the offset for the color to use
color_offset = (colors + (x * size_num))
// set current color to string at that position
canvas_set_fill_style(ctx,mem_num(color_offset))
canvas_set_fill_style(ctx,mem(color_offset))
// draw the rect
canvas_fill_rect(ctx,(x * 10),(x * 10),50,50)
// recur until 3 squares are drawn
Expand Down
8 changes: 4 additions & 4 deletions src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl Compiler {
} else {
panic!("call must have at least function signature and function index")
}
} else if &x.function_name == "mem" {
} else if &x.function_name == "mem_byte" {
if x.params.len() == 1 {
self.process_expression(i, &x.params[0]);
self.function_implementations[i].with_instructions(vec![I32_TRUNC_S_F64]);
Expand All @@ -392,7 +392,7 @@ impl Compiler {
self.function_implementations[i]
.with_instructions(vec![F64_CONST, 0.0.into()]);
} else {
panic!("invalid number params for mem")
panic!("invalid number params for mem_byte")
}
} else if &x.function_name == "mem_heap_start" {
if x.params.len() == 0 {
Expand Down Expand Up @@ -423,7 +423,7 @@ impl Compiler {
} else {
panic!("invalid number params for mem_heap_start")
}
} else if &x.function_name == "mem_num" {
} else if &x.function_name == "mem" {
if x.params.len() == 1 {
self.process_expression(i, &x.params[0]);
self.function_implementations[i].with_instructions(vec![
Expand All @@ -444,7 +444,7 @@ impl Compiler {
self.function_implementations[i]
.with_instructions(vec![F64_CONST, 0.0.into()]);
} else {
panic!("invalid number params for mem_num")
panic!("invalid number params for mem")
}
} else if &x.function_name == "=="
|| &x.function_name == "!="
Expand Down

0 comments on commit 646a461

Please sign in to comment.