File: HACKING

package info (click to toggle)
nyacc 1.09.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,540 kB
  • sloc: lisp: 34,985; sh: 682; makefile: 462; ansic: 279; javascript: 61; tcl: 27
file content (85 lines) | stat: -rw-r--r-- 2,755 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

Copyright (C) 2015-2019 Matthew R. Wette

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.  This file is offered as-is,
without any warranty.

=== This package can be installed or executed in situ. 

To play with example code and try modifications without installing:

  $ cd examples
  $ source env.sh

=== Hacking on the C99 parser ====

To play with the C99 code, in place, I recommend the following:
After sourcing env.sh in the examples subdirectory, execute

  $ cd nyacc/lang/c99
  $ ./cxp hello.c

The Guile source program cxp will print out the parse tree for hello.c
This is based on a C99 parser written with the NYACC parser generator.
 
IF you modify module/nyacc/lang/c99/mach.scm you will need to rebuild the
files in the subdirectory mach.d.  To do this run, in guile, the following:
  (use-modules (nyacc lang c99 mach))
  (use-modules (nyacc lang c99 cppmach))

  (gen-c99-files ".")
  (compile-file "parser.scm")
  (gen-cpp-files ".")
  (compile-file "cpp.scm")

=== Nyacc eXtension languages (or not-exactly languages)

  $ guile
  ...
  scheme@(guile-user)> ,L nx-javascript
  Happy hacking with nx-javascript!  To switch back, type `,L scheme'.
  nx-javascript@(guile-user)> var a = 1;
  nx-javascript@(guile-user)> ,L nx-octave
  Happy hacking with nx-octave!  To switch back, type `,L nx-javascript'.
  nx-octave@(guile-user)> b = 2;
  nx-octave@(guile-user)> ,L nx-tcl
  Happy hacking with nx-tcl!  To switch back, type `,L nx-octave'.
  nx-tcl@(guile-user)> set c 3
  nx-tcl@(guile-user)> ,L scheme
  Happy hacking with Scheme!  To switch back, type `,L nx-tcl'.
  scheme@(guile-user)> (+ a b)
  $1 = 3
  scheme@(guile-user)> c
  $2 = "3"

=== Hacking on the FFI Helper ====
  $ cd examples
  $ source env.sh 			# if you haven't done so previously
  $ guild compile-ffi ffi/cairo.ffi
  $ cd nyacc/lang/c99/ffi-exam
  $ guile demo-cairo.scm		# should generate demo-cairo.png

  $ guile
  guile> (use-modules (nyacc lang c99 ffi-help))
  guile> (use-modules (bytestructures guile))
  guile> (use-modules (system ffi-help-rt))
  guile> (use-modules ((system foreign) #:prefix ffi:))
  guile> (define fh-llibs '())
  guile> (define fexp (fh-cnvt-cdecl "fmod" "double fmod(double x,double y);")
  guile> ,pp exp
  $1 = (begin
    (define ~fmod
      (delay (fh-link-proc
               ffi:double
               "fmod"
               (list ffi:double ffi:double)
               fh-llibs)))
    (define (fmod x y)
      (let ((~x (unwrap~float x)) (~y (unwrap~float y)))
        ((force ~fmod) ~x ~y)))
    (export fmod))
  guile> (eval exp (current-module))
  guile> (fmod 2.3 0.5)
  $2 = 0.2999999999999998