Skip to content

Commit

Permalink
Work on chained dot calls
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKBeck committed Apr 30, 2018
1 parent 49ea869 commit 1c18ade
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
20 changes: 16 additions & 4 deletions Tests/4/test00.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
class A {
var x = 100;
var a = 0;

static function main() {
return 4;
function X() {
a = a + 1;
return this;
}

function Y() {
a = a + 1;
return this;
}

}
static function main() {
var obj = new A();
obj.X().Y();

return obj.a;
}
}
40 changes: 34 additions & 6 deletions state-manipulation.scm
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,34 @@
(get-current-class state cfuncsinstance)
#f
cfuncsinstance))

; single case: funcall (funcall (dot obj X))
; non-single case: (funcall (dot (funcall (dot obj X)) Y))

; dotted-class-instance: 'a (the name of the instance
; dottedname: (a f) where f is the name of the call and a is the object
((and (dot-expr? name) (list? (dotted-class-instance (arglist-dot name))))
(let* ([evaled-instance-pair (G-eval-atomic-statement->value_state
(dotted-class-instance (arglist-dot name))
state
cfuncsinstance)]

; TODO: left off on line below
;[evaled-instance (list `(classname ,(get-base-class (get-value-from-pair evaled-instance-pair)))
; (get-value-from-pair evaled-instance-pair))]
[evaled-instance (get-value-from-pair evaled-instance-pair)]
[evaled-state (push-variable-as-literal->state '.temp evaled-instance (get-state-from-pair evaled-instance-pair))]
[dottedname (list '.temp (dotted-class-call (arglist-dot name)))]
[evaled-function (eval-function-post-name-eval (evaluate-dotted-function-name dottedname evaled-state)
args
evaled-state
(construct-dotted-state dottedname evaled-state)
(get-current-class (construct-dotted-state dottedname evaled-state) cfuncsinstance)
#t
cfuncsinstance)]
[function-return (get-value-from-pair evaled-function)]
[function-state (get-state-from-pair evaled-function)])
(list function-return (update-class-instance (dotted-class-instance dottedname) (extract-new-class-instance-state function-state) evaled-state))))
((dot-expr? name)
(let* ([dottedname (arglist-dot name)]
[evaled-function (eval-function-post-name-eval (evaluate-dotted-function-name dottedname state)
Expand All @@ -152,9 +180,9 @@
[function-return (get-value-from-pair evaled-function)]
[function-state (get-state-from-pair evaled-function)])
(list function-return (update-class-instance (dotted-class-instance dottedname) (extract-new-class-instance-state function-state) state))))
(else (eval-function-post-name-eval name args state state default-currentclass #t cfuncsinstance)))))
;(trace G-eval-function->value_state)
(else (eval-function-post-name-eval name args state state default-currentclass #t cfuncsinstance)))))

(trace G-eval-function->value_state)
(define get-base-class
(lambda (state cfuncsinstance)
(get-value-from-pair (G-value-lookup->value_state '.class state cfuncsinstance))))
Expand Down Expand Up @@ -267,7 +295,7 @@
(lambda (instancename state)
(append (G-get-instance-state instancename state)
(G-pop-to-class-level->state state))))

(trace add-class-instance-to-state)
(define extract-new-class-instance-state
(lambda (state)
(reverse (extract-new-class-instance-state-sub (get-tail-scope (reverse state))))))
Expand Down Expand Up @@ -480,6 +508,7 @@
(cond
(else (list (list 'classname cn) (G-eval-class-closure->state cn state)))))))


; Pushes the declaration statement to the state
(define declare-var->state
(lambda (name state)
Expand Down Expand Up @@ -536,8 +565,7 @@
(define handle-this-expr
(lambda (state)
(list (extract-new-class-instance-state state) state)))

; STUB
(trace handle-this-expr)
(define dot-expr?
(lambda (arglist)
(cond
Expand Down

0 comments on commit 1c18ade

Please sign in to comment.