rename as3 -> avm2 since we don't actually deal with actionscript anywhere
[swf2.git] / compile / compiler-context.lisp
blob4aa545388383cda7c8f5e983ca2130cccc4a5dba
1 (in-package :avm2-compiler)
3 ;;; copied from old code, not used yet...
5 (defclass symbol-table ()
6 ((functions :initform (make-hash-table) :accessor functions)
7 ;; functions are really methods at the bytecode level, haven't
8 ;; figured out how to make separate functions yet
9 (variables :initform (make-hash-table) :accessor variables)
10 (properties :initform (make-hash-table) :accessor properties)
11 ;; not sure if constants work the same as properties yet, so
12 ;; keeping separate for now
13 ;; (static-properties might be a better name, if they are separate?)
14 (constants :initform (make-hash-table) :accessor constants)
15 (class-methods :initform (make-hash-table) :accessor class-methods)
16 (static-methods :initform (make-hash-table) :accessor class-static-methods)
17 (classes :initform (make-hash-table) :accessor classes)
18 (inherited :initform nil :initarg :inherit :accessor inherited-symbol-tables)))
20 (defparameter *player-symbol-table* (make-instance 'symbol-table))
22 (defparameter *cl-symbol-table* (make-instance 'symbol-table :inherit (list *player-symbol-table*)))
24 (defparameter *symbol-table*
25 (make-instance 'symbol-table :inherit (list *cl-symbol-table*)))
27 ;; fixme: combine these?
28 (defun find-swf-method (symbol &optional (s *symbol-table*))
29 (or (car (gethash symbol (class-methods s)))
30 (loop for i in (inherited-symbol-tables s)
31 when (find-swf-method symbol i)
32 return it)))
34 (defun find-swf-static-method (symbol &optional (s *symbol-table*))
35 (or (car (gethash symbol (class-static-methods s)))
36 (loop for i in (inherited-symbol-tables s)
37 when (find-swf-static-method symbol i)
38 return it)))
39 ;;(inherited-symbol-tables *symbol-table*)
40 ;;(find-swf-static-method 'flash::math.random )
42 (defun find-swf-property (symbol &optional (s *symbol-table*))
43 (or (car (gethash symbol (properties s)))
44 (loop for i in (inherited-symbol-tables s)
45 when (find-swf-property symbol i)
46 return it)))
48 (defun find-swf-function (symbol &optional (s *symbol-table*))
49 (or (car (gethash symbol (functions s)))
50 (loop for i in (inherited-symbol-tables s)
51 when (find-swf-function symbol i)
52 return it)))
55 (defun find-swf-class (symbol &optional (s *symbol-table*))
56 (or (gethash symbol (classes s))
57 (loop for i in (inherited-symbol-tables s)
58 when (find-swf-class symbol i)
59 return it)))
61 ;;; handler for normal form evaluation, evaluate ARGS, and call
62 ;;; function/member/whatever identified by OPERATOR
63 (defmethod scompile-cons (operator args)
64 (let ((tmp))
65 (cond
67 ;; if OPERATOR is a known method, call with %call-property
68 ;; (prop obj args...) === obj.prop(args)
69 ((setf tmp (find-swf-method operator *symbol-table*))
70 (scompile `(%call-property ,(first args) ,tmp ,@(rest args))))
72 ;; if OPERATOR is a known static method, call with %call-lex-prop
73 ;; (prop obj args...) === obj.prop(args)
74 ((setf tmp (find-swf-static-method operator *symbol-table*))
75 (scompile `(%call-lex-prop ,(car tmp) ,(second tmp) ,@args)))
77 ;; if OPERATOR is a known property (member var), call %get-property
78 ;; (:prop obj)
79 ((setf tmp (find-swf-property operator *symbol-table*))
80 (scompile `(%get-property ,(first args) ,tmp)))
82 ;; normal function call, find-prop-strict + call-property
83 ((setf tmp (find-swf-function operator *symbol-table*))
84 (scompile `(%call-property-without-object ,(car tmp) ,@args)))
86 ;; default = normal call?
87 ;; fixme: might be nicer if we could detect unknown functions
89 (scompile `(%call-property-without-object ,operator ,@args))
90 #+nil(error " unknown function call? ~s ~s ~% " operator args)))))