Skip to content

Commit

Permalink
Re-arrange things a little - just in stage 2 for now. This gets an NQ…
Browse files Browse the repository at this point in the history
…P built that more fully uses QRegex. Lots to fix - this is mostly just shuffling around the build process and dependency chain somewhat.
  • Loading branch information
jnthn committed Jan 6, 2012
1 parent 27a79fe commit 129d9b2
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 47 deletions.
2 changes: 2 additions & 0 deletions src/QAST/Node.nqp
@@ -1,3 +1,5 @@
use NQPHLL;

class QAST::Node is NQPCapture {
has $!name;
has $!node;
Expand Down
9 changes: 3 additions & 6 deletions src/QHLL/Grammar.pm
@@ -1,11 +1,8 @@
use NQPRegex;
use QRegex;

grammar HLL::Grammar {
my $brackets := "<>[]()\{}\xab\xbb\x[0f3a]\x[0f3b]\x[0f3c]\x[0f3d]\x[169b]\x[169c]\x[2045]\x[2046]\x[207d]\x[207e]\x[208d]\x[208e]\x[2329]\x[232a]\x[2768]\x[2769]\x[276a]\x[276b]\x[276c]\x[276d]\x[276e]\x[276f]\x[2770]\x[2771]\x[2772]\x[2773]\x[2774]\x[2775]\x[27c5]\x[27c6]\x[27e6]\x[27e7]\x[27e8]\x[27e9]\x[27ea]\x[27eb]\x[2983]\x[2984]\x[2985]\x[2986]\x[2987]\x[2988]\x[2989]\x[298a]\x[298b]\x[298c]\x[298d]\x[298e]\x[298f]\x[2990]\x[2991]\x[2992]\x[2993]\x[2994]\x[2995]\x[2996]\x[2997]\x[2998]\x[29d8]\x[29d9]\x[29da]\x[29db]\x[29fc]\x[29fd]\x[3008]\x[3009]\x[300a]\x[300b]\x[300c]\x[300d]\x[300e]\x[300f]\x[3010]\x[3011]\x[3014]\x[3015]\x[3016]\x[3017]\x[3018]\x[3019]\x[301a]\x[301b]\x[301d]\x[301e]\x[fd3e]\x[fd3f]\x[fe17]\x[fe18]\x[fe35]\x[fe36]\x[fe37]\x[fe38]\x[fe39]\x[fe3a]\x[fe3b]\x[fe3c]\x[fe3d]\x[fe3e]\x[fe3f]\x[fe40]\x[fe41]\x[fe42]\x[fe43]\x[fe44]\x[fe47]\x[fe48]\x[fe59]\x[fe5a]\x[fe5b]\x[fe5c]\x[fe5d]\x[fe5e]\x[ff08]\x[ff09]\x[ff3b]\x[ff3d]\x[ff5b]\x[ff5d]\x[ff5f]\x[ff60]\x[ff62]\x[ff63]";
# XXX Can just be Regex::Cursor after full package refactor switch-over.
my $cursor_class := (((GLOBALish.WHO)<Regex>).WHO)<Cursor>;

token ws { <!ww> [ \s+ | '#' \N* ]* }
my $cursor_class := NQPCursor;

token termish {
<prefixish>*
Expand Down Expand Up @@ -316,7 +313,7 @@ of the match.

method panic(*@args) {
my $pos := self.pos();
my $target := pir::getattribute__PPPs(self, Regex::Cursor, '$!target');
my $target := pir::getattribute__PPPs(self, NQPCursor, '$!target');
@args.push(' at line ');
@args.push(HLL::Compiler.lineof($target, $pos) + 1);
@args.push(', near "');
Expand Down
48 changes: 21 additions & 27 deletions src/QHLL/SerializationContextBuilder.pm → src/QHLL/World.pm
@@ -1,32 +1,26 @@
# A serialization context contains a bunch of objects that we want to persist
# across the compile time / run time boundary.
# While the grammar represents the syntactic elements of our language and
# the actions take care of building up an AST to represent the semantics
# of it, the world is about the declarative aspects of a language. This
# includes:
#
# The long term goal is that we'll support actually serializing these in an
# efficient way, and be able to do load-time linking between objects in
# different libraries. For now, that's a lot of work, so we adopt a simpler
# approach, in the hope that it will be upgradeable to a "full blown"
# mechanism in the future.
# * Symbol table management
# * Creating meta-object instances
# * Parts of library loading (most likely it delegates to an actual loader)
# * Resolving references to objects, within or between compilation units
#
# A serialization context is essentially made up of objects and "events" that
# we perform on them. By performing an action on an object through the context
# builder, it ensures that the action is performed both on the object now, and
# also enough information is persisted to be able to re-create an object with
# the same state. There are two common situations.
# Just as there is one AST produced per compilation unit, there is also a
# world produce per compilation unit.
#
# 1) We compile some code and run it straight away. In this case, the objects
# have already been created, and we only need to do some fixing up.
# 2) We compile some code and persist it as PIR. In this case, the objects need
# to be re-created by replaying the event stream that creates them.
# A world includes a serialization context. This contains a bunch of
# objects - often meta-objects - that we want to persist across the
# compile time / run time boundary. In the near future, we'll switch to
# actually serializing these. At the moment, we instead save a series of
# "events" that will be used to re-construct them.
#
# Essentially, we use PIR as our serialization language until we can do better.
# Note that deserialization and installation aren't the same thing; the first
# step sees us producing an array of objects, while the second is about putting
# them in places the HLL can find them.
#
# It may be that this approach will also carry almost directly over to nqpclr
# and nqpjvm.
# Note that this reconstruction code is not generated in the case that we
# are just going to immediately run.

class HLL::Compiler::SerializationContextBuilder {
class HLL::World {
# Represents an event that we need to handle when fixing up or deserializing.
my class Event {
# The PAST that we emit to perform the action if in deserialization mode.
Expand Down Expand Up @@ -73,8 +67,8 @@ class HLL::Compiler::SerializationContextBuilder {
method BUILD(:$handle!, :$description!) {
$!sc := pir::nqp_create_sc__PS($handle);
$!handle := $handle;
%!addr_to_slot := pir::new('Hash');
@!event_stream := pir::new('ResizablePMCArray');
%!addr_to_slot := nqp::hash();
@!event_stream := nqp::list();
$!sc.set_description($description);
$!precomp_mode := %*COMPILING<%?OPTIONS><target> eq 'pir';
}
Expand Down Expand Up @@ -163,7 +157,7 @@ class HLL::Compiler::SerializationContextBuilder {

# Gets PAST for referencing an object in a serialization context,
# either the one being built or another one.
method get_object_sc_ref_past($obj) {
method get_ref($obj) {
# Get the object's serialization context; we're stuck if it
# has none.
my $sc := pir::nqp_get_sc_for_object__PP($obj);
Expand Down
2 changes: 0 additions & 2 deletions src/QRegex.nqp

This file was deleted.

1 change: 1 addition & 0 deletions src/QRegex/P6Regex/Grammar.nqp
@@ -1,4 +1,5 @@
use NQPHLL;
use QAST;

grammar QRegex::P6Regex::Grammar is HLL::Grammar {

Expand Down
39 changes: 27 additions & 12 deletions tools/build/Makefile.in
Expand Up @@ -79,26 +79,32 @@ QHLL_SOURCES = \
src/QHLL/Actions.pm \
src/QHLL/Compiler.pm \
src/QHLL/CommandLine.pm \
src/QHLL/SerializationContextBuilder.pm \
src/QHLL/World.pm \

QAST_COMBINED = QAST.nqp
QAST_PIR = QAST.pir
QAST_PBC = QAST.pbc
QAST_SOURCES = \
src/QAST/Node.nqp \
src/QAST/Regex.nqp \
src/QAST/Compiler.nqp \

P6REGEX_SOURCES = \
src/Regex/P6Regex/Grammar.pm \
src/Regex/P6Regex/Actions.pm \
src/Regex/P6Regex/Compiler.pm \

P6QREGEX_SOURCES = \
src/QRegex/P6Regex/Grammar.nqp \
src/QRegex/P6Regex/Actions.nqp \
src/QRegex/P6Regex/Compiler.nqp \

QREGEX_COMBINED = QRegex.nqp
QREGEX_PIR = QRegex.pir
QREGEX_PBC = QRegex.pbc
QREGEX_SOURCES = \
src/QRegex.nqp \
src/QAST/Node.nqp \
src/QAST/Regex.nqp \
src/QAST/Compiler.nqp \
src/QRegex/NFA.nqp \
src/QRegex/Cursor.nqp \
src/QRegex/P6Regex/Grammar.nqp \
src/QRegex/P6Regex/Actions.nqp \
src/QRegex/P6Regex/Compiler.nqp \

NQP_SOURCES = \
src/NQP/World.pm \
Expand Down Expand Up @@ -170,7 +176,7 @@ CORE_SETTING_PIR = gen/NQPCORE.setting.pir

STAGE0_PBCS = $(STAGE0)/$(HLL_PBC) $(STAGE0)/$(P6REGEX_PBC) $(STAGE0)/$(NQP_PBC) $(STAGE0)/$(REGEX_PBC) $(STAGE0)/$(CORE_SETTING_PBC) $(STAGE0)/$(MODULE_LOADER_PBC)
STAGE1_PBCS = $(STAGE1)/$(HLL_PBC) $(STAGE1)/$(P6REGEX_PBC) $(STAGE1)/$(NQP_PBC) $(STAGE1)/$(REGEX_PBC) $(STAGE1)/$(CORE_SETTING_PBC) $(STAGE1)/$(MODULE_LOADER_PBC) $(STAGE1)/$(NQP_MO_PBC)
STAGE2_PBCS = $(STAGE2)/$(HLL_PBC) $(STAGE2)/$(P6REGEX_PBC) $(STAGE2)/$(NQP_PBC) $(STAGE2)/$(REGEX_PBC) $(STAGE2)/$(CORE_SETTING_PBC) $(STAGE2)/$(MODULE_LOADER_PBC) $(STAGE2)/$(NQP_MO_PBC) $(STAGE2)/$(QREGEX_PBC)
STAGE2_PBCS = $(STAGE2)/$(HLL_PBC) $(STAGE2)/$(P6REGEX_PBC) $(STAGE2)/$(NQP_PBC) $(STAGE2)/$(REGEX_PBC) $(STAGE2)/$(CORE_SETTING_PBC) $(STAGE2)/$(MODULE_LOADER_PBC) $(STAGE2)/$(NQP_MO_PBC) $(STAGE2)/$(QREGEX_PBC) $(STAGE2)/$(QAST_PBC)
ALL_PBCS = $(HLL_PBC) $(P6REGEX_PBC) $(NQP_PBC) $(CORE_SETTING_PBC) $(MODULE_LOADER_PBC) $(REGEX_PBC)

GROUP = nqp_group
Expand Down Expand Up @@ -639,7 +645,7 @@ $(STAGE2)/$(QREGEX_PBC): $(STAGE1_PBCS) $(STAGE2)/$(CORE_SETTING_PBC) $(QREGEX_S
$(STAGE2)/$(REGEX_PBC): $(DYNEXT_TARGET) $(REGEX_SOURCES) $(STAGE2)/$(CORE_SETTING_PBC)
$(PARROT) -o $(STAGE2)/$(REGEX_PBC) $(REGEX_SOURCES)

$(STAGE2)/$(HLL_PBC): $(STAGE1_PBCS) $(STAGE2)/$(REGEX_PBC) $(STAGE2)/$(CORE_SETTING_PBC) $(QHLL_SOURCES)
$(STAGE2)/$(HLL_PBC): $(STAGE1_PBCS) $(STAGE2)/$(REGEX_PBC) $(STAGE2)/$(CORE_SETTING_PBC) $(STAGE2)/$(QREGEX_PBC) $(QHLL_SOURCES)
$(MKPATH) $(STAGE2)/gen
$(PERL) tools/build/gen-cat.pl $(QHLL_SOURCES) > $(STAGE2)/$(HLL_COMBINED)
$(PARROT) --library=$(STAGE1) $(STAGE1)/$(NQP_PBC) \
Expand All @@ -648,9 +654,17 @@ $(STAGE2)/$(HLL_PBC): $(STAGE1_PBCS) $(STAGE2)/$(REGEX_PBC) $(STAGE2)/$(CORE_SET
$(PARROT) --include=$(STAGE2) -o $(STAGE2)/$(HLL_PBC) \
$(STAGE2)/$(HLL_COMBINED_PIR)

$(STAGE2)/$(P6REGEX_PBC): $(STAGE1_PBCS) $(STAGE2)/$(HLL_PBC) $(P6REGEX_SOURCES)
$(STAGE2)/$(QAST_PBC): $(STAGE1_PBCS) $(STAGE2)/$(CORE_SETTING_PBC) $(STAGE2)/$(HLL_PBC) $(QAST_SOURCES)
$(MKPATH) $(STAGE2)/gen
$(PERL) tools/build/gen-cat.pl $(QAST_SOURCES) > $(STAGE2)/$(QAST_COMBINED)
$(PARROT) --library=$(STAGE1) $(STAGE1)/$(NQP_PBC) \
--target=pir --output=$(STAGE2)/$(QAST_PIR) \
--module-path=$(STAGE2) --setting-path=$(STAGE2) $(STAGE2)/$(QAST_COMBINED)
$(PARROT) -o $(STAGE2)/$(QAST_PBC) $(STAGE2)/$(QAST_PIR)

$(STAGE2)/$(P6REGEX_PBC): $(STAGE1_PBCS) $(STAGE2)/$(HLL_PBC) $(STAGE2)/$(QAST_PBC) $(P6QREGEX_SOURCES)
$(MKPATH) $(STAGE2)/gen
$(PERL) tools/build/gen-cat.pl $(P6REGEX_SOURCES) > $(STAGE2)/$(P6REGEX_COMBINED)
$(PERL) tools/build/gen-cat.pl $(P6QREGEX_SOURCES) > $(STAGE2)/$(P6REGEX_COMBINED)
$(PARROT) --library=$(STAGE1) $(STAGE1)/$(NQP_PBC) \
--target=pir --output=$(STAGE2)/$(P6REGEX_COMBINED_PIR) \
--module-path=$(STAGE2) --setting-path=$(STAGE2) $(STAGE2)/$(P6REGEX_COMBINED)
Expand All @@ -674,6 +688,7 @@ $(ALL_PBCS): $(STAGE2_PBCS)
$(CP) $(STAGE2)/$(QREGEX_PBC) .
$(CP) $(STAGE2)/$(REGEX_PBC) .
$(CP) $(STAGE2)/$(HLL_PBC) .
$(CP) $(STAGE2)/$(QAST_PBC) .
$(CP) $(STAGE2)/$(P6REGEX_PBC) .
$(CP) $(STAGE2)/$(NQP_PBC) .

Expand Down

0 comments on commit 129d9b2

Please sign in to comment.