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
Josep M. Bach
committed
Dec 23, 2012
1 parent
abd28d9
commit ea6193c
Showing
22 changed files
with
358 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-> { 3 } |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
parent = Object.clone() | ||
parent = Object.new | ||
parent.age = 50 | ||
parent.money = 1000 | ||
child = parent.clone() | ||
|
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
Object.prelude_ran = true | ||
def new | ||
VM.new_object | ||
end |
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,14 @@ | ||
_main | ||
:1:3 | ||
"block_472 | ||
67 | ||
0 | ||
20 | ||
144 | ||
_block_472 | ||
:1:2 | ||
3 | ||
17 | ||
0 | ||
144 | ||
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,39 @@ | ||
_main | ||
:8:13 | ||
3 | ||
1 | ||
"- | ||
9 | ||
"/ | ||
"* | ||
"+ | ||
"puts | ||
16 | ||
17 | ||
0 | ||
17 | ||
1 | ||
128 | ||
2 | ||
1 | ||
17 | ||
0 | ||
17 | ||
3 | ||
17 | ||
0 | ||
128 | ||
4 | ||
1 | ||
128 | ||
5 | ||
1 | ||
128 | ||
6 | ||
1 | ||
128 | ||
7 | ||
1 | ||
20 | ||
144 | ||
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 |
---|---|---|
@@ -1,10 +1,37 @@ | ||
#include <forkix/function.h> | ||
#include <forkix/value.h> | ||
|
||
Function* | ||
Function_new(int *code, DArray *literals) | ||
{ | ||
Function *fn = calloc(1, sizeof(Function)); | ||
fn->code = code; | ||
fn->literals = literals; | ||
fn->c_fn = NULL; | ||
return fn; | ||
} | ||
|
||
Function* | ||
Function_native_new(native_fn c_fn) | ||
{ | ||
Function *fn = calloc(1, sizeof(Function)); | ||
fn->code = NULL; | ||
fn->literals = NULL; | ||
fn->c_fn = c_fn; | ||
return fn; | ||
} | ||
|
||
VALUE | ||
Function_native_call(Function *fn, VALUE receiver, DArray *locals) | ||
{ | ||
VALUE result = NULL; | ||
if (DArray_at(locals, 1)) { | ||
result = fn->c_fn(receiver, DArray_at(locals, 0), DArray_at(locals, 1)); | ||
} else if (DArray_at(locals, 0)) { | ||
result = fn->c_fn(receiver, DArray_at(locals, 0), NULL); | ||
} else { | ||
result =fn->c_fn(receiver, NULL, NULL); | ||
} | ||
|
||
return result; | ||
} |
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,78 @@ | ||
#include <forkix/primitives.h> | ||
#include <forkix/runtime.h> | ||
#include <assert.h> | ||
|
||
/* | ||
* Generic primitives | ||
*/ | ||
|
||
VALUE | ||
Primitive_print(void *_, void *b, void *__) | ||
{ | ||
Value_print((VALUE)b); | ||
return NilObject; | ||
} | ||
|
||
VALUE | ||
Primitive_puts(void *a, void *b, void *c) | ||
{ | ||
Primitive_print(a, b, c); | ||
printf("\n"); | ||
return NilObject; | ||
} | ||
|
||
|
||
/* | ||
* Integer primitives | ||
*/ | ||
|
||
VALUE | ||
Primitive_Integer_add(void *a, void *b, void *_) | ||
{ | ||
VALUE left = (VALUE)a; | ||
VALUE right = (VALUE)b; | ||
|
||
CHECK_TYPE(left, IntegerType); | ||
CHECK_TYPE(right, IntegerType); | ||
|
||
return Integer_new(VAL2INT(left) + VAL2INT(right)); | ||
} | ||
|
||
VALUE | ||
Primitive_Integer_sub(void *a, void *b, void *_) | ||
{ | ||
VALUE left = (VALUE)a; | ||
VALUE right = (VALUE)b; | ||
|
||
CHECK_TYPE(left, IntegerType); | ||
CHECK_TYPE(right, IntegerType); | ||
|
||
return Integer_new(VAL2INT(left) - VAL2INT(right)); | ||
} | ||
|
||
VALUE | ||
Primitive_Integer_mul(void *a, void *b, void *_) | ||
{ | ||
VALUE left = (VALUE)a; | ||
VALUE right = (VALUE)b; | ||
|
||
CHECK_TYPE(left, IntegerType); | ||
CHECK_TYPE(right, IntegerType); | ||
|
||
return Integer_new(VAL2INT(left) * VAL2INT(right)); | ||
} | ||
|
||
VALUE | ||
Primitive_Integer_div(void *a, void *b, void *_) | ||
{ | ||
VALUE left = (VALUE)a; | ||
VALUE right = (VALUE)b; | ||
|
||
CHECK_TYPE(left, IntegerType); | ||
CHECK_TYPE(right, IntegerType); | ||
|
||
assert(VAL2INT(right) != 0 && "Cannot divide by zero"); | ||
|
||
return Integer_new(VAL2INT(left) / VAL2INT(right)); | ||
} | ||
|
Oops, something went wrong.