Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Forge Script
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Microhacks
Forge Script
Commits
117901ce
Verified
Commit
117901ce
authored
2 years ago
by
Louis
Browse files
Options
Downloads
Patches
Plain Diff
Print statement in interpreter
parent
a9de8dbf
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#495
passed with stages
Stage:
Stage:
in 55 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
forge-script-lang/src/runtime/executor/simple.rs
+22
-2
22 additions, 2 deletions
forge-script-lang/src/runtime/executor/simple.rs
with
22 additions
and
2 deletions
forge-script-lang/src/runtime/executor/simple.rs
+
22
−
2
View file @
117901ce
use
crate
::
parse
::
ast
::{
BinaryOp
,
DeclareFunction
,
ExpressionList
,
Program
,
UnaryOp
,
ValueExpression
,
VoidExpression
,
BinaryOp
,
DeclareFunction
,
ExpressionList
,
Print
,
Program
,
UnaryOp
,
ValueExpression
,
VoidExpression
,
};
use
crate
::
runtime
::
executor
::
Visitor
;
use
crate
::
runtime
::
value
::{
ForgeValue
,
UnsupportedOperation
};
...
...
@@ -110,7 +111,19 @@ impl Visitor for SimpleExecutor {
&
mut
self
,
expression
:
&
VoidExpression
,
)
->
Result
<
Self
::
Output
,
Self
::
Error
>
{
Err
(
RuntimeError
::
Unsupported
(
"Void Expression"
))
match
expression
{
VoidExpression
::
ConditionLoop
(
_
)
=>
{
return
Err
(
RuntimeError
::
Unsupported
(
"ConditionLoop"
))
}
VoidExpression
::
Import
(
_
)
=>
return
Err
(
RuntimeError
::
Unsupported
(
"Import"
)),
VoidExpression
::
Export
(
_
)
=>
return
Err
(
RuntimeError
::
Unsupported
(
"Export"
)),
VoidExpression
::
Print
(
Print
{
expr
})
=>
{
let
value
=
self
.evaluate_value_expression
(
expr
.as_ref
())
?
;
println!
(
"{}"
,
value
);
}
}
Ok
(
ForgeValue
::
Null
)
}
fn
evaluate_program
(
&
mut
self
,
program
:
&
Program
)
->
Result
<
Self
::
Output
,
Self
::
Error
>
{
...
...
@@ -154,4 +167,11 @@ mod interpreter_test {
let
mut
vm
=
SimpleExecutor
::
default
();
assert_eq!
(
vm
.evaluate_program
(
&
add_numbers
),
Ok
(
ForgeValue
::
from
(
0
)));
}
#[test]
fn
print
()
{
let
print_4
=
parse_program
(
"print 2 + 2"
)
.expect
(
"Failed to parse"
);
let
mut
vm
=
SimpleExecutor
::
default
();
assert_eq!
(
vm
.evaluate_program
(
&
print_4
),
Ok
(
ForgeValue
::
Null
));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment