added a new class variable declarator 'var' or 'variable'

supported  | .. | style declartion at the class level.
added the RDONLY flag to the object header
wrote some code to support default values for class-level variables such as instance variables
This commit is contained in:
hyunghwan.chung
2017-04-19 16:46:44 +00:00
parent a768bd8803
commit 4656bf128e
21 changed files with 864 additions and 476 deletions

View File

@ -133,6 +133,15 @@ class Apex(nil)
method basicAt: index put: anObject
{
<primitive: #_basic_at_put>
## TODO: proper error handling
(*
if (primitiveError == error(generic))
{
}
else
{
self index: index outOfRange: (self basicSize).
}*)
self index: index outOfRange: (self basicSize).
}
@ -429,6 +438,11 @@ class Apex(nil)
{
^self class notImplemented: method_name
}
method messageProhibited: method_name
{
^self class messageProhibited: method_name
}
method cannotExceptionizeError
{

View File

@ -4,7 +4,8 @@
##
class(#pointer) Class(Apex)
{
dcl spec selfspec superclass subclasses name modname instvars classvars classinstvars pooldics instmthdic classmthdic nsdic trsize.
var spec, selfspec, superclass, subclasses, name, modname, instvars.
var classvars, classinstvars, pooldics, instmthdic, classmthdic, nsdic, cdic, trsize, initv.
method(#class) basicNew
{

View File

@ -164,7 +164,7 @@ class(#byte) ByteArray(Collection)
class Set(Collection)
{
dcl tally bucket.
var tally, bucket.
method(#class) new: size
{
@ -550,7 +550,7 @@ extend Apex
class Link(Object)
{
dcl prev next value.
var prev, next, value.
method(#class) new: value
{
@ -570,7 +570,7 @@ class Link(Object)
class LinkedList(Collection)
{
dcl first last tally.
var first, last, tally.
method initialize
{

View File

@ -1,7 +1,7 @@
## TODO: move Pointe to a separate file
class Point(Object)
{
dcl x y.
var x, y.
method(#class) new
{

View File

@ -1,6 +1,6 @@
class(#pointer) Context(Apex)
{
dcl sender ip sp ntmprs.
var sender, ip, sp, ntmprs.
method sender
{
@ -44,7 +44,7 @@ block context...
class(#pointer) MethodContext(Context)
{
dcl method receiver home origin.
var method, receiver, home, origin.
method pc
{
@ -101,7 +101,7 @@ class(#pointer) MethodContext(Context)
class(#pointer) BlockContext(Context)
{
dcl nargs source home origin.
var nargs, source, home, origin.
method vargCount
{
@ -328,8 +328,8 @@ class(#pointer) BlockContext(Context)
class(#pointer) CompiledMethod(Object)
{
## dcl owner name preamble preamble_data_1 preamble_data_2 ntmprs nargs code source.
dcl owner name preamble preamble_data_1 preamble_data_2 ntmprs nargs source.
## var owner, name, preamble, preamble_data_1, preamble_data_2, ntmprs, nargs, code, source.
var owner, name, preamble, preamble_data_1, preamble_data_2, ntmprs, nargs, source.
method preamble
{

View File

@ -6,7 +6,7 @@
##
class Exception(Apex)
{
dcl signalContext handlerContext messageText.
var signalContext, handlerContext, messageText.
method(#class) signal
{
@ -383,6 +383,10 @@ class InvalidArgumentException(Exception)
{
}
class ProhibitedMessageException(Exception)
{
}
extend Apex
{
method(#class) primitiveFailed
@ -428,6 +432,11 @@ ctx := thisContext.
NotImplementedException signal: (method_name & ' not implemented by ' & (self name)).
}
method(#class) messageProhibited: method_name
{
ProhibitedMessageException signal: (method_name & ' not allowed for ' & (self name)).
}
method(#class) cannotExceptionizeError
{
## todo: accept the object

View File

@ -10,7 +10,7 @@ class _FFI(Object) from 'ffi'
class FFI(Object)
{
dcl name ffi funcs.
var name, ffi, funcs.
method(#class) new: aString
{

View File

@ -4,7 +4,7 @@ class Magnitude(Object)
class Association(Magnitude)
{
dcl key value.
var key, value.
method(#class) key: key value: value
{

View File

@ -2,8 +2,8 @@
class Mill(Object)
{
dcl registrar.
dcl obj.
var registrar.
var obj.
method initialize
{

View File

@ -1,7 +1,7 @@
class(#pointer) Process(Object)
{
dcl initial_context current_context state sp prev next sem.
var initial_context, current_context, state, sp, prev, next, sem.
method new
{
@ -99,7 +99,7 @@ class(#pointer) Process(Object)
class Semaphore(Object)
{
dcl count waiting_head waiting_tail heapIndex fireTimeSec fireTimeNsec ioIndex ioData ioMask.
var count, waiting_head, waiting_tail, heapIndex, fireTimeSec, fireTimeNsec, ioIndex, ioData, ioMask.
method(#class) forMutualExclusion
{
@ -176,7 +176,7 @@ class Semaphore(Object)
class SemaphoreHeap(Object)
{
dcl arr size.
var arr, size.
method initialize
{
@ -358,7 +358,7 @@ class SemaphoreHeap(Object)
class ProcessScheduler(Object)
{
dcl tally active runnable_head runnable_tail sem_heap.
var tally, active, runnable_head, runnable_tail, sem_heap.
method new
{

View File

@ -1,7 +1,7 @@
class Stdio(Object) from 'stdio'
{
dcl(#class) in out err.
var(#class) in, out, err.
method(#primitive) open(name, mode).
method(#primitive) close.

View File

@ -6,18 +6,18 @@ class X11(Object) from 'x11'
{
(* The X11 class represents a X11 display *)
dcl(#class) default_display.
var(#class) default_display.
dcl cid.
dcl windows. ## all windows registered
var cid.
var windows. ## all windows registered
dcl event_loop_sem event_loop_proc.
dcl ll_event_blocks.
var event_loop_sem, event_loop_proc.
var ll_event_blocks.
dcl expose_event.
dcl key_event.
dcl mouse_event.
dcl mouse_wheel_event.
var expose_event.
var key_event.
var mouse_event.
var mouse_wheel_event.
method(#primitive) _connect.
method(#primitive) _disconnect.
@ -35,7 +35,7 @@ class X11.Exception(System.Exception)
class X11.Rectangle(Object)
{
dcl x y width height.
var x, y, width, height.
method initialize
{
@ -79,6 +79,7 @@ pooldic X11.LLEvent
LEAVE_NOTIFY := 8.
EXPOSE := 12.
VISIBILITY_NOTIFY := 15.
DESTROY_NOTIFY := 17.
CONFIGURE_NOTIFY := 22.
CLIENT_MESSAGE := 33.
}
@ -87,36 +88,56 @@ class X11.Event(Object)
{
}
class X11.InputEvent(X11.Event)
class X11.KeyEvent(X11.Event)
{
}
class X11.KeyEvent(X11.InputEvent)
pooldic X11.MouseButton
{
LEFT := 1.
MIDDLE := 2.
RIGHT := 3.
}
class X11.MouseEvent(X11.InputEvent)
class X11.MouseEvent(X11.Event)
{
dcl x y.
var x, y, button.
method x { ^self.x }
method y { ^self.y }
method x { ^self.x }
method y { ^self.y }
method button { ^self.button } ## X11.MouseButton
method x: x y: y
method initialize
{
self.x := 0.
self.y := 0.
self.button := 0.
}
method x: x y: y button: button
{
self.x := x.
self.y := y.
self.button := button.
}
}
class X11.MouseWheelEvent(X11.InputEvent)
class X11.MouseWheelEvent(X11.Event)
{
dcl x y amount.
var x, y, amount.
method x { ^self.x }
method y { ^self.y }
method amount { ^self.amount }
method initialize
{
self.x := 0.
self.y := 0.
self.amount := 0.
}
method x: x y: y amount: amount
{
self.x := x.
@ -127,13 +148,21 @@ class X11.MouseWheelEvent(X11.InputEvent)
class X11.ExposeEvent(X11.Event)
{
dcl x y width height.
var x, y, width, height.
method x { ^self.x }
method y { ^self.y }
method width { ^self.width }
method height { ^self.height }
method initialize
{
self.x := 0.
self.y := 0.
self.width := 0.
self.height := 0.
}
method x: x y: y width: width height: height
{
self.x := x.
@ -143,11 +172,6 @@ class X11.ExposeEvent(X11.Event)
}
}
class X11.WindowEvent(X11.Event)
{
dcl width height.
}
## ---------------------------------------------------------------------------
## Graphics Context
## ---------------------------------------------------------------------------
@ -163,7 +187,7 @@ pooldic X11.GCAttr
class X11.GC(Object) from 'x11.gc'
{
dcl window id.
var window, id.
method(#primitive) _make (display, window).
method(#primitive) _kill.
@ -215,7 +239,7 @@ class X11.GC(Object) from 'x11.gc'
class X11.Component(Object)
{
dcl parent.
var parent.
method new
{
@ -268,8 +292,8 @@ class X11.Canvas(Component)
class X11.WindowedComponent(Component) from 'x11.win'
{
dcl(#class) geom.
dcl wid bounds.
var(#class) geom.
var wid, bounds.
method(#primitive) _get_window_dwatom.
method(#primitive) _get_window_id.
@ -331,6 +355,11 @@ class X11.WindowedComponent(Component) from 'x11.win'
}
}
method cachedBounds
{
^self.bounds
}
method bounds
{
self _get_window_geometry (self.bounds).
@ -374,7 +403,7 @@ class X11.WindowedComponent(Component) from 'x11.win'
}
method mousePressed: event
{
('MOUSE PRESSED' & (self.wid asString) & ' ' & (event x asString) & ' ' & (event y asString)) dump.
('MOUSE PRESSED' & (self.wid asString) & ' ' & (event x asString) & ' ' & (event y asString) & ' ' & (event button asString)) dump.
}
method mouseReleased: event
{
@ -388,7 +417,7 @@ class X11.WindowedComponent(Component) from 'x11.win'
class X11.Container(WindowedComponent)
{
dcl components.
var components.
method initialize
{
@ -417,7 +446,7 @@ class X11.Container(WindowedComponent)
class X11.FrameWindow(Container)
{
dcl display.
var display.
method display { ^self.display }
method display: display { self.display := display }
@ -528,6 +557,7 @@ extend X11
at: X11.LLEvent.ENTER_NOTIFY put: #__handle_notify:;
at: X11.LLEvent.LEAVE_NOTIFY put: #__handle_notify:;
at: X11.LLEvent.EXPOSE put: #__handle_expose:;
at: X11.LLEvent.DESTROY_NOTIFY put: #__handle_destroy_notify:;
at: X11.LLEvent.CONFIGURE_NOTIFY put: #__handle_configure_notify:;
at: X11.LLEvent.CLIENT_MESSAGE put: #__handle_client_message:.
}
@ -583,12 +613,9 @@ extend X11
while ((event := self _get_event) notNil)
{
## XCB_EXPOSE 12
## XCB_DESTROY_WINDOW 4
('EVENT================>' & event asString) dump.
if (event isError)
{
'Error has occurred in ....' dump.
System logNl: ('Error while getting a event from display ' & self.cid asString).
ongoing := false.
break.
}
@ -638,7 +665,6 @@ extend X11
}
else
{
('Performing ...' & mthname asString) dump.
^self perform (mthname, event).
##^self perform: mthname with: event.
}
@ -698,6 +724,7 @@ extend X11
method __handle_button_event: event
{
(*
typedef uint8_t xcb_button_t;
typedef struct xcb_button_press_event_t {
uint8_t response_type;
xcb_button_t detail; // uint8_t
@ -731,16 +758,10 @@ extend X11
detail := event getUint8(1).
if (detail >= 1 and: [detail <= 3])
{
(*
self.mouse_event
## TODO: encode detail also..
x: System _getUint16(event, 24) ## event_x
y: System _getUint16(event, 26). ## event_y
*)
self.mouse_event
## TODO: encode detail also..
x: event getUint16(24) ## event_x
y: event getUint16(26). ## event_y
x: event getUint16(24) ## event_x
y: event getUint16(26) ## event_y
button: detail.
if (type == X11.LLEvent.BUTTON_PRESS)
{
@ -755,12 +776,6 @@ extend X11
{
if (type == X11.LLEvent.BUTTON_RELEASE)
{
(*
self.mouse_wheel_event
x: System _getUint16(event, 24) ## event_x
y: System _getUint16(event, 26) ## event_y
amount: (if (detail == 4) { -1 } else { 1 }).
*)
self.mouse_wheel_event
x: event getUint16(24) ## event_x
y: event getUint16(26) ## event_y
@ -775,6 +790,33 @@ extend X11
}
}
method __handle_destroy_notify: event
{
(*
typedef struct xcb_destroy_notify_event_t {
uint8_t response_type;
uint8_t pad0;
uint16_t sequence;
xcb_window_t event;
xcb_window_t window;
} xcb_destroy_notify_event_t;
*)
| wid window |
wid := System _getUint32(event, 4). ## event
window := self.windows at: wid.
if (window notError)
{
'WINDOW DESTROYED....................' dump.
}
else
{
System logNl: ('Destroy notify event on unknown window - ' & wid asString).
}
}
method __handle_configure_notify: event
{
(*
@ -805,7 +847,7 @@ extend X11
{
width := System _getUint16(event, 20).
height := System _getUint16(event, 22).
bounds := window bounds.
bounds := window cachedBounds. ## old bounds before resizing.
if (bounds width ~= width or: [bounds height ~= height]) { window windowResized }.
}
else
@ -844,7 +886,6 @@ extend X11
dw := event getUint32(12). ## data.data32[0]
if (dw == window _get_window_dwatom)
{
## TODO: call close query callback???
window close.
}
@ -914,9 +955,9 @@ class MyButton(X11.Button)
class MyFrame(X11.FrameWindow)
{
dcl gc.
dcl b1.
dcl b2.
var gc.
var b1.
var b2.
method windowOpened
{

View File

@ -62,7 +62,7 @@ class MyObject(Object)
') expected'
'] expected'
'. expected'
' expected'
', expected'
'| expected'
'> expected'
':= expected'
@ -75,14 +75,15 @@ class MyObject(Object)
'contradictory class definition'
'wrong class name'
'non-pointer class inheriting superclass with trailer size set'
'dcl not allowed'
'variable declaration not allowed'
'modifier expected'
'wrong modifier'
'disallowed modifier'
'duplicate modifier'
'wrong method name'
'method name expected'
'duplicate method name'
'invalid variadic method definition'
'variable name expected'
'duplicate argument name'
'duplicate temporary variable name'
'duplicate variable name'