-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into kjcjohnson/json-problem
- Loading branch information
Showing
17 changed files
with
377 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
;;;; | ||
;;;; Compiles programs into a single state transformer function | ||
;;;; | ||
(in-package #:com.kjcjohnson.synthkit.ast) | ||
|
||
(defun %compile-process-calling-card (semantics node cc) | ||
"Processes a single calling card and returns a transformer function" | ||
(let* ((children-sem-fns | ||
(loop for req in (semantics-descriptor-requests cc) | ||
for desc = (semantics-descriptor-request-descriptor req) | ||
for id = (semantics-descriptor-request-node-id req) | ||
if (eql id :self) ; do-compile-and-cache handles the rec call machinery | ||
collect (compile-program semantics desc node) | ||
else | ||
collect (compile-program semantics desc (nth-child id node))))) | ||
(funcall (semantic-builder-function cc) | ||
children-sem-fns | ||
node | ||
(children node)))) | ||
|
||
(defun %compile-combine-chc-transformers (chc-transformers) | ||
"Combines multiple CHC transformer functions into a single transformer" | ||
(if (> (length chc-transformers) 1) | ||
(lambda (input-state) | ||
(declare (type smt:state input-state)) | ||
(declare (optimize (speed 3))) | ||
(loop for transformer in chc-transformers | ||
do (multiple-value-bind (result valid) | ||
(funcall (the transformer transformer) | ||
input-state) | ||
(when (or (not (null result)) valid) | ||
(return (values result t))))) | ||
(error "No applicable semantics")) | ||
(first chc-transformers))) | ||
|
||
(defun compile-program (semantics descriptor node) | ||
"Walks program rooted at NODE and returns a compiled function of one argument, the | ||
input state, that returns the output state computed using SEMANTICS from DESCRIPTOR" | ||
(do-compile-or-cache (node descriptor) | ||
(let ((ccs (operational-semantics-for-production semantics | ||
descriptor | ||
(production node)))) | ||
(%compile-combine-chc-transformers | ||
(loop for cc in ccs | ||
collecting (%compile-process-calling-card semantics node cc)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
;;;; | ||
;;;; Program traversal | ||
;;;; | ||
(in-package #:com.kjcjohnson.synthkit.ast) | ||
|
||
(defun traverse-program (program function type) | ||
"Traverses the atoms of PROGRAM, calling FUNCTION on each one (at time by TYPE)" | ||
(declare (type program-atom program) | ||
(type (function (program-atom)) function) | ||
(type (member :pre-order :post-order) type)) | ||
(flet ((call-node () | ||
(funcall function program)) | ||
(iterate-children () | ||
(when (typep program 'program-node) | ||
(loop for child in (children program) | ||
do (traverse-program child function type))))) | ||
(case type | ||
(:pre-order | ||
(call-node) | ||
(iterate-children)) | ||
(:post-order | ||
(iterate-children) | ||
(call-node))))) | ||
|
||
(*:define-do-macro do-traverse-program ((var program type &optional return) &body body) | ||
`(traverse-program ,program #'(lambda (,var) ,@body) ,type)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
;;;; | ||
;;;; Variables for AST and execution control | ||
;;;; | ||
(in-package #:com.kjcjohnson.synthkit.ast) | ||
|
||
;;; | ||
;;; Allows exiting a program early | ||
;;; | ||
(defvar *program-execution-exit-hook*) | ||
(defun abort-program-execution () | ||
(funcall *program-execution-exit-hook*)) | ||
|
||
;;; | ||
;;; Handles simple unbounded-recursion detection | ||
;;; | ||
(defvar *self-recursion-counter* 0 | ||
"Counts recursion depth to find probably-non-terminating programs.") | ||
(defparameter *self-recursion-limit* 200) | ||
(declaim (type fixnum *self-recursion-counter* *self-recursion-limit*)) | ||
|
||
;;; | ||
;;; Debugging controls | ||
;;; | ||
(defvar *exe-debug* nil "Set to T when execution debugging is triggered") | ||
(defvar *exe-level* 0 "Level of nested program execution") | ||
(defvar *exe-debug-match* nil "If non-nil, must be a string that, when contained in the | ||
serialization of a program node, triggers ``*EXE-DEBUG*`` to be set to T.") | ||
(declaim (type (or null string) *exe-debug-match*)) | ||
|
||
;;; | ||
;;; Stores the root input state | ||
;;; | ||
(defvar *root-input-state* nil "The initial input state passed to EXECUTE-PROGRAM") | ||
(defvar *root-input-descriptor* nil "The initial descriptor passed to EXECUTE-PROGRAM") | ||
|
||
;;; | ||
;;; Control variables | ||
;;; | ||
(defvar *use-program-compiler* nil "Whether or not to use the program compiler") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.