From c9fc22dfdb24676309a05b8a3c63e564abd1128b Mon Sep 17 00:00:00 2001 From: Vasily Chekalkin Date: Sun, 27 Mar 2011 21:52:53 +1100 Subject: [PATCH] Start jitting actual PAST::*: 1. Handle simple Vars/Vals. 2. Generate function calls. --- compilers/opsc/src/Ops/JIT.pm | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/compilers/opsc/src/Ops/JIT.pm b/compilers/opsc/src/Ops/JIT.pm index c52553cd83..934756a077 100644 --- a/compilers/opsc/src/Ops/JIT.pm +++ b/compilers/opsc/src/Ops/JIT.pm @@ -356,11 +356,22 @@ method process(Ops::Op $op, %c) { # Recursively process body chunks returning string. our multi method process(PAST::Val $val, %c) { - #die('!!!'); + my $type := $val.returns; + if $type eq 'string' { + $!builder.global_string_ptr(_dequote($val.value), :name<.str>); + } + else { + } } our multi method process(PAST::Var $var, %c) { #die('!!!'); + #LLVM::Constant::(); + if $var.isdecl { + } + else { + %c{ $var.name } // die("Unknown variable { $var.name }"); + } } =item process(PAST::Op) @@ -390,6 +401,13 @@ our method process:pasttype (PAST::Op $chunk, %c) { } our method process:pasttype (PAST::Op $chunk, %c) { + my $function := %!functions{ $chunk.name }; + + say("# Unknown function { $chunk.name }") + && return undef + unless pir::defined($function); + + $!builder.call($function, |self.process_children($chunk, %c)); } our method process:pasttype (PAST::Op $chunk, %c) { @@ -453,6 +471,15 @@ our method process:macro(PAST::Op $chunk, %c) { our method process:macro(PAST::Op $chunk, %c) { } +method process_children(PAST::Op $chunk, %c) { + # XXX .grep is temporaty solution for unhandled chunks. + @($chunk).map(->$_{ self.process($_, %c) }).grep(->$_{ pir::defined($_) }); +} + +sub _dequote($str) { + my $length := pir::length($str); + pir::substr($str, 1, $length - 2); +} INIT { pir::load_bytecode("LLVM.pbc");