aboutsummaryrefslogtreecommitdiff
path: root/pd/Atom.cs
blob: 532956e0a834d3392123c417767e2738583e36c3 (plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Runtime.InteropServices; // for structures

namespace PureData
{
	public enum AtomType {Null = 0, Float = 1, Symbol = 2, Pointer = 3};

    [StructLayout (LayoutKind.Sequential)]
    sealed public class Symbol
    {
        // this should NOT be public
        readonly private IntPtr ptr;
        
        public Symbol(IntPtr p)
        {
            ptr = p;
        }

        public Symbol(Symbol s)
        {
            ptr = s.ptr;
        }

        public Symbol(string s)
        {
            ptr = Core.GenSym(s);
        }
        
        override public string ToString()
        {
            return Core.EvalSym(this);
        }
    }

    [StructLayout (LayoutKind.Sequential)]
    sealed public class Pointer
    {
        public IntPtr ptr;
    }

    [StructLayout (LayoutKind.Explicit)]
    public struct Word
    {
        [FieldOffset(0)] public float w_float;
        [FieldOffset(0)] public Symbol w_symbol;
        [FieldOffset(0)] public Pointer w_pointer;
    }

    //[StructLayout (LayoutKind.Explicit)]
	[StructLayout (LayoutKind.Sequential)]
	sealed public class Atom 
	{
	
		public AtomType type;
		public Word word;
		
		public Atom(float f)
		{
			type = AtomType.Float;
			word.w_float = f;
		}

		public Atom(int i)
		{
            type = AtomType.Float;
            word.w_float = (float)i;
        }

        public Atom(Symbol s)
        {
            type = AtomType.Symbol;
            word.w_symbol = s;
        }
        
		public Atom(string s)
		{
            type = AtomType.Symbol;
            word.w_symbol = new Symbol(s);
		}
	}
	
	
	// this struct is relative to this c struct, see clr.c

	/*
		// simplyfied atom
		typedef struct atom_simple atom_simple;
		typedef enum
		{
			A_S_NULL=0,
			A_S_FLOAT=1,
			A_S_SYMBOL=2,
		}  t_atomtype_simple;
		typedef struct atom_simple
		{
			t_atomtype_simple a_type;
			union{
				float float_value;
				MonoString *string_value;
			} stuff;
		};
		*/

}