Embedded programming language for Zig
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Move some stuff around

IamPyu 43edb54f 0637f7e5

+102 -102
+102 -102
src/std/core.zig
··· 22 22 try scope.insert("let", try Value.initNativeMacro(scope, let)); 23 23 try scope.insert("lambda", try Value.initNativeMacro(scope, lambda)); 24 24 25 - try scope.insert("add", try Value.initNativeFunc(scope, add)); 26 - try scope.insert("sub", try Value.initNativeFunc(scope, sub)); 27 - try scope.insert("mul", try Value.initNativeFunc(scope, mul)); 28 - try scope.insert("div", try Value.initNativeFunc(scope, div)); 29 - try scope.insert("eql", try Value.initNativeFunc(scope, eql)); 30 - try scope.insert("not", try Value.initNativeFunc(scope, not)); 31 - try scope.insert("and", try Value.initNativeFunc(scope, @"and")); 32 - try scope.insert("or", try Value.initNativeFunc(scope, @"or")); 33 - 34 25 try scope.insert("eval", try Value.initNativeFunc(scope, eval)); 35 26 try scope.insert("define", try Value.initNativeFunc(scope, define)); 36 27 try scope.insert("set", try Value.initNativeFunc(scope, set)); ··· 40 31 try scope.insert("list", try Value.initNativeFunc(scope, list)); 41 32 try scope.insert("append", try Value.initNativeFunc(scope, append)); 42 33 try scope.insert("map", try Value.initNativeFunc(scope, map)); 34 + 35 + try scope.insert("add", try Value.initNativeFunc(scope, add)); 36 + try scope.insert("sub", try Value.initNativeFunc(scope, sub)); 37 + try scope.insert("mul", try Value.initNativeFunc(scope, mul)); 38 + try scope.insert("div", try Value.initNativeFunc(scope, div)); 39 + try scope.insert("eql", try Value.initNativeFunc(scope, eql)); 40 + try scope.insert("not", try Value.initNativeFunc(scope, not)); 41 + try scope.insert("and", try Value.initNativeFunc(scope, @"and")); 42 + try scope.insert("or", try Value.initNativeFunc(scope, @"or")); 43 43 } 44 44 45 45 // -- MACROS -- ··· 154 154 // TODO: implement dolist 155 155 } 156 156 157 - // -- OPERATORS -- 158 - 159 - pub fn add(scope: *Scope, args: []const *Value) RuntimeError!*Value { 160 - if (args.len == 0) { 161 - return Value.initNil(scope); 162 - } 163 - 164 - var first = try args[0].clone(scope); 165 - 166 - for (args[1..]) |v| { 167 - first = try first.add(scope, v); 168 - } 169 - 170 - return first; 171 - } 172 - 173 - pub fn sub(scope: *Scope, args: []const *Value) RuntimeError!*Value { 174 - if (args.len == 0) { 175 - return Value.initNil(scope); 176 - } 177 - 178 - var first = try args[0].clone(scope); 179 - 180 - for (args[1..]) |v| { 181 - first = try first.sub(scope, v); 182 - } 183 - 184 - return first; 185 - } 186 - 187 - pub fn mul(scope: *Scope, args: []const *Value) RuntimeError!*Value { 188 - if (args.len == 0) { 189 - return Value.initNil(scope); 190 - } 191 - 192 - var first = try args[0].clone(scope); 193 - 194 - for (args[1..]) |v| { 195 - first = try first.mul(scope, v); 196 - } 197 - 198 - return first; 199 - } 200 - 201 - pub fn div(scope: *Scope, args: []const *Value) RuntimeError!*Value { 202 - if (args.len == 0) { 203 - return Value.initNil(scope); 204 - } 205 - 206 - var first = try args[0].clone(scope); 207 - 208 - for (args[1..]) |v| { 209 - first = try first.div(scope, v); 210 - } 211 - 212 - return first; 213 - } 214 - 215 - pub fn eql(scope: *Scope, args: []const *Value) RuntimeError!*Value { 216 - if (args.len != 2) { 217 - return RuntimeError.InvalidArguments; 218 - } 219 - 220 - const b = args[0].isEqual(args[1]); 221 - return Value.initFromAny(scope, b); 222 - } 223 - 224 - pub fn not(scope: *Scope, args: []const *Value) RuntimeError!*Value { 225 - if (args.len != 1) { 226 - return RuntimeError.InvalidArguments; 227 - } 228 - 229 - return Value.initFromAny(scope, !args[0].isTruthy()); 230 - } 231 - 232 - pub fn @"and"(scope: *Scope, args: []const *Value) RuntimeError!*Value { 233 - if (args.len != 2) { 234 - return RuntimeError.InvalidArguments; 235 - } 236 - 237 - const b = args[0].isTruthy() and args[1].isTruthy(); 238 - return Value.initFromAny(scope, b); 239 - } 240 - 241 - pub fn @"or"(scope: *Scope, args: []const *Value) RuntimeError!*Value { 242 - if (args.len != 2) { 243 - return RuntimeError.InvalidArguments; 244 - } 245 - 246 - const b = args[0].isTruthy() or args[1].isTruthy(); 247 - return Value.initFromAny(scope, b); 248 - } 249 - 250 157 // -- FUNCTIONS -- 251 158 252 159 pub fn eval(scope: *Scope, args: []const *Value) RuntimeError!*Value { ··· 426 333 427 334 return iterable; 428 335 } 336 + 337 + // -- OPERATORS -- 338 + 339 + pub fn add(scope: *Scope, args: []const *Value) RuntimeError!*Value { 340 + if (args.len == 0) { 341 + return Value.initNil(scope); 342 + } 343 + 344 + var first = try args[0].clone(scope); 345 + 346 + for (args[1..]) |v| { 347 + first = try first.add(scope, v); 348 + } 349 + 350 + return first; 351 + } 352 + 353 + pub fn sub(scope: *Scope, args: []const *Value) RuntimeError!*Value { 354 + if (args.len == 0) { 355 + return Value.initNil(scope); 356 + } 357 + 358 + var first = try args[0].clone(scope); 359 + 360 + for (args[1..]) |v| { 361 + first = try first.sub(scope, v); 362 + } 363 + 364 + return first; 365 + } 366 + 367 + pub fn mul(scope: *Scope, args: []const *Value) RuntimeError!*Value { 368 + if (args.len == 0) { 369 + return Value.initNil(scope); 370 + } 371 + 372 + var first = try args[0].clone(scope); 373 + 374 + for (args[1..]) |v| { 375 + first = try first.mul(scope, v); 376 + } 377 + 378 + return first; 379 + } 380 + 381 + pub fn div(scope: *Scope, args: []const *Value) RuntimeError!*Value { 382 + if (args.len == 0) { 383 + return Value.initNil(scope); 384 + } 385 + 386 + var first = try args[0].clone(scope); 387 + 388 + for (args[1..]) |v| { 389 + first = try first.div(scope, v); 390 + } 391 + 392 + return first; 393 + } 394 + 395 + pub fn eql(scope: *Scope, args: []const *Value) RuntimeError!*Value { 396 + if (args.len != 2) { 397 + return RuntimeError.InvalidArguments; 398 + } 399 + 400 + const b = args[0].isEqual(args[1]); 401 + return Value.initFromAny(scope, b); 402 + } 403 + 404 + pub fn not(scope: *Scope, args: []const *Value) RuntimeError!*Value { 405 + if (args.len != 1) { 406 + return RuntimeError.InvalidArguments; 407 + } 408 + 409 + return Value.initFromAny(scope, !args[0].isTruthy()); 410 + } 411 + 412 + pub fn @"and"(scope: *Scope, args: []const *Value) RuntimeError!*Value { 413 + if (args.len != 2) { 414 + return RuntimeError.InvalidArguments; 415 + } 416 + 417 + const b = args[0].isTruthy() and args[1].isTruthy(); 418 + return Value.initFromAny(scope, b); 419 + } 420 + 421 + pub fn @"or"(scope: *Scope, args: []const *Value) RuntimeError!*Value { 422 + if (args.len != 2) { 423 + return RuntimeError.InvalidArguments; 424 + } 425 + 426 + const b = args[0].isTruthy() or args[1].isTruthy(); 427 + return Value.initFromAny(scope, b); 428 + }