funky Compiler implementation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

funky Compiler implementation

Nicolas Cellier
Try:

Compiler evaluate: '0r0 + 1'.

Then:

Compiler evaluate: '1 + 0r0'.

and explain the difference...

...

It lies in initialization, the first token being scanned before the
encoder is set properly...
No encoder, no class information easily accessible, no
SyntaxErrorNotification issued...
So the first returns nil...

Nicolas

Reply | Threaded
Open this post in threaded view
|

Re: funky Compiler implementation

Nicolas Cellier
2010/2/25 Nicolas Cellier <[hidden email]>:

> Try:
>
> Compiler evaluate: '0r0 + 1'.
>
> Then:
>
> Compiler evaluate: '1 + 0r0'.
>
> and explain the difference...
>
> ...
>
> It lies in initialization, the first token being scanned before the
> encoder is set properly...
> No encoder, no class information easily accessible, no
> SyntaxErrorNotification issued...
> So the first returns nil...
>
> Nicolas
>

 I could attempt to change this one:

parse: sourceStream class: class category: aCategory noPattern:
noPattern context: ctxt notifying: req ifFail: aBlock
        "Answer a MethodNode for the argument, sourceStream, that is the root of
         a parse tree. Parsing is done with respect to the argument, class, to find
         instance, class, and pool variables; and with respect to the argument,
         ctxt, to find temporary variables. Errors in parsing are reported to the
         argument, req, if not nil; otherwise aBlock is evaluated. The argument
         noPattern is a Boolean that is true if the the sourceStream does not
         contain a method header (i.e., for DoIts)."

        | methNode repeatNeeded myStream s p |
        category := aCategory.
        myStream := sourceStream.
        [repeatNeeded := false.
         p := myStream position.
         s := myStream upToEnd.
         myStream position: p.
+ self encoder init: class context: ctxt notifying: self.
         self init: myStream notifying: req failBlock: [^ aBlock value].
         doitFlag := noPattern.
         failBlock:= aBlock.
         [methNode := self
                                        method: noPattern
                                        context: ctxt
- encoder: (self encoder init: class context: ctxt notifying: self)]
+ encoder: self encoder]
                on: ReparseAfterSourceEditing
                do: [ :ex |
                        repeatNeeded := true.
                        myStream := ReadStream on: requestor text string].
! But there is a minor problem here ^^^^^^^^^^^^^^^^^^^
         repeatNeeded] whileTrue:
                [encoder := self encoder class new].
        methNode sourceText: s.
        ^methNode

The problem is if I select some partial code to evaluate in a Debugger
or a Workspace:

| a b |
^(a := 1) + a

And that I remove b, then the whole text is compiled instead of just
my selection...
I find all these workarounds like requestorOffset and the like very fragile...

Nicolas