-
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.
Added two tiny stdlib modules and support for importing them.
- Loading branch information
1 parent
cfe50f6
commit e7beee6
Showing
20 changed files
with
208 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ mod config; | |
mod heap; | ||
mod natives; | ||
mod scanner; | ||
mod stdlib; | ||
mod types; | ||
mod value; | ||
mod vm; | ||
|
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 @@ | ||
use crate::value::{ias_f64, ModuleContents, Number, Value}; | ||
use crate::vm::VM; | ||
|
||
pub(super) fn sqrt_native(_vm: &mut VM, args: &mut [&mut Value]) -> Result<Value, String> { | ||
match &args[0] { | ||
Value::Number(Number::Float(n)) => Ok(n.sqrt().into()), | ||
Value::Number(Number::Integer(n)) => Ok((ias_f64(*n)).sqrt().into()), | ||
x => Err(format!("'sqrt' expected numeric argument, got: {}", *x)), | ||
} | ||
} | ||
|
||
pub(super) fn module() -> ModuleContents { | ||
vec![("sqrt", &[1], sqrt_native)] | ||
} |
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,7 @@ | ||
mod math; | ||
|
||
use crate::vm::VM; | ||
|
||
pub fn register(vm: &mut VM) { | ||
vm.register_stdlib_module(&"math", math::module()); | ||
} |
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 @@ | ||
print("Zen of generic or something??"); |
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 @@ | ||
import "zen"; # expect: Zen of generic or something?? |
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 @@ | ||
import "math"; | ||
|
||
print(math); # expect: <module math> |
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 @@ | ||
import "nope.gen"; # expect runtime error: Could not find the file to be imported. Attempted path "test/import/nope.gen" | ||
import "nope.gen"; # expect runtime error: Could not find the file to be imported. Attempted path "test/import/nope.gen" and stdlib. |
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 @@ | ||
import "math"; |
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 @@ | ||
import "nested/nested_rust_stdlib.gen"; | ||
|
||
print(math); # expect runtime error: Undefined variable 'math'. |
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,3 +1,5 @@ | ||
from "math" import sqrt; | ||
|
||
print(sqrt(9)); # expect: 3.0 | ||
|
||
sqrt(1, 2); # expect runtime error: Native function 'sqrt' expected 1 argument, got 2. |
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,3 +1,5 @@ | ||
from "math" import sqrt; | ||
|
||
print(sqrt(9)); # expect: 3.0 | ||
|
||
sqrt(true); # expect runtime error: 'sqrt' expected numeric argument, got: true |
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,5 @@ | ||
import "math"; | ||
|
||
print(math.sqrt(9)); # expect: 3.0 | ||
|
||
math.sqrt(nil); # expect runtime error: 'sqrt' expected numeric argument, got: nil |
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,5 @@ | ||
import "math"; | ||
|
||
print(math.sqrt(9)); # expect: 3.0 | ||
|
||
math.sqrt("s"); # expect runtime error: 'sqrt' expected numeric argument, got: s |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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