AutoHotkey Community

It is currently May 27th, 2012, 6:51 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Introspection
PostPosted: September 15th, 2011, 6:29 am 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
I am playing around with exposing some autohotkey internals as script objects.

Using Lexikos' implementation of the func object as a guide, I have created object types for: line, hotkey, hotkeyvariant, argstruct, and exprtokentype.
So far only a few attributes are exposed:
argstruct: nextArg, test, token
exprtokentype: nextToken, test, symbol, token (circuit_token)
Line: actionType, argStruct, nextLine, sourceFile, sourceLine, source (sourcetext)
hotkeyvariant: hotwintitle, hotwintext, hotexpression, hotcriterion, nextvariant
hotkey: name, modifiers, variant, keyup, suppress

these attributes are readonly for now.
I plan to add more, and start making some writable.

I had to replace simpleheap::malloc with new ExprTokenType[size], increasing memory usage.

I also added func.sourceFile and func.sourceLine, to the func object.

I hope to be able to dump a syntax tree of the ahk internals in to a script object. Then I can use it as a test for a new pygments / ply based ahk parser.

source: https://github.com/tinku99/ahkdll
test script: https://github.com/tinku99/ahkdll/blob/ ... t/test.ahk

by the way, I couldn't have done this without having read the c++ fqa recently.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 15th, 2011, 7:28 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
I would rather love to see lowlevel functions in AHK_L.
We could also provide functions to get pointers to global AHK structures like g, g_script and others.

In AHK_H you can already do that:
Code:
#include <AHKStructures>
#include <_Struct>

f := new _Struct(_AHKFunc,FindFunc("fx"))
msgbox % f.JumpToLine.FileIndex " - " f.JumpToLine.LineNumber

l:=f.JumpToLine ;new _Struct(_AHKLine,line:=DllCall(A_AhkPath "\ahkExecuteLine","UInt",0,"Uint",0,"UInt",0)) ;get first line

msgbox % l.FileIndex " " l.LineNumber " actiontype: " l.ActionType " source: " l.arg.text
l := l.NextLine

a := l.arg
msgbox % "argstruct text: " a.text
t := a.postfix
msgbox % "token symbol: " t.symbol
Return

fx(){
msgbox % test
msgbox % "test"
}
f5::
reload
return

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Introspection
PostPosted: September 15th, 2011, 7:55 pm 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
HotKeyIt wrote:
I would rather love to see lowlevel functions in AHK_L.
We could also provide functions to get pointers to global AHK structures like g, g_script and others.
In AHK_H you can already [parse]... <AHKStructures>

agree with exposing global ahk structures.
I would rather provide script objects rather than pointers to structs alone for easier maintainability.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Introspection
PostPosted: September 15th, 2011, 10:53 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
tinku99 wrote:
I had to replace simpleheap::malloc with new ExprTokenType[size], ...
Search the project for "operator new" to see how new and delete can be overloaded to use SimpleHeap.
Quote:
... increasing memory usage.
Increasing the size of ExprTokenType (by adding virtual methods/a virtual function table) means more stack memory used for each expression-evaluation, which means that fewer recursions can be made into recursive script functions before stack overflow occurs.
Quote:
agree with exposing global ahk structures.
I disagree with exposing internal structures. The entire line -> arg -> deref/postfix array hierarchy may change in a future version, and most of it is useful only in very specific cases.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group