1
0
mirror of https://github.com/weiju/amiga-stuff synced 2025-11-22 10:08:15 +00:00

added fdtool runner for racket and refined the function offset computation

This commit is contained in:
Wei-ju Wu
2013-02-28 20:24:25 -08:00
parent 60573256c1
commit 112562c8b1
2 changed files with 21 additions and 7 deletions

5
fdtool/fdcmd.rkt Normal file
View File

@ -0,0 +1,5 @@
#lang racket
;; A simple top-level program to
(require "fdtool.rkt")
(process-fd (command-line #:program "fdtool.rkt"
#:args (filename) filename))

View File

@ -22,22 +22,31 @@
[(and (> (string-length line) 7) (string=? (substring line 0 6) "##base"))
(hash-set! params "base" (substring line 7))]
[(and (> (string-length line) 7) (string=? (substring line 0 6) "##bias"))
(hash-set! params "bias" (string->number (substring line 7)))])
(hash-set! params "offset" (string->number (substring line 7)))])
params)
;; process a function definition, extracting the function name,
;; the parameter names and the assigned registers
(define (process-fundef params line)
(let* ([fun-regexp #rx"^([^()]+)[(]([^()]*)[)][(]([^()]*)[)].*$"]
[fun-match (regexp-match fun-regexp line)])
(cond [fun-match (print (cdr fun-match))])))
(let ([fun-match (regexp-match
#rx"^([^()]+)[(]([^()]*)[)][(]([^()]*)[)].*$" line)])
(cond [fun-match
;; only process public functions
(cond [(not (hash-ref params "is-private"))
(printf "-~s -> ~a\n"
(hash-ref params "offset") (car (cdr fun-match)))])
;; we need to advance the offset for both private and public
(hash-set! params "offset" (+ 6 (hash-ref params "offset")))])))
;; Process the input file line-by-line
(define (process-fd filename)
;; params is a hash, could be a struct as well
(let* ([params (make-hash '(("base" . "") ("is-private" . #T) ("bias" . 0)))]
[lines (filter (lambda (x) (not (fd-comment? x))) (file->lines filename))])
(let ([params (make-hash '(("base" . "")
("is-private" . #T)
("offset" . 0)))]
[lines (filter (lambda (x) (not (fd-comment? x))) (file->lines filename))])
(map (lambda (line)
(if (fd-command? line) (set! params (process-command params line))
(process-fundef params line))) lines)
params))
;; make sure we do not print a potential return value
(void)))