-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[interpreter] (#18) Dynamically resolve types of Values.
Instead of having each `Value` type define `.type`, the type is now determined via a call to `__typeof` (and the scope via `__scopeof`). This allows the interpreter to be fully encapsulated, meaning that programs can freely modify the Kernel types (e.g., define new methods on `List`) without affecting other instances of the Interpreter.
- Loading branch information
1 parent
5628e61
commit 8d76cbc
Showing
18 changed files
with
540 additions
and
477 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
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,31 +1,38 @@ | ||
module Myst | ||
BOOLEAN_TYPE.instance_scope["to_s"] = TFunctor.new([ | ||
TNativeDef.new(0) do |this, _args, _block, _itr| | ||
TString.new(this.as(TBoolean).value ? "true" : "false") | ||
end | ||
] of Callable) | ||
class Interpreter | ||
def init_boolean | ||
bool_type = TType.new("Boolean") | ||
bool_type.instance_scope["to_s"] = TFunctor.new([ | ||
TNativeDef.new(0) do |this, _args, _block, _itr| | ||
TString.new(this.as(TBoolean).value ? "true" : "false") | ||
end | ||
] of Callable) | ||
|
||
BOOLEAN_TYPE.instance_scope["=="] = TFunctor.new([ | ||
TNativeDef.new(1) do |this, (arg), _block, _itr| | ||
this = this.as(TBoolean) | ||
case arg | ||
when TBoolean | ||
TBoolean.new(this.value == arg.value) | ||
else | ||
TBoolean.new(false) | ||
end | ||
end | ||
] of Callable) | ||
bool_type.instance_scope["=="] = TFunctor.new([ | ||
TNativeDef.new(1) do |this, (arg), _block, _itr| | ||
this = this.as(TBoolean) | ||
case arg | ||
when TBoolean | ||
TBoolean.new(this.value == arg.value) | ||
else | ||
TBoolean.new(false) | ||
end | ||
end | ||
] of Callable) | ||
|
||
bool_type.instance_scope["!="] = TFunctor.new([ | ||
TNativeDef.new(1) do |this, (arg), _block, _itr| | ||
this = this.as(TBoolean) | ||
case arg | ||
when TBoolean | ||
TBoolean.new(this.value != arg.value) | ||
else | ||
TBoolean.new(true) | ||
end | ||
end | ||
] of Callable) | ||
|
||
BOOLEAN_TYPE.instance_scope["!="] = TFunctor.new([ | ||
TNativeDef.new(1) do |this, (arg), _block, _itr| | ||
this = this.as(TBoolean) | ||
case arg | ||
when TBoolean | ||
TBoolean.new(this.value != arg.value) | ||
else | ||
TBoolean.new(true) | ||
end | ||
@kernel.scope["Boolean"] = bool_type | ||
end | ||
] of Callable) | ||
end | ||
end |
Oops, something went wrong.