Skip to content

Commit c00aa72

Browse files
committed
Initial commit: ArnoldC-Native systems programming language
I'LL BE BACK - Extended ArnoldC with native code generation Features: - Complete type system (u8-u64, i8-i64, void, char, pointers) - Struct and union definitions - Array operations with initializers - Bitwise operations (AND, OR, XOR, NOT, shifts) - Extended control flow (for, do-while, switch, break, continue, goto) - I/O port operations (byte, word, dword) - Interrupt control (CLI, STI, HLT, NOP, PAUSE) - Inline assembly support - Function pointers - Memory operations (alloc, free, memcpy, memset) - Enum definitions - Preprocessor directives (#define, #include, #ifdef, #ifndef) - Source-level comments - Full test suite (52 test cases) - CI/CD with GitHub Actions GET YOUR ASS TO MARS - Now generates freestanding C code for OS kernels
0 parents  commit c00aa72

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+8109
-0
lines changed

.github/workflows/test.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: ArnoldC-Native CI
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
pull_request:
7+
branches: [ main, master ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up JDK 17
18+
uses: actions/setup-java@v4
19+
with:
20+
java-version: '17'
21+
distribution: 'temurin'
22+
cache: 'sbt'
23+
24+
- name: Run tests
25+
run: sbt test
26+
27+
- name: Build assembly JAR
28+
run: sbt assembly
29+
30+
- name: Upload JAR artifact
31+
uses: actions/upload-artifact@v4
32+
with:
33+
name: ArnoldC-Native-jar
34+
path: target/scala-2.13/ArnoldC-Native.jar
35+
retention-days: 30
36+
37+
build-examples:
38+
runs-on: ubuntu-latest
39+
needs: test
40+
41+
steps:
42+
- name: Checkout code
43+
uses: actions/checkout@v4
44+
45+
- name: Set up JDK 17
46+
uses: actions/setup-java@v4
47+
with:
48+
java-version: '17'
49+
distribution: 'temurin'
50+
cache: 'sbt'
51+
52+
- name: Build compiler
53+
run: sbt assembly
54+
55+
- name: Compile example - VGA Hello
56+
run: |
57+
java -jar target/scala-2.13/ArnoldC-Native.jar -native examples/vga_hello.arnoldc
58+
cat vga_hello.c
59+
60+
- name: Compile example - Keyboard Driver
61+
run: |
62+
java -jar target/scala-2.13/ArnoldC-Native.jar -native examples/keyboard_driver.arnoldc
63+
cat keyboard_driver.c

.gitignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Scala/SBT
2+
target/
3+
project/target/
4+
project/project/
5+
.bsp/
6+
.metals/
7+
.bloop/
8+
metals.sbt
9+
.scala-build/
10+
11+
# IDE
12+
.idea/
13+
.vscode/
14+
*.iml
15+
*.ipr
16+
*.iws
17+
18+
# OS
19+
.DS_Store
20+
Thumbs.db
21+
desktop.ini
22+
23+
# Build artifacts
24+
*.class
25+
*.jar
26+
*.log
27+
28+
# Generated files
29+
*.c
30+
*.asm
31+
*.o
32+
*.bin
33+
*.elf
34+
35+
# Test artifacts
36+
test-output/
37+
38+
# Secrets
39+
.env
40+
*.pem
41+
*.key

CONTRIBUTING.md

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
# Contributing to ArnoldC-Native
2+
3+
"Come with me if you want to contribute." - The Contributor
4+
5+
## Getting Started
6+
7+
### Prerequisites
8+
9+
- JDK 11 or later
10+
- SBT (Scala Build Tool)
11+
- Git
12+
13+
### Setup
14+
15+
```bash
16+
# Clone the repo
17+
git clone https://github.com/YOUR_USERNAME/ArnoldC-Native.git
18+
cd ArnoldC-Native
19+
20+
# Compile
21+
sbt compile
22+
23+
# Run tests
24+
sbt test
25+
26+
# Build JAR
27+
sbt assembly
28+
```
29+
30+
## How to Contribute
31+
32+
### 1. Adding New Arnold Quotes
33+
34+
Want to add a new Arnold quote as a keyword? Here's how:
35+
36+
#### Step 1: Add the Keyword
37+
38+
In `ArnoldParserExtended.scala`, add your keyword:
39+
40+
```scala
41+
// In the keywords section
42+
val MyNewKeyword = "HASTA LA VISTA"
43+
```
44+
45+
#### Step 2: Create AST Node
46+
47+
Create a new case class in the appropriate `*Nodes.scala` file:
48+
49+
```scala
50+
case class MyNewNode(value: AstNode) extends StatementNode {
51+
def generate(mv: MethodVisitor, symbolTable: SymbolTable) = {}
52+
}
53+
```
54+
55+
#### Step 3: Add Parser Rule
56+
57+
In `ArnoldParserExtended.scala`:
58+
59+
```scala
60+
def MyNewStatement: Rule1[MyNewNode] = rule {
61+
MyNewKeyword ~ WhiteSpace ~ Operand ~ EOL ~~> MyNewNode
62+
}
63+
```
64+
65+
Don't forget to add it to the `Statement` rule!
66+
67+
#### Step 4: Add Code Generation
68+
69+
In `NativeGenerator.scala`:
70+
71+
```scala
72+
case MyNewNode(value) =>
73+
val code = generateExpression(value)
74+
emit(s"my_c_function($code); /* HASTA LA VISTA */")
75+
```
76+
77+
#### Step 5: Add Tests
78+
79+
In `ArnoldParserExtendedSpec.scala`:
80+
81+
```scala
82+
it should "parse my new statement" in {
83+
val code = """IT'S SHOWTIME
84+
|HASTA LA VISTA 42
85+
|YOU HAVE BEEN TERMINATED
86+
|""".stripMargin
87+
88+
val result = parser.parse(code)
89+
// assertions...
90+
}
91+
```
92+
93+
And in `NativeGeneratorSpec.scala`:
94+
95+
```scala
96+
it should "generate my new C code" in {
97+
val code = """...""".stripMargin
98+
val cCode = compile(code)
99+
cCode should include ("my_c_function")
100+
}
101+
```
102+
103+
#### Step 6: Update Documentation
104+
105+
- Add to `docs/LANGUAGE_SPEC.md`
106+
- Update `README.md` with the new keyword
107+
108+
### 2. Bug Fixes
109+
110+
1. Create an issue describing the bug
111+
2. Fork the repo
112+
3. Create a branch: `git checkout -b fix/issue-number`
113+
4. Write a failing test that demonstrates the bug
114+
5. Fix the bug
115+
6. Ensure all tests pass: `sbt test`
116+
7. Submit a PR
117+
118+
### 3. Feature Requests
119+
120+
1. Open an issue with the `enhancement` label
121+
2. Describe the feature and its use case
122+
3. Include example ArnoldC code if applicable
123+
4. Bonus points for Arnold quote suggestions!
124+
125+
## Code Style
126+
127+
### Scala
128+
129+
- Use 2-space indentation
130+
- Follow Scala style guide
131+
- Add comments for complex logic
132+
- Use meaningful variable names (Arnold quotes optional)
133+
134+
### Commit Messages
135+
136+
Use conventional commits with Arnold flair:
137+
138+
```
139+
feat: Add HASTA LA VISTA keyword for process termination
140+
fix: Parser now handles nested STICK AROUND loops
141+
docs: Update README with new examples
142+
test: Add tests for bitwise operations
143+
```
144+
145+
## Testing
146+
147+
### Running Tests
148+
149+
```bash
150+
# All tests
151+
sbt test
152+
153+
# Specific test class
154+
sbt "testOnly org.arnoldc.ArnoldParserExtendedSpec"
155+
156+
# With coverage
157+
sbt coverage test coverageReport
158+
```
159+
160+
### Writing Tests
161+
162+
- Each new feature needs parser AND generator tests
163+
- Test edge cases
164+
- Include Arnold-appropriate test names
165+
166+
Example:
167+
```scala
168+
it should "terminate when asked nicely" in {
169+
// test code
170+
}
171+
```
172+
173+
## Pull Request Process
174+
175+
1. Update documentation
176+
2. Add/update tests
177+
3. Ensure CI passes
178+
4. Request review
179+
5. Address feedback
180+
6. Merge with "I'LL BE BACK"
181+
182+
## Questions?
183+
184+
Open an issue or reach out. We don't bite (unless you're a bug).
185+
186+
---
187+
188+
"GET TO THE CHOPPER!" - When you see a merge conflict
189+
190+
"CONSIDER THAT A DIVORCE" - When closing a stale PR
191+
192+
"I'LL BE BACK" - Standard PR merge message

0 commit comments

Comments
 (0)