Skip to content

NyAncQt/cs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CS — C Scripting Language

A lightspeed scripting language with Lua-like syntax, compiled to bytecode and executed on a fast stack-based VM — all written in pure C.

Build

cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build

Run

# Run a script
./build/cs examples/hello.cs

# Start the REPL
./build/cs

Syntax

Variables

let x = 42
let name = "hello"
let active = true
let nothing = nil

Functions

fn add(a, b)
  return a + b
end

fn fib(n)
  if n < 2 then return n end
  return fib(n - 1) + fib(n - 2)
end

print(fib(30))

Control Flow

if x > 10 then
  print("big")
elseif x > 5 then
  print("medium")
else
  print("small")
end

Loops

while x > 0 do
  x = x - 1
end

for i = 0, 10 do
  print(i)
end

Strings

let greeting = "Hello" .. " " .. "World"
print(greeting)

Comments

-- This is a comment
let x = 42 -- inline comment

Builtins

  • print(value) — print a value to stdout
  • clock() — returns elapsed time in seconds (for benchmarking)
  • type(value) — returns the type of a value as a string
  • tostring(value) — converts a value to a string
  • tonumber(value) — converts a value to a number

Performance

CS compiles source code directly to bytecode in a single pass (no AST), then executes on an optimized stack-based virtual machine. This architecture minimizes memory allocations and maximizes throughput.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages