-
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.
export and export* to create alive modules
See #16
- Loading branch information
Showing
8 changed files
with
142 additions
and
45 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
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,43 @@ | ||
---- | ||
-- Functions for loading strings and files of alive code. | ||
-- | ||
-- @module load | ||
import Result from require 'alv.result' | ||
import Builtin from require 'alv.base' | ||
import Scope from require 'alv.scope' | ||
import Error from require 'alv.error' | ||
import program from require 'alv.parsing' | ||
builtin = require 'alv.builtin' | ||
|
||
slurp = (file) -> | ||
file = io.open file, 'r' | ||
with file\read '*all' | ||
file\close! | ||
|
||
--- Attempt to load alive code from string. | ||
-- | ||
-- @tparam string code the code to load | ||
-- @tparam ?string file name of the source file (for error reporting) | ||
-- @treturn Result | ||
-- @treturn AST the parsed and updated AST | ||
loadstring = (code, file='(unnamed)') -> | ||
Error.wrap "evaluating '#{file}'", -> | ||
ast = program\match code | ||
if not ast | ||
error Error 'syntax', "failed to parse" | ||
|
||
scope = Scope builtin | ||
result = ast\eval scope | ||
result, ast | ||
|
||
--- Attempt to load alive code from a file. | ||
-- | ||
-- @tparam string file filepath of the source file | ||
-- @treturn Result | ||
-- @treturn AST the parsed and updated AST | ||
loadfile = (file) -> loadstring (slurp file), file | ||
|
||
{ | ||
:loadstring | ||
:loadfile | ||
} |
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