|
Class: JavaScriptCompiler
Object
|
+--Scanner
|
+--JavaScriptScanner
|
+--JavaScriptParser
|
+--JavaScriptCompiler
|
+--JavaScriptCompilerWithBreakpointSupport
- Package:
- stx:libjavascript
- Category:
- Languages-JavaScript-Compiling & Parsing
- Version:
- rev:
1.69
date: 2023/08/08 11:12:24
- user: cg
- file: JavaScriptCompiler.st directory: libjavascript
- module: stx stc-classLibrary: libjavascript
JavaScriptCompiler has a lot of stuff copied from ByteCodeCompiler.
This is a very BAD SMELL!
copyrightCOPYRIGHT (c) 2005 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
compiling methods
-
compile: aString forClass: aClass inCategory: cat
-
-
compile: aString forClass: aClass inCategory: cat notifying: requestor
-
compile a source-string for a method in classToCompileFor.
errors are forwarded to requestor.
The method will get cat as category.
Returns the new method, #Error or nil.
-
compile: aString forClass: aClass inCategory: cat notifying: requestor install: install
-
-
compile: aString forClass: aClass inCategory: cat notifying: requestor install: install skipIfSame: skipIfSame silent: silent
-
compile a source-string for a method in aClass.
errors are forwarded to requestor.
The method will get cat as category.
if install is true, the method is installed in the class.
if skipIfSame, the method is not installed if there is no change
(used when filing in).
if silent is true, no warnings are output.
Returns the new method, #Error or nil.
-
compile: aString forClass: aClass inCategory: cat notifying: requestor install: install skipIfSame: skipIfSame silent: silent foldConstants: fold
-
not needed...
-
compile: aString in: aClass notifying: requestor ifFail: failBlock
-
-
evaluate: aString notifying: requestor compile: doCompile
-
used to install new classes
-
newCodeSet
-
instance creation
-
new
-
Pretty ugly hack. A caller to compiler may provide a set of breakpoints
private
-
selectorFor: jsName numArgs: nargs
-
self selectorFor:'foo' numArgs:0 -> #foo
self selectorFor:'foo' numArgs:1 -> #foo:
self selectorFor:'foo' numArgs:2 -> #'foo:_:'
self selectorFor:'foo' numArgs:3 -> #'foo:_:_:'
self selectorFor:'foo' numArgs:4 -> #'foo:_:_:_:'
self selectorFor:'foo' numArgs:5 -> #'foo:_:_:_:_:'
accessing
-
methodClass: something
-
code generation
-
absJumpFromJump: code
-
given a jump-symbolic code, return corresponding absolute jump
-
addLiteral: anObject
-
add a literal to the literalArray - watch for and eliminate
duplicates. return the index of the literal in the Array
-
addReloc: symIndex
-
remember to relocate offset at symIndex later ...
-
appendByte: aByte
-
append a byte to the code-Array, checking for byte-range (debug-only)
-
appendByteCodeFor: codeSymbol
-
append the byteCode for an instructionSymbol to the code-Array
-
appendEmptyByte
-
append an empty byte to the code-Array
-
appendSignedByte: aByte
-
append a signedbyte (as in jump-offsets) to the code-Array,
check range and report an error if invalid
-
appendSignedWord: aWord
-
append a signed word to the code-Array,
check range and report an error if invalid
-
appendWord: aWord
-
append an unsigned word (low-high) to the code-Array,
checking for word-range (debug-only)
-
byteCodeFor: aSymbol
-
given a symbolic instruction, return the corresponding bytecode.
as a side-effect, leave number of bytes pushed/popped by this instr.
in stackDelta, and, if the instruction needs extra arguments, leave
this info in extra. Also lineno is set to true, if this code has line
information and extraLiteral is set if any hidden send is performed by it.
-
code
-
-
codeLineNumber: nr on: codeStream
-
generate lineNumber information
-
contextMustBeReturnable
-
-
correctedSource
-
-
createMethod
-
fixup CheapBlocks method-field in literal array,
-
genByteCodeFrom: symbolicCodeArray
-
convert symbolicCode into bytecodes
-
genSymbolicCode
-
traverse the parse-tree producing symbolicCode - return the codeArray
-
generateVariables: varCollection on: codeStream
-
generate code to set it up.
-
isBuiltInSelector: sel forReceiver: receiver
-
-
maxStackDepth
-
-
methodClass
-
-
numberOfMethodArgs
-
-
numberOfMethodVars
-
-
relocateWith: symbolicCodeArray relocInfo: relocInfo
-
helper for genByteCodeFrom - relocate code using relocInfo.
if relocation fails badly (due to long relative jumps) patch
symbolicCode to use absolute jumps instead and return false
(genByteCodeFrom will then try again). Otherwise return true.
Also, on the fly, jumps to jumps and jumps to return are handled.
-
specialGlobalCodeFor: aSymbol
-
-
specialSendCodeFor: sel
-
return the codeExtension for sends,
which can be performed by specialSend opCode
compiling
-
compile: aString forClass: aClass inCategory: cat
-
compile from source code
-
compile: aString forClass: aClass inCategory: cat notifying: requestorArg install: install skipIfSame: skipIfSame silent: silent foldConstants: fold
-
compile from source code
-
compile: sourceCodeString forClass: aClass inCategory: cat notifying: aRequestor install: install skipIfSame: skipIfSame silent: silent foldConstants: fold ifFail: failBlock
-
compile from source code
-
compileTree: tree source: sourceString forClass: aClass inCategory: cat notifying: requestor install: install skipIfSame: skipIfSame silent: silent foldConstants: fold
-
compile from a parsetree
-
compileTree: tree source: sourceString forClass: aClass inCategory: cat notifying: requestor install: install skipIfSame: skipIfSame silent: silent foldConstants: fold ifFail: failBlock
-
compile from a parsetree
initialization
-
reset
-
needed between functions, when reading multiple functions
loops
-
loopDescription
-
-
newLoopDescription
-
-
newLoopDescriptionForBlock
-
-
newSwitchDescription
-
-
popLoopDescription
-
-
pushLoopDescription: aDescription
-
parsing
-
compileFunctionDefinitions
-
because the first token ('function') has already been read,
LoopDescription
LoopDescriptionForBlock
SwitchDescription
|f|
f := JavaScriptCompiler
compile:'max(a, b) {
if (a > b) return a;
return b;
}'
forClass:nil
inCategory:nil
notifying:nil.
f valueWithReceiver:nil arguments:#(10 20).
|
|f|
f := JavaScriptCompiler
compile:'max(a, b) {
if (a > b) ;
else return b;
return a;
}'
forClass:nil
inCategory:nil
notifying:nil.
f valueWithReceiver:nil arguments:#(10 20).
|
|f|
f := JavaScriptCompiler
compile:'max(a, b) {
if (a > b) return a;
else return b;
}'
forClass:nil
inCategory:nil
notifying:nil.
f valueWithReceiver:nil arguments:#(20 10).
|
|f|
f := JavaScriptCompiler
compile:('test(arg) {
var n;
n = arg;
while (n > 0) {
n--;
Transcript.showCR(#hello#);
}
}' replaceAll:$# with:Character doubleQuote)
forClass:nil
inCategory:nil
notifying:nil.
f valueWithReceiver:nil arguments:#(5).
|
|f|
f := JavaScriptCompiler
compile:('test(arg) {
var n;
n = 1;
while (n <= arg) {
n++;
Transcript.showCR(#hello#);
}
}' replaceAll:$# with:Character doubleQuote)
forClass:nil
inCategory:nil
notifying:nil.
f valueWithReceiver:nil arguments:#(5).
|
|f|
f := JavaScriptCompiler
compile:'test(arg) {
var n;
n = 1;
while (n <= arg) {
Transcript.showCR(n++);
}
}'
forClass:nil
inCategory:nil
notifying:nil.
f valueWithReceiver:nil arguments:#(5).
|
|f|
f := JavaScriptCompiler
compile:'test(arg) {
var n;
n = 1;
while (n++ <= arg) {
Transcript.showCR(n);
}
}'
forClass:nil
inCategory:nil
notifying:nil.
f valueWithReceiver:nil arguments:#(5).
|
|f|
f := JavaScriptCompiler
compile:'foo() {
Transcript.showCR(''start'');
try {
Error.raise();
} catch(Error) {
Transcript.showCR(''caught error'');
};
Transcript.showCR(''end'');
}'
forClass:nil
inCategory:nil
notifying:nil.
f valueWithReceiver:nil arguments:#().
|
|