Skip to content

Commit

Permalink
* Implement warn($), exit(), and the "..." term.
Browse files Browse the repository at this point in the history
  • Loading branch information
Audrey Tang committed Jul 20, 2010
1 parent 90ad541 commit 6fd3e0b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CodeGen.pm
Expand Up @@ -50,6 +50,8 @@ use 5.010;
'Kernel.NewRWScalar' => [m => 'Variable'],
'Kernel.NewRWListVar' => [m => 'Variable'],
'Console.WriteLine' => [m => 'Void'],
'Console.Error.WriteLine' => [m => 'Void'],
'Environment.Exit' => [m => 'Void'],
'String.Concat' => [m => 'String'],
'Kernel.SubMO' => [f => 'DynMetaObject'],
'Kernel.ScalarMO' => [f => 'DynMetaObject'],
Expand Down
14 changes: 14 additions & 0 deletions Op.pm
Expand Up @@ -187,6 +187,20 @@ use CgOp;
extends 'Op';

has kind => (isa => 'Str', is => 'ro', required => 1);

sub code {
my ($self, $cg, $body) = @_;

CgOp::prog(
CgOp::subcall(
CgOp::fetch(CgOp::scopedlex("&warn")),
CgOp::string_var(">>>Stub code executed<<<")
),
CgOp::subcall(
CgOp::fetch(CgOp::scopedlex("&exit")),
),
);
}
}

{
Expand Down
13 changes: 13 additions & 0 deletions setting
Expand Up @@ -263,13 +263,26 @@ sub infix:<< != >>($l,$r) { Q:CgOp {
(unbox Double (fetch (scopedlex $r)))))
} }
sub warn($str) { Q:CgOp {
(prog [rawscall Console.Error.WriteLine
(unbox String (fetch (methodcall (scopedlex $str) Str))])
[box Bool (bool 1)]
)
} }

sub say($str) { Q:CgOp {
(prog [rawscall Console.WriteLine
(unbox String (fetch (methodcall (scopedlex $str) Str))])
[box Bool (bool 1)]
)
} }
sub exit() { Q:CgOp {
(prog [rawscall Environment.Exit (int 0) ]
[null Variable]
)
} }

sub infix:<=> { Q:CgOp { (prog [assign (pos 0) (pos 1)] (pos 0)) } }
# Buglet in STD: standard infix operators look custom inside the setting, and
Expand Down

0 comments on commit 6fd3e0b

Please sign in to comment.